function getLocationSearchStatus() {
	 if(searchFormType=="pinyin"){
        if(document.cityForm.city[0].value=="[Enter city in Pinyin]")  {
            document.cityForm.city[0].value="";
        }
        cityEmpty = (document.cityForm.city[0].value=="");
    }else{
        cityEmpty = (document.cityForm.city[1].value =="");
    }
	stateProvinceEmpty = (document.cityForm.stateCode.value == "");
	countryEmpty = (document.cityForm.countryCode.value=="");
	countryUS = (document.cityForm.countryCode.value=="US");

	if ((!cityEmpty) && (!stateProvinceEmpty) && (!countryEmpty)) { return "COMPLETE_SEARCH"; }
	if ((!stateProvinceEmpty) && (!countryEmpty)) { return "STATE_SEARCH"; }
	if ((!cityEmpty) && (!countryUS) && (!countryEmpty)) { return "NON_US_CITY_SEARCH"; }
	if ((!countryEmpty) && (!countryUS) ) { return "NON_US_COUNTRY_SEARCH"; }
	if ((stateProvinceEmpty) && (countryUS) && (!cityEmpty) ){ return "MISSING_STATE_US_SEARCH"; }
	if ((stateProvinceEmpty) && (countryUS) ){ return "INVALID_US_SEARCH"; }
	if ((!cityEmpty) && (stateProvinceEmpty) && (countryEmpty)) { return "CITY_ONLY"; }
	if ((cityEmpty) && (stateProvinceEmpty) && (countryEmpty)) { return "BLANK"; }

	return "INCOMPLETE";
}

var searchFormType='pinyin';
function updateState(){
    if(searchFormType == "pinyin"){
        //Do the following
        stateCode_onChange();
    }else{
        changedStateProv();
    }

}
function updateCountry(){
    if(searchFormType == "pinyin"){
        //Do the following
        countryCode_onChange();

    }else{
        //Do this
        changedCountry();
    }

}

var isStandardShufflingDone=false;
var isPinyinShufflingDone=true;

function showHide(whichDiv){
    
 if(whichDiv == 'pinyin'){
      document.cityForm.reset();
      if(isStandardShufflingDone){
          var temp=document.getElementById('countryContent').innerHTML;
         document.getElementById('countryContent').innerHTML = document.getElementById('cityContent').innerHTML;
         document.getElementById('cityContent').innerHTML=temp;
         isPinyinShufflingDone = true;
         isStandardShufflingDone = false;
     }
     searchFormType = whichDiv;
     document.getElementById('pinyinCityField').disabled=false;
     document.getElementById('pinyinCityField').style.display='inline';

     document.getElementById('cityField').disabled=true;
     document.getElementById('cityField').style.display='none';

     document.getElementById('stateProvince').disabled=false;
     document.getElementById('country').disabled=false;

      document.getElementById('stateProvince').disabled=false;
      document.cityForm.city_list.options[0].selected=true;

 }else{

     if(isPinyinShufflingDone){
          var temp=document.getElementById('countryContent').innerHTML;
         document.getElementById('countryContent').innerHTML = document.getElementById('cityContent').innerHTML;
         document.getElementById('cityContent').innerHTML=temp;
         isStandardShufflingDone = true;
         isPinyinShufflingDone = false;
     }
     clearFields();
     searchFormType = whichDiv;
     document.getElementById('pinyinCityField').disabled=true;
     document.getElementById('pinyinCityField').style.display='none';

     document.getElementById('cityField').disabled='true';
     document.getElementById('cityField').style.display='inline';

     document.getElementById('stateProvince').disabled=true;
     document.getElementById('stateProvince').style.display='inline';

     document.getElementById('country').style.display='inline';
      document.cityForm.city_list.options[1].selected=true;
 }
}
/*
 * Disabling the city, state and country components for the standard search
 */
function clearFields() {
	document.getElementById("pinyinCityField").value = "";
    document.cityForm.city.value="";
    document.cityForm.stateProvince.selectedIndex = 0;
    document.cityForm.stateProvince.value="";
    document.cityForm.country.selectedIndex = 0;
    document.cityForm.country.value="";

}
/*
 * Clearing the state and the country components depending on the focus on the city component 
 */
function city_onFocus() {
	document.cityForm.city.value = "";
    document.getElementById('pinyinCityField').value = "";
    if (stateCodeAutoSet) { document.cityForm.stateCode.selectedIndex = 0; }

	if (countryCodeAutoSet) { document.cityForm.countryCode.selectedIndex = 0; }
}


// Initialize form correctly
var f;
function initCities() {
    f = document.cityForm;
    var countryField = document.getElementById("country");
	var stateProvince = document.getElementById("stateProvince");
	var cityField = document.getElementById("cityField");
    if ((countryField.value == "US") || (countryField.value == "CA")) {
		stateProvince.disabled = false;
        if (stateProvince.value != "") {
			constructXMLQuery();
		}
	} else {
		if (countryField.value != "") {
			constructXMLQuery();
		} else {
			stateProvince.value = "";
			stateProvince.disabled = false;  // disabled for the pinyin search
			cityField.disabled = true;


        }
	}
}

