var ignor="";

function TestEmail(email)
{
  var MatchEmailPattern = 
			"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
     + "((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
     + "([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
     + "([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$";

	var validRegExp = /^[a-zA-Z]+([_\.-]?[a-zA-Z0-9]+)*@[a-zA-Z0-9]+([\.-]?[a-zA-Z0-9]+)*(\.[a-zA-Z]{2,4})+$/; 
	 
	if (email != null && email.search(validRegExp) !=-1) {
		return true;
	} else {
		return false;
  	}
}

function isValidDate(date) {
  var regex = /^([0-3]\d|[1-9])\.([0-3]\d|[1-9])\.(\d{4}|\d{2})$/g;
  if(!regex.exec(date)) {
     return false;
  }
  tmp = new Date(RegExp.$3,RegExp.$2,0);
  if(tmp.getDate() < RegExp.$1 || RegExp.$2 > 12 || (RegExp.$3>99 && RegExp.$3 < 1900))
     return false;
  return true;
}

function isInt(a) {
 if (a.value) {
 	var zahl = "" + (a.value * 1);
 } else {
 	var zahl = "" + (a * 1);
 }
 if (zahl) {
 	if (parseInt(zahl) == parseFloat(zahl)) {
	 	return true;
	} else {
	 	return false;
	}
 }
 return false;
}

function checkPreForm(field){
		var fields = field.split(",");
		var returnvalue = true;
		var anzzi = 0;
		var anzez = 0;
		var anzdz = 0;
		var mz = true;
		var color="#CA0018";
		var colorok="#A3A3A3";
		for (var i=0;i<fields.length;i++){
			if (ignor.indexOf(fields[i])<0){
				var field = document.getElementById(fields[i]);
				if (field) {
					if (field.type=="text" || field.type=="textarea"){
						if (field.value=="" || field.value=="01.mm.jjjj" || field.value=="tt.mm.jjjj"){
							field.style.borderWidth="2px";
							field.style.borderColor=color;
							returnvalue = false;
						} else if ((fields[i]=="email" || fields[i]=="weiter_sendto" || fields[i]=="weiter_sendfrom") && field.value.indexOf("@")<0){
							field.style.borderWidth="2px";
							field.style.borderColor=color;
							returnvalue = false;
						// } else if ((fields[i].indexOf('gebdatum')>-1) && (field.value.length != 10)) { 
						} else if (fields[i].indexOf('gebdatum')>-1) {
							var arr = field.value.split('.');
						  	if (arr[0] <= 31 && arr[1] <= 12 && arr[2] >= 1900) {
						  		//	alert('Alles klar!');
							  	field.style.borderWidth="1px";
								field.style.borderColor=colorok;
						  	} else {
						  		//	alert('Datum ung&#252;ltig!');

								field.style.borderWidth="2px";
								field.style.borderColor=color;
								// field.value="TT.MM.JJJJ";	
								returnvalue = false;							  
						  	}

						
						} else {
							field.style.borderWidth="1px";
							field.style.borderColor=colorok;
						}
					} else if (field.type=="radio"){
						var schleife = false;
						field=document.getElementsByName(fields[i]);
						for (var j=0; j<field.length; j++) {
							if (field[j].checked) {
								schleife=true;
								if (fields[i].indexOf('versichertja')>-1){
									if (document.getElementById('vnr'+fields[i].substr(fields[i].length-1)).value==""){
									document.getElementById('vnr'+fields[i].substr(fields[i].length-1)).style.borderWidth="2px";
									document.getElementById('vnr'+fields[i].substr(fields[i].length-1)).style.borderColor=color;
									returnvalue = false;
									} else {
									schleife=true;
									document.getElementById('vnr'+fields[i].substr(fields[i].length-1)).style.borderWidth="1px";
									document.getElementById('vnr'+fields[i].substr(fields[i].length-1)).style.borderColor=colorok;
									}
								}
							}
						}
						if (fields[i].indexOf('versichertja')>-1){
							schleife=true;
						}
						if (schleife==false){
							for (var j=0; j<field.length; j++) {
								field[j].style.borderWidth="2px";
								field[j].style.borderColor=color;
							}
							returnvalue = false;
						} else {
							for (var j=0; j<field.length; j++) {
								field[j].style.borderWidth="0px";
								field[j].style.borderColor=colorok;
							}
						}
						
					} else if (field.type=="select-one"){
						if (field.selectedIndex==0){
							field.style.backgroundColor="#FCDBDF";
							returnvalue = false;
						} else {
							field.style.backgroundColor="";
						}
					
					} 
	
					if (fields[i]=="ez1") {
						anzzi = 1;
						field=document.getElementsByName(fields[i]);
						if (field[0].checked == true) {
							anzez = 1;
						} else {
							anzdz = 1;
						}
						if (field[2]) {
						mz = false;
						}
					}
					if (fields[i]=="ez2") {
						anzzi = 2;
						field=document.getElementsByName(fields[i]);
						if (field[0].checked == true) {
							anzez++;
						} else {
							anzdz++;
						}
					}	
					if (fields[i]=="ez3") {
						anzzi = 3;
						field=document.getElementsByName(fields[i]);
						if (field[0].checked == true) {
							anzez++;
						} else {
							anzdz++;
						}
					}
					if (fields[i]=="ez4") {
						anzzi = 4;
						field=document.getElementsByName(fields[i]);
						if (field[0].checked == true) {
							anzez++;
						} else {
							anzdz++;
						}
					}
				}
			}
		}
		if (((anzdz==1) || (anzdz==3)) && (mz == true)) {
			field=document.getElementById("hotel");
			field.style.border = "solid #CA0018 2px";
			// field.style.borderColor=color;
			// document.getElementById("hotel").style.backgroundColor=color;
			// document.getElementById("hotel2").style.border = "solid #CA0018 2px";
			// document.getElementById("hotel2").style.borderColor='#CA0018';
			returnvalue = false;
		} else {
			field=document.getElementById("hotel");
			if (field) {
				field.style.border = "none";
			}
		}
				  
		/**
		if ((anzzi==2 && anzdz==1) || (anzzi==2 && anzdz > 1 && anzez > 0)) {
			returnvalue = false;
			document.getElementById("hotel").style.backgroundColor=#CA0018;

		} 
		if (anzzi==3 && (anzdz ==1 && anzez > 1) || anzdz > 1) {
			returnvalue = false;
		} 
		if ((anzzi==4 && anzdz > 2) || (anzzi==4 && anzdz > 1 && anzez > 0) || (anzzi==4 && anzdz==1 && anzez != 2))  {
			returnvalue = false;
		} 
		*/
	return returnvalue;
	}
	
	function checkPreReForm(field){
		var fields = field.split(",");
		var returnvalue = true;
		var fieldcb=document.getElementById(fields[1]); 
		var color="#CA0018";
		var colorok="#A3A3A3";
		for (var i=0;i<fields.length;i++){
 
		    var fieldn=document.getElementById(fields[i]);
			if (fieldn.type=="checkbox"){
				if (fieldn.checked==true){
				fieldcb.style.backgroundColor="#A3A3A3";
				} else {
					// fieldn.style.borderWidth="2px";
					// fieldn.style.borderColor=color;
					fieldcb.style.backgroundColor="#CA0018";
					returnvalue = false;
				}
				
			}
		}

		return returnvalue;

	}
	


	function viewUpload(id){
		document.getElementById(id).style.display="block";
	}
	function closeUpload(id){
		document.getElementById(id).style.display="none";
		document.getElementById(id+"gif").onmouseover="";
		document.getElementById(id+"gif").onmouseout="";
		document.getElementById(id+"check").checked ="true";
	}
	
	function checkMailForm(){
		if (document.emailform.email.value=="E-Mail Adresse"){
			document.emailform.email.style.borderWidth="2px";
			document.emailform.email.style.borderColor="#CA0018";
			return false;
		} else if (document.emailform.email.value==""){
			document.emailform.email.style.borderWidth="2px";
			document.emailform.email.style.borderColor="#CA0018";
			return false;
		} else if (document.emailform.email.value.indexOf("@")<0){
			document.emailform.email.style.borderWidth="2px";
			document.emailform.email.style.borderColor="#CA0018";
			return false;
		}
		return true;
	}
	
	function checkKontaktFormBanner(field1,field2){
		var color="#CA0018";
		var colorok="#FFFFFF";
		var ret=true;
		var opt=false;
		ret=checkKontaktForm(field1);
		field2 = field2.split(",");
		for (var i=0;i<field2.length;i++){
			var field = document.getElementById(field2[i]);
			if (field && field.type=="checkbox"){
				if (field.checked==true){
					opt=true;
				}
					field.style.borderWidth="1px";
					field.style.backgroundColor=colorok;
			}
			
		}
		if (opt==false){
			for (var i=0;i<field2.length;i++){
				var field = document.getElementById(field2[i]);
				if (field && field.type=="checkbox"){
					field.style.borderWidth="2px";
					field.style.backgroundColor=color;
				}
			}
			ret=false;
		
		}
		return ret;
	}
	
	function checkKontaktForm(field){
		var fields = field.split(",");
		var returnvalue = true;
		var color="#CA0018";
		var colorok="#A3A3A3";
		for (var i=0;i<fields.length;i++){
			var field = document.getElementsByName(fields[i])[0];
			if (field.type=="text" || field.type=="textarea"){
				if (field.value==""){
					field.style.borderWidth="2px";
					field.style.borderColor=color;
					returnvalue = false;
				// } else if ((fields[i]=="email" || fields[i]=="weiter_sendto" || fields[i]=="weiter_sendfrom") && field.value.indexOf("@")<0){
				} else if ((fields[i]=="email" || fields[i]=="weiter_sendto" || fields[i]=="weiter_sendfrom") && TestEmail(field.value) !=true){
						field.style.borderWidth="2px";
						field.style.borderColor=color;
						returnvalue = false;
				} else if (fields[i]=="geburtsdatum" && (isValidDate(field.value)!= true)) {
						field.style.borderWidth="2px";
						field.style.borderColor=color;
						returnvalue = false;
				} else if (fields[i]=="anzahl" && (isInt(field.value)!= true)) {
						field.style.borderWidth="2px";
						field.style.borderColor=color;
						returnvalue = false;						
				} else {
					field.style.borderWidth="1px";
					field.style.borderColor=colorok;

				}
				
			//   }
				
			} else if (field.type=="radio"){
					var schleife = false;
					field=document.getElementsByName(fields[i]);
					for (var j=0; j<field.length; j++) {
						if (field[j].checked) {
							schleife=true;
						}
					}
					if (schleife==false){
						for (var j=0; j<field.length; j++) {
							field[j].style.borderWidth="2px";
							field[j].style.borderColor=color;
						}
						returnvalue = false;
					} else {
						for (var j=0; j<field.length; j++) {
							field[j].style.borderWidth="0px";
							field[j].style.borderColor=colorok;
						}
					}
				} else if (field.type=="checkbox"){
					if (field.checked!=true){
							field.style.borderWidth="2px";
							field.style.backgroundColor=color;
							returnvalue = false;
					} else {
						field.style.borderWidth="1px";
						field.style.backgroundColor="";
					}
				}
		}
	return returnvalue;
	}
	
	function openWeiter(){
		document.getElementById('weiterempfehlen').style.display='inline';
		document.getElementById('weiter_sendto').focus();
	}
	
	function setContentColor(obj){
		obj.style.backgroundColor="#F4F4F4";
	}
	
	function setContentColorOut(obj){
		obj.style.backgroundColor="";
	}
	
	function setBackground(obj,url){
	
	}
	
	function setBackgroundColor(obj){
		if (obj.style.backgroundColor.toUpperCase()=="#E4E4E4" || obj.style.backgroundColor == "rgb(228, 228, 228)"){
			
			obj.style.backgroundColor="";
			if (obj.previousSibling){
				if (obj.previousSibling.tagName=="DIV"){
					obj.previousSibling.childNodes[0].style.borderBottom="1px #D0D0D0 solid";
					obj.style.borderTop="0px #D0D0D0 solid";
				} else if (obj.previousSibling.previousSibling && obj.previousSibling.previousSibling.tagName=="DIV"){
					obj.previousSibling.previousSibling.childNodes[1].style.borderBottom="1px #D0D0D0 solid";
					obj.style.borderTop="0px #D0D0D0 solid";
				}
			}
			if (obj.nextSibling){
				if (obj.nextSibling.tagName=="DIV"){
					obj.nextSibling.style.paddingTop ="10px";
					obj.style.borderBottom="0px #D0D0D0 solid";
					obj.childNodes[0].style.borderBottomColor="";
				} else if (obj.nextSibling.nextSibling&& obj.nextSibling.nextSibling.tagName=="DIV"){
					obj.nextSibling.nextSibling.style.paddingTop ="10px";
					obj.style.borderBottom="0px #D0D0D0 solid";
					obj.childNodes[1].style.borderBottomColor="";
				}
			}
		} else {
			obj.style.backgroundColor="#E4E4E4";
			obj.style.borderBottom="1px #D0D0D0 solid";
			if (obj.previousSibling){
				if (obj.previousSibling.tagName=="DIV"){
					obj.previousSibling.childNodes[0].style.borderBottom="0px";
					obj.style.borderTop="1px #D0D0D0 solid";
				} else if (obj.previousSibling.previousSibling && obj.previousSibling.previousSibling.tagName=="DIV"){
					obj.previousSibling.previousSibling.childNodes[1].style.borderBottom="0px";
					obj.style.borderTop="1px #D0D0D0 solid";
				}
			}
			if (obj.nextSibling){
				if (obj.nextSibling.tagName=="DIV"){
					obj.nextSibling.style.paddingTop ="9px";
					obj.childNodes[0].style.borderBottomColor="#E4E4E4";
				} else if (obj.nextSibling.nextSibling&& obj.nextSibling.nextSibling.tagName=="DIV"){
					obj.nextSibling.nextSibling.style.paddingTop ="9px";
					obj.childNodes[1].style.borderBottomColor="#E4E4E4";
				}
			}
			
			
		}
	}
	
	
function openBanner(width,height,id,w,h,lang){
		window.open('http://www.sympany.ch/showbanner?id='+id+'&w='+w+'&h='+h+'&lang='+lang,'_blank','left=150,top=150,width='+width+',height='+height+',toolbar=no,status=no,scrollbars=no,menubar=no,location=no,resizable=yes');
	}
	
	
function toggleVersichert(ele){
	var ischecked = ele.checked;
	if(ischecked==true){
		ele.value="ja";
		document.getElementById('vnr').style.display='inline';
		document.getElementById('vnrinput').style.display='inline';	
		

		
	}else if(ischecked==false){
		ele.value="nein";
		document.getElementById('vnr').style.display='none';
		document.getElementById('vnrinput').style.display='none';
		
	}

}
	
	
function addForm(name,value){
	var newname=new Number(name.substr(4));
	newname++;
	newname="file"+newname;
		var input = document.createElement("input");
		input.type="file";
	    input.name=name;
		input.className="inputbox";
		input.onchange=function(){addForm(this.name,this.value);};
		input.style.width="334px";
		var formarea = document.getElementById("zuploadform");
		formarea.appendChild(input)
	
	}