//<script>
if (typeof(allowAllCities) == "undefined")
	allowAllCities = true;
var useCityIDs = false;
var hideCityList = false;
function sChangeList(dropList, frm, sel) {
	  if (document.all)
		{
	  	var hasStates = dropList.options[sel].hasStates
	  }
		else
		{
	  	if (dropList.options[sel].attributes[1].name == 'value')
			{
		    var hasStates = dropList.options[sel].attributes[0].value
			}
			else
			{
			    var hasStates = dropList.options[sel].attributes[1].value
			}
	  }
		
   if  (hasStates =='true') {
		  if (document.getElementById('USAList')){
			  document.getElementById('USAList').style.display = 'none';
		  }
		  if (document.getElementById('CanadaList')){
			  document.getElementById('CanadaList').style.display = 'none';
		  }
		  if (document.getElementById('AustraliaList')){
			  document.getElementById('AustraliaList').style.display = 'none';
		  }
		  document.getElementById(dropList[sel].value + 'List').style.display = '';
	  	if (hideCityList){
		  frm.city.style.display = 'none';
		}
		else {
	  	  frm.city.disabled = true;
		}
		  document.getElementById('dummy').style.display = 'none';
   }else{

	   if (dropList.name == 'country'){
		  if (document.getElementById('USAList')){
			  document.getElementById('USAList').style.display = 'none';
		  }
		  if (document.getElementById('CanadaList')){
			  document.getElementById('CanadaList').style.display = 'none';
		  }
		  if (document.getElementById('AustraliaList')){
			  document.getElementById('AustraliaList').style.display = 'none';
		  }
		  frm.state.selectedIndex = 0;
	  }
	  	if (hideCityList){
		  frm.city.style.display = '';
		}
		else {
	  	  frm.city.disabled = false;
		}
		//  document.getElementById('CityList').style.visibility = 'visible';
		if (dropList.name == 'country'){
		  document.getElementById('dummy').style.display = '';
		}else{
		  document.getElementById('dummy').style.display = 'none';
		}
	  if (document.all){
	  	var cityList = dropList.options[sel].cities
	  }else{
		if (dropList.options[sel].attributes[1].name == 'value') {
		    var cityList = dropList.options[sel].attributes[0].value
		}
		else {
		    var cityList = dropList.options[sel].attributes[1].value
		}
	  }
	  if (cityList == ""){ 
	  	if (hideCityList){
		  frm.city.style.display = 'none';
		}
		else {
	  	  frm.city.disabled = true;
		}
		return;
	  }
		
	  if (!allowAllCities){
	      sChangeList1(frm.city, cityList, '-- Select a City --')
	  }
	  else {
	      sChangeList1(frm.city, cityList, 'All Cities')
	  }
     }
 }   
    
    
function sChangeList1(dropList, MyArr, firstOptionText){
    var StateElements;
	var i; 
	var aStateList = MyArr.split(',');
	var tVal = '', tText = '', tArr = ''

	if (aStateList) {
	    clearList(dropList);
		if (firstOptionText != null){
			addElement(dropList, firstOptionText, 0);
		}
		for (i = 0; i < (aStateList.length-1); i++) {
			if (dropList.name == 'city'){
			  if (aStateList[i].indexOf(';') != -1){
				tArr = aStateList[i].split(';');
				if (useCityIDs){
					tText = tArr[0];
				}
				else {
					tText = tArr[1];
				}
				tVal = tArr[1];
			  }
			  else {
				tText = aStateList[i];
				tVal = aStateList[i];
			  }
			}
			//StateElements=aStateList[i].split('#');
			addElement(dropList, tVal, tText);
		}
    } 
}

function clearList(list) {
    var i = 0;
    var o = list.options;

    for (i = o.length; i >= 0; --i){
		o[i] = null;
	}
	if (hideCityList){
	  list.style.display = 'none';
	}
	else {
      list.disabled = true;
	}
}


function addElement(list, text_in, value_in){
var selectedItem = false;
if (text_in.indexOf('-') == text_in.length-1) {
	text_in = text_in.substring(0,text_in.length-1)
	selectedItem = true;
}
if (value_in.length > 1) {
	if (value_in.indexOf('-') == value_in.length-1) {
		value_in = value_in.substring(0,value_in.length-1)
		selectedItem = true;
	}
}
    var o = list.options;
    var nIdx;
	if (o.length < 0){ //IE for Mac 4.5 sets length to -1 if list is empty
		nIdx = 0;
	}else{
		nIdx = o.length;
	}
	o[nIdx] = new Option(text_in, value_in);
	if (selectedItem) {
		o[nIdx].selected = true;
	}
	if (hideCityList){
	  list.style.display = '';
	}
	else {
	  list.disabled = false;
	}
}


function setDefaultByText(list, text_in){
    with (list){
        for (var i = 0; i < (options.length); i++){
             if (options[i].text == text_in){
                 selectedIndex = i;
                 return;
             }
        }
    }
}


function setDefaultByValue(list, value_in){
    with (list){
        for (var i = 0; i < (options.length); i++){
             if (options[i].value == value_in){
                 selectedIndex = i;
                 return;
             }
         }
    }
}
//</script>
