var g_currentZone		= -1;
var g_currentMonth		= "";
var g_DateFrom			= "";
var g_DateTo			= "";
var g_currentLength		= "0|0";
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_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 = "";
	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("Seniors",frame);
	var cbMilitary	= getElement("Military",frame);
	var cbEO		= getElement("EO",frame);
	var cbZip1		= getElement("Zip1",frame);
	var cbZip2		= getElement("Zip2",frame);
	var cbPromoCode	= getElement("PromoCode",frame);
	var cbSkin		= getElement("AG",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 DestName = "";
	
	if (cbSkin == null)
	    cbSkin		= getElement("ClientID",frame);
	
	if(cbDest != null)
	{
		for(var idx=0; idx < cbDest.options.length; idx++)
		{
			if(cbDest.options[idx].selected)
			{
				DestName = cbDest.options[idx].innerHTML;
			}
		}
	}
	
	strUrl   += "?Go=1&CD="	+ ((cbDest != null)?escape(cbDest.value):'-1');
		
	if(cbMonth != null)
	{
		strUrl   += "&DF="	+ ((cbMonth != null)?escape(cbMonth.value):'-1'); // escape(cbMonth.value);
	}
	
	strUrl   += "&CL="	+ ((cbLen != null)?escape(cbLen.value):'0|0'); //escape(cbLen.value);
	strUrl   += "&CV="	+ ((cbVnd != null)?escape(cbVnd.value):'-1'); //escape(cbVnd.value);
	strUrl   += "&CSP=" + ((cbShp != null)?escape(cbShp.value):'-1'); //escape(cbShp.value);
	strUrl   += "&CST=" + ((cbSort != null)?escape(cbSort.value):'-1'); //escape(cbSort.value);
	strUrl   += "&CP="	+ ((cbPort != null)?escape(cbPort.value):'-1'); //escape(cbPort.value);

	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   += "&MT="	+ ((cbMilitary != null)?escape(cbMilitary.checked):'false'); //escape(cbShowPort.value);
	strUrl   += "&ZP1="	 + ((cbZip1 != null)?escape(cbZip1.value):''); //escape(cbShowPort.value);
	strUrl   += "&ZP2="	 + ((cbZip2 != null)?escape(cbZip2.value):''); //escape(cbShowPort.value);
	strUrl   += "&PC="	 + ((cbPromoCode != null)?escape(cbPromoCode.value):''); //escape(cbShowPort.value);
	strUrl   += "&AG="	 + ((cbSkin != null)?escape(cbSkin.value):'1'); //escape(cbShowPort.value);
	strUrl   += "&PIN=" + ((cbPIN != null)?escape(cbPIN.value):''); //escape(cbShowPort.value);
	strUrl   += "&Phone=" + ((cbPhone != null)?escape(cbPhone.value):''); //escape(cbShowPort.value);
	strUrl   += "&Home=" + ((cbHome != null)?escape(cbHome.value):''); //escape(cbShowPort.value);cbbranch
	strUrl   += "&LID=" + ((cbLID != null)?escape(cbLID.value):''); //escape(cbShowPort.value);
	strUrl   += "&branch=" + ((cbbranch != null)?escape(cbbranch.value):'');
		
	strUrl	  = strFile + strUrl;
	
	if(strLayout == '1')
	{
		if(strFile.indexOf('cruiseresultspage.aspx') >=0)
		{
			strUrl += CendantState();
		}
		
		if(strFile.indexOf('SailingsResultsPage.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";
	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 cbZip2		= getElement("Zip2");
	var cbPromoCode	= getElement("PromoCode");
	var cbSkin		= getElement("AG");
	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");

	strUrl   += "?Go=1&CD="	+ ((cbDest != null)?escape(cbDest.value):'-1');
		
	if(cbMonth != null)
	{
		strUrl   += "&DF="	+ ((cbMonth != null)?escape(cbMonth.value):'-1'); // escape(cbMonth.value);
	}
	
	strUrl   += "&CL="	+ ((cbLen != null)?escape(cbLen.value):'0|0'); //escape(cbLen.value);
	strUrl   += "&CV="	+ ((cbVnd != null)?escape(cbVnd.value):'-1'); //escape(cbVnd.value);
	strUrl   += "&CSP=" + ((cbShp != null)?escape(cbShp.value):'-1'); //escape(cbShp.value);
	strUrl   += "&CST=" + ((cbSort != null)?escape(cbSort.value):'-1'); //escape(cbSort.value);
	strUrl   += "&CP="	+ ((cbPort != null)?escape(cbPort.value):'-1'); //escape(cbPort.value);
	strUrl   += "&LLF=" + ((cbLLF != null)?escape(cbLLF.value):'0'); //escape(cbLLF.value);
	strUrl   += "&LLT="	+ ((cbLLT != null)?escape(cbLLT.value):'0'); //escape(cbLLT.value);

	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');
	}

	strUrl   += "&ZP1="	 + ((cbZip1 != null)?escape(cbZip1.value):''); //escape(cbShowPort.value);
	strUrl   += "&ZP2="	 + ((cbZip2 != null)?escape(cbZip2.value):''); //escape(cbShowPort.value);
	strUrl   += "&PC="	 + ((cbPromoCode != null)?escape(cbPromoCode.value):''); //escape(cbShowPort.value);
	strUrl   += "&AG="	 + ((cbSkin != null)?escape(cbSkin.value):'1'); //escape(cbShowPort.value);
	strUrl   += "&PIN=" + ((cbPIN != null)?escape(cbPIN.value):''); //escape(cbShowPort.value);
	strUrl   += "&Phone=" + ((cbPhone != null)?escape(cbPhone.value):''); //escape(cbShowPort.value);
	strUrl   += "&Home=" + ((cbHome != null)?escape(cbHome.value):''); //escape(cbShowPort.value);
	strUrl   += "&LID=" + ((cbLID != null)?escape(cbLID.value):''); //escape(cbShowPort.value);
	strUrl   += "&ClientID=" + ((cbClientID != null)?escape(cbClientID.value):'');
	strUrl   += "&LVID="	 + ((cbLVID != null)?escape(cbLVID.value):'');
	strUrl   += "&LSID="	 + ((cbLSID != null)?escape(cbLSID.value):'');
	strUrl   += "&LSNO="	 + ((cbLSNO != null)?escape(cbLSNO.value):'');
	strUrl   += "&LDF="		 + ((cbLDF != null)?escape(cbLDF.value):'');
	strUrl   += "&LDT="		 + ((cbLDT != null)?escape(cbLDT.value):'');
	strUrl   += "&LIID="	 + ((cbLIID != null)?escape(cbLIID.value):'');
	strUrl   += "&AGS="		 + ((cbAGS != null)?escape(cbAGS.value):'');
	strUrl   += "&SORTFLD="	 + cabin;
	strUrl   += "&SORTDIR="	 + direction;
	strUrl   += "&Sailings=" + ((cbSailings != null)?escape(cbSailings.value):'');
	document.location.href  = strUrl;
	
} 

///
///
///
///
function CendantState()
{
	var strUrl = "";
	
	var cbLSN	= getElement("LSN");
	var	cbLMT	= getElement("LMT");
	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");
		
	strUrl   += "&LSN="		+ ((cbLSN != null)?escape(cbLSN.value):'');
	strUrl   += "&LMT="		+ ((cbLMT != null)?escape(cbLMT.value):''); 
	strUrl   += "&LZP1="	+ ((cbLZP1 != null)?escape(cbLZP1.value):''); 
	strUrl   += "&LZP2="	+ ((cbLZP2 != null)?escape(cbLZP2.value):'');
	strUrl   += "&LPC="		+ ((cbLPC != null)?escape(cbLPC.value):'');
	strUrl   += "&LCD="		+ ((cbLCD != null)?escape(cbLCD.value):'');
	strUrl   += "&LCP="		+ ((cbLCP != null)?escape(cbLCP.value):''); 
	strUrl   += "&LDF="		+ ((cbLDF != null)?escape(cbLDF.value):''); 
	strUrl   += "&LDT="		+ ((cbLDT != null)?escape(cbLDT.value):''); 
	strUrl   += "&LCL="		+ ((cbLCL != null)?escape(cbLCL.value):''); 
	strUrl   += "&LCV="		+ ((cbLCV != null)?escape(cbLCV.value):'');
	strUrl   += "&LCSP="	+ ((cbLCSP != null)?escape(cbLCSP.value):'');
	strUrl   += "&LCST="	+ ((cbLCST != null)?escape(cbLCST.value):'');
	strUrl   += "&LSO="		+ ((cbLSO != null)?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 cbZP1	= getElement("LZP1");
	var cbZP2	= getElement("LZP2");
	var cbPC	= getElement("LPC");
		
	strUrl   += "&LIID="	+ ((cbIID != null)?escape(cbIID.value):'');
	strUrl   += "&LVID="	+ ((cbVID != null)?escape(cbVID.value):'');
	strUrl   += "&LSID="	+ ((cbSID != null)?escape(cbSID.value):''); 
	strUrl   += "&LSNO="	+ ((cbSNO != null)?escape(cbSNO.value):''); 
	strUrl   += "&LDF="		+ ((cbDF != null)?escape(cbDF.value):'');
	strUrl   += "&LDT="		+ ((cbDT != null)?escape(cbDT.value):'');
	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):''); 
	
	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);
	
	/*var oOption							= new Option(showAll, "")
	cbDate.options[cbDate.length]		= oOption;
	oOption								= new Option(showAll, "0|0")
	cbDate.options[cbLength.length]	= oOption;*/
			
	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, '6|9');
			}else
			{
				setDefaultSelection(cbLength, '0|0');
			}
			break;
		}
	}
	setDefaultSelection(cbLength, g_currentLength);	
}

//
//
//
//
function GetQueryString(isRadioSortCruises)
{
	var strQueryString = "";
	// Destination
	var cbDest		= getElement("ZoneDropDown");
	
	if(cbDest != null && cbDest.value != null)
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "CD=" + cbDest.value;
	}
	//Date
	var	cbMonth		= getElement("DateDropDown");
	if(cbMonth != null && cbMonth.value != null)
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "DF=" + cbMonth.value;
	}
	// Cruise Length
	var cbLen		= getElement("LenDropDown");
	if(cbLen != null && cbLen.value != null)
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "CL=" + cbLen.value;
	}
	//Vendor drop down
	var cbVnd		= getElement("VndDropDown");
	if(cbVnd != null && cbVnd.value != null)
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "CV=" + cbVnd.value;
	}
	//Ships Drop Down
	var cbShp		= getElement("ShipsDropDown");
	if(cbShp != null && cbShp.value != null)
	{
		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 != null)
		{
			if(strQueryString != "")strQueryString += "&";
			strQueryString += "CST=" + cbSort.value;
		}
	}
	
	//Port drop down
	var cbPort		= getElement("PortDropDown");
	if(cbPort != null && cbPort.value != null)
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "CP=" + cbPort.value;
	}
	//Seniors
	var cbSenior	= getElement("Seniors");
	if(cbSenior != null && cbSenior.value != null)
	{
	    // Cheap tickets : Special case
	    if( cbSenior.value != null && (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("Military");
	if(cbMilitary != null && cbMilitary.value != null)
	{
	    // Cheap tickets : Special case
	    if( cbMilitary.value != null && (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;
		}
	}
	
	// Zip1
	var cbZip1		= getElement("Zip1");
	if(cbZip1 != null && cbZip1.value != null)
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "ZP1=" + cbZip1.value;
	}
	// Zip2
	var cbZip2		= getElement("Zip2");
	if(cbZip2 != null && cbZip2.value != null)
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "ZP2=" + cbZip2.value;
	}

	// PromoCode
	var cbPromoCode		= getElement("PromoCode");
	if(cbPromoCode != null && cbPromoCode.value != null)
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "PC=" + cbPromoCode.value;
	}

	//Skin
	var cbSkin		= getElement("AG");
	if(cbSkin != null && cbSkin.value != null)
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "AG=" + cbSkin.value;
	}else
	{
		cbSkin		= getElement("ClientID");
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "AG=" + cbSkin.value;
	}
	
	//PIN
	var cbPIN		= getElement("PIN");
	if(cbPIN != null && cbPIN.value != null)
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "PIN=" + cbPIN.value;
	}
	
	//Phone
	var cbPhone		= getElement("Phone");
	if(cbPhone != null && cbPhone.value != null)
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "Phone=" + cbPhone.value;
	}
	
	//Home
	var cbHome		= getElement("Home");
	if(cbHome != null && cbHome.value != null)
	{
		if(strQueryString != "")strQueryString += "&";
		strQueryString += "Home=" + cbHome.value;
	}
	
	//LID
	var cbLID		= getElement("LID");
	if(cbLID != null && cbLID.value != null)
	{
		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);
	strQueryString += "&look=" + (Querystring_get('look', null) != null ? Querystring_get('look', null) : '');
	strQueryString += "&template=" + (Querystring_get('template', null) != null ? Querystring_get('template', null) : '');
	strQueryString += "&GroupOnly=" + (Querystring_get('GroupOnly', null) != null ? Querystring_get('GroupOnly', 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 (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 stateObj		= getElement('__STATE');
	var strQueryString	= GetQueryString(isRadioSortCruises);
	//stateObj.value		= strQueryString;
	
	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;
	}
} 
