
function validateProductSearch(theForm) {
	if (!rightLength(theForm.searchfor.value,1,200,"Produktsøk")){
		theForm.searchfor.focus();
		return (false);
	}
	if (!validText(theForm.searchfor.value," -_.,&%*!?;:/\()[]{}<>$£#@","Produktsøk")){
		theForm.searchfor.focus();
		return (false);
	}
	
	return (true);
}

function ValidateLogin(theForm){
	if (!rightLength(theForm.username.value,1,100,"Email")){
		theForm.username.focus();
		return (false);
	}
	if (!isEmailAdress(theForm.username.value)){
		alert("The email is not valid!");
		theForm.username.focus();
		return (false);
	}

	if (!theForm.sendpass.checked == true) {
		if (!rightLength(theForm.password.value,5,20,"Password")){
			theForm.password.focus();
			return (false);
		}
		if (!validText(theForm.password.value,"_-,./#$%&@/()=?\+}][{$£!<>","Password")){
			theForm.password.focus();
			return (false);
		}
	}
	
	return true;
}

function ValidateNumbers(theForm){
	if (!rightLength(theForm.quantity.value,1,2,"Numbers")){
		theForm.quantity.focus();
		return (false);
	}
	if (!isInteger(theForm.quantity.value)){
		alert("Illegal format on numbers. Only use integers!");
		theForm.quantity.focus();
		return (false);
	}
	
	return true;
}

function ValidateRegister(theForm){
	if (!rightLength(theForm.Epost.value,1,100,"Email")){
		theForm.Epost.focus();
		return (false);
	}
	if (!isEmailAdress(theForm.Epost.value)){
		alert("The email is not valid!");
		theForm.Epost.focus();
		return (false);
	}
	if (!rightLength(theForm.password.value,5,20,"Password")){
		theForm.password.focus();
		return (false);
	}
	if (!validText(theForm.password.value,"_-,./#$%&@/()=?\+}][{$£!<>","Password")){
		theForm.password.focus();
		return (false);
	}
	if (!rightLength(theForm.passwordrep.value,5,20,"Repeat password")){
		theForm.passwordrep.focus();
		return (false);
	}
	if (!validText(theForm.passwordrep.value,"_-,./#$%&@/()=?\+}][{$£!<>","Repeat password")){
		theForm.passwordrep.focus();
		return (false);
	}
	if (!theForm.password.value.equals(theForm.passwordrep.value)) {
		alert("The passwords must be equal!");
		theForm.password.focus();
		return (false);
	}
	
	if (!rightLength(theForm.Firmanavn.value,0,50,"Companyname")){
		theForm.Firmanavn.focus();
		return (false);
	}
	if (!validText(theForm.Firmanavn.value," _-,.&@;:?[]()\/<>","Companyname")){
		theForm.Firmanavn.focus();
		return (false);
	}
	if (!rightLength(theForm.Organisasjonsnr.value,0,20,"Org. nr")){
		theForm.Organisasjonsnr.focus();
		return (false);
	}
	if (!validText(theForm.Organisasjonsnr.value," ","Org. nr")){
		theForm.Organisasjonsnr.focus();
		return (false);
	}
	if (!isEmpty(theForm.Firmanavn.value) && isEmpty(theForm.Organisasjonsnr.value)) {
		alert("You must enter org.nr and companyname");
		theForm.Organisasjonsnr.focus();
		return (false);
	}else if (isEmpty(theForm.Firmanavn.value) && !isEmpty(theForm.Organisasjonsnr.value)) {
		alert("You must enter org.nr and companyname");
		theForm.Firmanavn.focus();
		return (false);
	}
	
	
	if (!rightLength(theForm.Fornavn.value,1,30,"Surname")){
		theForm.Fornavn.focus();
		return (false);
	}
	if (!validText(theForm.Fornavn.value," _-,.","Surname")){
		theForm.Fornavn.focus();
		return (false);
	}
	if (!rightLength(theForm.Etternavn.value,1,30,"Lastname")){
		theForm.Etternavn.focus();
		return (false);
	}
	if (!validText(theForm.Etternavn.value," _-,.","Lastname")){
		theForm.Etternavn.focus();
		return (false);
	}
	
	if (!rightLength(theForm.Adresse.value,0,30,"Address")){
		theForm.Adresse.focus();
		return (false);
	}
	if (!validText(theForm.Adresse.value," _-,.:/","Address")){
		theForm.Adresse.focus();
		return (false);
	}
	if (!rightLength(theForm.Postnr.value,4,6,"Postal place")){
		theForm.Postnr.focus();
		return (false);
	}
	if (!isInteger(theForm.Postnr.value)){
		alert("Illegal format on postal place. Only use integers!");
		theForm.Postnr.focus();
		return (false);
	}
	if (!rightLength(theForm.Sted.value,1,20,"Place")){
		theForm.Sted.focus();
		return (false);
	}
	if (!validText(theForm.Sted.value," _-,./","Place")){
		theForm.Sted.focus();
		return (false);
	}
	if (!rightLength(theForm.Tlfnr.value,1,15,"Phonenr")){
		theForm.Tlfnr.focus();
		return (false);
	}
	if (!isInteger(theForm.Tlfnr.value)){
		alert("Illegal format on phonenr. Only use integers!");
		theForm.Tlfnr.focus();
		return (false);
	}

	return true;
}

function ValidateDelivery(theForm){
	
	if (!rightLength(theForm.Navn.value,1,60,"Name")){
		theForm.Navn.focus();
		return (false);
	}
	if (!validText(theForm.Navn.value," _-,.&@;:?[]()\/<>","Name")){
		theForm.Navn.focus();
		return (false);
	}
	
	if (!rightLength(theForm.Adresse.value,0,30,"Adress")){
		theForm.Adresse.focus();
		return (false);
	}
	if (!validText(theForm.Adresse.value," _-,.:/","Adress")){
		theForm.Adresse.focus();
		return (false);
	}
	if (!rightLength(theForm.Postnr.value,4,4,"Postnr")){
		theForm.Postnr.focus();
		return (false);
	}
	if (!isInteger(theForm.Postnr.value)){
		alert("Illegal format on postnr. Only use integers!");
		theForm.Postnr.focus();
		return (false);
	}
	if (!rightLength(theForm.Sted.value,1,20,"Place")){
		theForm.Sted.focus();
		return (false);
	}
	if (!validText(theForm.Sted.value," _-,./","Place")){
		theForm.Sted.focus();
		return (false);
	}
	if (!rightLength(theForm.Tlfnr.value,1,15,"Phonenr")){
		theForm.Tlfnr.focus();
		return (false);
	}
	if (!isInteger(theForm.Tlfnr.value)){
		alert("Illegal format on phonenr. Only use integers!");
		theForm.Tlfnr.focus();
		return (false);
	}

	return true;
}

function ValidateProfile(theForm) {
	if (!rightLength(theForm.Firmanavn.value,0,50,"Companyname")){
		theForm.Firmanavn.focus();
		return (false);
	}
	if (!validText(theForm.Firmanavn.value," _-,.&@;:?[]()\/<>","Companyname")){
		theForm.Firmanavn.focus();
		return (false);
	}
	if (!rightLength(theForm.Organisasjonsnr.value,0,20,"Org. nr")){
		theForm.Organisasjonsnr.focus();
		return (false);
	}
	if (!validText(theForm.Organisasjonsnr.value," ","Org. nr")){
		theForm.Organisasjonsnr.focus();
		return (false);
	}
	if (!isEmpty(theForm.Firmanavn.value) && isEmpty(theForm.Organisasjonsnr.value)) {
		alert("You must enter org.nr and companyname");
		theForm.Organisasjonsnr.focus();
		return (false);
	}else if (isEmpty(theForm.Firmanavn.value) && !isEmpty(theForm.Organisasjonsnr.value)) {
		alert("You must enter org.nr and companyname");
		theForm.Firmanavn.focus();
		return (false);
	}
	
	
	if (!rightLength(theForm.Fornavn.value,1,30,"Surname")){
		theForm.Fornavn.focus();
		return (false);
	}
	if (!validText(theForm.Fornavn.value," _-,.","Surname")){
		theForm.Fornavn.focus();
		return (false);
	}
	if (!rightLength(theForm.Etternavn.value,1,30,"Lastname")){
		theForm.Etternavn.focus();
		return (false);
	}
	if (!validText(theForm.Etternavn.value," _-,.","Lastname")){
		theForm.Etternavn.focus();
		return (false);
	}
	
	if (!rightLength(theForm.Adresse.value,0,30,"Adress")){
		theForm.Adresse.focus();
		return (false);
	}
	if (!validText(theForm.Adresse.value," _-,.:/","Adress")){
		theForm.Adresse.focus();
		return (false);
	}
	if (!rightLength(theForm.Postnr.value,4,4,"Postnr")){
		theForm.Postnr.focus();
		return (false);
	}
	if (!isInteger(theForm.Postnr.value)){
		alert("Illegal format on postnr. Only use integers!");
		theForm.Postnr.focus();
		return (false);
	}
	if (!rightLength(theForm.Sted.value,1,20,"Place")){
		theForm.Sted.focus();
		return (false);
	}
	if (!validText(theForm.Sted.value," _-,./","Place")){
		theForm.Sted.focus();
		return (false);
	}
	if (!rightLength(theForm.Tlfnr.value,1,15,"Phonenr")){
		theForm.Tlfnr.focus();
		return (false);
	}
	if (!isInteger(theForm.Tlfnr.value)){
		alert("Illegal format on phonenr. Only use integers!");
		theForm.Tlfnr.focus();
		return (false);
	}

	return true;
}

function ValidateTipsoss(theForm){
	if (!rightLength(theForm.Epost.value,1,100,"Your email")){
		theForm.Epost.focus();
		return (false);
	}
	if (!isEmailAdress(theForm.Epost.value)){
		alert("The email is not valid!");
		theForm.Epost.focus();
		return (false);
	}

	if (!rightLength(theForm.Tittel.value,1,200,"Title")){
		theForm.Tittel.focus();
		return (false);
	}
	if (!validText(theForm.Tittel.value," _-,.&@;:?![]()\/<>","Title")){
		theForm.Tittel.focus();
		return (false);
	}
	
	if (!rightLength(theForm.Tekst.value,1,2000,"Tips")){
		theForm.Tekst.focus();
		return (false);
	}
	if (!validText(theForm.Tekst.value," _-,.&@;:?![]()\/<>","Text")){
		theForm.Tekst.focus();
		return (false);
	}
	
	return true;
}

