// JavaScript Document

function changeAll() {change('tab_1','norm_tab');change('tab_2','norm_tab');change('tab_3','norm_tab');change('tab_4','norm_tab');change('tab_5','norm_tab');change('tab_6','norm_tab');change('tab_7','norm_tab');change('tab_8','norm_tab');}
	
	// hide and show id's
	function hideAll() {hide('hotel_frame');hide('air_frame');hide('airHotel_frame');hide('car_frame');hide('lmd_frame');hide('cruise_frame');hide('nav_frame');hide('general_frame');hide('cruise_info_frame');}
	// hide all subs
	function hideAllSub() {hide('hotel_help');hide('air_help');hide('custom_help');hide('cars_help');hide('lmd_help');hide('cruise_help');hide('tracker_help');hide('faq');hide('web_support');hide('contact');hide('cruise_info_why');hide('cruise_info_toknow');hide('cruise_info_honeymoon');hide('cruise_info_dest');hide('cruise_info_contact');hide('cruise_info_articles');}

// toggle search boxes and higlights tabs
	function helpcenterFlip () {
		
	}
	function flip(idLayer){
	   //document.images[idLayer].src = 'images/nav_' + idLayer + '_select.gif';
	   selectimg = idLayer;

		hideAll();
		if (idLayer=='1' || idLayer=='hotel'){ searchType = "hotel";show('hotel_frame');changeAll();change('tab_1','active_tab');}
		if (idLayer=='2' || idLayer=='air'){ searchType = "air";show('air_frame');changeAll();change('tab_2','active_tab');}
		if (idLayer=='3' || idLayer=='customtrip'){searchType = "airHotel";show('airHotel_frame');changeAll();change('tab_3','active_tab');}
		if (idLayer=='4' || idLayer=='car'){searchType = "car";show('car_frame');changeAll();change('tab_4','active_tab');}
		if (idLayer=='5' || idLayer=='lmd'){searchType = "lmd";show('lmd_frame');changeAll();change('tab_5','active_tab');}
		if (idLayer=='6' || idLayer=='cruise'){searchType = "cruise";show('cruise_frame');changeAll();change('tab_6','active_tab');}
		if (idLayer=='7' || idLayer=='navhelp'){show('nav_frame');}
		if (idLayer=='8' || idLayer=='generalhelp'){show('general_frame');}
		if (idLayer=='9' || idLayer=='cruiseinfo'){show('cruise_info_frame');}
	}

// toggle help pages by sub nav
	function flip_sub(idLayer){
	   //document.images[idLayer].src = 'images/nav_' + idLayer + '_select.gif';
		selectimg = idLayer;

		hideAllSub();
		if (idLayer=='hotel_help'){ show('hotel_help'); }
		if (idLayer=='air_help'){ show('air_help'); }
		if (idLayer=='custom_help'){ show('custom_help'); }
		if (idLayer=='cars_help'){ show('cars_help'); }
		if (idLayer=='lmd_help'){ show('lmd_help'); }
		if (idLayer=='cruise_help'){ show('cruise_help'); }
		if (idLayer=='tracker_help'){ show('tracker_help'); }
		if (idLayer=='faq'){ show('faq'); }
		if (idLayer=='web_support'){ show('web_support'); }
		if (idLayer=='contact'){ show('contact'); }
		
		if (idLayer=='cruise_info_why'){ show('cruise_info_why'); }
		if (idLayer=='cruise_info_toknow'){ show('cruise_info_toknow'); }
		if (idLayer=='cruise_info_honeymoon'){ show('cruise_info_honeymoon'); }
		if (idLayer=='cruise_info_dest'){ show('cruise_info_dest'); }
		if (idLayer=='cruise_info_contact'){ show('cruise_info_contact'); }
		if (idLayer=='cruise_info_articles'){ show('cruise_info_articles'); }
	}

	// hide all cruise subs
	function hideCruiseSubs() {hide('cruise_destination');hide('cruise_port');hide('cruise_date');hide('cruise_line');hide('cruise_ship');}

// toggle help pages by sub nav
	function flip_cruise_sub(idLayer){

hideCruiseSubs();
		if (idLayer=='cruise_destination'){ show('cruise_destination'); }
		if (idLayer=='cruise_port'){ show('cruise_port'); }
		if (idLayer=='cruise_date'){ show('cruise_date'); }
		if (idLayer=='cruise_line'){ show('cruise_line'); }
		if (idLayer=='cruise_ship'){ show('cruise_ship'); }
	}

function init_originations_ideas(objFormName) {

		var orig = objFormName.in_origination_key;
		orig.options[0] = new Option('Choose a City', 'all');
		var i = 1;
		for (o in originations) {
				orig.options[i] = new Option(originations[o], o); 
				i++;
		}
		var idx = 0;
		i = 1;
		for (k in originations) {
			if (k == 371)
				break;
			i++;
		}
		orig.selectedIndex = 0;
}

function last_minute_deals(searchStr,src_aid, src, search_travel_link)
	{
		var wct_lmd_url = "http://" + search_travel_link + "/nexres/start-pages/gateway.cgi?engine=LASTMINDEALS&action=search&src=" + src + "&src_aid=" + src_aid;
	  var lmd_str;
	  var lmd_orig_city = "&in_origination_key=" + document.needIdeas_a.in_origination_key.value;
	  if (document.needIdeas_a.in_origination_key.value == 'all') {
	  document.needIdeas_a.in_origination_key.focus;
	  alert ("Please Select the City you are traveling from!");
	  } 
	  else
	  {
	  if (searchStr == '250') {
		lmd_str = "&in_cost_string=" + searchStr;
	  } 
	  else
	  {
	    if (searchStr == '5000560') {
			lmd_str = "&in_activity=" + searchStr;
		} 
		else 
		{
		  lmd_str = "&in_search_string=" + searchStr;
		 }
	  }
	  
	  wct_lmd_url += lmd_str + lmd_orig_city;

	  popURL(wct_lmd_url,'hotel');
	  }
	}
	
	YAHOO.namespace("example.calendar");

	// to redirect to 4hr car advanced search page
	function go() {
	
		   var destination = document.CarSearch.puwhere.value;
	
		   var re = new RegExp('CarRequest');
		   var m = re.exec(destination);
		   if (m != null)
		   {
				   //location.target="_blank";
				   top.location.href = destination;
		   } else {
				   return false;
		   }
	}

	function newWindow(curr)
	{
		currWindow = window.open(curr, 'CurrConverter', 'width=460,height=310');
		currWindow.focus;
	}

function processForm(formObj, url, w, h, l, t, m, s, r)
{

  var urlString='';
  var els = formObj.elements; 
  //alert(els);
  for(i=0; i<els.length; i++){ 
    if(els[i].type == 'hidden' || els[i].type == 'text'  || els[i].type == 'textarea' || els[i].type == 'checkbox' || els[i].type == 'radio' || els[i].type == 'select-one') {
	 
	 //if(els[i].type == 'select-one') {
	   //elvalue = els[i].options[els[i].selectedIndex].value;
	 //} else {
	  (elvalue = els[i].value);
	 //}
	 urlString += els[i].name + "=" + elvalue + '&';
	 //alert(urlString);
	}
  }
  url = url + '?' + urlString;
//alert(url);
//document.write(url);
 logSearch(url);
 win = window.open (url, "mywindow", "left=" + l + ", top=" + t + ", width=" + w + ", height=" + h + ", menubar=" + m + ", scrollbars=" + s + ", resizable=" + r + "");
  
  return false;
}
//used for the multi-search
function processForm2(formObj, url, w, h, l, t, m, s, r)
{
  var urlString='';
  var els = formObj.elements; 

	for(i=0; i<els.length; i++){ 
    if(els[i].type == 'hidden' || els[i].type == 'text'  || els[i].type == 'textarea' || els[i].type == 'checkbox' || els[i].type == 'radio' || els[i].type == 'select-one') {
	 
	(elvalue = els[i].value);
	/*
	if(els[i].name == 'flightType'){
		 if(els[11].value == ''){
		 	els[i].value = 'oneway';
			elvalue = els[i].value;
			
			els[7].name = 'leavingFrom';
			els[8].name = 'goingTo';
			els[9].name = 'leavingDate';
			
			//els[10].name = 'returningDate';
			//els[9].value = 'mm/dd/yyyy';
			//elvalue = els[9].value;
		 }
	 }
	*/
	if(els[i].name == 'leavingFrom1'){
		 if(els[i].value == ''){
		 window.self.close();
		 }
	 }

	if(els[i].name == 'leavingFrom2'){
		 if(els[i].value == ''){
		 window.self.close();
		 }
	 }


	if(els[i].name == 'leavingFrom2'){
		 if(els[i].value == ''){
		 elvalue = els[23].value;
		 i=23;
		 }
	 }

	if(els[i].name == 'leavingFrom3'){
		 if(els[i].value == ''){
		 //its 19 here moving to next set of fields
		 i=19;
		 }
	 }
	 if(els[i].name == 'leavingFrom4'){
		 if(els[i].value == ''){
			 //its 19 here moving to next set of fields
			 i=22;
		 }
	 }
	 urlString += els[i].name + "=" + elvalue + '&';
	}
  }
  url = url + '?' + urlString;
  logSearch(url);
  win = window.open (url, "_blank", "left=" + l + ", top=" + t + ", width=" + w + ", height=" + h + ", menubar=" + m + ", scrollbars=" + s + ", resizable=" + r + "");
  window.self.close();
  
  return false;
}


function processURL(url, w, h, l, t, m, s, r)
{
  win = window.open (url, "mywindow", "left=" + l + ", top=" + t + ", width=" + w + ", height=" + h + ", menubar=" + m + ", scrollbars=" + s + ", resizable=" + r + "");
}
function popURL(url, type)
{
	if(type == 'hotel'){
		processURL(url, '785', '650', '30', '30', '0', '1', '1');
	}
	if(type == 'ticket'){
		processURL(url, '792', '650', '30', '30', '0', '1', '1');
	}
	if(type == 'guide'){
		processURL(url, '840', '650', '30', '30', '0', '1', '1');
	}
	if(type == 'traker'){
		processURL(url, '820', '700', '30', '30', '0', '1', '1');
	}
	if(type == 'car'){
		processURL(url, '400', '400', '30', '30', '0', '1', '1');
	}
	if(type == 'multi'){
		processURL(url, '450', '410', '80', '80', '0', '1', '1');
	}
}

function logSearch(searchUrl) {
	var xhr;
	if(xhr = getXmlHttp()) {
		var logUrl = "includes/searchbox/search_log.php?url=" + escape(searchUrl);
		xhr.open("GET", logUrl, true);
		xhr.send(null);
	}
}
// openPopWin
// winFeatures = scrollbars,toolbar,menubar,resizable
var popWin = null    // use this when referring to pop-up window
var winCount = 0
var winName = "popWin"
function openPopWin(winURL, winWidth, winHeight, winFeatures, winLeft, winTop){
    var d_winLeft = 20  // default, pixels from screen left to window left
    var d_winTop = 20   // default, pixels from screen top to window top
    winName = "popWin" + winCount++ //unique name for each pop-up window
    closePopWin()           // close any previously opened pop-up window
    if (openPopWin.arguments.length >= 4)  // any additional features? 
        winFeatures = "," + winFeatures
    else 
        winFeatures = "" 
    if (openPopWin.arguments.length == 6)  // location specified
        winFeatures += getLocation(winWidth, winHeight, winLeft, winTop)
    else
        winFeatures += getLocation(winWidth, winHeight, d_winLeft, d_winTop)
    popWin = window.open(winURL, winName, "width=" + winWidth + ",height=" + winHeight + winFeatures)
}
function closePopWin(){    // close pop-up window if it is open 
  if (navigator.appName != "Microsoft Internet Explorer" 
      || parseInt(navigator.appVersion) >=4) //do not close if early IE
    if(popWin != null) if(!popWin.closed) popWin.close() 
  }
  function getLocation(winWidth, winHeight, winLeft, winTop){
  return ""
  }
//-->
// for Netscape 4+ and IE 4+
<!--
function getLocation(winWidth, winHeight, winLeft, winTop)
{
  var winLocation = ""
  if (winLeft < 0)
    winLeft = screen.width - winWidth + winLeft
  if (winTop < 0)
    winTop = screen.height - winHeight + winTop
  if (winTop == "cen")
    winTop = (screen.height - winHeight)/2 - 20
  if (winLeft == "cen")
    winLeft = (screen.width - winWidth)/2
  if (winLeft>0 & winTop>0)
    winLocation =  ",screenX=" + winLeft + ",left=" + winLeft    
                + ",screenY=" + winTop + ",top=" + winTop
  else
    winLocation = ""
  return winLocation
  }
//-->
function getXmlHttp() {
	var objXmlHttp;
	
	try {
	    objXmlHttp = new XMLHttpRequest();
	} catch (e) {
		try {
			objXmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				objXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				return false;
			}
		}
	}
	return objXmlHttp;
}

function showHelpcenterStaticMenu( obj ) {        
    key = obj.getAttribute( "key" );        
    frame = document.getElementById ( key + "_frame" );
    submenuContiner = document.getElementById ( "helpCenterSubMenu" );    
    framesArray = submenuContiner.childNodes;            
    for ( i = 0; i < framesArray.length; i++ ) {         
        if ( framesArray [ i ].tagName == "DIV" ) {                  
            if ( framesArray [ i ].id != key + "_frame" ) {
                framesArray [ i ].style.display = "none";
            }
            else {
                framesArray [ i ].style.display = "";
            }   
        }            
    }
}
function showHelpcenterMenu( obj ) {
    key = obj.getAttribute( "key" );	
    frame = document.getElementById ( key + "_frame" );    
    submenuContiner = document.getElementById ( "helpCenterSubMenu" );        
    framesArray = submenuContiner.childNodes;
    for ( i = 0; i < framesArray.length; i++ ) {        
        if ( framesArray [ i ].tagName == "DIV" ) {
            if ( framesArray [ i ].id != key + "_frame" ) {
                framesArray [ i ].style.display = "none";
            }
            else {
                framesArray [ i ].style.display = "";
            }   
        }            
    }
}
function showHelpCenterDocumentContent( contentAlias, submenuId, submenuImageName ) {    
    pageDivs = document.getElementsByTagName ( "DIV" );
    for ( i = 0; i < pageDivs.length; i++ ) {
        if ( pageDivs[ i ]. getAttribute( 'helpcenterBlock' ) == 'true') {
            pageDivs[ i ].style.display = "none";
        }
        if ( pageDivs[ i ].id.search(/submenuFrame_/) != -1 ) {
            pageDivs[ i ].style.display = "none";
        }        
    }
    if ( document.getElementById( contentAlias ) ) {
        document.getElementById( contentAlias ).style.display = "block";
    }
    submenuMenu = document.getElementById( "submenuFrame_" + submenuId );
    if ( submenuMenu ) {
        submenuMenu.style.display = "block";
    }    
    if ( submenuImageName != "" && submenuImageName != undefined ) {
        if ( document.getElementById( "helpCenterSubMenuLogo" ) ) {
            document.getElementById( "helpCenterSubMenuLogo" ).src = submenuImageName;
        }
    }
    
}
function showHelpCenterCustomDocuments( contentAlias ) {
    pageAnchors = document.getElementsByTagName ( "A" );
    for ( i = 0; i < pageAnchors.length; i ++ ) {
        var customDest = pageAnchors[ i ].getAttribute ( "customDestination" );
        if ( customDest != "" && customDest != undefined && customDest != contentAlias ) {
            if ( document.getElementById( customDest ) ) {
                document.getElementById( customDest ).style.display = "none";
            }
        }
    }
    if ( document.getElementById( contentAlias ) ) {
        document.getElementById( contentAlias ).style.display = "block";
    }       
}
function initHelpcenterDocuments() {
    hMenu = document.getElementById( "helpcenterMenu" );
    if ( hMenu ) {
        var category =  hMenu.getAttribute( "seletedCategory" );
        var subCategory = hMenu.getAttribute( "selectedSubcategory" );
        var documentAlias = hMenu.getAttribute( "selectedDocumentAlias" );        
        if ( category > 0 ) {
            frame = document.getElementById( category + "_frame" );
            if ( frame ) {
                frame.style.display = "";
            }
        }       
        if ( subCategory > 0 ) {
            showHelpCenterDocumentContent( documentAlias, subCategory, "" );
        }
    }
}
