// FRA Compliance Javascript

function loadpage() {
	if(document.inputform.elements[0]!=null) {
  if (document.getElementById("focuson").value=="") {
			var i;
			var max = document.inputform.length;
			for(i=0; i<max; i++) {
				if(document.inputform.elements[i].type != "hidden" &&
					!document.inputform.elements[i].disabled &&
					!document.inputform.elements[i].readOnly ) {
					document.inputform.elements[i].focus();
					break;
				}
			}
		}
		else {
   document.getElementById(document.getElementById("focuson").value).focus();
  }
 }
}

function gosubmit() {
	var errs = '';
	var elm = '';

/*
	if (document.getElementById("firstname").value=='') {
		errs+= "* Please complete the first name field\n";
		if (elm=='') {
   elm = 'firstname';
  }
 }
	if (document.getElementById("surname").value=='') {
		errs+= "* Please complete the surname field\n";
		if (elm=='') {
   elm = 'surname';
  }
 }
	if (document.getElementById("company").value=='') {
		errs+= "* Please complete the company field\n";
		if (elm=='') {
   elm = 'company';
  }
 }
	if (document.getElementById("address").value=='') {
		errs+= "* Please complete the address field\n";
		if (elm=='') {
   elm = 'address';
  }
 }
	if (document.getElementById("phone").value=='') {
		errs+= "* Please complete the contact phone number field\n";
		if (elm=='') {
   elm = 'phone';
  }
 }
	if (document.getElementById("email").value=='') {
		errs+= "* Please complete the e-mail address field\n";
		if (elm=='') {
   elm = 'email';
  }
 }
	if (!validemail(document.getElementById("email").value) && document.getElementById("email").value!='') {
		errs+= "* Please enter a valid e-mail address\n";
		if (elm=='') {
   elm = 'email';
  }
	}
	if (document.getElementById("noemployees").selectedIndex==0) {
		errs+= "* Please select the number of employees\n";
		if (elm=='') {
   elm = 'noemployees';
  }
 }
	if (!document.inputform.q1[0].checked && !document.inputform.q1[1].checked) {
		errs+= "* Please answer question 1\n";
 }
	if (!document.inputform.q2[0].checked && !document.inputform.q2[1].checked) {
		errs+= "* Please answer question 2\n";
 }
	if (!document.inputform.q3[0].checked && !document.inputform.q3[1].checked) {
		errs+= "* Please answer question 3\n";
 }
	if (!document.inputform.q4[0].checked && !document.inputform.q4[1].checked) {
		errs+= "* Please answer question 4\n";
 }
	if (!document.inputform.q5[0].checked && !document.inputform.q5[1].checked) {
		errs+= "* Please answer question 5\n";
 }
	if (!document.inputform.q6[0].checked && !document.inputform.q6[1].checked) {
		errs+= "* Please answer question 6\n";
 }
*/

	if (errs=='') {
  document.getElementById("actn").value = "submit";
	 document.inputform.submit();
	}
	else {
		alert('Please correct the following errors:\n\n'+errs);
		return false;
	}
}

function goback() {
 var loc = document.getElementById("refURI").value;
	window.location = loc;
}



function validemail(email) {
	var at="@"
	var dot="."
	var lat=email.indexOf(at)
	var lstr=email.length
	var ldot=email.indexOf(dot)
	if (email.indexOf(at)==-1) {
		return false;
	}
	if (email.indexOf(at)==-1 || email.indexOf(at)==0 || email.indexOf(at)==lstr) {
		return false;
	}
	if (email.indexOf(dot)==-1 || email.indexOf(dot)==0 || email.indexOf(dot)==lstr) {
		return false;
	}
	if (email.indexOf(at,(lat+1))!=-1) {
		return false;
	}
	if (email.substring(lat-1,lat)==dot || email.substring(lat+1,lat+2)==dot) {
		return false;
	}
	if (email.indexOf(dot,(lat+2))==-1) {
		return false;
	}
	if (email.indexOf(" ")!=-1) {
		return false;
	}
	return true;
}