
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 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 {
		if(document[f].lief_vorname.TestField.length > 0) {
			name = document[f].lief_vorname.value;
			if((name.length == 0) || (name.length > 50)) {
				ErrorMsg += oErrorArray['100001'];
				hasError = true;
			}
		}
	} catch (e) {
	};

	try {
		if(document[f].lief_name.TestField.length > 0) {
			name = document[f].lief_name.value;
			if((name.length == 0) || (name.length > 50)) {
				ErrorMsg += oErrorArray['100002'];
				hasError = true;
			}
		}
	} catch (e) {
	};
	
	try {
		if(document[f].lief_street.TestField.length > 0) {
			street = document[f].lief_street.value;
			if((street.length == 0) || (street.length >50)) {
				ErrorMsg += oErrorArray['100003'];
				hasError = true;
			}
		}
	} catch (e) {
	};
	
	try {
		if(document[f].lief_zipcode.TestField.length > 0) {
			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 {		
		if(document[f].lief_town.TestField.length > 0) {
			town = document[f].lief_town.value;
			if((town.length == 0) || (town.length >50)) {
				ErrorMsg += exists(oErrorArray['100006']);
				hasError = true;
			}
		}
	} catch (e) {
	};


	try {	
		if(document[f].lief_phone.TestField.length > 0) {
			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].rech_vorname.TestField.length > 0) {
			name = document[f].rech_vorname.value;
			if((name.length == 0) || (name.length > 50)) {
				ErrorMsg += oErrorArray['100009'];
				hasError = true;
			}
		}
	} catch (e) {
	};

	try {
		if(document[f].rech_name.TestField.length > 0) {
			name = document[f].rech_name.value;
			if((name.length == 0) || (name.length > 50)) {
				ErrorMsg += oErrorArray['100010'];
				hasError = true;
			}
		}
	} catch (e) {
	};
	
	try {
		if(document[f].rech_street.TestField.length > 0) {
			street = document[f].rech_street.value;
			if((street.length == 0) || (street.length >50)) {
				ErrorMsg += oErrorArray['1000011'];
				hasError = true;
			}
		}
	} catch (e) {
	};
	
	try {
		if(document[f].rech_zipcode.TestField.length > 0) {
			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 {	
		if(document[f].rech_town.TestField.length > 0) {
			town = document[f].rech_town.value;
			if((town.length == 0) || (town.length >50)) {
				ErrorMsg += oErrorArray['100014'];
				hasError = true;
			}
		}
	} catch (e) {
	};


	try {	
		if(document[f].rech_phone.TestField.length > 0) {
			phone = document[f].rech_phone.value;
			if((phone.length == 0) || (phone.length > 50)) {
				ErrorMsg += oErrorArray['100015'];
				hasError = true;
			}
		}
	} catch (e) {
	};

	// Mail prüfen
	try {
		if(document[f].mail.TestField.length > 0) {
			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 {	
		if(document[f].mail2.TestField.length > 0) {
			mail2 = document[f].mail2.value;
			if(!mail == mail2) {
				ErrorMsg += oErrorArray['100021'];
				hasError = true;		
			}
		}
	} catch (e) {
	};

	try {
		if(document[f].username.TestField.length > 0) {
			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() {

	var urlTxt =  window.location.href;
	var ErrorMsg = "";
	var nr = urlTxt.substr(urlTxt.indexOf('errorno=')+8,urlTxt.length);
	ErrorMsg = GetErrorMsg(nr);

	if(ErrorMsg.length > 0) {
		alert(ErrorMsg);
	};
}