// JavaScript Document
var CountrySelected = 9;
var CitySelected = 0;
//////////////////////////
function mod_country(CountrySelected){
	// - > Put the country values inside the select DOM element <option>
 	for(i=0;i<aPais.length;i++){
		paisName = aPais[i];
	 	if(paisName != null){ // ->comprueba que no este vacio	
			addOption(document.PkgFormWithFlight.country, i , paisName);
			addOption(document.PkgFormWithFlightCar.country, i , paisName);
		}
	}
	document.PkgFormWithFlight.country.options[CountrySelected].selected=true;
	document.PkgFormWithFlightCar.country.options[CountrySelected].selected=true;
}
function mod_cities(countryValue){
	//removeAllOptions(document.PkgFormWithFlight.DestName);
	removeAllOptions(document.PkgFormWithFlight.DestName);
	removeAllOptions(document.PkgFormWithFlightCar.DestName);
	for(j = 0; j< aCity[countryValue].length; j+=2){
	 cityName = aCity[countryValue][j];
	addOption(document.PkgFormWithFlight.DestName, aCity[countryValue][j+1] , cityName);
	addOption(document.PkgFormWithFlightCar.DestName, aCity[countryValue][j+1] , cityName);
  	}
}

function removeAllOptions(selectbox){
	var i;
	for(i=selectbox.options.length-1;i>=0;i--){
		selectbox.remove(i);
	}
}


function addOption(selectbox, value, text ){
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}

function Interaction(){
	
	// - 1rst FORM
	// - on Country Change
	var selectmenu=document.PkgFormWithFlight.country;
	selectmenu.onchange=function(){
	var chosenoption=this.options[this.selectedIndex] 
	  if (chosenoption.value!=""){
		 mod_cities(chosenoption.value);
	  }
	}
	// On Change City Select
	var selectmenu=document.PkgFormWithFlight.DestName;
	  selectmenu.onchange=function(){
	  var chosenoption=this.options[this.selectedIndex] 
		  if (chosenoption.value!=""){
			//alert(chosenoption.value);
		  }
	  }
	  
	// - 2rst FORM
	// - on Country Change
	var selectmenu=document.PkgFormWithFlightCar.country;
	selectmenu.onchange=function(){
	var chosenoption=this.options[this.selectedIndex] 
	  if (chosenoption.value!=""){
		 mod_cities(chosenoption.value);
	  }
	}
	// On Change City Select
	var selectmenu=document.PkgFormWithFlightCar.DestName;
	  selectmenu.onchange=function(){
	  var chosenoption=this.options[this.selectedIndex] 
		  if (chosenoption.value!=""){
			//alert(chosenoption.value);
		  }
	  }
}
function Interface(){
	Interaction();
	mod_country(CountrySelected);
	mod_cities(CountrySelected);
	document.PkgFormWithFlight.DestName.options[CitySelected].selected=true;
	document.PkgFormWithFlightCar.DestName.options[CitySelected].selected=true;
}
function ResetInputs(){
	removeAllOptions(document.PkgFormWithFlight.country);
	removeAllOptions(document.PkgFormWithFlightCar.country);
	removeAllOptions(document.PkgFormWithFlight.DestName);
	removeAllOptions(document.PkgFormWithFlightCar.DestName);
	Interface();
}
