function windowOpen(sUrl, iWidth, iHeight) {

	if (iWidth && iWidth != "" && iHeight && iHeight != "") {
		window.open(sUrl, "_blank", "toolbar=no, location=no, status=no, menubar=no, personalbar=no, scrollbars=yes, width=" + iWidth + ", height=" + iHeight + ", resizable=yes, screenx=50, left=50, screenY=50, top=50");
	}
	else {
		window.open(sUrl, "_blank", "toolbar=no, location=no, status=no, menubar=no, personalbar=no, scrollbars=yes, width=775, height=500, resizable=yes, screenx=50, left=50, screenY=50, top=50");
	}
}

function printPage(sUrl) {

	window.open("", "printWindow", "toolbar=no, location=no, status=no, menubar=no, personalbar=no, scrollbars=yes, width=612, height=500, resizable=yes, screenx=50, left=50, screenY=50, top=50");
	
	var oForm = document.globalForm;
	oForm.action = sUrl;
	oForm.method = "post";
	oForm.target = "printWindow";
	
	oForm.submit();
}

function changeLanguage(sUrl) {

	var oForm = document.globalForm;
	oForm.action = sUrl;
	oForm.target = "_self";
	oForm.method = "post";
	oForm.submit();
}

function CheckMandatoryFields(oForm) {


	
	var i, j, sElementName, sElementType, bCheck;
	var bError = 0;
	var bgColor = "#ff0000";
	var bgColor2 = "#ffffff";
	
	
	if (oForm.name == "dispobox_bestellen" && document.getElementById("total").value < 20) {
		alert("Mindestens 20 Dispobox müssen bestellt werden.");
		document.getElementById("total").focus();
		return false;
	}
	
	if (oForm.name =="anmeldung") {
		if (checkRoute() == 0) return false;
	} 
	
	if (oForm.name =="pickpost") {
		if (checkPickpost() == 0) return false;
		
	} 
	
	if (oForm.name =="spibestellung") {
		if (checkInternationalBrochure() == 0) return false;
		
	} 
	
	if (oForm.name =="logisticcontact") {
		if (checkPostLogisticsFields() == 0) return false;
		
	} 
	
	if (oForm.name =="dp_kundenloyalitaet") {
		if (checkDpKundenLoyalitaetFields() == 0) return false;
		
	} 
	
			
	for (i = 0; i < oForm.elements.length; i++) {
		
		oElement = oForm.elements[i];
		sElementName = oElement.name;
		sElementType = oElement.type;
		sElementId = oElement.id;
		
							
		if (sElementName != "") {
			
					
			if (sElementName.length > 1) {
			
						
				if (sElementName.substr(sElementName.length - 1, 1) == "*") {
					sElementName=sElementName.replace(/\* *$/, "");
					sElementName=sElementName.replace(/\* *$/, "");
					
										
					
					switch (sElementType) {
						case "text":
							if (oElement.value == "") {
								//alert("Vogliate introdurre "+ sElementName +", per favore!");
								alert("Vogliate introdurre "+ "tutti i campi" +", per favore!");
								//oElement.style.backgroundColor = bgColor;
								oElement.focus();
								return false;						
								
							} else {
							
								oElement.style.backgroundColor = bgColor2;
							}
							break;
														
						case "textarea":
						
							if (oElement.value == "") {
								//alert("Vogliate introdurre "+ sElementName +", per favore!");
								alert("Vogliate introdurre "+ "tutti i campi" +", per favore!");
								//oElement.style.backgroundColor = bgColor;
								oElement.focus();
								return false;
							} else {
							
								oElement.style.backgroundColor = bgColor2;
							}
							break;

						case "checkbox":
						
							if (oElement.checked == false) {
								//alert("Vogliate introdurre "+ sElementName +", per favore!");
								alert("Vogliate introdurre "+ "tutti i campi" +", per favore!");
								//oElement.style.backgroundColor = bgColor;
								oElement.focus();
								return false;
							} else {
							
								oElement.style.backgroundColor = bgColor2;
							}
							break;
							
						case "select-one":
						
							if (oElement[oElement.selectedIndex].value == "" || oElement[oElement.selectedIndex].value == "null") {
								//alert("Vogliate introdurre "+ sElementName +", per favore!");
								alert("Vogliate introdurre "+ "tutti i campi" +", per favore!");
								//oElement.style.backgroundColor = bgColor;
								oElement.focus();
								return false;
							} else {
							
								oElement.style.backgroundColor = bgColor2;
							}
							break;
							
						case "select-multiple":

							bCheck = 0;

							for (j = 0; j < oElement.options.length; j++) {
							
							alert(oElement.options[j].selected);
								if (oElement.options[j].selected) {
									bCheck++;
								}
							}

							if (bCheck > 0) {
								bError = 1;
							}
							break;
					}
				}
				
				if (sElementName.indexOf('mail') != -1 && oElement.value != "") {
					
					if(checkEmail(oElement.value) == false){
						bError = 2;
						alert("L'indirizzo E-Mail deve contenere un '@' e un '.'.\nScrivete di nuovo l'indirizzo e-mail, per favore.");
						oForm[oElement.name].focus();
						return false;
					}
				}
				
						
				
				if (sElementName == "npa" || sElementName == "npa_2") {
				
					if (oElement.value == "") {
						alert("Vogliate introdurre NPA, per favore!");
						//oElement.style.backgroundColor = bgColor;
						oElement.focus();
						return false;
					} else {
				
						oElement.style.backgroundColor = bgColor2;
					}
					
					if (oElement.value.length < 4) {
						bError = 4;
						alert("Attenzione NPA deve contenere delle cifre e almeno 4!");
						oElement.focus();
						return false;
					}
				}
				
				
				if (sElementName == "Bestimmungsland") {
					if (oElement[oElement.selectedIndex].value == "" || oElement[oElement.selectedIndex].value == "null") {
						alert("Vogliate introdurre "+ sElementName +", per favore!");
						//oElement.style.backgroundColor = bgColor;
						oElement.focus();
						return false;
					}
				}
				
				if (sElementName == "Format") {
					if (oElement[oElement.selectedIndex].value == "" || oElement[oElement.selectedIndex].value == "null") {
						alert("Vogliate introdurre "+ sElementName +", per favore!");
						//oElement.style.backgroundColor = bgColor;
						oElement.focus();
						return false;
					}
				}
			}
		}
	}

	if (bError == 0) {
		oForm.submit();
	}
	if (bError == 1) {
		alert("Bitte füllen Sie alle mit einem * markierten Felder aus.");
		
	}
	if (bError == 3) {
		alert("Vogliate introdurre il NPA con delle cifre, per favore!");
	}
}



function checkEmail(emailAddress) {
	
	var re = /^(([^<>()[\]\\.,;:@\"]+(\.[^<>()[\]\\.,;:@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
	return re.test(emailAddress);
}



function confirmDelete(){
	var re = window.confirm("Desiderate effettivamente cancellare questo oggetto?");
    return re;
}

function writeTrackingImage(iPageId, iLanguageId, iSendPageSendId, iSendPageViewId, iMediumId, sTeaserIds, iTeaserId, iRefererPageId, sQuery) {

	var sRandomPath = parseInt(Math.random() * 1000000);
	document.write("<img src=\"" + sRandomPath + "/statistik?pageId=" + iPageId + "&languageId=" + iLanguageId + "&sendPageSend=" + iSendPageSendId + "&sendPageView=" + iSendPageViewId + "&mediumId=" + iMediumId + "&teaserIds=" + sTeaserIds + "&teaserId=" + iTeaserId + "&refererPageId=" + iRefererPageId + "&query=" + sQuery + "\" width=\"0\" height=\"0\" border=\"0\" alt=\"\">");
}


function checkRoute() {

  var p_day_a = "";
  var p_day_b = "";
  var p_day_c = "";
  var p_day_d = "";
  var p_day_e = "";
  
  var p_day_a_date = "";
  var p_day_b_date = "";
  var p_day_c_date = "";
  var p_day_d_date = "";
  var p_day_e_date = "";
		
  if (document.anmeldung.routeA) p_day_a = document.anmeldung.routeA[document.anmeldung.routeA.selectedIndex].value;
  if (document.anmeldung.routeB) p_day_b = document.anmeldung.routeB[document.anmeldung.routeB.selectedIndex].value;
  if (document.anmeldung.routeC) p_day_c = document.anmeldung.routeC[document.anmeldung.routeC.selectedIndex].value;		
  if (document.anmeldung.routeD) p_day_d = document.anmeldung.routeD[document.anmeldung.routeD.selectedIndex].value;
  if (document.anmeldung.routeE) p_day_e = document.anmeldung.routeE[document.anmeldung.routeE.selectedIndex].value;
   
  if (document.anmeldung.datenRouteA) p_day_a_date = document.anmeldung.datenRouteA[document.anmeldung.datenRouteA.selectedIndex].value;
  if (document.anmeldung.datenRouteB) p_day_b_date = document.anmeldung.datenRouteB[document.anmeldung.datenRouteB.selectedIndex].value;
  if (document.anmeldung.datenRouteC) p_day_c_date = document.anmeldung.datenRouteC[document.anmeldung.datenRouteC.selectedIndex].value;		
  if (document.anmeldung.datenRouteD) p_day_d_date = document.anmeldung.datenRouteD[document.anmeldung.datenRouteD.selectedIndex].value;
  if (document.anmeldung.datenRouteE) p_day_e_date = document.anmeldung.datenRouteE[document.anmeldung.datenRouteE.selectedIndex].value;



	if (p_day_a != "" && p_day_a_date =="") {
		alert("Bitte wählen!");
		document.anmeldung.datenRouteA.focus();
		return 0;
	}
	
	if (p_day_a == "" && p_day_a_date !="") {
		alert("Bitte wählen!");
		document.anmeldung.routeA.focus();
		return 0;
	}
	
	if (p_day_b != "" && p_day_b_date =="") {
		alert("Bitte wählen!");
		document.anmeldung.datenRouteB.focus();
		return 0;
	}
	
	if (p_day_b == "" && p_day_b_date !="") {
		alert("Bitte wählen!");
		document.anmeldung.routeB.focus();
		return 0;
	}
	
	if (p_day_c != "" && p_day_c_date =="") {
		alert("Bitte wählen!");
		document.anmeldung.datenRouteC.focus();
		return 0;
	}
	
	if (p_day_c == "" && p_day_c_date !="") {
		alert("Bitte wählen!");
		document.anmeldung.routeC.focus();
		return 0;
	}
	
	if (p_day_d != "" && p_day_d_date =="") {
		alert("Bitte wählen!");
		document.anmeldung.datenRouteD.focus();
		return 0;
	}
	
	if (p_day_d == "" && p_day_d_date !="") {
		alert("Bitte wählen!");
		document.anmeldung.routeD.focus();
		return 0;
	}
	
	if (p_day_e != "" && p_day_e_date =="") {
		alert("Bitte wählen!");
		document.anmeldung.datenRouteE.focus();
		return 0;
	}
	
	if (p_day_e == "" && p_day_e_date !="") {
		alert("Bitte wählen!");
		document.anmeldung.routeE.focus();
		return 0;
	}
	
	return 1;
}
