// JavaScript Document


function validate(theform,HideItems) {

var s = HideItems;


	//Need to check if more than 1 item passed otherwise we get a JS error
	if(s.length >1) {
	var arrItems = new Array();
	arrItems = s;//.split(",");
	}
	else {
	var arrItems=s;
	}
		


 
// The whitespace has been trimmed from the beginning and end of myString
// Let's use the string's built-in length function to test that


	//Every form has first, last name, email and phone 	
		if (Trim(theform.FirstName.value)=="") {
		alert("Please enter your first name");
		theform.FirstName.focus()
		return false; }

		if (Trim(theform.LastName.value)=="") {
		alert("Please enter your last name");
		theform.LastName.focus()
		return false; }
	
		if (Trim(theform.EmailAddress.value)=="") {
		alert("Please enter your email address");
		theform.EmailAddress.focus()
		return false; }
		
		if (Trim(theform.PhoneNumber.value)== "") {
		alert("Please enter a contact number");
		theform.PhoneNumber.focus()
		return false; }
	
		if (!IsNumeric(theform.PhoneNumber.value)) {
		alert('Please enter numeric characters only for your contact number') 
		theform.PhoneNumber.focus(); 
		return false; 
		} 
					
	
		
		
}



function CheckForOther(obj1,obj2) {
var el1 = document.getElementById(obj1);
var el2 = document.getElementById(obj2);

//details is the name of the form
var w = document.details.found.selectedIndex;
var selected_text = document.details.found.options[w].text;

	if (selected_text=="Other") {
	el1.style.visibility="visible";
	el2.style.visibility="visible";
	el2.style.display = 'block';
	el1.style.display = 'block';
	}
	else {
	el1.style.visibility="hidden";
	el2.style.visibility="hidden";
	}
	
}


function inArray(needle, haystack) {



	for (h in haystack) {
		
		if (haystack[h] == needle) {
		return true;

		}

	}

return false;

} 


//Checks to ensure only numeric values are entered for postcode and phone number
function IsNumeric(sText)
{
   var ValidChars = "0123456789 ";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
   

// I renamed the function TrimUsingWhileLoop to just Trim for short
function Trim(str)
{  while(str.charAt(0) == (" ") )
  {  str = str.substring(1);
  }
  while(str.charAt(str.length-1) == " " )
  {  str = str.substring(0,str.length-1);
  }
  return str;
}


function validateContactUs(theform) {

	
		if (theform.department.value== "-- Select Department --") {
		alert("Please select a department for your query");
		theform.department.focus()
		return false; }
	
		if (theform.subject.value == "") {
		alert('Please enter a subject title for your query') 
		theform.subject.focus(); 
		return false; 
		} 
		
		if (theform.name.value == "") {
		alert('Please enter your name') 
		theform.name.focus(); 
		return false; 
		} 


		if (theform.email.value == "") {
		alert('Please enter your email address') 
		theform.email.focus(); 
		return false; 
		} 
	
		
		if (theform.phone.value == "") {
		alert('Please enter a contact number') 
		theform.phone.focus(); 
		return false; 
		} 
		
		
		if (theform.message.value == "") {
		alert('Please enter your query') 
		theform.message.focus(); 
		return false; 
		} 

}