
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,"Epostadresse")){
		theForm.username.focus();
		return (false);
	}
	if (!isEmailAdress(theForm.username.value)){
		alert("Epostadressen er ikke gyldig!");
		theForm.username.focus();
		return (false);
	}

	if (!theForm.sendpass.checked == true) {
		if (!rightLength(theForm.password.value,5,20,"Passord")){
			theForm.password.focus();
			return (false);
		}
		if (!validText(theForm.password.value,"_-,./#$%&@/()=?\+}][{$£!<>","Passord")){
			theForm.password.focus();
			return (false);
		}
	}
	
	return true;
}


function ValidateRegister(theForm){
	if (!rightLength(theForm.Epost.value,1,100,"Epostadresse")){
		theForm.Epost.focus();
		return (false);
	}
	if (!isEmailAdress(theForm.Epost.value)){
		alert("Epostadressen er ikke gyldig!");
		theForm.Epost.focus();
		return (false);
	}
	if (!rightLength(theForm.password.value,5,20,"Passord")){
		theForm.password.focus();
		return (false);
	}
	if (!validText(theForm.password.value,"_-,./#$%&@/()=?\+}][{$£!<>","Passord")){
		theForm.password.focus();
		return (false);
	}
	if (!rightLength(theForm.passwordrep.value,5,20,"Gjenta passord")){
		theForm.passwordrep.focus();
		return (false);
	}
	if (!validText(theForm.passwordrep.value,"_-,./#$%&@/()=?\+}][{$£!<>","Gjenta passord")){
		theForm.passwordrep.focus();
		return (false);
	}
	if (!theForm.password.value.equals(theForm.passwordrep.value)) {
		alert("Passordene må være like!");
		theForm.password.focus();
		return (false);
	}
	
	if (!rightLength(theForm.Firmanavn.value,0,50,"Firmanavn")){
		theForm.Firmanavn.focus();
		return (false);
	}
	if (!validText(theForm.Firmanavn.value," _-,.&@;:?[]()\/<>","Firmanavn")){
		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("Du må fylle ut Org.nr i tillegg til Firmanavn");
		theForm.Organisasjonsnr.focus();
		return (false);
	}else if (isEmpty(theForm.Firmanavn.value) && !isEmpty(theForm.Organisasjonsnr.value)) {
		alert("Du må fylle ut Firmanavn i tillegg til Org. nr");
		theForm.Firmanavn.focus();
		return (false);
	}
	
	
	if (!rightLength(theForm.Fornavn.value,1,30,"Fornavn")){
		theForm.Fornavn.focus();
		return (false);
	}
	if (!validText(theForm.Fornavn.value," _-,.","Fornavn")){
		theForm.Fornavn.focus();
		return (false);
	}
	if (!rightLength(theForm.Etternavn.value,1,30,"Etternavn")){
		theForm.Etternavn.focus();
		return (false);
	}
	if (!validText(theForm.Etternavn.value," _-,.","Etternavn")){
		theForm.Etternavn.focus();
		return (false);
	}
	
	if (!rightLength(theForm.Adresse.value,0,30,"Adresse")){
		theForm.Adresse.focus();
		return (false);
	}
	if (!validText(theForm.Adresse.value," _-,.:/","Adresse")){
		theForm.Adresse.focus();
		return (false);
	}
	if (!rightLength(theForm.Postnr.value,4,4,"Postnr")){
		theForm.Postnr.focus();
		return (false);
	}
	if (!isInteger(theForm.Postnr.value)){
		alert("Ulovlig format på postnr. Bruk kun heltall!");
		theForm.Postnr.focus();
		return (false);
	}
	if (!rightLength(theForm.Sted.value,1,20,"Sted")){
		theForm.Sted.focus();
		return (false);
	}
	if (!validText(theForm.Sted.value," _-,./","Sted")){
		theForm.Sted.focus();
		return (false);
	}
	if (!rightLength(theForm.Tlfnr.value,1,15,"Telefonnr")){
		theForm.Tlfnr.focus();
		return (false);
	}
	if (!isInteger(theForm.Tlfnr.value)){
		alert("Ulovlig format på telefonnr. Bruk kun heltall!");
		theForm.Tlfnr.focus();
		return (false);
	}

	return true;
}

function ValidateDelivery(theForm){
	
	if (!rightLength(theForm.Navn.value,1,60,"Navn")){
		theForm.Navn.focus();
		return (false);
	}
	if (!validText(theForm.Navn.value," _-,.&@;:?[]()\/<>","Navn")){
		theForm.Navn.focus();
		return (false);
	}
	
	if (!rightLength(theForm.Adresse.value,0,30,"Adresse")){
		theForm.Adresse.focus();
		return (false);
	}
	if (!validText(theForm.Adresse.value," _-,.:/","Adresse")){
		theForm.Adresse.focus();
		return (false);
	}
	if (!rightLength(theForm.Postnr.value,4,4,"Postnr")){
		theForm.Postnr.focus();
		return (false);
	}
	if (!isInteger(theForm.Postnr.value)){
		alert("Ulovlig format på postnr. Bruk kun heltall!");
		theForm.Postnr.focus();
		return (false);
	}
	if (!rightLength(theForm.Sted.value,1,20,"Sted")){
		theForm.Sted.focus();
		return (false);
	}
	if (!validText(theForm.Sted.value," _-,./","Sted")){
		theForm.Sted.focus();
		return (false);
	}
	if (!rightLength(theForm.Tlfnr.value,1,15,"Telefonnr")){
		theForm.Tlfnr.focus();
		return (false);
	}
	if (!isInteger(theForm.Tlfnr.value)){
		alert("Ulovlig format på telefonnr. Bruk kun heltall!");
		theForm.Tlfnr.focus();
		return (false);
	}

	return true;
}

function ValidateProfile(theForm) {
	if (!rightLength(theForm.Firmanavn.value,0,50,"Firmanavn")){
		theForm.Firmanavn.focus();
		return (false);
	}
	if (!validText(theForm.Firmanavn.value," _-,.&@;:?[]()\/<>","Firmanavn")){
		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("Du må fylle ut Org.nr i tillegg til Firmanavn");
		theForm.Organisasjonsnr.focus();
		return (false);
	}else if (isEmpty(theForm.Firmanavn.value) && !isEmpty(theForm.Organisasjonsnr.value)) {
		alert("Du må fylle ut Firmanavn i tillegg til Org. nr");
		theForm.Firmanavn.focus();
		return (false);
	}
	
	
	if (!rightLength(theForm.Fornavn.value,1,30,"Fornavn")){
		theForm.Fornavn.focus();
		return (false);
	}
	if (!validText(theForm.Fornavn.value," _-,.","Fornavn")){
		theForm.Fornavn.focus();
		return (false);
	}
	if (!rightLength(theForm.Etternavn.value,1,30,"Etternavn")){
		theForm.Etternavn.focus();
		return (false);
	}
	if (!validText(theForm.Etternavn.value," _-,.","Etternavn")){
		theForm.Etternavn.focus();
		return (false);
	}
	
	if (!rightLength(theForm.Adresse.value,0,30,"Adresse")){
		theForm.Adresse.focus();
		return (false);
	}
	if (!validText(theForm.Adresse.value," _-,.:/","Adresse")){
		theForm.Adresse.focus();
		return (false);
	}
	if (!rightLength(theForm.Postnr.value,4,4,"Postnr")){
		theForm.Postnr.focus();
		return (false);
	}
	if (!isInteger(theForm.Postnr.value)){
		alert("Ulovlig format på postnr. Bruk kun heltall!");
		theForm.Postnr.focus();
		return (false);
	}
	if (!rightLength(theForm.Sted.value,1,20,"Sted")){
		theForm.Sted.focus();
		return (false);
	}
	if (!validText(theForm.Sted.value," _-,./","Sted")){
		theForm.Sted.focus();
		return (false);
	}
	if (!rightLength(theForm.Tlfnr.value,1,15,"Telefonnr")){
		theForm.Tlfnr.focus();
		return (false);
	}
	if (!isInteger(theForm.Tlfnr.value)){
		alert("Ulovlig format på telefonnr. Bruk kun heltall!");
		theForm.Tlfnr.focus();
		return (false);
	}

	return true;
}

function ValidateTipsoss(theForm){
	if (!rightLength(theForm.Epost.value,1,100,"Din epostadresse")){
		theForm.Epost.focus();
		return (false);
	}
	if (!isEmailAdress(theForm.Epost.value)){
		alert("Epostadressen er ikke gyldig!");
		theForm.Epost.focus();
		return (false);
	}

	if (!rightLength(theForm.Tittel.value,1,200,"Tittel")){
		theForm.Tittel.focus();
		return (false);
	}
	if (!validText(theForm.Tittel.value," _-,.&@;:?![]()\/<>","Tittel")){
		theForm.Tittel.focus();
		return (false);
	}
	
	if (!rightLength(theForm.Tekst.value,1,2000,"Tips")){
		theForm.Tekst.focus();
		return (false);
	}
	if (!validText(theForm.Tekst.value," _-,.&@;:?![]()\/<>","Tekst")){
		theForm.Tekst.focus();
		return (false);
	}
	
	return true;
}
