
// Global
var formData;
var formDataRes;
var controlRes=0;
var formPromoAddDays=1;

function hotel( cName, code )
{
	this.cname = cName;
	this.code = code;
}

function city ( cName, code )
{
	this.cname = cName;
	this.code = code;
	this.hotels = [];
}

function country( cName , code)
{
	this.cname = cName;
	this.code = code;
	this.cities = [];
}

function formdata ()
{
	
	this.countries = [];
	this.cities2 =[];
	this.hotels2=[];
	this.cbCountry = null;
	this.cbCity = null;
	this.cbHotel = null;
	this.ignorechange=false;
	this.opTextCountry = "?";
	this.opTextCity = "?";
	this.opTextHotel = "?";
	this.countryValue="*";
	this.cityValue="*";
	this.hotelValue="*";
	
}

formdata.prototype.addCountry = function ( cName, code ) 
{
	this.countries.push(new country(cName, code));
	
}

formdata.prototype.addCity = function ( cName, code ) 
{
	var lastcountry = this.countries[ this.countries.length-1 ];
	lastcountry.cities.push ( new city(cName, code) );
	this.cities2.push(new city(cName, code));
}

formdata.prototype.addHotel = function ( cName, code ) 
{
	var lastcountry = this.countries[ this.countries.length-1 ];
	var lastcity = lastcountry.cities[ lastcountry.cities.length - 1 ];
	lastcity.hotels.push( new hotel(cName, code) );
	this.hotels2.push(new hotel(cName, code));
}

formdata.prototype.listHotels = function ( )
{
	var out="", i,j,k;
	var country, city, hotel; 
	
	for (i=0; i<this.countries.length; i++)
	{
		country  = this.countries[i];
		for (j=0; j<country.cities.length; j++)
		{
			city = country.cities[j];
			
			for (k=0; k<city.hotels.length; k++)
			{
				hotel = city.hotels[k];
				
				out = out + country.cname + "." + city.cname + "." + hotel.cname + ";";
			}
		}
	}
	
	alert ( out );
}


formdata.prototype.loadFromString = function ( stringLoad )
{
	var nodes = stringLoad.split(";");
	var i;
	
	for (i=0; i<nodes.length; i++)
	{
		var splits = nodes[i].split(":");
		var nodetype = splits[0].substr(0,1);
		var val = splits[0].substr(1,splits[0].length-1);
		var code = splits[1];
		switch ( nodetype )	
		{
			case 'P':
			
				this.addCountry( val, code );
				var pais = val;
				break;
			case 'C':
				this.addCity ( val, code );
				var cidade = val;
				break;
			case 'H':
				this.addHotel( val, code );
				break;
		}
	}	
}	

formdata.prototype.optionLanguageText = function ( tCountry, tCity, tHotel )
{
	this.opTextCountry = tCountry;
	this.opTextCity = tCity;
	this.opTextHotel = tHotel;
}


formdata.prototype.removeSubCombos = function ( what )
{
	var i;
	
	for ( ; this.cbHotel.length>0 ; ) 
	{
	
		this.cbHotel.options[this.cbHotel.length-1] = null;
	}
	
	this.cbHotel.options[0] = new Option ( this.opTextHotel, "*", false, false);

	if (what > 1)
	{
		for ( ; this.cbCity.length>0 ;) 
		{
			this.cbCity.options [ this.cbCity.length-1 ] = null;
		}
		this.cbCity.options[0] = new Option ( this.opTextCity, "*", false, false);
	}
}
	
formdata.prototype.setComboID = function ( cbcountry, cbcity, cbhotel )
{
	
	this.cbCountry = cbcountry;
	this.cbCity = cbcity;
	this.cbHotel = cbhotel;
	
	
}	

formdata.prototype.setValue = function ( ctrValue, cityValue, htlValue, promoDaysValue ) 
{
	
	this.countryValue = ( ctrValue=="")?"*":ctrValue;
	this.cityValue = ( cityValue=="" )?"*":cityValue;
	this.hotelValue = ( htlValue=="")?"*":htlValue;
	
	if ( parseInt(promoDaysValue)>0){ 	formPromoAddDays = promoDaysValue; }
	
	
}

formdata.prototype.loadComboPos = function (xformData)
{
	
	var iIndex=0;
	
	this.cbCountry = document.forms[0].elements[ this.cbCountry ];
	this.cbCity = document.forms[0].elements[ this.cbCity ];
	this.cbHotel = document.forms[0].elements[ this.cbHotel ];
	
	this.removeSubCombos ( 2 );
	
	// country
	if ( this.countryValue !="*" ) 
	{
		xformData.loadPosCountry();
	}
	
	xformData.loadPosCity();
	
	xformData.loadPosHotel();
	
}

formdata.prototype.loadPosCountry = function ()
{
	
	for (var i=0; i<this.countries.length; i++)
	{
		if ( this.countries[i].code == this.countryValue)
		{
			var iIndex = i+1;
		}

	}
	
	this.cbCountry.selectedIndex = iIndex;

}

formdata.prototype.loadPosCity = function ()
{
// position city

	var icountry=0;
	var icity=0;
	var numCity=0;
	var n=0;
	
	
	icountry = this.cbCountry.selectedIndex;
	
	for ( i=0;i<this.countries.length;i++)
	{
		if ( icountry == 0 )
		{
					
			country = this.countries[ i ];
			
			for (n=0; n<country.cities.length; n++ )
			{
				numCity++
				this.cbCity.options[numCity] = new Option ( country.cities[n].cname, country.cities[n].code, false, false);
				if ( this.cityValue == country.cities[n].code) 
				{
					icity = numCity;
				}
				
				
			}	
		} 
		else
		{
			if ( i==icountry )
			{
				
				country = this.countries[ i-1 ];
				for (n=0; n<country.cities.length; n++ )
				{
					this.cbCity.options[n+1] = new Option ( country.cities[n].cname, country.cities[n].code, false, false);
					if ( this.cityValue == country.cities[n].code) 
					{
						icity = n+1
					}
				}	
				break;
			}
			
		}
		
	}
	this.cbCity.selectedIndex = icity;
}

formdata.prototype.loadPosHotel = function ()
{
	
	var icountry=0;
	var icity=0;
	var ihotel=0;
	var i=0;
	var n=0;
	var country;
	var city;
	var numHotel=0;
	
	icountry = this.cbCountry.selectedIndex;
	icity = this.cbCity.selectedIndex
	
	if ( ( icountry == 0 ) && ( icity == 0 ) )
	{
		
		for (i=0; i<this.hotels2.length; i++)
		{
			this.cbHotel.options[i+1] = new Option ( this.hotels2[i].cname, this.hotels2[i].code, false, false);
			if ( this.hotelValue==this.hotels2[i].code){ ihotel=i+1 }
		}
	} 
	else if ( ( icountry != 0 ) && ( icity == 0 ) )
	{
	
		country = this.countries[ icountry - 1 ];
		
		for (i=0; i<country.cities.length; i++ )
		{
					
			city = country.cities [ i ];
			
			for (var n=0; n<city.hotels.length; n++ )
			{
				numHotel++;
				this.cbHotel.options[numHotel] = new Option ( city.hotels[n].cname, city.hotels[n].code, false, false);
				
				if ( this.hotelValue==city.hotels[n].code){ 
					ihotel=numHotel;
					}

			} 
			
		} 			
		
	}
	else if ( ( icountry == 0 ) && ( icity != 0 ) )
	{
	
		for ( i=0;i<this.countries.length;i++)
		{
			country = this.countries[i];
			
			for (n=0; n<country.cities.length; n++ )
			{
				if ( country.cities[n].code == this.cityValue )
				{
					icountry = i;
					icity = n;
				}
				if ( icountry!=0 ) break;
			}
			
			if ( icountry!=0)  { break; }
			
		}
		
		country = this.countries[ icountry ];
		city = country.cities [ icity ];
	
		for (i=0; i<city.hotels.length; i++ )
		{
			this.cbHotel.options[i+1] = new Option ( city.hotels[i].cname, city.hotels[i].code, false, false);
			if ( this.hotelValue==city.hotels[i].code){ ihotel=i+1 }
		}
	}
	else if ( ( icountry != 0 ) && ( icity != 0 ) )
	{

		country = this.countries[ icountry -1 ];
		city = country.cities [ icity -1 ];
	
		for (i=0; i<city.hotels.length; i++ )
		{
			this.cbHotel.options[i+1] = new Option ( city.hotels[i].cname, city.hotels[i].code, false, false);
			if ( this.hotelValue==city.hotels[i].code){ ihotel=i+1 }
		}
	}
	
	
	
	this.cbHotel.selectedIndex = ihotel;
	
}
	
formdata.prototype.loadCombos = function ( Inicialize )
{
	var i;
	var iNum=0;
	
	if ( Inicialize == '1 ' )
	{
		this.cbCountry = document.forms[0].elements[ this.cbCountry ];
		this.cbCity = document.forms[0].elements[ this.cbCity ];
		this.cbHotel = document.forms[0].elements[ this.cbHotel ];
	}
	
	this.removeSubCombos ( 2 );
	
	this.cbCountry.options[0] = new Option ( this.opTextCountry, "*", false, false);
	iNum=0;
	for (i=0; i<this.countries.length; i++)
	{
	
		this.cbCountry.options[i+1] = new Option ( this.countries[i].cname, this.countries[i].code, false, false);
		if ( this.countries[i].code==this.countryValue ) { iNum = i + 1 };
		
	}
	
	this.cbCountry.selectedIndex = iNum;
	iNum=0
	for (i=0; i<this.cities2.length; i++)
	{
		this.cbCity.options[i+1] = new Option ( this.cities2[i].cname, this.cities2[i].code, false, false);
		if ( this.cities2[i].code==this.cityValue ) { iNum = i + 1 };
	}
	
	this.cbCity.selectedIndex = iNum;
	iNum=0;
	for (i=0; i<this.hotels2.length; i++)
	{
		this.cbHotel.options[i+1] = new Option ( this.hotels2[i].cname, this.hotels2[i].code, false, false);
		if ( this.hotels2[i].code==this.hotelValue ) { iNum = i + 1 };
	}
	
	
	this.cbHotel.selectedIndex = iNum;
				
}


formdata.prototype.loadCombo = function ( icountry, icity, itype )
{
	var i;
	var country, city;
	var numCity=0;
	
	switch ( itype )
	{
		case 1:
		
			// country changed
			country = this.countries[icountry];
			for (i=0; i<country.cities.length; i++ )
			{
				this.cbCity.options[i+1] = new Option ( country.cities[i].cname, country.cities[i].code, false, false);
				
				city = country.cities [ i ];
					
				for (var ii=0; ii<city.hotels.length; ii++ )
				{
					numCity++
					this.cbHotel.options[numCity] = new Option ( city.hotels[ii].cname, city.hotels[ii].code, false, false);

				} 
				
			} 	
			
			
			
			break;
			
		case 2:
		
			// city changed
			if ( this.cbCountry.selectedIndex-1 <0 ) 
			{
				var cityValue = this.cbCity.value;
				icountry=0;
				icity=0;
				
				for ( i=0;i<this.countries.length;i++)
				{
					country = this.countries[i];
					
					for (ii=0; ii<country.cities.length; ii++ )
					{
						
						if ( parseInt(country.cities[ii].code) == parseInt(cityValue) )
						{
							icountry = i;
							icity = ii;
						}
						if ( icountry!=0 ) break;
					}
					
					if ( icountry!=0)  { break; }
					
				}
				
				country = this.countries[ icountry ];
				city = country.cities [ icity ];
			
				for (i=0; i<city.hotels.length; i++ )
				{
					this.cbHotel.options[i+1] = new Option ( city.hotels[i].cname, city.hotels[i].code, false, false);
				}
				
			}
			else
			{
				
				country = this.countries[ this.cbCountry.selectedIndex-1 ];
				city = country.cities [ icity ];
			
				for (i=0; i<city.hotels.length; i++ )
				{
					this.cbHotel.options[i+1] = new Option ( city.hotels[i].cname, city.hotels[i].code, false, false);
				}
			} 				
			break;
			
		case 3:
		
			country = this.countries[icountry];
			for (i=0; i<country.cities.length; i++ )
			{
				
				city = country.cities [ i ];
					
				for (var ii=0; ii<city.hotels.length; ii++ )
				{
					numCity++

					this.cbHotel.options[numCity] = new Option ( city.hotels[ii].cname, city.hotels[ii].code, false, false);

				} 
				
			} 	
			
			break;
		
	}
	
}

formdata.prototype.countryChange = function (xformData)
{

	var si = xformData.cbCountry.selectedIndex-1; 	

	xformData.ignorechange = true;
	
	xformData.removeSubCombos ( 2 );
	
	if ( si >=0 )
	{
		xformData.loadCombo ( si, '', 1);			
	}
	else
	{
		xformData.loadCombos(0);
	}

	xformData.ignorechange = false;
}

formdata.prototype.cityChange = function (xformData)
{
	if ( !xformData.ignorechange )
	{
		var si = xformData.cbCity.selectedIndex-1; 	
		
		if ( si >=0 ) 
		{
			xformData.removeSubCombos ( 1 );
			xformData.loadCombo ( '', si, 2);			
		}
		else
		{
			if ( ( xformData.cbCountry.selectedIndex==0 ) && ( xformData.cbCity.selectedIndex==0 ) ) 
			{
				xformData.removeSubCombos ( 2 );
				xformData.loadCombos(0);
				
			}else
			{
				if ( xformData.cbCity.selectedIndex==0 )
				{
					xformData.removeSubCombos ( 1 );
					si = xformData.cbCountry.selectedIndex - 1
					xformData.loadCombo ( si, '', 3);
				}
				
			}
			
		}
		
	}
}

function countryChange(xformData)
{
	formdata.prototype.countryChange(xformData)
	
}
function cityChange(xformData)
{
	formdata.prototype.cityChange(xformData);
}

function hotelChange()
{

}

function _onLoad()
{
		
		switch ( controlRes ) 
		{
			case 1:
			
				formDataRes.loadFromString ( ResstringLoad );
				formDataRes.loadCombos(1);
				formData.loadFromString ( stringLoad );
				formData.loadCombos(1);	
				break;
					
			case 2: 
			
				formData.loadFromString ( stringLoad );
				formData.loadComboPos(formData);
				break;
				
			default:
			
				formData.loadFromString ( stringLoad );
				formData.loadCombos(1);	
				break;
				
		}
		
}

		
function changesDates(cboDay, cboMonth, cboYear, addDays, dDays, dMonth, dYear)
		{
		
			
			var cbDays = document.form.elements[ cboDay ];
			var cbMonth = document.form.elements[ cboMonth ];
			var cbYear = document.form.elements[ cboYear ];
		
			var iYear = cbYear.options[cbYear.selectedIndex].value;
			var iMonth = cbMonth.options[cbMonth.selectedIndex].value;
			iMonth = parseInt(iMonth) - 1 ;
			var iDay = cbDays.options[cbDays.selectedIndex].value; 
			var today = new Date(iYear, iMonth, iDay);
			var myDate=new Date(iYear, iMonth, iDay)
			
			myDate.setDate(myDate.getDate() + parseInt(addDays) ); 
						
			document.form.elements[ dDays ].options[myDate.getDate()-1].selected=true;
			document.form.elements[ dMonth ].options[myDate.getMonth()].selected=true;
			
			iYear=  myDate.getYear() - today.getYear() ;
			if ( iYear == 0 ) 
			{
				iYear = cbYear.selectedIndex;
			}
			document.form.elements[ dYear ].options[iYear].selected=true;
			
			if (document.form.cal2ctrl!=undefined)
			{
				document.form.cal2ctrl.value= myDate.getDate() + '-' + parseInt(myDate.getMonth ()+1) + '-' + myDate.getFullYear();
			}
			
			
		}		
		
//PARTE ANTIGA
function hotel( cName, code, parent )
{
	this.cname = cName;
	this.code = code;
	this.parent = parent;
}

function city ( cName, code, parent )
{
	this.cname = cName;
	this.code = code;
	this.hotels = [];
	this.parent = parent;
}

function country( cName , code)
{
	this.cname = cName;
	this.code = code;
	this.cities = [];
}

function formdata ( stringLoad )
{
	this.stringLoad = stringLoad;
	this.countries = [];
	
	this.sortCountries = [];
	this.sortCities = [];
	this.sortHotels = [];
	
	/* cb id names */
	this.cbCountry = null;
	this.cbCity = null;
	this.cbHotel = null;

	/* hd id names */
	this.hdCountry = null;
	this.hdCity = null;
	this.hdHotel = null;

	this.ignorechange=false;

	/* cb option name */
	this.opTextCountry = "?";
	this.opTextCity = "?";
	this.opTextHotel = "?";
	
	/* initial/selected values */
	this.iniCountry = "";
	this.iniCity = "";
	this.iniHotel = "";

	/* initial disabled values */
	this.disCountry = "";
	this.disCity = "";
	this.disHotel = "";

}

formdata.prototype.init = function ()
{
	this.loadFromString ( this.stringLoad );
	this.loadCombos ( 0, null );
	hotelChangeByVal(this.iniHotel, this);	
}

formdata.prototype.findCountryByID = function ( code ) 
{
	var i;


	for (i=0; i<this.sortCountries.length; i++)
	{
		if ( this.sortCountries[i].code == code ) return this.sortCountries[i];
	}

	return null;
}

formdata.prototype.findCityByID = function ( code ) 
{
	var i;

	for (i=0; i<this.sortCities.length; i++)
	{
		if ( this.sortCities[i].code == code ) return this.sortCities[i];
	}

	return null;
}

formdata.prototype.findHotelByID = function ( code ) 
{
	var i;

	
	for (i=0; i<this.sortHotels.length; i++)
	{
		if ( this.sortHotels[i].code == code ) return this.sortHotels[i];
	}

	return null;
}




formdata.prototype.addCountry = function ( cName, code ) 
{
	var current_country = new country(cName, code);
	this.countries.push(current_country);
	this.sortCountries.push(current_country);
	
	return current_country;
}

formdata.prototype.addCity = function ( cName, code, parent ) 
{
	var current_city = new city(cName, code, parent);
	parent.cities.push ( current_city );
	this.sortCities.push ( current_city );
	
	return current_city;
}

formdata.prototype.addHotel = function ( cName, code, parent ) 
{
	var current_hotel = new hotel(cName, code,parent);
	parent.hotels.push( current_hotel );
	this.sortHotels.push( current_hotel );

	return current_hotel;
}

formdata.prototype.listHotels = function ( )
{
	var out="", i,j,k;
	var country, city, hotel; 
	
	for (i=0; i<this.countries.length; i++)
	{
		country  = this.countries[i];
		for (j=0; j<country.cities.length; j++)
		{
			city = country.cities[j];
			
			for (k=0; k<city.hotels.length; k++)
			{
				hotel = city.hotels[k];
				
				out = out + country.cname + "." + city.cname + "." + hotel.cname + ";";
			}
		}
	}
	
	alert ( out );
}

formdata.prototype.objectCompare = function ( a, b )
{
	if ( a.cname < b.cname ) return -1;
	else if (a.cname > b.cname ) return 1;
	else return 0;
}


formdata.prototype.loadFromString = function ( stringLoad )
{
	var nodes = stringLoad.split(";");
	var i;
	var last_country, last_city, last_hotel;
	
	for (i=0; i<nodes.length; i++)
	{
		var splits = nodes[i].split(":");
		var nodetype = splits[0].substr(0,1);
		var val = splits[0].substr(1,splits[0].length-1);
		var code = splits[1];
		switch ( nodetype )	
		{
			case 'P':
				last_country = this.addCountry( val, code );
				break;
			case 'C':
				last_city = this.addCity ( val, code, last_country );
				break;
			case 'H':
				last_hotel = this.addHotel( val, code, last_city );
				break;
		}
	}
	
	this.sortCountries.sort ( this.objectCompare );
	this.sortCities.sort ( this.objectCompare );
	this.sortHotels.sort ( this.objectCompare );
}

formdata.prototype.optionLanguageText = function ( tCountry, tCity, tHotel )
{
	this.opTextCountry = tCountry;
	this.opTextCity = tCity;
	this.opTextHotel = tHotel;
}


formdata.prototype.removeSubCombos = function ( what )
{
	var i;
	
	for ( ; this.cbHotel.length>0 ; ) 
	{
		this.cbHotel.options[this.cbHotel.length-1] = null;
	}
	
	if (what > 1)
	{
		for ( ; this.cbCity.length>0 ;) 
		{
			this.cbCity.options [ this.cbCity.length-1 ] = null;
		}
	}
}

formdata.prototype.setDefaults = function ( iniCountry, iniCity, iniHotel )
{
	this.iniCountry = iniCountry;
	this.iniCity = iniCity;
	this.iniHotel = iniHotel;
	
}

formdata.prototype.setEnabled = function ( enableCountry, enableCity, enableHotel )
{

	this.disCountry = !enableCountry;
	this.disCity = !enableCity;
	this.disHotel = !enableHotel;

}
	
formdata.prototype.setComboID = function ( cbcountry, cbcity, cbhotel )
{
	this.cbCountry = cbcountry;
	this.cbCity = cbcity;
	this.cbHotel = cbhotel;
}	

formdata.prototype.setHiddenID = function ( hdcountry, hdcity, hdhotel )
{
	this.hdCountry = hdcountry;
	this.hdCity = hdcity;
	this.hdHotel = hdhotel;
}	

formdata.prototype.loadComboCountry = function (  )
{
	var selected = false;
	
	this.cbCountry.options[0] = new Option ( this.opTextCountry, "*", false, false);
	for (i=0; i<this.sortCountries.length; i++)
	{
		selected = ( this.sortCountries[i].code == this.iniCountry );
		this.cbCountry.options[i+1] = new Option ( this.sortCountries[i].cname, this.sortCountries[i].code, false, selected );
	}
	this.cbCountry.disabled = this.disCountry;
}

formdata.prototype.loadComboCity = function ( country_changed )
{
	var selected = false;

	this.cbCity.options[0] = new Option ( this.opTextCity, "*", false, false);

	if ( country_changed != null )
	{

	    country_changed.cities.sort ( this.objectCompare );

		for (i=0; i<country_changed.cities.length; i++)
		{
			selected = ( country_changed.cities[i].code == this.iniCity );
			this.cbCity.options[i+1] = new Option ( country_changed.cities[i].cname, country_changed.cities[i].code, false, selected );
		}
	}
	else
	{
		this.cbCity.options[0] = new Option ( this.opTextCity, "*", false, false);
		for (i=0; i<this.sortCities.length; i++)
		{
			selected = ( this.sortCities[i].code == this.iniCity );
			this.cbCity.options[i+1] = new Option ( this.sortCities[i].cname, this.sortCities[i].code, false, selected);
		}
	}
	this.cbCity.disabled = this.disCity;
}

formdata.prototype.loadHotelParents  = function ( hotel_changed )
{
	this.ignorechange = true;

	this.setDefaults ( hotel_changed.parent.parent.code, hotel_changed.parent.code, hotel_changed.code );

	this.removeSubCombos ( 2 );
							
	for (i=0; i<this.cbCountry.options.length; i++ )
	{
		if ( this.cbCountry.options[i].value == this.iniCountry )
		{
			this.cbCountry.selectedIndex = i;
			break;
		}
	}

	this.loadComboCity ( hotel_changed.parent.parent );
	this.loadComboHotel ( null, hotel_changed.parent );		

	this.ignorechange = false;
}

formdata.prototype.loadComboHotel = function ( country_changed, city_changed )
{
	var selected = false;

	this.cbHotel.options[0] = new Option ( this.opTextHotel, "*", false, false);

	if ( country_changed != null )
	{
		for (j=1, i=0; i<this.sortHotels.length; i++)
		{
			if ( this.sortHotels[i].parent.parent.code == country_changed.code )
			{
				selected = ( this.sortHotels[i].code == this.iniHotel );
				this.cbHotel.options[j++] = new Option ( this.sortHotels[i].cname, this.sortHotels[i].code, false, selected );
			}
		}
	}
	else if (city_changed != null )
	{
		city_changed.hotels.sort ( this.objectCompare );

		for (i=0; i<city_changed.hotels.length; i++)
		{
			selected = ( city_changed.hotels[i].code == this.iniHotel );
			this.cbHotel.options[i+1] = new Option ( city_changed.hotels[i].cname, city_changed.hotels[i].code, false, selected);
		}

		/* exceptional case */		
		
		if ( this.cbCountry.options[ this.cbCountry.selectedIndex ].value != city_changed.parent.code )
		{
			for (i=0; i<this.cbCountry.options.length; i++ )
			{
				if ( this.cbCountry.options[i].value == city_changed.parent.code )
				{
					this.cbCountry.selectedIndex = i;
					this.setDefaults ( city_changed.parent.code, city_changed.code, this.cbHotel.code );
					this.cbCountry.onchange ( this.cbCountry, this );
					
					break;
				}
			}
		}
		
	}
	else
	{
		this.cbHotel.options[0] = new Option ( this.opTextHotel, "*", false, false);
		for (i=0; i<this.sortHotels.length; i++)
		{
			this.cbHotel.options[i+1] = new Option ( this.sortHotels[i].cname, this.sortHotels[i].code, false, false);
		}
	}
	this.cbHotel.disabled = this.disHotel;

}


formdata.prototype.loadCombos = function ( Initialize, objchanged )
{
	var i;
	
	switch ( Initialize)
	{
		case 0:
		{		
		
			this.cbCountry = document.forms[0].elements[ this.cbCountry ];
			this.cbCity = document.forms[0].elements[ this.cbCity ];
			this.cbHotel = document.forms[0].elements[ this.cbHotel ];

			this.hdCountry = document.forms[0].elements[ this.hdCountry ];
			this.hdCity = document.forms[0].elements[ this.hdCity ];
			this.hdHotel = document.forms[0].elements[ this.hdHotel ];

            var country = this.findCountryByID( this.iniCountry );
            var city = this.findCityByID ( this.iniCity );

			this.loadComboCountry();
			this.loadComboCity ( country );
			this.loadComboHotel ( null, city );		

			break;
		}
		case 1:
		{
			// country changed
			var country_changed = objchanged;
			this.removeSubCombos ( 2 );
			this.loadComboCity ( country_changed );
			this.loadComboHotel ( country_changed, null );
			break;
		}
		case 2:
		{
			// city changed
			var city_changed = objchanged;
			this.removeSubCombos ( 1 );
			this.loadComboHotel ( null, city_changed );
			break;
		}
		case 3:
		{
			var hotel_changed = objchanged;
			this.loadHotelParents ( hotel_changed );
			break;
		}
	}
}



function _onLoad()
{
    formData1.init();
}

function countryChange(o, master)
{
	if (!master.ignorechange )
	{
		master.ignorechange = true;
		
		var country = master.findCountryByID ( o.value );
		master.loadCombos (1, country);	
		master.ignorechange = false;
	}
}

function regionChange(o, master)
{
	if (!master.ignorechange )
	{
		master.ignorechange = true;
		
		var city = master.findCityByID ( o.value );
		if ( city != null )
		{
			master.loadCombos (2, city);
		}
		else
		{
			master.cbHotel.value = '*' ;
		}

		master.ignorechange = false;
	}
}

function hotelChange(o, master)
{
	if (!master.ignorechange )
	{
		master.ignorechange = true;

		var hotel = master.findHotelByID ( o.value );
		if (hotel != null )
		{
			master.loadCombos (3, hotel);	
		}
	
		master.ignorechange = false;
	}
}

function hotelChangeByVal(val, master)
{
	if (!master.ignorechange && val != "" )
	{
		master.ignorechange = true;

		var hotel = master.findHotelByID ( val );
		if (hotel != null )
		{
			master.loadCombos (3, hotel);	
		}
	
		master.ignorechange = false;
	}
}

function updateHidden( master)
{

    master.hdHotel.value = master.cbHotel.value;
    master.hdCity.value = master.cbCity.value;
    master.hdCountry.value = master.cbCountry.value;
}

function addOnloadEvent(fnc)
{
      if ( typeof window.addEventListener != "undefined" )
      {
            // mozilla
            window.addEventListener( "load", fnc, false );
      }
      else if ( typeof window.attachEvent != "undefined" ) 
      {
            //ie
            window.attachEvent( "onload", fnc );
      }
      else 
      {
            if ( window.onload != null ) 
            {
                  var oldOnload = window.onload;
                  window.onload = function ( e ) 
                  {
                        oldOnload( e );
                        window[fnc]();
                  };
            }
            else window.onload = fnc;
      }
}

