// JavaScript Document
try{
   sender = new XMLHttpRequest();
}
catch (e){
  try{
	   sender = new ActiveXObject("Msxml2.XMLHTTP");
  } 
  catch (e){
	 try{
		 sender = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	catch (failed){
		sender = null;
	}
 }  
}

function stripslashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\0/g,'\0');
str=str.replace(/\\\\/g,'\\');
return str;
}

xreq_dest="new_mails_cnt";

request_running=false;
request_busy_cnt=0;
windows=new Array();
windows[0]=new Array();

function focus_win(n) {
  alert(n+" focused! "+windows[0][n].name);
	windows[0][n].focus();
}
k=0;
function handleReceiveStat(){            
  play=false;
	switch(sender.readyState) {
	case 4:
	if(sender.status!=200) {
		//alert("Fehler:"+sender.status); 
		request_running=false;
	}else{   
		//alert(req.responseText);
		//scroll_y=find_div(xreq_dest).scrollTop;
		//more_debug(scroll_y+" ");
		cont=sender.responseText;
		if (xreq_dest.indexOf('info_div_')!=-1)
		  user_info_requesting=false;
		if (xreq_dest=='new_mails_cnt')
		  if (cont=='0' || cont=='(0)') cont=''; 
		//alert(cont);
		if (cont.indexOf("Privatchat")!=-1) {
			arr=cont.split("?to_id=");
			for (i=1;i<arr.length;i++) {
				id=arr[i].split("'")[0];
				if (document.getElementById(xreq_dest).innerHTML.indexOf("to_id="+id)==-1)
				  windows[k++]=window.open('chatroom/pchat.php?to_id='+id+sessident,'chat_win_'+id,'width=400, height=300, resizable=no'); 
			}
		}
		
		if (xreq_dest!="" && xreq_dest!="NIL") {
		  document.getElementById(xreq_dest).style.display="";
		  document.getElementById(xreq_dest).innerHTML = cont;
		}
		/*if (xreq_dest=="suggest_layer") {
		  alert(document.getElementById(xreq_dest).style.left+ " : " + document.getElementById(xreq_dest).style.top);
		  document.getElementById("suggest_layer").style.display="";
		  alert(document.getElementById(xreq_dest).innerHTML);
		}*/
		//find_div(xreq_dest).scrollTop=scroll_y;
			
		if (xreq_dest=="additional_content")
		  location.href="#anchor_additional_content";
		//xreq_dest="additional_content";
		request_running=false;
	}
	break;
	
	default: 
		return false;
	break;     
  }
};

function debug(s) {
	
}

function xrequest(url,destination) {

if (!request_running) {
	
	  if (destination !="" && !document.getElementById(destination) && destination!='NIL') {
			return;
		}
    xreq_dest=destination;

    sender.open("GET", url, true);
    sender.onreadystatechange = handleReceiveStat;
    //"http://"+location.hostname+"/"+
    sender.send(" ");
    //alert(url);
  } else {
    window.setTimeout("xrequest('"+url+"','"+destination+"')",1500+Math.round(Math.random()*3000));
	debug("xrequest('"+url+"','"+destination+"')");
	request_busy_cnt++;
	if (request_busy_cnt>100) {
	  request_running=false;
	  request_busy_cnt=0;
	}
  }
}

function xrequest_find_dest(url,dest_start) {
  obj=dest_start;
  while (obj.id.toLowerCase().indexOf("info_content")==-1 && obj.id.toLowerCase().indexOf("center_content")==-1) {
    obj=obj.parentNode;
  }
  xreq_dest=obj.id;
	document.getElementById(xreq_dest).innerHTML=document.getElementById("loader_span").innerHTML;
	if (!request_running) {
		sender.open("GET", url, true);
		sender.onreadystatechange = handleReceiveStat;
		//"http://"+location.hostname+"/"+
		sender.send(" ");
		document.getElementById("sound_launch").Play();
		request_running=true;
	} else {
    window.setTimeout("xrequest('"+url+"','"+xreq_dest+"')",1500+Math.round(Math.random()*3000));
		debug("xrequest('"+url+"','"+destination+"')");
		request_busy_cnt++;
		if (request_busy_cnt>100) {
			request_running=false;
			request_busy_cnt=0;
		}
  }
  //alert(url);
}

function find_div(dest_start) {
  obj=document.getElementById(dest_start);
  if (!obj) return document.body;
  if (obj.id.indexOf("scr_win_")!=-1) return obj;
  elems=obj.getElementsByTagName("div");
  for (i=0;i<elems.length;i++)
    if (elems[i].id.indexOf("scr_win_")!=-1) {
	  return elems[i];
	  break;
	}
  return obj;
}
  
function bcheck() {
  ver=navigator.appVersion;
  appname=navigator.appName;
  if (ver.indexOf('MSIE 7')!=-1 || appname.indexOf('Opera')!=-1)
    return true; else
	  return false;
}

function bcheck_ie() {
  ver=navigator.appVersion;
  appname=navigator.appName;
  if (ver.indexOf('MSIE')!=-1 || appname.indexOf('Opera')!=-1)
    return true; else
	  return false;
}


function writeFlashPlayer(div_name,code) {
  if (bcheck())
    document.getElementById(div_name).innerHTML='<object width="500" height="411"><param name="movie" value="http://www.youtube.com/v/'+code+'"></param><param name="wmode" value="transparent"></param><embed allowfullscreen="true" src="http://www.youtube.com/v/'+code+'" type="application/x-shockwave-flash" wmode="transparent" width="500" height="411"></embed></object>';	
}

function loadUrlHere(url) {
  y = document.all?document.body.clientTop:pageYOffset;
  location.href=url + '&goY=' + y;
}


function goY(y){
  window.scrollTo(0,y);
}

function getypos(obj) {
  y=0;
  while (obj!=null) {
    y+=obj.offsetTop;
	//if (!document.all)
	  //obj=obj.parentNode; else
	    obj=obj.offsetParent;
  }
  return y;
}
function getxpos(obj) {
  x=0;
  while (obj!=null) {
    x+=obj.offsetLeft;
	//if (!document.all)
	  //obj=obj.parentNode; else
	    obj=obj.offsetParent;
  }
  return x;
}
function align_layer_to(layer,obj,px,py) {
  x=getxpos(obj)-168;
  y=getypos(obj)+18;
	if (!px) px=0;
	if (!py) py=0;
  document.getElementById(layer).style.top=y+py+"px";
  document.getElementById(layer).style.left=(x+obj.offsetWidth)+px+"px";
  document.getElementById(layer).style.display="block";
}

function align_layer_to_tl(layer,obj,px,py) {
  x=getxpos(obj);
  y=getypos(obj);
	if (!px) px=0;
	if (!py) py=0;
  document.getElementById(layer).style.top=y+py+"px";
  document.getElementById(layer).style.left=x+px+"px";
  document.getElementById(layer).style.display="block";
}

current_display_id="";
user_info_requesting=false;
function user_info_window(id) {
	if (current_display_id!=id && !user_info_requesting) {
	  divs=document.getElementsByTagName("div");
	  for (i=0;i<divs.length;i++)
	    if (divs[i].id.indexOf("info_div_")!=-1) {
		    divs[i].innerHTML="";
				divs[i].style.display='none';
			}
	  xrequest('user_short_inf.php?uid='+id,'info_div_'+id);
		user_info_requesting=true;
		align_layer_to_tl('info_div_'+id,document.getElementById('info_trigger_'+id),0,-70);
		//document.getElementById('info_div_'+id).style.display='';
	  current_display_id=id;
	}
}

function close_actual_info_window() {
  document.getElementById('info_div_'+current_display_id).innerHTML='';
	document.getElementById('info_div_'+current_display_id).style.display='none';
	current_display_id='';
}

function remember(id) {
  xrequest("remember.php?id="+id,"remember_"+id);	
}

// Auslagerung aus dem Maintemplate

function forgot_password() {
  document.getElementById("password").value="#forgot#password#";
  document.getElementById("loginform_main").submit();
}
function setaspassword(focus) {
  val='';
  //document.getElementById("passwordspan").innerHTML='<input name="password" type="password" class="standardinput" id="password" value="'+val+'">';
  //if (focus) window.setTimeout("document.loginform.password.focus();",100);
  p1=document.getElementById("fake_password_div");
  p2=document.getElementById("password_div");
  p1.style.display="none";
  p2.style.display="block";
  if (focus) p2.focus();
}

function getypos(obj) {
  y=0;
  while (obj!=null) {
    y+=obj.offsetTop;
	//if (!document.all)
	  //obj=obj.parentNode; else
	    obj=obj.offsetParent;
  }
  return y;
}
function getxpos(obj) {
  x=0;
  while (obj!=null) {
    x+=obj.offsetLeft;
	//if (!document.all)
	  //obj=obj.parentNode; else
	    obj=obj.offsetParent;
  }
  return x;
}

function getDims(e) {
	aw = e.offsetWidth.toString().replace(/px/,"")*1;
	ah = e.offsetHeight.toString().replace(/px/,"");
	return {x:getxpos(e), y:getypos(e), w:aw*1, h:ah*1 };
}

sizesKnown = false;
divSizes = new Array();
expanded = null;
expanding = null;
deflating = null;

function expandThis(no) {
  if (!sizesKnown) {
		for (i=0;i<3;i++) {
			if (document.getElementById("expDiv"+(i+1))) {
				el = document.getElementById("expDiv"+(i+1));
				el.style.display = "";
				dim = getDims(el);
				divSizes[i] = dim.h;
				el.style.display = "none";
			}
		}
		sizesKnown = true;
	}
	if (no != -1) {
		aEl = document.getElementById("expDiv"+(no));
		if (aEl.style.display == "none") {
			aEl.style.display = "";
			aEl.style.overflow = "hidden";
			aEl.style.height = "0px";
			expanding = no;
			for (i=0;i<3;i++)
			  if (document.getElementById("expDiv"+(i+1)) && document.getElementById("expDiv"+(i+1)).style.display == "" && i+1!=no) {
					document.getElementById("expDiv"+(i+1)).style.overflow = "hidden";
			    document.getElementById("expDiv"+(i+1)).style.height = divSizes[i] + "px";
			    deflating = i+1;
					break;
				}
		} else
		if (aEl.style.display == "" && deflating == null) {
			aEl.style.overflow = "hidden";
			aEl.style.height = divSizes[no-1] + "px";
			deflating = no;
		}
	}
	if (expanding != null) {
		expEl = document.getElementById("expDiv"+(expanding));
		h = expEl.style.height.replace(/px/,"")*1;
		//alert(h + " : " + divSizes[expanding-1]);
		if (h<divSizes[expanding-1]) {
		  expEl.style.height = (h + Math.ceil((divSizes[expanding-1] - h)/2)) + "px";
		} else {
			expanded = expanding;
			expanding = null;
			expEl.style.display = "";
			expEl.style.overflow = "visible";
		}
	}
	if (deflating != null) {
		expEl = document.getElementById("expDiv"+(deflating));
		h = expEl.style.height.replace(/px/,"")*1;
		//alert(h + " : " + divSizes[expanding-1]);
		if (h>0) {
		  expEl.style.height = (h - Math.ceil(h/2)) + "px";
		} else {
			expEl.style.display = "none";
			expEl.style.overflow = "visible";
			deflating = null;
		}
	}
	if (expanding != null || deflating != null)
	  window.setTimeout("expandThis(-1)",100);
}


function update_design() {
	if(document.getElementById('uploadPrototype') != undefined) {
    another_pic();
  } 
	if (typeof(initGeo) != "undefined")	 {
	  geoInit();
		for (var j=0;j<TFuncs.length;j++) {
		  eval(TFuncs[j]);
		}
	}

	contentTD = null;
	mainContentTD = null;
	elms = document.getElementsByTagName("td");
	for (i=0;i<elms.length;i++) {
		if (elms[i].className.indexOf("top_td")!=-1) {
			contentTD = elms[i];
		}
		if (elms[i].className.indexOf("td_content3")!=-1) {
			mainContentTD = elms[i];
		}
	}
	if (contentTD != null) {
		dim = getDims(contentTD);
		h=dim.h;
		
		if (h>150) {
			contentTD.style.height="80px";
			if (document.getElementById("advertise_left"))
			document.getElementById("advertise_left").innerHTML="";
			if (mainContentTD != null)
			  mainContentTD.innerHTML+="<div style='height:200px'></div>";
		}
	}
}

//window.onload = update_design;
