// JavaScript Document


  if(window.attachEvent)
    window.attachEvent("onload",setListeners);

  function setListeners(){
    inputList = document.getElementsByTagName("INPUT");
    for(i=0;i<inputList.length;i++){
      inputList[i].attachEvent("onpropertychange",restoreStyles);
      inputList[i].style.backgroundColor = "";
    }
    selectList = document.getElementsByTagName("SELECT");
    for(i=0;i<selectList.length;i++){
      selectList[i].attachEvent("onpropertychange",restoreStyles);
      selectList[i].style.backgroundColor = "";
    }
  }

  function restoreStyles(){
    if(event.srcElement.style.backgroundColor != "")
      event.srcElement.style.backgroundColor = "";
  }


// Radio Button Validation
// copyright Stephen Chapman, 15th Nov 2004,14th Sep 2005
// you may copy this function but please keep the copyright notice with it
function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}
  

 function validateForm(TSA)

{

    if (document.forms[0].type_of_manual_required.selectedIndex <= 0)

    {alert("Please select the type of manual required.");

    document.forms[0].type_of_manual_required.focus();return (false);

    }

    if (document.forms[0].ceo_director_company_responsible_person.value == "")

    {alert("Please enter the CEO/Director/Company Responsible Person.");

    document.forms[0].ceo_director_company_responsible_person.focus();return(false)

    }

    // check if email field is blank
    if (document.forms[0].ceo_director_company_responsible_person_email.value == "")

    {alert("Please enter the CEO/Director/Company Responsible Person email address.");

    document.forms[0].ceo_director_company_responsible_person_email.focus();return (false);

    }


   // test if valid email address, must have @ and .
   var checkEmail = "@.";
   var checkStr =  document.forms[0].ceo_director_company_responsible_person_email.value;
   var EmailValid = false;

   var EmailAt = false;
   var EmailPeriod = false;
   for (i = 0;  i < checkStr.length;  i++)
   {
	ch = checkStr.charAt(i);
  	for (j = 0;  j < checkEmail.length;  j++)
	{
		if (ch == checkEmail.charAt(j) && ch == "@")
			EmailAt = true;
		if (ch == checkEmail.charAt(j) && ch == ".")
			EmailPeriod = true;
	  	if (EmailAt && EmailPeriod)
			break;
	 	if (j == checkEmail.length)
			break;
	}
	// if both the @ and . were in the string
	if (EmailAt && EmailPeriod)
	{
		EmailValid = true
		break;
	}
   }
   if (!EmailValid)
   {
	alert("Please enter a valid CEO/Director/Company Responsible Person email address.");
 	document.forms[0].ceo_director_company_responsible_person_email.focus();
	return (false);
   }
    // check if first contact repeat email field is blank
    if (document.forms[0].ceo_director_company_responsible_person_email_2.value == "")

    {alert("Please re-enter the CEO/Director/Company Responsible Person email address.");

    document.forms[0].ceo_director_company_responsible_person_email_2.focus();return (false);

    }
    if (document.forms[0].ceo_director_company_responsible_person_email.value != document.forms[0].ceo_director_company_responsible_person_email_2.value)

    {alert("The CEO/Director/Company Responsible Person emails you entered do not match - please re-enter the CEO/Director/Company Responsible Person email address.");

    document.forms[0].ceo_director_company_responsible_person_email_2.focus();return (false);

    }



    if (document.forms[0].HSEQ_admin_manager.value == "")

    {alert("Please enter the HSEQ/Admin Manager.");

    document.forms[0].HSEQ_admin_manager.focus();return(false)

    }

    // check if email field is blank
    if (document.forms[0].HSEQ_admin_manager_email.value == "")

    {alert("Please enter the HSEQ/Admin Manager email address.");

    document.forms[0].HSEQ_admin_manager_email.focus();return (false);

    }


   // test if valid email address, must have @ and .
   var checkEmail = "@.";
   var checkStr =  document.forms[0].HSEQ_admin_manager_email.value;
   var EmailValid = false;

   var EmailAt = false;
   var EmailPeriod = false;
   for (i = 0;  i < checkStr.length;  i++)
   {
	ch = checkStr.charAt(i);
  	for (j = 0;  j < checkEmail.length;  j++)
	{
		if (ch == checkEmail.charAt(j) && ch == "@")
			EmailAt = true;
		if (ch == checkEmail.charAt(j) && ch == ".")
			EmailPeriod = true;
	  	if (EmailAt && EmailPeriod)
			break;
	 	if (j == checkEmail.length)
			break;
	}
	// if both the @ and . were in the string
	if (EmailAt && EmailPeriod)
	{
		EmailValid = true
		break;
	}
   }
   if (!EmailValid)
   {
	alert("Please enter a valid HSEQ/Admin Manager email address.");
 	document.forms[0].HSEQ_admin_manager_email.focus();
	return (false);
   }
    // check if HSEQ/Admin Manager repeat email field is blank
    if (document.forms[0].HSEQ_admin_manager_email_2.value == "")

    {alert("Please re-enter the HSEQ/Admin Manager email address.");

    document.forms[0].HSEQ_admin_manager_email_2.focus();return (false);

    }
    if (document.forms[0].HSEQ_admin_manager_email.value != document.forms[0].HSEQ_admin_manager_email_2.value)

    {alert("The HSEQ/Admin Manager emails you entered do not match - please re-enter the HSEQ/Admin Manager email address.");

    document.forms[0].HSEQ_admin_manager_email_2.focus();return (false);

    }



    if (document.forms[0].contractor_name.value == "")

    {alert("Please enter the Contractor name.");

    document.forms[0].contractor_name.focus();return (false);

    }

    if (document.forms[0].trading_name.value == "")

    {alert("Please enter the Trading name.");

    document.forms[0].trading_name.focus();return (false);

    }

    if (document.forms[0].ABN.value == "")

    {alert("Please enter the ABN.");

    document.forms[0].ABN.focus();return (false);

    }

    if ((document.forms[0].address_1.value == "") && (document.forms[0].address_2.value == ""))

    {alert("Please enter the trading address.");

    document.forms[0].address_1.focus();return(false)

    }
	
    if (document.forms[0].suburb.value == "")

    {alert("Please enter the trading address suburb.");

    document.forms[0].suburb.focus();return(false)

    }

    if (document.forms[0].post_code.value == "")

    {alert("Please enter the trading address post code.");

    document.forms[0].post_code.focus();return(false)

    }
	
    if ((document.forms[0].company_phone.value == "") && (document.forms[0].company_mobile.value == "")) 

    {alert("Please enter a company phone number.");

    document.forms[0].company_phone.focus();return (false);

    }

    // check if administration email field is blank
    if (document.forms[0].administration_email.value == "")

    {alert("Please enter an administration email address.");

    document.forms[0].administration_email.focus();return (false);

    }


   // test if valid email address, must have @ and .
   var checkEmail = "@.";
   var checkStr =  document.forms[0].administration_email.value;
   var EmailValid = false;

   var EmailAt = false;
   var EmailPeriod = false;
   for (i = 0;  i < checkStr.length;  i++)
   {
	ch = checkStr.charAt(i);
  	for (j = 0;  j < checkEmail.length;  j++)
	{
		if (ch == checkEmail.charAt(j) && ch == "@")
			EmailAt = true;
		if (ch == checkEmail.charAt(j) && ch == ".")
			EmailPeriod = true;
	  	if (EmailAt && EmailPeriod)
			break;
	 	if (j == checkEmail.length)
			break;
	}
	// if both the @ and . were in the string
	if (EmailAt && EmailPeriod)
	{
		EmailValid = true
		break;
	}
   }
   if (!EmailValid)
   {
	alert("Please enter a valid administration email address.");
 	document.forms[0].administration_email.focus();
	return (false);
   }
    // check if contact repeat email field is blank
    if (document.forms[0].administration_email_2.value == "")

    {alert("Please re-enter the administration email address.");

    document.forms[0].administration_email_2.focus();return (false);

    }
    if (document.forms[0].administration_email.value != document.forms[0].administration_email_2.value)

    {alert("The administration emails you entered do not match - please re-enter the administration email address.");

    document.forms[0].administration_email_2.focus();return (false);

    }


    if (document.forms[0].ceo_director_managing_director.value == "")

    {alert("Please enter the CEO/Director/Managing Director.");

    document.forms[0].ceo_director_managing_director.focus();return (false);

    }

    if (!(document.forms[0].read_and_accepted_terms_and_conditions.checked)) {
    alert("Please read the Terms and Conditions and check the accept box if you accept them.");
    return false;
    }

    if (!(document.forms[0].declare_information_is_correct.checked)) {
    alert("Please declare that the information provided is correct");
    return false;
    }

    if (document.forms[0].name.value == "")

    {alert("You did not enter your name. Please enter your name in the field provided");

    document.forms[0].name.focus();return(false)

    }

    if ((document.forms[0].date_day.selectedIndex <= 0) || (document.forms[0].date_month.selectedIndex <= 0) || (document.forms[0].date_year.selectedIndex <= 0))

    {alert("Please enter the declaration date.");

    document.forms[0].date_day.focus();return (false);

    }


}



 function validateSearchForm(TSA)

{

var e, i = 0, checked = false;
while (e = TSA.elements[i++]) {if (e.type == 'checkbox' && e.checked) checked = true};
if (!checked) alert ("You did not select any positions to view. Please select the positions you would like to view");
return checked;

}
