// functions for results pages
// Please try to comment around functions what page(s) use them.

/* - - - - - - - - - - - - - - -
AIR
- - - - - - - - - - - - - - - */

function AirResultsPageInit() {
	// Once flex is done, this if statement should be removed, but still need to call scrollToExpandedPAR() - mduhan - 20050803
	if (!eval(bFromExchange)) {
		theForm = document.flightSearchForm;
		if (!eval(bFromDealsDetails) && !eval(bFromFareCalSearch)) {
			switch(sSearchType) {
				case "oneway":
					dateDDs = new Array(theForm.elements['slice1:month'],theForm.elements['slice1:day']);
					stripYears(theForm.elements['slice1:month']);
				break;
				case "roundtrip":
					dateDDs = new Array(theForm.elements['slice1:month'],theForm.elements['slice1:day'],theForm.elements['slice2:month'],theForm.elements['slice2:day']);
					stripYears(theForm.elements['slice1:month']);stripYears(theForm.elements['slice2:month']);
				break;
				case "multiflight":
					//dateDDs redefined near drop-downs
				break;
			}
		}
	}
	scrollToExpandedPAR();
}

// PAR
function expandPreferredSearch() {
   theForm = document.botForm;
   theForm.corpPreferredOnlySearchOverride.value = 'True';
   theForm.submit();
}
function collapseParModule(moduleId) {
	with (document) {
		getElementById(moduleId+"E").style.display = "none";
		getElementById(moduleId+"E").style.visibility = "hidden";
		getElementById(moduleId+"C").style.display = "block";
		getElementById(moduleId+"C").style.visibility = "visible";
	}
}
function expandParModule(moduleId) {
	//this function is for re-expanding a PAR module that has been collapsed by the user - other PAR modules require a page refresh
	with (document) {
		getElementById(moduleId+"C").style.display = "none";
		getElementById(moduleId+"C").style.visibility = "hidden";
		getElementById(moduleId+"E").style.display = "block";
		getElementById(moduleId+"E").style.visibility = "visible";
	}
}
function switchParHotelDetails(resultIndex, hotelItem) {
	//this function is for PARs with multiple hotels. It switches the details section when the user clicks a radio button.
	var oPar1 = document.getElementById("par"+resultIndex+"Hotel1");
	var oPar2 = document.getElementById("par"+resultIndex+"Hotel2");
	var oPop1 = document.getElementById("pop"+resultIndex+"Hotel1");
	var oPop2 = document.getElementById("pop"+resultIndex+"Hotel2");
	switch (hotelItem) {
		case "1":
			oPar2.style.display = "none";
			oPar2.style.visibility = "hidden";
			oPar1.style.display = "block";
			oPar1.style.visibility = "visible";
			oPop2.style.display = "none";
			oPop2.style.visibility = "hidden";
			oPop1.style.display = "block";
			oPop1.style.visibility = "visible";
		break;
		case "2":
			oPar1.style.display = "none";
			oPar1.style.visibility = "hidden";
			oPar2.style.display = "block";
			oPar2.style.visibility = "visible";
			oPop1.style.display = "none";
			oPop1.style.visibility = "hidden";
			oPop2.style.display = "block";
			oPop2.style.visibility = "visible";
		break;
	}
}
function scrollToExpandedPAR() {
	if (sParAnchor != "null" && sParAnchor != "") {
		parAnchor = parseFloat(sParAnchor);
		var parAnchorHref = "";
		if (parAnchor > -1) {
			parAnchorHref = "result"+(parAnchor);
		}
		if (location.hash != '#' + parAnchorHref && parAnchorHref != '') {
			location.hash = parAnchorHref;
		}
	}
}

/* - - - - - - - - - - - - - - -
AIR FLEX
- - - - - - - - - - - - - - - */

function AirFlexResultsPageInit() {
	var sForm = "";
	switch(fareCalSearchType) {
		case "flexible weekend":		sForm = "fareCalChangeWeekend";	break;
		case "flexible around dates":	sForm = "fareCalChangeDates";	break;
		case "flexible trip length":	sForm = "fareCalTripLength";	break;
	}
	theForm = eval("document." + sForm);
	switch(sFareCalSearchTypeValue) {
		case "flexible around dates":
			dateDDs = [
				theForm.elements['fareCalFlexDaysSlice1:month']
				, theForm.elements['fareCalFlexDaysSlice1:day']
				, theForm.elements['fareCalFlexDaysSlice2:month']
				, theForm.elements['fareCalFlexDaysSlice2:day']
			];
			stripYears(theForm.elements['fareCalFlexDaysSlice1:month']);
			stripYears(theForm.elements['fareCalFlexDaysSlice2:month']);
		break;
		case "flexible trip length":
			dateDDs = [
				theForm.elements['fareCalFlexTripSlice1:month']
				, theForm.elements['fareCalFlexTripSlice1:day']
				, theForm.elements['fareCalFlexTripSlice2:month']
				, theForm.elements['fareCalFlexTripSlice2:day']
			];
			stripYears(theForm.elements['fareCalFlexTripSlice1:month']);
			stripYears(theForm.elements['fareCalFlexTripSlice2:month']);
		break;
	}
}


function changeBGColor (isOn,col,row,div) {
	if (document.getElementById) {
		col=document.getElementById(col);
		row=document.getElementById(row);
		div=document.getElementById(div);
		if (isOn) {
			col.style.backgroundColor = "#ff3";
			row.style.backgroundColor = "#ff3";
			div.style.backgroundColor = "#ff3";
		} else {
			col.style.backgroundColor = "#cef";
			row.style.backgroundColor = "#cef";
			div.style.backgroundColor = "#fff";
		}
	}
}

/* - - - - - - - - - - - - - - -
APH
- - - - - - - - - - - - - - - */

//rewritten by bdillard 07.15.2005 - now used for APH, HPC, and airFlex matrices - two functs could later be combined
var oldClassName = "";
function DPMatrixHili(sTD) {

        if(document.getElementById(sTD).innerHTML.replace(/^\s+|\s+$/g, '').length == 0) {
            return false;
        }

	var a = sTD.split("c");
	var sRow = a[0];
	var sRowPhoto = "r" + sRow;
	var saver="row" + sRow;
	var sCol = "c" + a[1];

	var bAlt = parseFloat(sRow.substring(1,sRow.length)) % 2 == 0;
	var bAlreadyHili = document.getElementById(sTD).className == "hili";

	if(!bAlreadyHili){
		oldClassName=document.getElementById(sTD).className;
	}
	var sClassTD = bAlreadyHili ? (bAlt ? "alt" : "norm") : "hili";

	var sClassRow = "rowHeaderDP ";
	sClassRow += bAlreadyHili ? (bAlt ? "alt" : "norm") : "hili";

	var sClassRowPhoto = "rowHeaderDPPhoto ";
	sClassRowPhoto += bAlreadyHili ? (bAlt ? "alt" : "norm") : "hili";

	var sClassCol = "colHeaderDP ";
	sClassCol += bAlreadyHili ? "norm" : "hili";

	if( bAlreadyHili && oldClassName != null ){
		sClassTD = oldClassName;
		oldClassName="";
	}
	changeCss(sTD, sClassTD);
	changeCss(sRow, sClassRow);
	if (document.getElementById(sRowPhoto)) changeCss(sRowPhoto, sClassRowPhoto);
	changeCss(sCol,	sClassCol);
	var  altRow = bAlt? "alt disc" : "norm disc";
	if(bAlreadyHili) {
		changeCss(saver,altRow );
	}
	else {
		changeCss(saver,'hili disc' );
	}
}

function AirMatrixHili(sTD) {
	var a = sTD.split("c");
	var sRow = a[0];
	var sRowPhoto = "r" + sRow;
	var sCol = "c" + a[1];
	var bAlreadyHili = document.getElementById(sTD).className == "hili";

	if(!bAlreadyHili){
		oldClassName=document.getElementById(sTD).className;
		oldClassRowHeader=document.getElementById(sRowPhoto).className;
		oldClassColHeader=document.getElementById(sCol).className;
	}
	var sClassTD = bAlreadyHili ? "" : "hili";

	var sClassRow = "";
	sClassRow += bAlreadyHili ? "" : "hili";

	var sClassRowPhoto = "rowHeaderOn rowHeaderhili ";
	sClassRowPhoto += bAlreadyHili ? "" : "hili";

	var sClassCol = "colHeaderOn colHeaderhili ";
	sClassCol += bAlreadyHili ? "" : "hili";

	if( bAlreadyHili && oldClassName != null ){
		sClassTD = oldClassName;
		oldClassName="";
	}
	changeCss(sTD, sClassTD);
	//changeCss(sRow, sClassRow);
	if (document.getElementById(sRowPhoto)) changeCss(sRowPhoto, sClassRowPhoto);
	changeCss(sCol,	sClassCol);
	if(bAlreadyHili) {
		changeCss(sCol,oldClassColHeader);
		changeCss(sRowPhoto,oldClassRowHeader );
	}
}

function FlexMatrixHili(sTD) {
	var a = sTD.split("c");
	var sRow = a[0];
	var sCol = "c" + a[1];

	var bAlreadyHili = document.getElementById(sTD).className == "hili";

	var sClassTD = bAlreadyHili ? "norm" : "hili";
	var sClassRow = "rowHeaderFlex " + (bAlreadyHili ? "alt" : "hili");
	var sClassCol = "colHeaderFlex " + (bAlreadyHili ? "alt" : "hili");

	changeCss(sTD, sClassTD);
	changeCss(sRow, sClassRow);
	changeCss(sCol,	sClassCol);
}

function showCarrierCode(thisID){
       // gets carrierCode element
       var carrierCode=document.getElementById(thisID);
       // shows carrierCode element
       carrierCode.style.visibility='visible';
}

function hideCarrierCode(thisID){
       // gets carrierCode element
       var carrierCode=document.getElementById(thisID);
       // hides carrierCode element
       carrierCode.style.visibility='hidden';
}

/*Script for drag-able popup*/
function iecompattest(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function loadwindow(url){
	if (!ie5&&!ns6)
		window.open(url,"","scrollbars=1")
	else{
		document.getElementById("dwindow").style.display=''
		document.getElementById("dwindow").style.width=325+"px"
		document.getElementById("dwindow").style.height=465+"px"
		document.getElementById("dwindow").style.left=offX+"px"
		document.getElementById("dwindow").style.top=offY+"px"
		document.getElementById("cframe").src=url
	}
}

function stopdrag(){
	dragapproved=false;
	document.getElementById("dwindow").onmousemove=null;
}
//Added as part of bug #57992
var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};

var crossShop = function() {
	var csOuterContainer = document.createElement("div");
	var csContainer = document.createElement("div");
	var csTitle = document.createElement("h2");
	var csText = document.createElement("p");
	var csFoot = document.createElement("p");
	var csButton = document.createElement("span");
	$(csContainer).addClassName("crossshopinfo");
	$(csFoot).addClassName("finePrint");
	csContainer.appendChild(csTitle);
	csContainer.appendChild(csText);
	csContainer.appendChild(csButton);
	csContainer.appendChild(csFoot);
	csOuterContainer.appendChild(csContainer);
	
	this.updateName = function(inSupplierName, inSupplierButton) {
		$(csButton).innerHTML = $(inSupplierButton).innerHTML;
		$(csTitle).update(inSupplierName);
		$(csText).update("Book directly on the " + inSupplierName + " site.");
		$(csFoot).update("You will be taken to the " + inSupplierName + " site in a new browser window.");
		return csContainer;
	}

}
// End of file
