// JavaScript Document
function getXMLHTTP() { //fuction to return the xml http object
		var xmlhttp=false;	
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				req = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		 	
		return xmlhttp;
    }
	
	function getState(countryId) {		
		
		var strURL="findStateSearch.php?country="+countryId;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('statediv').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}
	
	
function callActionPage()
{
var total_array=0;
       if(document.formsearch.state.length)
       {
               total = document.formsearch.state.length;
               for (i=1;i<total;i++)
               {
                       if (document.formsearch.state[i].selected)
                       {
                            total_array++;
                       }
               }
       }
return  total_array;
}	
 
function validate()
{ 
   
	var middle=document.formsearch.country ;
	if (middle.value=='')
	{
		alert("Please select the state");
		middle.focus();
		return false;
	}
	
	var sel=callActionPage();
	if(sel == 0) {
	   alert('Please select suburbs');
	   document.formsearch.state.focus();
	   return false;
	}
	else if (sel > 3)
	{
	   alert('You can select no more than 3 suburbs');
	   document.formsearch.state.focus();
	   return false;
	}
	
}