// 080617 - 5:00pm || ad placement fix for the none sbs search paths
/*-------------------
* FUNCTION LIST
loadReg()
FindTedX(oEl,iAdd)
FindTedY(oEl,iAdd)
getSrchPos()
getWidth()
setXPos()
getXPos()
---------------------*/

// REGISTER POSITIONING
/*
W3C compliant browsers use the addEventListener().
IE browsers use attachEvent(). */
function loadReg() {
	if (window.addEventListener) {
		window.addEventListener('resize', getXPos, false); // Modern Browsers, none IE
	} else {
		if (window.attachEvent) {
			window.attachEvent('onresize', getXPos); // IE Browsers
		} else {
			var old2 = window.onscroll; 
			window.onresize = function() { if (old2) old2(); getXPos(); } // IE Mac
		}
	}
	setXPos();
}

function FindTedX(oEl,iAdd) {
	var x = String(iAdd) == 'undefined' ? 0 : iAdd;
	if (oEl.offsetWidth) { x += oEl.offsetWidth; }
	if (oEl.offsetParent) {
		while (oEl.offsetParent) {
			x += oEl.offsetLeft
			oEl = oEl.offsetParent;
		}
	} else if (oEl.x) { x += oEl.x };
	return x;
}

function FindTedY(oEl,iAdd) {
	var y = String(iAdd) == 'undefined' ? 0 : iAdd;
	if (oEl.offsetHeight) y += oEl.offsetHeight;
	if (oEl.offsetParent) {
		while (oEl.offsetParent) {
			y += oEl.offsetTop
			oEl = oEl.offsetParent;
		}
	} else if (oEl.y) y += oEl.y;
	return y;
}	

function getSrchPos() {
	getHID = document.getElementById('srchAgn');
	newPY  = (FindTedY(getHID)+15)
	if (this.chkBrowser('msie') && this.chkBrowser('mac')) {
		newPY = newPY-295;
	}
	newPY = newPY+'px';
	return newPY;
}
	
function getWidth() {
	var theWidth; 
	if (window.innerWidth) {
		theWidth = window.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		theWidth = document.documentElement.clientWidth;
	} else if (document.body) {
		theWidth = document.body.clientWidth;
	}
	return theWidth; 
}

function getCoords(pObj, pCoordParam) {
	var obj = document.getElementById(pObj);
	if (!obj) { return; }
	var pCoord = pCoordParam.toLowerCase();
	var pCoordParam = 0;
	if (obj.offsetParent) {
		if (pCoord == "y") {
			pCoordParam = obj.offsetTop;
			while (obj = obj.offsetParent) {
				pCoordParam += obj.offsetTop;
			}
		} else {
			pCoordParam = obj.offsetLeft;
			while (obj = obj.offsetParent) {
				pCoordParam += obj.offsetLeft;
			}														
		}													
	}
	return pCoordParam;
}

// FIRES ONLOAD
function setXPos() {
	// chkBrowser() found in ube.js
	getHID   = document.getElementById('blueHeader');
	adB      = document.getElementById('ad');
	getPrc   = document.getElementById('prctip'); // AKA floaty
	newPX    = FindTedX(getHID);
	theWidth = getWidth();
	adjVal   = (theWidth-newPX)/1;	
	//newPYad  = FindTedY(getHID);
	
	// 080417
	if (!document.getElementById('tabs')) {
		newPYad = 40;
	} else {
		newPYad = 0;
	}
		
	// AD
	if (adB) {
		if (chkBrowser('msie') && chkBrowser('mac')) {
			//adB.style.left = (newPX-127)+'px';
			adB.style.left = (newPX-147)+'px'; // 080507
		}
		newPYadNoneSBS = FindTedY(getHID);
		adB.style.left = (newPX-127)+'px';		
		adB.style.top  = (newPYadNoneSBS+5)+'px';
		//adB.style.top  = (newPYad+5)+'px';
	}
	
	if (getPrc) {
		// ADJUST Y POS OF FLOATY IF ERROR MESSAGE ON PAGE
		var ubeMsgAreaHeight = getCoords('flightsWrapper0', 'y');
		
		getPrc.style.top = ubeMsgAreaHeight+newPYad+'px'; // Y POS // org = getPrc.style.top=(newPYad+166)+'px'; //getPrc.style.top = (newPYad+106+ubeMsgAreaHeight)+'px'; // Y POS // org = getPrc.style.top=(newPYad+166)+'px';
		
		if (chkBrowser('msie') && chkBrowser('mac')) {
			if (adjVal > 0 || adjVal == 0) {		
				getPrc.style.left = (newPX-adjVal)-114+'px';
			} else {
				getPrc.style.left='640px';
			}
		} else {
			adjVal = 494; // adjVal=717;
			if (gFloatyPos == "right") { // gFloatyPos, declared inline.
				getPrc.style.left = (newPX-134)+'px';
			} else {
				getPrc.style.left = (newPX-391)+'px'; // X POS // floaty left side = 127 // org = getPrc.style.left=(newPX-127)+'px';
			}
			
		}
		getPrc.style.display = 'block';
	}
	
	if (chkBrowser('msie') && chkBrowser('mac')) {
		if (adjVal > 0 || adjVal == 0) {
			// Nothing
		} else {
			newPX = 762;
		}
	}	
	
	if (getPrc) {
		pXVal = newPX-100;
	} else {
		pXVal = newPX-135;
	}
	
	if (chkBrowser('msie') && chkBrowser('mac')) {
		if (adjVal > 0 || adjVal == 0) {
			PX1Val = ((newPX-adjVal)+19)-643;
			PX2Val = ((newPX-adjVal)+19)-251; //PX2Val=((newPX-adjVal)+19)-382;
		} else {
			PX1Val = 129;
			PX2Val = 390;
		}
	} else {
		PX1Val = newPX-643;
		PX2Val = newPX-251; //PX2Val=newPX-382;
	}
}	

// FIRES ON WINDOW RESIZE 
function getXPos() {
	adB     = document.getElementById('ad');
	getHID  = document.getElementById('blueHeader');
	getPrc  = document.getElementById('prctip'); // AKA floaty
	newPYad = FindTedY(getHID);
	
	if (chkBrowser('msie') && chkBrowser('mac')) {
		rsz = 1;
		setXPos();
	} else {
		// repos for all others
		rsz      = 1;
		theWidth = getWidth();
		newPX    = FindTedX(getHID);
		
		// AD
		if (adB) {
			adB.display = 'none';
			adB.style.left = (newPX-127)+'px';
		}
		
		if (getPrc) {
			pXVal = newPX-100;
		} else {
			pXVal = newPX-135;
		}
		
		PX1Val = newPX-643;
		PX2Val = newPX-251; // PX2Val=newPX-382;
		
		if (getPrc) {
			adjVal = 494; // adjVal=717;
			if (gFloatyPos == "right") { // gFloatyPos, declared inline.
				getPrc.style.left = (newPX-134)+'px';
			} else {
				getPrc.style.left = (newPX-391)+'px'; // X POS // floaty left side = 127 // org = getPrc.style.left=(newPX-127)+'px';
			}
		}
	}
}	



