/* Kontrollerar fält i registreringsformulär för nyhetsbrev */
function checkNewsletterReg(theForm){
	var errorMsg = "";
	var focusSet = false;
	if(theForm.firstname.value.length <= 0){
		errorMsg += "Förnamn\n";
		theForm.firstname.focus();
		focusSet = true;
	}
	
	if(theForm.lastname.value.length <= 0) {
		errorMsg += "Efternamn\n";
		if(!focusSet){
			theForm.lastname.focus();
			focusSet = true;
		}
	}
	
	if(theForm.email.value.length <= 0) {
		errorMsg += "E-post\n";
		if(!focusSet){
			theForm.email.focus();
			focusSet = true;
		}
		
	}
	
	if(errorMsg.length > 0){
		alert("Du glömde fylla i följande fält:\n" + errorMsg);
		return false;
	} else {
		return true;
	}
}

/* Kontrollerar fält i inloggningsformulär för nyhetsbrev */
function checkNewsletterLogin(theForm){
	var errorMsg = "";
	var focusSet = false;

	if(theForm.email.value.length <= 0) {
		errorMsg += "E-post\n";
		theForm.email.focus();		
	}
	
	if(errorMsg.length > 0){
		alert("Du glömde fylla i följande fält:\n" + errorMsg);
		return false;
	} else {
		return true;
	}
}

/* Kontrollerar fält i uppdateringsformulär för nyhetsbrev */
function checkNewsletterChange(theForm){
	var errorMsg = "";
	var focusSet = false;
	if(theForm.firstname.value.length <= 0){
		errorMsg += "Förnamn\n";
		theForm.firstname.focus();
		focusSet = true;
	}
	
	if(theForm.lastname.value.length <= 0) {
		errorMsg += "Efternamn\n";
		if(!focusSet){
			theForm.lastname.focus();
			focusSet = true;
		}
	}
	
	if(theForm.email.value.length <= 0) {
		errorMsg += "E-post\n";
		if(!focusSet){
			theForm.email.focus();
			focusSet = true;
		}
		
	}
	
	if(errorMsg.length > 0){
		alert("Du glömde fylla i följande fält:\n" + errorMsg);
		return false;
	} else {
		return true;
	}
}

/* Kontrollerar fält i kommentarformulär */
function checkCommentary(theForm){
	var errorMsg = "";
	var focusSet = false;
	if(theForm.title.value.length <= 0){
		errorMsg += "Titel\n";
		theForm.title.focus();
		focusSet = true;
	}
	
	if(theForm.message.value.length <= 0) {
		errorMsg += "Text\n";
		if(!focusSet){
			theForm.message.focus();
			focusSet = true;
		}
	}
	
	if(theForm.name.value.length <= 0) {
		errorMsg += "Namn\n";
		if(!focusSet){
			theForm.name.focus();
			focusSet = true;
		}
	}
	
	if(theForm.email.value.length <= 0) {
		errorMsg += "E-post\n";
		if(!focusSet){
			theForm.email.focus();
			focusSet = true;
		}
	}	
	
	if(errorMsg.length > 0){
		alert("Du glömde fylla i följande fält:\n" + errorMsg);
		return false;
	} else {
		return true;
	}
}

/* Kontrollar fält i sökformulär för "hästmarknaden" */
function checkHorsesearch(theForm)
{
	if (theForm.Tag_Dep.selectedIndex==0)
	{
		alert("Du måste välja en kategori för att kunna söka!");
		return false;
	}
	if (theForm.Wordsearch.value=="")
	{
		alert("Du måste skriva något i fritext för att kunna söka!");
		return false;
	}
}


/* Kontrollerar fält i formulär för tävling */
function checkCompetition(theForm){
	var errorMsg = "";
	var focusSet = false;
	
	//Namn
	if(theForm.name.value.length <= 0) {
		errorMsg += "Namn\n";
		if(!focusSet){
			theForm.name.focus();
			focusSet = true;
		}
	}

	//Adress
	if(theForm.commentary.value.length <= 0) {
		errorMsg += "Adress\n";
		if(!focusSet){
			theForm.commentary.focus();
			focusSet = true;
		}
	}

	if(errorMsg.length > 0){
		alert("Du glömde fylla i följande fält:\n" + errorMsg);
		return false;
	} else {
		return true;
	}	
}

/*Kontrollerar fält i formulär för webacl registrering för bonussidorna*/
function checkBonusReg(theForm){
	
	var browserName = navigator.appName; //tar fram browsertyp

	var errorMsg = "";
	var focusSet = false;
	
	if(theForm.email.value.length <= 0) {
		errorMsg += "E-post\n";
		if(!focusSet){
			theForm.email.focus();
			focusSet = true;
		}
	}
	
	if(document.layer || browserName == "Netscape") {
		if (theForm.email.value.indexOf("@") < 2) {
			errorMsg += "E-post (ej en korrekt e-post adress) \n";
			if(!focusSet){
				theForm.email.focus();
				focusSet = true;
			}		
		}
	} else {
		var regEmail = new RegExp("^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]{2,}[.][a-zA-Z]{2,5}$");
		if (!regEmail.test(theForm.email.value)) {
			errorMsg += "E-post (ej en korrekt e-post adress) \n";
			if(!focusSet){
				theForm.email.focus();
				focusSet = true;
			}
		}
	}	

	if ((theForm.confemail.value != theForm.email.value)) {
		errorMsg += "E-postadress (matchar inte den bekräftade e-postadressen)\n"; 
		if(!focusSet){
			theForm.confpassword.focus();
			focusSet = true;
		}
	}	

	if (theForm.password.value.length < 4 ) {
		errorMsg += "Lösenord (måste vara minst 4 tecken)\n";
		if(!focusSet){
			theForm.password.focus();
			focusSet = true;
		}
	}
	
	if ((theForm.confpassword.value != theForm.password.value)) {
		errorMsg += "Lösenord (matchar inte det bekräftade lösenordet)\n"; 
		if(!focusSet){
			theForm.confpassword.focus();
			focusSet = true;
		}
	}	

	if(theForm.confpassword.value.length <= 0) {
		errorMsg += "Bekräfta lösenord\n";
		if(!focusSet){
			theForm.confpassword.focus();
			focusSet = true;
		}
	}		
		
	if(theForm.firstname.value.length <= 0){
		errorMsg += "Förnamn\n";
		if(!focusSet){
			theForm.firstname.focus();
			focusSet = true;
		}
	}
	
	if(theForm.lastname.value.length <= 0) {
		errorMsg += "Efternamn\n";
		if(!focusSet){
			theForm.lastname.focus();
			focusSet = true;
		}
	}
	

	if(errorMsg.length > 0){
		alert("Följande fält är inte korrekt ifyllda:\n" + errorMsg);
		return false;
	} else {
		return true;
	}
}