﻿
$.clientCoords = function() {
    var dimensions = { width: 0, height: 0, offsetTop: 0 };
    if (document.documentElement) {
        dimensions.width = document.documentElement.offsetWidth;
        dimensions.height = document.documentElement.offsetHeight;
        dimensions.offsetTop = document.documentElement.offsetTop;
    } else if (window.innerWidth && window.innerHeight) {
        dimensions.width = window.innerWidth;
        dimensions.height = window.innerHeight;
        dimensions.offsetTop = 0;
    }
    return dimensions;
}

function setAdPosition() {
    var w = $.clientCoords().width;
    var h = $.clientCoords().height;

    var adW = ((w - 820) / 2) + 820 + 10;

   
    //alert(adW);
    $('#ad').css('left', adW + 'px');

    var sTop = $(window).scrollTop();
    if (sTop >= 154) {
        $('#ad').css('top', sTop - 154 + 10 + 'px');
    } else { $('#ad').css('top', '10px');  }
}

/* dom ready */
$(function() {

    $('#cboTo').change(function() {
        var si = this.selectedIndex;
        if (si > 14) {
            $('#isToAirport').val('N');
        } else {
            $('#isToAirport').val('Y');
        }
        //alert($('#isToAirport').val());
    });

    $('#cboFrom').change(function() {
        var si2 = this.selectedIndex;
        if (si2 > 14) {
            $('#isFromAirport').val('N');
        } else {
            $('#isFromAirport').val('Y');
        }

       // alert($('#isFromAirport').val());
    });
	
	
	$('.txtDatetime').datepicker({ closeAtTop: false, currentText: 'Now', gotoCurrent: true, dateFormat: 'dd/mm/y', minDate: 'Now' });

    var currentTime = new Date()
    var month = currentTime.getMonth() + 1
    var day = currentTime.getDate()
    var year = currentTime.getFullYear()

    $('.txtDatetime').val(day + "/" + month + "/" + year);

    /*$.get('/Includes/ad.htm', 'html', function(data) {
        $('.w100').append(data);
        setAdPosition();
        //alert(data);
    });*/


    
    $(window).scroll(function(e) {
        //var offset = $('#ad').offset();
        //e.stopPropagation();
        //$('#ad').scroll().height;
        //$('#ad').scrollTop();


        //document.getElementById('ad').offsetTop = '10px';
        setAdPosition();
    });

    function doSomething() {
        setAdPosition();
    };

    var resizeTimer = null;
    $(window).bind('resize', function() {
        if (resizeTimer) clearTimeout(resizeTimer);
        resizeTimer = setTimeout(doSomething, 10);
    });



    /* $.post("http://weather.yahoo.com/London-United-Kingdom/UKXX0085/forecast.html?unit=c", function(data) {
    //var html = $('.forecast-temp', data).html();
    alert(data);
    });*/

    /*$("#links").load("/Main_Page #jq-p-Getting-Started li");*/


     $('input[name=rbCarType]:checked').each(function() {
        $('.ct').removeClass("selected");
        $(this).parent().addClass("selected");
    });


    $('.ct').click(function() {

        $('.ct').removeClass("selected");
        $(this).addClass("selected");

        $(this).children().attr('checked', true);

    });

    /*$('input[name=rbCarType]').change(function() {
    $('.ct').removeClass("selected");
    $(this).prev().addClass("selected");
    });*/

});


function validateTransferSearch() {
    if (document.frmSearch.cboTo.value == "-") {
        alert("Please Select Pick Up Point")
        document.frmSearch.cboTo.focus();
        return false;
    }
    if (document.frmSearch.cboFrom.value == "-") {
        alert("Please Select Destination")
        document.frmSearch.cboFrom.focus();
        return false;
    }
    if (document.frmSearch.txtDatetime.value == "-") {
        alert("Please Select Departure Date")
        document.frmSearch.txtDatetime.focus();
        return false;
    }

    if (document.frmSearch.cboMonth.value == "-") {
        alert("Please Select Departure Month")
        document.frmSearch.cboMonth.focus();
        return false;
    }
    if (document.frmSearch.cboHour.value == "-") {
        alert("Please Select Time of Pickup")
        document.frmSearch.cboHour.focus();
        return false;
    }
    if (document.frmSearch.cboMin.value == "-") {
        alert("Please Select Time of Pickup")
        document.frmSearch.cboMin.focus();
        return false;
    }

    if (document.frmSearch.cboTransfer.value == "-") {
        alert("Please Select type of transfer")
        document.frmSearch.cboTransfer.focus();
        return false;
    }
    if (document.frmSearch.rbCarType.value == "-") {
        alert("Please Select a vehicle Type")
        document.frmSearch.rbCarType.focus();
        return false;
    }


    return true
}













function ValidateData() {
    if (document.frmStep5.txtGivename.value == "") {
        alert("Please enter your Passenger Name")
        document.frmStep5.txtGivename.focus();
        return false;
    }

    if (document.frmStep5.txtEmailAddress.value == "") {
        alert("Please enter Email Address.");
        document.frmStep5.txtEmailAddress.focus();
        return false;
    }
    if (!isEmailAddr(document.frmStep5.txtEmailAddress.value)) {
        alert("Please enter a valid Email Address.");
        document.frmStep5.txtEmailAddress.focus();
        return false;
    }
    if (document.frmStep5.txtEmailAddress.value.length < 3) {
        alert("Please enter a valid Email Address.");
        document.frmStep5.txtEmailAddress.focus();
        return false;
    }

    if (document.frmStep5.txthomeAddress.value == "") {
        alert("Please enter the address")
        document.frmStep5.txthomeAddress.focus();
        return false;
    }

    
    if (document.frmStep5.txtTelephone.value == "") {
        alert("Please enter your Telephone Number")
        document.frmStep5.txtTelephone.focus();
        return false;
    }
    if (document.frmStep5.txtFlightNo.value == "") {
        alert("Please enter your Flight Number")
        document.frmStep5.txtFlightNo.focus();
        return false;
    }
    return true
}

function isEmailAddr(txtEmail) {
    var result = false
    var theStr = new String(txtEmail)
    var index = theStr.indexOf("@");
    if (index > 0) {
        var pindex = theStr.indexOf(".", index);
        if ((pindex > index + 1) && (theStr.length > pindex + 1))
            result = "1";
    }
    return result;
}


function __print(id) {
    var prtContent = document.getElementById(id);
    var WinPrint = window.open('', '', 'letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
    WinPrint.document.write(prtContent.innerHTML);
    WinPrint.document.close();
    WinPrint.focus();
    WinPrint.print();
    WinPrint.close();
}



function __trackEvent(category,action,labal,value){
    pageTracker._trackEvent(category,action,labal,value);
}