
var g_currentItnTmp	= ""; // itinerary template to be displayed if the list of locations is nu
var lastSailingID	= "";
var lastItnColor	= "#000099";

/*
*
*
*/
function setDefaultSelection(cb, defSel)
{
    if (cb != null && cb.options != null)
    {
	    for(var i = 0; i < cb.options.length; i++)
	    {
		    var op = cb.options[i];
		    if(defSel == op.value)
		    {
			    cb.options[i].selected = true;
			    break;
		    }
	    }
	}
}

/*
*
*
*/
function SetDefault(cb, cookieName)
{
	var cookieSel	= getCookie(cookieName);
	for(var i=0; i< cb.length ;i++)
	{
		var oOption			= cb.options[i];
		if(oOption.value	== cookieSel)
		{
			oOption.selected = true;
		}
	}
}

/*
*
*
*/
function MM_openWindow(theURL,winName,features) 
{ //v2.0
    if (currSailingID != '' && currSailingID != null && currSailingID != '-1' )
    {
    	theURL += "&SID=" + currSailingID;
    }
	MM_openBrWindow(theURL, winName, features);
}

function MM_openWindowTemp(theURL, winName, features) 
{ //v2.0
	MM_openBrWindow(theURL, winName, features);	
}

/*
*
*
*/
function MM_findObj(n, d) 
{ //v4.01
	var p,i,x;  
	if(!d) d=document; 
	if((p=n.indexOf("?"))>0&&parent.frames.length) 
	{
		d=parent.frames[n.substring(p+1)].document; 
		n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) 
		x=d.all[n]; 
	
	for (i=0;!x&&i<d.forms.length;i++) 
		x=d.forms[i][n];
		
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
		x=MM_findObj(n,d.layers[i].document);
		
	if(!x && d.getElementById) x=d.getElementById(n); 
	return x;
}
		
/*
*
*
*/
function MM_swapImgRestore() 
{ //v3.0
	var i,x,a=document.MM_sr; 
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) 
	{
		x.src=x.oSrc;
	}
}

/////////////////////////////////////////////////////////////////////////

var cookieDays			= 90;

/////////////////////////////////////////////////////////////////////////

function BuildSearchReferrer(callFromDeals)
{
	if((callFromDeals != null) || 
		(parent.frames != null && parent.frames["mainFrame"] != null))
	{
		try 
		{ 
    		return escape(parent.document.location);
        } 
        catch(e) 
        {
    		return escape(document.location);
        }
	}else
	{
		var url = SendState("cruiseresultspage.aspx", 1, 0, true);
		return escape(url);
	}
}

function TransferToABE(cbeUrl, SailingDate, sailingId, skinId, vendorId, shipId, sz, withAir, is55, mil, zp1, zp2, pc, callFromDeals, csURL, PIN, lid, Phone, Home)
{
    childFrame = window.parent.setSailingInfo(vendorId, shipId, SailingDate, sailingId, pc, is55, mil, zp1, zp2);
}
/*
*
*/
function BookCruise(cbeUrl, sailingID, skinID, vndID, sz, withAir, is55, mil, zp1, zp2, pc, callFromDeals, csURL, PIN, lid, Phone, Home, branch, Resstate, mode)
{
	var resCity = getElement('ResCityDropDown');
	var depCity = getElement('DepCityDropDown');
	var adult	= getElement('AdultDropDown');
	var child	= getElement('ChildrenDropDown');
	var infant	= getElement('InfantDropDown');
	var senior	= getElement('SeniorDropDown');
	
	var vid	= getElement('LVID');
	var iid	= getElement('LIID');
	var sid	= getElement('LSID');
			
	/*
	if(adult != null)
	{
		setCookie("TravTechAdultPax",	adult.value,	cookieDays);
	}
	
	if(child != null)
	{
		setCookie("TravTechChildPax",	child.value,	cookieDays);
	}
	*/
	
	if(depCity != null)	
	{
		setCookie("TravTechDeparture",	depCity.value,  cookieDays);
	}
	
	var depName= "";
	if(depCity != null)
	{
		for(var idx=0; idx < depCity.options.length; idx++)
		{
			if(depCity.options[idx].selected)
			{
				depName = depCity.options[idx].innerHTML;
			}
		}
	}
	if(withAir == 'True' && depCity.value == "")
	{
		getElement('PleaseSelectAirFromLabel').style.display="block";
		getElement('PleaseSelectAirFrom').style.display="block";
		
	}
	else
	{
		var strURL = csURL + "/TestParams.aspx";
		if('true' == withAir || 'True' == withAir)
		{
			
		}
		if(sailingID != null && sailingID != '')
		    strURL += "?sailingid=" + sailingID;
		    
		    		
		if(skinID != null && skinID!='')
		{
		    var arrURL=strURL.split('?');
		    if(arrURL.length==1)
		    strURL += "?skin="+skinID;
		    else
		    strURL += "&skin="+skinID;
		}
		
		strURL += "&SearchReferrer="		+ BuildSearchReferrer(callFromDeals);//escape(document.location);
		if(depCity != null && depCity.value!='' && depCity.value!=null)
		{
		    var arrURL=strURL.split('?');
		    if(arrURL.length==1)
		    strURL += "?dep="+depCity.value;
		    else
		    strURL += "&dep="+depCity.value;
		}
		if(depName != null && depName!='')
		{
		    var arrURL=strURL.split('?');
		    if(arrURL.length==1)
		    strURL += "?depname="+escape(depName);
		    else
		    strURL += "&depname="+escape(depName);
		}
		
		if(Resstate != null && Resstate!='')
		{
		    var arrURL=strURL.split('?');
		    if(arrURL.length==1)
		    strURL += "?res="+escape(Resstate);
		    else
		    strURL += "&res="+escape(Resstate);
		}
		if(adult != null && adult.value != "" && adult.value != null)
		{
		    var arrURL=strURL.split('?');
		    if(arrURL.length==1)
		    strURL += "?ad="+adult.value;
		    else
		    strURL += "&ad="+adult.value;
		}
		if(child != null && child.value != "" && child.value != null)
		{
		    var arrURL=strURL.split('?');
		    if(arrURL.length==1)
		    strURL += "?ch="+child.value;
		    else
		    strURL += "&ch="+child.value;
		}
		if(infant != null && infant.value != "" && infant.value != null)
		{
		    var arrURL=strURL.split('?');
		    if(arrURL.length==1)
		    strURL += "?inf="+infant.value;
		    else
		    strURL += "&inf="+infant.value;
		}
		if(senior != null && senior.value != "" && senior.value != null)
		{
		    var arrURL=strURL.split('?');
		    if(arrURL.length==1)
		    strURL += "?se="+senior.value;
		    else
		    strURL += "&se="+senior.value;
		}
		if(sz != null && sz != "")
		{
		    var arrURL=strURL.split('?');
		    if(arrURL.length==1)
		    strURL += "?sz="+escape(sz);
		    else
		    strURL += "&sz="+escape(sz);
		}
		if(withAir != null && withAir != "")
		{
		    var arrURL=strURL.split('?');
		    if(arrURL.length==1)
		        strURL += "?air=" + withAir;
		    else
		        strURL += "&air=" + withAir;
		}
		if(PIN != null && PIN != "")
		{
		    var arrURL=strURL.split('?');
		    if(arrURL.length==1)
		    strURL += "?PIN="+PIN;
		    else
		    strURL += "&PIN="+PIN;
		}
		if(Phone != null && Phone != "")
		{
		    var arrURL=strURL.split('?');
		    if(arrURL.length==1)
		    strURL += "?Phone="+Phone;
		    else
		    strURL += "&Phone="+Phone;
		}
		if(Home != null && Home != "")
		{
		    var arrURL=strURL.split('?');
		    if(arrURL.length==1)
		    strURL += "?Home="+Home;
		    else
		    strURL += "&Home="+Home;
		}
		if(branch != null && branch != "")
		{
		    var arrURL=strURL.split('?');
		    if(arrURL.length==1)
		    strURL += "?branch="+branch;
		    else
		    strURL += "&branch="+branch;
		}
		if(lid != null && lid != "")
		{
		    var arrURL=strURL.split('?');
		    if(arrURL.length==1)
		    strURL += "?LID="+lid;
		    else
		    strURL += "&LID="+lid;
		}
		if(mode != null && mode != "")
		{
		    var arrURL=strURL.split('?');
		    if(arrURL.length==1)
		    strURL += "?mode="+mode;
		    else
		    strURL += "&mode="+mode;
		}
			
		if('true' == withAir || 'True' == withAir)
		{
			strURL += "&FromSailingsList=True"; //
		}
		
		if(!callFromDeals)
		{
		    if(is55 != null && is55 != "")
	        {
	            var arrURL=strURL.split('?');
	            if(arrURL.length==1)
	            strURL += "?s55="+is55;
	            else
	            strURL += "&s55="+is55;
	        }
		    
			if(mil != null && mil != "")
	        {
	            var arrURL=strURL.split('?');
	            if(arrURL.length==1)
	            strURL += "?mil="+mil;
	            else
	            strURL += "&mil="+mil;
	        }
			
			if(zp1 != null && zp1 != "")
	        {
	            var arrURL=strURL.split('?');
	            if(arrURL.length==1)
	            strURL += "?ZP1="+zp1;
	            else
	            strURL += "&ZP1="+zp1;
	        }
			
			if(zp2 != null && zp2 != "")
	        {
	            var arrURL=strURL.split('?');
	            if(arrURL.length==1)
	            strURL += "?ZP2="+zp2;
	            else
	            strURL += "&ZP2="+zp2;
	        }
			if(pc != null && pc != "")
	        {
	            var arrURL=strURL.split('?');
	            if(arrURL.length==1)
	            strURL += "?PC="+pc;
	            else
	            strURL += "&PC="+pc;
	        }
		}
		else
		{
        	var hotDealsSeniors = getElement('HotDealsSeniors');
        	var hotDealsMilitary = getElement('HotDealsMilitary');
        	
            if(hotDealsSeniors != null && hotDealsSeniors.checked != "")
	        {
	            var arrURL=strURL.split('?');
	            if(arrURL.length==1)
	            strURL += "?s55="+hotDealsSeniors.checked;
	            else
	            strURL += "&s55="+hotDealsSeniors.checked;
	        }
	        
			if(hotDealsMilitary != null && hotDealsMilitary.checked != "")
	        {
	            var arrURL=strURL.split('?');
	            if(arrURL.length==1)
	            strURL += "?mil="+hotDealsMilitary.checked;
	            else
	            strURL += "&mil="+hotDealsMilitary.checked;
	        }
	        
			
		}
		
		if(callFromDeals!=null && callFromDeals!='')
        {
            var arrURL=strURL.split('?');
            if(arrURL.length==1)
            strURL += "?callFromDeals="+callFromDeals;
            else
            strURL += "&callFromDeals="+callFromDeals;
        }
	        						
		
		try 
		{ 
            parent.document.location = strURL;
        }
        catch(e) 
        {
            document.location = strURL;
        }
	}	
}



function LoadPax(strDefAdult, strDefChild, maxPax, minPax)
{
	var adult			= getElement('AdultDropDown');
	var children		= getElement('ChildrenDropDown');
	var infant  		= getElement('InfantDropDown');

	var defAdult		= parseInt(strDefAdult);
	var defChild		= parseInt(strDefChild);

	FillPaxDropDown(adult, maxPax, minPax); // fill adult drop down starting from defAdult
    setDefaultSelection(adult, 2); 
	
	FillPaxDropDown(children, maxPax - 1, 0);

	FillPaxDropDown(infant, maxPax - 1, 0);
				
	
}


function LoadPaxOffline(minPax, maxPax)
{
	var adult			= document.getElementById('AdultDropDown');
    FillPaxDropDown(adult, maxPax, minPax);
    setDefaultSelection(adult, 2); 
}

function OnPaxChange(MaxPax, ChangedControl)
{
	var adult		= getElement('AdultDropDown');
	var children	= getElement('ChildrenDropDown');
	var infant  	= getElement('InfantDropDown');
	
	var selAdult		= parseInt(adult.value);
	var selChild		= children == null ? 0 : parseInt(children.value);
	var selInfant		= infant == null ? 0 : parseInt(infant.value);
	var total			= selAdult + selChild + selInfant;

    if (total > MaxPax)
    {
        var totalOtherPax = 0;
        switch (ChangedControl)
        {
            case 'AdultDropDown':
                totalOtherPax = selChild + selInfant;
        		break;
            case 'ChildrenDropDown':
                totalOtherPax = selAdult + selInfant;
        		break;
            case 'InfantDropDown':
                totalOtherPax = selAdult + selChild;
        		break;
        }

        alert('Maximum ' + MaxPax + ' passengers are allowed on this cruise including adults, children, and infants.');	
    	setDefaultSelection(getElement(ChangedControl), MaxPax - totalOtherPax); 
    }
}

	
function FillPaxDropDown(cb, difPax, index)
{
    if (cb == null)
        return;
        
	for(var i = index; i <= difPax; i++)
	{
		var oOption				= new Option(i, i);
		cb.options[cb.length]	= oOption;
	}
}



