// Èý¼¶Áª¶¯ JavaScript Document

function initSelectOne(showOne, showTwo, showThree)
{
 makeSelectOptions(showOne, opArrayOne);
 initSelectTwo(showTwo, opArrayTwo[0][1], showThree);
 makeSelectOptions(showThree, opArrayThree[0][1]);
 $(showOne).change(function(){
  var SelectOneCheck = $(showOne).find("option");
  getSelectTwo(showTwo, opArrayTwo, SelectOneCheck[this.selectedIndex].value, showThree);
 });
}

function initSelectTwo(showTwo, showTwoArr, showThree)
{
 makeSelectOptions(showTwo, showTwoArr);
 $(showTwo).change(function(){
  var SelectOneCheck = $(showTwo).find("option");
  getSelectThree(showThree, opArrayThree ,SelectOneCheck[this.selectedIndex].value);
 });
}

function getSelectTwo(showTwo, arr, selectedValue, showThree){
 getSelectThree(showTwo, arr, selectedValue);
 var firstSelectChild = $($(showTwo).children().get(0)).val();
 getSelectThree(showThree, opArrayThree, firstSelectChild);
 $(showTwo).change(function(){
  var SelectOneCheck = $(showTwo).find("option");
  getSelectThree(showThree, opArrayThree ,SelectOneCheck[this.selectedIndex].value);
 });
}

function getSelectThree(item, arr, selectedValue){
 $.each(arr, function(){
  if( selectedValue == $(this).get(0))
  {
   $(item).empty();
   makeSelectOptions(item, $(this).get(1));
  }
 });
}
function makeSelectOptions(parentItem, selectItem)
{
 $(selectItem).each(function(i, row){
     //var opt = document.createElement("option");
   //opt.value = row[0];
   //opt.text = row[1];
   //opt.label = row[1];
   //opt.setAttribute("value",row[0]);
   //opt.setAttribute("text",row[1]); 
   var opt = new Option(row[1], row[0]);
   opt.innerHTML = row[1];
   $(parentItem).append(opt);
  });
}

