// 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].organisation_name.value == "")

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

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

    }
	

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

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

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

    }

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

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

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

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

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

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

    }

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

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

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

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

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

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

    }

    if ((document.forms[0].phone_number.value == "") && (document.forms[0].mobile_number.value == "")) 

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

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

    }

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

    {alert("Please enter a valid contact email address");

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

    }


   // test if valid email address, must have @ and .
   var checkEmail = "@.";
   var checkStr =  document.forms[0].contact_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 contact email address.");
 	document.forms[0].contact_email.focus();
	return (false);
   }
	
    if(document.contractor_preassessment["states_in_which_you_operate[]"].value == "")
    {alert("Please select the states in which you operate.");
    return false; }


    if(document.contractor_preassessment["states_in_which_you_have_offices[]"].value == "")
    {alert("Please select the states in which you have offices.");
    return false; }

    if ((document.forms[0].type_of_work_performed.value == "") || (document.forms[0].type_of_work_performed.value == "(brief description)"))

    {alert("Please enter the type of work performed");

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

    }

    var btn = valButton(document.forms[0].are_you_a_principal_contractor);
    if (btn == null) {
    alert("Please specify if you are a principal contractor.");
    return(false);
    }

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

    {alert("Please select the number of employees you have.");

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

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

    {alert("Please select the number of sub-contractors you have.");

    document.forms[0].number_of_subcontractors.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;

}
