 /**This file holds portal methods
 * @author Vivek Mohan
 * @version 1.0.0.4
 * @created 5/14/2009
 */

overrideFormName = false;
var activeSE = '';
var activeName = '';



//preloading alphacube images
pic1= new Image(); 
pic1.src="/STATICS/imgs/commons/ajaxloader.gif";

pic2= new Image(); 
pic2.src="/STATICS/imgs/prototype/alphacube/left-top.gif"; 

pic3= new Image(); 
pic3.src="/STATICS/imgs/prototype/alphacube/top-middle.gif"; 

pic4= new Image(); 
pic4.src="/STATICS/imgs/prototype/alphacube/right-top.gif"; 

pic5= new Image(); 
pic5.src="/STATICS/imgs/prototype/alphacube/frame-left.gif"; 

pic6= new Image(); 
pic6.src="/STATICS/imgs/prototype/alphacube/frame-right.gif"; 

pic7= new Image(); 
pic7.src="/STATICS/imgs/prototype/alphacube/bottom-left-c.gif"; 

pic8= new Image(); 
pic8.src="/STATICS/imgs/prototype/alphacube/bottom-middle.gif"; 

pic9= new Image(); 
pic9.src="/STATICS/imgs/prototype/alphacube/bottom-right-c.gif"; 

function search(lg, code)
{	if(code == 0)
		return;
	add = (code != 'pure_luxury')? 'luxury_hotels_' : 'hotels_';


	//removed LOCATION
	if (code=='spa' || code=='gastronomy' || code=='golf' || code=='pure_luxury' || code=='elegance_tradition' || code=='design_contemporary'  || code=='mansions_castles')
		$("idForm").action = '/'+lg+'/'+add+code+'.htm';
	else
		$("idForm").action = '/'+lg+'/location/'+add+code+'.htm';

	if (overrideFormName==true)
		$("idForm").submit();
	else
		$("idForm").submit();
}


function displaymorerooms(rowid)
{
	$('DIV'+rowid).style.display = '';
	$('btn_rooms'+rowid).style.display = 'none';
	
}

function search11(code, w, h, top, left)
{
	if(code != undefined && code != "")
		$("zone").value = code;

	if (parseInt($("zone").value) < 0)
	{
		alert('Select a district');
		return;
	}

	/*
	var arrival_date = $F("fromdate");
	var nb_adult = $F("nbadult");
	var nb_child = $F("nbchild");
	var currency = $F("currency");
	var nb_days = $F("nbdays");
	var zone = $F("zone");
	*/
	//console.log("date:"+arrival_date+"\nadult:"+nb_adult+"\nchild:"+nb_child+"\ncurrency:"+currency+"\nnbdays:"+nb_days+"\nzone:"+zone);
	if (overrideFormName==true)
		$("idForm2").submit();
	else
		$("idForm").submit();

	if(w == undefined)
		w = 500;
	if(h == undefined)
		h = 200;
		
	if(top != undefined) elmt_top = top;
	if(left != undefined) elmt_left = left;

	if(typeof(elmt_w) != "undefined") w = elmt_w;
	if(typeof(elmt_h) != "undefined") h = elmt_h;
	
	if($('moteur_carte'))
		$('moteur_carte').style.visibility = 'hidden';

	if($('flash_promo'))
		$('flash_promo').style.visibility = 'hidden';
		
	if($("quicksearchphoto"))
		$('quicksearchphoto').style.visibility = 'hidden';
		
	if($("quicksearchvideo"))
		$('quicksearchvideo').style.visibility = 'hidden';
	Dialog.info(pop_title + "<br><img src='/STATICS/imgs/commons/ajaxloader.gif' border='0' vspace='20'>", {width:w, height:h, top:elmt_top, left:elmt_left, className: "alphacube"});
}






function search_quick(code, w, h, top, left)
{
	//prepare all needed attributes
	var attr = "action=hotel";
		//attr += "&page="+$F("crtPage");
		attr += "&page="+$F("currentPage");
		attr += "&site=paris";
		attr += "&lg="+$F("pushLanguage");
		attr += "&quicksearch=request";
		attr += "&cname="+$F("cname");
		attr += "&fromdate="+$F("fromdate");
		attr += "&fromdate_txt="+$F("fromdate_txt");
		attr += "&nbdays="+$F("nbdays");
		attr += "&nbadults="+$F("nbadults");
		attr += "&currency="+$F("currency");

	if ((activeSE=='') && (document.getElementById('bloc_search_engine_video')!=null))
	{
		activeSE = document.getElementById('bloc_search_engine_video').innerHTML;
		activeName = 'bloc_search_engine_video';
		usingObj = document.getElementById('bloc_search_engine_video');
	}
	else
		if ((activeSE=='') && (document.getElementById('bloc_search_engine_photo')!=null))
		{
			activeSE = document.getElementById('bloc_search_engine_photo').innerHTML;
			activeName = 'bloc_search_engine_photo';
			usingObj = document.getElementById('bloc_search_engine_photo');
		}

	//usingObj.update("<div><br><br><br><br><br><br><table align=center><tr><td><img src='/STATICS/imgs/commons/ajaxloader.gif' border='0' vspace='20'><br></td></tr></table></div>");
	usingObj.innerHTML = "<div><br><br><br><br><br><br><table align=center><tr><td><img src='/STATICS/imgs/commons/ajaxloader.gif' border='0' vspace='20'><br></td></tr></table></div>";
	var myAjax = new Ajax.Request(
                    '../../PHP/anyscript.php',
                    {
                        method: 'post',
                        parameters: attr,
                        asynchronous: true,
                        onComplete: showResponse,
                        contentType:'application/x-www-form-urlencoded',
                        encoding: 'UTF-8'
                    });

        function showResponse(originalRequest)
        {
                var result = originalRequest.responseText;
		usingObj.innerHTML = originalRequest.responseText;
		document.getElementById("result").style.display = 'block';
	}
}

function ShowPage(page)
{
	querystring = "?page="+page;
	/*
	querystring+= "&day="+d;
	querystring+= "&month="+m;
	querystring+= "&year="+y;
	querystring+= "&nbdays="+night;
	querystring+= "&nbadult="+adult;
	querystring+= "&nbchild="+child;
	querystring+= "&currency="+currency;
	*/
	//alert(querystring);
	location.href=querystring;
}

function hhotelResaDist(cname, lg, codeprice, codetrack, firstroom, firstdate, CurrencyLabel, nights, adults)
{
	if (adults == "")
		adults = 1;
	if(firstdate=='')
	{
		firstdate = document.getElementById('arrdate_txt').value;
		firstdate = firstdate.split('/');
		firstdate = firstdate[0].substring(2)+firstdate[1]+firstdate[2];
		var index = document.getElementById('currency').selectedIndex;
		CurrencyLabel = document.getElementById('currency').options[index].value;
	}
	hhotelResaDist_(cname, lg, codeprice, codetrack, firstroom, firstdate, CurrencyLabel, nights, adults);
}

function hhotelResaDist_(cname, lg, codeprice, codetrack, firstroom, firstdate, CurrencyLabel, nights, adults)
{
	var waction = "http://www.fastbooking.co.uk/DIRECTORY/preresa.phtml?Hotelnames="+cname;
	if (lg != "") waction += "&langue="+lg;
	waction += "&style=DIRECT";
	waction += "&clustername=NO";	// no cross-selling
	if (codeprice != "") waction += "&FSTBKNGCode=FB-DISTRIB";
	else waction += "&FSTBKNGCode=FB-DISTRIB";
	waction += "&FSTBKNGTrackLink="+codetrack;
	if (firstroom != "") waction += "&FirstRoomName="+firstroom;
	if (firstdate != "") waction += "&FirstDate="+firstdate+';'+nights+';'+adults+';0';
	waction += '&so=9&pres=CHT&brand=CHT';
	if (CurrencyLabel != "") waction += "&CurrencyLabel="+CurrencyLabel;
	window.open(waction,"reservation","toolbar=no,width=400,height=350,menubar=no,scrollbars=yes,resizable=yes,alwaysRaised=yes");
}

function hwindow(url) {
	window.open(url, 'infos', 'status=yes,location=yes,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,alwaysRaised=yes');
	return false;
}
function hhistory(url) {
	window.open(url, 'history', 'status=no,location=no,toolbar=no,width=600,height=350,menubar=no,scrollbars=yes,resizable=yes,alwaysRaised=yes');
	//return false;
}

function salescondition(url)
{
	var domaine = "http://portal.fastbooking-sa.fr/fiche/conditions.phtml?";
	domaine += url;
	window.open(domaine, 'salescond', 'status=no,location=no,toolbar=no,width=600,height=600,menubar=no,scrollbars=yes,resizable=yes,alwaysRaised=yes');
}

//xiti
function xt_clic(typecl,site,section,page,url,nvlle)
{
Xt_r = document.referrer;
Xt_h = new Date();
xt_img = new Image();
Xt_i = 'http://logi7.xiti.com/hit.xiti?s='+site+'&s2='+section;
Xt_i += '&p='+page+'&clic='+typecl+'&hl=' + Xt_h.getHours() + 'x' + Xt_h.getMinutes() + 'x' + Xt_h.getSeconds();
if(parseFloat(navigator.appVersion)>=4)
{Xiti_s=screen;Xt_i += '&r=' + Xiti_s.width + 'x' + Xiti_s.height + 'x' + Xiti_s.pixelDepth + 'x' + Xiti_s.colorDepth;}
Xt_i += '&ref=' + Xt_r.replace(/[<>]/g, '').replace(/&/g, '$');
xt_img.src = Xt_i;
if (url != null)
{ if ((nvlle=='')||(nvlle==null)) { document.location = url;} else {xfen = window.open(url,'xfen',''); xfen.focus();}}
else
{return;}
}

var mydomain = "fastbooking";
function printMail(user) {
	var address = user + "@" + mydomain;
	document.writeln(address + "." + "com");
}

function sleep(milliseconds) 
{
	var start = new Date().getTime();
	for (var i = 0; i < 1e7; i++) 
	{
    if ((new Date().getTime() - start) > milliseconds)
      break;
	}
}


/* already defined below
function hhotelDispopriceFHP(cname, lg, codetrack, year, month, day, nights, currency)
{
	var waction = "http://81.25.194.32/00000001/032/023112/dispopricev2.phtml?Clusternames="+cname;
 // FRRBeaulieu&Hotelnames=FRRBeaulieu&fromday=8&frommonth=1&fromyear=2009&nbdays=1&adulteresa=1&redir=UK-so5523q0o4&showPromotions=1&showPromotions=1&rt=1231424675
 if (lg != "") waction += "&langue="+lg;
 waction += "&Hotelnames=cname";
 waction += "&FSTBKNGTrackLink="+codetrack;
 if (day != "") waction += "&fromday="+day;
 if (month != "") waction += "&frommonth="+month;
 if (year != "") waction += "&fromyear="+year;
 waction += "&nbdays=1";
// if (CurrencyLabel != "") waction += "&CurrencyLabel="+CurrencyLabel;
 waction +=  '&redir=UK-so5523q0o4&showPromotions=1&showPromotions=1&rt=1231424675'
 window.open(waction,"reservation","toolbar=no,width=400,height=350,menubar=no,scrollbars=yes,resizable=yes,alwaysRaised=yes");
}
*/
function WindowCancel()
{
	waction = "http://portal.fastbooking-sa.fr/fiche/cancel.phtml";
	window.open(waction,"cancel","toolbar=no,width=650,height=550,menubar=no,scrollbars=yes,resizable=yes,alwaysRaised=yes");
}


function upd(divName, hotelName, lg)
{
 var attr = "refresh=true";
	attr += "&page="+hotelName;
	attr += "&site=paris";
	attr += "&lg="+lg;
	attr += "&action=hotel";
	attr += "&quicksearch=request";

	var myAjax = new Ajax.Request(
	    '../../PHP/anyscript.php',
	    {
		method: 'post',
		parameters: attr,
		asynchronous: true,
		onComplete: showResponse,
		contentType:'application/x-www-form-urlencoded',
		encoding: 'UTF-8'
	    });

	function showResponse(originalRequest)
	{
		var result = originalRequest.responseText;
		document.getElementById(divName).innerHTML = result;
		switchSearchEngine(1);
	}
}


function loadPreviousSE(divName, hotelName, lg)
{
	if ((activeSE=='') || (activeSE==null))
	{
		upd(divName, hotelName, lg);
	}
	else
	{
		document.getElementById(activeName).innerHTML = activeSE;
	}

//init calendar
	
}


function hhotelDispopriceFHP(cluster, cname, lg, codetrack, year, month, day, nights, currency, nbadults)
{//cluster, cname, lg, codetrack, year, month, day, nights, currency
	if (nbadults == "")
		nbadults = 1;

	if(year=='')
	{
		firstdate = document.getElementById('arrdate_txt').value;
		firstdate = firstdate.split('/');
		year = firstdate[0];
		if(year.length==2)
		{
			month = firstdate[1];
			day = firstdate[0];
			year = firstdate[2];
		}
		else
		{
			month = firstdate[1]
			day = firstdate[2];
		}
		nights = document.getElementById('nonights').innerHTML;
		var index = document.getElementById('currency').selectedIndex;
		currency = document.getElementById('currency').options[index].value;

	}

	hhotelDispopriceFHP_(cluster, cname, lg, codetrack, year, month, day, nights, currency, nbadults);
}

function hhotelFormDispopriceFHP(cluster, cname, lg, codetrack, year, month, day, nights, currency)
{//cluster, cname, lg, codetrack, year, month, day, nights, currency


	if(year=='')
	{
		firstdate = document.getElementById('arrdate_txt').value;
		firstdate = firstdate.split('/');
		year = firstdate[0];
		if(year.length==2)
		{
			month = firstdate[1];
			day = firstdate[0];
			year = firstdate[2];
		}
		else
		{
			month = firstdate[1]
			day = firstdate[2];
		}
		nights = document.getElementById('nonights').innerHTML;
		var index = document.getElementById('currency').selectedIndex;
		currency = document.getElementById('currency').options[index].value;

	}
	price = "FB-DISTRIB";
	firstdate = year.substring(2,4)+month+day;
	hhotelFormDispopriceFHP_(cluster, lg, price, codetrack, firstdate, nights, currency);
}

function hhotelDispopriceFHP_(cluster, cname, lg, codetrack, year, month, day, nights, currency, nbadults)
{//cluster, cname, lg, codetrack, year, month, day, nights, currency
	var waction = "http://www.fastbooking.co.uk/DIRECTORY/dispoprice.phtml?clusterName="+cluster;
	if (lg != "") waction += "&langue="+lg;
	waction += "&Hotelnames="+cluster;
	waction += "&FSTBKNGTrackLink="+codetrack;
	if (day != "") waction += "&fromday="+day;
	if (month != "") waction += "&frommonth="+month;
	if (year != "") waction += "&fromyear="+year;
	waction += "&nbdays="+nights;
	if (currency != "") waction += "&CurrencyLabel="+currency;
	waction += '&showPromotions=1';
	waction += '&so=9&brand=CHT';
	waction += '&adulteresa='+nbadults;
	window.open(waction,"reservation","toolbar=no,width=800,height=550,menubar=no,scrollbars=yes,resizable=yes,alwaysRaised=yes");
}

function hhotelFormDispopriceFHP_(cluster, lg, price, codetrack, firstdate, nights, currency)
{
	// firstdate is in format: YYMMDD
	var waction = "http://www.fastbooking.co.uk/DIRECTORY/crs.phtml?clusterName="+cluster;
	if (lg != "") waction += "&langue="+lg;
	if (price != "") waction += "&FSTBKNGCode="+price;
	waction += "&from="+codetrack;
	if (firstdate != "") waction += "&FirstDate="+firstdate;
	if (nights != "") waction += "&nights="+nights;
	if (currency != "") waction += "&Currency="+currency;
	waction += '&so=9&brand=CHT';
	window.open(waction,"search","toolbar=no,width=800,height=550,menubar=no,scrollbars=yes,resizable=yes,alwaysRaised=yes");
}
