﻿var IdStart = "ctl00_ContentPlaceHolder1_";

function clearMe() {
    var tex = document.getElementById("txtEmail");
    tex.value = "";
    return;
}

function checkME() {
    var tex = document.getElementById("txtEmail");
    if (tex.value = "") {
        tex.value = "Your email address here";
        return;
    }
}

function uncheckallAirlines(comp) {
    var form1 = "form1";


    for (i = 0; i < document.form1.elements.length; i++) {

        if (document.form1.elements[i].type == "radio") {
            var mytool_array = document.form1.elements[i].id.split("_");
            var mytool_array1 = comp.id.split("_");
            if (mytool_array[0] == mytool_array1[0]) {
                if (document.form1.elements[i].id != comp.id) {
                    document.form1.elements[i].checked = false;
                }
            }
        }
    }
}
function uncheckallHotels(comp) {
    var form1 = "form1";
    for (i = 0; i < document.form1.elements.length; i++) {

        if (document.form1.elements[i].type == "radio") {
            var mytool_array = document.form1.elements[i].id.split("_");
            var mytool_array1 = comp.id.split("_");
            if (mytool_array[0] == mytool_array1[0]) {
                if (document.form1.elements[i].id != comp.id) {
                    document.form1.elements[i].checked = false;
                }
            }
        }
    }
}

function validateAirLineBooking() {


    var Bookingname = document.getElementById(IdStart + "txtName");
    var ReqDate = document.getElementById(IdStart + "txtBookingDate");
    var name = document.getElementById(IdStart + "txtTravellerName");
    var telephone = document.getElementById(IdStart + "txtPhone");
    var email = document.getElementById(IdStart + "txtEmail");
    var Country = document.getElementById(IdStart + "txtCountry");
    //alert(Bookingname);
    if (Bookingname.value == "") {
    
        alert('Name can not be blank');
        Bookingname.focus();
        return false;
    }
    if (ReqDate.value == "") {
        alert('Request date can not be blank');
        ReqDate.focus();
        return false;
    }
    if (name.value == "") {
        alert('Traveller name can not be blank');
        name.focus();
        return false;
    }
    if (telephone.value == "") {
        alert('Contact number can not be blank');
        telephone.focus();
        return false;
    }
    if (email.value == "") {
        alert('Email can not be blank');
        email.focus();
        return false;
    }
    else {
        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        var address = email.value;
        if (reg.test(address) == false) {
            alert('Invalid Email Address');
            email.value = "";
            email.focus();
            return false;
        }
    }
    if (Country.value == "") {
        alert('City/Country can not be blank');
        Country.focus();
        return false;
    }
    

}
function validatePackcageBooking() {

    var clientName = document.getElementById(IdStart + "txtName");
    var city = document.getElementById(IdStart + "txtCity");
    var Checkindate = document.getElementById(IdStart + "txtDateFrom");
    var Checkoutdate = document.getElementById(IdStart + "txtDateTo");
    var email = document.getElementById(IdStart + "txtEmail");
    dt1 = getDateObject(Checkindate.value, "/");
    dt2 = getDateObject(Checkoutdate.value, "/");

    
    if (clientName.value == "") {

        alert('Name can not be blank');
        clientName.focus();
        return false;
    }
    if (city.value == "") {
        alert('City can not be blank');
        city.focus();
        return false;
    }
    if (Checkindate.value == "") {
        alert('Checkin date can not be blank');
        Checkindate.focus();
        return false;
    }
    if (Checkoutdate.value == "") {
        alert('Checkout date  can not be blank');
        Checkoutdate.focus();
        return false;
    }
    if (dt2 < dt1) {
        alert("Check out date should be greater than check in date")
        Checkoutdate.value = "";
        Checkoutdate.focus();
        return false;
    }
    
    if (email.value == "") {
        alert('Email can not be blank');
        email.focus();
        return false;
    }
    else {
        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        var address = email.value;
        if (reg.test(address) == false) {
            alert('Invalid Email Address');
            email.value = "";
            email.focus();
            return false;
        }
    }

}

function validateContacctUs() {
    var Subject = document.getElementById(IdStart + "txtSubject");
    var email = document.getElementById(IdStart + "txtEmail");
    var Description = document.getElementById(IdStart + "txtMessage");

    if (Subject.value == "") {
        alert('Subject can not be blank');
        Subject.focus();
        return false;
    }

    if (email.value == "") {
        alert('Email can not be blank');
        email.focus();
        return false;
    }
    else {
        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        var address = email.value;
        if (reg.test(address) == false) {
            alert('Invalid Email Address');
            email.value = "";
            email.focus();
            return false;
        }
    }
    if (Description.value == "") {
        alert('Message can not be blank');
        Description.focus();
        return false;
    }
    
}
function validateEmail(comp) {
   /* var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var address = comp.value;
    if (reg.test(address) == false) {
        alert('Invalid Email Address');
        comp.value = "";
        comp.focus();
        return false;
    }*/
    var email = document.getElementById("txtEmail");

    if ((email.value == null) || (email.value == "")) {
        alert("Please Enter your Email ID")
       
        email.focus()
        return false
    }
    if (echeck(email.value) == false) {
        email.value = ""
        email.focus()
        return false
    }
    return true
}
function echeck(str) {

    var at = "@"
    var dot = "."
    var lat = str.indexOf(at)
    var lstr = str.length
    var ldot = str.indexOf(dot)
    if (str.indexOf(at) == -1) {
        alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
        alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
        alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(at, (lat + 1)) != -1) {
        alert("Invalid E-mail ID")
        return false
    }

    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
        alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(dot, (lat + 2)) == -1) {
        alert("Invalid E-mail ID")
        return false
    }

    if (str.indexOf(" ") != -1) {
        alert("Invalid E-mail ID")
        return false
    }

    return true
}
function comparedate(comp1, comp2) {
    dt1 = getDateObject(comp1.value, "/");
    dt2 = getDateObject(comp2.value, "/");

    if (dt1 > dt2)
        alert("dt1 is greater than dt2")
    else
        alert("dt1 is less than dt2")

}
function getDateObject(dateString, dateSeperator) {
    //This function return a date object after accepting 
    //a date string ans dateseparator as arguments
    var curValue = dateString;
    var sepChar = dateSeperator;
    var curPos = 0;
    var cDate, cMonth, cYear;

    //extract day portion
    curPos = dateString.indexOf(sepChar);
    cDate = dateString.substring(0, curPos);

    //extract month portion				
    endPos = dateString.indexOf(sepChar, curPos + 1); cMonth = dateString.substring(curPos + 1, endPos);

    //extract year portion				
    curPos = endPos;
    endPos = curPos + 5;
    cYear = curValue.substring(curPos + 1, endPos);

    //Create Date Object
    dtObject = new Date(cYear, cMonth, cDate);
    return dtObject;
}
