
// 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;
		}
	}
	//SetSelected(cbVendorCategory, cbCruiseVendor, cbShip );
	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;
    }
    catch(e)
    {
        document.getElementById(frame).height = 1600;
    }
}

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;
	strUrl   		+= "?LSID="	+ intShipID;
	strUrl   		+= "&LIID="	+ intItnID;
	strUrl   		+= "&LVID="	+ vndID;
	strUrl   		+= "&LSNO="	+ sailingNumber;
	strUrl   		+= "&DF="	+ depFrom;
	strUrl   		+= "&DT="	+ depTo;
	
	var cbSN	= getElement("LSN");
	var	cbMT	= getElement("LMT");
	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){ }

	strUrl		+= "&LSN="	+ ((cbSN != null)?escape(cbSN.value):''); 
	strUrl		+= "&LMT="	+ ((cbMT != null)?escape(cbMT.value):''); 
	strUrl		+= "&LZP1="	+ ((cbZP1 != null)?escape(cbZP1.value):'');
	strUrl		+= "&LZP2=" + ((cbZP2 != null)?escape(cbZP2.value):'');
	strUrl		+= "&LPC="  + ((cbPC != null)?escape(cbPC.value):'');
	strUrl		+= "&PIN=" + ((cbPIN != null)?escape(cbPIN.value):'');
	strUrl		+= "&Phone=" + ((cbPhone != null)?escape(cbPhone.value):'');
	strUrl		+= "&Home=" + ((cbHome != null)?escape(cbHome.value):'');
	strUrl		+= "&LID="  + ((cbLID != null)?escape(cbLID.value):'');
	strUrl   	+= "&EO="	+ ((cbEO != null)?escape(cbEO.value):''); 
		
	//if(strLayout == '1')
	{
		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 cbZip1		= getElement("Zip1");
		var cbEO		= getElement("EO");
		//var cbZip2		= getElement("Zip2");
		//var cbSkin		= getElement("AG");
	
    	Querystring(null);
		strUrl   += "&CD="	+ ((cbDest != null)?escape(cbDest.value):
		        (Querystring_get('CD', null) != null ? Querystring_get('CD', null) : '-1')  ); 
		strUrl   += "&CL="	+ ((cbLen != null)?escape(cbLen.value):
		        (Querystring_get('CL', null) != null ? Querystring_get('CL', null) : '0|0')  ); 
		strUrl   += "&CV="	+ ((cbVnd != null)?escape(cbVnd.value):
		        (Querystring_get('CV', null) != null ? Querystring_get('CV', null) : '-1')  );
		strUrl   += "&CSP=" + ((cbShp != null)?escape(cbShp.value):
		        (Querystring_get('CSP', null) != null ? Querystring_get('CSP', null) : '-1')  );
		strUrl   += "&CST=" + ((cbSort != null)?escape(cbSort.value):
		        (Querystring_get('CST', null) != null ? Querystring_get('CST', null) :'-1')  ); 
		strUrl   += "&CP="	+ ((cbPort != null)?escape(cbPort.value):
		        (Querystring_get('CP', null) != null ? Querystring_get('CP', null) :'-1')  );
		
		//strUrl   += "&SN="	+ ((cbSenior != null)?escape(cbSenior.checked):'false'); 
		if(cbSenior != null && (cbSenior.checked == 'true' || cbSenior.checked == 'false' ))
		{
			strUrl   += "&SN="	+ ((cbSenior != null)?escape(cbSenior.checked):'false'); 
		}else // drop-down
		{
			strUrl   += "&SN="	+ ((cbSenior != null && cbSenior.value != null)?escape(cbSenior.value):'false');
		}
		
		if(cbMilitary != null && (cbMilitary.checked == 'true' || cbMilitary.checked == 'false' ))
		{
			strUrl   += "&MT="	+ ((cbMilitary != null)?escape(cbMilitary.checked):'false'); 
		}else // drop-down
		{
			strUrl   += "&MT="	+ ((cbMilitary != null && cbMilitary.value != null)?escape(cbMilitary.value):'false');
		}
		if(cbEO != null && (cbEO.checked == 'true' || cbEO.checked == 'false'))
		{
			strUrl   += "&EO="	+ ((cbEO != null)?escape(cbEO.checked):'false'); 
		}
		else // drop-down
		{
			strUrl   += "&EO="	+ ((cbEO != null && cbEO.value != null)?escape(cbEO.value):'false');
		}
		
		
	}
	
	strUrl += "&look=" + (Querystring_get('look', null) != null ? Querystring_get('look', null) : '');
	strUrl += "&template=" + (Querystring_get('template', null) != null ? Querystring_get('template', null) : '');
	strUrl			+= "&AG="	+ skinID;
	
	strUrl		+= "&branch=" + ((cbbranch != null)?escape(cbbranch.value):'');	
    strUrl += "&GroupOnly=" + (Querystring_get('GroupOnly', null) != null ? Querystring_get('GroupOnly', null) : 'false');

	
	
	    
	
	var form1		= getElement("Form1");
	form1.target	= "_self";
	//alert(strUrl);
	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) {}
	
	/*	
	if(hasFrames)
	{
		var frm			= getElement('Form1');
		frm.action		= strUrl;
		frm.target		= "_self";
		frm.submit();
	}else
	{
	*/
		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 != null)
	{
		strLastState = "&";
		strLastState += "LSN=" + cbLSN.value;
	}
	
	var cbLMT		= getElement("LMT");
	if(cbLMT!= null && cbLMT.value != null)
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LMT=" + cbLMT.value;
	}
	
	var cbLZP1		= getElement("LZP1");
	if(cbLZP1 != null && cbLZP1.value != null)
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LZP1=" + cbLZP1.value;
	}
	
	var cbLZP2		= getElement("LZP2");
	if(cbLZP2 != null && cbLZP2.value != null)
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LZP2=" + cbLZP2.value;
	}
	
	var cbLPC		= getElement("LPC");
	if(cbLPC != null && cbLPC.value != null)
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LPC=" + cbLPC.value;
	}

	var cbLCD		= getElement("LCD");
	if(cbLCD != null && cbLCD.value != null)
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LCD=" + cbLCD.value;
	}
	
	var cbLCP		= getElement("LCP");
	if(cbLCP != null && cbLCP.value != null)
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LCP=" + cbLCP.value;
	}
	
	var cbLCL		= getElement("LCL");
	if(cbLCL != null && cbLCL.value != null)
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LCL=" + cbLCL.value;
	}
	
	var cbLDF		= getElement("LDF");
	if(cbLDF != null && cbLDF.value != null)
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LDF=" + cbLDF.value;
	}
	
	var cbLDT		= getElement("LDT");
	if(cbLDT != null && cbLDT.value != null)
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LDT=" + cbLDT.value;
	}
	
	var cbLCV		= getElement("LCV");
	if(cbLCV != null && cbLCV.value != null)
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LCV=" + cbLCV.value;
	}
	
	var cbLCSP		= getElement("LCSP");
	if(cbLCSP != null && cbLCSP.value != null)
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LCSP=" + cbLCSP.value;
	}
	
	var cbLCST		= getElement("LCST");
	if(cbLCST != null && cbLCST.value != null)
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LCST=" + cbLCST.value;
	}
	
	var cbLSO		= getElement("LSO");
	if(cbLSO != null && cbLSO.value != null)
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LSO=" + cbLSO.value;
	}
	
	var cbLRef		= getElement("LRef");
	if(cbLRef != null && cbLRef.value != null)
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LRef=" + cbLRef.value;
	}
	
	var cbLPIN		= getElement("LPIN");
	if(cbLPIN != null && cbLPIN.value != null)
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LPIN=" + cbLPIN.value;
	}
	
	var cbLCC		= getElement("LCompCruises");		
	
	if(cbLCC != null && cbLCC.value != null)
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LCompCruises=" + cbLCC.value;
	}
	
	/* GetQueryString is taking care of it
	var cbPhone		= getElement("LPhone");
	if(cbPhone != null && cbPhone.value != null)
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "Phone=" + cbPhone.value;
	}

	var cbHome		= getElement("LHome");
	if(cbHome != null && cbHome.value != null)
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "Home=" + cbHome.value;
	}
	*/

	var cbLLID		= getElement("LLID");
	if(cbLLID != null && cbLLID.value != null)
	{
		if(strLastState != "")strLastState += "&";
		strLastState += "LLID=" + cbLLID.value;
	}
	
	var cbLEO		= getElement("LEO");
	if(cbLEO != null && cbLEO.value != null)
	{
		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);
}

