//JavaScript File for Calendar Control
var Var_ShowPaymentGatewayMessage = false;
function checkDate(sender, args) {

    var selectedDate = new Date(sender._selectedDate);
    var today = new Date();
    today.setHours(0, 0, 0, 0);

    if (selectedDate < today) {
        alert("Please select a date greater or equal to today's date.");
        sender._selectedDate = new Date();
        // set the date back to the today
        sender._textbox.set_Value(sender._selectedDate.format(sender._format))
    }

}

function validate_email(clientID) {

    var emailReg = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,3}$/;
    var regex = new RegExp(emailReg);
    var field = document.getElementById(clientID).value;
    if (field == "") {
        alert("Please enter an email address.");
        document.getElementById(clientID).focus();
        return false;
    }
    else if (regex.test(field) == false) {
        alert("Please enter a valid email address.");
        document.getElementById(clientID).focus();
        document.getElementById(clientID).value = "";
        return false;
    }
    return true;
}

//Javascript for Home Search City and Weather City Control

function validate_city(clientID) {
    var field = document.getElementById(clientID).value;
    if (field == '') {
        alert("Please select city from the list.");
        document.getElementById(clientID).focus();
        return false;
    }
    else return true;
}

//Javscript for home weather redirection control
var CityDropdownClientId = '';
var MapRedirectUrl = '';
var WeatherRedirectUrl = '';

function ChangeLink() {
    var CityName = document.getElementById(CityDropdownClientId).value;
    var aNav = document.getElementById('aNavigate');
    var aYahooRadio = document.getElementById('rdYahooWeather');
    if (CityName != '') {
        if (aYahooRadio.checked == true)
            aNav.href = WeatherRedirectUrl.replace("{0}", CityName.replace(' ', '_'));
        else
            aNav.href = MapRedirectUrl.replace("{0}", CityName.replace(' ', '_'));
    }
    else {
        aNav.href = '';
    }
}

// function to check upload image file extention
function CheckUploadImageFileType(FileUploadID) {
    if (document.getElementById(FileUploadID)) {
        var FileNameVar = document.getElementById(FileUploadID).value;
        FileNameVar = FileNameVar.trim();
        var BooleanValue = false;

        if (FileNameVar.length > 0) {
            var VarLastIndex = FileNameVar.lastIndexOf('.');
            var FileExtension = FileNameVar.substring(VarLastIndex);
            FileExtension = FileExtension.toLowerCase();

            switch (FileExtension) {
                case ".jpg":
                    BooleanValue = true;
                case ".jpeg":
                    BooleanValue = true;
                case ".gif":
                    BooleanValue = true;
                case ".png":
                    BooleanValue = true;
                case ".tif":
                    BooleanValue = true;
                case ".tiff":
                    BooleanValue = true;
            }

            if (BooleanValue == true) {
                return true;
            }
            alert('To upload, please select an image file with extension .jpeg,.jpg,.gif,.png,.bmp, .tif or.tiff');
        }
        else {
            alert('Please select an appropriate image file to upload!');
        }
    }
    return false;
}

// function to check upload image file extention
function CheckUploadImageFileTypeWithMessage(FileUploadID, GridViewID, MessageToUser) {
    if (document.getElementById(FileUploadID)) {
        var FileNameVar = document.getElementById(FileUploadID).value;
        FileNameVar = FileNameVar.trim();
        var BooleanValue = false;

        if (FileNameVar.length > 0) {
            var VarLastIndex = FileNameVar.lastIndexOf('.');
            var FileExtension = FileNameVar.substring(VarLastIndex);
            FileExtension = FileExtension.toLowerCase();

            switch (FileExtension) {
                case ".jpg":
                    BooleanValue = true;
                case ".jpeg":
                    BooleanValue = true;
                case ".gif":
                    BooleanValue = true;
                case ".png":
                    BooleanValue = true;
                case ".tif":
                    BooleanValue = true;
                case ".tiff":
                    BooleanValue = true;
            }

            if (BooleanValue == false) {
                alert('To upload, please select an image file with extension .jpeg,.jpg,.gif,.png,.bmp,.tif or.tiff only');
                return false;
            }
            if (document.getElementById(GridViewID) != null) {
                if (document.getElementById(GridViewID).rows.length <= 1) {
                    return true;
                }
            }
            else {
                return true;
            }
            if (confirm(MessageToUser)) {
                return true;
            }
            else {
                return false;
            }
        }
        else {
            alert('Please select an appropriate image file to upload!');
        }
    }

    return false;
}

// function to check upload image file extention
function CheckUploadImageFileType(FileUploadID, GridViewID, MessageToUser) {
    if (document.getElementById(FileUploadID)) {

        var FileNameVar = document.getElementById(FileUploadID).value;
        FileNameVar = FileNameVar.trim();
        var BooleanValue = false;

        if (FileNameVar.length > 0) {
            var VarLastIndex = FileNameVar.lastIndexOf('.');
            var FileExtension = FileNameVar.substring(VarLastIndex);
            FileExtension = FileExtension.toLowerCase();

            switch (FileExtension) {
                case ".jpg":
                    BooleanValue = true;
                case ".jpeg":
                    BooleanValue = true;
                case ".gif":
                    BooleanValue = true;
                case ".png":
                    BooleanValue = true;
                case ".tif":
                    BooleanValue = true;
                case ".tiff":
                    BooleanValue = true;
            }

            if (BooleanValue == false) {
                alert('To upload, please select an image file with extension .jpeg,.jpg,.gif,.png,.bmp,.tif or.tiff only');
                return false;
            }
            if (document.getElementById(GridViewID) != null) {
                if (document.getElementById(GridViewID).rows.length <= 1) {
                    return true;
                }
            }
            else {
                return true;
            }
            if (confirm(MessageToUser)) {
                return true;
            }
            else {
                return false;
            }
        }
        else {
            alert('Please select an appropriate image file to upload!');
        }
    }

    return false;
}

// function to check upload image file extention
function CheckUploadImageFileType(FileUploadID, MessageToUser) {
    if (document.getElementById(FileUploadID)) {

        var FileNameVar = document.getElementById(FileUploadID).value;
        FileNameVar = FileNameVar.trim();
        var BooleanValue = false;

        if (FileNameVar.length > 0) {
            var VarLastIndex = FileNameVar.lastIndexOf('.');
            var FileExtension = FileNameVar.substring(VarLastIndex);
            FileExtension = FileExtension.toLowerCase();

            switch (FileExtension) {
                case ".jpg":
                    BooleanValue = true;
                case ".jpeg":
                    BooleanValue = true;
                case ".gif":
                    BooleanValue = true;
                case ".png":
                    BooleanValue = true;
                case ".tif":
                    BooleanValue = true;
                case ".tiff":
                    BooleanValue = true;
            }

            if (BooleanValue == false) {
                alert('To upload, please select an image file with extension .jpeg,.jpg,.gif,.png,.bmp,.tif or.tiff only');
                return false;
            }
            if (confirm(MessageToUser)) {
                return true;
            }
            else {
                return false;
            }
        }
        else {
            alert('Please select an appropriate image file to upload!');
        }
    }

    return false;
}

// function to check upload video file extension
function CheckUploadVideoFileType(FileUploadID, GridViewID) {
    if (document.getElementById(FileUploadID)) {

        var FileNameVar = document.getElementById(FileUploadID).value;
        FileNameVar = FileNameVar.trim();
        var BooleanValue = false;

        if (FileNameVar.length > 0) {
            var VarLastIndex = FileNameVar.lastIndexOf('.');
            var FileExtension = FileNameVar.substring(VarLastIndex);
            FileExtension = FileExtension.toLowerCase();

            switch (FileExtension) {
                case ".jpg":
                    BooleanValue = true;
                case ".jpeg":
                    BooleanValue = true;
                case ".gif":
                    BooleanValue = true;
                case ".png":
                    BooleanValue = true;
                case ".avi":
                    BooleanValue = true;
                case ".mov":
                    BooleanValue = true;
                case ".mpg":
                    BooleanValue = true;
                case ".swf":
                    BooleanValue = true;
                case ".wmv":
                    BooleanValue = true;
            }

            if (BooleanValue == true) {
                return true;
            }

            alert('To upload, please select a video file with extension .jpg, .jpeg, .gif, .png, .avi, .mov, .mpg, .swf or .wmv only');
        }
        else {
            alert('Please select an appropriate video file to upload!');
        }
    }

    return false;
}

// function to check upload video file extension
function CheckUploadVideoFileType(FileUploadID) {
    if (document.getElementById(FileUploadID)) {

        var FileNameVar = document.getElementById(FileUploadID).value;
        FileNameVar = FileNameVar.trim();
        var BooleanValue = false;

        if (FileNameVar.length > 0) {
            var VarLastIndex = FileNameVar.lastIndexOf('.');
            var FileExtension = FileNameVar.substring(VarLastIndex);
            FileExtension = FileExtension.toLowerCase();

            switch (FileExtension) {
                case ".avi":
                    BooleanValue = true;
                case ".mov":
                    BooleanValue = true;
                case ".mpg":
                    BooleanValue = true;
                case ".swf":
                    BooleanValue = true;
                case ".wmv":
                    BooleanValue = true;
            }

            if (BooleanValue == true) {
                return true;
            }

            alert('To upload, please select a video file with extension .avi, .mov, .mpg, .swf or .wmv only');
        }
        else {
            alert('Please select an appropriate video file to upload!');
        }
    }

    return false;
}

// function to check the deletion file list
function CheckImageListForDeletion(GridViewID) {
    var imgCheckedForDeletion = false;
    if (document.getElementById(GridViewID)) {
        var grid = document.getElementById(GridViewID);
        for (i = 0; i < grid.rows.length; i++) {
            var inputelements = grid.rows[i].cells[4].getElementsByTagName('input');
            var maxj = inputelements.length;
            for (j = 0; j < maxj; j++) {
                if (inputelements[j].getAttribute('type') == 'checkbox') {
                    if (inputelements[j].checked == true) {
                        return true;
                    }
                }
            }
        }
        if (imgCheckedForDeletion == false) {
            alert("Please select the image/s you want to delete!");
            return false;
        }
    }

    return false;
}

function TrimString(sInString) {
    sInString = sInString.replace(/^\s+/g, ""); // strip leading
    return sInString.replace(/\s+$/g, "");  // strip trailing
}

// Check a textbox value for numeric value only
function CheckNumericValue(varfield, varname) {
    varfield.value = TrimString(varfield.value);
    if (isNaN(varfield.value)) {
        alert(varname + " should be numeric only.");
        varfield.focus();
        return false;
    }
    return true;
}

function CheckRateValue(GridViewID) { //RateBoxClientID    
    if (document.getElementById(RateBoxClientID)) {
        var Rate = document.getElementById(RateBoxClientID);
        Rate.value = TrimString(Rate.value);

        if (Rate.value == '') {
            alert("Please enter a Room Rate!");
            return false;
        }

        if (Rate.value != '') {
            if (!CheckNumericValue(Rate, "Room Rate")) {
                return false;
            }
        }
    }
    return true;
}

/**************Function for trim*************/
function trim(strTrim) {
    return strTrim.replace(/^\s*|\s*$/g, "");
}

//*********** end For Display Current Salary *************************************
function textCounter(field, maxlimit) {
    if (field.value.length > maxlimit) // if too long...trim it!
    {
        field.value = field.value.substring(0, maxlimit);
    }
    // otherwise, update 'characters left' counter
    //else
    //cntfield.value = maxlimit - field.value.length;
}

function isNumeric(elem) {
    var numericExpression = "[0-9-+ ]{1,20}$";
    if (elem.value.match(numericExpression)) {
        return true;
    } else {
        return false;
    }
}



//function isAlphabet(elem) {
//    var alphaExp = "^[a-zA-Z. ']{1,50}$";
//    if (elem.value.match(alphaExp)) {
//        return true;
//    }
//    else {
//        return false;
//    }
//}

function isAlphaNumeric(val) {
    //var alphaNumExp = /^[a-zA-Z0-9',_&/:@!?.#%*-=/(/) ]+$/;
    var alphaNumExp = "^[a-zA-Z\\0-9,_&/:@!?.#%'*-=/(/) ]+$";
    if (val.value.match(alphaNumExp)) {
        return true;
    }
    else {
        return false;
    }
}

function isAlpha(val) {

    var alphaExp = "^[a-zA-Z0-9]{1,50}$";
    if (val.value.match(alphaExp)) {
        return true;
    }
    else {
        return false;
    }
}

function isAlphabet(elem, maxlimit) {

    if (maxlimit == 50)
        var alphaExp = "^[a-zA-Z. ']{1,50}$";
    else if (maxlimit == 100)
        var alphaExp = "^[a-zA-Z. ']{1,100}$";
    if (elem.value.match(alphaExp)) {
        return true;
    }
    else {
        return false;
    }
}


/*Gmap popup script*/

function popupUrl(url, width, height, resizable) {
    var newwindow = window.open(url, 'PrintMap', 'height=' + height.toString() + ',width=' + width.toString() + ',resizable=' + resizable.toString() + '');
    if (window.focus) { newwindow.focus(); }
}

/*Javascript Image Rotator script*/
var ListOfSlideShowObject;

function AddRotatorDetails(ContainerClassName, ThumbnailClassName, Delay) {
    if (!ListOfSlideShowObject) {
        ListOfSlideShowObject = new Array();
    }
    var index = ListOfSlideShowObject.length;
    ListOfSlideShowObject[index] = new Array();
    ListOfSlideShowObject[index][0] = ContainerClassName;
    ListOfSlideShowObject[index][1] = ThumbnailClassName;
    ListOfSlideShowObject[index][2] = Delay;
}

function InitializeRotator() {
    if (ListOfSlideShowObject) {
        for (var i = 0; i < ListOfSlideShowObject.length; i++) {
            var obj = {
                wait: ListOfSlideShowObject[i][2],
                effect: 'fade',
                duration: 500,
                loop: true,
                thumbnails: false,
                backgroundSlider: true,
                onClick: function(i) { }
            }
            var show = new SlideShow(ListOfSlideShowObject[i][0], ListOfSlideShowObject[i][1], obj);
            show.play();
        }

    }

}

function SetGuestDetails() {
    if (document.getElementById("ctl00_ctl00_CPH_MainContainer_CPH_MainContainer_CTL_HotelGuestDetails_UC_HotelGuestBookedBy_CB_SameDetails").checked == true) {
        document.getElementById("ctl00_ctl00_CPH_MainContainer_CPH_MainContainer_CTL_HotelGuestDetails_UC_HotelGuestBookedBy_txtFirstName").value = document.getElementById("ctl00_ctl00_CPH_MainContainer_CPH_MainContainer_CTL_HotelGuestDetails_GV_HGD_RoomsGrid_ctl02_GV_HGD_PassengerGrid_ctl02_Txt_HGD_FirstName").value;

        document.getElementById("ctl00_ctl00_CPH_MainContainer_CPH_MainContainer_CTL_HotelGuestDetails_UC_HotelGuestBookedBy_txtLastName").value = document.getElementById("ctl00_ctl00_CPH_MainContainer_CPH_MainContainer_CTL_HotelGuestDetails_GV_HGD_RoomsGrid_ctl02_GV_HGD_PassengerGrid_ctl02_Txt_HGD_LastName").value;

        document.getElementById("ctl00_ctl00_CPH_MainContainer_CPH_MainContainer_CTL_HotelGuestDetails_UC_HotelGuestBookedBy_txtEmail").value = document.getElementById("ctl00_ctl00_CPH_MainContainer_CPH_MainContainer_CTL_HotelGuestDetails_GV_HGD_RoomsGrid_ctl02_GV_HGD_PassengerGrid_ctl02_Txt_HGD_EmailId").value;

        document.getElementById("ctl00_ctl00_CPH_MainContainer_CPH_MainContainer_CTL_HotelGuestDetails_UC_HotelGuestBookedBy_txtMobileNo").value = document.getElementById("ctl00_ctl00_CPH_MainContainer_CPH_MainContainer_CTL_HotelGuestDetails_GV_HGD_RoomsGrid_ctl02_GV_HGD_PassengerGrid_ctl02_Txt_HGD_MobileNumber").value;

        document.getElementById("ctl00_ctl00_CPH_MainContainer_CPH_MainContainer_CTL_HotelGuestDetails_UC_HotelGuestBookedBy_txtCountryCode").value = document.getElementById("ctl00_ctl00_CPH_MainContainer_CPH_MainContainer_CTL_HotelGuestDetails_GV_HGD_RoomsGrid_ctl02_GV_HGD_PassengerGrid_ctl02_Txt_HGD_CountryCode").value;
    }
    else {
        document.getElementById("ctl00_ctl00_CPH_MainContainer_CPH_MainContainer_CTL_HotelGuestDetails_UC_HotelGuestBookedBy_txtFirstName").value = "First Name";

        document.getElementById("ctl00_ctl00_CPH_MainContainer_CPH_MainContainer_CTL_HotelGuestDetails_UC_HotelGuestBookedBy_txtLastName").value = "Last Name";

        document.getElementById("ctl00_ctl00_CPH_MainContainer_CPH_MainContainer_CTL_HotelGuestDetails_UC_HotelGuestBookedBy_txtEmail").value = "Email Id";

        document.getElementById("ctl00_ctl00_CPH_MainContainer_CPH_MainContainer_CTL_HotelGuestDetails_UC_HotelGuestBookedBy_txtMobileNo").value = "Mobile No.";
        document.getElementById("ctl00_ctl00_CPH_MainContainer_CPH_MainContainer_CTL_HotelGuestDetails_UC_HotelGuestBookedBy_txtCountryCode").value = "Code"

    }
}


function FormSubmit() {
    ShowHoldingDiv();
    FormSubmitted = true;
}

function ShowHoldingDiv() {
    if (window.parent) {
        if (window.parent.document.getElementById('HoldingContainer')) {
            window.parent.document.getElementById('HoldingContainer').style.display = 'block';
            //alert("parent");
        }
    } else {
        if (document.getElementById('HoldingContainer')) {
            document.getElementById('HoldingContainer').style.display = 'block';
        }
    }
    if (Var_ShowPaymentGatewayMessage == true) {
        //document.getElementById('<%=Div_Holding.ClientID %>').Visible = true;
        //document.getElementById('<%=Div_PaymentHolding.ClientID %>').Visible = false;
        document.getElementById('Div_Holding').style.display = 'none';
        document.getElementById('Div_PaymentHolding').style.display = 'block'
    }
    else {
        document.getElementById('Div_Holding').style.display = 'block';
        document.getElementById('Div_PaymentHolding').style.display = 'none'
    }
    //    if (window.parent) {
    //        if (window.parent.document.getElementById('HoldingContainer')) {
    //            window.parent.document.getElementById('HoldingContainer').style.display = 'block';
    //            //alert("parent");
    //        }
    //    } else {
    //        if (document.getElementById('HoldingContainer')) {
    //            document.getElementById('HoldingContainer').style.display = 'block';
    //        }
    //    }
    //alert($('#ctl00_CPH_MainContainer_HotelMain1_UC_HM_HotelDetails_UC_HD_ImageListControl_FU_IU_ImageUpload').MultiFile.files);
}