var g_currentZone		= -1;
var g_currentMonth		= "";
var g_DateFrom			= "";
var g_DateTo			= "";
var g_currentLength		= "0999";
var g_currentCategory	= -1;
var g_currentVendor		= -1;
var g_currentShip		= -1;
var g_currentPort		= -1;
var g_currentSort		= 10;
var currMonth			= 0;
var currDay				= 0;
var currYear			= (new Date()).getFullYear();
var g_isSenior			= 'false';
var g_isMilitary		= 'false';
var g_isPastPassenger	= 'false';
var g_Zip1				= '';
var g_Zip2				= '';
var g_PromoCode			= '';

var ShowAllVendors		= true;

/**
*
*/
function Dst(vID, vName, vPorts, vVnd)
{
	this.ID			= vID; 
	this.Name		= vName;
	this.Ports		= vPorts;
	this.Vnd		= vVnd;
}

/**
*
*/
function Port(portID, portName)
{
	this.ID		= portID;
	this.Name	= portName;
}

/**
*
*/
function Vnd(vID, vName, vShipsArray, vMonthsArray)
{
	this.ID			= vID;
	this.Name		= vName;
	this.ShipArray	= vShipsArray;
	this.Months		= vMonthsArray;
}

/**
*
*/
function Shp(vID, vName)
{
	this.ID		=	vID;
	this.Name	=	vName;
}

/**
*
*/
function Sort(sortID, sortName)
{
	this.ID		= sortID;
	this.Name	= sortName;
}

/*
*
*/
function Month(mValue, mText, mDaysArray)
{
	this.ID		= mValue;
	this.Name	= mText;	
	this.days	= mDaysArray;
} 

/*
*
*/
function Day(dValue, dText, dTotal)
{
	this.ID		= dValue;
	this.Name	= dText;
	this.total	= dTotal;
}

/**
*
*
*/
function SortAlphabetically(obj1, obj2)
{
	var Obj1_Name = obj1.Name.toUpperCase();
	var Obj2_Name = obj2.Name.toUpperCase();
	
	if(Obj1_Name < Obj2_Name)
		return -1;
	if(Obj1_Name == Obj2_Name)
		return 0;
	//if(Obj1_Name > Obj2_Name)
		return 1;
}

/**
*
*
*/
function checkNumeric()
{
	if ((event.keyCode<48) || (event.keyCode>57))
	event.keyCode = 0;
}

///<summary>
/// Fill Combo box with a list of items
///</summary>
///<parameter>cb			- DropDown element that should be filled </parameter>
///<parameter>arrayText		- array with text attributes </parameter>
///<parameter>arrayValues	- array with values attributes </parameter>
function FillCombo2(cb, arrayObjects)
{
	if(cb != null && arrayObjects != null)
	{
		for(var i=0; i<arrayObjects.length; i++)
		{
			var oOption				= new Option()
			oOption.label.text		= "<a href='' title='" + arrayObjects[i].Name + " '>" + arrayObjects[i].Name + "</a>"; 
			oOption.value			= arrayObjects[i].ID;
			oOption.text			= arrayObjects[i].Name;
			cb.options[cb.length]	= oOption;
		}
	}
}

//
//
//
//
function setDefaultSelection(cb, defSel) {
	if(cb != null && cb.options != null) {
		for(var i = 0; i < cb.options.length; i++) {
			if(defSel == cb.options[i].value) {
				cb.options[i].selected = true;
				break;
			}
		}
	}
}

/*
*
*
*/
function OnStartupSortLoad(cbSortID) {
	var cbSort = getElement(cbSortID);
	var arrSort	= eval("ArrSortObj");
	if(arrSort != null && arrSort.length > 0) {
		FillCombo2(cbSort, arrSort);
		setDefaultSelection(cbSort, g_currentSort);
	} else
		cbSort.options[cbSort.length] = new Option("Price (Low to High)", 2);
}

//////////////////////////////////////////
//Zone-Port drop down
//////////////////////////////////////////
function OnStartupZonesLoad(ZoneDropDownID, PortDropDownID, allDest) {	
	//alert("Current Zone = " + g_currentZone)
	var cbPortDropDown		= getElement(PortDropDownID);
	var cbZonesDropDown		= getElement(ZoneDropDownID);

	var zonesArray			= eval("ArrDestObj");
	if(allDest == "true")
		cbZonesDropDown.options[cbZonesDropDown.length]	= new Option(allDestinations, "-1");
	
	if(zonesArray != null && zonesArray.length > 0)
		FillCombo2(cbZonesDropDown, zonesArray);
	
	setDefaultSelection(cbZonesDropDown, g_currentZone);
}

/*
*
*
*/
function OnStartupPortLoad(ZonesDropDownID, PortDropDownID)
{
	var cbZonesDropDown		= getElement(ZonesDropDownID);
	var cbPortDropDown		= getElement(PortDropDownID);
	var cbZonesDropDownVal	= cbZonesDropDown.value;
	
	var zonesArray			= eval("ArrDestObj");	
	var portsArray			= eval("ArrPortObj");
	
	var portList			= "";

	if(cbZonesDropDownVal != -1 && cbZonesDropDownVal != -2)
	{
		for(var zoneIdx = 0; zoneIdx < zonesArray.length; zoneIdx++)
		{
			if(zonesArray[zoneIdx].ID == cbZonesDropDownVal)
			{
				portList = zonesArray[zoneIdx].Ports;
				break;
			}
		}
		
		var arrPortID		= portList.split(",");
		var destPortsArr	= new Array();
		if(arrPortID != null && arrPortID.length > 0)
		{
			for(var portIdx=0; portIdx < arrPortID.length; portIdx++)
			{
				for(var k =0; k < portsArray.length; k++)
				{
					if(arrPortID[portIdx] == portsArray[k].ID)
					{
						var port	= new Port(arrPortID[portIdx], portsArray[k].Name);
						destPortsArr[destPortsArr.length] = port;
						break;
					}
				}			
			}
		}
	}
	else
	{
		destPortsArr = portsArray;
	}
	
	ClearCombo(cbPortDropDown);
	var oOption										= new Option(allPorts, "-1")
	cbPortDropDown.options[cbPortDropDown.length]	= oOption;
	destPortsArr.sort(SortAlphabetically);
	FillCombo2(cbPortDropDown, destPortsArr);
	setDefaultSelection(cbPortDropDown, g_currentPort);
}

/**
*
* 
*/
function SortMonth(month1, month2)
{
	var arrMonth1	= month1.ID.split("/");
	var arrMonth2	= month2.ID.split("/");
	
	var varMonth1	= new Date(parseInt(arrMonth1[2]) - 1,parseInt(arrMonth1[0]) - 1,parseInt(arrMonth1[1]) - 1);
	var varMonth2	= new Date(parseInt(arrMonth2[2]) - 1,parseInt(arrMonth2[0]) - 1,parseInt(arrMonth2[1]) - 1);

	if(varMonth1 < varMonth2)
		return -1;
	
	if(varMonth1 == varMonth2)
		return 0;
	
	if(varMonth1 > varMonth2)
		return 1;
}

//////////////////////////////////////////////////
// Vendor-Ship
/////////////////////////////////////////////////

/**
*
*
*/
function OnStartupVndLoad(cbVndID, cbShipID)
{
	var cbVendor	= getElement(cbVndID);
	var cbShip		= getElement(cbShipID);
	
	var vendorsArr = eval("ArrVndObj");
	if(vendorsArr==null)
	{
		alert('Vendors array is NULL');
		return;
	}
	
	//alert("Cb Vendor = " + cbVendor)
	if(cbVendor != null && cbVendor.length == 0)
	{
		if(ShowAllVendors == true || vendorsArr.length==0)
		{
			AddAllOption(cbVendor,	allCruiselines);
		}
	
		FillCombo2	(cbVendor,	vendorsArr);
		setDefaultSelection(cbVendor, g_currentVendor);
	}
	
	OnVndDropDownChange(cbVndID, cbShipID);
	setDefaultSelection(cbShip, g_currentShip);
}

/**
*
*
*/
function OnVndDropDownChange(cbVndID, cbShipID)
{
	var cbVendor	= getElement(cbVndID);
	var cbShip		= getElement(cbShipID);
	
	var vendorsArr = eval("ArrVndObj");
	if(vendorsArr==null)
	{
		alert('Vendors array is NULL');
		return;
	}
		
	ClearCombo(cbShip);
	AddAllOption(cbShip, allShips);
	
	if(cbVendor.value == -1)
	{
		//load all vendors
		var arrShips = new Array();
		for(var j=0;j<vendorsArr.length;j++)
		{
			arrShips = arrShips.concat(vendorsArr[j].ShipArray);
		}
		arrShips.sort(SortAlphabetically);
		FillCombo2(cbShip, arrShips);
	}
	else
	{
		for(var j=0;j<vendorsArr.length;j++)
		{
			if(vendorsArr[j].ID == cbVendor.value)
			{
				var arrShips = vendorsArr[j].ShipArray;
				FillCombo2(cbShip, arrShips);
				break;
			}
		}
	}
}

function OnStartupLenLoad(cbLenID)
{
	var cbLen	= getElement(cbLenID);
	if(cbLen != null)
	{
		setDefaultSelection(cbLen, g_currentLength);
	}
}

//
//
//
function SendState(strFile, target, frame, getStringOnly, params, strLayout)
{
	var strUrl = "?Go=1";
	var cbDest		= getElement("ZoneDropDown", frame);
	var	cbMonth		= getElement("DateDropDown", frame);
	var cbLen		= getElement("LenDropDown",frame);
	var cbVnd		= getElement("VndDropDown",frame);
	var cbShp		= getElement("ShipsDropDown",frame);
	var cbSort		= getElement("SortDropDown",frame);
	var cbPort		= getElement("PortDropDown",frame);
	var cbSenior	= getElement("lfChk55p",frame);
	var cbMilitary	= getElement("lfChkUSM",frame);
	var cbPastPassenger	= getElement("PastPassenger",frame);
	var cbEO		= getElement("EO",frame);
	var cbZip1		= getElement("selResidency",frame);
	var cbZip2		= getElement("Zip2",frame);
	var cbPromoCode	= getElement("txtPromoCode",frame);
	var cbSkin		= getElement("skin",frame);
	
	var cbPIN		= getElement("PIN",frame);
	var cbPhone		= getElement("Phone",frame);
	var cbHome		= getElement("Home",frame);
	var cbbranch	= getElement("branch",frame);
	var cbLID		= getElement("LID",frame);
	var cbBestDeal	= getElement("BestDeal",frame);
	var cbCC    	= getElement("CC",frame);
	
	var DestName = "";
	
	if (cbSkin == null)
	{
	    cbSkin  	= getElement("AG",frame);
	    if (cbSkin == null)
	    {
	        cbSkin  = getElement("ClientID",frame);
	    }
	}
	if (cbSkin != null && cbSkin.value != '')
	{
	    var skinId = escape(cbSkin.value);
	    if (skinId.length == 1)
	    {
	        skinId = "00" + skinId;
	    }
	    else if (skinId.length == 2)
	    {
	        skinId = "0" + skinId;
	    }
	    strUrl += "Skin=" + skinId; 
	}
	
	if(cbDest != null)
	{
		for(var idx = 0; idx < cbDest.options.length; idx++)
		{
			if(cbDest.options[idx].selected)
			{
				DestName = cbDest.options[idx].innerHTML;
			}
		}
	}
	if (cbDest != null && cbDest.value != '')
	{
	    strUrl += "&CD=" + escape(cbDest.value);
	}	
	
	if (cbMonth != null && cbMonth.value != '')
	{
		strUrl += "&DF=" + escape(cbMonth.value);
	}
	
	if (cbLen != null && cbLen.value != '')
	{
	    strUrl += "&CL=" + escape(cbLen.value);
	}
	
	if (cbVnd != null && cbVnd.value != '')
	{
	    strUrl += "&CV=" + escape(cbVnd.value);
	}
	
	if (cbShp != null && cbShp.value != '')
	{
	    strUrl += "&CSP=" + escape(cbShp.value);
	}
	
	if (cbSort != null && cbSort.value != '')
	{
	    strUrl += "&CST=" + escape(cbSort.value);
	}
	
	if (cbPort != null && cbPort.value != '')
	{
	    strUrl += "&CP=" + escape(cbPort.value);
	}

	if (cbSenior != null && (cbSenior.checked == true || cbSenior.checked == false))
	{
		strUrl += "&SN=" + escape(cbSenior.checked); 
	}
	else if (cbSenior != null && cbSenior.value != '') // drop-down
	{
		strUrl += "&SN=" + escape(cbSenior.value);
	}
	
	if (cbMilitary != null && (cbMilitary.checked == true || cbMilitary.checked == false))
	{
		strUrl += "&MT=" + escape(cbMilitary.checked); 
	}
	else if (cbMilitary != null && cbMilitary.value != '')// drop-down
	{
		strUrl += "&MT=" + escape(cbMilitary.value);
	}
	
	if (cbPastPassenger != null && cbPastPassenger.checked == true)
	{
		strUrl += "&PP=Y"; 
	}
	else if (cbPastPassenger != null && cbPastPassenger.value != '') // drop-down
	{
		strUrl += "&PP=" + escape(cbPastPassenger.value);
	}

	if(cbEO != null && (cbEO.checked == true || cbEO.checked == false))
	{
		strUrl += "&EO=" + escape(cbEO.checked); 
	}
	else if (cbEO != null && cbEO.value != '') // drop-down
	{
		strUrl += "&EO=" + escape(cbEO.value);
	}

    if (cbZip1 != null && cbZip1.value != '')
    {
	    strUrl += "&ZP1=" + escape(cbZip1.value); 
	}
		
	if (cbPromoCode != null && cbPromoCode.value != '')
	{
	    strUrl += "&PC=" + escape(cbPromoCode.value); 
	}
		
	if (cbPIN != null && cbPIN.value != '')
	{
	    strUrl += "&PIN=" + escape(cbPIN.value); 
	}
	
	if (cbPhone != null && cbPhone.value != '')
	{
	    strUrl += "&Phone=" + escape(cbPhone.value);
	}
	
	if (cbLID != null && cbLID.value != '')
	{
	    strUrl += "&LID=" + escape(cbLID.value); 
	}
	
	if (cbbranch != null && cbbranch.value != '')
	{
    	strUrl += "&Branch=" + escape(cbbranch.value);
	}
	if (cbBestDeal != null && cbBestDeal.value != '')
	{
    	strUrl += "&BestDeal=" + escape(cbBestDeal.value);
	}	
	if (cbCC != null && cbCC.value != '')
	{
	    strUrl   += "&CC="   + escape(cbCC.value);
	}
	//HOME - Must be the last QS param
	if (cbHome != null && cbHome.value != '')
	{
	    strUrl += "&Home=" + escape(cbHome.value);
	}
		
	strUrl = strFile + strUrl;
	
	if (strLayout == '1')
	{
		if (strFile.indexOf('cruiseresultspage.aspx') >=0)
		{
			strUrl += CendantState();
		}
		
		if (strFile.indexOf('cruisedetails.aspx') >=0)
		{
			strUrl += CendantCruiseState();
		}
	}
	
	if (getStringOnly)
	{
		return strUrl;
	}
	else
	{
		if(target)
		{
			parent.frames[target].location.href  = strUrl;
		}
		else 
		{
		    if(parent)
                document.location.href = (params)?(strUrl + "&" + params):strUrl;
		    else
			    document.location.href  = strUrl;
		}
	}
} 

///
///
///
///
function SendStateHotDeals(cabin, direction)
{
	var strUrl		= "cruisedeals.aspx?Go=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("lfChk55p");
	var cbMilitary	= getElement("lfChkUSM");
	var cbPastPassenger	= getElement("PastPassenger");
	var cbZip1		= getElement("selResidency");
	var cbZip2		= getElement("Zip2");
	var cbPromoCode	= getElement("txtPromoCode");
	var cbSkin		= getElement("skin");
	var cbPIN		= getElement("PIN");
	var cbPhone		= getElement("Phone");
	var cbHome		= getElement("Home");
	var cbLID		= getElement("LID");
	var cbClientID	= getElement("ClientID");	
	var cbLVID		= getElement("LVID");
	var cbLSID		= getElement("LSID");
	var cbLSNO		= getElement("LSNO");	
	var cbLDF		= getElement("LDF");		
	var cbLDT		= getElement("LDT");	
	var cbLLF		= getElement("LLF");	// sailing length from 
	var cbLLT		= getElement("LLT");	// sailing length to 
		
	var cbLIID		= getElement("LIID");	
	var cbAGS		= getElement("AGS");		
	var cbSailings  = getElement("Sailings");
	var cbBestdeal  = getElement("bestdeal");
	var cbCC        = getElement("CC");

    if (cbSkin != null && cbSkin.value != '')
 	{
	    strUrl   += "&Skin="	 + escape(cbSkin.value);
	}
    if (cbDest != null && cbDest.value != '')
	{
	    strUrl += "&CD=" + escape(cbDest.value);
	}
		
	if(cbMonth != null && cbMonth.value != '')
	{
		strUrl   += "&DF="	+ escape(cbMonth.value);
	}
	
	if (cbLen != null && cbLen.value != '')
	{
	    strUrl   += "&CL="	+ escape(cbLen.value);
	}
	
	if (cbVnd != null && cbVnd.value != '')
	{
	    strUrl   += "&CV="	+ escape(cbVnd.value);
	}
	
	if (cbShp != null && cbShp.value != '')
	{
	    strUrl   += "&CSP=" + escape(cbShp.value);
	}
	
	if (cbSort != null && cbSort.value != '')
	{
	    strUrl   += "&CST=" + escape(cbSort.value);
	}
	
	if (cbPort != null && cbPort.value != '')
	{
	    strUrl   += "&CP="	+ escape(cbPort.value);
	}
	
	if (cbLLF != null && cbLLF.value != '')
	{
	    strUrl   += "&LLF=" + escape(cbLLF.value);
	}
	
	if (cbLLT != null && cbLLT.value != '')
	{
	    strUrl   += "&LLT="	+ escape(cbLLT.value);
    }

	if(cbSenior != null && (cbSenior.checked == true || cbSenior.checked == false))
	{
		strUrl   += "&SN="	+ escape(cbSenior.checked); 
	}
	else if (cbSenior != null && cbSenior.value != '') // drop-down
	{
		strUrl   += "&SN="	+ escape(cbSenior.value);
	}
	
	if(cbMilitary != null && (cbMilitary.checked == true || cbMilitary.checked == false))
	{
		strUrl   += "&MT="	+ escape(cbMilitary.checked);
	}
	else ifalse (cbMilitary != null && cbMilitary.value != '') // drop-down
	{
		strUrl   += "&MT="	+ escape(cbMilitary.value);
	}
	
	if(cbPastPassenger != null && cbPastPassenger.checked == true)
	{
		strUrl   += "&PP=Y";
	}
	else ifalse (cbPastPassenger != null && cbPastPassenger.value != '') // drop-down
	{
		strUrl   += "&PP="	+ escape(cbPastPassenger.value);
	}

    if (cbZip1 != null && cbZip1.value != '')
    {
	    strUrl   += "&ZP1="	 + escape(cbZip1.value);
	}
	
	if (cbZip2 != null && cbZip2.value != '')
	{
	    strUrl   += "&ZP2="	 + escape(cbZip2.value);
	}
	
	if (cbPromoCode != null && cbPromoCode.value != '')
	{
	    strUrl   += "&PC="	 + escape(cbPromoCode.value);
	}
		
	if (cbPIN != null && cbPIN.value != '') 
	{
	    strUrl   += "&PIN=" + escape(cbPIN.value);
	}
	
	if (cbPhone != null && cbPhone.value != '')
	{
	    strUrl   += "&Phone=" + escape(cbPhone.value);
	}	
		
	if (cbLID != null && cbLID.value != '') 
	{
	    strUrl   += "&LID=" + escape(cbLID.value);
	}
	
	if (cbClientID != null && cbClientID.value != '')
	{
	    strUrl   += "&ClientID=" + escape(cbClientID.value);
	}
	
	if (cbLVID != null && cbLVID.value != '')
	{
	    strUrl   += "&LVID="	 + escape(cbLVID.value);
	}
	
	if (cbLSID != null && cbLSID.value != '')
	{
	    strUrl   += "&LSID="	 + escape(cbLSID.value);
	}
	
	if (cbLSNO != null && cbLSNO.value != '')
	{
	    strUrl   += "&LSNO="	 + escape(cbLSNO.value);
	}
	
	if (cbLDF != null && cbLDF.value != '')
	{
		strUrl   += "&LDF="		 + escape(cbLDF.value);
	}
	
	if (cbLDT != null && cbLDT.value != '')
	{
	    strUrl   += "&LDT="		 + escape(cbLDT.value);
	}
	
	if (cbLIID != null && cbLIID.value != '')
	{
		strUrl   += "&LIID="	 + escape(cbLIID.value);
	}
	
	if (cbAGS != null && cbAGS.value != '')
	{
	    strUrl   += "&AGS="		 + escape(cbAGS.value);
	}
	
	if (cabin != null || cabin != '')
	{
	    strUrl   += "&SORTFLD="	 + cabin;
	}
		
	if (direction != null || direction != '')
	{
	    strUrl   += "&SORTDIR="	 + direction;
	}
	
	if (cbSailings != null && cbSailings.value != '')
	{
	    strUrl   += "&Sailings=" + escape(cbSailings.value);
	}
	
	if (cbBestdeal != null && cbBestdeal.value != '')
	{
	    strUrl   += "&Bestdeal=" + escape(cbBestdeal.value);
	}
	if (cbCC != null && cbCC.value != '')
	{
	    strUrl   += "&CC=" + escape(cbCC.value);
	}
	//HOME - Must be the last QS param
	if (cbHome != null && cbHome.value != '')
	{
	    strUrl   += "&Home=" + escape(cbHome.value);
	}
	
	document.location.href  = strUrl;
} 

///
///
///
///
function CendantState()
{
	var strUrl = "";
	
	var cbLSN	= getElement("LSN");
	var	cbLMT	= getElement("LMT");
	var	cbLPP	= getElement("LPP");
	var cbLZP1	= getElement("LZP1");
	var cbLZP2	= getElement("LZP2");
	var cbLPC	= getElement("LPC");
	var cbLCD	= getElement("LCD");
	var cbLCP	= getElement("LCP");
	var cbLDF	= getElement("LDF");
	var cbLDT	= getElement("LDT");
	var cbLCL	= getElement("LCL");
	var cbLCV	= getElement("LCV");
	var cbLCSP	= getElement("LCSP");
	var cbLCST	= getElement("LCST");
	var cbLSO	= getElement("LSO");
		
	if (cbLSN != null && cbLSN.value != '')
	{
	    strUrl += "&LSN=" + escape(cbLSN.value);
	}
	
	if (cbLMT != null && cbLMT.value != '')
	{
	    strUrl += "&LMT=" + escape(cbLMT.value);
	}
	
	if (cbLPP != null && cbLPP.value != '')
	{
	    strUrl += "&LPP=" + escape(cbLPP.value);
	}
	
	if (cbLZP1 != null && cbLZP1.value != '')
	{
	    strUrl += "&LZP1=" + escape(cbLZP1.value);
	}
	
	if (cbLZP2 != null && cbLZP2.value != '')
	{
	    strUrl += "&LZP2=" + escape(cbLZP2.value);
	}
	
	if (cbLPC != null && cbLPC.value != '')
	{ 
	    strUrl += "&LPC=" + escape(cbLPC.value);
	}
	
	if (cbLCD != null && cbLCD.value != '') 
	{
	    strUrl += "&LCD=" + escape(cbLCD.value);
	}
	
	if (cbLCP != null && cbLCP.value != '')
	{
	    strUrl += "&LCP=" + escape(cbLCP.value);
	}
	
	if (cbLDF != null && cbLDF.value != '')
	{
	    strUrl += "&LDF=" + escape(cbLDF.value);
	}
	
	if (cbLDT != null && cbLDT.value != '')
	{
	    strUrl += "&LDT=" + escape(cbLDT.value); 
	}
	
	if (cbLCL != null && cbLCL.value != '')
	{
	    strUrl += "&LCL=" + escape(cbLCL.value); 
	}
	
	if (cbLCV != null && cbLCV.value != '')
	{
	    strUrl += "&LCV=" + escape(cbLCV.value);
	}
	
	if (cbLCSP != null && cbLCSP.value != '')
	{
	    strUrl += "&LCSP=" + escape(cbLCSP.value);
	}
	
	if (cbLCST != null && cbLCST.value != '')
	{
	    strUrl += "&LCST=" + escape(cbLCST.value);
	}
	
	if (cbLSO != null && cbLSO.value != '')
	{
	    strUrl += "&LSO=" + escape(cbLSO.value);
	}
	
	return strUrl;
} 

///
///
///
///
function CendantCruiseState()
{
	var strUrl = "";

	var cbIID	= getElement("LIID");
	var cbVID	= getElement("LVID");
	var	cbSID	= getElement("LSID");
	var cbSNO	= getElement("LSNO");
	var cbDF	= getElement("LDF");
	var cbDT	= getElement("LDT");
	var cbSN	= getElement("LSN");
	var cbMT	= getElement("LMT");
	var cbPP	= getElement("LPP");
	var cbZP1	= getElement("LZP1");
	var cbZP2	= getElement("LZP2");
	var cbPC	= getElement("LPC");
	
	if (cbIID != null && cbIID.value != '')
	{	
	    strUrl += "&LIID=" + escape(cbIID.value);
	}
	
	if (cbVID != null && cbVID.value != '')
	{
	    strUrl += "&LVID=" + escape(cbVID.value);
	}
	
	if (cbSID != null && cbSID.value!= '')
	{
	    strUrl += "&LSID=" + escape(cbSID.value);
	}
	
	if (cbSNO != null && cbSNO.value != '')
	{
	    strUrl += "&LSNO=" + escape(cbSNO.value);
	}
	
	if (cbDF != null && cbDF.value != '')
	{
	    strUrl += "&LDF=" + escape(cbDF.value);
	}
	
	if (cbDT != null && cbDT.value != '')
	{
	    strUrl += "&LDT=" + escape(cbDT.value);
	}
	
	if (cbSN != null && cbSN.value != '')
	{
	    strUrl += "&LSN=" + escape(cbSN.value); 
	}
	
	if (cbMT != null && cbMT.value != '')
	{
	    strUrl += "&LMT=" + escape(cbMT.value);
	}
	
	if (cbPP != null && cbPP.value != '')
	{
	    strUrl += "&LPP=" + escape(cbPP.value);
	}
	
	if (cbZP1 != null && cbZP1.value != '')
	{ 
	    strUrl += "&LZP1=" + escape(cbZP1.value);
	}
	
	if (cbZP2 != null && cbZP2.value != '')
	{
	    strUrl += "&LZP2=" + escape(cbZP2.value);
	}
	
	if (cbPC != null && cbPC.value != '')
	{
	    strUrl += "&LPC=" + escape(cbPC.value);
	}
	
	return strUrl;
}

//
//
//
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);
}

//
//
//
function FillDates(cbDateID)
{
	var cbDate	= getElement(cbDateID);
	var dateArr	= eval(ArrDatesObj);
	// problem with sorting 
	dateArr.sort(SortMonth);
		
	FillCombo2(cbDate, dateArr);
	
	if(g_DateFrom != null && g_DateFrom != "")
	{
		var strMonth	= (g_DateFrom.getMonth() == 0)?12:g_DateFrom.getMonth();
		var strYear		= (g_DateFrom.getMonth() == 0)?(g_DateFrom.getFullYear() -1):g_DateFrom.getFullYear();
		var strDefault	= strMonth + "/1/" + strYear;
		setDefaultSelection(cbDate, strDefault);
	}
}

//
//
//
function DateDropDownChanged(cbDateID, cbLenDropDownID, shrink)
{
	var cbDate		= getElement(cbDateID);
	var cbLength	= getElement(cbLenDropDownID);

	var dateArr		= eval(ArrDatesObj);
	var monthsArr	= null;
	var dateSel		= cbDate.value;
	
	if(dateArr  == null || (dateArr != null && dateArr.length==0))
	{
		var oOption							= new Option(showAll, "")
		cbDate.options[cbDate.length]		= oOption;
		oOption								= new Option(showAll, "-1")
		cbLength.options[cbLength.length]	= oOption;
		return;
	}
	
	for(var idx=0; idx < dateArr.length; idx++)
	{
		if(dateArr[idx].ID == cbDate.value)	
		{
			ClearCombo(cbLength);
			FillLengthCombo(cbLength, dateArr[idx].days, shrink);
			if(g_currentZone != "1") 
			{
				setDefaultSelection(cbLength, '0|999');
			}
			break;
		}
	}
	setDefaultSelection(cbLength, g_currentLength);	
}

//
//
//
//
function GetQueryString(isRadioSortCruises)
{
	var strQueryString  = "";
	
	// Destination
	var cbDest		    = getElement("ZoneDropDown");	
	if(cbDest != null && cbDest.value != '')
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "CD=" + cbDest.value;
	}
	//Date
	var	cbMonth		= getElement("DateDropDown");
	if(cbMonth != null && cbMonth.value != '')
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "DF=" + cbMonth.value;
	}
	// Cruise Length
	var cbLen		= getElement("LenDropDown");
	if(cbLen != null && cbLen.value != '')
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "CL=" + cbLen.value;
	}
	//Vendor drop down
	var cbVnd		= getElement("VndDropDown");
	if (cbVnd != null && cbVnd.value != '')
	{
		if (strQueryString != "")strQueryString += "&";
		    strQueryString += "CV=" + cbVnd.value;
	}
	//Ships Drop Down
	var cbShp		= getElement("ShipsDropDown");
	if(cbShp != null && cbShp.value != '')
	{
		if (strQueryString != "")strQueryString += "&";
		    strQueryString += "CSP=" + cbShp.value;
	}
	
	if (isRadioSortCruises != null && isRadioSortCruises == 'true')
	{
		//Sort Radio Buttons
		var rdoSort	= document.Form1.rdoSortCruises;
		if (rdoSort != null && rdoSort.length > 0)
		{
			for (i=0; i < rdoSort.length; i++)
			{
				if (rdoSort[i].checked)
				{
					if(strQueryString != "")strQueryString += "&";
					strQueryString += "CST=" + rdoSort[i].value;
				}
			}
		}
	}
	else
	{
		//Sort Drop Down
		var cbSort		= getElement("SortDropDown");
		if(cbSort != null && cbSort.value != '')
		{
			if(strQueryString != "")strQueryString += "&";
			strQueryString += "CST=" + cbSort.value;
		}
	}
	
	//Port drop down
	var cbPort		= getElement("PortDropDown");
	if(cbPort != null && cbPort.value != '')
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "CP=" + cbPort.value;
	}
	//Seniors
	var cbSenior	= getElement("lfChk55p");
	if(cbSenior != null && cbSenior.value != '')
	{
	    // Cheap tickets : Special case
	    if( cbSenior.value != '' && (cbSenior.value == "true" ||cbSenior.value == "false"))
        {
          if(strQueryString != "")strQueryString += "&";
		  strQueryString += "SN=" + cbSenior.value;
	    }
	    else
	    { // All other Web sites
		  if(strQueryString != "")strQueryString += "&";
		  strQueryString += "SN=" + cbSenior.checked;
		}
	}
	
	//Military
	var cbMilitary	= getElement("lfChkUSM");
	if(cbMilitary != null && cbMilitary.value != '')
	{
	    // Cheap tickets : Special case
	    if( cbMilitary.value != '' && (cbMilitary.value == "true" || cbMilitary.value == "false"))
        {
          if(strQueryString != "")strQueryString += "&";
		  strQueryString += "MT=" + cbMilitary.value;
	    }
	    else
	    { // All other Web sites
		  if(strQueryString != "")strQueryString += "&";
		  strQueryString += "MT=" + cbMilitary.checked;
		}
	}
	
	//PastPassenger
	var cbPastPassenger	= getElement("PastPassenger");
	if(cbPastPassenger != null && cbPastPassenger.value != '')
	{
	    // Cheap tickets : Special case
	    if(cbPastPassenger.value != '' && cbPastPassenger.value == "true")
        {
          if(strQueryString != "")strQueryString += "&";
		  strQueryString += "PP=Y";
	    }
        else if (cbPastPassenger.checked)
	    { // All other Web sites
		  if(strQueryString != "")strQueryString += "&";
		  strQueryString += "PP=Y";
		}
	}
	
	// Zip1
	var cbZip1		= getElement("selResidency");
	if(cbZip1 != null && cbZip1.value != '')
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "ZP1=" + cbZip1.value;
	}
	// Zip2
	var cbZip2		= getElement("Zip2");
	if(cbZip2 != null && cbZip2.value != '')
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "ZP2=" + cbZip2.value;
	}

	// PromoCode
	var cbPromoCode		= getElement("txtPromoCode");
	if(cbPromoCode != null && cbPromoCode.value != '')
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "PC=" + cbPromoCode.value;
	}

	//Skin
	var cbSkin		= getElement("skin");
	if(cbSkin != null && cbSkin.value != '')
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "Skin=" + cbSkin.value;
	}
	else
	{	
	    cbSkin		= getElement("AG");    
		if (cbSkin != null && cbSkin.value != '')
		{
		    if(strQueryString != "")strQueryString += "&";
		    strQueryString += "Skin=" + cbSkin.value;
		}
		else
	    {
	        cbSkin	= getElement("ClientID");
		    if (cbSkin != null && cbSkin.value != '')
		    {
		        if(strQueryString != "")strQueryString += "&";
		        strQueryString += "Skin=" + cbSkin.value;
		    }
	    }
	}	
	
	//PIN
	var cbPIN		= getElement("PIN");
	if(cbPIN != null && cbPIN.value != '')
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "PIN=" + cbPIN.value;
	}
			
	//LID
	var cbLID		= getElement("LID");
	if(cbLID != null && cbLID.value != '')
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "LID=" + cbLID.value;
	}
	
	//Special Offers
	var cbEO		= getElement("EO");
	if(cbEO != null)
	{
		if(cbEO.checked)
		{
			strQueryString += "&EO=true";
		}
		else
		{
			strQueryString += "&EO=false";
		}
	}
	
	Querystring(null);
	
	//Phone
	var cbPhone		= getElement("Phone");
	if(cbPhone != null && cbPhone.value != '')
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "Phone=" + cbPhone.value;
	}
	if (Querystring_get('phone', null) != null && strQueryString.indexOf('Phone=') < 0)
	{
	    strQueryString += "&Phone=" + Querystring_get('phone', null);
	}
	
	if (Querystring_get('look', null) != null)
	{
	    strQueryString += "&Look=" + Querystring_get('look', null);
	}
	
	if (Querystring_get('logo', null) != null && Querystring_get('logo', null) != '0')
	{
	    strQueryString += "&Logo=" + Querystring_get('logo', null);
	}
	 
	if (Querystring_get('template', null) != null) 
	{    
	    strQueryString += "&Template=" + Querystring_get('template', null);
	}
	
	if (Querystring_get('grouponly', null) != null)
	{
	    strQueryString += "&GroupOnly=" + Querystring_get('grouponly', null);
	}
	if (Querystring_get('bestdeal', null) != null)
	{
	    strQueryString += "&BestDeal=" + Querystring_get('bestdeal', null);
	}
	if (Querystring_get('vendor', null) != null)
	{
	    strQueryString += "&Vendor=" + Querystring_get('vendor', null);
	}
	if (Querystring_get('cc', null) != null)
	{
	    strQueryString += "&CC=" + Querystring_get('cc', null);
	}
	
	if (Querystring_get('transitcode', null) != null)
	{
	    strQueryString += "&TransitCode=" + Querystring_get('transitcode', null);
	}
	
	//HOME - Must be the last QS param
	var cbHome		= getElement("Home");
	if(cbHome != null && cbHome.value != '')
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "Home=" + cbHome.value;
	}
	else if (Querystring_get('home', null) != null)
	{
	    strQueryString += "&Home=" + Querystring_get('home', null);
	}
	
	return strQueryString;
}

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 (name == 'home')
        {
            if (pair.length == 2)
		        value = unescape(pair[1])
		    else if (pair.length == 3)
		        value = unescape(pair[1]) + "=" + unescape(pair[2])
        }
	    else 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 ClickGo(strFile, target, isRadioSortCruises)
{
	var strUrl			= strFile;
	var strQueryString	= GetQueryString(isRadioSortCruises);
		
	strUrl += "?Ref=GO&" + strQueryString;
		
	if(target)
	{	
		parent.frames[target].location.href  = strUrl;
	}
	else if(parent)
	{
	    if (document.location.pathname.toLowerCase().indexOf("cruisedeals.aspx") != -1)
	    {
    		document.location.href  = strUrl;
	    }
		else
		    parent.location.href  = strUrl;
	}
	else
	{
		document.location.href  = strUrl;
	}
}
