// JavaScript Document


function FillSyncRegions($country_code)
{
	if ($country_code!="")
	{
		var region = document.getElementById("region_synd");
		strValues = HttpCall($country_code);
		
		var arrRegions = strValues.split("|");
		ClearDropDown();
		
		for(i=0;i<arrRegions.length-1;i++)
		{
			var arrValues = arrRegions[i].split("@");
			var oOption = document.createElement("OPTION"); 
			oOption.text=ReplaceAll(unescape(arrValues[1]),"+", " "); 
			oOption.value=arrValues[0]; 
			region.options.add(oOption);
		}
	}
}
function filltyperegion()
{
	var region = document.getElementById("region_synd");
	var region_index = region.selectedIndex;
	
	document.getElementById("desc_region").value = document.getElementById("region_synd").options[region_index].text;
}

function SelectCountrySynd()
{
	
	var country = document.getElementById("country_code");
	var country_index = country.selectedIndex;
	
	if (country.options[country_index].value!="")
	{
		strValues = country.options[country_index].value;
		
		FillSyncRegions(strValues);
	}		
}
function ReplaceAll(Source,stringToFind,stringToReplace){

  var temp = Source;

    var index = temp.indexOf(stringToFind);

        while(index != -1){

            temp = temp.replace(stringToFind,stringToReplace);

            index = temp.indexOf(stringToFind);

        }

        return temp;

}


function ClearDropDown()
{
	var cbo = document.getElementById("region_synd");
 	var len = cbo.options.length;
	for(i=len-1; i>=0; i--)
	{
		//cbo.options.remove(i);
		cbo.remove(i);
	}
	var oOption = document.createElement("OPTION"); 
	oOption.text="All Regions"; 
	oOption.value=0; 
	cbo.options.add(oOption);
}
function HttpCall(strCode)
{
	var xmlhttp=false;
	var strResponse="";
	
	if (window.XMLHttpRequest) 
	{ 
		xmlhttp = new XMLHttpRequest();
		if (xmlhttp.overrideMimeType) {
			xmlhttp.overrideMimeType('text/plain');
		}
		xmlhttp.open("GET", "/widget/api/get_regions.php?code=" + strCode ,false);
		xmlhttp.send(null);
		if(xmlhttp.status == 200)   
			strResponse = xmlhttp.responseText;  
	}
	else
	{
		try 
		{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try 
			{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (E) 
			{
				xmlhttp = false;
			}
		}
		xmlhttp.open("GET", "/widget/api/get_regions.php?code=" + strCode ,false);
		xmlhttp.onreadystatechange=function() 
		{
			if (xmlhttp.readyState==4) 
			{
				strResponse = xmlhttp.responseText;
				//alert(strResponse);
			}
		}
		xmlhttp.send(null);
	}
	return strResponse;
}
