/////////////////////////////////////////////////////
//	The file contains scripts used across various
//	pages in AEV
//	Created on 05 March 2009
//	@author: TCS
/////////////////////////////////////////////////////

var childwindow=null;
/**
 * This function is used to show
 * pop ups. Default window size is 600 x 400
 */

function popUp(page,width,height,windowName,options){

	
	
	if( width == null ){
		width = 600;
	}
	if( height == null ){
		height = 400;
	}
	if( windowName == null ){
		windowName = '_target';
	}
	if( options == null ){
		options = 'left=0,top=0,scrollbars=yes,resizable=yes';
	}
	
	   if(windowName!=null && windowName=="hinfo"){
	    //window.open('/aev/pages/static/Load.html',windowName,'width=' + width + ',height=' + height + ','+options);
	   }
		childwindow=window.open(page,windowName,'width=' + width + ',height=' + height + ','+options);	
		childwindow.focus();	
		

}

/**
 * find cursor position
 * @param obj
 * @return
 */
function getPosition(obj) {
	var curleft = curtop = 0;
	if (obj && obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

/**
 * Redirect to sso when clicking the 'check point balance' link
 * in the MR Box
 * @param url
 * @return
 */
function callSSO(url){

	var source="";
	if($("#atbsource").val()!=null && "undefined"!=typeof($("#atbsource").val()) ){
		source=$("#atbsource").val();
	}

	url=url+"?source="+source;
	document.location.href=url;


	}

/**
 * Redirect to sso when the user login from Availability,Summary & Confirmation by
 * clicking Login link comes in the My Trips Alert box (Breadcrumb.jsp)
 *
 * @param url
 * @param pSource
 * @return
 */
function callSSOFromMyTrips(url){
	// if the pSource is mytrips, it will redirect to My Trip Home page after successful login
	// in other case, we are not passing this argument.It's only for My Trips
	var requestFor = document.forms['dataform'].requestFor.value;           // [Possible values are LT (Load Trips) & ST (Save Trip)]
	var pSource = document.forms['dataform'].source.value;
	
	if(requestFor == "undefined" || requestFor == null || requestFor == "null" || requestFor == ""){
		url=url+"?source="+pSource;
	}else{
		url=url+"?source="+pSource+"_"+requestFor;
	}	
	document.location.href=url;
}

/**
 * Sets Hotel ratings link
 */
function setHotelRatingsURL(){
	$("SPAN").find("#ratingLink").each(function(i) {
		$(this).css( 'cursor','pointer' );
		$(this).click( function(){
			popUp('/aev/pages/static/Ratings.html',600,450,'hotelRating','menubar=no,toolbar=no,resizable=0');
		});
	});
}


/**
 * Shows hotel information page.This method is called from FH page,Summary & Confirmation
 * @param idx hc
 */
function goToHotelInfo(hc,dc){
	document.dataform.hCode.value = hc;
	var actionUrl = '/aev/hotelinfo.action';
	
	var pUrl = '/aev/pages/static/Load.html?'
	+ 'dCode=' + dc
	+ '&hCode=' + hc;
	
	
   popUp(pUrl,825,600,"hinfo");

}