// 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 = "";
  }


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


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

    if ((document.forms[0].type_of_work_performed.value == "Please Select") || (document.forms[0].type_of_work_performed.value == ""))

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

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

    }

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

    {alert("Please enter the best day for you to view a presentation");

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

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

    {alert("Please enter the best time for you to view a presentation");

    document.forms[0].preferred_presentation_time.focus();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;

}
