

layerdata	= null;


function addRegisterLayer( type, fromFrame, id ){

	if( fromFrame != false ){
		fromFrame	= true;
	}

	if( id == 'undefined' ){
		id = 0;
	}

	var syncRequest	= new Request({
		url:'/js/ajax/registerLayer.php',
		onSuccess:function(response){
		layerdata	= JSON.decode(response);
		openRegisterLayer(layerdata.title, layerdata.content);

		}
	}).get({'layer':'register','fromFrame':fromFrame,'layerType':type, 'id':id});
}


function openRegisterLayer(title, content){

	var width		= 'auto';
	var height		= 'auto';
	var id			= 'layerStartpage';
	var background	= true;

	addSquareLayer(title,content,id,width,height, background, 'closeRegisterInfoLayer');
	document.getElementById('scr').value=screen.width+"x"+screen.height;
	window.setTimeout(function(){document.frmAnmeldung.spitzname.focus();},100);
	createCloseLayer();
}

function register(){
	
	if( checkValues() == true ){
		document.frmAnmeldung.submit();
	}
}

function checkValues(){
	if(document.frmAnmeldung.spitzname.value==""){
		document.frmAnmeldung.spitzname.focus();
		return false;
	}
	if(document.frmAnmeldung.kennwort.value==""){
		document.frmAnmeldung.kennwort.focus();
		return false;
	}
	if(document.frmAnmeldung.kennwort2.value==""){
		document.frmAnmeldung.kennwort2.focus();
		return false;
	}
	if(document.frmAnmeldung.email.value==""){
		document.frmAnmeldung.email.focus();
		return false;
	}
	if(document.frmAnmeldung.erfVon.value==0){
	showInfoLayer(document.getElementById('erfVon'),7);
		return false;
	}
	return true;
}

function checkLayerKey( event ){
	if(event.keyCode==13){
		register();
	}
}



function changeNickname( obj ){
	document.getElementById('spitzname').value					= obj.id;
	document.getElementById('nicknameMessage').innerHTML		= '';
	document.getElementById('nicknameMessage').style.display	= 'none';
}



function checkNickname( input ){

	var syncRequest	= new Request({
		url:'/js/ajax/register.php',
		onSuccess:function(response){

			var data		= JSON.decode(response);
			var cssClass		= (data.error !=0 )?'messageError':'messageOk';
			var innerHTML	= '<div class="'+cssClass+'">';

			innerHTML	+= '<span>'+data.errorMessage+'</span></div>';

			if( data.error == 7 || data.error == 8 ){

				for( var i=0; i<data.otherNicknames.length ; i++ ){
					innerHTML	+= '<div class="otherNicknameContainer"><span><input id="'+data.otherNicknames[i]+'" class="otherNicknames" type="radio" value="'+data.otherNicknames[i]+'" name="suggest" onclick="changeNickname(this);" /><label for="'+data.otherNicknames[i]+'">'+data.otherNicknames[i]+'</label></span></div>'
				}

			}

			document.getElementById('nicknameMessage').innerHTML		= innerHTML;
			document.getElementById('nicknameMessage').style.display	= 'block';

		}
	}).get({'check':'nickname', 'nickname':input.value});
}


function checkPassword( passwordInput, nicknameId, repeatPasswordId ){

	var	nickname	= (document.getElementById(nicknameId) && document.getElementById(nicknameId).value)?document.getElementById(nicknameId).value:null;

	if( passwordInput.value != "" ){
		var syncRequest	= new Request({
			url:'/js/ajax/register.php',
			onSuccess:function(response){

				var data		= JSON.decode(response);
				var cssClass		= (data.error !=0 )?'messageError':'messageOk';
				var innerHTML	= '<div class="'+cssClass+'">';

				if( data.error != 0 ){
					innerHTML	+= '<span>'+data.errorMessage+'</span>';
				}else{
					innerHTML	+= '<span>'+data.pointMessage+'</span>';
				}


				innerHTML	+= '</div>';
				document.getElementById('passwordMessage').style.display	= 'block';
				document.getElementById('passwordMessage').innerHTML		= innerHTML;


				document.getElementById('repeatPasswordMessage').innerHTML		= "";
				document.getElementById('repeatPasswordMessage').style.display	= 'none';
				document.getElementById(repeatPasswordId).value				= "";

			}
		}).get({'check':'password', 'password':passwordInput.value, 'nickname':nickname});
	}else{
		document.getElementById('passwordMessage').innerHTML		= "";
		document.getElementById('passwordMessage').style.display	= 'none';
	}
}


function checkRepeatPassword( passwordRepeatInput, passwordInputId ){

	var passwordInput	= document.getElementById(passwordInputId);

	if( passwordInput.value != "" ){
		if( passwordRepeatInput.value != passwordInput.value ){
			document.getElementById('repeatPasswordMessage').innerHTML	= '<div class="messageError">'+layerdata.language.repeatPasswordFalse+'</div>';
			document.getElementById('repeatPasswordMessage').style.display	= 'block';
			passwordRepeatInput.value	= "";
			passwordInput.value			= "";
			document.frmAnmeldung.kennwort.focus();
			document.getElementById('passwordMessage').innerHTML		= "";
			document.getElementById('passwordMessage').style.display	= 'none';
			window.setTimeout(function(){
				document.getElementById('repeatPasswordMessage').innerHTML		= "";
				document.getElementById('repeatPasswordMessage').style.display	= 'none';
			},2000);
		}else{
			document.getElementById('repeatPasswordMessage').innerHTML		= '<div class="messageOk">'+layerdata.language.repeatPasswordOk+'</div>';
			document.getElementById('repeatPasswordMessage').style.display	= 'block';
		}
	}else{
		document.getElementById('repeatPasswordMessage').innerHTML		= "";
		document.getElementById('repeatPasswordMessage').style.display	= 'none';
	}

}










function checkEmailAdress( emailInput ){

	var syncRequest	= new Request({
		url:'/js/ajax/register.php',
		onSuccess:function(response){

			var data		= JSON.decode(response);
			if(data.error !=0 ){
				var innerHTML	= '<div class="messageError">';
			}else{
				var innerHTML	= '<div>';
			}

			if( data.error != 0 ){
				innerHTML	+= '<span>'+data.errorMessage+'</span>';
			}


			innerHTML	+= '</div>';

			if( data.error == 0 ){
				innerHTML	= "";
			}

			document.getElementById('eMailMessage').innerHTML	= innerHTML;

		}
	}).get({'check':'email', 'email':emailInput.value});

}


function createCloseLayer(){
	document.getElementById('spitzname').onfocus=closeRegisterInfoLayer;
	document.getElementById('kennwort').onfocus=closeRegisterInfoLayer;
	document.getElementById('kennwort2').onfocus=closeRegisterInfoLayer;
	document.getElementById('email').onfocus=closeRegisterInfoLayer;
}


var activeInfoTaglayerTs = 0;

function showInfoLayer(layerObj,layerNr){
	
	if(!document.getElementById('anmInfoLayerBox')){

		var anmInfoLayerBox = document.createElement('div');
		anmInfoLayerBox.className = "anmInfoLayerBox";
		anmInfoLayerBox.id = "anmInfoLayerBox";

		var anmInfoLayerBoxTop = document.createElement('div');
		anmInfoLayerBoxTop.className = "anmInfoLayerBoxTop";

		var anmInfoLayerBoxMiddle = document.createElement('div');
		anmInfoLayerBoxMiddle.className = "anmInfoLayerBoxMiddle";

		var anmInfoLayerCloseBox1 = document.createElement('div');
		anmInfoLayerCloseBox1.className = "anmInfoLayerCloseBox1";

		var anmInfoLayerCloseBox2 = document.createElement('div');
		anmInfoLayerCloseBox2.className = "anmInfoLayerCloseBox2";

		var anmInfoLayerHeadlineSpan = document.createElement('span');
		var anmInfoLayerHeadline	= document.createTextNode(layerdata.language.registerHelp);

		var anmInfoLayerCloseHref = document.createElement('a');
		anmInfoLayerCloseHref.onclick = closeRegisterInfoLayer;

		var closeImg = document.createElement('img');
		closeImg.src="/css/bk/infoLayer/close.gif";

		var anmInfoLayerContentBox = document.createElement("div");
		anmInfoLayerContentBox.id = "anmInfoLayerContentBox";
		anmInfoLayerContentBox.className = "anmInfoLayerContentBox";
				
		anmInfoLayerCloseHref.appendChild(closeImg);
		anmInfoLayerCloseBox2.appendChild(anmInfoLayerCloseHref);
		anmInfoLayerHeadlineSpan.appendChild(anmInfoLayerHeadline);
		anmInfoLayerCloseBox1.appendChild(anmInfoLayerHeadlineSpan);
		anmInfoLayerBoxMiddle.appendChild(anmInfoLayerCloseBox1);
		anmInfoLayerBoxMiddle.appendChild(anmInfoLayerCloseBox2);
		anmInfoLayerBoxMiddle.appendChild(anmInfoLayerContentBox);

		var anmInfoLayerBoxBottom = document.createElement('div');
		anmInfoLayerBoxBottom.className = "anmInfoLayerBoxBottom";
		
		anmInfoLayerBox.appendChild(anmInfoLayerBoxTop);
		anmInfoLayerBox.appendChild(anmInfoLayerBoxMiddle);
		anmInfoLayerBox.appendChild(anmInfoLayerBoxBottom);
		document.body.appendChild(anmInfoLayerBox);
		
	}else{
		var anmInfoLayerBox = document.getElementById('anmInfoLayerBox');
		try{anmInfoLayerBox.style.visibility	= "visible";}catch(e){}
		anmInfoLayerBox.style.display			= "block";
		var anmInfoLayerContentBox = document.getElementById('anmInfoLayerContentBox');
	}

	anmInfoLayerContentBox.innerHTML = "";

	if(layerNr==1){
		anmInfoLayerContentBox.innerHTML = '<div>'+layerdata.language.selectNickname+'</div>';
	}
	if(layerNr==2){
		anmInfoLayerContentBox.innerHTML = '<div>'+layerdata.language.passwordRule+'</div>';
	}
	if(layerNr==3){
		anmInfoLayerContentBox.innerHTML = '<div>'+layerdata.language.emailRule+'</div>';
	}

	if(layerNr==4){
		anmInfoLayerContentBox.innerHTML = '<div>'+layerdata.language.friendKey+'</div>';
	}
	if(layerNr==5){
		anmInfoLayerContentBox.innerHTML = '<div>'+layerdata.language.couponCode+'</div>';
	}
	if(layerNr==6){
		anmInfoLayerContentBox.innerHTML = '<div>'+layerdata.language.friendNickname+'</div>';
	}
	if(layerNr==7){
		anmInfoLayerContentBox.innerHTML = '<div>'+layerdata.language.experience+'</div>';
	}

	var dim_anmInfoLayerBox	= getDimension("anmInfoLayerBox");
	var pos_layerObj		= getPosition(layerObj.id);
	var dim_layerObj		= getDimension(layerObj.id);

	anmInfoLayerBox.style.top	= 	(pos_layerObj.top + dim_layerObj.height+5)+"px";
	anmInfoLayerBox.style.left	= 	(pos_layerObj.left-dim_layerObj.width+dim_layerObj.width)+"px";

	var tsNow = new Date();
	activeInfoTaglayerTs = tsNow.getTime();

	if( layerNr != 8 ){
		closeTimer(activeInfoTaglayerTs,10);
	}

}

function closeTimer(activeInfoTaglayerTsInstanz,seconds){
	if(seconds>0){
		seconds = seconds-1;
		window.setTimeout(function(){closeTimer(activeInfoTaglayerTsInstanz,seconds);},1000);
		return false;
	}
	if(activeInfoTaglayerTs == activeInfoTaglayerTsInstanz){
		closeRegisterInfoLayer();
		return true;
	}
}

function closeRegisterInfoLayer(){
	try{
		if( document.getElementById("anmInfoLayerBox") && document.getElementById("anmInfoLayerBox").style.display != 'none' ){
			var anmInfoLayerBox	= document.getElementById("anmInfoLayerBox");
			anmInfoLayerBox.style.display		= "none";
			anmInfoLayerBox.style.visibility	= "none";
		}
	}catch(e){}
}



function closeLayer(event){
	if(!event){
		event=window.event;
	}
	if(event.keyCode==27){
		if( document.getElementById("anmInfoLayerBox") != null && document.getElementById("anmInfoLayerBox").style.display != 'none' ){
			var anmInfoLayerBox	= document.getElementById("anmInfoLayerBox");
			anmInfoLayerBox.style.display		= "none";
			try{anmInfoLayerBox.style.visibility	= "none";}catch(e){}
		}else{
			closeSquareLayer('layerStartpage');
		}
	}
}


document.onkeydown=closeLayer;



function changeErfVon(was){

	if(was==4){

		document.getElementById('friendContainer').style.display='block';
		document.getElementById('couponContainer').style.display='none';
		document.getElementById('friendshipKeyContainer').style.display='none';
		showInfoLayer(document.getElementById('gewVonN'),6);

		document.getElementById('gutschein').value='';
		document.getElementById('friendshipKey').value='';
		document.getElementById('gewVonN').value='';

	}else if(was==11){

	 	document.getElementById('friendshipKeyContainer').style.display='block';
		document.getElementById('couponContainer').style.display='none';
		document.getElementById('friendContainer').style.display='none';
		showInfoLayer(document.getElementById('friendshipKey'),4);

		document.getElementById('gutschein').value='';
		document.getElementById('friendshipKey').value='';
		document.getElementById('gewVonN').value='';

	}else if(was==7){

		document.getElementById('friendContainer').style.display='none';
		document.getElementById('friendshipKeyContainer').style.display='none';
		document.getElementById('couponContainer').style.display='block';
		showInfoLayer(document.getElementById('gutschein'),5);

		document.getElementById('gutschein').value='';
		document.getElementById('friendshipKey').value='';
		document.getElementById('gewVonN').value='';

	}else{

		document.getElementById('friendContainer').style.display='none';
		document.getElementById('friendshipKeyContainer').style.display='none';
		document.getElementById('couponContainer').style.display='none';

		document.getElementById('gutschein').value='';
		document.getElementById('friendshipKey').value='';
		document.getElementById('gewVonN').value='';
		closeRegisterInfoLayer();
	}

}