// JavaScript Document
function ValidateForm() {
	var bolSubmitForm = true;
	$(".Req").each(function(){
		ErrorType = "";
		if($(this).hasClass("Text")){
			if(this.value.match(/[A-Za-z0-9]/gi)==null){
				ErrorType = "Text";
			}
		}
		if($(this).hasClass("Email")) {
			if(this.value.match(/\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b/gi)==null){
				ErrorType = "Email";
			}
		}
		if($(this).hasClass("Password")) {
			if(this.value.match(/^(?=.{7,})(((?=.*[a-z])(?=.*[0-9]))).*$/g)==null){
				ErrorType = "Password";
			}
		}
		if($(this).hasClass("isNumber")) {
			//this.value = this.value.replace(/,/g,".");
			if(isNaN(this.value)){
				ErrorType = "isNumber";
			}
		}
		if($(this).hasClass("Select")) {
			if(this.options[this.selectedIndex].value==0){
				ErrorType = "Select";
			}
		}
		if($(this).hasClass("DatoFormat")) {
			var regDateFormat = new RegExp(/^[0-3][0-9]-(0|1)[0-9]-(19|20)[0-9]{2}/)
			//alert(this.value.match(regDateFormat));
			if(this.value.match(regDateFormat)==null){
				ErrorType = "DatoFormat";
			}
			else
			{
				var arrDate = this.value.split("-");
				if(arrDate[0]==0 || arrDate[0]>31 || arrDate[1]==0 || arrDate[1]>12 || arrDate[2]<1900) ErrorType = "DatoFormat";
			}
		}
		
		if(ErrorType!=""){
			if(!$(this).hasClass("Error")) {
				$(this).after(htmlErrorMsg(ErrorType));
			}
			$(this).addClass("Error");
			bolSubmitForm = false;
		}
		else if($(this).hasClass("Error"))
		{
			$(this).removeClass("Error");
			this.parentNode.childNodes[1].style.display="none";
		}
		else
		{
			if(bolSubmitForm) bolSubmitForm = true;
		}
	});
	if(bolSubmitForm) {
		return true;
	}
	else {
		return false;
	}
}


var ErrorMsgId = 0;
function htmlErrorMsg(errType) {
	var strErrorMsg = "";
	switch(errType) {
		case 'Text':
			strErrorMsg = "<b>Dette felt skal udfyldes!</b><br />Venligst udfyld feltet.";
			break;
		case 'Email':
			strErrorMsg = "<b>Formatet p&aring; e-mail adressen er ikke korrekt!</b><br />Venligst udfyld feltet med en gyldig e-mail address.";
			break;
		case 'Password':
			strErrorMsg = "Dit kodeord skal v&aelig;re mindst 8 karakterer langt, og det skal indeholde b&aring;de tal og bogstaver.";
			break;
		case 'DateDay':
			strErrorMsg = "<b>The day format is not correct!</b><br />Please type in a number between 1 and 31";
			break;
		case 'DateMonth':
			strErrorMsg = "<b>The month format is not correct!</b><br />Please type in a number between 1 and 12 ";
			break;
		case 'DateYear':
			strErrorMsg = "<b>The year format is not correct!</b><br />Please type in a 4 digit number.";
			break;
		case 'isNumber':
			strErrorMsg = "<b>Dette felt m&aring; kun indehold tal!</b><br />Venligst udfyld feltet med et nummer.";
			break;
		case 'Select':
			strErrorMsg = "<b>Intet valgt!</b><br />Venligst v&aelig;lg et punkt p&aring; listen.";
			break;
		case 'DatoFormat':
			strErrorMsg = "<b>Dato formatet er ikke korrekt!</b><br />Det skal skrives i f&oslash;lgende format 24-12-2009.";
			break;
	}
	strOutput = '<div class="ErrorIcon" style="position:relative;">';
	strOutput += '<a href="javascript:void(0)" onmouseover="showErrMsg('+ErrorMsgId+',1)" onmouseout="showErrMsg('+ErrorMsgId+',0)"><img src="/files/system/morsoe/graphics/FormFieldErrorInfoIcon.gif" width="15" height="14" border="0"></a>';
	strOutput += '<div class="ErrorMsg'+ErrorMsgId+' ErrDisplay Hide" style="position:absolute; z-index:2;"><img src="/files/system/morsoe/graphics/FormFieldErrorInfoBoxArrow.gif" style="position:absolute; z-index:1; left:-7px; top:13px;" />'+strErrorMsg+'</div></div>';
	ErrorMsgId++;
	return strOutput;
}

function showErrMsg(displayNum,displayState) {
	if(displayState==1) {
		$(".ErrorMsg"+displayNum).removeClass("Hide")
	}
	else
	{
		$(".ErrorMsg"+displayNum).addClass("Hide")
	}
}