var dayCell;
var selectedBar;
var selectedDay;
function changeTripType(formId) {
    //document.forms[formId].submit();
    document.getElementById(formId + ":hiddenButton").click();
    //return false;
}
function changeSearchOffersTripType(currentType, lang) {
    var cheapFlightsSearch = document.getElementById("cheapFlightsSearch");
    for (var i = 0; i < cheapFlightsSearch.tripTypeName.length; ++i) {
        if (cheapFlightsSearch.tripTypeName[i].checked == true) {
            if (cheapFlightsSearch.tripTypeName[i].value != currentType) {
                if (cheapFlightsSearch.tripTypeName[i].value == "ONE_WAY") {
                    document.getElementById("returnDate").value = onewaylabel;
                }
                initSwoosh("paso1", "vuelos", "cheapFlightsSearch", lang);
                cheapFlightsSearch.submit();
            }
        }
    }
}
function switchStyle(id) {
    document.getElementById("d1").style.display = "none";
    if (document.getElementById("d2")) {
        document.getElementById("d2").style.display = "none";
    }
    if (document.getElementById("d3")) {
        document.getElementById("d3").style.display = "none";
    }
    if (document.getElementById("d4")) {
        document.getElementById("d4").style.display = "none";
    }
    document.getElementById(id).style.display = "block";
}
function cellOverOut(cell) {
    var cellClass = cell.className;
    cell.className = (cell.className == 'overBarCell') ? 'barCell' : 'overBarCell';
}
function barCellOverOut(barImg) {
    var cell = barImg.parentNode.parentNode;
    if (barImg == selectedBar) {
        cell.className = 'barCell';
        return;
    }
    var dayCellId = "day" + barImg.parentNode.id;
    dayCell = document.getElementById(dayCellId);
    cellOverOut(cell);
    highLightDay(dayCell);
}
function dayCellOverOut(dayLink) {
    var myDayCell = dayLink.parentNode;
    var cellId = myDayCell.id.substring(3, myDayCell.id.length).toLowerCase();
    var cell = document.getElementById(cellId).parentNode;
    dayCell = myDayCell;
    highLightDay(myDayCell);
    cellOverOut(cell);
}
function highLightDay(myDayCell) {
    var currCellStyle;
    if (myDayCell.className.indexOf(" ") != -1) {
        currCellStyle = myDayCell.className.substring(0, myDayCell.className.indexOf(" "));
    } else {
        currCellStyle = myDayCell.className;
    }
    if (currCellStyle == 'dayCell' || currCellStyle == 'weekendCell') {
        myDayCell.oldCellStyle = myDayCell.className;
        myDayCell.className = 'sellCell';
    } else if (currCellStyle == 'selDayCell') {
        //        myDayCell.oldCellStyle = 'selDayCell';
        myDayCell.className = 'selDayCell';
    } else {
        myDayCell.className = myDayCell.oldCellStyle;
    }
}
function resetBar(barImg) {
    barImg.src = "/images/shared/orangebar.gif";
}
function selectBar(elem) {
    var myDayCell, myDayId;
    var myBar, myBarId;

    myDayId = "daycol" + elem.id.substring(3, elem.id.length);
    myDayCell = document.getElementById(myDayId);
    myBarId = "bar" + elem.id.substring(3, elem.id.length);
    myBar = document.getElementById(myBarId);

    if (selectedBar) {
        resetBar(selectedBar);
    }

    if (selectedDay) {
        selectedDay.className = selectedDay.oldCellStyle;
        selectedDay.childNodes[0].className = 'daylink';
    }

    selectedDay = myDayCell;
    selectedBar = myBar;
    if (myBar != null) {
        myBar.src = "/images/espanol/design/transit/blackpix.gif";
    }

    if (myDayCell != null) {
        myDayCell.className = 'selDayCell';
        myDayCell.childNodes[0].className = 'sellDayLink';
    }
}
var scrollId;
var browser = navigator.appName;
var windowYPos, windowXPos;
function getDocPos() {
    if (browser == "Netscape") {
        windowYPos = window.screenY;
        windowXPos = window.screenX;
    } else {
        windowYPos = window.screenTop;
        windowXPos = window.screenLeft;
    }
}
function depDayClicked(date, bar) {
    selectBar(bar);
    var step2Div = document.getElementById('step2');
    var step3Div = document.getElementById('step3');
    step2Div.style.display = "block";
    step3Div.style.display = "none";
    var firstStepForm = document.getElementById('firstDateForm');
    firstStepForm.departureDate.value = date;
    firstStepForm.submit();
    //    window.scrollTo(0, 500);
    getDocPos();
    scrollId = window.setInterval("scrollWindow(320)", 10);
}
function scrollWindow(where) {
    if (windowYPos < where) {
        windowYPos += 10;
        window.scrollTo(windowXPos, windowYPos);
    } else {
        window.clearInterval(scrollId);
    }
}

function retDayClicked(depLoc, arrLoc, depDate, retDate, tripType, trajectprice, totalPrice, bar) {
    selectBar(bar);
    var parentDoc = this.parent.document;
    var step3Div = parentDoc.getElementById('step3');
    var offersForm = parentDoc.getElementById('offersForm');

    var depLocSpan = parentDoc.getElementById('depLoc');
    var arrLocSpan = parentDoc.getElementById('arrLoc');
    var depDateSpan = parentDoc.getElementById('depDate');
    var retDateSpan = parentDoc.getElementById('retDate');
    var trajectPriceSpan = parentDoc.getElementById('trajectPrice');
    var totalPriceSpan = parentDoc.getElementById('totalPrice');
    var fakePr = trajectPriceSpan.innerHTML;

    depDate = addZerosToDate(depDate);
    if (tripType == "ROUND_TRIP") {
        retDate = addZerosToDate(retDate);

        trajectPriceSpan.innerHTML = trajectprice;
        totalPriceSpan.innerHTML = totalPrice;
        retDateSpan.innerHTML = retDate;
        offersForm.returnDate.value = retDate;
    } else {
        parentDoc.getElementById('retDateLabel').style.display = "none";
        parentDoc.getElementById('trajectPriceLabel').style.display = "none";
        parentDoc.getElementById('trajectPriceLabel2').style.display = "none";
        trajectPriceSpan.style.visibility = "hidden";
        totalPriceSpan.innerHTML = trajectprice;
        offersForm.returnDate.value = onewaylabel;
        offersForm.returnDate.disabled = true;
    }

    depLocSpan.innerHTML = depLoc;
    arrLocSpan.innerHTML = arrLoc;
    depDateSpan.innerHTML = depDate;

    offersForm.departureDate.value = depDate;
    offersForm.tripTypeName.value = tripType;

    getDocPos();
    scrollId = window.setInterval("scrollWindow(520)", 10);
    step3Div.style.display = "block";
}
function addZerosToDate(date) {
    var day = date.split("/")[0];
    var month = date.split("/")[1];
    var year = date.split("/")[2];

    day = (day.length < 2) ? "0" + day : day;
    month = (month.length < 2) ? "0" + month : month;

    return day + "/" + month + "/" + year;
}


