function closeDisplay(){
	new Effect.Fade('display', {duration:.5});
	$('deactivate').style.display = "none";
}
function showDisplay(){
	new Effect.Appear('display', {duration:.5});
	deactivateAll();
}
function initDisplay(){
	$('display').onclick = closeDisplay;
	$('deactivate').onclick = closeDisplay;
}

function clearLoginForm(){
	if($('u_name').value=="Benutzername"){
		$('u_name').value="";
		$('u_pass').value="";
	}
}

function forgotPswd(){
	$('loginForm').action = "/modules/forgot_pswd.php";
	$('loginForm').submit();
}

function showWSDetail(_elem){
	if($(_elem).style.display=="none"){
		new Effect.BlindDown(_elem, {duration:.5})
	}else{
		new Effect.BlindUp(_elem, {duration:.5})
	}
}

function showAwl(q,id, p){
	var profi = false;
	if(!arguments[3]) swapAwl(q+"_"+id)
	if(arguments[4]===true) profi = true;

	var url = '/awl/get_awl.php';
	$('awl_wait_'+q+"_"+id).style.display = "block";
	var quickEditReq = new Ajax.Request(url, {method:'post', parameters:"q="+q+"&p="+p+"&id="+id+"&profi="+profi, 
			onComplete:function(elem){
				var jsString = elem.responseText;
				var _cnt = jsString.split("#####");
				var _swap = $('awl_box_swap_'+q+"_"+id);
				$('awl_box_head_'+q+"_"+id).innerHTML = _cnt[0];
				_swap.innerHTML = _cnt[1];
				
				$('awl_wait_'+q+"_"+id).style.display = "none";
				
				//new Effect.SlideUp(_swap);
				/*$('awl_box_cnt_'+id).innerHTML = jsString;
				$('awl_wait_'+id).style.display = "none";
				//new Effect.SlideUp(_e);
				
				new Effect.SlideUp(_swap);
				//alert(_swap.className)*/
			}
	});

}

function swapAwl(_id){
if(document.swap_awl == "false") return true;

	//new Effect.SlideDown("awl_box_swap_"+_id, {duration:.5})
	var _elem = document.getElementsByClassName("awl_box_swap");
	for(var a = 0; a<_elem.length; a++){
		_e = _elem[a];
		var id = _e.getAttribute("id").replace("awl_box_swap_", "");
		if(id!=_id){
			$('awl_wait_'+id).className = "awl_wait small"
			if(_e.className !="awl_box_swap deact") new Effect.BlindUp(_e, {duration:.5})
			_e.className ="awl_box_swap deact";
		}else{
			var _wait = $('awl_wait_'+id)		
			if(_e.className !="awl_box_swap act") new Effect.BlindDown(_e, {duration:.5, afterFinishInternal:function(){_wait.className = "awl_wait"}})
			_e.className ="awl_box_swap act";
			_anchor = id;
		}		
	}
	
	//$('awl_box_'+_id).className = "awl_box";	
}

function swapGrp(_id){

	document.swap_awl = "false";
	var _elem = document.getElementsByClassName("grp_swap");
	for(var a = 0; a<_elem.length; a++){
		_e = _elem[a];
		var id = _e.getAttribute("id").replace("grp_swap_", "");
		if(id!=_id){
			if(_e.className !="grp_swap deact") new Effect.BlindUp(_e, {duration:.5})
			_e.className ="grp_swap deact";
			
			$('grp_head_'+id).className ="icn_yellow deact";
		}else{	
			if(_e.className !="grp_swap act") new Effect.BlindDown(_e, {duration:.5})
			_e.className ="grp_swap act";
				$('grp_head_'+id).className ="icn_yellow act";
		}		
	}



}



function swapAwlAll(){
	var _elem = document.getElementsByClassName("awl_box_swap");
	for(var a = 0; a<_elem.length; a++){
	_e = _elem[a];
		var id = _e.getAttribute("id").replace("awl_box_swap_", "");
		new Effect.BlindDown(_e, {duration:0})
		_e.className ="awl_box_swap act";
	}
}

function sendFAQ(){
	$("faq_wait").style.display = "block";
	var url = "/modules/ajax/sendFAQ.php";
	var param = Form.serialize("quest");
	var quickEditReq = new Ajax.Request(url, {method:'post', parameters:param, 
			onComplete:function(elem){
				$("faq_wait").style.display = "none";
				var jsString = elem.responseText;
				//jsString = jsString.replace("#", "'");
				var can_parse = jsString.match(/^\[.*\]$/);
				if(can_parse){
					var resp_array = eval(jsString);
					if(resp_array[0]!="fail"){
						_class = "";
						$("faqForm").innerHTML = resp_array[1];
						new Effect.Highlight("faqForm")
					}else{
						_class = "fail";
					}
					$('question_msg').className ="";
						$('mail_msg').className ="";
					for(a=1; a<resp_array.length; a++){
							var el = $(resp_array[a]+"_msg");
							if(el) el.className = _class;
						}
				}else{	
					alert("Ubekannter Fehler");	
				}
				
			}
	});
}	


function calculateSeminarPrice(price_1, price_2){
	var _e = $('users')
	var _res = $('calc_price');
	var _nums = _e.value;
	_result = _nums*price_1;
	if(price_2) _result = (_nums-1)*price_2+price_1;
	_res.innerHTML = _result;
	$('more_users_field').style.display = _nums>1 ? "block" : "none"
}


function openCart(_elem){
	deactivateAll();
	var w = arguments[1];
	var h = arguments[2];
	_big_map = $(_elem);
	_big_map.style.marginLeft="0px"; 
	_big_map.style.marginTop="0px";	
	var pagesize = getPageSize();
	var arrayPageScroll = getPageScrollTop();
	_big_map.style.width=w+"px";
	_big_map.style.height=h+"px";
	_big_map.style.display = "block",
	_big_map.style.left = ((pagesize[0] - 100)/2)-(w/2)+"px";
	_big_map.style.top = (arrayPageScroll[1] + ((pagesize[1]-100)/2))-(h/2)+"px";
	$("deactivate").onclick = function(){ closePopup(); }
	$(_big_map).onclick = function(){ closePopup(); }
}

function deactivateAll(){
	var deact_all = $("deactivate");
	if (window.innerHeight && window.scrollMaxY) {	
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		yScroll = document.body.offsetHeight;
  	}
	deact_all.style.height = yScroll +"px";
	deact_all.style.display = "block";
	
}

function closePopup(){
	
	$('deactivate').style.display = "none";
	$('edit_popup').style.display ="none";
	$('edit_popup_content').innerHTML = "";
}

function getPageScrollTop(){
	var yScrolltop;
	if (self.pageYOffset) {
		yScrolltop = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScrolltop = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScrolltop = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScrolltop) 
	return arrayPageScroll;
}

function getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	
	arrayPageSize = new Array(w,h) 
	return arrayPageSize;
}

function openPopup(_url, _w, _h){
	deactivateAll();
	
	$('edit_popup').style.display ="block";

	var quickEditReq = new Ajax.Request(_url, {method:'post', parameters:"", 
			onComplete:function(elem){
				_resp = elem.responseText;
				$('edit_popup_content').innerHTML = _resp;
			}
	});
}



function changeUsername(){
	var url = "/modules/change_username_form.php";
	openPopup(url, 410, 400);
}

function changePassword(){

	var url = "/modules/change_password_form.php";
	openPopup(url, 410, 420);
}

function saveChangePassword(){
	var _param = Form.serialize("c_pswd");
	var _url = "/modules/change_password.php";
	$('l_o_pswd').className = "";
	$('l_n_pswd').className = "";
	$('l_r_pswd').className = "";
	var quickEditReq = new Ajax.Request(_url, {method:'post', parameters:_param, 
			onComplete:function(elem){
				_resp = elem.responseText;

				switch(_resp){
					case "1":
						alert("Ihr neues Passwort wurde übernommen")
						closePopup();
					break;
					case "2":
						$('l_o_pswd').className = "error";
					break;
					case "3":
						$('l_n_pswd').className = "error";
					break;
					case "4":
						$('l_r_pswd').className = "error";
					break;
					default:
					alert("UNBEKANNTER FEHLER:\n"+_resp);
					break;
				}
			}
	});
}

function saveChangeUsername(){
	$('l_o_uname').className = "";
	$('l_n_uname').className = "";
	$('l_o_pswd').className = "";
	var _param = Form.serialize("c_uname");
	var _url = "/modules/change_username.php";
	var quickEditReq = new Ajax.Request(_url, {method:'post', parameters:_param, 
			onComplete:function(elem){
				_resp = elem.responseText;
				
				switch(_resp){
					case "1":
						alert("Ihr neuer Benutzername wurde übernommen");
						closePopup();
					break;
					case "2":
						$('l_o_uname').className = "error";
					break;
					case "3":
						$('l_n_uname').className = "error";
					break;
					case "4":
						$('l_o_pswd').className = "error";
					break;
					case "5":
						alert("Der Benutzername "+$('n_uname').value+" ist bereits vergeben");
						$('l_n_uname').className = "error";
					break;
					default:
					alert("UNBEKANNTER FEHLER:\n"+_resp);
					break;
				}
			}
	});
}

