function GetRegionsByCountryHideRegionIfEmpty(
    messageelement, 
    countrydropdown, 
    regiondropdown)
{
    GetRegionsByCountry(
        messageelement, 
        countrydropdown, 
        regiondropdown);
    
    if (regiondropdown.length <= 1)
        regiondropdown.disabled = true;
    else
        regiondropdown.disabled = false;
}
function GetGeoSuggestions(sGeo)
{
    //alert('here');
	var sXml = '<RequestData><![CDATA[' + sGeo + ']]></RequestData>';
	alert(sXml);
	alert(ContentProviderUrl);
	return RemoteScriptingCall(ContentProviderUrl + 
                '/xcommon/services/Geo.asmx', sXml,'GetGeoSuggestions','http://www.bizbuysell.com/Geo', 
                'ResponseData');
}
function ValidateZipCode(
    zipCode)
{
    var isValidZipCode = false;
    
    var xml = (
        '<ZipCode>' +
        zipCode +
        '</ZipCode>');
        
    if (typeof(RemoteScriptingCall) == 'function')
    {
        var sReturn = RemoteScriptingCall(
            (ContentProviderUrl + 
                '/xcommon/services/Geo.asmx'), 
                xml,
                'ValidateZipCode',
                'http://www.bizbuysell.com/Geo', 
                'ResponseData');
                
        if ((sReturn != null) &&
            (sReturn.documentElement != null))
        {
            var text = (
                sReturn.documentElement.textContent ? 
                sReturn.documentElement.textContent : 
                sReturn.documentElement.text);
                
            if (text == 'true')
            {
                isValidZipCode = true;
            }
        }
    }
    
    return isValidZipCode;
}

function GetRegionsByCountry(
    messageelement, 
    countrydropdown, 
    regiondropdown)
{
    //alert('called');
    //check the category dropdown for selected items, build xml
    var xml = '';
    var hasCountry = false;
    
    for (i = 0; i < countrydropdown.options.length; i++)
    {
        if (countrydropdown.options[i].selected && countrydropdown.options[i].value != '')
        {
            hasCountry = true;
            xml += '<Country CountryID="' + countrydropdown.options[i].value + '"/>';
        }
    }

    if (typeof (ClearDropDown) == 'function')
    {
        ClearDropDown(
            regiondropdown);
    } 
        
    if (!hasCountry)
    {
		if (typeof(HideRemoteScriptingMsg) == 'function')
		{
		    HideRemoteScriptingMsg(messageelement);
		}
		
        return;
    }
    
    //alert(xml);
    //alert(ContentProviderUrl + '/xcommon/services/Geo.asmx');
    
    if (typeof(RemoteScriptingCall) == 'function')
    {
        var sReturn = RemoteScriptingCall(
            (ContentProviderUrl + 
                '/xcommon/services/Geo.asmx'), 
                xml,
                'GetRegionsForCountry',
                'http://www.bizbuysell.com/Geo', 
                'ResponseData');
                
        //xml coming back is a subcategory list <SubCategoryList><SubCategory/></SubCategoryList>
        //alert(sReturn);
        //alert('Returned');
        //alert(sReturn.xml);
        
        if (sReturn.documentElement.hasChildNodes)
        {
            //alert(sReturn.documentElement.firstChild.xml);
            
            for(i = 0; i < sReturn.documentElement.firstChild.childNodes.length; i++)
            {
                var newOpt = new Option(
                    sReturn.documentElement.firstChild.childNodes[i].getAttribute("Description"), 
                    sReturn.documentElement.firstChild.childNodes[i].getAttribute("RegionID"));			
                    	
			    regiondropdown.options[regiondropdown.options.length] = newOpt;
            }
        }
    }
    
    if (typeof(HideRemoteScriptingMsg) == 'function')
	{
	    HideRemoteScriptingMsg(messageelement);
	}
}

function GetCountiesByRegions(
    messageElement, 
    regionDropDown, 
    countyDropDown, 
    regionDropDownIncludesCountries,
    regionValueIsRegionAbbreviation,
    selectedCountyID) {

    var possibleLabel = document.getElementById('spnValidationMessage');

    if (possibleLabel != null) {
        possibleLabel.style.display = 'none';
    }
    //check the region dropdown for selected items, build xml
    var hasRegion = false;
    var hasCountry = false;
    
    if ((regionDropDown != null) &&
        (countyDropDown != null))
    {
        // Taking out for-loop since multiple values cannot
        // be selected in the region drop down list
        //for (var i = 0; i < regiondropdown.options.length; i++)
        //{
            //if ((regiondropdown.options[i].selected) && 
            //    (regiondropdown.options[i].value != ''))
            //{
            
        var value = regionDropDown.options[regionDropDown.selectedIndex].value;
        
        if ((value != null) &&
            (value != ''))
        {
            var region = '';
            var country = '';
            
            if (value.indexOf('r_') >= 0)
            {
                region = value.replace(
                    'r_',
                    '');
            }
            else
            {
                region = value;
            }
            
            if (regionDropDownIncludesCountries)
            {
                if (value.indexOf('c_') >= 0)
                {
                    country = value.replace(
                        'c_',
                        '');
                        
                    region = '';
                }
            }
            
            if ((region != null) &&
                (region.length > 0))
            {
                hasRegion = true;
            }
            else if ((country != null) &&
                (country.length > 0))
            {
                hasCountry = true;
            }
        }
    }
    
    if (typeof (ClearDropDown) == 'function')
    {
        ClearDropDown(
            countyDropDown);
    } 
    
    if (hasCountry)
    {
        if (typeof(HideRemoteScriptingMsg) == 'function')
		{
            HideRemoteScriptingMsg(messageElement);
        }
    }
    else if (hasRegion)
    {
        var xml = '';
        
        if (hasRegion)
        {
            xml = '<RegionList>'
            
            if ((typeof(regionValueIsRegionAbbreviation) != 'undefined') &&
                (regionValueIsRegionAbbreviation))
            {
                xml += ('<Region Abbreviation="' + 
                    region + 
                    '"/>');
            }
            else
            {
                xml += ('<Region RegionID="' + 
                    region + 
                    '"/>');
            }
                
            xml += '</RegionList>';        
        }
        
        if (typeof(RemoteScriptingCall) == 'function')
        {
            var sReturn = RemoteScriptingCall(
                ContentProviderUrl + 
                '/xcommon/services/Geo.asmx', 
                xml,
                'GetCounties',
                'http://www.bizbuysell.com/Geo', 
                'ResponseData');
            
            if ((sReturn) && 
                (sReturn.documentElement))
            {
                if ((sReturn.documentElement.hasChildNodes()) &&
                    (sReturn.documentElement.firstChild.hasChildNodes()))
                {
                    countyDropDown.disabled = false;
                    //alert(sReturn.documentElement.firstChild.xml);

                    for (var i = 0; i < sReturn.documentElement.firstChild.childNodes.length; i++)
                    {
                        var countyName = sReturn.documentElement.firstChild.childNodes[i].getAttribute("CountyName");
                        var countyCode = sReturn.documentElement.firstChild.childNodes[i].getAttribute("CountyCode");

                        var newOpt = new Option(
                            countyName,
                            countyCode);

                        if ((typeof (selectedCountyID) != 'undefined') &&
                            (countyCode == selectedCountyID))
                        {
                            newOpt.selected = true;
                        }

                        countyDropDown.options[countyDropDown.options.length] = newOpt;
                    }
                }
            }
        }
        
        if (typeof(HideRemoteScriptingMsg) == 'function')
		{
	        HideRemoteScriptingMsg(messageElement);
	    }
	}
	else
	{
	    if (typeof(HideRemoteScriptingMsg) == 'function')
		{
	        HideRemoteScriptingMsg(messageElement);
	    }
	}
}
