/***************************************
form name = mainform
select item name is  state  --> city 
use array
    provinceIDArray, NameArray , ValueArray
***************************************/

// delete all item 

function deleteAllItem1city(theForm) {

   var length 
   
   length = theForm.city.options.length
   
   for (var i=0; i < length; i++) {
        theForm.city.options[0]=null
        }   
}

// get data and insert them

function populatecity(inForm,choice,cityed) {

   if (choice==0) {choice=provinceIDArray[0]}

   var j=0
   for (var k=0 ;k<provinceIDArray.length ;k++) {
   if (provinceIDArray[k]==choice) {
      eval("var option"+j+"= new Option(NameArray[k], NameArray1[k])")
      j++
   }
   }
  
   
 for (var i=0; i < j; i++) {
      eval("inForm.city.options[i]=option" + i)
      if(cityed == ''){
	      if (i==0) {
	         inForm.city.options[i].selected=true
	      }
			}
	    else
	    {
	      if (inForm.city.options[i].value == cityed) {
	         inForm.city.options[i].selected=true
	      }
      }
   }
}

// main 
function FillDefcity(thForm,city_selected)
{
//	var choice
//	Choice=thForm.state.options[thForm.state.selectedIndex].value
	deleteAllItem1city(thForm)
	populatecity(thForm, thForm.state.options[thForm.state.selectedIndex].value, city_selected)
//	document.mainform.statename.value =  form.state.options[form.state.selectedIndex].text
}
