function id(name) {
	return document.getElementById(name);
}

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 trim(stringToTrim) {
	return stringToTrim.replace(/^\s*/, '').replace(/\s*$/, '');
}

// getScreenCenterY()
// --------------------------------------------------------------------------------
// Center in visible area
//
function getScreenCenterY() {
	var y = 0;
	y = getScrollOffset() + (getInnerHeight() / 2);
	return (y);
}

function getInnerHeight() {
	var y;
	if (self.innerHeight)
		y = self.innerHeight; // non IE
	else
		y = document.documentElement.clientHeight;
	return (y);
}

function getScrollOffset() {
	var y;
	if (self.pageYOffset)
		y = self.pageYOffset;// non IE
	else
		y = document.documentElement.scrollTop;
	return (y);
}

// displayInfo()
// --------------------------------------------------------------------------------
// Display the universal popup
//
function displayInfo(target, contentTarget, position, addOffset) {

	if (document.getElementById(contentTarget)
			&& document.getElementById("tooltipContent")) {

		document.getElementById("tooltipContent").innerHTML = document
				.getElementById(contentTarget).innerHTML;

		var x = findPosX(target);
		var y = findPosY(target) - 2;
		var rightPos = true;

		if (position == "right") {
			x += 20;
			x += target.offsetWidth;

			if (addOffset)
				x += addOffset;
		} else {
			x -= 20;
			if (addOffset)
				x += addOffset;
			rightPos = false;
		}

		universalPopup(y, x, rightPos);
	}
}

// hideInfo()
// --------------------------------------------------------------------------------
// Hide the universal popup
//
function hideInfo() {
	if (document.getElementById("tooltip")) {
		document.getElementById("tooltip").style.display = 'none';
	}
	if (document.getElementById('messageHolder')) {
		document.getElementById('messageHolder').innerHtml = '';
	}
}

// universalPopup()
// --------------------------------------------------------------------------------
// Display a universal popup on the page
//
function universalPopup(top, left, tip) {

	var x = left;

	document.getElementById("tooltip").style.display = "";

	if (!tip) {
		x -= document.getElementById("tooltip").offsetWidth;
	}

	document.getElementById("tooltip").style.top = top + "px";
	document.getElementById("tooltip").style.left = x + "px";
	document.getElementById('tip').className = (tip) ? 'tipL' : 'tipR';

	setPopupCover("tooltip");
}

// setUniversalPopupCover()
// --------------------------------------------------------------------------------
// If IE, make sure that the popup works on top of pulldowns
//
function setUniversalPopupCover(popupName) {
	if (navigator.appName != "Microsoft Internet Explorer")
		return;

	var popupDiv = document.getElementById(popupName);
	var cov = document.getElementById(popupName + "Cover");
	cov.style.display = "block";
	cov.style.left = popupDiv.style.left;
	cov.style.top = popupDiv.style.top;
	cov.style.width = popupDiv.offsetWidth;
	cov.style.height = popupDiv.offsetHeight;

}

/*******************************************************************************
 * Function: . Input : none Returns : none
 ******************************************************************************/
function setPopupCover() {
	if (navigator.appName != "Microsoft Internet Explorer")
		return;
	var popupDiv = document.getElementById("dapopup");
	var cov = document.getElementById("dapopupcover");
	if (cov == null) {
		cov = document.getElementById("dapopupCover");
	}
	cov.style.display = "block";
	cov.style.left = popupDiv.style.left;
	cov.style.top = popupDiv.style.top;
	cov.style.width = popupDiv.offsetWidth;
	cov.style.height = popupDiv.offsetHeight;
	cov.style.visibility = "visible";
}

/*******************************************************************************
 * Function: to Cover dapopup2 in IE. Input : none Returns : none
 ******************************************************************************/
function setPopupCover2() {
	if (navigator.appName != "Microsoft Internet Explorer")
		return;
	var popupDiv = document.getElementById("dapopup2");
	var cov = document.getElementById("dapopupcover2");
	cov.style.display = "block";
	cov.style.left = popupDiv.style.left;
	cov.style.top = popupDiv.style.top;
	cov.style.width = popupDiv.offsetWidth;
	cov.style.height = popupDiv.offsetHeight;
	cov.style.visibility = "visible";
}

// baggageInfoPopup()
// --------------------------------------------------------------------------------
// Display baggage info box
//
function baggageInfoPopup() {

	exitPopupWin = window
			.open(
					"/common/baggagePopup.jsp",
					'baggage info',
					'scrollbars=auto, resizable=no, toolbar=no, menubar=no, status=no, location=no, left=85, top=20, height=500px, width=650px');
}

if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { // test for MSIE x.x;
	var ieversion = new Number(RegExp.$1) // capture x.x portion and store as
											// a number
	if (ieversion < 9) {
		document.createElement("article");
		document.createElement("footer");
		document.createElement("header");
		document.createElement("nav");
	}

}

//Added for Language selection
function selectLanguage(langId) {
	
	LoadAjaxCallFunction('/home/changeLanguageId.jsp', "newLanguageId=" + langId
					+ "&s=" + sessionId, reloadPage, '');
}

function reloadPage(){	
	var query = window.location.search.substring(1);	
	if(query == ''){
		query = "s="+sessionId;
	}	
	/*var queryVars = getQueryVariable();	
	var query = ''; //
	for(var key in queryVars){
		query += key+"="+queryVars[key]+"&";
	}
	if(query) {
		// add session id
		query += "s="+sessionId;
	}else{
		query = query.replace(/&$/,""); // remove last &
	}	*/
	window.location="?"+query;
	
	
	
}
// get query variables in JSON 
// modification may result in broken js in CMS.
function getQueryVariable() {        
	var query = window.location.search.substring(1);
    var vars = query.split("&");
    var obj = {};
    for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        obj[pair[0]] = pair[1];  
    }
    return obj;				          
}
