var Mail = {
	submitEmailForm : function() {
		 try {
		 var err=""
		 if(document.getElementById("_fornavn").value=="") {
		 	err+="- Vennligst fyll inn fornavn\n";
		 }
		 if(document.getElementById("_etternavn").value=="") {
		 	err+="- Vennligst fyll inn etternavn\n";
		 }
		 if(!this.check_Email(document.getElementById("_epost").value)) {
		 	err+="- E-post er ugyldig\n";
		 }
		 
		 if(document.getElementById("_telefon").value=="") {
		 	err+="- Vennligst fyll inn telefonnummer\n";
		 }
		 if(err=="") {
			 if(confirm("Er all informasjon korrekt?")) {
				 ImperialAjax_MailForm.sendMail(
				 	document.getElementById("_fornavn").value, 
				 	document.getElementById("_etternavn").value, 
				 	document.getElementById("_epost").value, 
				 	document.getElementById("_telefon").value);
				}
		}
		else {
			err="Meldingen kan ikke sendes. Noen felt mangler informasjon:\n\n"+err;
			alert(err);
		}
	}
	catch(ex) {
		
	}
		return false;
	},
	check_Email : function(email) {
		return email.match(/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/);
	},
	disable_Submit : function(bool) {
		document.getElementById("_submitcmd").disabled=bool;
	},
	setValue : function(el,val) {
		el.value=val;
	},
	setValue_onFocus : function(el,val) {
		if(el.value=="") {
			this.setValue(el,val);
		}
	},
	setValue_onBlur : function(el,val) {
		if(el.value=="") {
			this.setValue(el,val);
		}
	}
}

var ImperialAjax_MailForm = {
	sendMail : function(from_firstname, from_surname, from_email, from_phone) {
		new ImperialAjax_MailForm_Send(from_firstname, from_surname, from_email, from_phone);
	}
} 

 /** Using AJAX to send an e-mail. Implementing code from SACK v1.6.1 **/
function ImperialAjax_MailForm_Send(from_firstname, from_surname, from_email, from_phone) {
	  var ajaxObj = new sack();
		try {
				
				ajaxObj.requestFile ='plugins/ajax/mail/sendmail.asp?fromfirstname=' + from_firstname  + '&fromsurname=' + from_surname  + '&fromemail=' + from_email  + '&fromphone=' + from_phone;
				ajaxObj.onCompletion = function() { 
					showClientData(ajaxObj); 
				};
				ajaxObj.runAJAX();	
		}
		catch(e) { alert("0x00: " + e.description); }
		
		function showClientData(ajaxObj) {
			try {
				var formObj = document.forms["_contactform"];	
				eval(ajaxObj.response);
			}
			catch(ex) { alert("0x01: "+ ex.description); }			
		}
}