/*
	(c)2003-2006 Copyright by Frank Monnerjahn
	Written for ogonek.net
*/
function openfoto(){
	open('/foto/','','width=500,height=300');
}


function helper(hid){
	helpshow=window.open("/faq/?id="+hid+"#help","helpshow","height=570,width=900,status=yes,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no");
	helpshow.focus()
}

function bgmove(obj,onoff){
 if(typeof(obj.style)!='undefined'){
	if(onoff){
		obj.style.backgroundColor='#4f2700';
	}else{
		obj.style.backgroundColor='';
	}
 }
}

function bgcheck(obj){
	if(obj.style.backgroundColor==''){
		obj.style.backgroundColor='RoyalBlue';
	}else{
		obj.style.backgroundColor='';
	}
}

// Counter
coe=new Array();

function setcor(s,o){coe[o]=s;}

function startc(){
	var ln=0;
	for(ce in coe){
		if(coe[ce]>=0){
//			document.all[ce].innerHTML=cor(coe[ce]);
			document.getElementById(ce).innerHTML=cor(coe[ce]);

			coe[ce]-=1;
			ln++;
		}
	}
	if(ln){setTimeout("startc()",1000);}
}

function counter(val,cred){
  window.setTimeout("counter("+val+","+cred+")", 1000)
}

function cor(insec){
	var weta="";
	if(insec){
		nexts=insec-1;
		if(insec>=604800){week=Math.floor(insec/604800);insec-=week*604800;weta=week+"W ";}
		if(insec>=86400){ tage=Math.floor(insec/86400);	insec-=tage*86400;weta+=tage+"T ";}
		stunde=	Math.floor(insec/3600);	insec-=stunde*3600;
		minu	=	Math.floor(insec/60);		insec-=minu*60;
		minu=minu>9?minu:"0"+minu;insec=insec>9?insec:"0"+insec;
		return weta+stunde+":"+minu+":"+insec;
	}else{
		return "Fertig";
//		location.reload();
	}
}
// Counter ende


function ccf(ob,cna){
var cnc=ob.form;
var onoff=ob.checked;
	for(i=0;i<cnc.length;i++){
		if(cnc[i].name.substring(0,cna.length)==cna){
			cnc[i].checked=onoff;
		}
	}
}


function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images ) { //&& (preloadFlag == true)
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}


function openchat(nick){
	open('http://www.clanintern.de/chat.php4?clan=82653&nick='+nick,'_blank','width=670,height=600,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,top=25');
}

function portalchat(){
	open('http://www.clanintern.de/chat.php4?clan=82653','_blank','width=670,height=600,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,top=25');
}

function pwlost(){
	open('/?action=lostpw','_blank','width=425,height=161,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,top=50,left=100');
}

// rohstoff count
ro=new Array();
function setro(s,ns,o,mr){
	ro[o] = new Array(s,ns,mr);
}

function startro(){
	for(cr in ro){
		ro[cr][0]+=ro[cr][1];
		if(ro[cr][0]>ro[cr][2]){
			tod=ro[cr][2];
		}else{
			tod=ro[cr][0];
		}
//		document.all[cr].innerHTML=fnum(Math.floor(tod));
		document.getElementById(cr).innerHTML=fnum(Math.floor(tod));
	}
	setTimeout("startro()",1000);
}

function fnum(za){
	za=za.toString();
	var cs="",co=0,le=0;
	le=za.length;
	co=3-(le-(Math.floor(le/3)*3));
	if(co==3){co=0;}
	for(i=0;i<=le;i++){
		cs+=za.substr(i,1);co++;
		if(co==3 && le != i+1){cs+=".";co=0;}
	}
	return cs;
}


// rohstoff count end

function openonline(){
	window.open('online.php','','scrollbars=1,resizable=1,menubar=0,width=230,height=350');
}


function nogfx(){
	x=500;y=380;
	nogfx=window.open('gfxpack/nogfx.html','','scrollbars=1,resizable=0,menubar=0,width='+x+',height='+y);
	nogfx.window.moveTo((screen.width/2)-(x/2),(screen.height/2)-(y/2));
	nogfx.window.focus();
}

function sht(el){
	if(el.style.display == "none") {
		el.style.display = "";
	}else{
		el.style.display = "none";
	}
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function loadmove(){
for(i=1;i<conf.length;i++){
	alph[i]=Math.random()*10;
	if(document.getElementById) laySyntax[i]=document.getElementById("P"+i).style;
	else if(document.all) laySyntax[i]=document.all.tags("div")[i].style;
	else if(document.layers) laySyntax[i]=document.layers[i];
}
//move();
}

function move(){
	for(p=1;p<conf.length;p++){ 
		c=conf[p];
		r=c[1]?1:-1;
		laySyntax[p].top =plani[c[0]][1]+c[2]*Math.sin(alph[p])-c[4];
		laySyntax[p].left=plani[c[0]][0]+c[2]*Math.cos(alph[p])-c[4];
      alph[p]+=(1/Math.pow(c[2],2.25))*r*300;

//		alph[p]+=c[3]*r;//0.03+((c[3]/1000)*r);
	}
	setTimeout('move()',100);
}


function ccfid(ob,cna){
var cnc=ob.form;
var onoff=ob.checked;
  for(i=0;i<cnc.length;i++){
    if(cnc[i].id.substring(0,cna.length)==cna){
      cnc[i].checked=onoff;
    }
  }
}

function checkid(id){
  if(document.getElementById(id).checked){
    document.getElementById(id).checked=false;
  }else{
    document.getElementById(id).checked=true;
  }
}

function fastbuild(pid,fid,prize){
  if(confirm('Bau sofort abschließen? Benötigt :'+prize+' Credits')){
    location.href='\?pid='+pid+'&fid='+fid;
  }
}

function clc(pid,cbau,pro){
  if(confirm('Bau wirklich abbrechen? Ressourcen gehen verloren!')){
    location.href='\?pid='+pid+'&cbau='+cbau+'&pro='+pro;
  }
}

//toolbox raumfahrt

function mdset(d) {
var ele=document.getElementsByName("multipd");
  for (i=0;i<ele.length;i++) ele[i].selectedIndex=d.selectedIndex;
}

function settext(was,d) {
var ele=document.getElementsByName("kord["+was+"]");
  for (i=0;i<ele.length;i++) ele[i].value=d.value;
}

//checkbox raumfahrt

function chkbox(ob,cna){
var ele=document.getElementsByName(cna);
for(i=0;i<ele.length;i++) ele[i].checked=ob.checked;
}

  var iv = new Array();
  iv[0] = new Image(); 
  iv[1] = new Image(); 
  iv[2] = new Image(); 
  iv[3] = new Image(); 
  iv[4] = new Image(); 
  iv[5] = new Image(); 
  iv[0].src ="/inva/nounit.gif";
  iv[1].src ="/inva/inf.png";
  iv[2].src ="/inva/flak.png";
  iv[3].src ="/inva/ari.png";
  iv[4].src ="/inva/tank2.png";
  iv[5].src ="/inva/gleiter.png";
  
  
function openogochat(){
	ogochat=open('/chat/','ogochat','width=860,height=430');
	ogochat.focus();
}


  
function openXMLHttpRequest() {
	if( window.XMLHttpRequest ) {	return new XMLHttpRequest();
	} else if( window.ActiveXObject && navigator.platform != 'MacPPC' ) {	return new ActiveXObject("Microsoft.XMLHTTP");
	} else {alert("Kein XMLHttpRequest");return null;}
}

runme=0;

function send(text){
	clearTimeout(runme);
	Requ = openXMLHttpRequest();
	Requ.onreadystatechange = function(){
		if( Requ.readyState != 4 ) {return;}
		if( Requ.status != 200 ) {window.alert('Failed to connect: ' + Requ.status +	' "' + Requ.statusText + '"');	return;}
		ob  = Requ.responseXML
		 //alert(Requ.responseText)
		//document.getElementById('debugtext').innerText = Requ.responseText;
		
		Xuser = ob.documentElement.getElementsByTagName('user');
		Xtext = ob.documentElement.getElementsByTagName('ctext');
		
		uli = document.getElementById('user');
		uli.innerHTML = "<p><b>Channel:" + ob.documentElement.getElementsByTagName('channelname')[0].firstChild.data +" ("+ Xuser.length +")</b></p>";
		for(i=0;i<Xuser.length;i++){
			if(Xuser[i].firstChild){
				uli.innerHTML += "<dd><a href=\"/?action=userinfo&amp;uid="+ Xuser[i].getAttribute('uid') +"\" target=\"_userinfo\">"+ Xuser[i].firstChild.data +"</a><br />\n";
			}
		}
		
		ot=document.getElementById('ctext');
		for(i=0;i<Xtext.length;i++){
			X=Xtext[i];
			if(X.firstChild){
			  if(X.getAttribute('system')){
					ot.innerHTML += "<i>["+ X.getAttribute('zeit') +"] * "+ X.getAttribute('user') +" * "+ X.firstChild.data +"</i><br />\n";
				}else{
					ot.innerHTML += "["+ X.getAttribute('zeit') +"] &lt;"+ X.getAttribute('user') +"&gt; "+ X.firstChild.data +"<br />\n";
					top.focus();
				}
				document.title= "ogoChat :" + X.firstChild.data.substr(0,25) + "...";
				ot.scrollTop=ot.scrollHeight;
			}
		}
	}
	if(text != ''){
		Requ.open("POST", "c2.php", true);
		Requ.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		Requ.send('send='+encodeURIComponent(text));
	}else{
		Requ.open("GET", "c2.php", true);
		Requ.send(0);
	}
  runme=setTimeout("send('')",3500);
}

function sendtext(){
	text=document.getElementById('textsender').value;
	document.getElementById('textsender').value="";
	document.getElementById('textsender').focus();
	send(text);
	return false;
}

var channelname="";
function channel(){
	if(channelname = prompt('Channel',channelname))
		send("/channel "+ channelname);
}
