// JavaScript Document

function returnObjById( id ) 
 { 
  if(document.getElementById) 
  var returnVar = document.getElementById(id);
  else if (document.all)
  var returnVar = document.all[id];
  else if (document.layers)
  var returnVar = document.layers[id];
  return returnVar;
 } 



function isEmailAddr (s){ 
	var rv = false
	if ((s == null) || (s.length == 0)) 
       rv = false;
  else {
		var reEmail =/([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		//reEmail = /.+\@.+\..+$/
		
		rv = reEmail.test(s)
    }
	if(rv){
	return rv
	}else{
		return false
	}
}
 
 function brochureOrderPublic(theForm){
  if (theForm.name.value == ""){
    alert("Please enter your name.");
    theForm.name.focus();
    return (false);
  }
  if (theForm.address.value == ""){
    alert("Please enter a delivery address.");
    theForm.address.focus();
    return (false);
  }
  if (theForm.city.value == ""){
    alert("Please enter a delivery city.");
    theForm.city.focus();
    return (false);
  }
  var c = 0
  for (i = 0; i < theForm.brochures.length; i++){
		if(theForm.brochures[i].checked){
			c = "true"
			break;
		}
  }
  if (c == 0){
    alert("Please tick at least one brochure.");
    theForm.brochures[0].focus();
    return (false);
  }
  if (!isEmailAddr(theForm.email_from.value)){
    alert("Please enter a complete email address in the form: yourname@yourdomain.com");
    theForm.email_from.focus();
    return (false);
  }
return true
 }
 
  function brochureOrderGP(theForm){
  if (theForm.gpname.value == ""){
    alert("Please enter your GP name.");
    theForm.gpname.focus();
    return (false);
  }
  if (theForm.name.value == ""){
    alert("Please enter your name.");
    theForm.name.focus();
    return (false);
  }
  if (theForm.address.value == ""){
    alert("Please enter a delivery address.");
    theForm.address.focus();
    return (false);
  }
  if (theForm.city.value == ""){
    alert("Please enter a delivery city.");
    theForm.city.focus();
    return (false);
  }
  if (!isEmailAddr(theForm.email_from.value)){
    alert("Please enter a complete email address in the form: yourname@yourdomain.com");
    theForm.email_from.focus();
    return (false);
  }
return true
 }
 
function newsletterS(theForm){
  if (theForm.name.value == ""){
    alert("Please enter your name.");
    theForm.name.focus();
    return (false);
  }
  if (!isEmailAddr(theForm.email.value)){
    alert("Please enter a complete email address in the form: yourname@yourdomain.com");
    theForm.email.focus();
    return (false);
  }
return true
 }
 
function preffer(theForm){
  if (theForm.PatientName.value == ""){
    alert("Please enter the Patients name.");
    theForm.PatientName.focus();
    return (false);
  }
  if (!isEmailAddr(theForm.email_from.value)){
    alert("Please enter a complete email address in the form: yourname@yourdomain.com");
    theForm.email_from.focus();
    return (false);
  }
return true
 }
 
 function toggleLayer(whichLayer)
{
if (document.getElementById)
{
// this is the way the standards work
var style2 = document.getElementById(whichLayer);
style2.style.display = "block";
}
else if (document.all)
{
// this is the way old msie versions work
var style2 = document.all[whichLayer]
style2.style.display = "block";
}
else if (document.layers)
{
// this is the way nn4 works
var style2 = document.layers[whichLayer];
style2.style.display = "block";
}

return style2
}

 
 //For are you a candidate? page
function checker(theForm){
	
	var no = false
	
	var noText = "Laser surgery is probably NOT the right surgery for you, but there may be other options that can be discussed with you. Please <a href=\"index.asp?pageID=2145835609\">call or email</a> us for more information."
	var yesText = "You should be suitable for LASIK. For more information, or to make a booking for an assessment, please contact us <a href=\"mailto:admin@aucklandeye.co.nz\">admin@aucklandeye.co.nz</a>"
	
	if(!theForm.radio1[0].checked && !theForm.radio1[1].checked){
		alert("Please answer if you are 20 years of age or older?")
		return false
	}else if(theForm.radio1[1].checked){
		no = true
	}
	
	if(!theForm.radio2[0].checked && !theForm.radio2[1].checked){
		alert("Please answer if your prescription has been stable for approximately 2 years?")
		return false
	}else if(theForm.radio2[1].checked){
		no = true
	}
	
	if(!theForm.radio3[0].checked && !theForm.radio3[1].checked){
		alert("Please answer if your eyes are healthy, apart from the need for glasses/contact lenses?")
		return false
	}else if(theForm.radio3[1].checked){
		no = true
	}
	
	if(!theForm.radio4[0].checked && !theForm.radio4[1].checked){
		alert("Please answer if you only wear glasses for closework eg reading, computer work, needlework etc?")
		return false
	}else if(theForm.radio4[0].checked){
		no = true
	}
	
	var div = toggleLayer('candidate')
	
	if(no)
		div.innerHTML = noText
	else
		div.innerHTML = yesText

return false
}

function referrerForm(theForm){
	if (theForm.name.value == ""){
    alert("Please enter your name.");
    theForm.name.focus();
    return (false);
  }
	if (theForm.surname.value == ""){
    alert("Please enter your surname.");
    theForm.surname.focus();
    return (false);
  }
	if (theForm.company.value == ""){
    alert("Please enter your company.");
    theForm.company.focus();
    return (false);
  }
  if (theForm.address.value == ""){
    alert("Please enter your address.");
    theForm.address.focus();
    return (false);
  }
  if (theForm.city.value == ""){
    alert("Please enter your city.");
    theForm.city.focus();
    return (false);
  }
  if (theForm.phone.value == ""){
    alert("Please enter a contact phone number.");
    theForm.phone.focus();
    return (false);
  }
  if (!isEmailAddr(theForm.email.value)){
    alert("Please enter a complete email address in the form: yourname@yourdomain.com");
    theForm.email.focus();
    return (false);
  }
  if (theForm.password.value == ""){
    alert("Please enter a password.");
    theForm.password.focus();
    return (false);
  }
  if (theForm.password.value.length < 5){
    alert("Your password needs to be at least 5 characters long.");
    theForm.password.focus();
    return (false);
  }
return true
}

function password(theForm){
	if (!isEmailAddr(theForm.email.value)){
    alert("Please enter a complete email address in the form: yourname@yourdomain.com");
    theForm.email.focus();
    return (false);
  }
return true
}



function insight(){
	var f = returnObjById('seminars')
	var counter = 0
	f.sem[0].checked = false
	f.sem[1].checked = false
	f.sem[2].checked = false
	if(f.seminar1.checked)
		f.sem[0].checked = true
	if(f.seminar2.checked)
		f.sem[1].checked = true
	if(f.seminar3.checked)
		f.sem[2].checked = true

}

function insightvalidation(theForm){
	if (theForm.name.value == ""){
    alert("Please enter your name.");
    theForm.name.focus();
    return (false);
  }
	if (theForm.practice.value == ""){
    alert("Please enter your practice name.");
    theForm.practice.focus();
    return (false);
  }
	if (theForm.street_address.value == ""){
    alert("Please enter your street address.");
    theForm.street_address.focus();
    return (false);
  }
  if (theForm.phone.value == ""){
    alert("Please enter your phone number (work).");
    theForm.phone.focus();
    return (false);
  }
  if (!isEmailAddr(theForm.email_from.value)){
    alert("Please enter a complete email address in the form: yourname@yourdomain.com");
    theForm.email_from.focus();
    return (false);
  }
  if(!theForm.seminar1.checked && !theForm.seminar2.checked && !theForm.seminar3.checked){
    alert("Please tick a seminar you would like to attend.");
    theForm.seminar1.focus();
    return (false);
  }
  if(theForm.seminar1.checked && theForm.Seminar1_date.value == ""){
    alert("Please select the date you would like to attend seminar 1.");
    theForm.Seminar1_date.focus();
    return (false);
  }
   if(theForm.seminar3.checked && theForm.Seminar3_date.value == ""){
    alert("Please select the date you would like to attend seminar 3.");
    theForm.Seminar3_date.focus();
    return (false);
  }
return true
}



function register(theForm){
	if (theForm.aenumber.value == ""){
    alert("Please enter your Auckland Eye number.");
    theForm.aenumber.focus();
    return (false);
  }
  if (theForm.name.value == ""){
    alert("Please enter your full name.");
    theForm.name.focus();
    return (false);
  }
  if (!isEmailAddr(theForm.email.value)){
    alert("Please enter a complete email address in the form: yourname@yourdomain.com");
    theForm.email.focus();
    return (false);
  }
  if (theForm.address.value == ""){
    alert("Please enter your address.");
    theForm.address.focus();
    return (false);
  }
  if (theForm.password.value == ""){
    alert("Please enter a password.");
    theForm.password.focus();
    return (false);
  }
  if (theForm.password.value != theForm.confirmp.value){
    alert("Your password don't match.");
    theForm.password.focus();
    return (false);
  }
  if(!theForm.terms.checked){
    alert("Please accept the Terms and Conditions.");
    theForm.terms.focus();
    return (false);
  }
return true
}

function appointment(theForm){
if (theForm.name.value == ""){
    alert("Please enter your full name.");
    theForm.name.focus();
    return (false);
  }  
  if (!isEmailAddr(theForm.email_from.value)){
    alert("Please enter a complete email address in the form: yourname@yourdomain.com");
    theForm.email_from.focus();
    return (false);
  }

  if (theForm.Phone.value == ""){
    alert("Please enter a daytime contact number.");
    theForm.Phone.focus();
    return (false);
  }
  if (theForm.Reason_for_appointment.value == ""){
    alert("What is your reason for the appointment.");
    theForm.Reason_for_appointment.focus();
    return (false);
  }
return true
}