function DoPostback(language)
{
	__doPostBack('lang',language);
}

function ValidateTransfer(list1, list2, list3) {
    /*if (!ValidateDropDown(list1)) {
        alert('An Airport is required!');
        return false;
    }*/
    if (!ValidateDropDown(list2)) {
        alert('A Destination is required!');
        return false;
    }
    if (!ValidateDropDown(list3)) {
        alert('A Vehicle must be selected!');
        return false;
    }
    else {
        return true;
    }
}
function ValidateDropDown(droplist) {
    var list = document.getElementById(droplist);
    var retVal = false;
    if (null != list) {
        var iValue = new Number(list.selectedIndex);
        if (iValue > 0)
            retVal = true;
        else {
            list.focus();
            retVal = false;
        }
    }
    return retVal;
}


function SetFocus(objID)
{
	var object=document.getElementById(objID);
	object.focus();
}


function ValidaLogin(usr,pwd)
{
	var object=document.getElementById(usr);
	if (object.value == '')
	{
		alert('El usuario es requerido!');
		object.focus();
		return false;
	}

	object=document.getElementById(pwd);
	if (object.value=='')
	{
	    alert('La contrase' + String.fromCharCode(241) + 'a es requerida!');
		object.focus();
		return false;
	}
	else
	{
		return true;
	}
}
function ValidateCategory(list)
{
	var dropList = document.getElementById(list);
	var retVal=false;
	if (null != dropList)
	{
	    var iValue = Number(dropList.selectedIndex);
		retVal = (iValue > 0);
		
	}
	if (!retVal)
	{
		alert('A Vehicle Must Be Selected!');
		dropList.focus();
	}
	return retVal;
}

function AbreVentana(ventana, x, y, h, w) {
    var mywindow;
    mywindow = window.open(ventana, 'mywindow', 'location=0,status=0,scrollbars=0,width=' + w + ',height=' + h);
    mywindow.moveTo(x, y);
    return false;
}

function AbreVentanaConHW(ventana, h, w) {
    var mywindow;
    mywindow = window.open(ventana, 'mywindow', 'location=1,status=0,scrollbars=1,toolbar=1,width=' + w + ',height=' + h);
    return false;
}

function AbreVentanaScroll(ventana, x, y, h, w)
{
    var mywindow;
    mywindow=window.open(ventana ,'mywindow','toolbar=0,location=0,menubar=0,status=0,scrollbars=1,width='+w+',height='+h);
    mywindow.moveTo(x,y);
    return false;
}

//Opens a Modal Popup Window.
function OpenModalWindowWithXY(targetURL, X, Y) {
    var width = X + "px";
    var height = Y + "px";
    var params = 'location:yes;status:yes;toolbar:no;scroll:yes;resizable:no;dialogWidth:' + width + ';dialogHeight:' + height;
    if (window.showModalDialog) {
        var modalwindow = window.showModalDialog(targetURL, 'modalwindow', params);
    }
    else {
        window.open(targetURL, 'modalWin',
			'height=800,width=550,toolbar=yes,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes');
    }
    return false;
}

function ValidateCar(source, arguments)
{
	//var genderList = document.getElementById(source.controltovalidate);
	var genderList = document.getElementById('SelectCarsFrame1_Cars');
	if (null != genderList)
	{
		var iValue = new Number(genderList.selectedIndex);
		arguments.IsValid=(iValue > 0);
	}
	else
	{
		arguments.IsValid = false;
	}
}

function CloseWindow()
{
	self.close();
	return false;
}

/**
* DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
*/
// Declaring valid date character, minimum year and maximum year
var dtCh = "/";
var minYear = 1900;
var maxYear = 2100;

function isInteger(s) {
    var i;
    for (i = 0; i < s.length; i++) {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag) {
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary(year) {
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
}
function DaysArray(n) {
    for (var i = 1; i <= n; i++) {
        this[i] = 31
        if (i == 4 || i == 6 || i == 9 || i == 11) { this[i] = 30 }
        if (i == 2) { this[i] = 29 }
    }
    return this
}

function isDate(dtStr) {
    var daysInMonth = DaysArray(12)
    var pos1 = dtStr.indexOf(dtCh)
    var pos2 = dtStr.indexOf(dtCh, pos1 + 1)
    var strDay = dtStr.substring(0, pos1)
    var strMonth = dtStr.substring(pos1 + 1, pos2)
    var strYear = dtStr.substring(pos2 + 1)
    strYr = strYear
    if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1)
    if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1)
    }
    month = parseInt(strMonth)
    day = parseInt(strDay)
    year = parseInt(strYr)
    if (pos1 == -1 || pos2 == -1) {
        alert("The date format should be : dd/mm/yyyy")
        return false
    }
    if (strMonth.length < 1 || month < 1 || month > 12) {
        alert("Please enter a valid month")
        return false
    }
    if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]) {
        alert("Please enter a valid day")
        return false
    }
    if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear) {
        alert("Please enter a valid 4 digit year between " + minYear + " and " + maxYear + '[' + strYr + ']')
        return false
    }
    if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false) {
        alert("Please enter a valid date")
        return false
    }
    return true
}

function ValidateForm() {
    var dt = document.getElementById("ctl00_ContentPlaceHolder1_TxtStartDate");
    if (isDate(dt.value) == false) {
        dt.focus();
        return false;
    }
    else {
        return true;
    }
}

function ValidateCar(label) {
    var retVal = false;
    var errMsg = document.getElementById(label);
    errMsg.innerHTML = '';
    var genderList = document.getElementById('Cars');
    if (null != genderList) {
        var iValue = new Number(genderList.selectedIndex);
        if (iValue > 0) {
            arguments.IsValid = true;
            retVal = true;
        }
        else {
            alert('A vehicle must be selected!');
            arguments.IsValid = false;
            genderList.focus();
        }
    }
    else {
        arguments.IsValid = false;
    }
    return retVal;
} 

function ValidateIFrame(label, dropcars, droploc1, droploc2) {
    var retVal = false;
    var errMsg = document.getElementById(label);
    errMsg.innerHTML = '';
    if (!ValidateDropDown(dropcars)) {
        errMsg.innerHTML = 'A vehicle must be selected!';
        return false;
    }
    if (!ValidateDropDown(droploc1)) {
        errMsg.innerHTML = 'A pick up location must be selected!';
        return false;
    }
    if (! ValidateDropDown(droploc2))
    {
        errMsg.innerHTML = 'A drop off location must be selected!';
        return false;
    }
    return true;
}

function onUpdating() {
    var list = document.getElementById('ctl00_ContentPlaceHolder1_ImgCar');
    list.style.display = 'none';
    return true;
}

function openBKGwindow(windowDesc) {
    var win;
    //win = window.open(windowDesc);
    win = window.location;
    window.parent.location = windowDesc;
}

function SetHRef(linkID, dropCarID, startID, endID, startTimeID, endTimeID, pickID, dropID, lblError, customerID, OnlineLocation) {
    if (!ValidateIFrame(lblError, dropCarID, pickID, dropID)) {
        return false;
    }

    //Dates
    var startDate = document.getElementById(startID);
    var endDate = document.getElementById(endID);
    if (!isDate(startDate.value)) {
        startDate.focus;
        return false;
    }
    if (!isDate(endDate.value)) {
        endDate.focus;
        return false;
    }

    var link = document.getElementById(linkID);
    var cars = document.getElementById(dropCarID);
    var startTime = document.getElementById(startTimeID);
    var endTime = document.getElementById(endTimeID);
    var pickLoc = document.getElementById(pickID);
    var dropLoc = document.getElementById(dropID);
    link.href = OnlineLocation + 'carandfare.aspx?cat=' + cars.options[cars.selectedIndex].value +
        '&sd=' + startDate.value + ' ' + startTime.options[startTime.selectedIndex].value +
        '&ed=' + endDate.value + ' ' + endTime.options[endTime.selectedIndex].value +
        '&pl=' + pickLoc.options[pickLoc.selectedIndex].value +
        '&dl=' + dropLoc.options[dropLoc.selectedIndex].value +
        '&cid=' + customerID;
    return true;
}

function SetHRefMini(linkID, dropCarID, startDayID, startMonthID, endDayID, endMonthID, startTimeID, endTimeID, pickID, dropID, lblError, customerID, OnlineLocation) {
    if (!ValidateIFrame(lblError, dropCarID, pickID, dropID)) {
        return false;
    }

    //Start Date
    var startDay = document.getElementById(startDayID);
    var startMonth = document.getElementById(startMonthID);

    var sday = startDay.options[startDay.selectedIndex].value;
    var smonth = startMonth.options[startMonth.selectedIndex].value;
    var syear = smonth.substring(2);
    smonth = smonth.substring(0, 2);

    var startDate = sday + '/' + smonth + '/' + syear;
    if (!isDate(startDate)) {
        startMonth.focus;
        return false;
    }

    //End Date
    var endDay = document.getElementById(endDayID);
    var endMonth = document.getElementById(endMonthID);

    var eday = endDay.options[endDay.selectedIndex].value;
    var emonth = endMonth.options[endMonth.selectedIndex].value;
    var eyear = emonth.substring(2);
    emonth = emonth.substring(0, 2);

    var endDate = eday + '/' + emonth + '/' + eyear;
    if (!isDate(endDate)) {
        endMonth.focus;
        return false;
    }


    var link = document.getElementById(linkID);
    var cars = document.getElementById(dropCarID);
    
    var startTime = document.getElementById(startTimeID);
    var endTime = document.getElementById(endTimeID);
    
    var pickLoc = document.getElementById(pickID);
    var dropLoc = document.getElementById(dropID);
    
    link.href = OnlineLocation + 'carandfare.aspx?cat=' + cars.options[cars.selectedIndex].value +
        '&sd=' + startDate + ' ' + startTime.options[startTime.selectedIndex].value +
        '&ed=' + endDate + ' ' + endTime.options[endTime.selectedIndex].value +
        '&pl=' + pickLoc.options[pickLoc.selectedIndex].value +
        '&dl=' + dropLoc.options[dropLoc.selectedIndex].value +
        '&cid=' + customerID;
    return true;
} 


function ClearGreenIframe(dropCarID, startID, endID, startTimeID, endTimeID, pickID, dropID, lblError) {
    var startDate = document.getElementById(startID);
    var endDate = document.getElementById(endID);
    var cars = document.getElementById(dropCarID);
    var startTime = document.getElementById(startTimeID);
    var endTime = document.getElementById(endTimeID);
    var pickLoc = document.getElementById(pickID);
    var dropLoc = document.getElementById(dropID);

    startDate.selectedIndex = 0;
    endDate.selectedIndex = 0;
    cars.selectedIndex = 0;
    pickLoc.selectedIndex = 0;
    dropLoc.selectedIndex = 0;
    lblError.innerHTML = '';
    
    //Times to 09:00
    startTime.selectedIndex = 18;
    endTime.selectedIndex = 18;
    
    //Dates
    var sDate = new Date();
    var eDate = new Date();
    sDate.setDate(sDate.getDate() + 2);
    eDate.setDate(eDate.getDate() + 9);
    
    //Days
    var day = AddZero(sDate.getDate());
    var dayEnd = AddZero(eDate.getDate());
    
    //Months
    var month = AddZero(sDate.getMonth());
    var monthEnd = AddZero(eDate.getMonth());
    
    startDate.value = day + '/' + month + '/' + sDate.getFullYear();
    endDate.value = dayEnd + '/' + monthEnd + '/' + eDate.getFullYear();

    return false;
}

function AddZero(Number) {
    if (Number.toString().length == 1) {
        return '0' + Number.toString();
    }
    else {
        return Number.toString();
    }
}
