function ctn_populateSelect(selectId, x, v, f, d, oid)
{
	$("#" + selectId + " *").remove();
	var prevValue = String("");
	for (var i = 0; i < x.length; i++)
		for (var j=0;j<x[i][2].length;j++)
			if ((x[i][2][j] == f ) || (x[i][2][j] == "" ) || (f == "")/* || (x[i][0] == d )*/) {
				var optionElement = document.createElement('OPTION');
				optionElement.setAttribute('value', x[i][0]);
				if (typeof oid != 'undefined') optionElement.setAttribute('id', oid + x[i][0]);
				var theData = document.createTextNode( x[i][1]);
				if ((x[i][1] == v ) || (x[i][0] == d )) optionElement.setAttribute('selected', 'true');
				optionElement.appendChild(theData);
				if ((x[i].length > 3) && ("" != x[i][3])){ 
					if (prevValue != x[i][3]) {
						prevValue = x[i][3];
						var optionGroup = document.createElement('OPTGROUP');
						optionGroup.setAttribute('label', x[i][3]);
						document.getElementById(selectId).appendChild(optionGroup);
					}
					optionGroup.appendChild(optionElement);
				} else {
					document.getElementById(selectId).appendChild(optionElement)
				};
				break;
			}
}
function ctn_seekArray(x, v, idx)
{	
	if (typeof idx == "undefined") idx = 0;
	for (var i = 0; i < x.length; i++) if (x[i][idx] == v ) return (x[i]);
	return (false);
}

function ctn_get_componentDHTML(_id, _c, _elements, _styles){

	var componentDHTML = {
		id: "", 
		c: "", 
		elements: [],
		styles: [],
		init: function (id, c, elements, styles){
			this.id= id; this.c= c; this.elements= elements; this.styles= styles; 
		},
		build: function() {  
			if (this.c != "") {
				if (!this.parsed) this.parseId();
				var _c = this.c;
				var _id = this.id;
				$(this.elements).each(function (i) {
					if (this.tag != "") {
						if (this.c == "") this.c = _c ;
						$(["<" , this.tag , " " , 
							(((this.tag=="INPUT") && (typeof this.tp != "undefined")) ? " type=\"" + this.tp + "\"" : "") , 
							" id=\"" , this.id , "\" >" , this.txt , "</" , this.tag , ">"].join("")).appendTo("#" + this.c);
						if (typeof this.attr != "undefined") $([this.tag, "#", this.id].join("")).attr(this.attr);
					}
				});
			} 
		},
		style: function() {
			if (!this.parsed) this.parseId();
			$(this.styles).each(function (i) {
				if (this.id != "") {
					$("#" + this.id).css(this.style);
				}
			});
		},
		make: function() {
			this.build();
			this.style();
		},
		// privates config attr
		parsed: false,
		// privates config methods
		parseId: function() {
			var _id = this.id;
			this.parsed = true;
			$(this.elements).each(function (i) {
				if (this.id != "") this.id = _id + this.id;
				if (this.c != "") this.c = _id + this.c;
			});
			$(this.styles).each(function (i) {
				if (this.id != "") this.id = _id + this.id;
			});
		},

		final: function() {}
	}
	componentDHTML.init(_id, _c, _elements, _styles);
	return (componentDHTML);
}

function ctn_valid_date(s_d)
{
	var a_d = s_d.split('/');
	if (a_d.length != 3) return false;
	for (var i= 0; i < 3; i++ ) if (isNaN(a_d[i])) return false; else a_d[i] = (1 * a_d[i]);
	var d_m_rs = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; 
	if (((a_d[2] % 4 == 0)&&((a_d[2] % 100) != 0))|| ((a_d[2] % 400 == 0))) d_m_rs[2] = 29;
	var d_rs = [{n:1, x:31}, {n:1, x:12}, {n:1950, x:2050}]; if (a_d[1] < d_m_rs.length) d_rs[0].x = d_m_rs[a_d[1]];
	for (var i= 0; i < 3; i++ ) if ((d_rs[i].n > a_d[i])|| (d_rs[i].x < a_d[i])) return false;
	return true;
}
function ctn_parse_date(s_d)
{
	var a_d = s_d.split('/');
	if (a_d.length != 3) return 0;
	for (var i= 0; i < 3; i++ ) if (isNaN(a_d[i])) return 0; else a_d[i] = (1 * a_d[i]);
	var t_d = new Date(a_d[2], a_d[1] - 1, a_d[0]);
	return (Date.parse(t_d));
}


function ctn_test_form(id)
{
	var msg_test = "Testing Mode"
	msg_test = msg_test + "\n----------------------------------------------------";
	msg_test = msg_test + "\nURL:" + $("#" + id + "").attr("action");
	$("#" + id + " input").each(function(i){
		msg_test = msg_test + "\n" + $(this).attr("name") + ": " + $(this).val();
	});
	msg_test = msg_test + "\n----------------------------------------------------";
	return (window.confirm (msg_test));
}


var tabsHelper = {
	tabs: function(){ return({
		tabs: [],
		active_tab: "",
		show: function(tabId){
			if (tabId != this.active_tab) {
				this.hide_tab(this.active_tab);
				this.show_tab(tabId);
				this.active_tab = tabId;
			}
		},
		show_tab: function(tabId){
			for (var i= 0; i < this.tabs.length; i++ )
				if (this.tabs[i].id == tabId){
						$("#" + this.tabs[i].id).addClass("selected");
						$("#" + this.tabs[i].page).fadeIn();
					}
		},
		hide_tab: function(tabId){
			for (var i= 0; i < this.tabs.length; i++ )
				if (this.tabs[i].id == tabId){
						$("#" + this.tabs[i].id).removeClass("selected");
						$("#" + this.tabs[i].page).fadeOut();
					}
		},
		add: function(tabId, pageId){
			this.tabs[this.tabs.length] = {id:tabId, page:pageId};
			this.active_tab= tabId;
		}
	})},
	bind: function (tabs){
		for (var i= 0; i < tabs.tabs.length; i++ ){
			$("#" + tabs.tabs[i].id).click(function(){ 
				tabs.show(this.id); 
		});
		}
	},
	add: function (tabs, tabId, pageId){
		tabs.add(tabId, pageId);
	},
	start: function (tabs, active_tab){
		if (typeof active_tab == "undefined"){ 
			if (tabs.tabs.length >= 0) tabs.active_tab = tabs.tabs[0].id;
		} else tabs.active_tab = active_tab;
		for (var i= 0; i < tabs.tabs.length; i++ ){
			$("#" + tabs.tabs[i].id).css("cursor", "pointer");
			if (tabs.tabs[i].id != tabs.active_tab) tabs.hide_tab(tabs.tabs[i].id); else tabs.show_tab(tabs.tabs[i].id);
		}
	}
};

var searchBox = {
	options: {
		c: "",
		id: "",
	
		commercial_client_code : "",
		point_of_sale : "",
		commercial_client_type : "",
		affiliate_id : "",
		reseller_id : "",
		
		box_mode: "book-ol",
		target: "_blank",
		method: "GET",

		site_from: "http://www.fast-manager.com", //site_from: "http://localhost:50000", //site_from: "http://site4.fast-manager.com", //
		language: "en",
		languages: ["en", "fr", "de", "es", "it", "nl"],
		currency: "USD",
		currencies : ["AUD","CAD","EUR","GBP","JPY","USD"],
		forbidden_currencies: [["CUB","USD"]],
	
		color_dark: "#000000", color_medium: "#097864", color_clear: "#ffffff",

		region: "Caribe",
	
		use_external_css: false,
	
		show_title: true, 
		show_currency: true,
	
/* /// No se usan
		contact_us_ta_link: "",	
		width: "100%", 
*/		
		loading: [['', 'loading data... ', [''], '']],
		ready: false
	},
	texts: {},
	boxes: [],
	init: function(){
		if (this.options.c != ""){
			var tabsSearch = tabsHelper.tabs();
	
			// se inicializan c/u de los buscadores empotrados
			for (var i = 0; i < this.boxes.length; i++) {
				var empty = {};
				this.boxes[i].options = $.extend(empty, this.options, this.boxes[i].options);

				var cD = ctn_get_componentDHTML(this.options.id, this.options.c, this.boxes[i].elements, this.boxes[i].styles);
				cD.make();
				
				if (typeof this.boxes[i].form_book_elements != "undefined") {
					var cFB = ctn_get_componentDHTML(this.options.id, this.options.c, this.boxes[i].form_book_elements, []);
					cFB.make();
				}

				if (typeof this.boxes[i].options.tab_id != "undefined") tabsHelper.add(tabsSearch, this.options.id + this.boxes[i].options.tab_id, this.options.id + this.boxes[i].options.tab_page);
			}
	
			tabsHelper.bind(tabsSearch);
			tabsHelper.start(tabsSearch);

			for (var i = 0; i < this.boxes.length; i++) {
				this.boxes[i].init();
				if (!this.options.use_external_css) {
					$("#" + this.boxes[i].options.id + this.boxes[i].options.form_id + " div.d").css({"background-color":this.boxes[i].options.color_clear, "border-color":this.boxes[i].options.color_dark});
					$("#" + this.boxes[i].options.id + this.boxes[i].options.form_id + " .t").css({"background-color":this.boxes[i].options.color_dark, "border-color":this.boxes[i].options.color_dark, "color":"#FFFFFF"});
					$("#" + this.boxes[i].options.id + this.boxes[i].options.form_id + " input.btn").css({"background-color":this.boxes[i].options.color_dark, "border-color":this.boxes[i].options.color_dark, "color":"#FFFFFF"});
				}
			}
			
			_self = this;
			$.getJSON(this.options.site_from + "/comun/scripts/sb_response_json.asp?q=lang_contents&language_id=" + this.options.language + "&jsoncallback=?", function(data, textStatus){
				var empty = {};
				_self.texts = $.extend(empty, data.lang_contents, _self.texts);
				
				for (var i = 0; i < _self.boxes.length; i++) {
					if (jQuery.isFunction(_self.boxes[i].set_elements_txt)) {
						_self.boxes[i].set_elements_txt(_self.texts);
					}
				}
			});
		}
	},
	setStyle: function(box, style){
		var found = false;
		for (var i = 0; i < box.styles.length; i++)
			if (style.id == box.styles[i].id) {
				var empty = {}
				box.styles[i].style = $.extend(empty, box.styles[i].style, style.style);
				found = true; break;
			}
		if (!found) box.styles = $.merge(box.styles, [style])
	},
	setStyles: function(box, styles){
		for (var i = 0; i < styles.length; i++)
			this.setStyle(box, styles[i]);
	},
	setElement: function(box, element){
		var found = false;
		for (var i = 0; i < box.elements.length; i++)
			if (element.id == box.elements[i].id) {
				if (typeof element.txt != "undefined") box.elements[i].txt = element.txt;
				if (typeof element.tag != "undefined") box.elements[i].tag = element.tag;
				if (typeof element.c != "undefined") box.elements[i].c  = element.c;
				var empty = {}
				box.elements[i].attr = $.extend(empty, box.elements[i].attr, element.attr);
				found = true; break;
			}
		if (!found) box.elements = $.merge(box.elements, [element])
	},
	setElements: function(box, elements){
		for (var i = 0; i < elements.length; i++)
			this.setElement(box, elements[i]);
	}
}

var searchComun = {	
	options: {},
	init: function(){
	},
	//	elements del buscador de hoteles
	elements: [{id:"t1", txt:"Book Cbb Trip", tag:"H2", c:"", attr:{"class":"t"}},
		//	elements del menú
		 {id:"tabs_menu", txt:"", tag:"UL", c:""},
		 {id:"tabs_menu_hotel", txt:"hotel", tag:"LI", c:"tabs_menu", attr:{"class":"tab"}},
		 {id:"tabs_menu_spc_li_1", txt:"", tag:"LI", c:"tabs_menu", attr:{"class":"sep"}},
		 {id:"tabs_menu_flight", txt:"flight", tag:"LI", c:"tabs_menu", attr:{"class":"tab"}},
		 {id:"tabs_menu_spc_li_2", txt:"", tag:"LI", c:"tabs_menu", attr:{"class":"sep"}},
		 {id:"tabs_menu_car", txt:"car", tag:"LI", c:"tabs_menu", attr:{"class":"tab"}}],
	styles:[]
};

var searchHotels = {
	options: {
		form_id: "hotel_form",
		tab_id: "tabs_menu_hotel",
		tab_page: "hotel",
		action_book_fc: "http://www.fastbookings.biz/DIRECTORY/dispoprice.phtml",
		target: "dispoprice",

		action_book_venere: "http://www.venere.com/search/wrapper.php",
		ref_venere: "854359",
		
		release_time : 3,
		country: '',
		destination: '',
		destination_name: '',
		destinations: [[""," - Any Destination - ",[""],"", "", ""]],
		hotel: '',
		hotels: [["All"," - Any Hotel - ",[""],"", "All", "All"]],
		
		nights: 1,
		adults: 1,
		children: 0,

		show_countries: true,
		show_destinations: true,
		show_hotels: true,
		show_iata_code: true		
	},
	init: function(){
		var _o = this.options;

		$("#" + _o.id + "hotel_country").css('display', (_o.show_countries ? '':'none'));
		$("#" + _o.id + "hotel_destination").css('display', (_o.show_destinations ? '':'none'));
		$("#" + _o.id + "hotel_hotel").css('display', (_o.show_hotels ? '':'none'));
		$("#" + _o.id + "hotel_a_code").css('display',(_o.show_iata_code ? '':'none'));
		$("#" + _o.id + "hotel_title").css('display', (_o.show_title ? '':'none'));
		$("#" + _o.id + "hotel_currency").css('display', (_o.show_currency ? '':'none'));

		//se busca si la moneda definida está dentro del arreglo, si no se establece EUR
		this.options.currency = ($.inArray(this.options.currency, this.options.currencies) != -1) ? this.options.currency : "EUR";
		
		//se busca si el idioma definido está dentro del arreglo, si no se establece EN
		this.options.language = ($.inArray(this.options.language, this.options.languages) != -1) ? this.options.language : "en";

		ctn_populateSelect(_o.id + "hotel_destination_select", _o.loading, '', '', '');
		ctn_populateSelect(_o.id + "hotel_hotel_select", _o.loading, '', '', '');
		ctn_populateSelect(_o.id + "hotel_currency_select", _o.loading, '', '', '');
		
		// calendarios de reserva de hoteles
		var d = new Date();
		d.setDate(d.getDate() + _o.release_time);
		$("#" + _o.id + "hotel_arrival_date_edit").val(d.getDate() + "/" + (d.getMonth() + 1) + "/" + d.getFullYear());
/*		$("#" + _o.id + "hotel_arrival_date_edit").datepicker({minDate: _o.release_time, maxDate: '+1Y', dateFormat: 'dd/mm/yy' });
		$("#" + _o.id + "hotel_arrival_date_edit").datepicker('setDate', _o.release_time + 'D' );
*/		
		ctn_populateSelect(_o.id + "hotel_country_select", _o.loading, '', '', '');
		$.getJSON(_o.site_from + "/comun/scripts/sb_response_json.asp?q=hotel_countries,currencies&language_id=" + _o.language + "&city_region=" + _o.region + "&jsoncallback=?", function(data, textStatus){
		
			_o.countries = data.hotel_countries;
			ctn_populateSelect(_o.id + "hotel_country_select", _o.countries, '', '', _o.country);
			ctn_populateSelect(_o.id + "hotel_currency_select", data.currencies, '', '', _o.currency, _o.id + "hotel_");
			
			$("#" + _o.id + "hotel_country_select").change(function(){
				_o.curr_country = $("#" + _o.id + "hotel_country_select option:selected").val();
				var found = false;
				for (var i= 0; i < _o.destinations.length; i++) if (_o.destinations[i][2][0] == _o.curr_country) {found = true; break}
				if (found){
					_o.destinations[0][0] = _o.curr_country;// Filtrar los hoteles por pais cuando se pueda escoger cualquier destino, filtro de hoteles: destino, destino padre o pais
					ctn_populateSelect(_o.id + "hotel_destination_select", _o.destinations, '', _o.curr_country, _o.destination);
					$("#" + _o.id + "hotel_destination_select").change();
				} else {
					ctn_populateSelect(_o.id + "hotel_destination_select", _o.loading, '', '', '');
					ctn_populateSelect(_o.id + "hotel_hotel_select", _o.loading, '', '', '');
					$.getJSON(_o.site_from + "/comun/scripts/sb_response_json.asp?q=hotel_destinations,hotel_hotels&language_id=" + _o.language + "&country=" + _o.curr_country + "&jsoncallback=?", function(data, textStatus){
						_o.destinations = $.merge(_o.destinations , data.hotel_destinations);

						if ((_o.destination_name != '') && (_o.destination == '')) {
							var t_param_destination = ctn_seekArray(_o.destinations, _o.destination_name, 7);
							if ($.isArray(t_param_destination)) _o.destination = t_param_destination[0];
						}

						_o.destinations[0][0] = _o.curr_country;// Filtrar los hoteles por pais cuando se pueda escoger cualquier hotel, los hoteles se filtran por destino, destino padre o pais
						ctn_populateSelect(_o.id + "hotel_destination_select", _o.destinations, '', _o.curr_country, _o.destination);
		
						_o.hotels = $.merge(_o.hotels , data.hotel_hotels);
						$("#" + _o.id + "hotel_destination_select").change(function(){
							_o.curr_destination = $("#" + _o.id + "hotel_destination_select option:selected").val();
							ctn_populateSelect(_o.id + "hotel_hotel_select", _o.hotels, '', _o.curr_destination, _o.hotel);
						}).change();
					});
				}
				$("#" + _o.id + "hotel_currency_select").change(function(){
				if ($("#" + _o.id + "hotel_currency_select option:selected").attr("disabled")) {
					$("#" + _o.id + "hotel_currency_select option:enabled:first").attr("selected","selected");
				}
			});

				$("#" + _o.id + "hotel_currency_select option").removeAttr("disabled").css({"color":""});
				for (var i = 0; i < _o.forbidden_currencies.length; i++) {
					if((_o.forbidden_currencies[i][0] == _o.curr_country) || (_o.forbidden_currencies[i][0] == "*")){
						$("#" + _o.id + "hotel_currency_select option#" + _o.id + "hotel_" + _o.forbidden_currencies[i][1]).attr("disabled","disabled").css({"color":"#CCC"}); break;
					}
				}
				$("#" + _o.id + "hotel_currency_select").change();

			}).change();
		});

		ctn_populateSelect(_o.id + "hotel_nights_select", [[1,1,['']],[2,2,['']],[3,3,['']],[4,4,['']],[5,5,['']],[6,6,['']],[7,7,['']],[8,8,['']],[9,9,['']],[10,10,['']],[11,11,['']],[12,12,['']],[13,13,['']],[14,14,['']],[15,15,['']]], '', '', _o.nights);
		ctn_populateSelect(_o.id + "hotel_adults_select", [[1,1,['']],[2,2,['']],[3,3,['']],[4,4,['']],[5,5,['']],[6,6,['']]], '', '', _o.adults);
		ctn_populateSelect(_o.id + "hotel_children_select", [[0,0,['']],[1,1,['']],[2,2,['']],[3,3,['']]], '', '', _o.children);
		
		$("#" + _o.id + "hotel_search_boton").click(function(){
			_o.ready = true;
			var sel_destination = ctn_seekArray(_o.destinations, $("#" + _o.id + "hotel_destination_select").val());
			var sel_hotel = ctn_seekArray(_o.hotels, $("#" + _o.id + "hotel_hotel_select").val());
			if (!$.isArray(sel_destination)) sel_destination = ["","",[""],"","","",""];
			if (!$.isArray(sel_hotel)) sel_hotel = ["","",[""],"","All",""];

			if((_o.ready) && (!ctn_valid_date($("#" + _o.id + "hotel_arrival_date_edit").val()))){
				alert('The hotel arrival date is incorrect. Please, type a date according to our settings (dd/mm/yyyy)');
				$("#" + _o.id + "hotel_arrival_date_edit").focus();
				_o.ready = false;
			}	
			
			if (_o.ready){
				var clusternames;
				_o.curr_country = $("#" + _o.id + "hotel_country_select option:selected").val();
				switch (_o.curr_country ) {
				   case "CUB" : clusternames = "crscubasct";break;
				   case "DOM" : clusternames = "crsdtnhotels";break;
				   default : clusternames = "";
				} 
				$("#" + _o.id + "hot_r input").val ("");

				if (typeof _o.affiliates_id != "undefined"){// codigo de afiliado en dependencia del pais
					for (var i = 0; i < _o.affiliates_id.length; i++) {
						if ((_o.affiliates_id[i][0] == _o.curr_country) || (_o.affiliates_id[i][0] == "*")) {
							_o.affiliate_id = _o.affiliates_id[i][1]; break;
						}
					}
				}
				
				if ((clusternames == "") || (sel_hotel[4] == "venere")) {// Pais en Destino fuera de FB u hotel con reserva via VENERE
					$("#" + _o.id + "hot_r_ref").val (_o.ref_venere);
					$("#" + _o.id + "hot_r_lg").val (_o.language);
					$("#" + _o.id + "hot_r_rval").val ($("#" + _o.id + "hotel_adults_select").val());
					if (sel_hotel[4] == "All"){
						if (sel_destination[4] != "")
							$("#" + _o.id + "hot_r_city").val ($("#" + _o.id + "hotel_destination_select option:selected").text());
						else $("#" + _o.id + "hot_r_city").val ($("#" + _o.id + "hotel_country_select option:selected").text());
						$("#" + _o.id + "hot_r_geoid").val ('');
					}
					var from_date = $("#" + _o.id + "hotel_arrival_date_edit").val().split('/');
					$("#" + _o.id + "hot_r_sd").val (from_date[0]);
					$("#" + _o.id + "hot_r_sm").val (from_date[1]);
					$("#" + _o.id + "hot_r_sy").val (from_date[2]);
					var end_date = new Date(new Date(from_date[2], from_date[1] - 1, from_date[0]).valueOf() + $("#" + _o.id + "hotel_nights_select").val() * 24*60*60*1000);
					$("#" + _o.id + "hot_r_ed").val (end_date.getDate());
					$("#" + _o.id + "hot_r_em").val (end_date.getMonth() + 1);
					$("#" + _o.id + "hot_r_ey").val (end_date.getFullYear());
					$("#" + _o.id + "hot_r_pval").val (parseInt ($("#" + _o.id + "hotel_adults_select").val()) + parseInt ($("#" + _o.id + "hotel_children_select").val()));
					$("#" + _o.id + "hot_r").attr({method: _o.method, target: _o.target});
					
					if((sel_hotel[5] == "") || (sel_hotel[5] == "All")) 
						$("#" + _o.id + "hot_r").attr({action:_o.action_book_venere});
					else
						$("#" + _o.id + "hot_r").attr({action:sel_hotel[5]});
	
					var submit_form_book = true;
					if (_o.box_mode == "test") submit_form_book = (ctn_test_form(_o.id + "hot_r"));
					if (submit_form_book) {$("#" + _o.id + "hot_r").submit()};
				} else {// Pais en Destino en FB y hotel con reserva via FB
					$("#" + _o.id + "hot_r_FSTBKNGTrackLink").val (_o.affiliate_id);
					var lc = ["en", "uk", "fr", "france", "de", "germany", "es", "spain", "it", "italy", "nl", "nether", "ja", "japan ", "jp", "japan", "hu", "hungria"];
					for (var i= 0; i < lc.length; i++ ) if (lc[i] == _o.language) break;
					$("#" + _o.id + "hot_r_langue").val (lc[i+1]);
	//				$("#" + _o.id + "hot_r_showPromotions").val ('');
					$("#" + _o.id + "hot_r_Clusternames").val (clusternames);
					$("#" + _o.id + "hot_r_region").val (sel_destination[4]);
					$("#" + _o.id + "hot_r_city").val (sel_destination[5]);
					$("#" + _o.id + "hot_r_Hotelnames").val (sel_hotel[5]);
					$("#" + _o.id + "hot_r_nbdays").val ($("#" + _o.id + "hotel_nights_select").val());
					$("#" + _o.id + "hot_r_AccessCode").val ($("#" + _o.id + "hotel_a_code_edit").val());
					var from_date = $("#" + _o.id + "hotel_arrival_date_edit").val().split('/');
					$("#" + _o.id + "hot_r_fromday").val (from_date[0]);
					$("#" + _o.id + "hot_r_frommonth").val (from_date[1]);
					$("#" + _o.id + "hot_r_fromyear").val (from_date[2]);
					$("#" + _o.id + "hot_r_adulteresa").val ($("#" + _o.id + "hotel_adults_select").val());
					$("#" + _o.id + "hot_r_enfantresa").val ($("#" + _o.id + "hotel_children_select").val());
					$("#" + _o.id + "hot_r_CurrencyLabel").val ($("#" + _o.id + "hotel_currency_select").val());
					
					$("#" + _o.id + "hot_r").attr({action: _o.action_book_fc, method: _o.method, target: _o.target});
	
					var submit_form_book = true;
					if (_o.box_mode == "test") submit_form_book = (ctn_test_form(_o.id + "hot_r"));
					if (submit_form_book) {// Abriendo proceso de reserva de hoteles de FB con su estilo de ventana popup
						window.open('',_o.target, 'toolbar=no,width=800,height=550,menubar=no,scrollbars=yes,resizable=yes');
						$("#" + _o.id + "hot_r").submit();
					}
				}
			}
		});

	},
	set_elements_txt: function (l){
		var elements_txt = [
			 {id:"hotel_title", txt:l.hotel_title},
			 {id:"hotel_country_label", txt:l.hotel_country_label},
			 {id:"hotel_destination_label", txt:l.hotel_destination_label},
			 {id:"hotel_hotel_label", txt:l.hotel_hotel_label},
			 {id:"hotel_arrival_label", txt:l.hotel_arrival_label},
			 {id:"hotel_arrival_span", txt:l.hotel_arrival_span},
			 {id:"hotel_nights_label", txt:l.hotel_nights_label},
			 {id:"hotel_adults_label", txt:l.hotel_adults_label},
			 {id:"hotel_children_label", txt:l.hotel_children_label},
			 {id:"hotel_currency_label", txt:l.hotel_currency_label},
			 {id:"hotel_a_code_label", txt:l.hotel_a_code_label},
			 {id:"hotel_a_code_span", txt:l.hotel_a_code_span}];

		for (var i = 0; i < elements_txt.length; i++) {
			$("#" + this.options.id + elements_txt[i].id).text(elements_txt[i].txt)
		}
		
		$("#" + this.options.id + "hotel_search_boton").val(l.hotel_button);
		
		this.options.destinations[0][1] = l.hotel_destination_option;
		this.options.hotels[0][1] = l.hotel_hotel_option;

		this.options.loading[0][1] = l.hotel_loading;
		
	},

	//	elements del buscador de hoteles
	elements: [
		 {id:"hotel_form", txt:"", tag:"FORM", c:""},
		 {id:"hotel", txt:"", tag:"DIV", c:"hotel_form", attr:{"class":"d"}},
		 {id:"hotel_title", txt:"Book Cbb Hotel", tag:"H3", c:"hotel", attr:{"class":"t"}},
		//	elements del buscador de hoteles: selector de pais
		 {id:"hotel_country", txt:"", tag:"DIV", c:"hotel", attr:{"class":"c"}},
		 {id:"hotel_country_label", txt:"Select Country:", tag:"LABEL", c:"hotel_country"},
		 {id:"hotel_country_select", txt:"", tag:"SELECT", c:"hotel_country"},
		//	elements del buscador de hoteles: selector de destino
		 {id:"hotel_destination", txt:"", tag:"DIV", c:"hotel", attr:{"class":"c"}},
		 {id:"hotel_destination_label", txt:"Select Destination:", tag:"LABEL", c:"hotel_destination"},
		 {id:"hotel_destination_select", txt:"", tag:"SELECT", c:"hotel_destination"},
		//	elements del buscador de hoteles: selector de hotel
		 {id:"hotel_hotel", txt:"", tag:"DIV", c:"hotel", attr:{"class":"c"}},
		 {id:"hotel_hotel_label", txt:"Select Hotel:", tag:"LABEL", c:"hotel_hotel"},
		 {id:"hotel_hotel_select", txt:"", tag:"SELECT", c:"hotel_hotel"},
		//	elements del buscador de hoteles: fecha de llegada
		 {id:"hotel_arrival", txt:"", tag:"DIV", c:"hotel", attr:{"class":"c"}},
		 {id:"hotel_arrival_label", txt:"Arrival date:", tag:"LABEL", c:"hotel_arrival"},
		 {id:"hotel_arrival_date_edit", txt:"", tag:"INPUT", c:"hotel_arrival", attr:{/* readonly:"true", */ "class":"date"}},
		 {id:"hotel_arrival_span", txt:"(dd/mm/yyyy)", tag:"SPAN", c:"hotel_arrival"},
		//	elements del buscador de hoteles: cantidad de noches 
		 {id:"hotel_nights", txt:"", tag:"DIV", c:"hotel", attr:{"class":"c"}},
		 {id:"hotel_nights_label", txt:"Nights:", tag:"LABEL", c:"hotel_nights"},
		 {id:"hotel_nights_select", txt:"", tag:"SELECT", c:"hotel_nights"},
		//	elements del buscador de hoteles: cantidad de mayores 
		 {id:"hotel_adults", txt:"", tag:"DIV", c:"hotel", attr:{"class":"c"}},
		 {id:"hotel_adults_label", txt:"Adults:", tag:"LABEL", c:"hotel_adults"},
		 {id:"hotel_adults_select", txt:"", tag:"SELECT", c:"hotel_adults"},
		//	elements del buscador de hoteles: cantidad de niños 
		 {id:"hotel_children", txt:"", tag:"DIV", c:"hotel", attr:{"class":"c"}},
		 {id:"hotel_children_label", txt:"Children:", tag:"LABEL", c:"hotel_children"},
		 {id:"hotel_children_select", txt:"", tag:"SELECT", c:"hotel_children"},
		//	elements  buscador de hoteles: moneda
		 {id:"hotel_currency", txt:"", tag:"DIV", c:"hotel", attr:{"class":"c"}},
		 {id:"hotel_currency_label", txt:"Currency:", tag:"LABEL", c:"hotel_currency"},
		 {id:"hotel_currency_select", txt:"", tag:"SELECT", c:"hotel_currency"},
		//	elements del buscador de hoteles: código de acceso
		 {id:"hotel_a_code", txt:"", tag:"DIV", c:"hotel", attr:{"class":"c"}},
		 {id:"hotel_a_code_label", txt:"IATA Code / Access Code:", tag:"LABEL", c:"hotel_a_code"},
		 {id:"hotel_a_code_edit", txt:"", tag:"INPUT", tp:"password", c:"hotel_a_code"},
		 {id:"hotel_a_code_span", txt:"(optional)", tag:"SPAN", c:"hotel_a_code"},
		//	elements del buscador de hoteles: boton
		 {id:"hotel_search", txt:"", tag:"DIV", c:"hotel", attr:{"class":"btn"}},
		 {id:"hotel_search_boton", txt:"", tag:"INPUT", tp:"button", c:"hotel_search", attr:{value:"Search Hotels", "class":"btn"}},
	 	 {id:"hotel_close", txt:"", tag:"DIV", c:"hotel", attr:{"class":"x"}}],

	styles: [{id:"hotel", style:{"position": "absolute"}}],

	form_book_elements: [
		 // parametros para FC
		 {id:"hot_r", txt:"", tag:"FORM", c:""},
		 {id:"hot_r_langue", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"langue"}},
		 {id:"hot_r_showPromotions", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"showPromotions"}},
		 {id:"hot_r_FSTBKNGTrackLink", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"FSTBKNGTrackLink"}},
		 {id:"hot_r_Clusternames", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"Clusternames"}},
		 {id:"hot_r_region", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"region"}},
		 {id:"hot_r_city", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"city"}},
		 {id:"hot_r_Hotelnames", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"Hotelnames"}},
		 {id:"hot_r_nbdays", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"nbdays"}},
		 {id:"hot_r_fromday", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"fromday"}},
		 {id:"hot_r_frommonth", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"frommonth"}},
		 {id:"hot_r_fromyear", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"fromyear"}},
		 {id:"hot_r_adulteresa", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"adulteresa"}},
		 {id:"hot_r_enfantresa", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"enfantresa"}},
		 {id:"hot_r_AccessCode", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"AccessCode"}},
		 {id:"hot_r_CurrencyLabel", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"CurrencyLabel"}},
		 // parametros para venere
		 {id:"hot_r_ref", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"ref"}},
		 {id:"hot_r_lg", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"lg"}},
		 {id:"hot_r_sd", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"sd"}},
		 {id:"hot_r_sm", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"sm"}},
		 {id:"hot_r_sy", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"sy"}},
		 {id:"hot_r_ed", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"ed"}},
		 {id:"hot_r_em", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"em"}},
		 {id:"hot_r_ey", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"ey"}},
		 {id:"hot_r_pval", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"pval"}},
		 {id:"hot_r_rval", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"rval"}},
		 {id:"hot_r_geoid", txt:"", tag:"INPUT", tp:"hidden", c:"hot_r", attr:{name:"geoid"}} ]

};



var searchFlights = {
	options: {
		form_id: "flight_form",
		tab_id: "tabs_menu_flight",
		tab_page: "flight",
		
		exclusion_country: "-1",
		
		action_books: [
			["CUB","*","http://secure.cubatravelnetwork.com/get_availability.aspx"],
			["*","CUB","http://secure.cubatravelnetwork.com/get_availability.aspx"],
			["*","*","http://secure.caribbeantravelnetwork.com/get_availability.aspx"]
			],
		
		action_book: "http://secure.caribbeantravelnetwork.com/get_availability.aspx",
		action_test: "http://site12.fast-manager.com/bookings/get_availability.aspx",
	
		release_time : 5,
		min_booking_time : 1,
		
		departure_city: "",
		arrival_city: "",
		passenger_class: '',
		
		adults: 1,
		children: 0,
		infants: 0,
		
		show_city_code: false,
		show_group: true,
		show_class: true,
		
		group_id: '',
//		airline: "",
		forbidden_routes: [["USA","*","VEN","*"]]
	},

	init: function(){
		var _o = this.options;

		$("#" + _o.id + "flight_departure_edit").css('display', (_o.show_city_code ? '':'none'));
		$("#" + _o.id + "flight_arrival_edit").css('display', (_o.show_city_code ? '':'none'));
		$("#" + _o.id + "flight_group").css('display', (_o.show_group ? '':'none'));
		$("#" + _o.id + "flight_class").css('display', (_o.show_class ? '':'none'));
		$("#" + _o.id + "flight_title").css('display', (_o.show_title ? '':'none'));
		$("#" + _o.id + "flight_currency").css('display', (_o.show_currency ? '':'none'));

		//se busca si la moneda definida está dentro del arreglo, si no se establece EUR
		this.options.currency = ($.inArray(this.options.currency, this.options.currencies) != -1) ? this.options.currency : "EUR";
		
		//se busca si el idioma definido está dentro del arreglo, si no se establece EN
		this.options.language = ($.inArray(this.options.language, this.options.languages) != -1) ? this.options.language : "en";
		
		// calendarios de reserva de vuelos
		var d = new Date();
		d.setDate(d.getDate() + _o.release_time);
		$("#" + _o.id + "flight_arrival_date_edit").val(d.getDate() + "/" + (d.getMonth() + 1) + "/" + d.getFullYear());
		d.setDate(d.getDate() + _o.min_booking_time);
		$("#" + _o.id + "flight_return_date_edit").val(d.getDate() + "/" + (d.getMonth() + 1) + "/" + d.getFullYear());
/*		$("#" + _o.id + "flight_arrival_date_edit").datepicker({minDate: _o.release_time, maxDate: '+1Y', dateFormat: 'dd/mm/yy', onSelect: 
			function(dateText, inst) {
				var t_date = $(this).datepicker( 'getDate' );
				var t_date_fin; 
				if (t_date_fin = $("#" + _o.id + "flight_return_date_edit").datepicker( 'getDate' )) {
					if (t_date.valueOf() + _o.min_booking_time * 24*60*60*1000 >=  t_date_fin.valueOf())  
						$("#" + _o.id + "flight_return_date_edit").datepicker('setDate', new Date(t_date.valueOf() + _o.min_booking_time * 24*60*60*1000 ));
				}
			}
		});
		$("#" + _o.id + "flight_arrival_date_edit").datepicker('setDate', _o.release_time + 'D');

		$("#" + _o.id + "flight_return_date_edit").datepicker({minDate: _o.release_time + _o.min_booking_time, maxDate: '+1Y', dateFormat: 'dd/mm/yy', onSelect: 
			function(dateText, inst) {
				var t_date = $(this).datepicker( 'getDate' );
				var t_date_ini; 
				if (t_date_ini = $("#" + _o.id + "flight_arrival_date_edit").datepicker( 'getDate' )) {
					if (t_date.valueOf() - _o.min_booking_time * 24*60*60*1000 <=  t_date_ini.valueOf())  
						$("#" + _o.id + "flight_arrival_date_edit").datepicker('setDate', new Date(t_date.valueOf() - _o.min_booking_time * 24*60*60*1000 ));
				}
			}
		});
		$("#" + _o.id + "flight_return_date_edit").datepicker('setDate', (_o.release_time + _o.min_booking_time) + 'D');
*/			
		ctn_populateSelect(_o.id + "flight_departure_select", _o.loading, '', '', '');
		ctn_populateSelect(_o.id + "flight_arrival_select", _o.loading, '', '', '');
		ctn_populateSelect(_o.id + "flight_class_select", _o.loading, '', '', '');

		var ct = _o.commercial_client_type.split(',');	
		for (var i = 0; i < ct.length; i++) ct[i] = [ct[i], ct[i], ['']];
	
		ctn_populateSelect(_o.id + 'flight_character_select', ct, '', '', '');
		
		$("#" + _o.id + "flight_character").css('display', (ct.length <= 1) ? 'none': '');
		$("#" + _o.id + "flight_character_select").change(function(){
			$("#" + _o.id + "flight_a_code").css('display', (($("#" + _o.id + "flight_character_select").val().toUpperCase() == "TRAVELAGENCY") || ($("#" + _o.id + "flight_character_select").val().toUpperCase() == "TUROPERATOR")) ? '' : 'none')
		});
		$("#" + _o.id + "flight_character_select").change();

		$.getJSON(_o.site_from + "/comun/scripts/sb_response_json.asp?q=flight_cities_exclude_region,flight_cities_include_region,flight_classes,currencies&language_id=" + _o.language + "&city_region=" + _o.region + "&exclusion_country=" + _o.exclusion_country + "&city_no_region=" + _o.region + "&jsoncallback=?", function(data, textStatus){
 
			_o.external_cities = data.flight_cities_exclude_region;
			_o.regional_cities = data.flight_cities_include_region;

			if ((_o.group_id == '') && (_o.departure_city != '')) {// Asignandole un tipo de ruta para ciudades de salida definidas
				_o.group_id = (ctn_seekArray(_o.external_cities, _o.departure_city) ? 'International': '');
				_o.group_id = (ctn_seekArray(_o.regional_cities, _o.departure_city) ? 'Regional': '');
			}

			$("#" + _o.id + "flight_group_inter_radio").click(function(){
				ctn_populateSelect(_o.id + "flight_departure_select", _o.external_cities, '', '', _o.departure_city);
				$("#" + _o.id + "flight_group_region_radio").attr({checked:false});
				$(this).attr({checked:true});
			});
			if ((_o.group_id == 'International') || (_o.group_id == '')) $("#" + _o.id + "flight_group_inter_radio").click();

			ctn_populateSelect(_o.id + "flight_arrival_select", _o.regional_cities, '', '', _o.arrival_city, _o.id);
			$("#" + _o.id + "flight_group_region_radio").click(function(){
				ctn_populateSelect(_o.id + "flight_departure_select", _o.regional_cities, '', '', _o.departure_city);
				$("#" + _o.id + "flight_group_inter_radio").attr({checked:false});
				$(this).attr({checked:true});
				$("#" + _o.id + "flight_departure_select").change();
			});
			if (_o.group_id == 'Regional') $("#" + _o.id + "flight_group_region_radio").click();

			$("#" + _o.id + "flight_currency_select").change(function(){
				if ($("#" + _o.id + "flight_currency_select option:selected").attr("disabled")) {
					$("#" + _o.id + "flight_currency_select option:enabled:first").attr("selected","selected");
				}
			});

			$("#" + _o.id + "flight_arrival_select").change(function(){
				$("#" + _o.id + "flight_currency_select option").removeAttr("disabled").css({"color":""});
				$("#" + _o.id + "flight_arrival_select option#" + _o.id + $("#" + _o.id + "flight_departure_select option:selected").val()).attr("disabled","disabled").css({"color":"#CCC"});
				if ($("#" + _o.id + "flight_arrival_select option:selected").attr("disabled")) {
					$("#" + _o.id + "flight_arrival_select option:enabled:first").attr("selected","selected");
				}
				var sel_departure = ctn_seekArray(_o.external_cities, $("#" + _o.id + "flight_departure_select").val());
				if (!sel_departure) sel_departure = ctn_seekArray(_o.regional_cities, $("#" + _o.id + "flight_departure_select").val());
				var sel_arrival = ctn_seekArray(_o.regional_cities, $("#" + _o.id + "flight_arrival_select").val());
				if (($.isArray(sel_departure)) || ($.isArray(sel_arrival))){ 
					for (var i = 0; i < _o.forbidden_currencies.length; i++) {
						if((_o.forbidden_currencies[i][0] == sel_departure[6]) || (_o.forbidden_currencies[i][0] == sel_arrival[6]) || (_o.forbidden_currencies[i][0] == "*")){
							$("#" + _o.id + "flight_currency_select option#" + _o.id + "flight_" + _o.forbidden_currencies[i][1]).attr("disabled","disabled").css({"color":"#CCC"}); break;
						}
					}
				}
				$("#" + _o.id + "flight_currency_select").change();
			});

			$("#" + _o.id + "flight_departure_select").change(function(){
				$("#" + _o.id + "flight_arrival_select option").removeAttr("disabled").css({"color":""});
				$("#" + _o.id + "flight_currency_select option").removeAttr("disabled").css({"color":""});
				var sel_departure = ctn_seekArray(_o.external_cities, $("#" + _o.id + "flight_departure_select").val());
				if (!sel_departure) sel_departure = ctn_seekArray(_o.regional_cities, $("#" + _o.id + "flight_departure_select").val());
				if ($.isArray(sel_departure)){ 
					for (var i = 0; i < _o.forbidden_routes.length; i++) {
						if(((_o.forbidden_routes[i][0] == sel_departure[6]) || (_o.forbidden_routes[i][0] == "*")) && 
							((_o.forbidden_routes[i][1] == sel_departure[0]) || (_o.forbidden_routes[i][1] == "*")) ){
							for (var j = 0; j < _o.regional_cities.length; j++) {
								if(((_o.forbidden_routes[i][2] == _o.regional_cities[j][6]) || (_o.forbidden_routes[i][0] == "*")) && 
									((_o.forbidden_routes[i][3] == _o.regional_cities[j][0]) || (_o.forbidden_routes[i][1] == "*")) ){
										$("#" + _o.id + "flight_arrival_select option#" + _o.id + _o.regional_cities[j][0]).attr("disabled","disabled").css({"color":"#CCC"});
								}									
							}
						}
					}
					var sel_arrival = ctn_seekArray(_o.regional_cities, $("#" + _o.id + "flight_arrival_select").val());
					if ($.isArray(sel_arrival)){ 
						for (var i = 0; i < _o.forbidden_currencies.length; i++) {
							if((_o.forbidden_currencies[i][0] == sel_departure[6]) || (_o.forbidden_currencies[i][0] == sel_arrival[6]) || (_o.forbidden_currencies[i][0] == "*")){
								$("#" + _o.id + "flight_currency_select option#" + _o.id + "flight_" + _o.forbidden_currencies[i][1]).attr("disabled","disabled").css({"color":"#CCC"}); break;
							}
						}
					}
					$("#" + _o.id + "flight_currency_select").change();
				}
				$("#" + _o.id + "flight_arrival_select").change();
			});
			$("#" + _o.id + "flight_departure_select").change();

			ctn_populateSelect(_o.id + "flight_class_select", data.flight_classes, '', '', _o.passenger_class);
			ctn_populateSelect(_o.id + "flight_currency_select", data.currencies, '', '', _o.currency, _o.id + "flight_");

		});
	
/// Ocultando fecha de regreso para viajes de solo ida y mostrandola para isa y vuelta
		$("#" + _o.id + "flight_flight_t_rt_radio").click(function(){
			$("#" + _o.id + "flight_return_date").show();
			$("#" + _o.id + "flight_flight_t_ow_radio").attr({checked:false});
			$(this).attr({checked:true});
		});

		$("#" + _o.id + "flight_flight_t_ow_radio").click(function(){
			$("#" + _o.id + "flight_return_date").hide();
			$("#" + _o.id + "flight_flight_t_rt_radio").attr({checked:false});
			$(this).attr({checked:true});
		});
		
		$("#" + _o.id + "flight_flight_t_rt_radio").click();

		ctn_populateSelect(_o.id + "flight_adults_select", [[1,1,['']],[2,2,['']],[3,3,['']],[4,4,['']],[5,5,['']],[6,6,['']]], '', '', _o.adults);
		ctn_populateSelect(_o.id + "flight_children_select", [[0,0,['']],[1,1,['']],[2,2,['']],[3,3,['']]], '', '', _o.children);
		ctn_populateSelect(_o.id + "flight_infants_select", [[0,0,['']],[1,1,['']],[2,2,['']],[3,3,['']]], '', '', _o.infants);

		$("#" + _o.id + "flight_search_boton").click(function(){
			_o.ready = true;

			if((_o.ready) && (!ctn_valid_date($("#" + _o.id + "flight_arrival_date_edit").val()))){
				alert('The flight departure date is incorrect. Please, type a date according to our settings (dd/mm/yyyy)');
				$("#" + _o.id + "flight_arrival_date_edit").focus();
				_o.ready = false;
			}	

			if((_o.ready) && (!ctn_valid_date($("#" + _o.id + "flight_return_date_edit").val())) && ($("#" + _o.id + "flight_f_type input:checked").val() == "R")){
				alert('The flight return date is incorrect. Please, type a date according to our settings (dd/mm/yyyy)');
				$("#" + _o.id + "flight_return_date_edit").focus();
				_o.ready = false;
			}	
			
			var d = new Date();
			s_today = d.getDate() + "/" + (d.getMonth() + 1) + "/" + d.getFullYear();
			var date_now = ctn_parse_date(s_today);
			var d_1 = ctn_parse_date($("#" + _o.id + "flight_arrival_date_edit").val());
			var d_2 = ctn_parse_date($("#" + _o.id + "flight_return_date_edit").val());

			if((_o.ready) && ((d_1 - date_now) < _o.release_time * 24 * 60 * 60 * 1000)){
				alert('Oh, sorry! We can not reserve a departure flight earlier than ' + _o.release_time + ' days. Please fix dates interval');
				$("#" + _o.id + "flight_departure_date_edit").focus();
				_o.ready = false;
			}	

			if((_o.ready) && ((d_2 - d_1) < 0) && ($("#" + _o.id + "flight_f_type input:checked").val() == "R")){
				alert('The return flight date can not be before than the departure flight. Please fix dates interval');
				$("#" + _o.id + "flight_return_date_edit").focus();
				_o.ready = false;
			}	

			if((_o.ready) && ((d_2 - d_1) < _o.min_booking_time * 24 * 60 * 60 * 1000) && ($("#" + _o.id + "flight_f_type input:checked").val() == "R")){
				alert('Oh, sorry! We can not reserve a return flight before ' + _o.min_booking_time + ' days from the departure flight date. Please fix dates interval');
				$("#" + _o.id + "flight_return_date_edit").focus();
				_o.ready = false;
			}	

			var need_typed_a_code = (($("#" + _o.id + "flight_character_select").val().toUpperCase() == "TRAVELAGENCY") || ($("#" + _o.id + "flight_character_select").val().toUpperCase() == "TUROPERATOR"));
			if((_o.ready) && ($("#" + _o.id + "flight_a_code_edit").val() == "") && (need_typed_a_code)){
				alert(_o.flight_msg_a_code);
				$("#" + _o.id + "flight_a_code_edit").focus();
				_o.ready = false;
			}	

			if (_o.ready){
				var sel_departure = ctn_seekArray(_o.external_cities, $("#" + _o.id + "flight_departure_select").val());
				if (!sel_departure) sel_departure = ctn_seekArray(_o.regional_cities, $("#" + _o.id + "flight_departure_select").val());
				var sel_arrival = ctn_seekArray(_o.regional_cities, $("#" + _o.id + "flight_arrival_select").val());
				
				if (($.isArray(sel_departure)) && ($.isArray(sel_arrival))){ 
					for (var i = 0; i < _o.action_books.length; i++) {// action en dependencia del pais ruta
						if(((_o.action_books[i][0] == sel_departure[6]) || (_o.action_books[i][0] == "*")) && 
							((_o.action_books[i][1] == sel_arrival[6]) || (_o.action_books[i][1] == "*")) ){
							_o.action_book = _o.action_books[i][2]; break;
						}
					}
					if (typeof _o.points_of_sale != "undefined"){// punto de venta en dependencia del pais ruta
						for (var i = 0; i < _o.points_of_sale.length; i++) {
							if(((_o.points_of_sale[i][0] == sel_departure[6]) || (_o.points_of_sale[i][0] == "*")) && 
								((_o.points_of_sale[i][1] == sel_arrival[6]) || (_o.points_of_sale[i][1] == "*")) ){
								_o.point_of_sale = _o.points_of_sale[i][2]; break;
							}
						}
					}
				}


				$("#" + _o.id + "flg_r input").val ("");

				$("#" + _o.id + "flg_r_point_of_sale").val (_o.point_of_sale);
				$("#" + _o.id + "flg_r_commercial_client_type").val ($("#" + _o.id + "flight_character_select").val());
				if (need_typed_a_code) 
					$("#" + _o.id + "flg_r_commercial_client_code").val ($("#" + _o.id + "flight_a_code_edit").val ());
				else  
					$("#" + _o.id + "flg_r_commercial_client_code").val (($("#" + _o.id + "flight_character_select").val ().toUpperCase() == "CTN") ? 'ctn': _o.commercial_client_code);
				$("#" + _o.id + "flg_r_reseller_id").val (_o.reseller_id);
				$("#" + _o.id + "flg_r_refSite").val (window.location.href);
				$("#" + _o.id + "flg_r_ctn_site_name").val (_o.site_name);
				$("#" + _o.id + "flg_r_language").val (_o.language);
				$("#" + _o.id + "flg_r_FlightType").val ($("#" + _o.id + "flight_group input:checked").val());
				$("#" + _o.id + "flg_r_OR").val ($("#" + _o.id + "flight_f_type input:checked").val());
				$("#" + _o.id + "flg_r_Class").val ($("#" + _o.id + "flight_class_select").val());
				$("#" + _o.id + "flg_r_CurrCode").val ($("#" + _o.id + "flight_currency_select").val());
				$("#" + _o.id + "flg_r_DeptAirPort").val ($("#" + _o.id + "flight_departure_edit").val() != '' ? $("#" + _o.id + "flight_departure_edit").val() : $("#" + _o.id + "flight_departure_select").val());
				var departure_date = $("#" + _o.id + "flight_arrival_date_edit").val().split('/');
				$("#" + _o.id + "flg_r_departureDate").val (departure_date[0]);
				$("#" + _o.id + "flg_r_departureMonth").val (departure_date[1]);
				$("#" + _o.id + "flg_r_departureYear").val (departure_date[2]);
				$("#" + _o.id + "flg_r_DestAirPort").val ($("#" + _o.id + "flight_arrival_edit").val() != '' ? $("#" + _o.id + "flight_arrival_edit").val() : $("#" + _o.id + "flight_arrival_select").val());
				if ($("#" + _o.id + "flg_r_OR").val() == "R") {
					var return_date = $("#" + _o.id + "flight_return_date_edit").val().split('/');
					$("#" + _o.id + "flg_r_returnDate").val (return_date[0]);
					$("#" + _o.id + "flg_r_returnMonth").val (return_date[1]);
					$("#" + _o.id + "flg_r_returnYear").val (return_date[2]);
				}
				$("#" + _o.id + "flg_r_Adults").val ($("#" + _o.id + "flight_adults_select").val());
				$("#" + _o.id + "flg_r_Children").val ($("#" + _o.id + "flight_children_select").val());
				$("#" + _o.id + "flg_r_Infants").val ($("#" + _o.id + "flight_infants_select").val());

				$("#" + _o.id + "flg_r").attr({action: (_o.box_mode == "book-ol" ? _o.action_book: _o.action_test ), method: _o.method, target: _o.target});

				var submit_form_book = true;
				if (_o.box_mode == "test") submit_form_book = (ctn_test_form(_o.id + "flg_r"));
				if (submit_form_book) $("#" + _o.id + "flg_r").submit();
			}
		});
		
	},
	set_elements_txt: function (l){
		var elements_txt = [
			 {id:"flight_title", txt:l.flight_title},
			 {id:"flight_group_inter_label", txt:l.flight_group_inter_label},
			 {id:"flight_group_region_label", txt:l.flight_group_region_label},
			 {id:"flight_departure_label", txt:l.flight_departure_label},
			 {id:"flight_arrival_label", txt:l.flight_arrival_label},
			 {id:"flight_flight_t_label", txt:l.flight_flight_t_label},
			 {id:"flight_flight_t_rt_label", txt:l.flight_flight_t_rt_label},
			 {id:"flight_flight_t_ow_label", txt:l.flight_flight_t_ow_label},
			 {id:"flight_arrival_date_label", txt:l.flight_arrival_date_label},
			 {id:"flight_arrival_date_span", txt:l.flight_arrival_date_span},
			 {id:"flight_return_date_label", txt:l.flight_return_date_label},
			 {id:"flight_return_date_span", txt:l.flight_return_date_span},
			 {id:"flight_class_label", txt:l.flight_class_label},
			 {id:"flight_adults_label", txt:l.flight_adults_label},
			 {id:"flight_children_label", txt:l.flight_children_label},
			 {id:"flight_infants_label", txt:l.flight_infants_label},
			 {id:"flight_currency_label", txt:l.flight_currency_label},
			 {id:"flight_character_label", txt:l.flight_character_label},
			 {id:"flight_a_code_label", txt:l.flight_a_code_label}];

		for (var i = 0; i < elements_txt.length; i++) {
			$("#" + this.options.id + elements_txt[i].id).text(elements_txt[i].txt)
		}
		
		$("#" + this.options.id + "flight_search_boton").val(l.flight_button);
		
		this.options.flight_msg_a_code = l.flight_msg_a_code;
		this.options.loading[0][1] = l.flight_loading;
	},
	//	elements del buscador de vuelos
	elements: [
		 {id:"flight_form", txt:"", tag:"FORM", c:""},
		 {id:"flight", txt:"", tag:"DIV", c:"flight_form", attr:{"class":"d"}},
		 {id:"flight_title", txt:"Book Cbb Flight", tag:"H3", c:"flight", attr:{"class":"t"}},
		//	elements del buscador de vuelos: radio selector de grupo de vuelos
		 {id:"flight_group", txt:"", tag:"DIV", c:"flight", attr:{"class":"c"}},
		 {id:"flight_group_inter", txt:"", tag:"DIV", c:"flight_group"},
		 {id:"flight_group_inter_label", txt:"Flights to the Caribbean", tag:"LABEL", c:"flight_group_inter"},
		 {id:"flight_group_inter_radio", txt:"", tag:"INPUT", tp:"radio",  c:"flight_group_inter", attr:{name:"sfb_rg_product_type", value:"International", "class":"radio"}},
		 {id:"flight_group_region", txt:"", tag:"DIV", c:"flight_group"},
		 {id:"flight_group_region_label", txt:"Regional Caribbean Flights ", tag:"LABEL", c:"flight_group_region"},
		 {id:"flight_group_region_radio", txt:"", tag:"INPUT", tp:"radio",  c:"flight_group_region", attr:{name:"sfb_rg_product_type", value:"Regional", "class":"radio"}},
		//	elements del buscador de vuelos: selector de lugar de partida
		 {id:"flight_departure", txt:"", tag:"DIV", c:"flight", attr:{"class":"c"}},
		 {id:"flight_departure_label", txt:"Leaving from:", tag:"LABEL", c:"flight_departure"},
		 {id:"flight_departure_select", txt:"", tag:"SELECT", c:"flight_departure"},
		 {id:"flight_departure_edit", txt:"", tag:"INPUT", c:"flight_departure", attr:{maxlength:"3", size:"3"}},
		//	elements del buscador de vuelos: selector de lugar de destino
		 {id:"flight_arrival", txt:"", tag:"DIV", c:"flight", attr:{"class":"c"}},
		 {id:"flight_arrival_label", txt:"Going to:", tag:"LABEL", c:"flight_arrival"},
		 {id:"flight_arrival_select", txt:"", tag:"SELECT", c:"flight_arrival"},
		 {id:"flight_arrival_edit", txt:"", tag:"INPUT", c:"flight_arrival", attr:{maxlength:"3", size:"3"}},
		//	elements del buscador de vuelos: radio selector de grupo de vuelos
		 {id:"flight_f_type", txt:"", tag:"DIV", c:"flight", attr:{"class":"c"}},
		 {id:"flight_flight_t_rt", txt:"", tag:"DIV", c:"flight_f_type"},
		 {id:"flight_flight_t_label", txt:"Flight Type:", tag:"LABEL", c:"flight_flight_t_rt"},
		 {id:"flight_flight_t_rt_label", txt:"Round Trip", tag:"LABEL", c:"flight_flight_t_rt"},
		 {id:"flight_flight_t_rt_radio", txt:"", tag:"INPUT", tp:"radio",  c:"flight_flight_t_rt", attr:{name:"sfb_rg_flight_type", value:"R", "class":"radio"}},
		 {id:"flight_flight_t_ow", txt:"", tag:"DIV", c:"flight_f_type"},
		 {id:"flight_flight_t_ow_label", txt:"One Way ", tag:"LABEL", c:"flight_flight_t_ow"},
		 {id:"flight_flight_t_ow_radio", txt:"", tag:"INPUT", tp:"radio",  c:"flight_flight_t_ow", attr:{name:"sfb_rg_flight_type", value:"O", "class":"radio"}},
		//	elements del buscador de vuelos: fecha de salida
		 {id:"flight_arrival_date", txt:"", tag:"DIV", c:"flight", attr:{"class":"c"}},
		 {id:"flight_arrival_date_label", txt:"Arrival date:", tag:"LABEL", c:"flight_arrival_date"},
		 {id:"flight_arrival_date_edit", txt:"", tag:"INPUT", c:"flight_arrival_date", attr:{/* readonly:"true", */ "class":"date"}},
		 {id:"flight_arrival_date_span", txt:"(dd/mm/yyyy)", tag:"SPAN", c:"flight_arrival_date"},
		//	elements del buscador de vuelos: fecha de regreso
		 {id:"flight_return_date", txt:"", tag:"DIV", c:"flight", attr:{"class":"c"}},
		 {id:"flight_return_date_label", txt:"Return date:", tag:"LABEL", c:"flight_return_date"},
		 {id:"flight_return_date_edit", txt:"", tag:"INPUT", c:"flight_return_date", attr:{/* readonly:"true", */ "class":"date"}},
		 {id:"flight_return_date_span", txt:"(dd/mm/yyyy)", tag:"SPAN", c:"flight_return_date"},
		//	elements del buscador de hoteles: clase de vuelos
		 {id:"flight_class", txt:"", tag:"DIV", c:"flight", attr:{"class":"c"}},
		 {id:"flight_class_label", txt:"Class:", tag:"LABEL", c:"flight_class"},
		 {id:"flight_class_select", txt:"", tag:"SELECT", c:"flight_class"},
		//	elements del buscador de vuelos: cantidad de mayores 
		 {id:"flight_adults", txt:"", tag:"DIV", c:"flight", attr:{"class":"c"}},
		 {id:"flight_adults_label", txt:"Adults:", tag:"LABEL", c:"flight_adults"},
		 {id:"flight_adults_select", txt:"", tag:"SELECT", c:"flight_adults"},
		//	elements del buscador de vuelos: cantidad de niños 
		 {id:"flight_children", txt:"", tag:"DIV", c:"flight", attr:{"class":"c"}},
		 {id:"flight_children_label", txt:"Children:", tag:"LABEL", c:"flight_children"},
		 {id:"flight_children_select", txt:"", tag:"SELECT", c:"flight_children"},
		//	elements del buscador de vuelos: cantidad de infantes 
		 {id:"flight_infants", txt:"", tag:"DIV", c:"flight", attr:{"class":"c"}},
		 {id:"flight_infants_label", txt:"Infants:", tag:"LABEL", c:"flight_infants"},
		 {id:"flight_infants_select", txt:"", tag:"SELECT", c:"flight_infants"},
		//	elements  buscador de vuelos: moneda
		 {id:"flight_currency", txt:"", tag:"DIV", c:"flight", attr:{"class":"c"}},
		 {id:"flight_currency_label", txt:"Currency:", tag:"LABEL", c:"flight_currency"},
		 {id:"flight_currency_select", txt:"", tag:"SELECT", c:"flight_currency"},
		//	elements  buscador de vuelos: caracter de la reserva
		 {id:"flight_character", txt:"", tag:"DIV", c:"flight", attr:{"class":"c"}},
		 {id:"flight_character_label", txt:"Commercial Client Type:", tag:"LABEL", c:"flight_character"},
		 {id:"flight_character_select", txt:"", tag:"SELECT", c:"flight_character"},
		//	elements del buscador de vuelos: codigo de acceso
		 {id:"flight_a_code", txt:"", tag:"DIV", c:"flight", attr:{"class":"c"}},
		 {id:"flight_a_code_label", txt:"Access code:", tag:"LABEL", c:"flight_a_code"},
		 {id:"flight_a_code_edit", txt:"", tag:"INPUT", c:"flight_a_code", attr:{}},
		//	elements del buscador de carros: boton
		 {id:"flight_search", txt:"", tag:"DIV", c:"flight", attr:{"class":"btn"}},
		 {id:"flight_search_boton", txt:"", tag:"INPUT", tp:"button", c:"flight_search", attr:{value:"Search Flights", "class":"btn"}},
	 	 {id:"flight_close", txt:"", tag:"DIV", c:"flight", attr:{"class":"x"}}],

	styles: [{id:"flight", style:{"position": "absolute"}},{id:"flight_arrival_date_edit", style: {}}],

	form_book_elements: [
		 {id:"flg_r", txt:"", tag:"FORM", c:""},
		 {id:"flg_r_commercial_client_code", txt:"", tag:"INPUT", tp:"hidden", c:"flg_r", attr:{name:"commercial_client_code"}},
		 {id:"flg_r_point_of_sale", txt:"", tag:"INPUT", tp:"hidden", c:"flg_r", attr:{name:"point_of_sale"}},
		 {id:"flg_r_commercial_client_type", txt:"", tag:"INPUT", tp:"hidden", c:"flg_r", attr:{name:"commercial_client_type"}},
		 {id:"flg_r_reseller_id", txt:"", tag:"INPUT", tp:"hidden", c:"flg_r", attr:{name:"reseller_id"}},
		 {id:"flg_r_refSite", txt:"", tag:"INPUT", tp:"hidden", c:"flg_r", attr:{name:"refSite"}},
		 {id:"flg_r_ctn_site_name", txt:"", tag:"INPUT", tp:"hidden", c:"flg_r", attr:{name:"ctn_site_name"}},
		 {id:"flg_r_language", txt:"", tag:"INPUT", tp:"hidden", c:"flg_r", attr:{name:"language"}},
		 {id:"flg_r_DeptAirPort", txt:"", tag:"INPUT", tp:"hidden", c:"flg_r", attr:{name:"DeptAirPort"}},
		 {id:"flg_r_Class", txt:"", tag:"INPUT", tp:"hidden", c:"flg_r", attr:{name:"Class"}},
		 {id:"flg_r_OR", txt:"", tag:"INPUT", tp:"hidden", c:"flg_r", attr:{name:"OR"}},
		 {id:"flg_r_departureDate", txt:"", tag:"INPUT", tp:"hidden", c:"flg_r", attr:{name:"departureDate"}},
		 {id:"flg_r_departureMonth", txt:"", tag:"INPUT", tp:"hidden", c:"flg_r", attr:{name:"departureMonth"}},
		 {id:"flg_r_departureYear", txt:"", tag:"INPUT", tp:"hidden", c:"flg_r", attr:{name:"departureYear"}},
		 {id:"flg_r_DestAirPort", txt:"", tag:"INPUT", tp:"hidden", c:"flg_r", attr:{name:"DestAirPort"}},
		 {id:"flg_r_returnDate", txt:"", tag:"INPUT", tp:"hidden", c:"flg_r", attr:{name:"returnDate"}},
		 {id:"flg_r_returnMonth", txt:"", tag:"INPUT", tp:"hidden", c:"flg_r", attr:{name:"returnMonth"}},
		 {id:"flg_r_returnYear", txt:"", tag:"INPUT", tp:"hidden", c:"flg_r", attr:{name:"returnYear"}},
		 {id:"flg_r_Adults", txt:"", tag:"INPUT", tp:"hidden", c:"flg_r", attr:{name:"Adults"}},
		 {id:"flg_r_Children", txt:"", tag:"INPUT", tp:"hidden", c:"flg_r", attr:{name:"Children"}},
		 {id:"flg_r_Infants", txt:"", tag:"INPUT", tp:"hidden", c:"flg_r", attr:{name:"Infants"}},
		 {id:"flg_r_ClientCountryCode", txt:"", tag:"INPUT", tp:"hidden", c:"flg_r", attr:{name:"ClientCountryCode", value:"GR"}},
		 {id:"flg_r_FlightType", txt:"", tag:"INPUT", tp:"hidden", c:"flg_r", attr:{name:"FlightType"}},
		 {id:"flg_r_CurrCode", txt:"", tag:"INPUT", tp:"hidden", c:"flg_r", attr:{name:"CurrCode"}}]
};


var searchCars = {
	options: {
		form_id: "car_form",
		tab_id: "tabs_menu_car",
		tab_page: "car",
		action_book: "http://secure.cubatravelnetwork.com/cars/selcar.aspx",
		action_test: "http://site12.fast-manager.com/bookings/cars/selcar.aspx",
	
		release_time : 4,
		min_booking_time : 3,
	
		pickup_destination : "",
		return_destination : "",
		pickup_time : "09:00",
		return_time : "09:00",
		
		car_code : "",
		car_category_code : "",
		company_code : "",
	
		show_countries: false,
		show_company: false,
		show_car_category: false,
		
		country: "CUB"
	},

	init: function(){
		var _o = this.options;

		$("#" + _o.id + "car_country").css('display', (_o.show_countries ? '':'none'));
		$("#" + _o.id + "car_company").css('display', (_o.show_company ? '':'none'));
		$("#" + _o.id + "car_category").css('display',(_o.show_car_category ? '':'none'));
		$("#" + _o.id + "car_title").css('display', (_o.show_title ? '':'none'));
		$("#" + _o.id + "car_currency").css('display', (_o.show_currency ? '':'none'));

		//se busca si la moneda definida está dentro del arreglo, si no se establece EUR
		this.options.currency = ($.inArray(this.options.currency, this.options.currencies) != -1) ? this.options.currency : "EUR";
		
		//se busca si el idioma definido está dentro del arreglo, si no se establece EN
		this.options.language = ($.inArray(this.options.language, this.options.languages) != -1) ? this.options.language : "en";
		
		// calendarios de reserva de carros
		var d = new Date();
		d.setDate(d.getDate() + _o.release_time);
		$("#" + _o.id + "car_pickup_date_edit").val(d.getDate() + "/" + (d.getMonth() + 1) + "/" + d.getFullYear());
		d.setDate(d.getDate() + _o.min_booking_time);
		$("#" + _o.id + "car_return_date_edit").val(d.getDate() + "/" + (d.getMonth() + 1) + "/" + d.getFullYear());
/*		$("#" + _o.id + "car_pickup_date_edit").datepicker({minDate: _o.release_time, maxDate: '+1Y', dateFormat: 'dd/mm/yy', onSelect: 
			function(dateText, inst) {
				var t_date = $(this).datepicker( 'getDate' );
				var t_date_fin; 
				if (t_date_fin = $("#" + _o.id + "car_return_date_edit").datepicker( 'getDate' )) {
					if (t_date.valueOf() + _o.min_booking_time * 24*60*60*1000 >=  t_date_fin.valueOf())  
						$("#" + _o.id + "car_return_date_edit").datepicker('setDate', new Date(t_date.valueOf() + _o.min_booking_time * 24*60*60*1000 ));
				}
			}
		});
		$("#" + _o.id + "car_pickup_date_edit").datepicker('setDate', _o.release_time + 'D');

		$("#" + _o.id + "car_return_date_edit").datepicker({minDate: _o.release_time + _o.min_booking_time, maxDate: '+1Y', dateFormat: 'dd/mm/yy', onSelect: 
			function(dateText, inst) {
				var t_date = $(this).datepicker( 'getDate' );
				var t_date_ini; 
				if (t_date_ini = $("#" + _o.id + "car_pickup_date_edit").datepicker( 'getDate' )) {
					if (t_date.valueOf() - _o.min_booking_time * 24*60*60*1000 <=  t_date_ini.valueOf())  
						$("#" + _o.id + "car_pickup_date_edit").datepicker('setDate', new Date(t_date.valueOf() - _o.min_booking_time * 24*60*60*1000 ));
				}
			}
		});
		$("#" + _o.id + "car_return_date_edit").datepicker('setDate', (_o.release_time + _o.min_booking_time) + 'D');
*/

		ctn_populateSelect(_o.id + "car_country_select", [['CUB','Cuba',['Caribe'],'']], '', '', '');
		ctn_populateSelect(_o.id + "car_pickup_place_select", _o.loading, '', '', '');
		ctn_populateSelect(_o.id + "car_return_place_select", _o.loading, '', '', '');
		ctn_populateSelect(_o.id + "car_company_select", _o.loading, '', '', '');
		ctn_populateSelect(_o.id + "car_category_select", _o.loading, '', '', '');
		ctn_populateSelect(_o.id + "car_currency_select", _o.loading, '', '', '');

		$.getJSON(_o.site_from + "/comun/scripts/sb_response_json.asp?q=car_destinations,car_rental_companies,car_categories,currencies&language_id=" + _o.language + "&country=" + _o.country + "&jsoncallback=?", function(data, textStatus){
			ctn_populateSelect(_o.id + "car_pickup_place_select", data.car_destinations, '', '', _o.pickup_destination);
			ctn_populateSelect(_o.id + "car_return_place_select", data.car_destinations, '', '', _o.return_destination);

			ctn_populateSelect(_o.id + "car_company_select", data.car_rental_companies, '', '', _o.company_code);

			ctn_populateSelect(_o.id + "car_category_select", data.car_categories, '', '', _o.car_category_code);

			ctn_populateSelect(_o.id + "car_currency_select", data.currencies, '', '', _o.currency);
		});

		var chr = 24; var hr = [];
		for (var i = 0 ; i < chr; i++) {
			if (i < 10) si = ['0',i].join(''); else si = i;
			hr[i*2] = [[si,'00'].join(':'), [si,'00'].join(':'), ['']];
			hr[i*2+1] = [[si,'30'].join(':'), [si,'30'].join(':'), ['']];
		}

		ctn_populateSelect(_o.id + 'car_pickup_time_select', hr, '', '', _o.pickup_time);
		ctn_populateSelect(_o.id + 'car_return_time_select', hr, '', '', _o.return_time);

		var ct = _o.commercial_client_type.split(',');	
		for (var i = 0; i < ct.length; i++) ct[i] = [ct[i], ct[i], ['']];
	
		ctn_populateSelect(_o.id + 'car_character_select', ct, '', '', '');
		
		$("#" + _o.id + "car_character").css('display', (ct.length <= 1) ? 'none': '');
		$("#" + _o.id + "car_character_select").change(function(){
			$("#" + _o.id + "car_a_code").css('display', (($("#" + _o.id + "car_character_select").val().toUpperCase() == "TRAVELAGENCY") || ($("#" + _o.id + "car_character_select").val().toUpperCase() == "TUROPERATOR")) ? '' : 'none')
		});
		$("#" + _o.id + "car_character_select").change();

		$("#" + _o.id + "car_search_boton").click(function(){
			_o.ready = true;

			if((_o.ready) && (!ctn_valid_date($("#" + _o.id + "car_pickup_date_edit").val()))){
				alert('The car pickup date is incorrect. Please, type a date according to our settings (dd/mm/yyyy)');
				$("#" + _o.id + "car_pickup_date_edit").focus();
				_o.ready = false;
			}	

			if((_o.ready) && (!ctn_valid_date($("#" + _o.id + "car_return_date_edit").val()))){
				alert('The car return date is incorrect. Please, type a date according to our settings (dd/mm/yyyy)');
				$("#" + _o.id + "car_return_date_edit").focus();
				_o.ready = false;
			}	
			
			var d = new Date();
			s_today = d.getDate() + "/" + (d.getMonth() + 1) + "/" + d.getFullYear();
			var date_now = ctn_parse_date(s_today);
			var d_1 = ctn_parse_date($("#" + _o.id + "car_pickup_date_edit").val());
			var d_2 = ctn_parse_date($("#" + _o.id + "car_return_date_edit").val());

			if((_o.ready) && ((d_1 - date_now) < (_o.release_time * 24 * 60 * 60 * 1000))){
				alert('Oh, sorry! We can not reserve a pickup car earlier than ' + _o.release_time + ' days. Please fix dates interval');
				$("#" + _o.id + "car_pickup_date_edit").focus();
				_o.ready = false;
			}	

			if((_o.ready) && ((d_2 - d_1) < 0)){
				alert('The return car date can not be before than the pickup car. Please fix dates interval');
				$("#" + _o.id + "car_return_date_edit").focus();
				_o.ready = false;
			}	

			if((_o.ready) && ((d_2 - d_1) < (_o.min_booking_time * 24 * 60 * 60 * 1000))){
				alert('Oh, sorry! We can not reserve a car for less than ' + _o.min_booking_time + ' days. Please fix dates interval');
				$("#" + _o.id + "car_return_date_edit").focus();
				_o.ready = false;
			}	

			if((_o.ready) && (isNaN($("#" + _o.id + "car_driver_age_edit").val()) || ($("#" + _o.id + "car_driver_age_edit").val() < 21)))	{
				alert(_o.car_msg_age);
				$("#" + _o.id + "car_driver_age_edit").focus();
				_o.ready = false;
			}	
			var need_typed_a_code = (($("#" + _o.id + "car_character_select").val().toUpperCase() == "TRAVELAGENCY") || ($("#" + _o.id + "car_character_select").val().toUpperCase() == "TUROPERATOR"));
			if((_o.ready) && ($("#" + _o.id + "car_a_code_edit").val() == "") && (need_typed_a_code)){
				alert(_o.car_msg_a_code);
				$("#" + _o.id + "car_a_code_edit").focus();
				_o.ready = false;
			}	

			if (_o.ready){
				$("#" + _o.id + "car_r input").val ("");

				$("#" + _o.id + "car_r_point_of_sale").val (_o.point_of_sale);
				$("#" + _o.id + "car_r_commercial_client_type").val ($("#" + _o.id + "car_character_select").val());
				if (need_typed_a_code) 
					$("#" + _o.id + "car_r_commercial_client_code").val ($("#" + _o.id + "car_a_code_edit").val ());
				else  
					$("#" + _o.id + "car_r_commercial_client_code").val (($("#" + _o.id + "car_character_select").val ().toUpperCase() == "CTN") ? 'ctn': _o.commercial_client_code);
				$("#" + _o.id + "car_r_reseller_id").val (_o.reseller_id);
				$("#" + _o.id + "car_r_refSite").val (window.location.href);
				$("#" + _o.id + "car_r_ctn_site_name").val ('');
				$("#" + _o.id + "car_r_carCode").val (_o.car_code);
				$("#" + _o.id + "car_r_carCategoryCode").val ($("#" + _o.id + "car_category_select").val());
				$("#" + _o.id + "car_r_companyCode").val ($("#" + _o.id + "car_company_select").val());
				$("#" + _o.id + "car_r_language").val (_o.language);
				$("#" + _o.id + "car_r_pickupDest").val ($("#" + _o.id + "car_pickup_place_select").val());
				var pickup_date = $("#" + _o.id + "car_pickup_date_edit").val().split('/');
				$("#" + _o.id + "car_r_pickupDay").val (pickup_date[0]);
				$("#" + _o.id + "car_r_pickupMonth").val (pickup_date[1]);
				$("#" + _o.id + "car_r_pickupYear").val (pickup_date[2]);
				$("#" + _o.id + "car_r_pickupTime").val ($("#" + _o.id + "car_pickup_time_select").val());
				$("#" + _o.id + "car_r_returnDest").val ($("#" + _o.id + "car_return_place_select").val());
				var return_date = $("#" + _o.id + "car_return_date_edit").val().split('/');
				$("#" + _o.id + "car_r_returnDay").val (return_date[0]);
				$("#" + _o.id + "car_r_returnMonth").val (return_date[1]);
				$("#" + _o.id + "car_r_returnYear").val (return_date[2]);
				$("#" + _o.id + "car_r_returnTime").val ($("#" + _o.id + "car_return_time_select").val());
				$("#" + _o.id + "car_r_driverAge").val ($("#" + _o.id + "car_driver_age_edit").val());
				$("#" + _o.id + "car_r_currCode").val ($("#" + _o.id + "car_currency_select").val());
				
				$("#" + _o.id + "car_r").attr({action: (_o.box_mode == "book-ol" ? _o.action_book: _o.action_test ), method: _o.method, target: _o.target});

				var submit_form_book = true;
				if (_o.box_mode == "test") submit_form_book = (ctn_test_form(_o.id + "car_r"));
				if (submit_form_book) $("#" + _o.id + "car_r").submit();
			}
		});
		
	},
	set_elements_txt: function (l){
		var elements_txt = [
			{id:"car_title", txt:l.car_title},
			{id:"car_country_label", txt:l.car_country_label},
			{id:"car_pickup_place_label", txt:l.car_pickup_place_label},
			{id:"car_pickup_date_label", txt:l.car_pickup_date_label},
			{id:"car_pickup_date_span", txt:l.car_pickup_date_span},
			{id:"car_pickup_time_label", txt:l.car_pickup_time_label},
			{id:"car_return_place_label", txt:l.car_return_place_label},
			{id:"car_return_date_label", txt:l.car_return_date_label},
			{id:"car_return_date_span", txt:l.car_return_date_span},
			{id:"car_return_time_label", txt:l.car_return_time_label},
			{id:"car_company_label", txt:l.car_company_label},
			{id:"car_category_label", txt:l.car_category_label},
			{id:"car_driver_age_label", txt:l.car_driver_age_label},
			{id:"car_currency_label", txt:l.car_currency_label},
			{id:"car_character_label", txt:l.car_character_label},
			{id:"car_a_code_label", txt:l.car_a_code_label}];

		for (var i = 0; i < elements_txt.length; i++) {
			$("#" + this.options.id + elements_txt[i].id).text(elements_txt[i].txt)
		}
		
		$("#" + this.options.id + "car_search_boton").val(l.car_button);
		
		this.options.car_msg_age = l.car_msg_age;
		this.options.car_msg_a_code = l.car_msg_a_code;
		this.options.loading[0][1] = l.car_loading;
	},
	//	elements del buscador de carros
	elements: [
		 {id:"car_form", txt:"", tag:"FORM", c:""},
		 {id:"car", txt:"", tag:"DIV", c:"car_form", attr:{"class":"d"}},
		 {id:"car_title", txt:"Car Rental", tag:"H3", c:"car", attr:{"class":"t"}},
		//	elements del buscador de carros: selector de pais
		 {id:"car_country", txt:"", tag:"DIV", c:"car", attr:{"class":"c"}},
		 {id:"car_country_label", txt:"Select Country:", tag:"LABEL", c:"car_country"},
		 {id:"car_country_select", txt:"", tag:"SELECT", c:"car_country"},
		//	elements del buscador de carros: selector de lugar de recogida del auto
		 {id:"car_pickup_place", txt:"", tag:"DIV", c:"car", attr:{"class":"c"}},
		 {id:"car_pickup_place_label", txt:"Pick-up Place:", tag:"LABEL", c:"car_pickup_place"},
		 {id:"car_pickup_place_select", txt:"", tag:"SELECT", c:"car_pickup_place"},
		//	elements del buscador de carros: fecha de recogida del auto
		 {id:"car_pickup_date", txt:"", tag:"DIV", c:"car", attr:{"class":"c"}},
		 {id:"car_pickup_date_label", txt:"Pick-up date:", tag:"LABEL", c:"car_pickup_date"},
		 {id:"car_pickup_date_edit", txt:"", tag:"INPUT", c:"car_pickup_date", attr:{/* readonly:"true", */ "class":"date"}},
		 {id:"car_pickup_date_span", txt:"(dd/mm/yyyy)", tag:"SPAN", c:"car_pickup_date"},
		//	elements del buscador de carros: selector de hora de recogida del auto
		 {id:"car_pickup_time", txt:"", tag:"DIV", c:"car", attr:{"class":"c"}},
		 {id:"car_pickup_time_label", txt:"Pick-up time:", tag:"LABEL", c:"car_pickup_time"},
		 {id:"car_pickup_time_select", txt:"", tag:"SELECT", c:"car_pickup_time"},
		//	elements del buscador de carros: selector de lugar de recogida del auto
		 {id:"car_return_place", txt:"", tag:"DIV", c:"car", attr:{"class":"c"}},
		 {id:"car_return_place_label", txt:"Return Place:", tag:"LABEL", c:"car_return_place"},
		 {id:"car_return_place_select", txt:"", tag:"SELECT", c:"car_return_place"},
		//	elements del buscador de carros: fecha de recogida del auto
		 {id:"car_return_date", txt:"", tag:"DIV", c:"car", attr:{"class":"c"}},
		 {id:"car_return_date_label", txt:"Return date:", tag:"LABEL", c:"car_return_date"},
		 {id:"car_return_date_edit", txt:"", tag:"INPUT", c:"car_return_date", attr:{/* readonly:"true", */ "class":"date"}},
		 {id:"car_return_date_span", txt:"(dd/mm/yyyy)", tag:"SPAN", c:"car_return_date"},
		//	elements del buscador de carros: selector de hora de recogida del auto
		 {id:"car_return_time", txt:"", tag:"DIV", c:"car", attr:{"class":"c"}},
		 {id:"car_return_time_label", txt:"Return time:", tag:"LABEL", c:"car_return_time"},
		 {id:"car_return_time_select", txt:"", tag:"SELECT", c:"car_return_time"},
		//	elements del buscador de carros: selector de compañía rentadora
		 {id:"car_company", txt:"", tag:"DIV", c:"car", attr:{"class":"c"}},
		 {id:"car_company_label", txt:"Company:", tag:"LABEL", c:"car_company"},
		 {id:"car_company_select", txt:"", tag:"SELECT", c:"car_company"},
		//	elements del buscador de carros: selector de compañía rentadora
		 {id:"car_category", txt:"", tag:"DIV", c:"car", attr:{"class":"c"}},
		 {id:"car_category_label", txt:"Category:", tag:"LABEL", c:"car_category"},
		 {id:"car_category_select", txt:"", tag:"SELECT", c:"car_category"},
		//	elements del buscador de carros: edad del conductor
		 {id:"car_driver_age", txt:"", tag:"DIV", c:"car", attr:{"class":"c"}},
		 {id:"car_driver_age_label", txt:"Driver Age:", tag:"LABEL", c:"car_driver_age"},
		 {id:"car_driver_age_edit", txt:"", tag:"INPUT", c:"car_driver_age", attr:{}},
		//	elements  buscador de carros: moneda
		 {id:"car_currency", txt:"", tag:"DIV", c:"car", attr:{"class":"c"}},
		 {id:"car_currency_label", txt:"Currency:", tag:"LABEL", c:"car_currency"},
		 {id:"car_currency_select", txt:"", tag:"SELECT", c:"car_currency"},
		//	elements  buscador de carros: caracter de la reserva
		 {id:"car_character", txt:"", tag:"DIV", c:"car", attr:{"class":"c"}},
		 {id:"car_character_label", txt:"Commercial Client Type:", tag:"LABEL", c:"car_character"},
		 {id:"car_character_select", txt:"", tag:"SELECT", c:"car_character"},
		//	elements del buscador de carros: codigo de acceso
		 {id:"car_a_code", txt:"", tag:"DIV", c:"car", attr:{"class":"c"}},
		 {id:"car_a_code_label", txt:"Access code:", tag:"LABEL", c:"car_a_code"},
		 {id:"car_a_code_edit", txt:"", tag:"INPUT", c:"car_a_code", attr:{}},
		//	elements del buscador de carros: boton
		 {id:"car_search", txt:"", tag:"DIV", c:"car", attr:{"class":"btn"}},
		 {id:"car_search_boton", txt:"", tag:"INPUT", tp:"button", c:"car_search", attr:{value:"Search Cars", "class":"btn"}},
	 	 {id:"car_close", txt:"", tag:"DIV", c:"car", attr:{"class":"x"}}],

	styles : [{id:"car", style:{position: "absolute"}}],

	form_book_elements: [
		 {id:"car_r", txt:"", tag:"FORM", c:""},
		 {id:"car_r_commercial_client_code", txt:"", tag:"INPUT", tp:"hidden", c:"car_r", attr:{name:"commercial_client_code"}},
		 {id:"car_r_point_of_sale", txt:"", tag:"INPUT", tp:"hidden", c:"car_r", attr:{name:"point_of_sale"}},
		 {id:"car_r_commercial_client_type", txt:"", tag:"INPUT", tp:"hidden", c:"car_r", attr:{name:"commercial_client_type"}},
		 {id:"car_r_reseller_id", txt:"", tag:"INPUT", tp:"hidden", c:"car_r", attr:{name:"reseller_id"}},
		 {id:"car_r_refSite", txt:"", tag:"INPUT", tp:"hidden", c:"car_r", attr:{name:"refSite"}},
		 {id:"car_r_ctn_site_name", txt:"", tag:"INPUT", tp:"hidden", c:"car_r", attr:{name:"ctn_site_name"}},
		 {id:"car_r_carCode", txt:"", tag:"INPUT", tp:"hidden", c:"car_r", attr:{name:"carCode"}},
		 {id:"car_r_carCategoryCode", txt:"", tag:"INPUT", tp:"hidden", c:"car_r", attr:{name:"carCategoryCode"}},
		 {id:"car_r_companyCode", txt:"", tag:"INPUT", tp:"hidden", c:"car_r", attr:{name:"companyCode"}},
		 {id:"car_r_language", txt:"", tag:"INPUT", tp:"hidden", c:"car_r", attr:{name:"language"}},
		 {id:"car_r_pickupDest", txt:"", tag:"INPUT", tp:"hidden", c:"car_r", attr:{name:"pickupDest"}},
		 {id:"car_r_pickupDay", txt:"", tag:"INPUT", tp:"hidden", c:"car_r", attr:{name:"pickupDay"}},
		 {id:"car_r_pickupMonth", txt:"", tag:"INPUT", tp:"hidden", c:"car_r", attr:{name:"pickupMonth"}},
		 {id:"car_r_pickupYear", txt:"", tag:"INPUT", tp:"hidden", c:"car_r", attr:{name:"pickupYear"}},
		 {id:"car_r_pickupTime", txt:"", tag:"INPUT", tp:"hidden", c:"car_r", attr:{name:"pickupTime"}},
		 {id:"car_r_returnDest", txt:"", tag:"INPUT", tp:"hidden", c:"car_r", attr:{name:"returnDest"}},
		 {id:"car_r_returnDay", txt:"", tag:"INPUT", tp:"hidden", c:"car_r", attr:{name:"returnDay"}},
		 {id:"car_r_returnMonth", txt:"", tag:"INPUT", tp:"hidden", c:"car_r", attr:{name:"returnMonth"}},
		 {id:"car_r_returnYear", txt:"", tag:"INPUT", tp:"hidden", c:"car_r", attr:{name:"returnYear"}},
		 {id:"car_r_returnTime", txt:"", tag:"INPUT", tp:"hidden", c:"car_r", attr:{name:"returnTime"}},
		 {id:"car_r_driverAge", txt:"", tag:"INPUT", tp:"hidden", c:"car_r", attr:{name:"driverAge"}},
		 {id:"car_r_currCode", txt:"", tag:"INPUT", tp:"hidden", c:"car_r", attr:{name:"currCode"}}]
};


var debbies_sb = searchBox;
debbies_sb.comun = searchComun;
debbies_sb.cars = searchCars;
debbies_sb.hotels = searchHotels;
debbies_sb.flights = searchFlights;
debbies_sb.boxes = [debbies_sb.comun, debbies_sb.hotels, debbies_sb.flights, debbies_sb.cars];