function popupWindow(obj,param) {
	var pDlg = window.open(obj,"",param + ",toolbar=0,menubar=0,resizable=1,scrollbars=no;");
}

function downloadDlg(obj) {
	var pDlg = window.open(obj,"Downloadfenster","width=900,height=600,left=100,top=20,scrollbars=yes");
}

function sendPage() {
	var pDlg = window.open( "./sendpage.php","print","width=500,height=400,left=100,top=20,scrollbars=yes");
}

function printPage() {
	var pDlg = window.open( "./printpage.php?GUID=","print","width=500,height=400,left=100,top=20,scrollbars=yes");
}

function doInit() {
	check4Anker();
}

function check4Anker() {
	var aCounted = document.all.tags("A");

	for(i=0;i<=aCounted.length;i++) {
		try {
			if(aCounted[i].href.indexOf("http://[anker]") != -1) {
				var CurrAnker = aCounted[i].id;
				aCounted[i].href = "#" + CurrAnker;
			}
		} catch (e) {
		}
	}
}

function checkRabattCode(v) {
	
	if(v.length > 0) {
		var RetURL = document.location.href;
		var PathName = document.location.pathname;
		var ScriptURL = "https://" + document.location.host + PathName.replace("index.php","xt_checkcode.php");
		document.location.href = ScriptURL + "?code=" + v + "&returl=" + RetURL;
	}
}

function SetValue(f,v) {
	if(document.all.showbilling.checked) {
		document.all[f].value = v;
	};
}

function EnableRechAddress() {
	if(document.all.showbilling.checked) {
		document.all.rech_anrede.disabled = true;
		document.all.rech_name.disabled = true;
		document.all.rech_street.disabled = true;
		document.all.rech_zipcode.disabled = true;
		document.all.rech_town.disabled = true;
		document.all.rech_country.disabled = true;
		document.all.rech_vorname.disabled = true;
	} else {
		document.all.rech_anrede.disabled = false;
		document.all.rech_name.disabled = false;
		document.all.rech_street.disabled = false;
		document.all.rech_zipcode.disabled = false;
		document.all.rech_town.disabled = false;
		document.all.rech_country.disabled = false;
		document.all.rech_vorname.disabled = false;
	}

	document.all.rech_anrede.value = document.all.lief_anrede.value;
	document.all.rech_name.value = document.all.lief_name.value;
	document.all.rech_street.value = document.all.lief_street.value;
	document.all.rech_zipcode.value = document.all.lief_zipcode.value;
	document.all.rech_town.value = document.all.lief_town.value;
	document.all.rech_country.value = document.all.lief_country.value;
	document.all.rech_vorname.value = document.all.lief_vorname.value;
}

function AGBPopup(Path) {
	window.open(Path, "","top=100,left=100,width=840,height=650,toolbar=0,menubar=0,resizable=1,scrollbars=1;");
}

function ConfirmNewPasswd(f, u, m) {
	return confirm("Confirm generate new password for user:\n\n" + u + "  send to  " + m);
}

function changeVisibility(f) {
	var Doc = eval("document.all." + f + ".style.visibility");
	if(Doc == "hidden") {
		document.all[f].style.visibility = "visible";
	} else {
		document.all[f].style.visibility = "hidden";
	}
}

function enableSubmit(f) {
	if(document[f].terms.checked) {
		document[f].SubmitBtn.disabled = false;
	} else {
		document[f].SubmitBtn.disabled = true;
	};
}

function chkUserForm(f) {
	try {
		var docForms = document.forms.length;
		for(i=0;i<=docForms;i++) {
			if((document[i].id == f)) {
				return checkForm(i);
				break;
			}
		}
	} catch (e) {
	return false;
	}
	return false;
}

function chkFormField(pForm) {
//	try {
		var noError = true;
		var ErrorMsg = "";
		var docForms = document.forms.length;
		for(i=0;i<docForms;i++) {
			if((document[i].id == pForm)) {
				var docFields = document.forms[i].elements.length;
				for(f=0;f<docFields;f++) {
					var CurrForm = document.forms[i].elements[f];

					if(document.forms[i].elements[f].TestForm) {
						switch(document.forms[i].elements[f].FormType) {
							case "text" :
								var CurrField = document.forms[i].elements[f].value;
								var CurrFieldName = document.forms[i].elements[f].name;
								if(CurrField.length == 0) {
									ErrorMsg += "\n* Bitte geben Sie einen Text für " + CurrFieldName + " ein.";
									noError = false;
								}
								break;
							case "number" :
								break;
							case "mail" :
								var CurrField = document.forms[i].elements[f].value;
								var CurrFieldName = document.forms[i].elements[f].name;
								if(CurrField.length == 0) {
									ErrorMsg += "\n* Bitte geben Sie Ihre E-Mail Adresse ein.";
									noError = false;
								}
								break;
						}
					} // ist Object
				}
			}
		}
//	} catch (e) {
//		alert(e); return false;
//	};
	if(!noError) {
	alert("Bitte korrigieren Sie die folgenden Fehler:\n" + ErrorMsg);
	}
	return noError;
}


function checkForm(f) {

	var retValue = false;
	var hasError = false;
	var ErrorMsg = "";

	try {
		Search = document[f].SearchTerm.value;
		if(Search.length == 0) {
			ErrorMsg += oErrorArray['400001'];
			hasError = true;
		}
	} catch (e) {
	};

	try {
		password = document[f].password.value;
		if((password.length == 0) || (password.length > 20)) {
			ErrorMsg += oErrorArray['400002'];
			hasError = true;
		}
	} catch (e) {
	};

	try {
		password2 = document[f].password2.value;
		if(password != password2) {
			ErrorMsg += oErrorArray['400003'];
			hasError = true;
		}
	} catch (e) {
	};

	// Lieferadresse testen
	try {
		name = document[f].lief_vorname.value;
		if((name.length == 0) || (name.length > 50)) {
			ErrorMsg += oErrorArray['100001'];
			hasError = true;
		}
	} catch (e) {
	};

	try {
		name = document[f].lief_name.value;
		if((name.length == 0) || (name.length > 50)) {
			ErrorMsg += oErrorArray['100002'];
			hasError = true;
		}
	} catch (e) {
	};
	
	try {
		street = document[f].lief_street.value;
		if((street.length == 0) || (street.length >50)) {
			ErrorMsg += oErrorArray['100003'];
			hasError = true;
		}
	} catch (e) {
	};
	
	try {
		zipcode = document[f].lief_zipcode.value;
		if((zipcode.length == 0) || (zipcode.length > 5)) {
			ErrorMsg += oErrorArray['100004'];
			hasError = true;
		}
		
		if(isNaN(zipcode)) {
			ErrorMsg += oErrorArray['100005'];
			hasError = true;
		}
	} catch (e) {
	};
		
	try {		
		town = document[f].lief_town.value;
		if((town.length == 0) || (town.length >50)) {
			ErrorMsg += exists(oErrorArray['100006']);
			hasError = true;
		}
	} catch (e) {
	};


	try {	
		phone = document[f].lief_phone.value;
		if((phone.length == 0) || (phone.length > 50)) {
			ErrorMsg += oErrorArray['100007'];
			hasError = true;
		}
	} catch (e) {
	};
	//Rechnungsdaten prüfen

	try {	
		if(!document[f].showbilling.checked) {
		
			try {
				name = document[f].rech_name.value;
				if((name.length == 0) || (name.length > 50)) {
					ErrorMsg += oErrorArray['100010'];
					hasError = true;
				}
			} catch (e) {
			};
			
			try {
				street = document[f].rech_street.value;
				if((street.length == 0) || (street.length >50)) {
					ErrorMsg += oErrorArray['1000011'];
					hasError = true;
				}
			} catch (e) {
			};
			
			try {
				zipcode = document[f].rech_zipcode.value;
				if((zipcode.length == 0) || (zipcode.length > 5)) {
					ErrorMsg += oErrorArray['100012'];
					hasError = true;
				}
				
				if(isNaN(zipcode)) {
					ErrorMsg += oErrorArray['100013'];
					hasError = true;
				}
			} catch (e) {
			};
				
			try {	
				town = document[f].rech_town.value;
				if((town.length == 0) || (town.length >50)) {
					ErrorMsg += oErrorArray['100014'];
					hasError = true;
				}
			} catch (e) {
			};
		
		
			try {	
				phone = document[f].rech_phone.value;
				if((phone.length == 0) || (phone.length > 50)) {
					ErrorMsg += oErrorArray['100015'];
					hasError = true;
				}
			} catch (e) {
			};
		};
	} catch (e) {
	}

	// Mail prüfen
	try {
		mail = document[f].mail.value;
		if(mail.indexOf('@') == -1) {
			ErrorMsg += oErrorArray['100016'];
			hasError = true;
		} else {
			if(mail.indexOf('.') == -1) {
				ErrorMsg += oErrorArray['100017'];
				hasError = true;
			} else {
				DotIndex = mail.lastIndexOf('.');
				if(DotIndex >= mail.length - 2) {
					ErrorMsg += oErrorArray['100018'];
					hasError = true;
				}
			}
			
			domTxt = mail.substring(mail.indexOf('@')+1,mail.length);
			domTxt = domTxt.substring(0,domTxt.indexOf('.'));
			if(domTxt.length == 0) {
				ErrorMsg += oErrorArray['100019'];
				hasError = true;
			}
		}
		if((mail.charAt(0) == '@') || (mail.charAt(0) == '.')) {
			ErrorMsg += oErrorArray['100020'];
			hasError = true;
		}
	} catch (e) {
	};

	try {	
		mail2 = document[f].mail2.value;
		if(!mail == mail2) {
			ErrorMsg += oErrorArray['100021'];
			hasError = true;		
		}
	} catch (e) {
	};

	try {
		username = document[f].username.value;
		if((username.length == 0) || (username.length > 50)) {
			ErrorMsg += oErrorArray['100022'];
			hasError = true;
		}
	} catch (e) {
	};

		
	if(hasError) {
		alert(oErrorArray['400004'] + ErrorMsg);
	}

	return !hasError;
}


// Parse SQL Errors in alert window
function parseError() {

//	try {
		var urlTxt =  window.location.href;
		var ErrorMsg = "";
		var nr = urlTxt.substr(urlTxt.indexOf('errorno=')+8,urlTxt.length);
		if(typeof(oErrorArray[nr]) == "string") {	
			if(oErrorArray[nr].length > 0) {
				alert(oErrorArray[nr]);	
			} else {
				ErrorMsg = GetErrorMsg(nr);
				if(ErrorMsg.length > 0) {
					alert(ErrorMsg);
				};
			}
		}
//	} catch (e) {}
}
