if(HCal){document.onclick = HCal;}

function hw(id)
{	 
    //alert(id);
    SH("errRw",0);
	var t;
	cwid = id;
	//if(cwid !=10){SetTI();SH1('divTI',1);}else{SH1('divTI',0);} //sets orange label text "Trip Information"
	SetTI();SH1('divTI',1); //sets orange label text "Trip Information"
	SetCst();    
			
	if (V()){ return;}
	if ('1'==id || '7'==id)
	{
	    t = DE('flx');
	    if(t) {bFlex = DE('flx').checked;}	    
    }

    if(cwid == '3'){SH1('divCC',1);SH1('divCA',1);}else{SH1('divCC',0);SH1('divCA',0);}
    if(cwid == '8'){SH1('divRes',1);} else {SH1('divRes',0);}
    if(cwid == '1' || cwid == '3' || cwid == '7' || cwid == '8' || cwid == '9' || cwid == '10') {SH1('divWho',0);} else {{SH1('divWho',1);}}//sets orange label text for search options with room	
	DE('r' + id).checked = true;
	
    //SO(); //CORE OFFER
	SetSearchType();	
	SetFW();	
	if (DE('bIE6') && DE('bIE6').value=='1') //if internet explorer 6
	{
		SHSelect('divWBody','0');
		var _wtimer = setInterval(function(){
			hw2();
			clearInterval(_wtimer);
		},		
		25);
	}
	else
	{
		hw2();
	}
}

function clearPPV(){de("tcy").options.length = 0;}

function fillDur(vals){objSelect = de("sv_dur");objSelect.options.length = 0;arVars = vals.split(",");for(var idx=0;idx<arVars.length;idx++){objSelect.options[objSelect.options.length] = new Option(arVars[idx] + " days", arVars[idx]);}de("sv_dur").value = 7;}


function addO(strVal, strText){objSelect = de("fcy");objSelect.options[objSelect.options.length] = new Option(strText, strVal);}
function addD(strVal, strText){objSelect = de("tcy");objSelect.options[objSelect.options.length] = new Option(strText, strVal);}
//NEED TO CHANGE THIS WITH NEW PPV FORMAT
function checkPPVDest(val){
    if(val.indexOf("|")>-1){arTmp = val.split("|");fillDur(arTmp[1]);}
    else{fillDur("7,14");}
}

function bldDests(dests)
{
    var strTmp = new String;
    strTmp = dests;
    
    arTmp = strTmp.split("~")
    arTmp.sort();
    
    for(idx=0;idx<arTmp.length;idx++)
    {
        arTmp2 = arTmp[idx].split("|");
        addD(arTmp2[1] + "|" + arTmp2[2] , arTmp2[0]);
    }
}

function addOrigs(origs)
{
    fillDur("7,14");
    var strTmp = new String;
    strTmp = origs;
    arTmp = strTmp.split("|")
    arTmp.sort();
    for(idx=1;idx<arTmp.length;idx++)
    {
        arTmp2 = arTmp[idx].split("~");
        addO(arTmp2[1] , arTmp2[0]);
    } 
}


function hw2()
{
	BuildFields();	
	
	if(cwid==10){addO("0","-- Select --");addOrigs(strOrigs);}
	SetST(cwid); //SET SEARCH TEXT
	pwid = cwid;	
	if(cwid < 6){arrSTYPE[cwid] = cst; DE('SType').value = arrSTYPE.join('|');  }	
}

function SHSelect(parentID,sh)
{		
	var ieSelects = DE(parentID).getElementsByTagName('select');
	var j;
	for (j=0; j<ieSelects.length; j++) 
	{		

		ieSelects[j].style.visibility = (sh == '1') ? 'visible' : 'hidden';		
	}
}

function SetCst()
{
	if (parseInt(cwid) < 6)
	{        
	    if (pwid==cwid)
	    {
	        if (cwid == '1')
	        {
	            if ( DE('typ_3').checked ) { cst = '3'; }
	            else if ( DE('typ_2').checked ) { cst = '2'; }  
	            else { cst = '1'; }
	        }
			else if (cwid == '4' || cwid == '5')
			{				 
				cst = '1';			
			}
	        else
	        {
	            t = DE('typ');
	            cst = t.options[t.selectedIndex].value;
	        }
	    }
	    else
	    {
	        cst = arrSTYPE[cwid];
	    }
	}		
}



function SetTI()
{
	var t = (cwid == '8') ? 'Cruise options:' : 'Trip information:';	
	SetIH('divTI',t);
}

function V()
{
	var bRepeated = false;
	
    switch(cwid)
    {        
        case '1':           
			if (cwid == pwid)
			{
				if (cst == 1) 
				{					
					var t = DE('flx');
					bRepeated = (arrSTYPE[cwid] == cst) && (t.checked == bFlex);
				}
				else
				{
					bRepeated = (arrSTYPE[cwid] == cst);
				}
			}
            break;            
        case '2':
        case '3':            
			bRepeated = (cwid == pwid) && (arrSTYPE[cwid] == cst);
            break;
        case '7':
			if (cwid == pwid)
			{
				bRepeated = (DE('flx').checked == bFlex);				
			}
        	break;
        default:               	
            bRepeated = (cwid == pwid);
            break;
    }
	
	return bRepeated;
}


function SetFW()
{    
   if(''!=pwid){DE('l'+pwid).style.fontWeight='normal';}
   DE('l'+cwid).style.fontWeight='bold';
   
}

var GetYL = (function(){
    var m_html = ['<div class="tST bl0 pb4" style="color:D3670B;font-weight:bold;">','','</div>'];
    return function(t){m_html[1] = t;return m_html.join('');}
})();


var GetSrchType = (function(){
    var m_html1, m_html45, m_arrFltST;	     
	var m_style = ['style="vertical-align:middle;float:left;margin:0 10px 0 ', (document.all) ? '-4px;"': '0;"'].join('');
    
    function _init1() {
        m_arrFltST = ['1|Return','2|One way','3|Multiple destinations'];		
        m_html1 = ['<div class="ST pb10" >',''/*GetYL('Trip Information:')*/,''/*GetGL('typ','Flight type: (e.g. one way, multiple destinations)')*/,'<!--br/-->','', '</div>'];
    }
    
    function _init45()
    {                
		var _js = ' onclick="document.location.href=\'/pub/agent.dll?qscr=cmsh&cdst=2\';" ';
		m_html45 = [
			'<div class="ST pb10">',
			'<div ',m_style,' ><input type="radio" name="typ" id="typ_1" value="1" /><label for="typ_1">One destination</label></div>',
			'<div ',m_style,_js,'><input type="radio" name="typ" id="typ_2" value="2" ',_js,' /><label for="typ_2">Two destinations</label></div>',
			'</div>'
			];		
    }
    
    return function() {
		if(bB) 
		{
			var _SType = DE('SType').value.split('|');
			for(var i=0; i < _SType.length; i++)
			{
				arrSTYPE[i] = _SType[i];				
			}					
			cst = arrSTYPE[cwid]; 
		}				
		
        switch(cwid)
        {
            case '1':
                if (m_html1 === undefined) {_init1();if(DE('FDate').value != 'dd/mm/yyyy' && DE('TDate').value == 'dd/mm/yyyy'){arrSTYPE[cwid]='2';cst='2';}}   
                m_html1[4] = GetRD('typ',m_arrFltST,cst,'med',m_style,' onclick="hw(\'1\');Rem(this);SetFocus(this);" ');
                return m_html1.join('');
                break;
            case '4':case'5':
                if (m_html45 === undefined) {_init45();}
                return m_html45.join('');
                break;
            default:break;                                
        }
        return '';
    }
})();

function SetFocus(obj)
{
	if(obj)
	{
		if (DE('bIE6') && DE('bIE6').value=='1') 
		{			
			var _focustimer = setInterval(function(){
				DE(obj.id).focus();;
				clearInterval(_focustimer);
			},		
			25);
		}
		else
		{
			DE(obj.id).focus();
		}				
	}		
}

function GetRD(id,arr,d,c,s,j)
{
    var i, it;    
    var h = [];
    for(i = 0; i < arr.length; i++)
    {            
        it = arr[i].split('|');
        h[h.length] = ['<div ',s,'>'].join('');
        h[h.length] = ['<input type="radio" name="',id,'" value="',it[0],'" id="',id,'_',it[0],'" ',j,' />'].join('');
        h[h.length] = ['<label for="',id,'_',it[0],'" >',it[1],'</label>'].join('');
        h[h.length] = '</div>';
    }
    return h.join('');
}

function BuildFields()
{
	//switch (pwid){case '4':case '5':switch (cwid){case '4':case '5':if(!bB){pwid = cwid;return;};break;}break;}
	if (bB)
	{
	    //GetSavedValuesG();
	    GetSavedValues();
	}	
	
	SetIH('divWFields',GetFieldsHTML());	
	switch(cwid)
	{
	    case '1':	 
	        DE('typ_'+cst).checked = true;
	        break;
	    case '3':case '7':
	        BuildDC();
	        break;
	    case '4':case '5':
			DE('typ_'+cst).checked = true;
	        if(bPart == '1'){SetPart();}
	        break;			
        case '8':
            if(Recidency == '1') DE('res').checked = true;SetRes();
            break;
        case '9':
			if (DE("LsTOverride").value == ""){
				if (DE("LsAtlasRegionId").value != "" && DE("tci"+DE("LsAtlasRegionId").value)){
					DE("tci"+DE("LsAtlasRegionId").value).checked = true; DE("tcy").value="";
				}
				else{
					DE('tci-1').checked = true;
					DE("tcy").value = GetDestination();
				}
			}			
			else if (TCity !== undefined && TCity.length > 2)
			{
				var _arr, i;
				for(i = 0; i < arrACities.length; i++)
				{
					_arr = arrACities[i].split('|');
					
					if ( TCity.toUpperCase() == _arr[1].toUpperCase() )
					{
						DE('tci'+_arr[0]).checked = true;
						if (ActTci != _arr[0])
						{
							DE('tciAct').value = ActTci = _arr[0];
						}
						break;
					}
				}				
				
				if(i == arrACities.length )
				{
					DE('tci-1').checked = true;
					DE('tcy').value = GetDestination();
				}				
			}
			else
			{
	            if (ActTci != '')
	            {				
	                var t = DE('tci'+ActTci);
	                if (t) {t.checked = true; DE('tcy').value='';}
	                else 
					{
						DE('tci-1').checked = true;
						if ('-1' != ActTci ) DE('tcy').value = ActTci;
					}
	            }				
			}
            break;
	    default:break;
	}

	BuildRASC();
	SetMOT(cwid); //SET MORE OPTION TEXT
	if ('1'==arrAO[cwid]){SetAO()};
	bB = false;
}

function BuildRASC()
{
	switch (pwid){case '1':case '4':case '5':switch (cwid){case '1':case '4':case '5':if (bB){return ''};break;}break;}
	var n = 0;
	switch (cwid)
	    {
	        case '1':case '7':n = 1;break;
	        case '2':case '4':case '5':case '6':n = 2;break;
	        case '3':case '8':n = 0;break;
	        default:n = 0;break;
	    }
	var s = true;
	if (cwid == '2' || cwid == '6'){s = false;minA = 1;}else{minA = 0;}
	if (cwid == '2'){maxR = 9;}else{maxR = 3;}
	SetRASC(n,s);
}


var GetFieldsHTML = (function(){
    
    var m_lblWW = GetYL('When and where?');
    var m_evtRem = ' onchange="Rem(this);"';
    var m_evtHCal = ' onfocus="HCal();this.select();" onchange="Rem(this);"';
    var m_strChkClass = (document.all) ? 'chkIE' : 'chkFF';
    
    var m_F, m_FL, m_FFlex,
        m_C,m_arrCarST,
        m_HC, m_Cr, m_PPV,
        m_A, m_A_aCity,
        m_H,m_HMain_cst4, m_HSTL, m_arrHotST ;
    
    function _GetFFDiv(chked)
    {
        if (m_FFlex === undefined)
        {
            m_FFlex = ['<div id="divFlex" class="bl0 pb2"><div class="bl0"><input id="flx" name="flx" type="checkbox" ',
                    '',
                    ' class="',
                    m_strChkClass,
                    '" onclick="hw(\'',
                    '',
                    '\');Rem(this);"/><label for="flx">Fare&nbsp;Calendar&nbsp;for&nbsp;flexible&nbsp;dates&nbsp;(popular&nbsp;routes)</label></div><div class="clearer"></div></div>'
            ];
        }
        m_FFlex[1] = chked ? ' checked ' : '';
        m_FFlex[5] = cwid;
        return m_FFlex.join('');        
    }
    
    function _F(t)
    {        
        if (undefined === m_F)
        {
            m_F =[
                '<div class="bl1">',
                '<div class="flmed">',
                GetGL('fcy','Leaving from:'),
                '<br/>',
                '',// GetCy(t,'F'),4
                '</div>',
                '<div class="frmed">',
                GetGL('tcy','Going to:'),
                '<br/>',
                '',//GetCy(t,'T'),9
                '</div>',
                '</div>',
                '<div class="bl1">',
                '<div class="flmed">',
                '<div class="fl">',
                GetGL('fdt','Departing:'),
                '<br/>',
                '',//GetDt(t,'F'),17
                '</div>',
                '<div class="fr">',
                GetGL('ftt','Time:'),
                '<br/>',
                '',//GetT(t,'F'),22
                '</div>',
                '</div>',
                '<div class="frmed">',
                '<div class="fl">',
                GetGL('tdt','Returning:'),
                '<br/>',
                '',//GetDt(t,'T'),29
                '</div>',
                '<div class="fr">',
                GetGL('ttt','Time:'),
                '<br/>',
                '',//GetT(t,'T'),34
                '</div>',
                '</div>',
                '</div>',
                '' // 38
            ];                        
        }
        m_F[4]  = GetCy(t,'F');
        m_F[9]  = GetCy(t,'T');
        m_F[17] = GetDt(t,'F');
        m_F[22] = GetT(t,'F');
        m_F[29] = GetDt(t,'T');
        m_F[34] = GetT(t,'T');
        m_F[38] = (t == 'FHC') ? _FHC() : '';
        
        return m_F.join('');
    }   
    
    var m_FHC;
    function _FHC()
    {
        if (undefined === m_FHC)
        {
            m_FHC = [
                '<div class="bl1">',
                '',
                '</div>','<div class="bl1" id="divPart" style="display:none;"></div>','<div class="clearer"></div>'
            ];
        }
        m_FHC[1] = GetCB('prt','1','I only need a hotel for part of my trip',bPart,'','',' onclick="SetPart();Rem(this)"',''); 
        return m_FHC.join('');
    } 
    
    function _FL()
    {
        if (undefined === m_FL)
        {        
            var m_FLtt = ['Don\'t see the city you\'re looking for?','Flexible-date searches are currently available only for our most popular routes. You can still search for flights in the usual way by putting in your departure and return dates.'];
            m_FL = [
                '<div class="bl1">',
                GetGL('fct','Leaving from:'),
                '<br/>',
                '',
                '</div>',
                '<div class="bl1">',
                GetGL('tct','Going to:'),
                '<br/>',
                '',
                '</div>',
                '<div class="bl1" >',
                GetTT(m_FLtt[0],m_FLtt[0],m_FLtt[1],0,'','',true),
                '</div>',
                '<div class="bl1">',
                '<div class="flmed">',
                GetGL('mon','Departure month:'),
                '<br/>',
                '',
                '</div>',
                '<div class="frmed">',
                GetGL('trl','Trip length:'),
                '<br/>',
                '',
                '</div></div><div class="clearer"></div>'
            ];
        }
        m_FL[3] = GetDD('fct',arrFD,FTLA,'large','',m_evtRem);
        m_FL[8] = GetDD('tct',arrTD,TTLA,'large','',m_evtRem);
        m_FL[17] = GetM(nm,MDate,'','',m_evtRem);
        m_FL[22] = GetDD('trl',arrTL,TL,'','',m_evtRem);
        return m_FL.join('');
    }        
   
    function _Address()
    {
        if (undefined === m_HMain_cst4)
        {
            m_HMain_cst4 = [
                '<div class="bl1">',
                '<div class="flmed">',
                '<div class="fl">',
                GetGL('tct','City:'),
                '<br/>',
                '',//GetGI('tct',TCity1,'','',' onfocus="HCal();this.select();" onchange="Rem(this);"','100'),5
                '</div>',
                '</div>',
                '<div class="frmed">',
                '<div class="fl">',
                GetGL('tst','State:'),
                '<br/>',
                '',//GetDD('tst',arrST,State,'small','',' onchange="Rem(this);"'),12
                '</div>',
                '<div class="fr">',
                GetGL('tzp','ZIP code:'),
                '<br/>',
                '',//GetGI('tzp',Zip,'small','',' onfocus="HCal();this.select();" onchange="Rem(this);"','5'),17
                '</div>',
                '</div>',
                '</div>'                                     
            ];
        }
        m_HMain_cst4[5]=GetGI('tct',TCity1,'','',m_evtHCal,'100');
        m_HMain_cst4[12]=GetDD('tst',arrST,State,'small','',m_evtRem);
        m_HMain_cst4[17]=GetGI('tzp',Zip,'small','',m_evtHCal,'5');
        return m_HMain_cst4.join('');        
    }
    
    function _H(t) // this is for the main launch page
    {
        if (undefined === m_H)
        {
            m_H = [
                GetGL('typ','Find hotels near:'),
                '<br/>',
                '',//GetDD('typ',arrHotST,cst,'med','',' onchange="hw(\'2\');" '), 2               
                '<div class="bl1 pt4">',
                '',//switch (cst),4
                '<br/>',
                '',//cst = 4 if/else,6
                '</div>',
                '',//if(cst == '4'),8                
                '<div class="bl1">',
                '<div class="flmed">',
                GetGL('fdt','Check-in:'),
                '<br/>',
                '',//GetDt('H','F'),13
                '</div>',
                '<div class="frmed">',
                GetGL('tdt','Check-out:'),
                '<br/>',
                '',//GetDt('H','T'),18
                '</div>',
                '</div>',
                '<div class="clearer"></div>'
            ];    
            
            m_HSTL ={
                '1':GetGL('tcy','What city?'),
                '2':GetGL('tcy','What airport? (Ex. Vancouver, YVR)'),
                '3':GetGL('tcy','What attraction? (Ex. CN Tower)'),
                '4':GetGL('tsr','Street address or intersection:')
            };
            
            m_arrHotST = ['1|A city','2|An airport','3|An attraction','4|A U.S. address'];            
        }
        
        m_H[2] = GetDD('typ',m_arrHotST,cst,'med','',' onchange="hw(\'2\');" ');
        m_H[4] = m_HSTL[cst];
        m_H[6] = cst == '4' ? 
            GetGI('tsr',Street,'large','',m_evtHCal,'255'):
            GetGI('tcy',GetDestination(),'large','',m_evtHCal,'100'); 
        m_H[8] = cst == '4' ? _Address() : '';
        m_H[13] = GetDt('H','F');
        m_H[18] = GetDt('H','T');
        
        return m_H.join('');
    }
    
    function _C()
    {
        if(undefined === m_C)
        {
            m_C = [
                GetGL('typ','Find car rentals near:'),
                '<br/>',
                '',//GetDD('typ',arrCarST,cst,'med','',' onchange="hw(\'3\');" '),2
                '',// cst,3
                '<div class="bl1">',
                '<div class="flmed">',
                '<div class="fl">',
                GetGL('fdt','Pick-up on:'),
                '<br/>',
                '',//GetDt('C','F'),9
                '</div>',
                '<div class="fr">',
                GetGL('ftt','Time:'),
                '<br/>',
                '',//GetT('C','F'),14
                '</div>',
                '</div>',
                '<div class="frmed">',
                '<div class="fl">',
                GetGL('tdt','Drop-off on:'),
                '<br/>',
                '',//GetDt('C','T'),21
                '</div>',
                '<div class="fr">',
                GetGL('ttt','Time:'),
                '<br/>',
                '',//GetT('C','T'),26
                '</div></div></div><div class="clearer"></div>'
            ];            
            
            m_CST = {
                '2':[
                    '<div class="bl1 pt4">',
                    '<div class="flmed" title="e.g. YYC, or Calgary">',
                    GetGL('tcy','Pick-up airport or city:'),
                    '<br/>',
                    '', // GetGI('tcy',TCity,'','',' onfocus="HCal();this.select();" onchange="Rem(this);"','100'),4
                    '</div>',
                    '<div class="frmed" title="e.g. YYC, or Calgary">',
                    GetGL('tcy1','Drop-off airport or city:'),
                    '<br/>',
                    '',// GetGI('tcy1',TCityD,'','',' onfocus="HCal();this.select();" onchange="Rem(this);"','100'),9
                    '</div></div>'
                ],
                '3':[
                    '<div class="bl1 pt4">',
                    '<div class="flmed" title="e.g.Toronto or CN Tower">',
                    GetGL('tcy','What attraction?'),
                    '<br/>',
                    '', // GetGI('tcy',TCity,'','',' onfocus="HCal();this.select();" onchange="Rem(this);"','100'),4
                    '</div>',
                    '<div class="frmed">',
                    GetGL('rds','Find cars within:'),
                    '<br/>',
                    '',//GetDD('rds',arrRD,Radius,'','',' onchange="Rem(this);"'),9
                    '</div>','</div>'
                ],
                '4':[
                    '<div class="bl1 pt4">',
                    GetGL('tsr','Street:'),
                    '<br/>',
                    '',//GetGI('tsr',Street,'large','',' onfocus="this.select();" onchange="Rem(this);"','255'),3
                    '</div>',
                    '', // _Address(),5
                    '<div class="bl1">',
					GetGL('rds','Find cars within:'),
					'<br/>',
					'', // 9
					'</div>'					
                ] 
            };
            
            m_arrCarST = ['2|An airport or city','3|An attraction','4|A U.S. address'];            

        }
        //m_evtHCal
        m_C[2] = GetDD('typ',m_arrCarST,cst,'med','',' onchange="hw(\'3\');" ');
        
        switch (cst)
        {
            case '2':
                m_CST['2'][4] = GetGI('tcy',GetDestination(),'','',m_evtHCal,'100');
                m_CST['2'][9] = GetGI('tcy1',TCityD,'','',m_evtHCal,'100');
                break;
            case '3':
                m_CST['3'][4] = GetGI('tcy',GetDestination(),'','',m_evtHCal,'100');
                m_CST['3'][9] = GetDD('rds',arrRD,Radius,'','',m_evtRem)               
                break;
            case '4':
                m_CST['4'][3] = GetGI('tsr',Street,'large','',m_evtHCal,'255');
                m_CST['4'][5] = _Address();                
				m_CST['4'][9] = GetDD('rds',arrRD,Radius,'','',' onchange="Rem(this);"');
                break;
            default:break;                
        }
        
        m_C[3] = m_CST[cst].join('');
        m_C[9] = GetDt('C','F');
        m_C[14] = GetT('C','F');
        m_C[21] = GetDt('C','T');
        m_C[26] = GetT('C','T');        
        
        return m_C.join('');     
    }
    
    function _HC(t)
    {
        if(m_HC === undefined)
        {
            m_HC = [
                '<div class="bl1">',
                GetGL('tcy','What location?'),
                '<br/>',
                '', // GetCy('H','T') 3
                '</div>',				
				'<div class="bl1"><div class="flmed">',
                GetGL('fdt','Hotel check-in:'),
                '<br/>',
                '', // GetDt(t,'F') 8
                '</div>',
				'<div class="frmed">',
                GetGL('ftt','Car pick-up time:'),
                '<br/>',
                '', // GetT('C','F') 13
                '</div></div>',				
				'<div class="bl1 pb8"><div class="flmed">',
                GetGL('tdt','Hotel check-out:'),
                '<br/>',
                '', // GetDt(t,'T') 18
                '</div>',
				'<div class="frmed">',
                GetGL('ttt','Car drop-off time:'),
                '<br/>',
                '', // GetT('C','T') 23
                '</div></div>'				
            ];
        }
        m_HC[3] = GetCy('H','T');
        m_HC[8] = GetDt('H','F');
        m_HC[13] = GetT('HC','F');
        m_HC[18] = GetDt('H','T') ;
        m_HC[23] = GetT('HC','T');
        return m_HC.join('');
    }    
    
    function _PPV()
    {
        if(m_PPV === undefined)
        {
            m_PPV = [
                '<div class="bl1">',
                '<div class="flmed">',
                GetGL('fcy','Leaving from:'),
                '<br/>',
                '<select name="fcy" id="fcy" onChange="getPPVDests(this.value);de(\'tcy\').focus();" class="med"></select>',
                '</div>',
                '<div class="frmed">',
                GetGL('tcy','Going to:'),
                '<br/>',
                '<select name="tcy" id="tcy" onChange="checkPPVDest(this.value);" class="med"></select>',
                '</div>',
                '</div>',
                
				'<div class="bl1"><div class="flmed">',
                GetGL('fdt','Departing:'),
                '<br/>',
                GetDt('H','F'),
                '</div>',
				'<div class="frmed"><BR>',
                '<input type="checkbox" name="sv_flex" id="sv_flex" onclick="if(this.checked==true){de(\'PPV_flex\').value=1;}else{de(\'PPV_flex\').value=0;}" style="BORDER-RIGHT:0px;BORDER-TOP:0px;VERTICAL-ALIGN:middle;BORDER-LEFT:0px;BORDER-BOTTOM:0px">&nbsp;Flexible on dates?',
                '</div></div>',				
				'<div class="bl1 pb8"><div class="flmed">',
                GetGL('tdt','Duration:'),
                '<br/>',
                '<select name="sv_dur" id="sv_dur" class="med"></select>',
                '</div>',
				'<div class="frmed">',
                '</div></div>',
                '<div class="bl1">',
                GetGL('','Price range (per person):'),
                '<div class="flmed">',
                '<div><input type="radio" name="sv_rnge" value="np"	ID="sv_rnge1" checked onclick="de(\'PPV_prce\').value=\'np\'">&nbsp;No preference<BR><input type="radio" name="sv_rnge" value="1000" ID="sv_rnge3" onclick="de(\'PPV_prce\').value=\'1000\'">&nbsp;Under C$1000</div>',            
                '</div>',
                '<div class="frmed">',
                '<div><input type="radio" name="sv_rnge" value="1500" ID="sv_rnge2" onclick="de(\'PPV_prce\').value=\'1500\'">&nbsp;Under C$1500<BR><input type="radio" name="sv_rnge" value="2000" ID="sv_rnge4" onclick="de(\'PPV_prce\').value=\'2000\'">&nbsp;Under C$2000</div>',
                '</div>',
                '</div>',
				'<div class="bl1 pb8"><div class="flmed">',
                GetGL('tdt','Star rating:'),
                '<br/>',
                '<select name="sv_star" id="sv_star" class="med"><option value="0">All Ratings</option><option value="2">2 Star or more</option><option value="3">3 Star or more</option><option value="4">4 Star or more</option><option value="5">5 Star</option></select>',
                '</div>',
				'<div class="frmed">',
                '</div></div>',
                '<div class="bl1">',
                GetGL('','Package features:'),
                '<div class="flmed">',
                '<div><input type="checkbox" name="sv_ai" ID="sv_ai">&nbsp;All-inclusive<BR><input type="checkbox" name="sv_kitch"	ID="sv_kitch">&nbsp;Kitchenette</div>',            
                '</div>',
                '<div class="frmed">',
                '<div><input type="checkbox" name="sv_beach" ID="sv_beach">&nbsp;Beachfront<BR><input type="checkbox" name="sv_golf" ID="sv_golf">&nbsp;Golf Course</div>',
                '</div>',
                '</div>'
            ];
        }
        
        
        return m_PPV.join('');
    }        
    
    function _Cr()
    {
        if(m_Cr === undefined)
        {
            m_Cr = [
                '<div class="bl1">',
                GetGL('tci','Select from top destinations:'),
                '<br/>',
                '', // GetDD('tci',arrTD,TCityId,'large','',' onchange="Rem(this);"'), 3
                '</div><div class="bl1"><div class="flmed">',
                GetGL('mon','Departure month:'),
                '<br/>',
                '', // GetM(18,MDate,'','',' onchange="Rem(this);"') 7
                '</div><div class="frmed">',
                GetGL('crl','Cruise line:'),
                '<br/>',
                '', // GetDD('crl',arrCL,Cruiseline,'','',' onchange="Rem(this);CS();"') 11 
                '</div></div><div class="bl1"><div class="fl">',
                '<input id="res" name="res" type="checkbox" class="',
                m_strChkClass,
                '" onclick="SetRes();Rem(this);" /></div>',
                '<div ><label for="res">Check to see if I qualify for residency, previous cruiser, or senior rates</label></div>',
                '</div><div class="clearer"></div>'
            ];
        }
        

        m_Cr[3] = GetDD('tci',arrTD,TCityId,'large','',m_evtRem);
        m_Cr[7] = GetM(18,MDate,'','',m_evtRem);
        m_Cr[11] = GetDD('crl',arrCL,Cruiseline,'','',' onchange="Rem(this);CS();"');
        return m_Cr.join('');        
    }
    
    function _A_GetACity(v,f)
    {	
        if (m_A_aCity === undefined)
        {
            m_A_aCity = [
                '<div class="',
                '',
                '"><input id="tci',
                '',
                '" name="tci" type="radio" class="',
                m_strChkClass,
                '" value="',
                '',
                '" onclick="DE(\'tcy\').value=\'\';Rem(this);" /><label for="tci',
                '',
                '" id="lbltci',
				'',
				'">',
                '', 
                '</label></div>'
            ];
        }
	    var t = v.split('|');
	    m_A_aCity[1] = (f == 'right') ? 'frAmed' : 'flAmed';
	    m_A_aCity[3] = m_A_aCity[7] = m_A_aCity[9] = m_A_aCity[11] = t[0];
        m_A_aCity[13] = t[1];	    	
	    return m_A_aCity.join('');
    }
    
    function _A_GetCities()
    {
        var j = parseInt(arrACities.length / 2);
        var t = [];        
		
        for(var i =0;i<9;i++)
        {
            t[t.length] = '<div class="bl0">'; 
            t[t.length] = _A_GetACity(arrACities[i],'left');
            t[t.length] = _A_GetACity(arrACities[i + 9],'right');
            t[t.length] = '<div class="clearer"></div>';
            t[t.length] = '</div>';
        }
        return t.join('');		
    }
    
    function _A()
    {
        if (m_A === undefined)
        {
			m_A = [
				'<div class="bl0" style="margin-bottom:2px;">Find activities in:</div>',
				'<div class="bl0">',
				//_A_GetACity(arrACities[0],'left'),
				'',
				'<div class="clearer"></div></div>',
				_A_GetCities(),
				'<div class="bl0" style="padding-bottom:6px;">',
				'<div class="fl"><input id="tci-1" name="tci" type="radio" class="',
				m_strChkClass,
				'" value="-1" onclick="DE(\'tcy\').focus();Rem(this);" /><label for="tci-1">Other City:</label></div>',
				'<div class="fr"><input id="tcy" name="tcy" value="" type="text" maxlength="100" style="width:180px;" onfocus="this.select();DE(\'tci-1\').checked=true;" onchange="Rem(this)" /></div>',
				'<div class="clearer"></div></div>',
                '<div class="bl0" style="height:40px;">',
                '<div class="flmed">',
                GetGL('fdt','From:'),
                '<br/>',
                '',//GetDt('H','F'),15
                '</div>',
                '<div class="frmed">',
                GetGL('tdt','To:'),
                '<br/>',
                '',//GetDt('H','T'),20
                '</div>',
                '<div class="clearer"></div></div>',
                ''
			];
        }
		        
        m_A[15] = GetDt('H','F');
        m_A[20] = GetDt('H','T');
        return m_A.join('');		
    }

    return function()
    {
        var t = [];
        t[t.length] = GetSrchType();
        t[t.length] = '';//GetYL('When and where?');
        
        switch(cwid)
        {
            case '1':case '7':

                if (cwid == '7'){cst='1';}
                switch (cst)
                {
                    case '1':

                        t[t.length] = _GetFFDiv(bFlex);
                        t[t.length] = bFlex ? _FL() : _F('F');
                        break;
                    case '2':
                        t[t.length] = GetMDHTML(1);
                       break;
		            case '3':
	                    if (DE('md').value == '1'){maxD1 = maxD;}
			            for(var i = minD; i < (maxD1 + 1); i++)
			            {
                            t[t.length] = '<div class="bl2" style="color:#cc6600;font-weight:bold;">Flight ';
                            t[t.length] = i;
                            t[t.length] = '</div>';
                            t[t.length] = GetMDHTML(i);
			            }
			            if(maxD1 == 3)
			            {
                            t[t.length] = '<div class="bl1" style="padding-bottom:12px;"><a rel="nofollow" id="amd" href="javascript:md();" onkeydown="md();return false;">Need more flights and destinations?</a></div>';
			            }
			            break;                                
                    default:
                        t[t.length] = _F('F');
                        break;
                }                
                break;
            case '4':case '5':
                t[t.length] = _F('FHC');
                break;
            case '2':
                t[t.length] = _H('H');
                break;
            case '3':
                t[t.length] = _C();
                break;
            case '6':
                t[t.length] = _HC('HC');
                break;
            case '8':
                t[t.length] = _Cr();
                break;                
            case '9':
                t[t.length] = _A();
                break;      
            case '10':
                t[t.length] = _PPV();
                break;      
            default:break;                          
        }       
		
        return t.join('');
    }
})();

function GetSavedValues()
{   
	GetSavedValuesG();	
    var v;
    v = DE('ao').value;if(v != '') arrAO = v.split('|');
    v = DE('aFCity').value;if (v != '') {aFCity = v.split('|');}aFCity[0] = FCity;
    v = DE('aTCity').value;if (v != '') {aTCity = v.split('|');}aTCity[0] = TCity;
    v = DE('aFDate').value;if (v != '') {aFDate = v.split('|');}aFDate[0] = FDate;
    v = DE('aFTime').value;if (v != '') {aFTime = v.split('|');}aFTime[0] = FTime;
    switch(cwid)
    {
        case '1':
	        v = DE('Airline').value;if (v != '') {Airline = v;}
	        v = DE('Class').value;if (v != '') {Class = v;}
	        v = DE('bNS').value;if (v != '') {bNS = v;}
	        v = DE('bCP').value;if (v != '') {bCP = v;}
	        bFlex = DE('bFlex').value == '1' ? true : false;
            break;    
        case '3':
	        v = DE('TCityD').value;if (v != '') {TCityD = v;}
	        v = DE('Street').value;if (v != '') {Street = v;}
	        v = DE('TCity1').value;if (v != '') {TCity1 = v;}
	        v = DE('State').value;if (v != '') {State = v;}
	        v = DE('Zip').value;if (v != '') {Zip = v;}
	        v = DE('Radius').value;if (v != '') {Radius = v;}
	        v = DE('CarC').value;if (v != '') {CCl = v;}
	        v = DE('Vendor').value;if (v != '') {Vendor = v;}
	        v = DE('DC').value;if (v != '') {DC = v;}
	        v = DE('CorpC').value;if (v != '') {CorpC = v;}
	        v = DE('CoupC').value;if (v != '') {CoupC = v;}
	        v = DE('RateC').value;if (v != '') {RateC = v;}
	        v = DE('OtherC').value;if (v != '') {OtherC = v;}
	        v = DE('Equipment').value;if (v != '') {arrE = v.split(',');}                    
	        break;
        case '8':
	        v = DE('TCityId').value;if (v != '') {TCityId = v;}
	        v = DE('MDate').value;if (v != '') {MDate = v;}
	        v = DE('Cruiseline').value;if (v != '') {Cruiseline = v;}
	        v = DE('State').value;if (v != '') {State = v;}
	        v = DE('ro').value;if (v!= '') {Recidency = v; }
	        v = DE('bSE').value;if (v != '') {bSE = v;}
	        v = DE('bPC').value;if (v != '') {bPC = v;}
	        v = DE('PC').value;if (v != '') {arrE = v.split(',');}else{for(var i = 1; i < arrCL.length; i++){arrE[i] = '0';}}
	        v = DE('CLength').value;if (v != '') {CLength = v;}
	        v = DE('StarRC').value;if (v != '') {StarRC = v;}
	        v = DE('Port').value;if (v != '') {Port = v;}
	        v = DE('Ship').value;if (v != '') {Ship = v;}        
            break;	        
        case '2':
	        v = DE('Street').value;if (v != '') {Street = v;}
	        v = DE('TCity1').value;if (v != '') {TCity1 = v;}
	        v = DE('State').value;if (v != '') {State = v;}
	        v = DE('Zip').value;if (v != '') {Zip = v;}
	        v = DE('HName').value;if (v != '') {HName = v;}
	        v = DE('StarR').value;if (v != '') {StarR = v;}        
            break;        
        case '4':case '5':case '6':
	        v = DE('PFDate').value;if (v != '') {PFDate = v;}
	        v = DE('PTDate').value;if (v != '') {PTDate = v;}
	        v = DE('bPart').value;if (v != '') {bPart = v;}        
            break;
        case '7':
            bFlex = DE('bFlex').value == '1' ? true : false;
	        v = DE('Airline').value;if (v != '') {Airline = v;}
	        v = DE('Class').value;if (v != '') {Class = v;}
	        v = DE('bNS').value;if (v != '') {bNS = v;}
	        v = DE('bCP').value;if (v != '') {bCP = v;}			
            break;            
        case '9':
            v = DE('tciAct').value;if (v != '') {ActTci = v;}
            break;
        default:break;
    }    
}

function Rem(el)
{     
	RemG(el);
    var n = el.id.substr(3);
    if(n == ''){n = 1;}	
	switch(cwid)
	{
        case '1':
	        switch (el.id.substr(0,3))
	        {
		        case 'fcy':aFCity[n - 1] = el.value;DE('aFCity').value = aFCity.join('|');FCity = aFCity[0];DE('FCity').value = FCity;FTLA = FCity.toUpperCase();DE('FTLA').value = FTLA;break;
		        case 'tcy':aTCity[n - 1] = el.value;DE('aTCity').value = aTCity.join('|');TCity = aTCity[0];DE('TCity').value = TCity;TTLA = TCity.toUpperCase();DE('TTLA').value = TTLA;break;
		        case 'fdt':aFDate[n - 1] = el.value;DE('aFDate').value = aFDate.join('|');FDate = aFDate[0];DE('FDate').value = FDate;break;
		        case 'ftt':aFTime[n - 1] = el.value;DE('aFTime').value = aFTime.join('|');FTime = aFTime[0];DE('FTime').value = FTime;break;        		
		        case 'fct':aFCity[0] = el.options[el.selectedIndex].text;DE('aFCity').value = aFCity.join('|');FCity = aFCity[0];DE('FCity').value = FCity;break;
		        case 'tct':aTCity[0] = el.options[el.selectedIndex].text;DE('aTCity').value = aTCity.join('|');TCity = aTCity[0];DE('TCity').value = TCity;break;        		
		        case 'aln':Airline = el.value;DE('Airline').value = Airline;break;
		        case 'acl':Class = el.value;DE('Class').value = Class;break;
		        case 'nos':if(el.checked){bNS = '1';}else{bNS = '0';}DE('bNS').value = bNS;break;
		        case 'chp':if(el.checked){bCP = '1';}else{bCP = '0';}DE('bCP').value = bCP;break;
		        case 'flx':if(el.checked){DE('bFlex').value='1';bFlex=true;}else{DE('bFlex').value='0';bFlex=false;}break;
		        default:break;
	        }   
            break;
        case '2':
	        switch (el.id.substr(0,3))
	        {
		        case 'tsr':Street = el.value;DE('Street').value = Street;break;
		        case 'tct':TCity1 = el.value;DE('TCity1').value = TCity1;break;
		        case 'tst':State = el.value;DE('State').value = State;break;
		        case 'tzp':Zip = el.value;DE('Zip').value = Zip;break;
		        case 'hnm':HName = el.value;DE('HName').value = HName;break;
		        case 'str':StarR = el.value;DE('StarR').value = StarR;break;
		        default:break;
	        }        
            break;            
        case '3': 
	        switch (el.id.substr(0,3))
	        {
		        case 'tcy':if(n != ''){TCityD = el.value;DE('TCityD').value = TCityD;}break;
		        case 'tsr':Street = el.value;DE('Street').value = Street;break;
		        case 'tct':TCity1 = el.value;DE('TCity1').value = TCity1;break;
		        case 'tst':State = el.value;DE('State').value = State;break;
		        case 'tzp':Zip = el.value;DE('Zip').value = Zip;break;
		        case 'rds':Radius = el.value;DE('Radius').value = Radius;break;
		        case 'ccl':CCl = el.value;DE('CarC').value = CCl;break;
		        case 'ven':Vendor = el.value;DE('Vendor').value = Vendor;break;
		        case 'dcd':DC = el.value;DE('DC').value = DC;break;
		        case 'coc':CorpC = el.value;DE('CorpC').value = CorpC;break;
		        case 'cpc':CoupC = el.value;DE('CoupC').value = CoupC;break;
		        case 'rtc':RateC = el.value;DE('RateC').value = RateC;break;
		        case 'otc':OtherC = el.value;DE('OtherC').value = OtherC;break;
		        case 'equ':if(el.checked){arrE[n] = '1';}else{arrE[n] = '0';}DE('Equipment').value = arrE.join(',');break;
		        default:break;
	        }                   
            break;
        case '4':case '5':
	        switch (el.id.substr(0,3))
	        {
		        case 'pfd':PFDate = el.value;DE('PFDate').value = PFDate;break;
		        case 'ptd':PTDate = el.value;DE('PTDate').value = PTDate;break;
		        case 'prt':DE('bPart').value = el.checked ? '1' : '';		        
		        default:break;
	        }                 
	        break;
        case '7':
            switch (el.id.substr(0,3))
            {				
				case 'flx':if(el.checked){DE('bFlex').value='1';bFlex=true;}else{DE('bFlex').value='0';bFlex=false;}break;
		        case 'nos':if(el.checked){bNS = '1';}else{bNS = '0';}DE('bNS').value = bNS;break;
		        case 'chp':if(el.checked){bCP = '1';}else{bCP = '0';}DE('bCP').value = bCP;break;
		        case 'aln':Airline = el.value;DE('Airline').value = Airline;break;
		        case 'acl':Class = el.value;DE('Class').value = Class;break;                
                default:break;
            }        	        
        case '8':            
	        switch (el.id.substr(0,3))
	        {
		        case 'crl':Cruiseline = el.value;DE('Cruiseline').value = Cruiseline;break;
		        case 'tst':State = el.value;DE('State').value = State;break;
		        case 'sen':if(el.checked){bSE = '1';}else{bSE = '0';}DE('bSE').value = bSE;break;
		        case 'prc':if(el.checked){bPC = '1';}else{bPC = '0';}DE('bPC').value = bPC;break;
		        case 'pcl':if(el.checked){arrE[n] = '1';}else{arrE[n] = '0';}DE('PC').value = arrE.join(',');break;
		        case 'cle':CLength = el.value;DE('CLength').value = CLength;break;
		        case 'str':StarRC = el.value;DE('StarRC').value = StarRC;break;
		        case 'por':Port = el.value;DE('Port').value = Port;break;
		        case 'shi':Ship = el.value;DE('Ship').value = Ship;break;
		        case 'res':if(el.checked){DE('ro').value = Recidency = '1';}else{DE('ro').value = Recidency = '0';} break;
		        default:break;
	        }        	           
	        break;
        case '9':
            switch (el.id.substr(0,3))
            {                
                case 'tci':
					DE('tciAct').value = ActTci = el.value;
					if (ActTci != '-1') DE('TCity').value = TCity = aTCity[0] = DE('lbltci'+ActTci).innerHTML;
					DE("LsTOverride").value="true";
					break;
				case 'tcy':
					DE('TCity').value = TCity = DE('tciAct').value = aTCity[0] = ActTci = el.value;
					DE("LsTOverride").value="true";
					break;
                default:break;
            }
			DE('aTCity').value = aTCity.join('|');
            break;	        
        default:break;
	}
}




var SetMOT = (function()
{
    var m_t = {
        '1':'Airline, first or business class, nonstop only',
        '2':'Hotel name, hotel class',
        '3':'Need any special equipment?',
		'7':'Airline, first or business class, nonstop only',
        '8':'Cruise ship, departure port, star rating...'
    };    
    
    var m_div = 'divO1';        
    var m_lbl1 = GetYL('Additional options:');
    var m_html = [
		m_lbl1,
        '<a rel="nofollow" href="#" onmouseover="window.status=\'',
        '',
        '\';return(true);" onmouseout="window.status=\'\'" onclick="SetAO(\'1\');" onkeydown="if(event.keyCode==13){SetAO(\'1\')};return true;">',
        '',
        '</a>'        
    ];
    
    return function(id)
    {       
		var isFFlex = (cwid == 1 && cst == 1 && bFlex) || (cwid == 7 && bFlex); 
        if( ('1' == id && !isFFlex) || ('7' == id && !isFFlex) || '2' == id || '3' == id || '8' == id)
        {
            SH1(m_div,1);            
            m_html[2] = m_html[4] = m_t[id];
            SetIH(m_div, m_html.join('') );
        }
        else
        {
            SH1(m_div,0);
        }
    };
})();


function SetAO()
{		    
	if (cwid == 1 && cst == 1 && bFlex) 
	{
		SH1('divO1',0);
		return;
	}
	
	SetIH('divO1',GetAOHTML());
	switch(cwid)
	{
		case '3':
			DE('imgH1').src = imgHand.src;
			DE('imgH2').src = imgHand.src;
			break;
		case '8':
			var t;
			if((t = DE('crl')) && t.selectedIndex == 0){SH1('divShip',0);}
			break;
        default:break;			
	}		
	arrAO[cwid]='1';
	DE('ao').value = arrAO.join('|');	
}


var SetST = (function()
{
    var m_t = {
    '1':'Search for flights',
    '2':'Search for hotels',
    '3':'Search for cars',
    '4':'Search for flights + hotels',
    '5':'Search for flights + hotels + cars',
    '6':'Search for hotels + cars',
    '7':'Search for flights + cars',
    '9':'Search for activities',
    '10':'Search for pre-packaged vacations'
    };    
    
    var m_html_btn= [                
        '<div style="float:right;">',
        '<div style="text-align:right; font-size:12px; font-family:Arial, Helvetica, sans-serif; margin-top:8px;" onmouseout="window.status=\'\'" onmouseover="stmo(\'',
        '',
        '\');"><a href="javascript:CF();" onmouseout="window.status=\'\'"  onmouseover="stmo(\'',
        '',
        '\');"><img src="http://media.expedia.com/media/content/expus/graphics/common/arrows/btn_wizard-search.gif" border="0" alt="',
        '',
        '" width="20" height="20" style ="margin: 0px 4px 2px 0px; vertical-align: middle;padding-bottom:3px"/></a>',
        '<span style="vertical-align: middle;"><a href="javascript:CF();"><B>',
        '',
        '</B></a></span></div></div>'
    ];        
    
    var m_h9r = 'Request 9+ hotel rooms';
    var m_div = 'divWst';
    var m_e = ' onclick="SF();" ';
    var m_e4 = [' onclick="SFBundle(','',');" onkeypress="if(event.keyCode==13){SFBundle(','',');}" '];
    var m_btmStyle = ' style="margin-top:8px;" ';
    var m_html = ['',''];

    function SetSTG2(text,evt,style)
    {
        if ('' == text) return '';        
        m_html_btn[2] = text;
        m_html_btn[4] = text;        
        m_html_btn[6] = text;        
        m_html_btn[9] = text;        
        return m_html_btn.join('');       
    }
    
    return function(id)
    {	
//        if (id == '1' && !bFlex && cst == '1' )		
//        {
//			m_e4[1] = m_e4[3] = '3';
//            m_html[0] = SetSTG2(m_t[id], m_e, '');
//            if (m_html[1] == '') m_html[1] = SetSTG2(m_t['4'], m_e4.join('') , m_btmStyle);
//            SetIH(m_div,m_html.join(''));
//        }
//        else
//        {
            if (id == '2' && rooms == 9) { SetIH(m_div, SetSTG2(m_h9r,m_e,''));}
            else { SetIH(m_div, SetSTG2(m_t[id],m_e,''));}                
//        }
    };
})();

function SetST_(id)
{ 
	switch (id)
	{
		case '1':SText = 'Search for flights';break;
		case '2':SText = 'Search for hotels';break;
		case '3':SText = 'Search for cars';break;
		case '4':SText = 'Search for flights + hotels';break;
		case '5':SText = 'Search for flights + hotels + cars';break;
		case '6':SText = 'Search for hotels + cars';break;
		case '7':SText = 'Search for flights + cars';break;
		case '9':SText = 'Search for activities';break;
		case '10':SText = 'Search for pre-packaged vacations';break;
		
	}
	SetSTG();
}


function GetRASCCAString()
{
	var k = '';
	switch (cwid)
	{
		case '1':
		case '7':
			k += '&NumRoom=1';
			k += '&NumAdult=' + aRA[0];
			k += '&NumSenior=' + aRS[0];
			if (aRC[0] > 0)
			{
				k += '&NumChild=' + aRC[0];
				for (var i = 0; i < aRC[0]; i++)
				{
					k += '&Child' + (i + 1) + 'Age=' + aRCA[0][i];
				}
				if (Inf == 's'){k += '&InfantInSeat=1';}
				else{k += '&InfantInSeat=2';}
			}
			break;
		case '2':
		case '4':
		case '5':
		case '6':
			k += '&NumRoom=' + nR;
			for (var i = 0; i < nR; i++)
			{
				if (nR == 1){k += '&NumAdult=' + aRA[i];k += '&NumSenior=' + aRS[i];}
				else{k += '&NumAdult' + (i + 1) + '=' + aRA[i];k += '&NumSenior' + (i + 1) + '=' + aRS[i];}
				if (aRC[i] > 0)
				{
					if (nR == 1){k += '&NumChild=' + aRC[i];}
					else{k += '&NumChild' + (i + 1) + '=' + aRC[i];}
					for (var j = 0; j < aRC[i]; j++)
					{
						if (i == 0){k += '&Child' + (j + 1) + 'Age=' + aRCA[i][j];}
						else{k += '&Rm' + (i + 1) + 'Child' + (j + 1) + 'Age=' + aRCA[i][j];}
					}
				}
			}
			if (Inf == 's'){k += '&InfantInSeat=1';}
			else{k += '&InfantInSeat=2';}
			break;		
		default:break;
	}
	return k;
}

function GetCruiseDatesString()
{
	var k = '';
	if (MDate == '1/1/4501'){k = '&sdat=1/1/4501';}
	else
	{
		var aD = MDate.split('-');
		var cd = new Date();
		if ((aD[0]==cd.getMonth()) && (aD[1]==cd.getFullYear())){k += '&sdat=' + (cd.getMonth() + 1) + '/' + cd.getDate() + '/' + cd.getFullYear();}
		else{k += '&sdat=' + (parseInt(aD[0]) + 1) + '/1/' + aD[1];}
	}
	return k;
}


var GetAOHTML = (function()
{
    var m_tl,       // array of all label 1 
        m_ti,       // array of all label 2
        m_te,       // array of all tooltip text
        m_t8,       // array of additional label for cruise 
        m_html1,    // array to hold ao html cwid 1, 2 or so on	
        m_html2,
        m_html3,
        m_html8,
		m_arrCurStar
    ;   
    
    var m_style = (document.all) ? 'margin-left:-4px;' : 'margin-left:-1px;';
    var m_evt = ' onchange="Rem(this);"';
	var m_aolbl = GetYL('Additional options:');
    
    function _init()
    {
        m_tl = {'1':'More info','3':'Availability and cost info','8':'Choosing Preferences'};
        m_ti = {'1':'No preference search','3':'Availability and cost of special equipment','8':'Choosing Preferences'};
        m_te = {
                '1':'A no preference search covers those airlines to which Expedia has access, which is most airlines. The flights displayed are those for which Expedia	was able to confirm availability. By searching for flights on more than just one airline, you may be able to find additional choices and possibly even lower prices.',
                '3':'Special equipment options may not be available for all cars or at all rental locations. Your selection(s) will be sent to the car vendor as a request; they are not guaranteed. <b>Before you depart, be sure to confirm with the car vendor that your requested equipment will be available. Please note that the car vendor may apply additional charges for the equipment you select.</b>',
                '8':'You may restrict your search by designating ship and port preferences. However, keep in mind that choosing detailed search criteria often decreases the number of cruises we are able to find for you. To find more cruises, please limit the number of preferences you choose.'                
            };
    }
    
    function _init1()
    {          
        m_html1 = [
                m_aolbl,
				'<div class="bl2">Low fare note: To increase your chances of finding low fares, leave the following unchecked.</div>',
                '<div class="bl1" style="padding-bottom:0px;">',
                '',
                '</div>',
                '<div class="bl1" style="padding-bottom:12px;">',
                '',
                '</div>',
                '<div class="bl3">',
                '<div class="flmed">',
                GetGL('aln','Airline:'),
                '<br/>',
                '',
                '</div>',
                '<div class="frmed">',
                GetGL('acl','Class:'),
                '<br/>',
                '',
                '</div>',
                '</div>',
                '<div class="bl1"  style="padding-top:3px;">',
                GetTT(m_tl['1'],m_ti['1'],m_te['1'],250,'','',true),
                '</div>',
                '<div class="clearer"></div>'
            ];    
    }
    
    function _init2()
    {
        m_html2 = [
			m_aolbl,
            '<div class="bl1" style="padding-top:3px;">',
            '<div class="flmed">',
            GetGL('hnm','Hotel name:'),
            '<br/>',
            '',
            '</div>',
            '<div class="frmed">Hotel class:<br/>',
            '',
            '</div>',
            '</div>',
            '<div class="clearer"></div>'
        ];
    }
    
    function _init3()
    {   
        m_html3 = [
			m_aolbl,
            '<div class="bl1" style="padding-top:3px;">Do you need any special equipment?</div>',
            '<div class="bl1">',
            GetTT(m_tl['3'],m_ti['3'],m_te['3'],275,'','',true),
            '</div>',
            '<div class="fl">',
            '<div class="flmed">',
            '',
            '</div>',
            '<div class="frmed">',
            '',
            '</div>',
            '</div>',
            '<div class="fl">',
            '<div class="flmed">',
            '',
            '</div>',
            '<div class="frmed">',
            '',
            '</div>',
            '</div>',
            '<div class="fl">',
            '<div class="flmed">',
            '',
            '<img id="imgH1" src="" alt="" style="margin-left:3px;"/></div>',
            '<div class="frmed">',
            '',
            '<img id="imgH2" src="" alt="" style="margin-left:2px;"/></div>',
            '</div>',
            '<div class="fl">',
            '',
            '</div>',
            '<div class="clearer"></div>'
        ];
    }
    
    function _init8()
    {   
        m_t8 =  {
            'tl':'Star Rating:',
            'ti':'Star Ratings',
            'te':'Star ratings are provided by Cruise Critic and are based on various criteria, including the ship, its amenities, and its itineraries.<ol type=disc><li>Five stars plus: Total luxury</li><li>Five stars: Highest levels of quality</li><li>Four stars plus: Excellent experience</li><li>Four stars: Very good experience</li><li>Three stars plus: Average experience</li><li>Three stars: Modest experience</li><li>Two stars: Avoid this ship</li></ol>'
        };        
		
		m_arrCurStar = ['0|Show all','1|1 Star or more','3|2 Stars or more','5|3 Stars or more','7|4 Stars or more','9|5 Stars'];
                
        m_html8 = [
			m_aolbl,
            '<div class="bl1" style="padding-top:3px;">',
            GetTT(m_tl['8'],m_ti['8'],m_te['8'],0,'','',true),
            '</div>',
            '<div class="bl1">',
            '<div class="flmed">',
            GetGL('cle','Cruise Length:'),
            '<br/>',
            '',
            '</div>',
            '<div class="frmed">',
            GetTT(m_t8['tl'],m_t8['ti'],m_t8['te'],0,'','',false),
            '<br/>',
            '',
            '</div>',
            '</div>',
            '<div class="bl1">',
            GetGL('por','Only show cruises departing from: (ex: Miami)'),
            '<br/>',
            '',
            '</div>',
            '<div class="bl1" id="divShip">',
            GetGL('shi','Ship:'),
            '<br/>',
            '', 
            '</div>',
            '<div class="clearer"></div>'
        ];    
    }
    
    return function()
    {
        if (m_tl === undefined) {_init();}
        switch(cwid)
        {
            case '1':
			case '7':
                if (m_html1 === undefined) {_init1();}
                m_html1[3] = GetCB('nos','','Nonstop only',bNS,'',m_style,m_evt);
                m_html1[6] = GetCB('chp','','Avoid most change penalties',bCP,'',m_style,m_evt);
                m_html1[12] = GetDD('aln',arrAL,Airline,'','',m_evt);
                m_html1[17] = GetDD('acl',arrAC,Class,'','',m_evt);
                return m_html1.join('');
                break;
            case '2':
                if (m_html2 === undefined) {_init2();}
                m_html2[5] = GetGI('hnm',HName,'','',' onfocus="HCal();this.select();" onchange="Rem(this);"','80');
                m_html2[8] = GetDD('str',arrSR,StarR,'','',m_evt);
                return m_html2.join('');
                break;
            case '3':
                if (m_html3 === undefined) {_init3();}
                m_html3[7] = GetCB('equ0','I','Infant car seat',arrE[0],'','',m_evt,'');
                m_html3[10] = GetCB('equ1','T','Toddler car seat',arrE[1],'','',m_evt,''); 
                m_html3[15] = GetCB('equ2','S','Ski rack',arrE[2],'','',m_evt,'');
                m_html3[18] = GetCB('equ3','W','Snow chains',arrE[3],'','',m_evt,'');
                m_html3[23] = GetCB('equ4','L','Left hand control',arrE[4],'','',m_evt,'');
                m_html3[26] = GetCB('equ5','R','Right hand control',arrE[5],'','',m_evt,'');
                m_html3[30] = GetCB('equ6','N','Navigational system',arrE[6],'','',m_evt,'');
                return m_html3.join('');
                break;
            case '8':
                if (m_html8 === undefined) {_init8();}
                m_html8[8] = GetDD('cle',arrLE,CLength,'','',m_evt);
                m_html8[13] = GetDD('str',m_arrCurStar,StarRC,'','',m_evt);
                m_html8[19] = GetGI('por',Port,'large','',' onblur="Rem(this);"','100');
                m_html8[24] = GetDD('shi',arrSH[DE('crl').selectedIndex],Ship,'','',m_evt);
                return m_html8.join('');
                break;                                                
            default:return '';break;
        }
    };    
})(); // end GetAOHTML()

var GetResHTML = (function(){
    var m_html, m_tt_sen, m_evt, m_prclbl; 
    
    function _init()
    {
        m_tt_sen = [
            'Someone in my party is a ',
            GetTT(
                'senior',
                'Senior rates',
                'For most cruise lines the senior age is 55. Any exceptions will be noted when you select your cabin category.',
                200,'','',false)
            ];

        m_html = [
                '<div class="bl1">To see if you qualify for any special rates, please give us a little more information (optional):</div>',
                '<div class="bl1">',
                GetGL('tst','Where do you live?'),
                '<br/>',
                '', // 4: GetDD('tst',arrST1,State,'','',' onchange="Rem(this);"'),
                '</div>',
                '<div class="fl">',
                '', // 7: GetCB('sen','','Someone in my party is a ' + GetTT(tl,ti,te,200,'','',false),bSE,'','',' onchange="Rem(this);"','')
                '</div>',
                '<div class="bl1">',
                '', // 10: GetCB('prc','','Someone in my party has cruised before',bPC,'','',' onclick="SetCL();" onchange="Rem(this);"','')
                '</div>',
                '<div class="bl1" id="divCL" style="display:none;"></div>',
                '<div class="clearer"></div>'
            ];    
            
        m_evt = [
            ' onchange="Rem(this);"',
            ' onclick="SetCL();" onchange="Rem(this);"'
        ];
        
        m_prclbl = 'Someone in my party has cruised before';
    }

    return function ()
    {
        if(m_html === undefined){_init();}
        
        m_html[4] = GetDD('tst',arrST1,State,'','',m_evt[0]);
        m_html[7] = GetCB('sen','',m_tt_sen.join(''),bSE,'','',m_evt[0],'');
        m_html[10] = GetCB('prc','',m_prclbl,bPC,'','',m_evt[1],'');
        
        return m_html.join('');
    }
        
})();

function SetRes()
{
    id = 'divRes';
    if(DE('res').checked)
    {
        DE('ro').value = '1';
        SH1(id,1);
	    SetIH(id,GetResHTML());
	    SetCL();
    }
    else
    {
        DE('ro').value = '0';
        SH1(id,0);
    }
}

function SetCL()
{
    var id = 'divCL';
    var t = [];
    var a;
    var arrCL1 = arrCL.slice(1);

    if(DE('prc').checked)
    {
        t[t.length] = '<div class="bl1">Which lines have you cruised with?</div>';
        var j = Math.round(arrCL1.length/2);
	    for (var i = 0; i < j; i++) 
		{
	        a = arrCL1[i].split('|');
	        t[t.length] = '<div class="fl">';
	        if(typeof(arrCL1[i + j]) != 'undefined')
	        {
	            t[t.length] = '<div class="flmed">' + GetCB('pcl' + i,a[0],a[1],arrE[i],'','',' onchange="Rem(this);"','') + '</div>';
	            a = arrCL1[i + j].split('|');
	            t[t.length] = '<div class="frmed">' + GetCB('pcl' + (i + j),a[0],a[1],arrE[i + j],'','',' onchange="Rem(this);"','') + '</div>';
	        }
	        else
	        {
	            t[t.length] = GetCB('pcl' + i,a[0],a[1],arrE[i],'','',' onchange="Rem(this);"','');
	        }
	        t[t.length] = '</div>';
		} 
        SH1(id,1);
        SetIH(id,t.join(''));
    }
    else
    {
        SH1(id,0);
    }
}

function CS()
{
	if (arrAO[8] == '1')
	{
	    var id = 'divShip';
	    if(DE('crl').selectedIndex == 0)
	    {
	        SH1(id,0);
	    }
	    else
	    {
	        SH1(id,1);
            SetIH(id,GetGL('shi','Ship:') + '<br/>' + GetDD('shi',arrSH[DE('crl').selectedIndex],Ship,'','',' onchange="Rem(this);"'));
	    }
    }
}

var GetMDHTML = (function(){
    var m_html, m_evt, m_n = 0;    
    
    function _init()
    {
        m_evt = [
                ' autocomplete="off" onfocus="HCal();this.select();" onchange="Rem(this);"',
                ' onblur="Rem(this);" onclick="event.cancelBubble=true;SC(this);" onfocus="SC(this);"',
                ' onfocus="HCal();" onchange="Rem(this);"'
            ];    
            
        m_html = [
                '<div class="bl1">',
                '<div class="flmed">',
                '', 
                '<br/>',
                '', 
                '</div>',
                '<div class="frmed">',
                '', 
                '<br/>',
                '', 
                '</div>',
                '</div>',
                '<div class="bl1" style="padding-bottom:14px;">',
                '<div class="flmed">',
                '<div class="fl">',
                '', 
                '<br/>',
                '', 
                '</div>',
                '<div class="fr">',
                '', 
                '<br/>',
                '', 
                '</div>',
                '</div>',            
                '</div>',
                '<div class="clearer"></div>'
            ];    
    }
    
    return function(i)
    {    
        if (m_html === undefined) { _init(); }        
        if (i > 1) 
		{ 
			m_n  = i; 
		} 
		else
		{ 
			m_n  = '';
		}	
		
        m_html[2] = GetGL('fcy' + m_n,'Leaving from:');
        //THIS BUILDS THE FROM BOX
        
        m_html[4] = GetGI('fcy' + m_n, aFCity[i - 1],'','',m_evt[0],'100');
        //m_html[4] = GetGI('fcy' + m_n, FCity,'','',m_evt[0],'100');
        
        m_html[7] = GetGL('tcy' + m_n,'Going to:');
        if(DE("LsTOverride").value == "" && i == 1){
			m_html[9] = GetGI('tcy' + m_n, GetDestination(),'','',m_evt[0],'100');
		}
		else{
			m_html[9] = GetGI('tcy' + m_n, aTCity[i - 1],'','',m_evt[0],'100');
		}
		
		m_html[15] = GetGL('fdt' + m_n,'Departing:');
        m_html[17] = GetGI('fdt' + m_n, aFDate[i - 1],'small','',m_evt[1],'12');
        m_html[20] = GetGL('ftt' + m_n,'Time:');
        m_html[22] = GetDD('ftt' + m_n,arrT1, aFTime[i - 1],'small','',m_evt[2]);
        return m_html.join('');
    }
})();

function md()
{
    DE('md').value = '1';
    maxD1 = maxD;
    pwid = '';
    hw('1');
}

function GetDefaultF(E)
{
	var t = '';
	switch (E)
	{
		case 'FCity':for (var i = minD; i < (maxD + 1); i++){t += ',';}break;
		case 'TCity':for (var i = minD; i < (maxD + 1); i++){t += ',';}break;
		case 'FDate':for (var i = minD; i < (maxD + 1); i++){t += 'dd/mm/yyyy,';}break;
		case 'FTime':for (var i = minD; i < (maxD + 1); i++){t += '362,';}break;
	}
	return t.substr(0,t.length-1);
}

function BuildDC()
{
    var d = 'divCC';
    var t = ''; 
        
	switch (cwid)
	{
	    case '3':
	        t += GetYL('Rental car preferences:');
			t += '<div class="bl1">' + GetGL('ccl','Car type:') + '<br/>' + GetDD('ccl',arrCC,CCl,'large','',' onchange="Rem(this);"') + '</div>';
			t += '<div class="bl1">' + GetGL('dcd','Do you have a discount code?') + '<br/>' + GetDD('dcd',arrDC,DC,'large','',' onchange="Rem(this);SetV();"') + '</div>';
			t += '<div class="bl1" id="divV" style="display:none;"></div>';
			t += '<div class="bl1" id="divDC" style="display:none;"></div>';
			t += '<div class="clearer"></div>';
	        break;
	    case '7':
			t += GetYL('Rental car preferences:');
			t += '<div class="bl1">' + GetGL('ccl','Car type:') + '<br/>' + GetDD('ccl',arrCC,CCl,'large','',' onchange="Rem(this);"') + '</div>';
			t += '<div class="clearer"></div>';
	        break;
		default:break;
	}			
    if(t != ''){SH1(d,1);SetIH('divCC',t);
    if(cwid == '3'){SetV();}}else{SH1(d,0);}    
    
}
function SetV()
{   
    var t = GetGL('ven','Rental car company:') + '<br/>';
	switch (DC)
	{
	    case '1':
			t = t + GetV(Vendor,'large','',' onchange="Rem(this);"');
	        break;
	    case '2':
			t = t + GetDD('ven',arrVv,Vendor,'large','',' onchange="Rem(this);SetDC();"');
	        break;
	    case '3':
			t = t + GetDD('ven',arrV,Vendor,'large','',' onchange="Rem(this);SetDC();"');
	        break;
		default:break;
    }
    SH1('divV',1);
    SetIH('divV',t);
    SetDC();
}

function GetV(d,c,s,j)
{
    var c1 = 'class="med" ';
    var s1 = '';
	if(c != ''){c1 = 'class="' + c + '" ';}
	if(s != ''){s1 = 'style="' + s + '" ';}
	var t = ['<select id="ven" name="ven" ',c1,s1,j,'><option value="">No Preference</option><optgroup label="Preferred Vendors"><option value="AL">Alamo Rent A Car</option><option value="ZD">Budget</option><option value="ZR">Dollar Rent A Car</option><option value="ET">Enterprise</option><option value="EP">Europcar</option><option value="ZE">Hertz</option><option value="ZL">National Car Rental</option><option value="ZT">Thrifty Car Rental</option></optgroup><optgroup label="More Companies"><option value="AC">ACE Rent A Car</option><option value="AD">Advantage Rent-A-Car</option><option value="ZI">Avis</option><option value="DS">Discount Car Rentals</option><option value="ZA">Payless</option><option value="SX">Sixt</option></optgroup></select>'].join('');
	return t.replace('value="' + d + '"','selected="selected" value="' + d + '"');
}

function SetDC()
{    
    var d = DE('divDC');
    var t = '';
    var t1 = '';
    var t2 = '';
    var t3 = '';
    var a;
    
    var v = DE('ven');   

    if(v.selectedIndex > 0)
    {
        a = arrV1[v.options[v.selectedIndex].value].split('|');
        if(DE('dcd').value == '2')
        {
	        t += '<div class="bl1">' + GetGL('coc',a[1] + ':') + '<br/>' + GetGI('coc',CorpC,'','',' onchange="Rem(this);"','100') + '</div>';
        }
        if(DE('dcd').value == '3')
        {
	        if(a[2] != ' '){a[2] = GetGL('cpc',a[2] + ':') + '<br/>' + GetGI('cpc',CoupC,'','',' onchange="Rem(this);"','100');}
	        if(a[3] != ' '){a[3] = GetGL('rtc',a[3] + ':') + '<br/>' + GetGI('rtc',RateC,'','',' onchange="Rem(this);"','100');}
	        if(a[4] != ' '){a[4] = GetGL('otc',a[4] + ':') + '<br/>' + GetGI('otc',OtherC,'','',' onchange="Rem(this);"','100');}
	        if(a[3] != ' ')
	        {
	            t1 = a[3];
	            if(a[2] != ' ')
	            {
	                t2 = a[2];
	                if(a[4] != ' ')
	                {
	                    t3 = a[4];
	                }
	            }
	        }
	        else if(a[2] != ' ')
	        {
	            t1 = a[2];
	            if(a[4] != ' ')
	            {
	                t2 = a[4];
	            }
	        }
	        else if(a[4] != ' ')
	        {
	            t1 = a[4];
	        }
	        if(t1 != '' && t2 != '')
	        {
	            t += '<div class="bl1">';
	            t += '<div class="flmed">' + t1 + '</div>';
	            t += '<div class="frmed">' + t2 + '</div>';
	            t += '</div>';
	            if(t3 != '')
	            {
	                t += '<div class="bl1">' + t3 + '</div>';
	            }
	        }
	        else if(t1 != '')
	        {
	            t += '<div class="bl1">';
	            t += '<div class="flmed">' + t1 + '</div>';
	            if(t3 != '')
	            {
	                t += '<div class="frmed">' + t3 + '</div>';
	            }
	            t += '</div>';
	        }
	        else if(t2 != '')
	        {
	            t += '<div class="bl1">';
	            t += '<div class="flmed">' + t2 + '</div>';
	            if(t3 != '')
	            {
	                t += '<div class="frmed">' + t3 + '</div>';
	            }
	            t += '</div>';
	        }
	        else if(t3 != '')
	        {
	            t += '<div class="bl1">' + t3 + '</div>';
	        }
        }
        t += '<div class="clearer"></div>';
    } 
    if(t != ''){SH1('divDC',1);SetIH('divDC',t);}else{SH1('divDC',0);}
}

function SetPart() 
{
    var id = 'divPart';
    if(DE('prt').checked)
    {
        bPart = '1';
        DE('bPart').value = '1';
        SH1(id,1);
	    SetIH(id,GetPartialHTML());
    }
    else
    {
        bPart = '0';
        DE('bPart').value = '0';
        SH1(id,0);
    }
}

var GetPartialHTML = (function(){
    var m_html = [
        '<div class="bl2">When do you need a hotel? (Check-in and check-out dates must be within dates of travel.)</div>',
        '<div class="bl1">',
        '<div class="flmed">',
        GetGL('pfd','Check-in:'),
        '<br/>',
        '',
        '</div>',
        '<div class="frmed">',
        GetGL('ptd','Check-out:'),
        '<br/>',
        '',
        '</div></div>'];
    var m_evt = [
        ' onblur="Rem(this);UpdDt(this);" onclick="event.cancelBubble=true;SC(this);" onfocus="SC(this);"',
        ' onblur="Rem(this);" onclick="event.cancelBubble=true;SC(this);" onfocus="SC(this);"'
    ];        
    return function()
    {
        m_html[5] =  GetGI('pfd',PFDate,'','',m_evt[0],'12');
        m_html[10] = GetGI('ptd',PTDate,'','',m_evt[1],'12');
        return m_html.join('');
    }
})();

function SH1(id,s){var e = DE(id);if(s){e.style.display = 'block';}else{e.style.display = 'none';}}
