﻿var air = document.getElementById("rbAir");
var tabAir = document.getElementById("tabAir");

var car = document.getElementById("rbCar");
var tabCar = document.getElementById("tabCar");

var hotel = document.getElementById("rbHotel");
var tabHotel = document.getElementById("tabHotel");

var vacation = document.getElementById("rbVacation");
var tabVacation = document.getElementById("tabVacation");

function ToggleTabs()
{
    manageCompTabs();
}

function ToggleTripType()
{
	if (document.getElementById("rbOW").checked)
	{
		GetTag("tdReturnDate").style.visibility = "hidden";
		GetTag("tdReturnTime").style.visibility = "hidden";		
	}
	else
	{
		GetTag("tdReturnDate").style.visibility = "visible";
		GetTag("tdReturnTime").style.visibility = "visible";		
	}
}

function getAirportCode(theTagID)
{
	var strUrl = "http://www.farebuzz.com/Affiliates/DesktopModules/Fareportal/Modules/Flight/AirportCode.aspx?frm=Form&textbox=" + theTagID;
	window.open(strUrl,"AirportPicker","toolbar=no,status=no,resizable=no,scrollbars=yes,width=650,height=700,top=100,left=100");
}

function ShowHotelDates()
{
    if (GetTag("vacHotelDates").style.display=="none")
    {
        GetTag("vacHotelDates").style.display="";
    }
    else
    {
        GetTag("vacHotelDates").style.display="none";
    }
}

function OnVacationsRoomChange()
{
    if (GetTag("ddlRoomCount").value == "2")
    {
       GetTag("trVacationRoom2").style.display = "";
    }
    else
    {
        GetTag("trVacationRoom2").style.display = "none";
    }
}

window.onload = function window_loaded()
{
	manageCompTabs();

	//set default dates
	var fromDate = new Date();
	var toDateDate = new Date();
	fromDate.setDate(fromDate.getDate()+14);
	toDateDate.setDate(toDateDate.getDate()+21);
	SetDateObj("tbDTime",fromDate);
	SetDateObj("tbRTime",toDateDate);
	SetDateObj("tbChIn",fromDate);
	SetDateObj("tbChOut",toDateDate);
	SetDateObj("tbPick",fromDate);
	SetDateObj("tbDrop",toDateDate);
	SetDateObj("txtDepartureDate",fromDate);
	SetDateObj("txtReturningDate",toDateDate);
	SetDateObj("txtHotelCheckInDate",fromDate);
	SetDateObj("txtHotelCheckOutDate",toDateDate);
}

function SetDateObj(objName,dateObj)
{
	document.getElementById(objName).value = (dateObj.getMonth()+1) + "/" + dateObj.getDate() + "/" + dateObj.getFullYear();
}

function manageCompTabs()
{
	if (air.checked)
	{
		tabAir.style.display = "";
		tabCar.style.display = "none";
		tabHotel.style.display = "none";		
		tabVacation.style.display = "none";
	}
	if (car.checked)
	{
		tabAir.style.display = "none";
		tabCar.style.display = "";
		tabHotel.style.display = "none";		
		tabVacation.style.display = "none";
	}
	if (hotel.checked)
	{
		tabAir.style.display = "none";
		tabCar.style.display = "none";
		tabHotel.style.display = "";
		tabVacation.style.display = "none";
	}
	if (vacation.checked)
	{
		tabAir.style.display = "none";
		tabCar.style.display = "none";
		tabHotel.style.display = "none";
		tabVacation.style.display = "";
	}
}

function GetTag(tagId)
{
    return document.getElementById(tagId);
}

function SearchNow()
{
    var searchStr = "http://www.farebuzz.com/Affiliates/Default.aspx?tabid=2300&caID=48069&FpAffiliate=RentSunnFLB2C&FpSub=";

    if (air.checked)
    {
        searchStr += "&from=" + GetTag("tbFrom").value 
                  + "&fromDt=" + GetTag("tbDTime").value
                  + "&fromTm=" + GetTag("ddOBTime").value 
                  + "&to=" + GetTag("tbTo").value
                  + "&toDt=" + GetTag("tbRTime").value 
                  + "&toTm=" + GetTag("ddInTime").value
                  + "&rt=" + GetTag("rbRT").checked 
                  + "&ad=" + GetTag("ddAdult").value
                  + "&ch=" + GetTag("ddChild").value 
                  + "&se=" + GetTag("ddSenior").value
                  + "&class=" + GetTag("ddClass").value;
    }
    else if (hotel.checked)
    {
        searchStr += "&to=" + GetTag("tbCity").value 
                  + "&fromDt=" + GetTag("tbChIn").value
                  + "&toDt=" + GetTag("tbChOut").value 
                  + "&ad=" + GetTag("ddGuest").value
                  + "&ht=";
    }
    else if (car.checked)
    {
        searchStr += "&to=" + GetTag("tbAirp").value 
                  + "&fromDt=" + GetTag("tbPick").value
                  + "&fromTm=" + GetTag("tbTPick").value 
                  + "&toDt=" + GetTag("tbDrop").value
                  + "&toTm=" + GetTag("tbTDrop").value 
                  + "&cr=" + GetTag("ddCar").value;
    }
    else if (vacation.checked)
    {
        searchStr = "http://www.farebuzz.com/Affiliates/Default.aspx?tabid=3994&caID=48069&FpAffiliate=RentSunnFLB2C&FpSub=";
        
        searchStr += "&from=" + GetTag("tbFromVac").value 
                  + "&to=" + GetTag("tbToVac").value 
                  + "&dep=" + GetTag("txtDepartureDate").value 
                  + "&ret=" + GetTag("txtReturningDate").value
                  + "&svc=" + GetTag("ddlFlightServiceClass").value 
                  + "&rm=" + GetTag("ddlRoomCount").value
                  + "&r1a=" + GetTag("ddlAdultsInRoom1").value;
                 
        if(GetTag("ddlRoomCount").value == "2")
        {
            searchStr += "&r2a=" + GetTag("ddlAdultsInRoom2").value;
        }
        if(GetTag("cbkRequireSeprateHotelDates").checked)
        {
            searchStr += "&cin=" + GetTag("txtHotelCheckInDate").value 
                      + "&cout=" + GetTag("txtHotelCheckOutDate").value;
        }
    }  
    
    window.open(searchStr);
}

