var ctn_languages = new Array("en", "fr", "de", "es", "it", "nl");
var ctn_currencies = new Array("AUD","CAD","EUR","GBP","JPY");

if (typeof commercial_client_code == 'undefined') {commercial_client_code = "";}
if (typeof point_of_sale == 'undefined') {point_of_sale = "";}
if (typeof commercial_client_type == 'undefined') {commercial_client_type = "";}
if (typeof ctn_affiliate_id == 'undefined') {ctn_affiliate_id = "";}
if (typeof reseller_id == 'undefined') {reseller_id = "";}

if (typeof ctn_box_mode== 'undefined' ) {ctn_box_mode= "book-ol";}
if (typeof ctn_color_dark== 'undefined' ) {ctn_color_dark= "#000000"; }
if (typeof ctn_currency== 'undefined' )  {ctn_currency= "EUR";}
if (typeof ctn_language == 'undefined') {ctn_language = "en";}
if (typeof ctn_site_from== 'undefined' ) {ctn_site_from= "http://www.fast-manager.com";}
if (typeof ctn_use_external_css== 'undefined' ) {ctn_use_external_css= "1";}
if (typeof ctn_width== 'undefined' ) {ctn_width= "320";}
if (typeof ctn_height== 'undefined' ) {ctn_height= "350";}
if (typeof ctn_template== 'undefined' ) {ctn_template= "btn_button";}
if (typeof ctn_refering_url== 'undefined' ) ctn_refering_url= ""; 

if (typeof ctn_opacity== 'undefined' ) {ctn_opacity= "04"; }

var ctn_width_offset = 4;

var ctn_test_sever = "http://site4.fast-manager.com"
if (ctn_test_sever.toLowerCase() == ctn_site_from.toLowerCase()) {ctn_box_mode= "test";}

//se busca si la moneda definida está dentro del arreglo, si no se establece EUR
for(var i = 0; i < ctn_currencies.length; i ++) if(ctn_currency == ctn_currencies[i]) break;
ctn_currency = (i < ctn_currencies.length) ? ctn_currencies[i] : "EUR";

//se busca si el idioma definido está dentro del areglo, si no se establece EN
for(var i = 0; i < ctn_languages.length; i ++) if(ctn_language == ctn_languages[i]) break;
ctn_language = (i < ctn_languages.length) ? ctn_languages[i] : "en";

if (ctn_refering_url == '') ctn_refering_url = escape(window.location.href);

var browser = {
	init: function () {
		this._b = this.ss(this._db) || "unknown";
		this._v = this.sv(navigator.userAgent) || this.sv(navigator.appVersion) || "unknown";
	},
	ss: function (data) {
		for (var i=0;i<data.length;i++)	{
			var _ds = data[i]._s;
			var _dp = data[i]._p;
			this._vss = data[i]._vs || data[i]._id;
			if (_ds) { if (_ds.indexOf(data[i]._bs) != -1) return data[i]._id;}
			else if (_dp) return data[i]._id;
		}
	},
	sv: function (_ds) {
		var index = _ds.indexOf(this._vss);
		if (index == -1) return;
		return parseFloat(_ds.substring(index+this._vss.length+1));
	},
	_db: [
		{ _s: navigator.userAgent, _bs: "Chrome", _id: "Chrome"},
		{ _s: navigator.userAgent, _bs: "OmniWeb", _vs: "OmniWeb/", _id: "OmniWeb"},
		{ _s: navigator.vendor, _bs: "Apple", _id: "Safari", _vs: "Version"},
		{ _p: window.opera, _id: "Opera"},
		{ _s: navigator.vendor, _bs: "iCab", _id: "iCab"},
		{ _s: navigator.vendor, _bs: "KDE", _id: "Konqueror"},
		{ _s: navigator.userAgent, _bs: "Firefox", _id: "Firefox" },
		{ _s: navigator.vendor, _bs: "Camino", _id: "Camino" },
		{ _s: navigator.userAgent, _bs: "Netscape", _id: "Netscape" },// for newer Netscapes (6+)
		{ _s: navigator.userAgent, _bs: "MSIE", _id: "Explorer", _vs: "MSIE" },
		{ _s: navigator.userAgent, _bs: "Gecko", _id: "Mozilla", _vs: "rv"},
		{ _bs: "Mozilla", _id: "Netscape", _vs: "Mozilla" }// for older Netscapes (4-)
	]
};browser.init();
if ((browser._b == 'Explorer') && (browser._v == '6')) {ctn_width_offset = 120;};

//Se asigna el valor de la etiqueta en función del idioma establecido
var button_label;
switch (ctn_language) {
case 'en': button_label = 'Book Now'; break;
case 'es': button_label = 'Reservar'; break;
case 'de': button_label = 'Buchen'; break;
case 'fr': button_label = 'R&eacute;server'; break;
case 'hu': button_label = 'Foglal&aacute;s'; break;
case 'it': button_label = 'Prenotare'; break;
case 'jp': button_label = 'Book Now'; break;
case 'nl': button_label = 'Boek'; break;
default: button_label = 'Book Now';
}

//se carga la hoja de estilos si no se usa ninguna externa
if (ctn_use_external_css == "0") {
	document.writeln('<link href="' + ctn_site_from + '\/comun\/styles\/btn_book_now.css" rel="stylesheet" type="text\/css">\r\n');
}

//Funcion que toma todos los valores de las variables definidas y llama a la funcion de reserva de FB
function ctn_book_hotel_action(el, ctn_hotel_code) {
	var waction = ctn_book_hotel_URL(ctn_hotel_code);
	window.open(waction,"reservation","toolbar=no,width=400,height=350,menubar=no,scrollbars=yes,resizable=yes,alwaysRaised=yes");
}
function ctn_book_car_action(el, ctn_car_code) {
	var waction = ctn_book_car_URL(ctn_car_code);
	ctn_show_popup(el, waction);
}
function ctn_book_flight_action(el, ctn_departure_city, ctn_arrival_city) {
	var waction = ctn_book_flight_URL(ctn_departure_city, ctn_arrival_city);
	ctn_show_popup(el, waction);
}

function ctn_book_hotel(ctn_hotel_code){
	var lnk_style ='';
	var btn_style ='';
    if (ctn_use_external_css == "0"){ 
		lnk_style = 'style="color:' + ctn_color_dark +'"';
	    btn_style = 'style="background-color:' + ctn_color_dark +';border:1px solid ' +ctn_color_dark+'"';
	}	 
	
	var innerText = new Array ();
	switch (ctn_template) {
       case 'btn_link': innerText = Array ('<a class="lnk_book" href="javascript:;" title="',button_label,'" onclick="ctn_book_hotel_action(this, \'',ctn_hotel_code,'\');return false;"',lnk_style,'>',button_label,'</a>'); break;
    default: innerText = Array ('<input class="btn_book" type="button" value="',button_label,'" title="',button_label,'" onclick="ctn_book_hotel_action(this, \'',ctn_hotel_code,'\');" ',btn_style,'>');
    }
    document.write(innerText.join(''));
}
function ctn_book_car(ctn_car_code){
	var lnk_style ='';
	var btn_style ='';
    if (ctn_use_external_css == "0"){ 
		lnk_style = 'style="color:' + ctn_color_dark +'"';
	    btn_style = 'style="background-color:' + ctn_color_dark +';border:1px solid ' +ctn_color_dark+'"';
	}	 
	
	var innerText = new Array ();
	switch (ctn_template) {
       case 'btn_link': innerText = Array ('<a class="lnk_book" href="javascript:;" title="',button_label,'" onclick="ctn_book_car_action(this, \'',ctn_car_code,'\');return false;"',lnk_style,'>',button_label,'</a>'); break;
    default: innerText = Array ('<input class="btn_book" type="button" value="',button_label,'" title="',button_label,'" onclick="ctn_book_car_action(this, \'',ctn_car_code,'\');" ',btn_style,'>');
    }
    document.write(innerText.join(''));
}
function ctn_book_flight(ctn_departure_city, ctn_arrival_city){
	var lnk_style ='';
	var btn_style ='';
    if (ctn_use_external_css == "0"){ 
		lnk_style = 'style="color:' + ctn_color_dark +'"';
	    btn_style = 'style="background-color:' + ctn_color_dark +';border:1px solid ' +ctn_color_dark+'"';
	}	 
	
	var innerText = new Array ();
	switch (ctn_template) {
       case 'btn_link': innerText = Array ('<a class="lnk_book" href="javascript:;" title="',button_label,'" onclick="ctn_book_flight_action(this, \'',ctn_departure_city, '\',\'',ctn_arrival_city,'\');return false;"',lnk_style,'>',button_label,'</a>'); break;
    default: innerText = Array ('<input class="btn_book" type="button" value="',button_label,'" title="',button_label,'" onclick="ctn_book_flight_action(this, \'',ctn_departure_city, '\',\'',ctn_arrival_city,'\');" ',btn_style,'>');
    }
    document.write(innerText.join(''));
}

function ctn_book_hotel_URL(ctn_hotel_code) {
	var FBRESA = "http://www.fastbookings.biz/DIRECTORY/";
	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] == ctn_language) break;

	var waction = FBRESA+"preresa.phtml?Hotelnames="+ctn_hotel_code;
	waction += "&langue="+lc[i+1];
	waction += "&FSTBKNGTrackLink="+ctn_affiliate_id;
	waction += "&HTTP_REFERER="+escape(document.location.href);

	return waction;
}

function ctn_book_car_URL(ctn_car_code) {
	var waction = ctn_site_from + "/comun/gadget/search_cars.asp?ctn_language="+ctn_language;
	
	waction += "&commercial_client_code="+commercial_client_code;
	waction += "&point_of_sale="+point_of_sale;
	waction += "&commercial_client_type="+commercial_client_type;
	waction += "&reseller_id="+reseller_id;
	
	if (typeof ctn_color_dark != 'undefined') waction += "&ctn_color_dark="+ctn_color_dark.replace('#','');
	if (typeof ctn_color_medium != 'undefined') waction += "&ctn_color_medium="+ctn_color_medium.replace('#','');
	if (typeof ctn_color_clear != 'undefined') waction += "&ctn_color_clear="+ctn_color_clear.replace('#',''); 
	
	if (typeof ctn_title != 'undefined') waction += "&ctn_title="+ctn_title;
	if (typeof ctn_currency != 'undefined') waction += "&ctn_currency="+ctn_currency; 
	if (typeof ctn_site_name != 'undefined') waction += "&ctn_site_name="+ctn_site_name;
	if (typeof ctn_width != 'undefined') waction += "&ctn_width="+ctn_width;
	if (typeof ctn_height != 'undefined') waction += "&ctn_height="+ctn_height;
	
	if (typeof ctn_pickup_destination != 'undefined') waction += "&ctn_pickup_destination="+ctn_pickup_destination;
	if (typeof ctn_return_destination != 'undefined') waction += "&ctn_return_destination="+ctn_return_destination;
	if (typeof ctn_pickup_time != 'undefined') waction += "&ctn_pickup_time="+ctn_pickup_time;
	if (typeof ctn_return_time != 'undefined') waction += "&ctn_return_time="+ctn_return_time;
	
	if (typeof ctn_car_code != 'undefined') waction += "&ctn_car_code="+ctn_car_code;
	if (typeof ctn_car_category_code != 'undefined') waction += "&ctn_car_category_code="+ctn_car_category_code;
	if (typeof ctn_company_code != 'undefined') waction += "&ctn_company_code="+ctn_company_code;
	
	if (typeof ctn_show_title != 'undefined') waction += "&ctn_show_title="+ctn_show_title;
	if (typeof ctn_show_commercial_client_type != 'undefined') waction += "&ctn_show_commercial_client_type="+ctn_company_code;
	if (typeof ctn_show_currency != 'undefined') waction += "&ctn_show_currency="+ctn_show_currency;
	if (typeof ctn_show_company != 'undefined') waction += "&ctn_show_company="+ctn_show_company;
	if (typeof ctn_show_car_category != 'undefined') waction += "&ctn_show_car_category="+ctn_show_car_category;
	
	if (typeof ctn_box_mode != 'undefined') waction += "&ctn_box_mode="+ctn_box_mode;
	if (typeof ctn_site_from != 'undefined') waction += "&ctn_site_from="+ctn_site_from;
	if (typeof ctn_refering_url != 'undefined') waction += "&ctn_refering_url="+ctn_refering_url;
	

	return waction;
}
function ctn_book_flight_URL(ctn_departure_city, ctn_arrival_city) {
	var waction = ctn_site_from + "/comun/gadget/search_flights.asp?ctn_language="+ctn_language;
	
	waction += "&commercial_client_code="+commercial_client_code;
	waction += "&point_of_sale="+point_of_sale;
	waction += "&commercial_client_type="+commercial_client_type;
	waction += "&reseller_id="+reseller_id;
	
	if (typeof ctn_color_dark != 'undefined') waction += "&ctn_color_dark="+ctn_color_dark.replace('#','');
	if (typeof ctn_color_medium != 'undefined') waction += "&ctn_color_medium="+ctn_color_medium.replace('#','');
	if (typeof ctn_color_clear != 'undefined') waction += "&ctn_color_clear="+ctn_color_clear.replace('#',''); 
	
	if (typeof ctn_title != 'undefined') waction += "&ctn_title="+ctn_title;
	if (typeof ctn_currency != 'undefined') waction += "&ctn_currency="+ctn_currency; 
	if (typeof ctn_site_name != 'undefined') waction += "&ctn_site_name="+ctn_site_name;
	if (typeof ctn_width != 'undefined') waction += "&ctn_width="+ctn_width;
	if (typeof ctn_height != 'undefined') waction += "&ctn_height="+ctn_height;
	
	if (typeof ctn_departure_city != 'undefined') waction += "&ctn_departure_city="+ctn_departure_city; 
	if (typeof ctn_arrival_city != 'undefined') waction += "&ctn_arrival_city="+ctn_arrival_city;
	if (typeof ctn_show_city_code != 'undefined') waction += "&ctn_show_city_code="+ctn_show_city_code;
	if (typeof ctn_group_id != 'undefined') waction += "&ctn_group_id="+ctn_group_id;
	if (typeof ctn_airline != 'undefined') waction += "&ctn_airline="+ctn_airline;
	
	if (typeof ctn_show_title != 'undefined') waction += "&ctn_show_title="+ctn_show_title;
	if (typeof ctn_show_commercial_client_type != 'undefined') waction += "&ctn_show_commercial_client_type="+ctn_company_code;
	if (typeof ctn_show_currency != 'undefined') waction += "&ctn_show_currency="+ctn_show_currency;
	if (typeof ctn_show_company != 'undefined') waction += "&ctn_show_company="+ctn_show_company;
	if (typeof ctn_show_car_category != 'undefined') waction += "&ctn_show_car_category="+ctn_show_car_category;

	if (typeof ctn_box_mode != 'undefined') waction += "&ctn_box_mode="+ctn_box_mode;
	if (typeof ctn_site_from != 'undefined') waction += "&ctn_site_from="+ctn_site_from;
	if (typeof ctn_refering_url != 'undefined') waction += "&ctn_refering_url="+ctn_refering_url;

	return waction;
}

function ctn_show_popup(el, waction) {
	var divOverlay;
	if (divOverlay = document.getElementById('divOverlay')) {;}
	else 
	{
		divOverlay = document.createElement('DIV');
		divOverlay.setAttribute('id', 'divOverlay');
		divOverlay.style.position= "absolute";
		divOverlay.style.top= "0px";
		divOverlay.style.left= "0px";
		if (ctn_opacity != ""){
			divOverlay.style.backgroundColor = ctn_color_dark;
			divOverlay.style.opacity = "0." + ctn_opacity
			divOverlay.style.filter =" alpha(opacity=" + ctn_opacity + ")";
		}
		divOverlay.onclick = function(){ctn_hide_popup()};
		var bd = document.getElementsByTagName("BODY")[0];
		bd.appendChild(divOverlay);
	}
	var ifSB;
	if (ifSB = document.getElementById('ifSB')) {;}
	else 
	{
		ifSB = document.createElement('IFRAME');
		ifSB.setAttribute('id', 'ifSB');
		ifSB.setAttribute('scrolling', 'no');
		ifSB.setAttribute('allowTransparency', 'true');
		ifSB.setAttribute('frameBorder', '0');
		ifSB.style.position= "absolute";
		ifSB.style.overflow = "hidden";
		ifSB.style.width = (parseInt(ctn_width) + parseInt(ctn_width_offset)) + "px"; 
		ifSB.style.height = ctn_height + "px";
		ifSB.style.border = "0px none";
		var bd = document.getElementsByTagName("BODY")[0];
		bd.appendChild(ifSB);
	}

	if (ifSB.getAttribute('src') != waction) ifSB.setAttribute('src', waction);

	var r = ctn_get_absolute_pos(el);
	ifSB.style.left = r.x + "px"; ifSB.style.top = r.y + "px";
	ifSB.style.display= "";

	var w = ctn_get_page_size();
	divOverlay.style.height = w.h + "px"; divOverlay.style.width = "100%";
	divOverlay.style.display= "";
}
function ctn_hide_popup() {
	var ifSB;
	var divOverlay;
	if (ifSB = document.getElementById('ifSB')) {ifSB.style.display= "none";};
	if (divOverlay = document.getElementById('divOverlay')) {divOverlay.style.display= "none";};
}

function ctn_get_absolute_pos(el) {
	var SL = 0, ST = 0;
	var is_div = /^div$/i.test(el.tagName);
	if (is_div && el.scrollLeft) SL = el.scrollLeft;
	if (is_div && el.scrollTop) ST = el.scrollTop;
	var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
	if (el.offsetParent) {
		var tmp = ctn_get_absolute_pos(el.offsetParent);
		r.x += tmp.x; r.y += tmp.y;
	}
	return r;
};

function ctn_get_page_size() {
	
	var myWidth = 0; var myHeight = 0;
	
	if (window.innerHeight && window.scrollMaxY) {	
		myWidth = document.body.scrollWidth;
		myHeight = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		myWidth = document.body.scrollWidth;
		myHeight = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		myWidth = document.body.offsetWidth;
		myHeight = document.body.offsetHeight;
	}
	var w = {w: myWidth, h: myHeight};

	return w;
}