var isNS4		= (document.layers)? true : false;
var isIE4		= (document.all && !document.getElementById)? true : false;
var isIE5		= (document.all && document.getElementById)? true : false;
var isNS6		= (!document.all && document.getElementById)? true : false;
var popCal;
var popFrame;

//////////////////////////////
var VnDisabledArr = new Array();
var ShipDisabledArr = new Array();
var PortDisabledArr = new Array();
var MonthDisabledArr = new Array();
var LengthDisabledArr = new Array();
var VendorTypeArr = new Array();

var v=0;
var i=0;
var j=0;
var k=0;
var l=0;
var m=0;


      function AddVndItem(DisabledId)
      {        
        VnDisabledArr[i] = DisabledId;
         i++;
      }
      
      function AddShipItem(DisabledId)
      {
        ShipDisabledArr[j] = DisabledId;
         j++;
      }
      
      function AddPortItem(DisabledId)
      {
        PortDisabledArr[k] = DisabledId;
         k++;
      }
      
       function AddMonthItem(DisabledName)
      {
        MonthDisabledArr[l] = DisabledName;
         l++;
      }
   
       function AddLengthItem(DisabledName)
      {
        LengthDisabledArr[m] = DisabledName;
         m++;
      }


      function IsDisabledItem(OptionItem,type)
      {      
        if (type=="Vendor") return Check(VnDisabledArr,OptionItem.value);
        else if (type=="Ship") return Check(ShipDisabledArr,OptionItem.value); 
        else if (type=="Port") return Check(PortDisabledArr,OptionItem.value); 
        else if (type=="Month") return Check(MonthDisabledArr,OptionItem.text); 
        else if (type=="Length") return Check(LengthDisabledArr,OptionItem.value); 		
      }          
     
     function Check(DisabledArr,Id)
     {
         var p=0;
       
         for(p=0;p<DisabledArr.length;p++)
          {
            if( DisabledArr[p] == Id)
            {
                return true;
            }
          }
          
          return false;      
     }
     
     function AssignHid(HidenVar,Hiddata)
     {
        getElement(HidenVar).value = Hiddata;
     }
     
     function KeepSelection(thisObject, Value, Type)
     {        
        var p=0;
        
        //Deselect All
        for(p=0;p<thisObject.options.length;p++)
           thisObject.options[p].selected=false;            
        
        if(Value==undefined || Value==-1) 
        {
            thisObject.options[0].selected=true;
            return;
        }

        for(p=0;p<thisObject.options.length;p++)
        {   
            if(thisObject.options[p].value == Value)
            {
                thisObject.options[p].selected=true;
            }
        }     
       
     }
     
function CompareFrom_TO_Dates(dtdropdown)
{

    try
    {
    //DateDropDown && DateTo
    var FromDate = getElement('DateDropDown').value;
    var ToDate = getElement('DateTo').value;
    
    if(FromDate!= null && ToDate!=null)
    {
      if(dtdropdown == 'fromdate')
      {
         if(Date.parse(ToDate)<Date.parse(FromDate))
            {    
                getElement('DateTo').value = FromDate;
            }
      }
      else if(dtdropdown == 'todate')
       {
            if(Date.parse(FromDate)>Date.parse(ToDate))
           {    
            getElement('DateDropDown').value = ToDate;
            }
       }
     }            
    }
    catch(e)
    {
    }
}
     
function VendorType(VenID, VenTypeID,VenName,VenAvialable)
{
	this.ID		= VenID;
	this.Type	= VenTypeID;	
	this.Name   = VenName;
	this.IsAvialable   = VenAvialable;
}

function AddVendorType(VenID, VenTypeID,VenName,VenAvialable)
{
	var MyVendorType= new VendorType(VenID, VenTypeID,VenName,VenAvialable);
	VendorTypeArr[v] = MyVendorType;
	v++;
}

var MonthArr = new Array();
var q=0;

function Month(MonthId, MonthName,MonthAvialable,MonthDate)
{
	this.ID		= MonthId;
	this.Name   = MonthName;
	this.IsAvialable = MonthAvialable;
	this.Day    =MonthDate;
}


function AddMonth(MonthId,MonthName,MonthAvialable,MonthDate)
{
	var MyMonth= new Month(MonthId,MonthName,MonthAvialable,MonthDate);
	MonthArr[q] = MyMonth;
	q++;
}

function Vendor_Intelligent_Selection()
{
    var VnDrpObj = getElement('VndDropDown');
      var vendtype= getElement('CruiseTypeDropDown').value;
      if(vendtype != -1)
     {
      VnDrpObj.options[0].selected=false;  
      VnDrpObj.options[0].className = "dwDropdownitemDisabled";  
      VnDrpObj.options[0].disabled=true;    
      }   
      else
      {
        VnDrpObj.options[0].selected=true;            
        VnDrpObj.options[0].className = "dwDropdownitemNormal";  
        VnDrpObj.options[0].disabled=false;
        
           for(z=1;z<VnDrpObj.options.length;z++)
           {
                VnDrpObj.options[z].selected=false;  
                if(!Check(VnDisabledArr,VnDrpObj.options[z].value))
                {               
                    VnDrpObj.options[z].className = "dwDropdownitemNormal";    
                     VnDrpObj.options[z].disabled=false;
                }
                else
                {               
                    VnDrpObj.options[z].className = "dwDropdownitemDisabled";   
                    VnDrpObj.options[z].disabled=true;
                }
           }
          
        return;
      }
                      
       for(z=1;z<VnDrpObj.options.length;z++)
       {
            if(!Check(VnDisabledArr,VnDrpObj.options[z].value))
            {
                VnDrpObj.options[z].selected=true;  
                VnDrpObj.options[z].className = "dwDropdownitemNormal";    
                VnDrpObj.options[z].disabled=false; 
            }
            else
            {
                VnDrpObj.options[z].selected=false;  
                VnDrpObj.options[z].className = "dwDropdownitemDisabled";   
                VnDrpObj.options[z].disabled=true;
            }
       }
}

function Month_Intelligent_Selection(DateDropDownId)
{
    var MyMonthObj = getElement(DateDropDownId); //DateDropDown
    var selectedMonth = MyMonthObj.options[MyMonthObj.options.selectedIndex].text;
    var IsDisabledFound=false;
    var IsAssigned=false;
    var h=0;
        
    //forward selection
    for(h=0;h<MonthArr.length;h++)
    {
        if(IsDisabledFound)
        {        
            if(MonthArr[h].IsAvialable=='true')
            {
                var c=0
                for(c=0;c<MyMonthObj.options.length;c++)
                {
                    if(MonthArr[h].Name==MyMonthObj.options[c].text && IsAssigned==false)
                    {                        
                        IsAssigned=true;                   
                        MyMonthObj.options[c].selected=true;  
                        MyMonthObj.options[c].className = "dwDropdownitemNormal";     
                        AssignHid('hidDId',MonthArr[h].Day);                                     
                    }
                }
            }
        }   
       
        if(selectedMonth==MonthArr[h].Name && MonthArr[h].IsAvialable=='false')
        { 
            IsDisabledFound=true; 
        }       
    }
    
    if(IsAssigned) return;
    
     //Backward selection
    for(h=MonthArr.length-1;h>=0;h--)
    {
        if(IsDisabledFound)
        {        
            if(MonthArr[h].IsAvialable=='true')
            {
                var c=0
                for(c=0;c<MyMonthObj.options.length;c++)
                {
                    if(MonthArr[h].Name==MyMonthObj.options[c].text && IsAssigned==false)
                    {
                        IsAssigned=true;                   
                        MyMonthObj.options[c].selected=true;    
                        MyMonthObj.options[c].className = "dwDropdownitemNormal";   
                        AssignHid('hidDId',MonthArr[h].Day);                     
                    }
                }
            }
        }   
        
        if(selectedMonth==MonthArr[h].Name && MonthArr[h].IsAvialable=='false')
        {  
            IsDisabledFound=true; 
        }       
    }
}



function getMyVenIdArrayByType(VType)
{
   var z=0;
   var y=0;
   //var MyArray = new Array();
   var DrpObj = getElement('VndDropDown');
   DrpObj.innerHTML="";
   getElement('ShipsDropDown').innerHTML="";
   
     if(VType==-1)
     {
           DrpObj.options[y]= new Option;
	       DrpObj.options[y].text= "All Cruiselines";
	       DrpObj.options[y].value=-1;
	       DrpObj.options[y].className = "dwDropdownitemNormal";
	       y++;
     }
     
   for(z=0;z<VendorTypeArr.length;z++)
   {
        if(VendorTypeArr[z].Type == VType || VType==9 || VType==-1  )
        {
            DrpObj.options[y]= new Option;
		    DrpObj.options[y].text= VendorTypeArr[z].Name;
		    DrpObj.options[y].value=VendorTypeArr[z].ID;	
		    if( VendorTypeArr[z].IsAvialable=='true')
		    {
		        DrpObj.options[y].className = "dwDropdownitemNormal";
		    }
		    else
		    {
		        DrpObj.options[y].className = "dwDropdownitemDisabled";
		    }
		    y++;		    
        }   
   }   
}

function OnChangeCruiseSort(thisObject, selectAllOptionLevel)
{ 
    getMyVenIdArrayByType(thisObject.options[thisObject.options.selectedIndex].value);
}

///////////////////////////////
var VndTypeClicked=false;
function OnSearchOptionChange(thisObject, selectAllOptionLevel, type, hidId, dtdropdown)
{   
   
    if(IsDisabledItem(thisObject.options[thisObject.options.selectedIndex], type))
    {        
        KeepSelection(thisObject, getElement(hidId).value, type);               
        return;
    } 
  
    if (type == "Month") CompareFrom_TO_Dates(dtdropdown);
    if (type == "VendorType") 
        VndTypeClicked=true;
    else
        VndTypeClicked=false;
    
    try
    {            
        __doPostBack(thisObject.id,'');
        //to adjust left search widget height with results page height
        
        getElement('ZoneDropDown').disabled  = true;            
        getElement('VndDropDown').disabled   = true;            
        getElement('DateDropDown').disabled  = true;
        getElement('LenDropDown').disabled   = true;
        getElement('CruiseTypeDropDown').disabled   = true;
        getElement('PortDropDown').disabled  = true;
        getElement('ShipsDropDown').disabled = true;
        getElement('DateTo').disabled = true;
        getElement('LoadFromDays').disabled = true;
        getElement('LoadToDays').disabled = true;
    }
    catch (e)
    {
    }       
}

function GetSearchWidgetHeight(searchFrame, frame, tableName)
{
    try 
    {
        if (window.parent.document.getElementById(frame) != null)
        {
            if (searchFrame != null && frame != null)
            {
                if (window.parent.document.getElementById(frame).height > 700)
                {
                    window.parent.document.getElementById(searchFrame).height = (window.parent.document.getElementById(frame).height) + "px";
                    var searchframe1 = window.parent.document.getElementById(searchFrame);
                    if (searchframe1.contentDocument)
                    {    // Firefox
                        _obj = searchframe1.contentDocument;
                    }
                    else if (searchframe1.contentWindow)
                    {
                        // Internet Explorer
                        _obj = searchframe1.contentWindow.document;
                    }
                    _obj.getElementById(tableName).style.height = window.parent.document.getElementById(frame).height + "px";
                }
                else
                {
                    window.parent.document.getElementById(searchFrame).height = 700;
                }
            }
        }
        else if (window.parent.document.getElementById(searchFrame) != null)
        {
            window.parent.document.getElementById(searchFrame).height = 1700 + "px";
        }
    }
    catch(e)
    {
        if (window.parent.document.getElementById(frame) != null)
        {
            window.parent.document.getElementById(frame).height = 1700;
            if (searchFrame != null)
            {
                window.parent.document.getElementById(searchFrame).height = 1700;
                var searchframe1 = window.parent.document.getElementById(searchFrame);
                if (searchframe1.contentDocument)
                {    // Firefox
                    _obj = searchframe1.contentDocument;
                }
                else if (searchframe1.contentWindow)
                {
                    // Internet Explorer
                    _obj = searchframe1.contentWindow.document;
                }
                _obj.getElementById(tableName).style.height = 1700 + "px";
            }
        }
        else if (window.parent.document.getElementById(searchFrame) != null)
        {
            window.parent.document.getElementById(searchFrame).height = 1700 + "px";
        }
    }
}

function IncludeOfflineVendorsChanged(thisObject)
{
    __doPostBack(thisObject.id, '');
}

function SendState(strFile, target, isRadioSortCruises)
{
    
	var strUrl = strFile;
	
	var type = strUrl.toString().substring(34);
				
	Querystring(null);
	strUrl += GetQueryStringParams(isRadioSortCruises,type);
	
	if(target == "_childframe")
	{
	    try
	    {
            childFrame = window.parent.getResultFrame();
	        childFrame.src = "/CS/" + strUrl;
	        return;
	    }
	    catch(e)
	    {
	    }
	}
	
	if (Querystring_get('nw', null) == 'true' || target == "_blank")
		window.open(strUrl);
	else
	{
		if (target && target == "_top")
			window.top.location.href = strUrl;
		else if (target && target == "_self")
			window.location.href = strUrl;
		else
			window.parent.location.href = strUrl;
	}
}

function GetQueryStringParams(isRadioSortCruises,type)
{
	var queryString     = "";
	
	//controls
	var cbDest		    = getElement("ZoneDropDown");
	var cbMonth		    = getElement("DateDropDown");
	var cbDateTo	    = getElement("DateTo");
	var cbLen		    = getElement("LenDropDown");
	var cbVnd		    = getElement("VndDropDown");
	
	// optional controls	
	var cbShp		    = getElement("ShipsDropDown");
	var cbPort		    = getElement("PortDropDown");
	var cbSort		    = getElement("SortDropDown");
	var cbSenior	    = getElement("Seniors");
	var cbMilitary	    = getElement("Military");
	var cbZip1		    = getElement("Zip1");
	var cbZip2		    = getElement("Zip2");
	var cbPromoCode	    = getElement("PromoCode");
	var cbPastPassenger	= getElement("PastPassenger");
	
	//hidden
	var cbRef		    = getElement("Ref");
	var cbShowSenior    = getElement("ShowSenior");
	var cbShowMilitary  = getElement("ShowMilitary");
	var cbShowPastPassenger = getElement("ShowPastPassenger");
	var cbEO		    = getElement("EO");
	var cbpsl           = getElement("PSL");
	var DayFrom         = getElement("LoadFromDays");
	var DayTo           = getElement("LoadToDays");
	var multivendor     = "";
	var hidCP           = getElement("vhidden");
    
    if (cbVnd != null)
	{
	    for (var i=0; i<cbVnd.options.length; i++)
	    {
	        if (cbVnd.options[i].selected)
	        {
	            if (multivendor == "")
	                multivendor +=  cbVnd.options[i].value;	
	            else   
	                multivendor += "," + cbVnd.options[i].value;
	        }  
        }
    }
	else if (Querystring_get('cv', null) != null)
	{
	    multivendor = Querystring_get('cv', null);
	}		
	else if (Querystring_get('vid', null) != null)
	{
	    multivendor = Querystring_get('vid', null);
	}
    if (multivendor == "") multivendor = -1;
	
	if (type == 'advanced')
    {
        queryString   += "&";
    }
    else
    {
        queryString   += "?";
    }
	
	var skinId;
	
    if (Querystring_get('skin', null) != null)
    {
        skinId = Querystring_get('skin', null);
    }
    else if (Querystring_get('ag', null) != null)
    {
        skinId = Querystring_get('ag', null);
    }
    else if (Querystring_get('clientid', null) != null)
    {
        skinId = Querystring_get('clientid', null);
    }	
    if (skinId != null && queryString.indexOf("skin=") < 0)
    {
        if (skinId.length == 1)
        {
            queryString   += "skin=00" + skinId;
        }
        else if (skinId.length == 2)
        {
            queryString   += "skin=0" + skinId;
        }
        else
        {
            queryString   += "skin=" + skinId;
        }
    }
		
	if (cbDest != null && cbDest.value != '' && cbDest.value != null)
	{
	    queryString   += "&CD="	+ cbDest.value;
	}
	if (queryString.indexOf('CD=') < 0)
	{
	    if (cbDest != null)
	    {}
	    else if (Querystring_get('did', null) != null)
	    {
	        queryString   += "&CD="   + Querystring_get('did', null);
	    }
	    else if (Querystring_get('cd', null) != null)
	    {
	        queryString   += "&CD="   + Querystring_get('cd', null);
	    }
	}
	
	if (cbMonth != null)
	{
	    queryString   += "&DF=";
	    if (DayFrom != null)
	    {
	        var arrDate = escape(cbMonth.value).split('/');	  	              
	        queryString += arrDate[0] + "/" + escape(DayFrom.value) + "/" + arrDate[2];
	    }
	    else
	    {
	        queryString += escape(cbMonth.value);
	    }
	}
		
	if (cbDateTo != null)
	{
	    queryString   += "&DT=";
	    
	    if (DayTo != null)
	    {
	        var arrDate = escape(cbDateTo.value).split('/');	  	              
	        queryString += arrDate[0] + "/"+ escape(DayTo.value) + "/" + arrDate[2];
	    }
	    else
	        queryString += escape(cbDateTo.value);
	}
	
	if (cbLen != null && cbLen.value != '' && cbLen.value != '0|0')
	{	    
	    queryString   +="&CL="	+ escape(cbLen.value);
	}
	if (queryString.indexOf('CL=') < 0)
	{	
	    if (cbLen != null)
	    {}
	    else if (Querystring_get('cl', null) != null)
	    {
	        queryString   += "&CL="   + Querystring_get('cl', null);
	    }
	    else if (Querystring_get('len', null) != null)
	    {
	        queryString   += "&CL="   + Querystring_get('len', null);
	    }
	}
	
	if (multivendor != -1)
	{
	    queryString   += "&CV=" + multivendor;
	}
	
	if (cbShp != null && cbShp.value != '' && cbShp.value != '-1')
	{	    
	    queryString   += "&CSP=" + escape(cbShp.value);
	}
	if (queryString.indexOf('CSP=') < 0)
	{
	    if (cbShp != null)
	    {}
	    else if (Querystring_get('sid', null) != null)
	    {
	        queryString   += "&CSP="   + Querystring_get('sid', null);
	    }
	    else if (Querystring_get('csp', null) != null)
	    {
	        queryString   += "&CSP="   + Querystring_get('csp', null);
	    }
	    else if (Querystring_get('ships', null) != null && Querystring_get('ships', null).toUpperCase() != 'Y' 
	        && Querystring_get('ships', null).toUpperCase() != 'N')
	    {
	        queryString   += "&CSP="   + Querystring_get('ships', null);
	    }
	}
	
	if (hidCP != null && hidCP.Value != '' && hidCP.value != '-1')
	{
	    queryString   += "&CP="	+ escape(hidCP.value);
	}
	else if (cbPort != null && cbPort.value != '' && cbPort.value != '-1')
	{
        queryString   += "&CP="	+ escape(cbPort.value);
	}
	if (queryString.indexOf('CP=') < 0)
	{
	    if (cbPort != null)
	    {}
	    else if (Querystring_get('pid', null) != null)
	    {
	        queryString   += "&CP="   + Querystring_get('pid', null);
	    }
	    else if (Querystring_get('cp', null) != null)
	    {
	        queryString   += "&CP="   + Querystring_get('cp', null);
	    }
	    else if(Querystring_get('ports', null) != null && Querystring_get('ports', null).toUpperCase() != 'Y' 
	        && Querystring_get('ports', null).toUpperCase() != 'N')
	    {
	        queryString   += "&CP="   + Querystring_get('ports', null);
	    }
	}
	
	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)
        		    queryString   += "&CST=" + rdoSort[i].value;
			}
		}
	}
	else if (cbSort != null && cbSort.value != '' && cbSort.value != '-1')
	{
	    queryString   += "&CST=" + cbSort.value;
	}
	if (queryString.indexOf('CST=') < 0)
	{
	    if (cbSort != null)
	    {}
	    else if (Querystring_get('cst', null) != null) 
	    {
	        queryString   += "&CST="   + Querystring_get('cst', null);
	    }
	    else if (Querystring_get('sort', null) != null && Querystring_get('sort', null).toUpperCase() != 'Y' 
	        && Querystring_get('sort', null).toUpperCase() != 'N')
	    {
	        queryString   += "&CST="   + Querystring_get('sort', null);
	    }
	}	
		
	if (cbSenior != null)
    {	        
        if ((cbSenior.type == "select-one") || (cbSenior.type == "hidden"))
        {
            if (cbSenior.value != null && cbSenior.value != '')
                queryString += "&SN=" + escape(cbSenior.value);
	    }
	    else
	    {
	        queryString += "&SN=" + escape(cbSenior.checked);		    
	    }
	}
	if (queryString.indexOf("SN=") < 0)
    {
        if (cbSenior != null)
        {}
	    else if (Querystring_get('sn', null) != null)
	    {
            queryString   += "&SN=" + Querystring_get('sn', null);
        }
    }

	if (cbMilitary != null)
    {	  
        if ((cbMilitary.type == "select-one") || (cbMilitary.type == "hidden"))
        {
            if (cbMilitary.value != null && cbMilitary.value != '')
                queryString += "&MT=" + escape(cbMilitary.value);
        }		       
        else
        {
	        queryString += "&MT=" + escape(cbMilitary.checked);
	    }
	}
	if (queryString.indexOf("MT=") < 0)
    {
        if (cbMilitary != null)
        {}
	    else if (Querystring_get('mt', null) != null)
	    {
            queryString   += "&MT=" + Querystring_get('mt', null);
        }
	}
	
	if (cbPastPassenger != null)
    {	  
        if ((cbPastPassenger.type == "select-one") || (cbPastPassenger.type == "hidden"))
        {
            if (cbPastPassenger.value != null && cbPastPassenger.value != '')
                queryString += "&PP=" + escape(cbPastPassenger.value);
        }
        else
        {
            queryString += "&PP=" + escape(cbPastPassenger.checked);
        }
    }
    if (queryString.indexOf("PP=") < 0)
    {
        if (cbPastPassenger != null)
        {}
        else if (Querystring_get('pp', null) != null)
        {
            queryString   += "&PP=" + Querystring_get('pp', null);
        }
    }
	
    if (cbZip1 != null && cbZip1.value != '' && cbZip1.value != '-1')
    {   
        queryString   += "&ZP1=" + escape(cbZip1.value);
    }    
    if (queryString.indexOf("ZP1=") < 0)
    {
        if (cbZip1 != null)
        {}
        else if (Querystring_get('zp1', null) != null)
        {
            queryString   += "&ZP1="   + Querystring_get('zp1', null).toUpperCase();
        }
        else if (Querystring_get('st1', null) != null)
        {
            queryString   += "&ZP1="   + Querystring_get('st1', null).toUpperCase();
        }
    }
    
//  TODO: uncomment when ZP2 is used
//	if(cbZip2  != null)
//	{
//	    if(cbZip2.value!='' && cbZip2.value!='-1')
//	    queryString   += "&ZP2="	+ escape(cbZip2.value);
//	}
//	else if(Querystring_get('zp2', null) != null)
//	{
//	    queryString   += "&ZP2="   + Querystring_get('zp2', null);
//	}
	
	if (cbPromoCode != null)
	{
	    if (cbPromoCode.value != '' && cbPromoCode.value != '-1')
	        queryString   += "&PC="	    + escape(cbPromoCode.value);
	}
	if (Querystring_get('pc', null) != null && (cbPromoCode == null) && (queryString.indexOf("PC=") < 0))
	{
	    queryString   += "&PC=" + Querystring_get('pc', null);
	}
	    
    if (Querystring_get('phone', null) != null && (queryString.indexOf("Phone=") < 0))
	{
	    queryString   += "&Phone="   + Querystring_get('phone', null);
	}
    	
	if ((cbEO != null) && (cbEO.type != "select-one"))
	{
	    queryString   += "&EO="	+ escape(cbEO.checked);
	}
	else if (Querystring_get('eo', null) != null)
	{
	    queryString   += "&EO="   + Querystring_get('eo', null);
	}
	
	if  (cbRef  != null)
	{
	    if (cbRef.value != '' && cbRef.value != '-1')
	        queryString   += "&Ref="  + escape(cbRef.value);
	}
	
    if (Querystring_get('pin', null) != null && queryString.indexOf("PIN=") < 0)
	{
	    queryString   += "&PIN="   + Querystring_get('pin', null);
	}
	
	if (Querystring_get('lid', null) != null)
	{
	    queryString   += "&LID="   + Querystring_get('lid', null);
	}
	
	if (Querystring_get('look', null) != null)
	{
	    queryString   += "&look=" + Querystring_get('look', null);
	}

	if (Querystring_get('template', null) != null)
	{
	    queryString   += "&template=" + Querystring_get('template', null);
	}
	
	if (Querystring_get('vendor', null) != null)
	{
	    queryString   += "&vendor=" + Querystring_get('vendor', null);
	}
	
	if (Querystring_get('adv', null) != null)
	{
	    queryString   += "&ADV="   + Querystring_get('adv', null);
	}
	
	if (cbpsl != null && cbpsl.value != '' && cbpsl.value != '-1')
	{
	    queryString   += "&PSL="   + escape(cbpsl.value);
	}
	else if (Querystring_get('psl', null) != null  && Querystring_get('psl', null) != '-1')
	{
	    queryString   += "&PSL="   + Querystring_get('psl', null);
	}	
	
	if (Querystring_get('logo', null) != null && Querystring_get('logo', null) != '0')
	{
	    queryString   += "&logo="   + Querystring_get('logo', null);
	}
	
	if (Querystring_get('branch', null) != null)
	{
	    queryString   += "&branch="   + Querystring_get('branch', null);
	}
	
	if (Querystring_get('ms', null) != null)
    {
        queryString   += "&MS="   + Querystring_get('ms', null);
    }
	    		
	if (Querystring_get('grouponly', null) != null)
	{
	    queryString   += "&GroupOnly="   + Querystring_get('grouponly', null);
	}
    
    if (Querystring_get('xml', null) != null)
	{
	    queryString   += "&xml=" + Querystring_get('xml', null);
	}
	
	if (Querystring_get('bestdeal', null) != null)
	{
	    queryString   += "&bestdeal=" + Querystring_get('bestdeal', null);
	}
	
	if (Querystring_get('so', null) != null)
	{
	    queryString   += "&SO=" + Querystring_get('so', null);
	}
	
	if (Querystring_get('parentag', null) != null)
	{
	    queryString   += "&ParentAG=" + Querystring_get('parentag', null);
	}
	
	if (Querystring_get('pageno', null) != null)
	{
	    queryString   += "&PageNo=" + Querystring_get('pageno', null);
	}
	else if (Querystring_get('pg', null) != null)
	{
	    queryString   += "&PageNo=" + Querystring_get('pg', null);
	}
	
	if (Querystring_get('lcompcruises', null) != null)
	{
	    queryString   += "&CmpCruises=" + Querystring_get('lcompcruises', null);
	}
	else if (Querystring_get('cmpcruises', null) != null)
	{
	    queryString   += "&CmpCruises=" + Querystring_get('cmpcruises', null);
	}

	if (Querystring_get('includeofflinevendors', null) != null)
	{
	    queryString   += "&IncludeOfflineVendors=" + Querystring_get('includeofflinevendors', null);
	}
	
	if (Querystring_get('liid', null) != null)
	{
	    queryString   += "&IID="   + Querystring_get('liid', null);
	}
	else if (Querystring_get('iid', null) != null)
	{
	    queryString   += "&IID="   + Querystring_get('iid', null);
	}
	
	if (Querystring_get('lsno', null) != null)
	{
	    queryString   += "&SNO="   + Querystring_get('lsno', null);
	}
	else if (Querystring_get('sno', null) != null)
	{
	    queryString   += "&SNO="   + Querystring_get('sno', null);
	}
	
	if (Querystring_get('home', null) != null)
	{
	    queryString   += "&Home="   + Querystring_get('home', null);
	} 
    
    return queryString;
}

function SendStatePortSearch(strFile, target)
{
	var strUrl		        = strFile;
	var cbShowSenior        = getElement("ShowSenior");
	var cbShowMilitary      = getElement("ShowMilitary");
	var cbShowPastPassenger = getElement("ShowPastPassenger");
	var cbSenior	        = getElement("Seniors");
	var cbMilitary	        = getElement("Military");
	var cbPastPassenger	    = getElement("PastPassenger");
	var cbVnd		        = getElement("VndDropDown");
	var cbPromoCode	        = getElement("PromoCode");
	var cbMonth             = getElement("DateDropDown");
	var skinId;
	
	Querystring(null);
        
    if (strUrl.indexOf("skin=") < 0)
    {
        if (Querystring_get('skin', null) != null)
        {
            var arrURL = strUrl.split('?');
            if(arrURL.length == 1)
                strUrl += "?skin=" + Querystring_get('skin', null);
            else
                strUrl += "&skin=" + Querystring_get('skin', null);
            skinId = Querystring_get('skin', null);
        }
        else if (Querystring_get('ag', null) != null)
        {
            var arrURL = strUrl.split('?');
            if (arrURL.length == 1)
                strUrl += "?skin=" + Querystring_get('ag', null);
            else
                strUrl += "&skin=" + Querystring_get('ag', null);
            skinId = Querystring_get('ag', null);
        }
        else if (Querystring_get('clientid', null) != null)
        {
            var arrURL = strUrl.split('?');
            if (arrURL.length == 1)
                strUrl += "?skin=" + Querystring_get('clientid', null);
            else
                strUrl += "&skin=" + Querystring_get('clientid', null);
            skinId = Querystring_get('clientid', null);
        }
    }
	
	if (Querystring_get('pin', null) != null && strUrl.indexOf("PIN=") < 0)
	{
	    var arrURL = strUrl.split('?');
	    if (arrURL.length == 1)
	        strUrl += "?PIN=" + Querystring_get('pin', null);
	    else
	        strUrl += "&PIN=" + Querystring_get('pin', null);
	}
	
	if (Querystring_get('phone', null) != null && strUrl.indexOf("Phone=") < 0)
	{
	    var arrURL = strUrl.split('?');
	    if (arrURL.length == 1)
	        strUrl += "?Phone=" + Querystring_get('phone', null);
	    else
	        strUrl += "&Phone=" + Querystring_get('phone', null);
	}
		
	if (Querystring_get('lid', null) != null)
	{
	    var arrURL = strUrl.split('?');
	    if (arrURL.length == 1)
	        strUrl += "?LID=" + Querystring_get('lid', null);
	    else
	        strUrl += "&LID=" + Querystring_get('lid', null);
	}
		
	strUrl   += "&HP=true&CT=4";
		
	//------------------------------sn,mt,pp-------------------------------------
	if (cbSenior != null)
    {	        
        if ((cbSenior.type == "select-one") || (cbSenior.type == "hidden"))
        {
            if (cbSenior.value != null && cbSenior.value != '')
                strUrl += "&SN=" + escape(cbSenior.value);
	    }		    
	    else
	    {
	        strUrl += "&SN=" + escape(cbSenior.checked);		    
	    }
	}    
    else if(Querystring_get('sn', null) != null)
    {
        strUrl   += "&SN="   + Querystring_get('sn', null); 
    }

	if (cbMilitary != null)
    {	  
        if ((cbMilitary.type == "select-one") || (cbMilitary.type == "hidden"))
        {
            if (cbMilitary.value != null && cbMilitary.value != '')
                strUrl += "&MT=" + escape(cbMilitary.value);
        }		       
        else
        {
	        strUrl += "&MT=" + escape(cbMilitary.checked);
	    }
	}
	else if(Querystring_get('mt', null) != null)
	{
        strUrl   += "&MT="   + Querystring_get('mt', null);
	}
	
	if (cbPastPassenger != null)
    {	  
        if ((cbPastPassenger.type == "select-one") || (cbPastPassenger.type == "hidden"))
        {
            if (cbPastPassenger.value != null && cbPastPassenger.value != '')
                strUrl += "&PP=" + escape(cbPastPassenger.value);            
        }		       
        else
        {
	        strUrl += "&PP=" + escape(cbPastPassenger.checked);
	    }
	}
	else if(Querystring_get('pp', null) != null)
    {
        strUrl   += "&PP="   + Querystring_get('pp', null);
    }
	    
	//----------------------------end of sn,mt,pp----------------------------------------
	
	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 multivendor = "";
	if (cbVnd != null)
	{
	    for(var i=0; i < cbVnd.options.length; i++)
	    {
	        if (cbVnd.options[i].selected)
	        {
	            if (multivendor == "")
	                multivendor +=  cbVnd.options[i].value ;	
	            else   
	                multivendor += "," + cbVnd.options[i].value ;
	        }		   	    
        }
    }
		
    if (multivendor == "") multivendor = -1;

    if (multivendor != -1)
    {
        strUrl   += "&CV=" + multivendor;
    }
		
	if (Querystring_get('template', null) != null)
	{
	    strUrl   += "&Template=" + Querystring_get('template', null);
	}
	
    if (cbMonth != null)
	{	    
	    strUrl += "&DF=" + escape(cbMonth.value);	    
	}
	else if (Querystring_get('df', null) != null)
	{
	    strUrl += "&DF=" + Querystring_get('df', null);
	}
	
	if (Querystring_get('dt', null) != null)
	{
	    strUrl   += "&DT=" + Querystring_get('dt', null);
	}
	
	if(Querystring_get('sort', null) != null)
	{
	    strUrl   += "&sort="   + Querystring_get('sort', null);
	}
	
	if(Querystring_get('zp1', null) != null)
	{
	    strUrl   += "&ZP1="   + Querystring_get('zp1', null);
	}
	else if(Querystring_get('st1', null) != null)
	{
	    strUrl   += "&ZP1="   + Querystring_get('st1', null);
	}
	
	if (cbPromoCode  != null)
	{
	    if (cbPromoCode.value != '' && cbPromoCode.value != '-1')
	        strUrl   += "&PC="	    + escape(cbPromoCode.value);
	}
	
	if (Querystring_get('eo', null) != null)
    {
        strUrl   += "&EO="   + Querystring_get('eo', null);
    }
	    
	if (Querystring_get('look', null) != null)
	{
	    strUrl   += "&look=" + Querystring_get('look', null);
	}
		
	if (Querystring_get('logo', null) != null && Querystring_get('logo', null) != '0')
    {
        strUrl   += "&logo="   + Querystring_get('logo', null);
    }
        
	if (Querystring_get('grouponly', null) != null)
    {
        strUrl   += "&GroupOnly="   + Querystring_get('grouponly', null);
    }
	    
	if (Querystring_get('branch', null) != null)
    {
        strUrl   += "&Branch="   + Querystring_get('branch', null);
    }
    if (Querystring_get('bestdeal', null) != null)
    {
        strUrl   += "&BestDeal="   + Querystring_get('bestdeal', null);
    }
	
	if(Querystring_get('home', null) != null)
	{
	    var arrURL = strUrl.split('?');
	    if(arrURL.length == 1)
	        strUrl += "?Home=" + Querystring_get('home', null);
	    else
	        strUrl += "&Home=" + Querystring_get('home', null);
	}
	
	if ((skinId != null && skinId == "132") || Querystring_get('nw', null) == 'true' || target == "_blank")
	{
		window.open(strUrl);
	}
	else
	{
		if (target && target == "_top")
		{
			window.top.location.href = strUrl;
		}
		else if (target && target == "_self")
		{
			window.location.href = strUrl;
	    }
		else
		{
			window.parent.location.href = strUrl;
		}
	}
}

function SendStateAdvanced(strFile, target)
{
	var strUrl		= strFile;
	var cbSkin		= getElement("Skin");
		
	if(cbSkin == null)
	{
		cbSkin		= getElement("AG");
		if(cbSkin == null)
		{
		    cbSkin	= getElement("clientid");
		}
	}
	
	if (strUrl.indexOf("skin=") < 0)
	{
	    strUrl   += "&skin="   + ((cbSkin != null) ? escape(cbSkin.value) : '1'); 
    }
	Querystring(null);
	
	if(cbSkin.value=="132" || Querystring_get('nw', null) == 'true' || target == "_blank")
		window.open(strUrl);
	else
	{
		if (target && target == "_top")
		{
			window.top.location.href = strUrl;
		}
		else
		{
			window.parent.location.href = strUrl;
		}
	}
}

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]).toLocaleLowerCase();

        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 displayCalendar(dateValue, inputControl, clientWindow)
{
    try
    {
       if (eval(popFrame.validateDateX(dateValue, 'From Date', 1033)))
            popFrame.fPopCalendar(inputControl, inputControl, popCal, clientWindow);
    }
    catch(e)
    {
    }

    return false;
}

//-----------------------------------------------------------------------------
// COMMOM FUNCTIONS
//-----------------------------------------------------------------------------
function getElement(name)
{
	var value = null;
	if(isIE4 || isIE5){
		value = document.all(name);
	}else if (isNS6){
		value = document.getElementById(name);
	}
	return value;
}

function getElements(name)
{
	var values = null;
	if(isIE4 || isIE5){
		values = document.all(name);
	}else if (isNS6){
		values = document.getElementsByName(name);
	}
	return values;
}
//-----------------------------------------------------------------------------

function initCal(){
    try
    {
	    popCal = window.parent.document.getElementById('popCal');
	    popFrame = window.parent.document.frames('popFrame');
	}
	catch(e)
	{
	}
}

function hideCalendar()
{
    try
    {
        window.parent.document.onclick.call();
    }
    catch(e)
    {
    }
}

function MM_openBrWindow(theURL,winName,features) 
{ //v2.0
    
    var strURL = '';
    var strPage = '';
    var intUrl = 0;
    intUrl = theURL.indexOf("?");
    if (intUrl > 0)
    {
        strPage = theURL.substr(0, intUrl + 1);
        
        strURL = theURL.substr(intUrl + 1).split('&');
        for (var i = 0; i < strURL.length; i++)
        {
            var pos = strURL[i].indexOf('=');
            var value = strURL[i].substr(pos + 1);
            if (value != "")
            {
                strPage += strURL[i] + "&";
            }        
        }
        strPage = strPage.substr(0, strPage.length-1);
    }
    else
    {
        strPage = theURL;
    }
    newwindow = window.open(strPage, winName, features);
    if (window.focus) 
    {
        newwindow.focus();
    }
}

function setDisplay(id,dstyle) 
{
	document.getElementById(id).style.display=dstyle;
	document.getElementById('vtext').style.display="none";
	document.getElementById('btnDown').style.display="none";
}

function msClose(id,hidId,type) 
{
    var ostring = ""; // only for demo purposes
    var otext = "";
    var items = 0;
    var txtitems = 0;
    o = document.getElementById(id);
    o.style.display = "none";
    
    for (var i=0; i<o.options.length; i++) {
      if (o.options[i].selected) {
        ostring += (items++>0?",":"")+ o.options[i].value;	// only for demo purposes
        otext+= (txtitems++>0?",":"")+ o.options[i].text;
        if (i==0) break;  // if "All" selected, skip all other options
      }
    }
    
    document.getElementById('vtext').style.display="block";
    document.getElementById('btnDown').style.display="block";
    document.getElementById("vtext").value=otext;
    document.getElementById("vhidden").value=ostring;

    if(IsDisabledItem(ostring,type))
    {        
        KeepSelection(thisObject,getElement(hidId).value ,type);               
        return;
    } 
  
    if (type=="Month") 
        CompareFrom_TO_Dates(dtdropdown);
    
    if(type=="VendorType") 
        VndTypeClicked=true;
    else
        VndTypeClicked=false;
    
    try
    {            
        __doPostBack(thisObject.id,'');                                    
        getElement('ZoneDropDown').disabled  = true;            
        getElement('VndDropDown').disabled   = true;            
        getElement('DateDropDown').disabled  = true;
        getElement('LenDropDown').disabled   = true;
        getElement('CruiseTypeDropDown').disabled   = true;
        getElement('PortDropDown').disabled  = true;
        getElement('ShipsDropDown').disabled = true;
        getElement('DateTo').disabled = true;
        getElement('LoadFromDays').disabled = true;
        getElement('LoadToDays').disabled = true;            
    }
    catch (e)
    {
    }	
}

function IsDisabledItem(ostring,type)
{      
    if (type=="Port") return Check(PortDisabledArr,ostring);
}

function Check(DisabledArr,Ids)
{
    var p=0;
    var q=0;
    var arrIds=Ids.toString().split(',');
    for(p=0;p<DisabledArr.length;p++)
    {
        for(q=0;q<arrIds.length;q++)
        {
            if( DisabledArr[p] == arrIds[q])
            {
                return true;
            }
        }
    }
    return false;      
}