
//var errMsgCountryMandatory = 'Select a Country' ;
//var errMsgCountryMandatory = '<bean:message key="pl.js.alert.select.country"/>' ;

 //var errMsgMultiCountry= 'Select at least a Country' ;
 //var errMsgMultiCountry= '<bean:message key="pl.js.alert.select.multicountry"/>' ;

// Functions for calling the Server for Advance Search Starts Here
function getAdvanceSearch() {
	document.plSearchForm.state.value = "";
     document.plSearchForm.zip.value = "";
     document.plSearchForm.city.value ="";
	var address= document.plSearchForm.address.value;
	var theForm = document.plSearchForm ;	
	var errMsg = validate() ;
	if(errMsg != ''){	
		alert(errMsg) ;
		return ;
	}
	if (document.plSearchForm.showMultiCountry.value == "Y" ){
		document.plSearchForm.lonlatRequired.value  = "N";
		document.plSearchForm.submit(); 
		return;
	}
 	if (gsupportcountry.match(theForm.country[theForm.country.selectedIndex].value ) != null)
 	{	
	 	if (address ==''){	 
			deSelect("proximity",false);
			document.plSearchForm.milesKms.value="miles";		
			address = theForm.country[theForm.country.selectedIndex].text  ;	
		} else {
			address += " " + theForm.country[theForm.country.selectedIndex].text  ;	
		}  
	  	
		setStandbyMessage();		 
		geocoder.getLocations(address,getInterestedLocationForHome);
		 
	} else {	   
		deSelect("proximity",false); 	
		document.plSearchForm.milesKms.value="miles";
		document.plSearchForm.city.value = document.plSearchForm.address.value; 	  
		address = theForm.country[theForm.country.selectedIndex].text  ;		    	
		setStandbyMessage();		 
		geocoder.getLocations(address,getInterestedLocationForHome);
 
	}
	
}   

function refineAdvanceSearchCriteria() {

	var theForm = document.plSearchForm ;	
	theForm.searchType.value = "RefineAdvanceSearchCriteria";
	theForm.action = "openAdvanceSearch.do";
	theForm.submit();
}

function resetAdvanceSearch(){
	var theForm = document.plSearchForm ;	
	
	theForm.companyName.value = "";
	deSelect("companyNameSearchType",false);
	deSelect("country",false);
	theForm.city.value = "";	 
 	theForm.address.value = "";	
	deSelect("proximity",false);
	//theForm.milesKms.value="miles";
    var RadioMiles = document.getElementsByName("milesKms")[0]; 
    RadioMiles.checked = true;
    var RadioKms = document.getElementsByName("milesKms")[1]; 
    RadioKms.checked = false;

	theForm.cpsURL.checked = false;
	unCheckAll(theForm.certifiedPartner);
	//unCheckAll(theForm.learningPartner);
	//unCheckAll(theForm.managedServices);		

	/*
	unCheck(theForm.technologySpecializationSelAll);			
	selectTab(theForm.technologySpecializationSelAll, 'technologySpecialization');

	unCheck(theForm.otherSpecializationSelAll);			
	selectTab(theForm.otherSpecializationSelAll, 'otherSpecialization');
	*/
	
	unCheck(theForm.specializationSelAll);			
	selectTab(theForm.specializationSelAll, 'specialization');
	
	unCheck(theForm.managedServicesSelAll);			
	selectTab(theForm.managedServicesSelAll, 'managedServices');
	
	unCheck(theForm.industryPartnerSelAll);			
	selectTab(theForm.industryPartnerSelAll, 'industryPartners');


	unCheck(theForm.advanceTechnologyProviderSelAll);			
	selectTab(theForm.advanceTechnologyProviderSelAll, 'advanceTechnologyProvider');

	unCheck(theForm.additionalPartnerProgramsSelAll);			
	selectTab(theForm.additionalPartnerProgramsSelAll, 'additionalPartnerPrograms');
	
	unCheck(theForm.learningPartnerSelAll);			
	selectTab(theForm.learningPartnerSelAll, 'learningPartner');
	
	//showSingleCountry();
	theForm.multiCountry.value =  '';
	onSelectCountry(theForm.country);
	//collaspeOption('technologySpecializationTab', 'technologySpecializationImg');
	//collaspeOption('otherSpecializationTab','otherSpecializationImg');
	collaspeOption('specializationTab','specializationImg');
	collaspeOption('managedServicesTab','managedServicesImg');	
	collaspeOption('industryPartnerTab','industryPartnerImg');
	collaspeOption('advanceTechnologyProviderTab','advanceTechnologyProviderImg');
	collaspeOption('additionalPartnerProgramsTab','additionalPartnerProgramsImg');
	collaspeOption('learningPartnerTab','learningPartnerImg');
}
function validate(){
	
	var errMsg = '' ;
	var theForm = document.plSearchForm ;
	if ( document.plSearchForm.showMultiCountry.value == "N" ){
		if(theForm.country.selectedIndex == 0)
			errMsg += errMsgCountryMandatory ;
	} else {	 
	  if(theForm.multiCountry.value == '')
			errMsg += errMsgMultiCountry ;
	}
	return errMsg  ;
}

// Functions for calling the Server for Advance Search Ends Here


// Functions for UI Display for Advance Search Starts Here
	function showHideOption(tabName, imageName)	{	
		var tab = document.getElementById(tabName);
		var img = document.getElementById(imageName);
		
		if(tab)
		{
			if(tab.style.display == 'none')
			{
				tab.style.display = 'block';
				if(img)
					img.src = minusImage.src ;
			}
			else
			{
				tab.style.display = 'none' ;
				if(img)
					img.src = plusImage.src ;
			}
		}
	}

	function onSelectCountry(selctCountry)
	{
		var cityLbl = document.getElementById("cityLabel") ;
		var selectedCountry = selctCountry[selctCountry.selectedIndex].value ;
		var proxSel = document.getElementById("proximitySpan") ;
		if(selectedCountry == "" || gsupportcountry.match(selectedCountry) != null)
		{
			if(zipsuppcountry.match(selectedCountry) != null)	
				cityLbl.innerHTML=cityLblInnerHTML2;
			else
				cityLbl.innerHTML=cityLblInnerHTML;
			proxSel.style.visibility="visible";
		}
		else 
		{
			cityLbl.innerHTML=cityLblInnerHTML;
			proxSel.style.visibility="hidden";
		}
	}
	
	function deSelect(selName, multiSelect)
	{
		var selObj = document.getElementById(selName) ;	
		
		if(selObj)
		{
			if(multiSelect)
				selObj.selectedIndex = -1;
			else
				selObj.selectedIndex = 0;
		}
	}
	
	function preFetchImages() {
	
		if (document.images)
		{
			plusImage = new Image(); // For Collapsed Block
			plusImage.src = "images/plus.gif";
			minusImage = new Image(); // For Expanded Block
			minusImage.src = "images/minus.gif";
		}	
	}


	function selectTab(selAll, tabName)
	{
		var isSelected = selAll.checked ;
		var chk = "" ;
		var numTabs = 0 ;
		var tabs = document.getElementsByName(tabName);
		
		if(tabs && tabs.length)
			numTabs = tabs.length ;

		if(isSelected)
			chk = "true" ;
		
		for(i=0 ; i < numTabs; i++)
		{
			if(tabs[i].checked != isSelected) 
				tabs[i].checked = chk ;
		}
	}
	
	function collaspeOption(tabName, imageName)
	{
		var tab = document.getElementById(tabName);
		
		if(tab)
		{
			if(tab.style.display == 'block')
			{
				showHideOption(tabName, imageName);
			}
		}
	
	}
	
	function unCheckAll(tabs)
	{
		var chk = "" ;
		var numTabs = 0 ;
		
		if(tabs && tabs.length)
			numTabs = tabs.length ;

		for(i=0 ; i < numTabs; i++)
		{
			tabs[i].checked = chk ;
		}
	
	}
	
	function unCheck(tab)
	{
		if(tab) 
			tab.checked = "" ;
	}
	
	function ischecked(tabname){
	var tab = document.getElementsByName(tabname);	 
		if (tab && tab.length){			 	        
	        for (i=0;i<tab.length;i++) {	        
	            if (tab[i].checked)
	                return true;
	         }
	    } 
	    return false;
	
	}
	
	function showSingleCountry(){	     
		var multiCou  = document.getElementById("multiCountryDiv") ;
		var singleCou  = document.getElementById("singleCountry") ;			 
	 	multiCou.style.display = 'none';
	 	singleCou.style.display = 'block';
	 	deSelect("multiCountry",true);
	 	document.plSearchForm.multiCountry.value = "";	 	 
	 	document.plSearchForm.showMultiCountry.value = "N";
	}
	
	function showMultipleCountry(){		 
		var multiCou  = document.getElementById("multiCountryDiv") ;
		var singleCou  = document.getElementById("singleCountry") ;			 
	 	multiCou.style.display = 'block';
	 	singleCou.style.display = 'none' ;	
	 	document.plSearchForm.latitude.value = "";
		document.plSearchForm.longitude.value ="";
	    document.plSearchForm.city.value = "";
	    document.plSearchForm.address.value = "";
	    deSelect("country",false);
	 	document.plSearchForm.showMultiCountry.value = "Y";
	}
	
	function showMulticountryforAuto(){
		if (document.plSearchForm.showMultiCountry.value =="Y") {
		     document.getElementById("multiCountryDiv").style.display = 'block';
		}  else {
			//document.getElementById("singleCountry").style.display = 'block';
		}
	}
	
	function hideMulticountryforAuto() {
		if (document.plSearchForm.showMultiCountry.value =="Y") {
		    document.getElementById("multiCountryDiv").style.display = 'none';
		}  else {
			//document.getElementById("singleCountry").style.display = 'none';
		}
	}
	
	// added for hiding proximity span 
	function showCityDivForAuto(selctCountry)
	{
		var cityLbl = document.getElementById("cityLabel") ;
		var proxSel = document.getElementById("proximitySpan") ;
		
		if (selctCountry!=null)
		{
			var selectedCountry = selctCountry;
			if(selectedCountry == "" || gsupportcountry.match(selectedCountry) != null)
			{
				if(zipsuppcountry.match(selectedCountry) != null)	
					cityLbl.innerHTML=cityLblInnerHTML2;
				else
					cityLbl.innerHTML=cityLblInnerHTML;
					proxSel.style.visibility="visible";
			}
			else 
			{
				cityLbl.innerHTML=cityLblInnerHTML;
				proxSel.style.visibility="hidden";
				
			}
		}
	}
// Functions for UI Display for Advance Search Ends Here
