document.write('<script type="text/javascript" src="/js/prototype.js?v=1"></script>');
document.write('<script type="text/javascript" src="/js/scriptaculous.js?load=builder,effects,dragdrop,slider,controls"></script>');


//////////////////////MAIN####################
function AppearEffect(element){
       new Effect.toggle(element, 'Appear', {duration:1.5});
   }
function Confirm(message){
	var test = confirm(message);
	if (test) {return true;}
	else {return false;}
}
function jumpNextField(el,el2){
	
	if($(el).value.length ==4){
		$(el2).focus();						   
	}
}
 function DisableButton(b)
   {
      b.disabled = true;
      b.value = 'Daten werden gesendet';
      b.form.submit();
   }
function checkEmail(id1,id2,retype) {
	
	var d1pastval = new String();
	var d2pastval = new String();
	if(document.getElementById(id1).value != document.getElementById(id2).value){
		document.getElementById(retype).style.display='block';
		}
	else{
		document.getElementById(retype).style.display='none';
		}
}
function check12month(el,div){
	var t = $('tag'+el).value;
	var m = $('monat'+el).value;
	var y = $('jahr'+el).value;	
	if(t!='' && m!='' && y!=''){	
		m = parseInt(m)-1;
		y = parseInt(y)+1;
		t = parseInt(t)+1;
		var today = new Date();
		var birth=new Date(y, m, t)
		
			if (today>=birth){
				$(div).style.display='none';
				}
			else{
				$(div).style.display='block';
				}	
		}
		else{
			$(div).style.display='none';
		}
}

//beim verlaengern: ist das Kind noch keine 17 Jahre und 10 Monate alt?
function check17years(){
	$('myXsubmit').style.display='none';
	$('myXError').style.display='none';
	$('myXFail').style.display='none';
	var t = $('tag_1_kinderX').value;
	var m = $('monat_1_kinderX').value;
	var y = $('jahr_1_kinderX').value;	
	if(t!='' && m!='' && y!=''){	
		m = parseInt(m);
		y = parseInt(y);
		t = parseInt(t);

		var today = new Date();
			
		//er ist juenger als 17
		if(today.getFullYear()-18 < y){
			$('myXsubmit').style.display='block';
			}
		
		//er ist 17 --> getMonth() geht von 0-11
		if(today.getFullYear()-18 == y){
			
			if(today.getMonth() +2 < m){ 
				$('myXsubmit').style.display='block';
			}
			else if(today.getMonth()+1 == m || today.getMonth()+2 == m){ 
				$('myXError').style.display='block';
			}
			else if(today.getMonth()+1 > m ){ 
				$('myXFail').style.display='block';
			}
			
		}
		//er ist 18	
		if(today.getFullYear()-18 > y){	
			$('myXFail').style.display='block';
		}
		
	}
}
//verlaengern der Karte
function extendMyCard(id){
	
	var params = Form.serialize($('Ablaufs'));
	Element.update('Ablaufs','<img src="../img/ajax-loader.gif" />');
	$('KarteNotValidTextText').style.display='none';
	new Ajax.Request('frontend/ajaxfunc.cfm?extendMyCard='+id,{asynchronous:true,parameters:params,
					 onSuccess: function(response){
					var response = response.responseText
						Element.update('Ablaufs',response);
						$('KarteNotValid').style.borderColor ='#5AD75C';
						$('KarteNotValid').style.backgroundColor ='#F0FBF0';
						$('KarteNotValidH3').style.display='none';
					},
				onFailure: function(){alert('Ein Fehler ist aufgetreten...')}});
	
}
function extendMyCardbackend(id){
	
}

//zaehle wieviele klicks ein sponsor bekommt
function klickSponsor(id){
	var url = 'frontend/ajaxfunc.cfm?klickSponsor='+id;
	var myAjax = new Ajax.Request(
		url, 
			{method: 'POST', 
			evalScripts: true,

				onSuccess: function(response){
					var response = response.responseText
					},
				onFailure: function(){alert('Ein Fehler ist aufgetreten...'+response)}
			});
	}
////////////////////////Backend Sponsor
function showSponsorForm(id,divname){
	Element.update(divname,'<img src="../img/ajax-loader.gif" />');
	var url = 'http://cms.hessen-agentur.de/HA_custom/familienkarte/backendfunction.cfm?getform='+id;
	var myAjax = new Ajax.Request(
		url, 
			{method: 'POST', 
			evalScripts: true,

				onSuccess: function(response){
					var response = response.responseText
						Element.update(divname,response);
						new Effect.Appear(divname);
						
					},
				onFailure: function(){alert('Ein Fehler ist aufgetreten...'+response)}
			});
	}
	

function deleteSponsor(id){
	var url = 'http://cms.hessen-agentur.de/HA_custom/familienkarte/backendfunction.cfm?delete='+id;
	var myAjax = new Ajax.Request(
		url, 
			{method: 'POST', 
				onSuccess: function(response){
						$('tr'+id).style.display='none';
					},
				onFailure: function(){alert('Ein Fehler ist aufgetreten...'+response)}
			});
	}
	


function deleteSponsorlogin(id){
	var url = 'http://cms.hessen-agentur.de/HA_custom/familienkarte/backendfunction.cfm?deletepartnerlogin='+id;
	var myAjax = new Ajax.Request(
		url, 
			{method: 'POST', 
				onSuccess: function(response){
						$('tr'+id).style.display='none';
					},
				onFailure: function(){alert('Ein Fehler ist aufgetreten...'+response)}
			});
	}
	
function deletesponsorbild(id){
	var url = 'http://cms.hessen-agentur.de/HA_custom/familienkarte/backendfunction.cfm?deletesponsorbild='+id;
	var myAjax = new Ajax.Request(
		url, 
			{method: 'POST', 
				onSuccess: function(response){
						
						//Element.update('fileuploadsecondchancediv','');
						Element.update('produktbilddelete','<input type="file" name="logo" class="file" />');
					},
				onFailure: function(){alert('Ein Fehler ist aufgetreten...'+response)}
			});
	}
	
	function deletesponsordatei(id,num){
	var url = 'http://cms.hessen-agentur.de/HA_custom/familienkarte/backendfunction.cfm?deletesponsordatei='+id+'&num='+num;
	var myAjax = new Ajax.Request(
		url, 
			{method: 'POST', 
				onSuccess: function(response){
						
						//Element.update('fileuploadsecondchancediv','');
						
							Element.update('produktdateidelete'+num,'<input type="file" name="datei" class="file" />');
						
					},
				onFailure: function(){alert('Ein Fehler ist aufgetreten...'+response)}
			});
	}
////////////////////////Backend Benutzer
function searchBenutzer(name){
	Element.update('newBenutzer','<img src="../img/ajax-loader.gif" />');
	var params = Form.serialize($(name));
	new Ajax.Request(
		'http://cms.hessen-agentur.de/HA_custom/familienkarte/backendfunction.cfm?searchBenutzer=1',
			{
			method: "POST",
			asynchronous:true,
			 parameters:params,
			
			 onComplete:function(response){
							var response = response.responseText
							Element.update('newBenutzer',response);
							}
			}
		); 

}

function showBenutzerForm(id,divname){
	Element.update(divname,'<img src="../img/ajax-loader.gif" />');
	var url = 'http://cms.hessen-agentur.de/HA_custom/familienkarte/backendfunction.cfm?showBenutzerForm='+id;
	var myAjax = new Ajax.Request(
		url, 
			{method: 'POST', 
				onSuccess: function(response){
					var response = response.responseText
						Element.update(divname,response);
						new Effect.Appear(divname);
						
					},
				onFailure: function(){alert('Ein Fehler ist aufgetreten...'+response)}
			});
	}
	
function insertBenutzer(name){
	var params = Form.serialize($(name));
	new Ajax.Request('http://cms.hessen-agentur.de/HA_custom/familienkarte/backendfunction.cfm?insertBenutzer=1',{asynchronous:true,parameters:params,
					onSuccess: function(response){
					var response = response.responseText
						Element.update('newBenutzer',response);
						
					},
				onFailure: function(){alert('Ein Fehler ist aufgetreten, bitte ueberpruefen Sie, ob alle benoetigten Daten eingegeben wurden...')}
			});
	
}
function updateBenutzer(name){
	var params = Form.serialize($(name));
	new Ajax.Request('http://cms.hessen-agentur.de/HA_custom/familienkarte/backendfunction.cfm?updateBenutzer=1',{asynchronous:true,parameters:params,
					 onSuccess: function(response){
					var response = response.responseText
						Element.update('newBenutzer',response);
						
					},
				onFailure: function(){alert('Ein Fehler ist aufgetreten...')}});
	
}
function deleteBenutzer(id,divname,bearbeiter){
	var url = 'http://cms.hessen-agentur.de/HA_custom/familienkarte/backendfunction.cfm?deleteBenutzer='+id+'&bearbeiter='+bearbeiter;
	var myAjax = new Ajax.Request(
		url, 
			{method: 'POST', 
				onSuccess: function(response){
						//hier loeschen wenn ein ganzer Datensatz angezeigt wird
						if(divname =='newBenutzer'){
							Element.update(divname,'<div class="info">L&ouml;schen erfolgreich</div>');	
							}
						//hier loeschen wenn ein Datensatz aus Liste gelöscht wird
						else{
							Element.update(divname,'');	
							}
						
					},
				onFailure: function(){alert('Ein Fehler ist aufgetreten...'+response)}
			});
	}

/*
ALT
function extendMyCard(id){
	Element.update('KarteNotValidText','<img src="../img/ajax-loader.gif" />');
	var url = 'frontend/ajaxfunc.cfm?extendMyCard='+id;
	var myAjax = new Ajax.Request(
		url, 
			{method: 'POST', 
				onSuccess: function(response){
							var response = response.responseText
							Element.update('KarteNotValidText',response);	
					},
				onFailure: function(){alert('Ein Fehler ist aufgetreten...'+response)}
			});
	}
	
function extendMyCardbackend(id){
	var url = 'frontend/ajaxfunc.cfm?extendMyCard='+id;
	var myAjax = new Ajax.Request(
		url, 
			{method: 'POST', 
				onSuccess: function(){
							$('KarteNotValid').style.display='none';	
					},
				onFailure: function(){alert('Ein Fehler ist aufgetreten...'+response)}
			});
	}*/


////////////////////////Frontend Sponsor
function searchSponsor(name){
	var params = Form.serialize($(name));
	new Ajax.Request('frontend/ajaxfunc.cfm?searchSponsor=1',{asynchronous:true,parameters:params,
					onSuccess: function(response){
					var response = response.responseText
						Element.update('Ajaxsponsor',response);
						
					},
				onFailure: function(){alert('Ein Fehler ist aufgetreten...')}
			});
	
}
function doThePaging(start,searchX,plz,range,cid,alle,und){
	new Ajax.Request('frontend/ajaxfunc.cfm?searchSponsor=1&search='+searchX+'&plz='+plz+'&range='+range+'&cid='+cid+'&alle='+alle+'&und='+und+'&start='+start,{
					onSuccess: function(response){
					var response = response.responseText
						Element.update('Ajaxsponsor',response);
						
					},
				onFailure: function(){alert('Ein Fehler ist aufgetreten...')}
			});
	}
	
function ShowMouseoverText(e,text){
	$('subupdateDiv').style.display='none';
	var myPos = getXY(e);
	Element.update('subupdateDiv',_utf8_decode(unescape(text)));
	$('subupdateDiv').style.display='block';
	$('subupdateDiv').style.left = parseInt(myPos[0]+50)+ "px";
	$('subupdateDiv').style.top = parseInt(myPos[1])+ "px";
}
function mouseoverweg(){
	$('subupdateDiv').style.display='none';
}
var mousex
var mousey;
function getXY(e) {
	  var posx = 0;
	  var posy = 0;
	  var mousePos = new Array();
	 
	  // Make sure event var is set
	  if (!e) var e = window.event;
	 
	  // Get mouse position; IE & FF Compatibility!
	  if (e.pageX || e.pageY){
			posx = e.pageX;
			posy = e.pageY;
	  }
	  else if (e.clientX || e.clientY){
			posx = e.clientX + document.body.scrollLeft
			  + document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop
			  + document.documentElement.scrollTop;
	  }
	 
	  // posx and posy contain the mouse pos; Return them both
	  mousePos[0] = posx;
	  mousePos[1] = posy;
	 
	  return mousePos;
}

function _utf8_decode(utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
function showNeutralPop(e,text){
	
	var ret='<table  style="VISIBILITY: visible; width: 200px;" cellspacing="0" cellpadding="0" width="200" border="0" zindex="1000"><tbody><tr style="height: 100%" valign="top"><td style="vertical-align: top; height: 100%; border:none; padding:0" align="right" width="20"><table style="height: 100%" cellspacing="0" cellpadding="0" border="0"><tbody><tr><td style="border:none; padding:0; font-size: 1px; padding-top: 8px;" valign="top" align="right"><div style="border-top: black 1px solid; font-size: 1px; left: 1px; width: 15px; POSITION: relative"><div style="overflow: hidden; border-left: black 1px solid; width: 14px; height: 1px; background-color: lemonchiffon"></div><div style="overflow: hidden; border-left: black 1px solid; width: 13px; height: 1px; background-color: lemonchiffon"></div><div style="overflow: hidden; border-left: black 1px solid; width: 12px; height: 1px; background-color: lemonchiffon"></div><div style="overflow: hidden; border-left: black 1px solid; width: 11px; height: 1px; background-color: lemonchiffon"></div><div style="overflow: hidden; border-left: black 1px solid; width: 10px; height: 1px; background-color: lemonchiffon"></div><div style="overflow: hidden; border-left: black 1px solid; width: 9px; height: 1px; background-color: lemonchiffon"></div><div style="overflow: hidden; border-left: black 1px solid; width: 8px; height: 1px; background-color: lemonchiffon"></div><div style="overflow: hidden; border-left: black 1px solid; width: 7px; height: 1px; background-color: lemonchiffon"></div><div style="overflow: hidden; border-left: black 1px solid; width: 6px; height: 1px; background-color: lemonchiffon"></div><div style="overflow: hidden; border-left: black 1px solid; width: 5px; height: 1px; background-color: lemonchiffon"></div><div style="overflow: hidden; border-left: black 1px solid; width: 4px; height: 1px; background-color: lemonchiffon"></div><div style="overflow: hidden; border-left: black 1px solid; width: 3px; height: 1px; background-color: lemonchiffon"></div><div style="overflow: hidden; border-left: black 1px solid; width: 2px; height: 1px; background-color: lemonchiffon"></div><div style="overflow: hidden; border-left: black 1px solid; width: 1px; height: 1px; background-color: lemonchiffon"></div></div></td></tr></tbody></table></td><td style="border:none; padding:0;padding-RIGHT: 5px; border-top: black 1px solid; padding-left: 5px; padding-bottom: 5px; border-left: black 1px solid; padding-top: 5px; border-bottom: black 1px solid; background-color: lemonchiffon" width="20"><img src="img/achtung.gif" alt="Achtung" border="0" /></td><td style="border:none; padding:0;padding-RIGHT: 5px; border-top: black 1px solid; padding-left: 5px; font-size: 10px; padding-bottom: 5px; padding-top: 5px; border-bottom: black 1px solid; font-family: verdana; background-color: lemonchiffon" width="100%"><span style="text-decoration:none;text-align:left;">'+ text +'</span></td><td style="border:none; padding:0;border-RIGHT: black 1px solid; padding-RIGHT: 2px; border-top: black 1px solid; padding-left: 2px; padding-bottom: 2px; vertical-align: top; padding-top: 2px; border-bottom: black 1px solid; background-color: lemonchiffon; text-align: right"><img style="cursor: pointer" src="img/close1.gif" border="none" alt="close" /></td></tr></tbody></table>';
	
	$('subupdateDiv2').style.display='none';
	var myPos = getXY(e);
	Element.update('subupdateDiv2',_utf8_decode(unescape(ret)));
	$('subupdateDiv2').style.display='block';
	$('subupdateDiv2').style.left = parseInt(myPos[0]+50)+ "px";
	$('subupdateDiv2').style.top = parseInt(myPos[1])+ "px";
	
}
function mouseoverweg2(){
	$('subupdateDiv2').style.display='none';
}


function removeSZ(thestring){
	var newstring = '';
	 for (i = 0; i < thestring.length; i++) {
		 	//unescape('%DF') = ß
		 if (thestring.charAt(i) ==unescape('%DF')){
			 newstring= newstring+'ss';
		  }
		  else{
			  newstring = newstring+thestring.charAt(i);
		  }
	 }
	 return newstring;
	 
}
//Textelement für den Mausover im Input
var gesperrt = 0;
var showkartemoustext ='';
function showNameOnKarte(div1,div2,num,area){
	
	//area = erster oder 2. Ansprechpartner
	var theGluedString = $('ErsatzVorname'+area).value + ' ' +$('ErsatzName'+area).value;
	//alert(theGluedString);
	theGluedString = removeSZ(theGluedString).toUpperCase();
	var mylen =theGluedString.length;
	
	//ErsatzName ist das was neben der Karte gezeigt wird
	//Druckvorname ist das hidden field, das übergeben wird
	//showNameOnKarte ist das Feld was auf der Karte angezeigt wird, aber nicht übergeben wird
	//num == 0 kommt aus den Feldern für den richtigen Namen
	//num == 1 kommt aus den Feldern für den ersatz Namen, den man selber editieren kann
	//Achtung Anzeigen	
	// 29 statt 27 zeichen, weil leerzeichen dabei
	if (mylen >= 27 ){
		//Achtung Text erscheint und Kartenbild wechselt
		showAchtungNameZuLang(area);
		//Absendeknopf disablen und Achtung Text schreiben
		$('absenden').disabled = true;
		$('absenden2').style.display = 'block';
		$('absenden').value='Absenden erst nach Korrektur';
		gesperrt =1;
		}
	else{
		$('showkarteAchtung'+area).style.visibility='hidden';
		$('showkarteOuter'+area).style.backgroundImage='url(img/Familienkarte-Hessen_Frontansicht.gif)';
		$('ErsatzVorname'+area).style.border='#ABADB3 1px solid';
		$('ErsatzName'+area).style.border='#ABADB3 1px solid';
		$('Ersatznamen'+area).style.border='none';
		$('absenden').disabled = false;
		$('absenden2').style.display = 'none';
		$('absenden').value='Daten Absenden';
		}
		
		
	//Felder werden aus name1 und vornmame1 gebildet
	if (mylen < 27 && num == 0 && gesperrt==0){
		 //$('showNameOnKarte'+area).value = theGluedString;
		 $('ErsatzVorname'+area).value = $('titel'+area).value +' '+ $('vorname'+area).value;
		 $('ErsatzName'+area).value = $('name'+area).value;
		 $('Druckvorname'+area).value = $('vorname'+area).value;
		 $('Druckname'+area).value = $('name'+area).value;
		
	}
	else if (mylen >= 27 && num == 0){
		//blende die Felder ein
		$('Ersatznamen'+area).style.visibility='visible';
		/*$('ErsatzVorname'+area).value = removeSZ($('vorname'+area).value);
		$('ErsatzName'+area).value = removeSZ($('name'+area).value);
		$('Druckvorname'+area).value = $('vorname'+area).value;
		$('Druckname'+area).value = $('name'+area).value;*/
	}
	else if(mylen <= 27 && num  == 1){
			//$('showNameOnKarte'+area).value = theGluedString;
			$('Druckvorname'+area).value = $('ErsatzVorname'+area).value;
			$('Druckname'+area).value = $('ErsatzName'+area).value;
			
	}
	//Extrafelder sperren, wenn mehr als 27 Zeichen
	
	var extraLen = $('ErsatzName'+area).value.length+$('ErsatzVorname'+area).value.length;
	$('ErsatzName'+area).maxLength= $('ErsatzName'+area).value.length + 27-extraLen;
	$('ErsatzVorname'+area).maxLength= $('ErsatzVorname'+area).value.length + 27-extraLen;
	
	theGluedString = $('ErsatzVorname'+area).value + ' ' +$('ErsatzName'+area).value;
	$('showNameOnKarte'+area).value = removeSZ(theGluedString).toUpperCase();
}

function showAchtungNameZuLang(area){
	$('showkarteAchtung'+area).style.visibility='visible';
	$('showkarteOuter'+area).style.backgroundImage='url(img/Familienkarte-Hessen_Frontansicht_27.gif)';
	$('ErsatzVorname'+area).style.border='solid 1px #922424';
	$('ErsatzName'+area).style.border='solid 1px #922424';
	$('Ersatznamen'+area).style.borderBottom='#922424 1px solid';
	$('Ersatznamen'+area).style.borderLeft='#922424 1px solid';
	$('Ersatznamen'+area).style.borderRight='#922424 1px solid';
	
	
	}
function getPageSize () {
	        
	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
	}
