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,'');                                    
            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 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
			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 cbGroup	= getElement("GroupOnly");
	
	var cbMilitary	= getElement("Military");
	var cbZip1		= getElement("Zip1");
	var cbZip2		= getElement("Zip2");
	var cbPromoCode	= getElement("PromoCode");
	
	//hidden
	var cbSkin		= getElement("Skin");
	var cbRef		= getElement("Ref");
	var cbPIN		= getElement("PIN");
	var cbSN		= getElement("SN");
	var cbMT		= getElement("MT");
	var cbShowSenior = getElement("ShowSenior");
	var cbShowMilitary = getElement("ShowMilitary");
	var cbPhone		= getElement("Phone");
	var cbHome		= getElement("Home");
	var cbLID		= getElement("LID");
	var cbEO		= getElement("EO");
	var cbadv       = getElement("ADV");
	var cbpsl       = getElement("PSL");
	var cbLogo      = getElement("logo");
	
	var cbbranch      = getElement("branch");
	
	var DayFrom      = getElement("LoadFromDays");
	var DayTo        = getElement("LoadToDays");
	
	
	 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 (cbSkin == null)
	{
		cbSkin = getElement("AG");
		if (cbSkin == null)
		{
		    cbSkin = getElement("ClientID");
		}
	}	
	
	if(type == 'advanced')
    {
        queryString   += "&";
    }
    else
    {
        queryString   += "?";
    }
	
	if (cbSkin != null)
	{
	    if (cbSkin.value != '' && cbSkin.value != '-1')
	        queryString   += "skin="   + escape(cbSkin.value);
	}
	
	if (cbDest.value != '' && cbDest.value != null)
	{
	    queryString   += "&CD="	+ cbDest.value;
	}
	
	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)
	{
	    if((cbLen.value!='')&&(cbLen.value!='0|0'))
	    queryString   +="&CL="	+escape(cbLen.value);
	}
	
	if(multivendor!=-1)
	{
	    queryString   += "&CV=" +multivendor;
	}
	if(cbShp   != null)
	{
	    if(cbShp.value!='' && cbShp.value!='-1')
	    queryString   += "&ships=" +escape(cbShp.value);
	}
	
	if(cbPort  != null)
	{
	    if(cbPort.value!='' && cbPort.value!='-1')
	    queryString   += "&ports="	+escape(cbPort.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)
        		    queryString   += "&sort=" + rdoSort[i].value;
			}
		}
	}
	else if (cbSort != null && cbSort.value != '' && cbSort.value != '-1')
	{
	    queryString   += "&sort=" + cbSort.value;
	}
		
	if(cbShowSenior.value == 'false') 
	{
	    if(cbSN != null && cbSN.value != '')
	    {
	        queryString   += "&SN=" + escape(cbSN.value);
	    }    	
    }
	else 
	{
	    if (cbSenior != null)
	    {	        
	        if ((cbSenior.type != "select-one")  && (cbSenior.type != "hidden") && (cbSenior.type != ''))
		        queryString   += "&SN="	+ escape(cbSenior.checked); 
		}
		else
		        queryString += "&SN=false"; 
    }

	if(cbShowMilitary.value == 'false')
	{
        if(cbMT != null && cbMT.value != '')
        {
            queryString += "&MT=" + escape(cbMT.value);
        }
	}
	else 
	{
	    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(cbZip1  != null)
    {   
        if(cbZip1.value!='' && cbZip1.value!='-1')
        {
            queryString   += "&ZP1="	+escape(cbZip1.value);
        }
    }
	
	if(cbZip2  != null)
	{
	    if(cbZip2.value!='' && cbZip2.value!='-1')
	    queryString   += "&ZP2="	+escape(cbZip2.value);
	}
	
	if(cbPromoCode  != null)
	{
	    if(cbPromoCode.value!='' && cbPromoCode.value!='-1')
	    queryString   += "&PC="	    +escape(cbPromoCode.value);
	}
	    
    if(cbPhone != null)
    {
        if(cbPhone.value!='' && cbPhone.value!='-1')
        queryString   += "&Phone=" +escape(cbPhone.value);
    }
    
    if(cbHome != null)
    {
        if(cbHome.value!='' && cbHome.value!='-1')
        queryString   += "&Home=" +escape(cbHome.value);
    }    
		
	if((cbEO != null)&&(cbEO.type != "select-one"))
	{
	    queryString   += "&EO="	+ escape(cbEO.checked);
	}
	
	if(cbRef  != null)
	{
	    if(cbRef.value!='' && cbRef.value!='-1')
	    queryString   += "&Ref="  +escape(cbRef.value);
	}
	
	if(cbPIN != null)
	{
	    if(cbPIN.value!='' && cbPIN.value!='-1')
	    queryString   += "&PIN=" +escape(cbPIN.value);
	}
	
	if(cbLID  != null)
	{
	    if(cbLID.value!='' && cbLID.value!='-1')
	    queryString   += "&LID="  +escape(cbLID.value);
	}
		
	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(cbadv != null)
	{
	    if(cbadv.value!='' && cbadv.value!='-1')
	    queryString   += "&ADV="   +escape(cbadv.value);
	}
	
	if(cbpsl != null)
	{
	    if(cbpsl.value!='' && cbpsl.value!='-1')
	    queryString   += "&PSL="   +escape(cbpsl.value);
	}
	
	
	if(cbLogo != null)
	{
	    if(cbLogo.value!='' && cbLogo.value!='-1')
	    queryString   += "&logo="   +escape(cbLogo.value);
	}
	
	
	if(cbbranch != null)
	{
	    if(cbbranch.value!='' && cbbranch.value!='-1')
	    queryString   += "&branch="   +escape(cbbranch.value);
	}
			
	if(cbGroup != null && cbGroup.checked)
	{
    	queryString   += "&GroupOnly=" + 'true';	
    }
    
    if(Querystring_get('xml', null) != null)
	{
	    queryString   += "&xml=" + Querystring_get('xml', null);
	}
    
    return queryString;
}

function SendStatePortSearch(strFile, target)
{
	var strUrl		= strFile;
	var cbSkin		= getElement("Skin");
	var cbPIN		= getElement("PIN");
	var cbPhone		= getElement("Phone");
	var cbHome		= getElement("Home");
	var cbLID		= getElement("LID");
		
	if(cbSkin == null)
	{
	    cbSkin		= getElement("AG");
	    if(cbSkin == null)
		{
		    cbSkin	= getElement("ClientID");
		}
	}
	if(cbSkin != null && cbSkin.value!='' && cbSkin.value!=null)
	{
	    var arrURL=strUrl.split('?');
	    if(arrURL.length==1)
	    strUrl += "?skin="+cbSkin.value;
	    else
	    strUrl += "&skin="+cbSkin.value;
	}
	
	if(cbPIN != null && cbPIN.value!='' && cbPIN.value!=null)
	{
	    var arrURL=strUrl.split('?');
	    if(arrURL.length==1)
	    strUrl += "?PIN="+cbPIN.value;
	    else
	    strUrl += "&PIN="+cbPIN.value;
	}
	if(cbPhone != null && cbPhone.value!='' && cbPhone.value!=null)
	{
	    var arrURL=strUrl.split('?');
	    if(arrURL.length==1)
	    strUrl += "?Phone="+cbPhone.value;
	    else
	    strUrl += "&Phone="+cbPhone.value;
	}
	if(cbHome != null && cbHome.value!='' && cbHome.value!=null)
	{
	    var arrURL=strUrl.split('?');
	    if(arrURL.length==1)
	    strUrl += "?Home="+cbHome.value;
	    else
	    strUrl += "&Home="+cbHome.value;
	}
	if(cbLID != null && cbLID.value!='' && cbLID.value!=null)
	{
	    var arrURL=strUrl.split('?');
	    if(arrURL.length==1)
	    strUrl += "?LID="+cbLID.value;
	    else
	    strUrl += "&LID="+cbLID.value;
	}
	strUrl   += "&HP=true&CT=4";
		
	Querystring(null);
	
	if(Querystring_get('vendor', null) != null)
	{
	    var arrURL=strUrl.split('?');
        if(arrURL.length==1)
        strUrl += "?vendor="+ Querystring_get('vendor', null);
        else
        strUrl += "&vendor="+ Querystring_get('vendor', null);
	}
		
	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 SendStateAdvanced(strFile, target)
{
	var strUrl		= strFile;
	var cbSkin		= getElement("Skin");
		
	if(cbSkin == null)
	{
		cbSkin		= getElement("AG");
		if(cbSkin == null)
		{
		    cbSkin	= getElement("ClientID");
		}
	}
	
	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])

	    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();
    }
}
