/* ======= Constants declaration ======== */ 
var PT_AIR_HOTEL_CAR = "CP";
var PT_HOTEL_CAR = "HC";
var PT_HOTEL_CONDO = "HO";
var PT_AIR_HOTEL = "AH";
var PT_AIR = "FO";
var PT_AIR_CAR = "FD";
var MAINDESTINATION_USA = "code__.__USA";

// To be Deprecated
//var BOOKING_SECTION = "BOOKING"; 
//var CUSTOMER_SECTION = "CUSTOMER";
//var CURRENT_SECTION = BOOKING_SECTION;

var SPECIAL_BOOKING = "SpecialBooking";
var OM_IMAGE_PATH = new String("/OMStorage/XXIMAGE/");
var TRAVEL_AGENT = "TravelAgent";
var ONLINE_ALIANCES = "OnlineAliances";
var ADMINISTRATOR = "Administrator";
var AIR_PASS = "AirPass";

function BrowserCheck() {
	var b = navigator.appName;
	if (b=="Netscape") this.b = "ns";
	else if (b=="Microsoft Internet Explorer") this.b = "ie";
	else this.b = "other";
	this.v = parseInt(navigator.appVersion);
	this.ns3 = (this.b=="ns" && this.v<4);
	this.ns4 = (this.b=="ns" && this.v==4);
	this.ns6 = (navigator.userAgent.indexOf('Netscape/6')>0);
	this.ns7 = (navigator.userAgent.indexOf('Netscape/7')>0);
	this.ie3 = (navigator.userAgent.indexOf('MSIE 3')>0);
	this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0);
	this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0);
	this.ie6 = (navigator.userAgent.indexOf('MSIE 6')>0);
	this.ie7 = (navigator.userAgent.indexOf('MSIE 7')>0);
	this.ns = (this.ns6 || this.ns7);
	this.ie = (this.ie5 || this.ie6 || this.ie7);
	this.dead = (this.ie3||this.ie4||this.ns3||this.ns4);
}

is = new BrowserCheck();
if(is.dead) { popWin(STATIC_CSSJS_PATH + "upgrade.htm","UPGRADE",470,200,1); }

function logOut(url) {
	createCookie("AutoLogonForUser");
	document.location = "Logoff.do?URL=" + url;
}

function eraseCookie(name)	{ createCookie(name,"",-1); }

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days*24*60*60*1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else { var expires = ""; }
	document.cookie = name + "=" + value + expires + "; path=/";
}
	
function swapBgCol(col,name) {
	target = document.getElementById(name);
	target.style.backgroundColor = col;
}

function swapImg(source, dest){ dest.src = source.src; }

function popWin(url,name,w,h,scroll) {
   var str = "height=" + h + ",innerHeight=" + h;
   str += ",width=" + w + ",innerWidth=" + w;
	if (window.screen) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;
		var xc = (aw - w) / 2;
		var yc = (ah - h) / 2;
		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
	}
	pop = window.open(url,name,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=" + scroll + ",resizable=1," + str);
   pop.focus();
}


function popWinLinks(url,name,sepcs) {
	//This function is used to pop up a window with different specifications for the pop up, relating to the window:
	pop = window.open(url,name,"" + sepcs + "");
	pop.focus();
}


	
function SwapDisplay(id){
	var obj = document.getElementById(id);
	if (obj.style.display == "block"){obj.style.display = "none";}
	else {obj.style.display = "block";}
}

function swapVisiblity(obj){
	if (obj.style.visibility == "visible"){obj.style.visibility = "hidden"; }
	else {obj.style.visibility = "visible";}
}

function post(anch){
   var f = document.myForm;
   f.submit();
}

function Rating(){ 
	var dv = document.getElementById("Rating");
	if (dv == null) { dv = document.getElementById("dvRating"); }
	posMouseRelative(dv);
	swapVisiblity(dv);
}




function Help(){ popWin('VoyagerHelpStepByStepDisplay.do?Booking_PopWin=true',"STANDARD",600,375,1); }
function popWinHostName(url,h,w,scroll){
	var str = "height=" + h + ",innerHeight=" + h;
	str += ",width=" + w + ",innerWidth=" + w;
	if (window.screen) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;
		var xc = (aw - w) / 2;
		var yc = (ah - h) / 2;
		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
	}
	pop = window.open(url,"pop","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=" + scroll + ",resizable=1," + str);
	pop.focus(); 
}
function aHrefHostName(urlval){ document.location = HOSTNAME + urlval; }
function taxFeesInfo(oid){ popWin(FORWARD_TAX_FEES + "?" + FN_TAX_FEES_DESTINATION_CITY_OID + "=" + oid,"TAXFEES",305,315,0); }

function addFavorites(pageName) {
	var f = document.favForm;
	popWin("","ADDFAV",400,200,0);
	f.TravelAgency_CustFavPageTitle.value = pageName;	
	f.target = "ADDFAV"; 
	f.submit();
	f.target = "_top"; 
}

function getWindowHeight() {
	if (document.all) { return document.body.clientHeight; }
	else if (document.getElementById && !document.all) { return window.innerHeight; }
	return -1;
}

function getWindowWidth() {
	if (document.all) { return document.body.clientWidth; }
	else if (document.getElementById && !document.all) { return window.innerWidth; }
	return -1;
}

function posMouseRelative(dv){
	dv.style.left = mp.x + "px"; //((parseInt(dv.style.width) + mp.x) < getWindowWidth())? mp.x : mp.x - parseInt(dv.style.width) + "px";
	dv.style.top = mp.y + "px";
}

function setMousePosition(e){
	if (!e) { var e = window.event; }
	mp.x = (e.clientX) ? e.clientX : e.pageX ;
	mp.y = (e.clientY)? e.clientY + document.body.scrollTop : e.pageY ;
}

function mousePosition(){
   this.x = 0;
   this.y = 0;
}

var mp = new mousePosition();
document.onmousemove = setMousePosition;

function findPosX(obj)
{
	var curleft = 0;
	
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
	
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

/*function whyIsImportant(state){ 

	var dv = document.getElementById("dvWhyImportant");
	var db = document.getElementById("dvWhyImportantBlock");
	if(db == null){
		dv.style.left = mp.x + 10;
		dv.style.top = mp.y - dv.offsetHeight;
	}else{
		dv.style.left = mp.x - findPosX(db) + 10;
		dv.style.top = mp.y - findPosY(db) - dv.offsetHeight;
	}	
	dv.style.visibility = (state)? "visible" : "hidden";
}

//from pleasanthildays.com
function whyIsImportant(state){ 
	var dv = document.getElementById("dvWhyImportant");
	var db = document.getElementById("dvWhyImportantBlock");
	dv.style.left = mp.x - findPosX(db) + 10;
	dv.style.top = mp.y - findPosY(db) - dv.offsetHeight / 1.2;
	dv.style.visibility = (state)? "visible" : "hidden";
}*/


//Use this function instead of the above ones : layers coordinates are well calculated below...
function whyIsImportant(state){ 
//debugger;
	var dv = document.getElementById("dvWhyImportant");
	var db = document.getElementById("dvWhyImportantBlock");
	if(db == null){
		dv.style.left = ((parseInt(dv.style.width) + mp.x) < getWindowWidth())? mp.x : mp.x - parseInt(dv.style.width);
		dv.style.top = mp.y;
	}else{
		dv.style.left = mp.x - findPosX(db) + 10;
		dv.style.top = mp.y - findPosY(db) - dv.offsetHeight / 1.2;
	}
	dv.style.visibility = (state)? "visible" : "hidden";
}

