// JavaScript Document
function Loader(flagID, nameID, phoneID, dropdownID){
	var input=geoip_country_name();
    input = input.toUpperCase()
	var Darray=dropdownID.split("|");
	var Parray=phoneID.split("|");
		for (p=0;p<Darray.length;p++){
			if (document.getElementById(Darray[p])){
				var output=document.getElementById(Darray[p]).options;
				for(var i=0;i<output.length;i++) {
					if(output[i].text.indexOf(input)==0)
						{
						output[i].selected=true;		
						var countryValue=   output[i].value;                    
						var countryCode= countryValue.split("-");
						document.getElementById(Parray[p]).value=countryCode[0]; 
						var Val=output[i];
						}
					if(geoip_country_name()==''){
					  output[0].selected=true;
					  document.getElementById(Parray[p]).value='1'; 
					  }
				}
			}
		}
       var Phone_Country_Code=Val.value;        
       var countryValue=   Phone_Country_Code;
       var countryCode= countryValue.split("-");
       setCountryFlagheader(countryCode[1], countryCode[0], Val.text,flagID, nameID, phoneID);
}
function FillCodeheader(flagID, nameID, phoneID, data)
{
	   var output=document.getElementById(data).options;
	   for(var i=0;i<output.length;i++) {
			if (output[i].selected==true){
				var Val=output[i];
			   var Phone_Country_Code=Val.value;        
			   var countryValue=   Phone_Country_Code;
			   var countryCode= countryValue.split("-");
			}
	   }
       setCountryFlagheader(countryCode[1], countryCode[0], Val.text,flagID, nameID, phoneID);
}

function setCountryFlagheader(countryValue, countryCode, fullname, flagID, nameID, phoneID) 
{     
		var Farray=flagID.split('|');
		var Narray=nameID.split('|');
		var Parray=phoneID.split('|');
		for (i=0;i<Farray.length;i++){
			if (document.getElementById(Farray[i])){
				var img=document.getElementById(Farray[i]);
				if (countryValue!=''){                   
					img.src='/images/flags/' + countryValue +'.gif';
				}else{
					img.src='/images/flags/us.gif';
				}
			}
		}
		for (i=0;i<Narray.length;i++){
			if (document.getElementById(Narray[i])){
				document.getElementById(Narray[i]).innerHTML=fullname;
			}
		}
		for (i=0;i<Parray.length;i++){
			if (document.getElementById(Parray[i])){
				document.getElementById(Parray[i]).value=countryCode=='0' ? '' : countryCode;
			}
		}

}
