var arrMuncipalities = new Array() var muncipalities_loaded = false; function LoadMuncipalities(selForm, selElement, selPrimaryElement, textElement){ var primaryDelimiter = "|||"; var secondaryDelimiter = "|"; var codeDelimiter = "$"; var CountryWithMuncipalitieCode = "16,AU,41,CA,106,IT"; //Australia, Canada, Italy var IsCountryWithMuncipalitieCode = false; var parsingData; var strList = selElement; if(document.forms[selForm]) { selElement = document.forms[selForm].elements[selElement]; // Task ID -E-Comm Start textElement = document.forms[selForm].elements[textElement]; // Task ID -E-Comm End selElement.disabled = false; var primarySelectedIndex = document.forms[selForm].elements[selPrimaryElement].selectedIndex; //alert(primarySelectedIndex); var primaryValue = document.forms[selForm].elements[selPrimaryElement].options[primarySelectedIndex].value; //alert(primaryValue); if(primaryValue.indexOf("|") > -1){ var arrCountry = primaryValue.split(secondaryDelimiter); primaryValue = arrCountry[0]; } var arrCt = CountryWithMuncipalitieCode.split(','); if (jQuery.inArray(primaryValue, arrCt) > -1) { IsCountryWithMuncipalitieCode = true; } if(arrMuncipalities[primaryValue] != null){ parsingData = arrMuncipalities[primaryValue]; $(textElement).value = ""; $(textElement).hide(); $(selElement).show(); muncipalities_loaded = true; if (parsingData == null) return; var arr = parsingData.split(primaryDelimiter); var arr2; //alert(primaryValue); while (selElement.options.length > 0) selElement.remove(0); var element = document.createElement("OPTION"); element.value = ""; element.text = "Please Select"; selElement.options.add(element); for (var i = 0; i < arr.length; i++){ if(arr[i].length > 0){ var element = document.createElement("OPTION"); arr2 = arr[i].split(codeDelimiter); if ( IsCountryWithMuncipalitieCode == true ) { if (arr2[0].length > 0){ element.value = arr2[0]; } else{ element.value = arr2[1]; } }else{ element.value = arr2[1]; } element.text = arr2[1]; selElement.options.add(element); } } //alert("Please select a State/Province"); //selElement.focus(); } else{ while (selElement.options.length > 0) selElement.remove(0); $(textElement).show(); $(selElement).hide(); muncipalities_loaded = false; } } } function selectMuncipality(selectedMuncipality, MuncipalityList){ if(muncipalities_loaded){ if(MuncipalityList.options.length > 0){ for(x = 0; x < MuncipalityList.options.length; x++){ if(MuncipalityList.options[x].value == selectedMuncipality){ MuncipalityList.options[x].selected = true; } } } } } function IsValueNumeric(sValue){ var ValidChars = "0123456789"; var IsNumber=true; for (i = 0; i < sValue.length; i++){ sCharacter = sValue.charAt(i); if (ValidChars.indexOf(sCharacter) == -1){ IsNumber = false; } } return IsNumber; }