var countryList = new Array();
var countryValue = new Array();
var stateList = new Array();
var stateValue = new Array();

function addCountry() {
  for(var i=0;i<arguments.length;i++) {
    countryList[i] = arguments[i];
  }
}

function addCountryValue() {
  for(var i=0;i<arguments.length;i++) {
    countryValue[i] = arguments[i];
  }
}

function addState() {
  stateList[arguments[0]] = new Array();
  
  for(var i=1;i<arguments.length;i++) {
    stateList[arguments[0]][i-1] = arguments[i];
  }
}

function addStateValue() {
  stateValue[arguments[0]] = new Array();
  for(var i=1;i<arguments.length;i++) {
    stateValue[arguments[0]][i-1] = arguments[i];
  }
}


function loadCountry(o1) {
  var length = countryList.length;
  
  for(var i=0;i<length;i++) {
    optionName = new Option(countryList[i],countryValue[i],false,false);
    
    o1.options[i+1] = optionName;
  }
  o1.options.length = i+1;
  o1.options[0].selected = true;  
}

function loadCountry2(o1) {
  var length = countryList.length;
  
  for(var i=0;i<length;i++) {
    optionName = new Option(countryList[i],countryValue[i],false,false);
    
    o1.options[i+1] = optionName;
  }
  o1.options.length = i+1;
  o1.options[0].selected = true;  
}

function loadState(o1,name) {
  var length = 0;
  
  if(stateList[name]!=null) {
    length = stateList[name].length;
    for(var i=0;i<length;i++) {
      optionName = new Option(stateList[name][i],stateValue[name][i],false,false);
      
      o1.options[i] = optionName;
    }
    o1.options.length = i;
    o1.options[0].selected = true;
    changeType(2);
  }
  else
    changeType(1);
}

function changeState(cObj,sObj,val) {
  var name = cObj.options[cObj.selectedIndex].text;
  var strValue = cObj.options[cObj.selectedIndex].value;
  var selNumber=0;
  var length = 0;
  
  if(name!=null && name!="" && stateList[name]!=null) {
    length = stateList[name].length;
    for(var i=0;i<length;i++) {
      optionName = new Option(stateList[name][i],stateValue[strValue][i],false,false);
    
      if(val!=null && stateValue[strValue][i]==val)
        selNumber = i;
    
      sObj.options[i] = optionName;
    }
    sObj.options.length = i;
    sObj.options[selNumber].selected = true;
    changeType(2);
  }
  else
    changeType(1);
}

function changeStateWithNoData(cObj,sObj,val) {
  var name = cObj.options[cObj.selectedIndex].text;
  var strValue = cObj.options[cObj.selectedIndex].value;
  var selNumber=0;
  var length = 0;
  
  if(name!=null && name!="" && stateList[name]!=null) {
    length = stateList[name].length;
    
    optionName = new Option("","",false,false);
    sObj.options[0] = optionName;
    
    for(var i=0;i<length;i++) {
      optionName = new Option(stateList[name][i],stateValue[strValue][i],false,false);
    
      if(val!=null && stateValue[strValue][i]==val)
        selNumber = i+1;
    
      sObj.options[i+1] = optionName;
    }
    sObj.options.length = i+1;
    sObj.options[selNumber].selected = true;
    changeType(2);
  }
  else
    changeType(1);
}

function changeType(num){
  if(num == 1) {
    document.all["s1"].style.display = 'block';
    document.all["s1"].style.visibility = 'visible';
    document.all["s2"].style.display = 'none';
    document.all["s2"].style.visibility = 'hidden';
    document.all["s3"].style.display = 'block';
    document.all["s3"].style.visibility = 'visible';
    document.all["s4"].style.display = 'none';
    document.all["s4"].style.visibility = 'hidden';
    document.all["s5"].style.display = 'none';
    document.all["s5"].style.visibility = 'hidden';
  }
  else if(num == 2){
    document.all["s2"].style.display = 'block';
    document.all["s2"].style.visibility = 'visible';
    document.all["s1"].style.display = 'none';
    document.all["s1"].style.visibility = 'hidden';
    document.all["s4"].style.display = 'block';
    document.all["s4"].style.visibility = 'visible';
    document.all["s3"].style.display = 'none';
    document.all["s3"].style.visibility = 'hidden';
    document.all["s5"].style.display = 'block';
    document.all["s5"].style.visibility = 'visible';
  }
}

/********************************************************/
/********************************************************/
function setCountryState(obj,v) {
  for(var i=0;i<obj.length;i++) {
    if(obj.options[i].value==v) {
      obj.options[i].selected = true;
      break;
    }
  }
}

function changeCountryWithData(objCountry,dbCountry,dbState){
    
    if(dbCountry!="") {
    	//document.ULMemberDetail.country.value = dbCountry;
    	setCountryState(objCountry,dbCountry);
    	var name = objCountry.options[objCountry.selectedIndex].text;
    
    	if(stateList[name]!=null) {
    	  //if(dbState!="")
      	  //  changeState(objCountry,objCountry.form.state2,dbState);
      	  //else
      	    changeStateWithNoData(objCountry,objCountry.form.state2,dbState);
    	}
    	else 
      	  objCountry.form.state1.value     = dbState;
    	objCountry.form.state.value     = dbState;
    }
}