// 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.asbestos_registration["states_in_which_you_operate[]"].value == "")
    {alert("Please select the states in which you operate.");
    return false; }


    if(document.asbestos_registration["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);

    }


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

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

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

    }

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

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

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

    }

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

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

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

    }

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

    {alert("You did not enter the number of building levels. Please enter the number of building levels in the field provided");

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

    }

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

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

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

    }

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

    {alert("You did not enter the number of buildings. Please enter the number of buildings in the field provided");

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

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

    {alert("Please enter the number of lifts.");

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

    }

    var btn = valButton(document.forms[0].ducted_air_conditioning_building_1_site_1);
    if (btn == null) {
    alert("Please specify if the building has ducted air conditioning.");
    return(false);
    }
    
    if (document.forms[0].generators_building_1_site_1.selectedIndex <= 0)

    {alert("Please enter the number of generators.");

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

    }

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

    {alert("Please enter the number of plant rooms.");

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

    }

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

    {alert("Please specify the year the building was built.");

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

    }

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

    {alert("You did not enter the number of tenancies. Please enter the number of tenancies in the field provided");

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

    }

    var btn = valButton(document.forms[0].residential_area_building_1_site_1);
    if (btn == null) {
    alert("Please specify if the building is a residential area.");
    return(false);
    }


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

    {alert("You did not enter the number of residential units. Please enter the number of residential units in the field provided");

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

    }

    var btn = valButton(document.forms[0].building_about_to_be_sold_demolished_refurbished_building_1_site_1);
    if (btn == null) {
    alert("Please specify if the building is about to be sold, leased, demolished or refurbished.");
    return(false);
    }

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

    {alert("You did not enter the building post code. Please enter the building post code in the field provided");

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

    }

    if (!(document.forms[0].declare_information_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;

}
