
var DropdownType=function(){this.country="country";this.state="state";this.city="city";this.district="district";this.cityother="cityother";}
var Cn=function(text,value){this.text=text;this.value=value;this.s=new Array();}
var St=function(text,value){this.text=text;this.value=value;this.c=new Array();}
var Ct=function(text,value){this.text=text;this.value=value;this.d=new Array();}
var Dt=function(text,value){this.text=text;this.value=value;}
var DropdownOption=function(text,value){this.t=text;this.v=value;}
function attachEventsToDropdowns(){var objCountry=document.getElementById(countryDropdownName);var objState=document.getElementById(stateDropdownName);var objCity=document.getElementById(cityDropdownName);var objDistrict=document.getElementById(districtDropdownName);var objCityOther=document.getElementById(cityotherTextBoxName);if(isCountryListPresent){addEventHandler(objCountry,"change",changeCountryList,false);}
addEventHandler(objState,"change",changeState,false);addEventHandler(objCity,"change",changeCity,false);addEventHandler(objDistrict,"change",changeDistrict,false);addEventHandler(objCityOther,"change",changeCityOther,false);}
function initCountry(arr){var objCountry=document.getElementById(countryDropdownName);if(objCountry!=null){clearSelectBox(objCountry);objCountry.options[0]=new Option(defaultSelectText,"");if(arr.length>0){addOptionToSelect(objCountry,arr);}
setChildDropDownVisibility(dropdownType.country,false);}}
function initState(arr){var objState=document.getElementById(stateDropdownName);if(objState!=null){clearSelectBox(objState);objState.options[0]=new Option(defaultsStateSelectText,"");if(arr!=null){if(arr.length>0){addOptionToSelect(objState,arr);setChildDropDownVisibility(dropdownType.state,false);if(arr.length==1)
{setSelectedItem(objState,arr[0].v);setHiddenValue(dropdownType.state);changeState();initCity(arr[0].c);}}
else{setChildDropDownVisibility(dropdownType.country,false);}}}}
function initCity(arr){var objCity=document.getElementById(cityDropdownName);if(objCity!=null){clearSelectBox(objCity);objCity.options[0]=new Option(defaultsCitySelectText,"");if(arr!=null){if(arr.length>0){addOptionToSelect(objCity,arr);setChildDropDownVisibility(dropdownType.city,false);if(arr.length==1)
{setSelectedItem(objCity,arr[0].v);setHiddenValue(dropdownType.city);changeCity();initDistrict(arr[0].d);}}
else{objCity.style.display="none";}}}}
function initCityOther()
{document.getElementById(cityotherTextBoxName).value=currCityOtherValue;setHiddenValue(dropdownType.cityother);}
function initDistrict(arr){var objDistrict=document.getElementById(districtDropdownName);if(objDistrict!=null){clearSelectBox(objDistrict);objDistrict.options[0]=new Option(defaultsDistrictSelectText,"");if(arr!=null){if(arr.length>0){addOptionToSelect(objDistrict,arr);setChildDropDownVisibility(dropdownType.district,true);if(arr.length==1)
{setSelectedItem(objDistrict,arr[0].v);setHiddenValue(dropdownType.district);changeDistrict();}}
else{setChildDropDownVisibility(dropdownType.district,false);}}
else{setChildDropDownVisibility(dropdownType.district,false);}}}
function changeCountryList(curr){var objCountry=document.getElementById(countryDropdownName);if(objCountry.selectedIndex<=0){objCountry.selectedIndex=0;setChildDropDownVisibility(dropdownType.country,false);if(typeof(curr)!="undefined"){if(curr!=""){setSelectedItem(objCountry,curr);setHiddenValue(dropdownType.country);setChildDropDownVisibility(dropdownType.country,true);initState(an[objCountry.selectedIndex-1].s);}}}
else{if(an!=null&&an[objCountry.selectedIndex-1].s!=null&&an[objCountry.selectedIndex-1].s.length>0){setChildDropDownVisibility(dropdownType.country,true);initState(an[objCountry.selectedIndex-1].s);}
else{setChildDropDownVisibility(dropdownType.country,false);}}
setHiddenValue(dropdownType.country);}
function changeState(curr){var objState=document.getElementById(stateDropdownName);var objCountry=document.getElementById(countryDropdownName);var stateList=null;if(isCountryListPresent){if(objCountry.selectedIndex>0){stateList=an[objCountry.selectedIndex-1].s;}}
else{stateList=as;}
if(objState.selectedIndex<=0){objState.selectedIndex=0;setChildDropDownVisibility(dropdownType.state,false);if(typeof(curr)!="undefined"){if(curr!=""&&stateList!=null){setSelectedItem(objState,curr);changeState();return;}}}
else{if(stateList!=null&&stateList[objState.selectedIndex-1].c!=null&&stateList[objState.selectedIndex-1].c.length>0){setChildDropDownVisibility(dropdownType.state,true);initCity(stateList[objState.selectedIndex-1].c);}
else{setChildDropDownVisibility(dropdownType.state,false);}}
setHiddenValue(dropdownType.state);}
function changeCity(curr){var objState=document.getElementById(stateDropdownName);var objCity=document.getElementById(cityDropdownName);var objCountry=document.getElementById(countryDropdownName);var stateList=null;var cityList=null;if(isCountryListPresent){if(objCountry.selectedIndex>0){stateList=an[objCountry.selectedIndex-1].s;if(objState.selectedIndex>0){cityList=stateList[objState.selectedIndex-1].c;}}}
else{if(objState.selectedIndex>0){cityList=as[objState.selectedIndex-1].c;}}
if(objCity.selectedIndex<=0){objCity.selectedIndex=0;setChildDropDownVisibility(dropdownType.city,false);if(typeof(curr)!="undefined"){if(curr!=""&&cityList!=null){setSelectedItem(objCity,curr);changeCity();return;}}}
else{if(objCity.value=="other"|objCity.value=="Other"){var objCityOther=document.getElementById(cityotherTextBoxName);objCityOther.value="";setHiddenValue(dropdownType.cityother);setChildDropDownVisibility(dropdownType.cityother,true);}
else if(cityList!=null&&cityList[objCity.selectedIndex-1].d!=null&&cityList[objCity.selectedIndex-1].d.length>0){setChildDropDownVisibility(dropdownType.city,true);initDistrict(cityList[objCity.selectedIndex-1].d);}
else{setChildDropDownVisibility(dropdownType.city,false);}}
setHiddenValue(dropdownType.city);}
function changeDistrict(){setHiddenValue(dropdownType.district);}
function changeCityOther(){setHiddenValue(dropdownType.cityother);}
function setDistrict(curr){var objDistrict=document.getElementById(districtDropdownName);if(typeof(curr)!="undefined"){if(curr!=""){setSelectedItem(objDistrict,curr);setHiddenValue(dropdownType.district);}}}
function setChildDropDownVisibility(type,isVisible){var objCountry=document.getElementById("CountryLbl");var objState=document.getElementById("StateLbl");var objCity=document.getElementById("CityLbl");var objDistrict=document.getElementById("DistrictLbl");var objCityOther=document.getElementById("CityOtherLbl");if(type==dropdownType.country){if(isVisible){objState.style.display="block";}
if(!isVisible){objState.style.display="none";}
objCity.style.display="none";objDistrict.style.display="none";objCityOther.style.display="none";}
if(type==dropdownType.state){if(isVisible){objCity.style.display="block";}
else{objCity.style.display="none";}
objDistrict.style.display="none";objCityOther.style.display="none";}
if(type==dropdownType.city){if(isVisible){objDistrict.style.display="block";}
else{objDistrict.style.display="none";}
objCityOther.style.display="none";}
if(type==dropdownType.district){if(isVisible){objDistrict.style.display="block";}
else{objDistrict.style.display="none";}
objCityOther.style.display="none";}
if(type==dropdownType.cityother){if(isVisible){objCityOther.style.display="block";}
else{objCityOther.style.display="none";}
objDistrict.style.display="none";}
setDefaultForHiddenFields();}
function setDefaultForHiddenFields(){var objCity=document.getElementById(cityDropdownName);var objDistrict=document.getElementById(districtDropdownName);var objCityOther=document.getElementById(cityotherTextBoxName);var objCityLbl=document.getElementById("CityLbl");var objDistrictLbl=document.getElementById("DistrictLbl");var objCityOtherLbl=document.getElementById("CityOtherLbl");var arr=new Array();arr[0]=new DropdownOption(defaultHiddenValue,defaultHiddenValue);if(objCityLbl.style.display=="none"){clearSelectBox(objCity);addOptionToSelect(objCity,arr);objCity.selectedIndex=0;}
if(objDistrictLbl.style.display=="none"){clearSelectBox(objDistrict);addOptionToSelect(objDistrict,arr);objDistrict.selectedIndex=0;}
if(objCityOtherLbl.style.display=="none"){objCityOther.value=defaultHiddenValue;}}
function setHiddenValue(type){var obj=null;var objHiddenText=null;if(type==dropdownType.country){obj=document.getElementById(countryDropdownName);objHiddenText=document.getElementById(countryHiddenTextboxName);objHiddenText.value=obj.value;}
if(type==dropdownType.state){obj=document.getElementById(stateDropdownName);objHiddenText=document.getElementById(stateHiddenTextboxName);objHiddenText.value=obj.value;document.getElementById("state").value=obj.value;}
if(type==dropdownType.city){obj=document.getElementById(cityDropdownName);objHiddenText=document.getElementById(cityHiddenTextboxName);objHiddenText.value=obj.value;document.getElementById("city").value=obj.value;}
if(type==dropdownType.district){obj=document.getElementById(districtDropdownName);objHiddenText=document.getElementById(districtHiddenTextboxName);objHiddenText.value=obj.value;document.getElementById("district").value=obj.value;}
if(type==dropdownType.cityother){obj=document.getElementById(cityotherTextBoxName);document.getElementById("cityother").value=obj.value;}}
function clearSelectBox(objSelect){objSelect.selectedIndex=0;while(objSelect.length>0){objSelect.remove(0);}}
function addOptionToSelect(objSelect,arr){if(arr.length===0){return;}
var i=0;while(i<arr.length){if(arr[i]===null){continue;}
objSelect.options[objSelect.length]=new Option(arr[i].t,arr[i].v);if(arr[i].v===""&&objSelect.length>0){objSelect.selectedIndex=objSelect.length-1;}
i=i+1;}}
function setSelectedItem(objSelect,value){objSelect.value=value;}
function addEventHandler(obj,evType,fn,useCapture){if(obj.addEventListener){obj.addEventListener(evType,fn,useCapture);return true;}
else if(obj.attachEvent){var r=obj.attachEvent('on'+evType,fn);return r;}
else{obj['on'+evType]=fn;}}
var dropdownType=new DropdownType();var Cn=function(text,value){this.text=text;this.value=value;this.s=new Array();}
var St=function(text,value){this.text=text;this.value=value;this.c=new Array();}
var Ct=function(text,value){this.text=text;this.value=value;this.d=new Array();}
var Dt=function(text,value){this.text=text;this.value=value;}
var an=new Array();var as=new Array();var ac=new Array();var ad=new Array();var jsonRaw=null;var currCountryValue="";var currStateValue="";var currCityValue="";var currCityOtherValue="";var currDistrictValue="";var isCountryListPresent=false;var countryDropdownName="";var countryHiddenTextboxName="";var stateDropdownName="";var stateHiddenTextboxName="";var cityDropdownName="";var cityHiddenTextboxName="";var districtDropdownName="";var districtHiddenTextboxName="";var cityotherTextBoxName="";var defaultHiddenValue="";var defaultSelectText="";var defaultsStateSelectText="";var defaultsCitySelectText="";var defaultsDistrictSelectText="";function initChaining(ctrLblId){initData();if(isCountryListPresent){an=jsonRaw;initCountry(an);if(currCountryValue!=""){changeCountryList(currCountryValue);}}
else{var objCountryLbl=document.getElementById(ctrLblId);objCountryLbl.style.display="none";as=jsonRaw;initState(as);if(currStateValue!=""){changeState(currStateValue);}
if(currCityValue!=""){changeCity(currCityValue);}
if(currCityOtherValue!="")
{initCityOther();}
if(currDistrictValue!=""){setDistrict(currDistrictValue);}}
attachEventsToDropdowns();}