function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}


function formValidater() {
	var valid = true;
	
	if (document.application.firstname.value == "" || document.application.lastname.value == "") {
	   alert('Name must be filled out');
	   document.application.firstname.focus();
	   valid = false;
	} else if (echeck(document.application.email.value)==false || document.application.email.value=="") {
	   alert('E-mail address invalid');
	   document.application.email.focus();
	   valid = false;
	} else if (isNaN(parseInt(document.application.mobile.value))) {
	   alert('Mobile has to be numbers');
	   document.application.mobile.focus();
	   valid = false;
	} else if (document.application.address1.value == "") {
	   alert('Address must be filled out');
	   document.application.address1.focus();
	   valid = false;
	} else if (document.application.zipcode.value == "") {
	   alert('Area code must be filled out');
	   document.application.zipcode.focus();
	   valid = false;
	} else if (document.application.location.value == "") {
	   alert('Place must be filled out');
	   document.application.location.focus();
	   valid = false;
	} else if (document.application.attachment_cv.value == "" && document.application.attachment_letter.value == "") {
	   alert('You must send in either CV or letter to submit the application.');
	   valid = false;
	} 
	
	if (document.application.attachment_cv.value != ""){
		var ext_cv = $('#attachment_cv').val().split('.').pop().toLowerCase();
		
		if($.inArray(ext_cv, ['doc','rtf','docx','xls','xlsx','pdf']) == -1) {
			alert('CV contains an illegal fileformat. Legal: Word, Acrobat og Excel.');
			valid = false;
		}
	}
	
	if (document.application.attachment_letter.value != ""){
		var ext_letter = $('#attachment_letter').val().split('.').pop().toLowerCase();
		
		if($.inArray(ext_letter, ['doc','rtf','docx','xls','xlsx','pdf']) == -1) {
			alert('Application letter contains an illegal fileformat. Legal: Word, Acrobat og Excel.');
			valid = false;
		}
	}

	return valid;
 
}
