
// Dynamische Tabs
function show_tab(tab){
	if(rt)
		window.clearTimeout(rt);
	if(active_tab != tab){

		if(active_tab != 'none'){
			document.getElementById('tab_left_'+active_tab).src = colix_zebra + "tab_left.png";
			document.getElementById('tab_'+active_tab).className = "navi";
			document.getElementById('tab_right_'+active_tab).src = colix_zebra + "tab_right.png";
		}
		document.getElementById('l2n_'+active_tab).style.display = 'none';

		if(tab != 'none'){
			document.getElementById('tab_left_'+tab).src = colix_background + "tab_left_active.png";
			document.getElementById('tab_'+tab).className = "navi_active";
			document.getElementById('tab_right_'+tab).src = colix_background + "tab_right_active.png";
		}
		document.getElementById('l2n_'+tab).style.display = 'block';

		active_tab = tab;
	}
}
function reset_tab(){
	if(rt)
		window.clearTimeout(rt);
	rt = window.setTimeout("show_tab(L1N)", 350);
}

// alle Divs im array "ids_to_show" anzeigen; alle anderen der klasse "hidden" verstecken
function show_rc(ids_to_show){
	var obj;
	for(var i = 0; i < ids_to_show.length; i++){
		obj = document.getElementById(ids_to_show[i]);
		obj.style.display = (obj.style.display != "block") ? "block" : "none";
	}
	for(i = 0; i < document.getElementsByTagName("div").length; i++){
		obj = document.getElementsByTagName("div")[i];
		if(obj.className == "hidden" && !in_array(obj.id,ids_to_show))
			obj.style.display = "none";
	}
}

function getHost(url){
	var start, i;
	if(url.substr(0,7) == "http://")
		start = 7;
	else
		start = 0;
	for(i = start; i < url.length; i++){
		if(url.charAt(i) == '/')
			return url.substring(start, i);
	}
	return url.substr(start);
}

function check4InternLink(link){
	var host;
	if(getHost(self.location.href) == (host = getHost(link)) ){
		if(!(link = link.substr(host.length + 7)))
			link = "/";
	}
	return link;
}

// einfuegen der sepcial tags
function add_link(textarea,i){
	if(!(link = prompt(prompt_link+":","http://www.")))
		return;
	if(!(desc = prompt(prompt_link_desc+":",link.replace("http://",""))))
		desc = link;
	if(link.substr(0,7) != "http://")
		link = "http://"+link;

	link = check4InternLink(link);

	document.getElementsByName(textarea)[i].value += "|link|"+link+"|"+desc+"|";
	document.getElementsByName(textarea)[i].focus();
}
function add_email(textarea,i){
	if((email = prompt(prompt_email+":","@"))){
		document.getElementsByName(textarea)[i].value += "|email|"+email+"|";
		document.getElementsByName(textarea)[i].focus();
	}
}
function add_img(textarea,i){
	window.open(ROOT+"etc/add_img.popup.php?f="+textarea+"&fi="+i+""+aSID,"add_img","width=450,height=500,left=0,top=0,scrollbars=yes");
}
function add_mp3(textarea,i){
	if(!(mp3 = prompt(prompt_mp3_url+":","http://www.")))
		return;
	if(!(desc = prompt(prompt_mp3_desc+":",mp3.match(/[^\/]*$/))))
		desc = mp3;
	document.getElementsByName(textarea)[i].value += "|mp3|"+mp3+"|"+desc+"|";
	document.getElementsByName(textarea)[i].focus();
}

function add_video_pre(textarea,i){
	if( ( obj = document.getElementById('imgp'+i+''+textarea) ) )
		obj.style.display = "none";
	obj = document.getElementById('vp'+i+''+textarea);
	obj.style.display = (obj.style.display != "inline") ? "inline" : "none";
}
function add_video(textarea,i,pre_url){
	if((video = prompt(prompt_video+":",pre_url))){
		document.getElementsByName(textarea)[i].value += "|video|"+video+"|";
		document.getElementsByName(textarea)[i].focus();
	}
	document.getElementById('vp'+i+''+textarea).style.display = "none";
}

function popUp(url,name,width,height){
	window.open(url,name,"width="+width+",height="+height+",left="+(screen.width - width - 10)+",top=0");
}
function openTermsOfUse(){
	window.open(ROOT+"etc/terms_of_use.popup.php"+qSID,"terms_of_use","width=500,height=550,left=0,top=0,scrollbars=yes");
}
function openHelp(p){
	window.open(ROOT+"etc/help.popup.php"+qSID+"#"+p,"help","width=500,height=550,left=0,top=0,scrollbars=yes");
}
function openChat(user){
	/*if(confirm(confirm_chat))
		popUp(ROOT+"chat/1on1chat.php?user="+user+aSID,"chat_win"+user,chat_win_width,chat_win_height);*/
}
function responseChat(server,key,user){
	popUp(ROOT+'chat/1on1chat.php?server='+server+'&key='+key+'&partner='+user+aSID,'chat_win'+user,chat_win_width,chat_win_height);
}
function in_array(el,array){
	for(var i = 0; i < array.length; i++){
		if(array[i] == el)
			return true;
	}
	return false;
}

// gewaehlten wert eines select menüs
function get_selected_value(obj){
	return obj.options[obj.options.selectedIndex].value;
}

// sys_msg per javascript nachtraeglich einblenden
function sys_msg(win,sys_msg){
	if(win.document.getElementById('sys_msg'))
		win.document.getElementById('sys_msg').style.display = "none";

	win.document.getElementById('deferred_sys_msg').innerHTML = '<div class="sys_msg"><table cellspacing="0" class="stripes"><tr><th class="stripe"><img src="'+ROOT+'_img/_gfx/blind.png" width="6" height="6" alt="" /></th><td class="bg_color"><table cellspacing="0" cellpadding="0"><tr><td class="top"><img src="'+ROOT+'home/'+sissis_id+'/my_pic_s.jpg"  width="'+my_pic_s_width+'" height="'+my_pic_s_height+'" alt="" /></td><td><ul>'+sys_msg+'</ul></td></tr></table></td><th class="stripe"><img src="'+ROOT+'_img/_gfx/blind.png" width="6" height="6" alt="" /></th></tr></table></div><div class="stripe">&nbsp;</div>';

	win.document.getElementById('deferred_sys_msg').style.display = "block";
}

// Timer
function extendSessionTime(){
	sendRequest(ROOT+"etc/extend_session_time.php"+qSID,resetTimeout,null,extendSessionTimeAlt,null);
}
function extendSessionTimeAlt(){
	popUp(ROOT+"etc/extend_session_time.php"+qSID,"extend_session_time",50,50);
	resetTimeout();
}
function sessionTimeout(){
	if(countdown > 0)
		ttag.innerHTML = ttag.innerHTML.replace(/\d\d?/,--countdown);
	else
		resetTimeout();
}
function resetTimeout(){
	window.clearInterval(t);
	ttag.style.display = 'none';
	countdown = fixed_countdown;
	ttag.innerHTML = ttag.innerHTML.replace(/\d\d?/,countdown);
	window.setTimeout('initTimeout()',(timeout*1000));
}
function initTimeout(){
	ttag = document.getElementById('timeout');
	ttag.style.display = 'block';
	t = window.setInterval("sessionTimeout();",1000);
}

function sendRequest(url, retFunc, retFuncArgs, retFuncAlt, retFuncArgsAlt){

	if(url.length > 1000){
		if(retFuncAlt)
			retFuncArgsAlt ? retFuncAlt(retFuncArgsAlt) : retFuncAlt();
		return;
	}

	var xr;

	try{ xr = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e){
		try{ xr = new ActiveXObject("Microsoft.XMLHTTP"); }
		catch (oc){ xr = null; }
	}
	if(!xr && typeof XMLHttpRequest != "undefined")
		xr = new XMLHttpRequest();

	try{		
		xr.open("GET", url, true);
		xr.onreadystatechange = function() {
			if(xr.readyState != 4)
				return;
			if(retFunc){
				retFuncArgs ? retFunc(xr.responseText,retFuncArgs) : retFunc(xr.responseText);
			}
		}
		xr.send(null);	
		delete xr;
	}
	catch(e){
		if(retFuncAlt)
			retFuncArgsAlt ? retFuncAlt(retFuncArgsAlt) : retFuncAlt();
	}
}