// ------------------------------------------------------------------
// FUP GENERALS
// ------------------------------------------------------------------

// Init
var loading_complete=false;
var wu_fe_init_stack=new Array();
window.onload=wu_fe_init;

// preloader
function wu_fe_init()
{
	// OnLoad Init
	for (var a=0; a<wu_fe_init_stack.length; a++) {eval(wu_fe_init_stack[a]);}
	
	loading_complete=true;
}


var wu_fe_key_pressed=0;
var wu_fe_hotkey_pressed=new Array(255);
var wu_fe_hotkey_href=new Array(255);
var wu_fe_click_handled=false;
var wu_fe_click_x=0;
var wu_fe_click_y=0;
var wu_fe_dropdown_active=null;

document.onclick=wu_fe_click;
document.onkeydown=wu_fe_keydown;
document.onkeyup=wu_fe_keyup;
function wu_fe_keycode(e)
{
	if (!e) {if (window.event) {e = window.event;} else {return 0;}}
	if (typeof(e.which)=='number') {return e.which;}
	if (typeof(e.keyCode)=='number') {return e.keyCode;}
	if (typeof(e.charCode)=='number') {return e.charCode;}
	return 0;
}
function wu_fe_keydown(e)	{wu_fe_key_pressed=wu_fe_keycode(e); wu_fe_hotkey_pressed[wu_fe_key_pressed]=true; return wu_fe_hotkeys(wu_fe_key_pressed);}
function wu_fe_keyup(e) 	{wu_fe_key_pressed=0; wu_fe_hotkey_pressed[wu_fe_keycode(e)]=false;}
function wu_fe_click(e) 	{if (window.event) {wu_fe_click_x=window.event.clientX; wu_fe_click_y=window.event.clientY;} else {wu_fe_click_x=e.pageX; wu_fe_click_y=e.pageY; wu_fe_dropdown_pos(wu_fe_dropdown_active);} if (wu_fe_click_handled) {wu_fe_click_handled=false;} else {wu_fe_dropdown_hide(wu_fe_dropdown_active);}}
function wu_fe_hotkeys(key)
{
	if (key==17 || (!wu_fe_hotkey_pressed[17] && key!=13 && key!=27)) {return true;}
	if (wu_fe_hotkey_href[key]) {eval(wu_fe_hotkey_href[key]); return false;}
	return true;
}
function wu_fe_dropdown_show(obj)
{
	if (wu_fe_dropdown_active) {wu_fe_dropdown_hide(wu_fe_dropdown_active); wu_fe_dropdown_active=null;}
	if (obj)
	{
		wu_fe_dropdown_pos(obj);
		wu_fe_dropdown_active=obj;
		wu_fe_click_handled=true;
	}
}
function wu_fe_dropdown_pos(obj)
{
	if (obj && window.event)
	{
		obj.style.posLeft = window.event.clientX + document.body.scrollLeft;
		obj.style.posTop = window.event.clientY + document.body.scrollTop;
		obj.style.visibility="visible";
	}
	else if (obj)
	{
		obj.style.left = wu_fe_click_x + window.pageXOffset;
		obj.style.top = wu_fe_click_y + window.pageYOffset;
		obj.style.visibility="visible";
	}
}
function wu_fe_dropdown_hide(obj)
{
	if (obj)
	{
		obj.style.visibility="hidden";
		if (wu_fe_dropdown_active==obj) {wu_fe_dropdown_active=null;}
	}
}
function wu_fe_textarea_maxlength(obj,maxlength,hint_id)
{
	if (!obj || !maxlength) {return;}
	var curlength=obj.value.length;
	
	if (curlength>maxlength)
	{
		obj.value=obj.value.substring(0,maxlength);
		curlength=maxlength;
	}

	if (hint_id)
	{
		document.getElementById(hint_id).innerHTML=(maxlength-curlength);
	}
}


// ------------------------------------------------------------------
// MouseOver
// ------------------------------------------------------------------
function tn_lo(obj) 		{if (obj.className!="tn_on") {obj.className="tn";}}
function tn_hi(obj) 		{if (obj.className!="tn_on") {obj.className="tn_hi";}}
function tn_on(a_id)
{
	var a_obj=document.getElementById(a_id);
	if (a_obj) {a_obj.className="tn_on";}
}
function tn_user_lo(obj){tn_lo(obj.parentNode.parentNode.parentNode.parentNode);}
function tn_user_hi(obj){tn_hi(obj.parentNode.parentNode.parentNode.parentNode);}
function sn_lo(obj) 		{obj.parentNode.className="sn";}
function sn_hi(obj) 		{obj.parentNode.className="sn_hi";}
function sn_on(a_id) 	{var a_obj=document.getElementById(a_id); if (a_obj) {a_obj.className="sn_on";}}
function img_lo(obj) 	{obj.src=obj.src.replace(/_(lo|hi|on)\./,"_lo.");}
function img_hi(obj) 	{obj.src=obj.src.replace(/_(lo|hi|on)\./,"_hi.");}

var map_on_img_src=new Array();
var map_lo_timer=null;
function map_lo_go(img_id) 		{document.getElementById(img_id).src=map_on_img_src[img_id];}
function map_lo_no() 				{if (map_lo_timer) {clearTimeout(map_lo_timer); map_lo_timer=null}}
function map_lo(img_id) 			{map_lo_no(); map_lo_timer=setTimeout('map_lo_go("'+img_id+'");',500);}
function map_hi(img_id,img_src)	{map_lo_no(); document.getElementById(img_id).src=img_src;}
function map_on(img_id,img_src) 	{map_lo_no(); document.getElementById(img_id).src=img_src; map_on_img_src[img_id]=img_src;}


// ------------------------------------------------------------------
// General
// ------------------------------------------------------------------

// global params
var my_user_id=0;
var my_register_href="/";

// generische PopUp-Funktion (u.a. für URLs aus dem Linkbuilder)
function popup(u,w,h)
{
	if (!w) {w=475;}
	if (!h) {h=475;}
	window.open(u,"_blank","width="+w+",height="+h+",scrollbars=yes,resizable=yes");
}



// PopUp => Main
// Main  => Blank
function plop(obj)
{
	plop_open(obj.href);
	return false;
}
function plop_open(url)
{
	if (window.name=="main")
	{
		document.location.href=url;
	}
	else if (opener && !opener.closed && opener.name=="main")
	{
		opener.location.href=url;
		opener.focus();
	}
	else
	{
		var win=window.open(url,"_blank");
		win.focus();
	}
}



// ------------------------------------------------------------------
// Allgmeines Image Popup
// ------------------------------------------------------------------
function img_popup(u,w,h)
{
	if (!w) {w=475;}
	if (!h) {h=475;}
	var win=window.open(u,"_blank","width="+(w+0)+",height="+(h+0)+",scrollbars=no,resizable=yes");
	if (win)
	{
		win.document.open();
		win.document.write('<html>');
		win.document.write('<body id="body" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="#000000" text="#ffffff" link="#dd0000" vlink="#dd0000" alink="#dd0000">');
		win.document.write('<table cellspacing="0" cellpadding="0" border="0" width="100%" height="100%"><tr><td align="center" valign="middle">');
		win.document.write('<a href="javascript:window.close();"><img src="'+u+'" width="'+w+'" height="'+h+'" alt="" border="0" /></a>');
		win.document.write('</td></tr></table>');
		win.document.write('</body>');
		win.document.write('</html>');
		win.document.close();
	}
}



// ------------------------------------------------------------------
// Allgmeine Upload Preview
// ------------------------------------------------------------------
function preview_upload(obj)
{
	if (!obj || !obj.name) {return;}
	var IE=navigator.appName.indexOf("Microsoft Internet Explorer") != -1;
	var base_name=obj.name.substr(0,obj.name.length-7);
	var img_obj=document.getElementById(base_name+"_preview");
	var img_box_obj=document.getElementById(base_name+"_preview_box");	
	var val=obj.value;

	if (IE && img_obj)
	{
		if (obj.value)
		{
			img_obj.src="file://"+obj.value;
			if (img_box_obj) {img_box_obj.style.display="block";}
		}
		else
		{
			img_obj.src="/img/_.gif";
			if (img_box_obj) {img_box_obj.style.display="none";}
		}
	}

	var ele=obj.form.elements;	
	if (!ele) {return;}
	for (var a=0; a<ele.length; a++)
	{
		if (ele[a].name!=base_name+"_modify") {continue;}
		else if (val && ele[a].value==3) {ele[a].checked=true; break;}
		else if (!val && ele[a].value==1) {ele[a].checked=true; break;}
	}
}




function rot13(txt)
{
	var enc='';
	var chr='';
	var ord=0;
	var abc="ElPauLoxkWOmTnHdVehijRSpIDqQrZtgXvMwNyzBfCFsGbJKcAUY";
	for (var a=0; a<txt.length; a++)
	{
		chr = txt.substr(a,1);
		ord = chr.charCodeAt(0);
		if (ord<65 || (ord>90 && ord<97) || ord>122) {enc+=chr;}
		else
		{     
          for(i=0; i<abc.length; i++)
          {
          	if (txt.substr(a,1) != abc.substr(i,1)) {continue;}
				enc	+=	i<13 ? abc.substr((i+13)%abc.length, 1)
						:	i>12&&i<26 ? abc.substr((i+39)%abc.length, 1) 
						:	i>25&&i<39 ? abc.substr((i+65)%abc.length,1) 
						:	abc.substr((i+91)%abc.length, 1);
          }
      }
  }
  return enc;
}

function download_select(obj)
{
	var val=obj.options[obj.selectedIndex].value;
	if (val)
	{
		window.open(val,"_blank");
	}
}
