
// Javascript for Netscape
var arrAllVendors		= null;
var cookieDays			= 90;
var CruiseSearchStatus;

/***************************************************
*
*
***************************************************/
function GoDiscovery(strUrl)
{
	if(parent != null)
	{
		parent.document.location = strUrl;
	}else
	{
		document.location = strUrl;
	}
}

/***************************************************
*
*
***************************************************/
function SetSelected(cbVendorCategory, cbCruiseVendor, cbShip )
{
	//set selected options
	if(g_currentCategory==-1)
	{
		cbVendorCategory.options[0].selected=true;
	}else
	{
		for(var idx1=0;idx1<cbVendorCategory.options.length;idx1++)
		{
			if(cbVendorCategory.options[idx1].value==g_currentCategory)
			{
				cbVendorCategory.options[idx1].selected=true;
				break;
			}
		}		
	}
	
	if(g_currentVendor==-1)
	{
		cbCruiseVendor.options[0].selected=true;
	}else
	{
		for(var idx2=0;idx2<cbCruiseVendor.options.length;idx2++)
		{
			if(cbCruiseVendor.options[idx2].value==g_currentVendor)
			{
				cbCruiseVendor.options[idx2].selected=true;
				break;
			}
		}
	}
	
	if(g_currentShip==-1)
	{
		cbShip.options[0].selected=true;
	}else
	{
		for(var idx3=0;idx3<cbShip.options.length;idx3++)
		{
			if(cbShip.options[idx3].value==g_currentShip)
			{
				cbShip.options[idx3].selected=true;
				break;
			}
		}
	}
}

/***************************************************
*
*
***************************************************/
function LoadRoyalOlympiaCombos(cbVendorCategory, cbCruiseVendor, cbShip, caller)
{
	var arrCategories = eval('ArrayCategoryObjects'); //get ahold of combo data
	if(arrCategories==null)
	{
		return;
	}

	var vendorsArr = null;
	for(var i = 0; i < arrCategories.length; i++)
	{
		if(arrCategories[i].ID == g_currentCategory)
		{
			vendorsArr = arrCategories[i].VendorArray;
			break;
		}
	}
	if(vendorsArr==null)
	{
		alert('cannot find any vendors for category' + g_currentCategory);
		return;
	}
	
	for(var j=0;j<vendorsArr.length;j++)
	{
		if(vendorsArr[j].ID == g_currentVendor)
		{
			var arrShips = vendorsArr[j].ShipArray;
			FillCombo2(cbShip, arrShips);
			break;
		}
	}
	for(var idx3=0;idx3<cbShip.options.length;idx3++)
	{
		if(cbShip.options[idx3].value==g_currentShip)
		{
			cbShip.options[idx3].selected=true;
			break;
		}
	}
}

/***************************************************
*
*
***************************************************/
function OnRoyalStartupLoad(ShipID)
{	
	var cbShip		= null;
	cbShip			= getElement(ShipID);
	LoadRoyalOlympiaCombos(null, null, cbShip, 'OnRoyalStartupLoad');
}

/***************************************************
*
*
***************************************************/
function AddNewElement(arrObjects, object)
{
	var found = false;
	for(var idx=0; idx < arrObjects.length; idx++)	
	{
		if(arrObjects[idx].ID == object.ID)
		{
			found = true;
			return;
		}
	}
	
	arrObjects[arrObjects.length] = object;
	return arrObjects;
}

var newwindow;
			
/***************************************************
*
*
***************************************************/
function poptastic(url, width, height)
{
	newwindow=window.open(url,'name','height='+height+ ',width='+width+',resizable=0,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}

function adjustHeight(frame)
{
    try 
    {
        document.getElementById(frame).height = document.getElementById(frame).contentWindow.document.body.scrollHeight + 30;
    }
    catch(e)
    {
        document.getElementById(frame).height = 1700;
    }
}

function adjustFrameHeightFromChild(frame)
{
    try 
    {
        if (window.parent.document.getElementById(frame) != null)
            window.parent.document.getElementById(frame).height = window.parent.document.getElementById(frame).contentWindow.document.body.scrollHeight;
    }
    catch(e)
    {
        if (window.parent.document.getElementById(frame) != null)
            window.parent.document.getElementById(frame).height = 1600;
    }
}

function doscroll()
{
try
{
parent.window.scroll(0,0);
}
catch(err)
{
}
}
/***************************************************
*
*
***************************************************/

      
 
    
function CruiseDetails(strFile, intShipID, intItnID, depFrom, depTo, vndID, sailingNumber, skinID, strLayout)
{
	var strUrl		= strFile;
	if(intShipID != null && intShipID!='')
	{
	    var arrURL=strUrl.split('?');
	    if(arrURL.length==1)
	    strUrl += "?LSID="+intShipID;
	    else
	    strUrl += "&LSID="+intShipID;
	}
	if(intItnID != null && intItnID!='')
	{
	    var arrURL=strUrl.split('?');
	    if(arrURL.length==1)
	    strUrl += "?LIID="+intItnID;
	    else
	    strUrl += "&LIID="+intItnID;
	}
	if(vndID != null && vndID!='')
	{
	    var arrURL=strUrl.split('?');
	    if(arrURL.length==1)
	    strUrl += "?LVID="+vndID;
	    else
	    strUrl += "&LVID="+vndID;
	}
	if(sailingNumber != null && sailingNumber!='')
	{
	    var arrURL=strUrl.split('?');
	    if(arrURL.length==1)
	    strUrl += "?LSNO="+sailingNumber;
	    else
	    strUrl += "&LSNO="+sailingNumber;
	}
	if(depFrom != null && depFrom!='')
	{
	    var arrURL=strUrl.split('?');
	    if(arrURL.length==1)
	    strUrl += "?DF="+depFrom;
	    else
	    strUrl += "&DF="+depFrom;
	}
	if(depTo != null && depTo!='')
	{
	    var arrURL=strUrl.split('?');
	    if(arrURL.length==1)
	    strUrl += "?DT="+depTo;
	    else
	    strUrl += "&DT="+depTo;
	}
	
	
	var cbSN	= getElement("LSN");
	var	cbMT	= getElement("LMT");
	var	cbPP	= getElement("LPP");
	var cbZP1	= getElement("LZP1");
	var cbZP2	= getElement("LZP2");
	var cbPC	= getElement("LPC");
	var cbPIN	= getElement("LPIN");
	var cbPhone	= getElement("LPhone");
	var cbHome	= getElement("LHome");
	var cbbranch= getElement("Lbranch");
	var cbLID	= getElement("LLID");
	var cbEO	= getElement("LEO");
	
			
	// inform the parent
	try{
		window.parent.initParams(vndID, intShipID)
	}
	catch(e){ }
    
    if(cbSN != null && cbSN.value!='')
	{
	    var arrURL=strUrl.split('?');
	    if(arrURL.length==1)
	    strUrl += "?LSN="+escape(cbSN.value);
	    else
	    strUrl += "&LSN="+escape(cbSN.value);
	}
	if(cbMT != null && cbMT.value!='')
	{
	    var arrURL=strUrl.split('?');
	    if(arrURL.length==1)
	    strUrl += "?LMT="+escape(cbMT.value);
	    else
	    strUrl += "&LMT="+escape(cbMT.value);
	}
	if(cbPP != null && cbPP.value!='')
	{
	    var arrURL=strUrl.split('?');
	    if(arrURL.length==1)
	    strUrl += "?LPP="+escape(cbPP.value);
	    else
	    strUrl += "&LPP="+escape(cbPP.value);
	}
	if(cbZP1 != null && cbZP1.value!='')
	{
	    var arrURL=strUrl.split('?');
	    if(arrURL.length==1)
	    strUrl += "?LZP1="+escape(cbZP1.value);
	    else
	    strUrl += "&LZP1="+escape(cbZP1.value);
	}
	if(cbZP2 != null && cbZP2.value!='')
	{
	    var arrURL=strUrl.split('?');
	    if(arrURL.length==1)
	    strUrl += "?LZP2="+escape(cbZP2.value);
	    else
	    strUrl += "&LZP2="+escape(cbZP2.value);
	}
	if(cbPC != null && cbPC.value!='')
	{
	    var arrURL=strUrl.split('?');
	    if(arrURL.length==1)
	    strUrl += "?LPC="+escape(cbPC.value);
	    else
	    strUrl += "&LPC="+escape(cbPC.value);
	}
	if(cbPIN != null && cbPIN.value!='')
	{
	    var arrURL=strUrl.split('?');
	    if(arrURL.length==1)
	    strUrl += "?PIN="+escape(cbPIN.value);
	    else
	    strUrl += "&PIN="+escape(cbPIN.value);
	}
	if(cbPhone != null && cbPhone.value!='')
	{
	    var arrURL=strUrl.split('?');
	    if(arrURL.length==1)
	    strUrl += "?Phone="+escape(cbPhone.value);
	    else
	    strUrl += "&Phone="+escape(cbPhone.value);
	}
	if(cbHome != null && cbHome.value!='')
	{
	    var arrURL=strUrl.split('?');
	    if(arrURL.length==1)
	    strUrl += "?Home="+escape(cbHome.value);
	    else
	    strUrl += "&Home="+escape(cbHome.value);
	}
	if(cbLID != null && cbLID.value!='')
	{
	    var arrURL=strUrl.split('?');
	    if(arrURL.length==1)
	    strUrl += "?LID="+escape(cbLID.value);
	    else
	    strUrl += "&LID="+escape(cbLID.value);
	}
	if(cbEO != null && cbEO.value!='')
	{
	    var arrURL=strUrl.split('?');
	    if(arrURL.length==1)
	    strUrl += "?EO="+escape(cbEO.value);
	    else
	    strUrl += "&EO="+escape(cbEO.value);
	}
		
	{
		var cbDest		= getElement("ZoneDropDown");
		var	cbMonth		= getElement("DateDropDown");
		var cbLen		= getElement("LenDropDown");
		var cbVnd		= getElement("VndDropDown");
		var cbShp		= getElement("ShipsDropDown");
		var cbSort		= getElement("SortDropDown");
		var cbPort		= getElement("PortDropDown");
		var cbSenior	= getElement("Seniors");
		var cbMilitary	= getElement("Military");
		var cbPastPassenger	= getElement("PastPassenger");
		var cbZip1		= getElement("Zip1");
		var cbEO		= getElement("EO");
		
    	Querystring(null);
    	if(cbDest != null && cbDest.value!='')
	    {
	        var arrURL=strUrl.split('?');
	        if(arrURL.length==1)
	        strUrl += "?CD="+escape(cbDest.value);
	        else
	        strUrl += "&CD="+escape(cbDest.value);
	    }
	    if(cbLen != null && cbLen.value!='')
	    {
	        var arrURL=strUrl.split('?');
	        if(arrURL.length==1)
	        strUrl += "?CL="+escape(cbLen.value);
	        else
	        strUrl += "&CL="+escape(cbLen.value);
	    }
	    if(cbVnd != null && cbVnd.value!='')
	    {
	        var arrURL=strUrl.split('?');
	        if(arrURL.length==1)
	        strUrl += "?CV="+escape(cbVnd.value);
	        else
	        strUrl += "&CV="+escape(cbVnd.value);
	    }
	    if(cbShp != null && cbShp.value!='')
	    {
	        var arrURL=strUrl.split('?');
	        if(arrURL.length==1)
	        strUrl += "?CSP="+escape(cbShp.value);
	        else
	        strUrl += "&CSP="+escape(cbShp.value);
	    }
	    if(cbSort != null && cbSort.value!='')
	    {
	        var arrURL=strUrl.split('?');
	        if(arrURL.length==1)
	        strUrl += "?CST="+escape(cbSort.value);
	        else
	        strUrl += "&CST="+escape(cbSort.value);
	    }
	    if(cbPort != null && cbPort.value!='')
	    {
	        var arrURL=strUrl.split('?');
	        if(arrURL.length==1)
	        strUrl += "?CP="+escape(cbPort.value);
	        else
	        strUrl += "&CP="+escape(cbPort.value);
	    }
		if(cbSenior != null && (cbSenior.checked == 'true' || cbSenior.checked == 'false' ))
		{
		    var arrURL=strUrl.split('?');
	        if(arrURL.length==1)
	        strUrl += "?SN="+escape(cbSenior.value);
	        else
	        strUrl += "&SN="+escape(cbSenior.value);
			
		}
		else if((cbSenior != null && cbSenior.value != null && cbSenior.value != '')) // drop-down
		{
		    var arrURL=strUrl.split('?');
	        if(arrURL.length==1)
	        strUrl += "?SN="+escape(cbSenior.value);
	        else
	        strUrl += "&SN="+escape(cbSenior.value);
		}
		
		if(cbMilitary != null && (cbMilitary.checked == 'true' || cbMilitary.checked == 'false' ))
		{
		    var arrURL=strUrl.split('?');
	        if(arrURL.length==1)
	        strUrl += "?MT="+escape(cbMilitary.value);
	        else
	        strUrl += "&MT="+escape(cbMilitary.value);
		}
		else if(cbMilitary != null && cbMilitary.value != null && cbMilitary.value != '') // drop-down
		{
		    var arrURL=strUrl.split('?');
	        if(arrURL.length==1)
	        strUrl += "?MT="+escape(cbMilitary.value);
	        else
	        strUrl += "&MT="+escape(cbMilitary.value);
		}
		
		if(cbPastPassenger != null && (cbPastPassenger.checked == 'true' || cbPastPassenger.checked == 'false' ))
		{
		    var arrURL=strUrl.split('?');
	        if(arrURL.length==1)
	        strUrl += "?PP="+escape(cbPastPassenger.value);
	        else
	        strUrl += "&PP="+escape(cbPastPassenger.value);
		}
		else if(cbPastPassenger != null && cbPastPassenger.value != null && cbPastPassenger.value != '') // drop-down
		{
		    var arrURL=strUrl.split('?');
	        if(arrURL.length==1)
	        strUrl += "?PP="+escape(cbPastPassenger.value);
	        else
	        strUrl += "&PP="+escape(cbPastPassenger.value);
		}
		
		if(cbEO != null && (cbEO.checked == 'true' || cbEO.checked == 'false'))
		{
		    var arrURL=strUrl.split('?');
	        if(arrURL.length==1)
	        strUrl += "?EO="+escape(cbEO.value);
	        else
	        strUrl += "&EO="+escape(cbEO.value);
			
		}
		else if((cbEO != null && cbEO.value != null && cbEO.value!='')) // drop-down
		{
		     var arrURL=strUrl.split('?');
	        if(arrURL.length==1)
	        strUrl += "?EO="+escape(cbEO.value);
	        else
	        strUrl += "&EO="+escape(cbEO.value);
			
		}
		
		
	}
	
	if(Querystring_get('look', null) != null)
	{
	    var arrURL=strUrl.split('?');
        if(arrURL.length==1)
        strUrl += "?look="+ Querystring_get('look', null);
        else
        strUrl += "&look="+ Querystring_get('look', null);
	    
	}
	if(Querystring_get('template', null)!=null)
	{
	    var arrURL=strUrl.split('?');
        if(arrURL.length==1)
        strUrl += "?template="+ Querystring_get('template', null);
        else
        strUrl += "&template="+ Querystring_get('template', null);
	    
	}
	if(skinID!=null && skinID!='')
	{
	    var arrURL=strUrl.split('?');
        if(arrURL.length==1)
        strUrl += "?skin="+ skinID;
        else
        strUrl += "&skin="+ skinID;
	    
	}
	if(cbbranch!=null && cbbranch.value!='' && cbbranch.value!=null)
	{
	    var arrURL=strUrl.split('?');
        if(arrURL.length==1)
        strUrl += "?branch="+ escape(cbbranch.value);
        else
        strUrl += "&branch="+ escape(cbbranch.value);
	    
	}
	if(Querystring_get('GroupOnly', null)!=null && Querystring_get('GroupOnly', null)!='')
	{
	    var arrURL=strUrl.split('?');
        if(arrURL.length==1)
        strUrl += "?GroupOnly="+ Querystring_get('GroupOnly', null);
        else
        strUrl += "&GroupOnly="+ Querystring_get('GroupOnly', null);
	    
	}
	
	if(Querystring_get('xml', null) != null)
	{
	    var arrURL=strUrl.split('?');
        if(arrURL.length==1)
        strUrl += "?xml="+ Querystring_get('xml', null);
        else
        strUrl += "&xml="+ Querystring_get('xml', null);   
	}    
	
	if(Querystring_get('vendor', null)!=null)
	{
	    var arrURL=strUrl.split('?');
        if(arrURL.length==1)
        strUrl += "?vendor="+ Querystring_get('vendor', null);
        else
        strUrl += "&vendor="+ Querystring_get('vendor', null);
	}
	
	var form1		= getElement("Form1");
	form1.target	= "_self";
	form1.action	= strUrl;
	form1.submit();
}

function Querystring(qs) { // optionally pass a querystring to parse
    this.params = new Object()
    this.get=Querystring_get
	
    if (qs == null)
	    qs=location.search.substring(1,location.search.length)

    if (qs.length == 0) return

    qs = qs.replace(/\+/g, ' ') //// Turn <plus> back to <space>
    var args = qs.split('&') // parse out name/value pairs separated via &
	
    // split out each name=value pair
    for (var i=0;i<args.length;i++) {
	    var value;
	    var pair = args[i].split('=')
	    var name = unescape(pair[0])

	    if (pair.length == 2)
		    value = unescape(pair[1])
	    else
		    value = name
		
	    this.params[name] = value
    }
}

function Querystring_get(key, default_) {
    // This silly looking line changes UNDEFINED to NULL
    if (default_ == null) default_ = null;
	
    var value = this.params[key]
    if (value == null) 
    {
        if (this.params['L' + key] != null)
            value = this.params['L' + key]
        else
            value=default_;
    }
	
    return value
}

/***************************************************
*
*
***************************************************/
function PageClick(pageNo1, type1, path1)
{
	var strUrl				= path1 + "?PG=" + pageNo1 + "&Ref=PG";
	
	var hasFrames = false;
	try { 
		hasFrames = (parent != null && parent.frames != null && parent.frames[1] != null && parent.location.host == parent.frames[1].location.host);
	} catch(e) {}
	
	
		var strLeftPanelState	= GetQueryString() + "&" + GetLastState();
		strUrl					+= "&" + strLeftPanelState;		
		var frm					= getElement('Form1');
		frm.action				= strUrl;
		frm.target				= "_self";
		frm.submit();
	
}

/***************************************************
*
*
***************************************************/
function GetLastState()
{
	var strLastState = "";
	
	var cbLSN		= getElement("LSN");
	
	if(cbLSN != null && cbLSN.value != '')
	{		
		if(strLastState != "")strLastState += "&";
		strLastState += "LSN=" + cbLSN.value;
	}
	
	var cbLMT		= getElement("LMT");
	if(cbLMT!= null && cbLMT.value != '')
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LMT=" + cbLMT.value;
	}
	
	var cbLPP		= getElement("LPP");
	if(cbLPP != null && cbLPP.value != '')
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LPP=" + cbLPP.value;
	}
	
	var cbLZP1		= getElement("LZP1");
	if(cbLZP1 != null && cbLZP1.value != '')
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LZP1=" + cbLZP1.value;
	}
	
	var cbLZP2		= getElement("LZP2");
	if(cbLZP2 != null && cbLZP2.value != '')
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LZP2=" + cbLZP2.value;
	}
	
	var cbLPC		= getElement("LPC");
	if(cbLPC != null && cbLPC.value != '')
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LPC=" + cbLPC.value;
	}

	var cbLCD		= getElement("LCD");
	if(cbLCD != null && cbLCD.value != '')
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LCD=" + cbLCD.value;
	}
	
	var cbLCP		= getElement("LCP");
	if(cbLCP != null && cbLCP.value != '' && cbLCP.value != '-1')
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LCP=" + cbLCP.value;
	}
	
	var cbLCL		= getElement("LCL");
	if(cbLCL != null && cbLCL.value != '')
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LCL=" + cbLCL.value;
	}
	
	var cbLDF		= getElement("LDF");
	if(cbLDF != null && cbLDF.value != '')
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LDF=" + cbLDF.value;
	}
	
	var cbLDT		= getElement("LDT");
	if(cbLDT != null && cbLDT.value != '')
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LDT=" + cbLDT.value;
	}
	
	var cbLCV		= getElement("LCV");
	if(cbLCV != null && cbLCV.value != '' && cbLCV.value != '-1')
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LCV=" + cbLCV.value;
	}
	
	var cbLCSP		= getElement("LCSP");
	if(cbLCSP != null && cbLCSP.value != '' && cbLCSP.value != '-1')
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LCSP=" + cbLCSP.value;
	}
	
	var cbLCST		= getElement("LCST");
	if(cbLCST != null && cbLCST.value != '')
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LCST=" + cbLCST.value;
	}
	
	var cbLSO		= getElement("LSO");
	if(cbLSO != null && cbLSO.value != '')
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LSO=" + cbLSO.value;
	}
	
	var cbLRef		= getElement("LRef");
	if(cbLRef != null && cbLRef.value != '')
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LRef=" + cbLRef.value;
	}
	
	var cbLPIN		= getElement("LPIN");
	if(cbLPIN != null && cbLPIN.value != '')
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LPIN=" + cbLPIN.value;
	}
	
	var cbLCC		= getElement("LCompCruises");		
	
	if(cbLCC != null && cbLCC.value != '')
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LCompCruises=" + cbLCC.value;
	}	

	var cbLLID		= getElement("LLID");
	if(cbLLID != null && cbLLID.value != '')
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LLID=" + cbLLID.value;
	}
	
	var cbLEO		= getElement("LEO");
	if(cbLEO != null && cbLEO.value != '')
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LEO=" + cbLEO.value;
	}
	
	return strLastState;
}



/***************************************************
*
*
***************************************************/
function Compare(maxCruises)
{
		var frm			= getElement('Form1');
		var elements = document.getElementsByTagName("*");
		var totalCruiseToCompare = 0;
		for (var i=0; i<elements.length; i++)
		{
			if (elements[i] != null && elements[i].id != null && elements[i].id.length > 8)
				if (elements[i].id.substring(0,8) == "Compare_")
					if (elements[i].checked == true)
						totalCruiseToCompare++;
		}
		
		if (totalCruiseToCompare <= 0)
		{
			alert('There are no cruises selected.');
			return;
		}
			
		if (maxCruises != null && maxCruises != undefined)
		{
		    if (totalCruiseToCompare > 5)
		    {
			    alert('Please select 5 or less cruises to compare.');
			    return;
		    }
		}
		else
		{
		    if (totalCruiseToCompare > 6)
		    {
			    alert('Please select 6 or less cruises to compare.');
			    return;
		    }
		}

    	frm.target	= "_self";
		frm.submit();
}

/***************************************************
*
*
***************************************************/
function getFullDate(cbMonthID, cbDayID, cbYearID)
{
	var cbYear	= getElement(cbYearID);
	var cbMonth	= getElement(cbMonthID);
	var cbDay	= getElement(cbDayID);
	
	var date	= new Date();
	var strDate = date.getMonth() + "/" + date.getDate() + "/" + date.getYear();
		
	if(cbMonth != null && cbDay != null && cbYear != null)
	{
		strDate = (parseInt(cbMonth.value) + 1) + "/" + cbDay.value + "/" + cbYear.value;
	}

	return escape(strDate);
}

