/**********************************Validate the driver incentive details***************************************/
var AlertDriverConfigNo = 'Please select a No.OfDrivers.';
var AlertDriverConfigAllowance = 'Please enter the Allowance Name.';
var AlertDriverConfigName = 'Please enter the Name.';
var AlertDriverConfigIncentive = 'Please enter the Incentive Name.';
var AlertDriverConfigAllowanceAmount = 'Please enter the Allowance Amount.';
var AlertDriverConfigViolationPoints = 'Please select a Violation Points.';
var AlertDriverConfigPerce = 'Please select a Percentage.';
var AlertDriverConfigAmount = 'Please enter the Rate Per KM Amount.';
var AlertDriverConfigFromRange = 'Please select a From Range KM.';
var AlertDriverConfigToRange = 'Please select a To Range KM.';
var AlertDriverConfigGreaterrange = 'Please select a To Range KM greater than From Range KM.';
var AlertDriverConfigFromTime = 'Please select the From Time.';
var AlertDriverConfigToTime = 'Please select the To Time.';
var AlertDriverConfigVehicleType = 'Please select a Vehicle Type.';
var AlertSelectFromTimeGreater = 'To Time should be greater than the From Time.';

function SetDriverCinfiguration(AlertDriverConfigNoMsg, AlertDriverConfigAllowanceMsg, AlertDriverConfigNameMsg, AlertDriverConfigIncentiveMsg, AlertDriverConfigAllowanceAmountMsg, AlertDriverConfigViolationPointsMsg,
AlertDriverConfigPerceMsg, AlertDriverConfigAmountMsg, AlertDriverConfigFromRangeMsg, AlertDriverConfigToRangeMsg, AlertDriverConfigGreaterrangeMsg, AlertDriverConfigFromTimeMsg, AlertDriverConfigToTimeMsg, AlertDriverConfigVehicleTypeMsg, AlertSelectFromTimeGreaterMsg) {
    AlertDriverConfigNo = AlertDriverConfigNoMsg;
    AlertDriverConfigAllowance = AlertDriverConfigAllowanceMsg;
    AlertDriverConfigName = AlertDriverConfigNameMsg;
    AlertDriverConfigIncentive = AlertDriverConfigIncentiveMsg;
    AlertDriverConfigAllowanceAmount = AlertDriverConfigAllowanceAmountMsg;
    AlertDriverConfigViolationPoints = AlertDriverConfigViolationPointsMsg;
    AlertDriverConfigPerce = AlertDriverConfigPerceMsg;
    AlertDriverConfigAmount = AlertDriverConfigAmountMsg;
    AlertDriverConfigFromRange = AlertDriverConfigFromRangeMsg;
    AlertDriverConfigGreaterrange = AlertDriverConfigGreaterrangeMsg; ;
    AlertDriverConfigToRange = AlertDriverConfigToRangeMsg;
    AlertDriverConfigFromTime = AlertDriverConfigFromTimeMsg;
    AlertDriverConfigToTime = AlertDriverConfigToTimeMsg;
    AlertDriverConfigVehicleType = AlertDriverConfigVehicleTypeMsg;
    AlertSelectFromTimeGreater = AlertSelectFromTimeGreaterMsg;

}
function ValidateIncentive() {

    var ddlVehicleType = document.getElementById('ddlVehicleType');
    var txtdescription = document.getElementById('txtDescription');
    var hdnIsAllowance = document.getElementById('hdnIsAllowance').value
    if (hdnIsAllowance == "true") {
        var ddlFromTime = document.getElementById('ddlFromTime');
        var ddlToTime = document.getElementById('ddlToTime');
        var txtOtherAmt = document.getElementById('txtOtherAmt');
        var ddlNoOfDrivers = document.getElementById('ddlNoOfDrivers');
    }
    else if (hdnIsAllowance == "Violations") {
        var ddlViolationPoints = document.getElementById('ddlViolationPoints');
        var ddlAllowance = document.getElementById('ddlAllowance');
    }
    else {
        var ddlFromRange = document.getElementById('ddlFromRange');
        var ddlToRange = document.getElementById('ddlToRange');
        var txtRatePerKm = document.getElementById('txtRatePerKm');
        var ddlNoOfDrivers = document.getElementById('ddlNoOfDrivers');
    }
    var errorMessage = '';
    var isError = false;

    if (!CheckIsSelected(ddlVehicleType.value)) {
        isError = true;
        ddlVehicleType.focus();
        errorMessage = AlertDriverConfigVehicleType;
        ddlVehicleType.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlVehicleType.style.backgroundColor = 'white';
    }
    if (hdnIsAllowance != "Violations") {
        if (!CheckIsSelected(ddlNoOfDrivers.value)) {
            errorMessage = (isError ? errorMessage + '\n' : '') + AlertDriverConfigNo;
            if (!isError) {
                ddlNoOfDrivers.focus();
                isError = true;
            }
            ddlNoOfDrivers.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlNoOfDrivers.style.backgroundColor = 'white';
        }
    }
    if (RemoveSpaces(txtdescription).length == 0) {
        if (hdnIsAllowance == "true") {
            errorMessage = (isError ? errorMessage + '\n' : '') + AlertDriverConfigAllowance;
        }
        else if (hdnIsAllowance == "Violations") {
            errorMessage = (isError ? errorMessage + '\n' : '') + AlertDriverConfigName;
        }
        else {
            errorMessage = (isError ? errorMessage + '\n' : '') + AlertDriverConfigIncentive;
        }
        if (!isError) {
            txtdescription.focus();
            isError = true;
        }
        txtdescription.style.backgroundColor = 'lightyellow';
    }
    else {
        txtdescription.style.backgroundColor = 'white';
    }

    if (hdnIsAllowance == "true") {
        if (RemoveSpaces(txtOtherAmt).length == 0) {

            errorMessage = (isError ? errorMessage + '\n' : '') + AlertDriverConfigAllowanceAmount;

            if (!isError) {
                txtOtherAmt.focus();
                isError = true;
            }
            txtOtherAmt.style.backgroundColor = 'lightyellow';
        }
        else {
            txtOtherAmt.style.backgroundColor = 'white';
        }
        if (!CheckIsSelectedHr(ddlFromTime.value)) {
            errorMessage = (isError ? errorMessage + '\n' : '') + AlertDriverConfigFromTime;
            if (!isError) {
                ddlFromTime.focus();
                isError = true;
            }
            ddlFromTime.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlFromTime.style.backgroundColor = 'white';
        }
        if (!CheckIsSelectedHr(ddlToTime.value)) {
            errorMessage = (isError ? errorMessage + '\n' : '') + AlertDriverConfigToTime;
            if (!isError) {
                ddlToTime.focus();
                isError = true;
            }
            ddlToTime.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlToTime.style.backgroundColor = 'white';
        }
    }
    else if (hdnIsAllowance == "Violations") {
        if (!CheckIsSelected(ddlViolationPoints.value)) {
            errorMessage = (isError ? errorMessage + '\n' : '') + AlertDriverConfigViolationPoints;
            if (!isError) {
                ddlViolationPoints.focus();
                isError = true;
            }
            ddlViolationPoints.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlViolationPoints.style.backgroundColor = 'white';
        }
        if (!CheckIsSelected(ddlAllowance.value)) {
            errorMessage = (isError ? errorMessage + '\n' : '') + AlertDriverConfigPerce;
            if (!isError) {
                ddlAllowance.focus();
                isError = true;
            }
            ddlAllowance.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlAllowance.style.backgroundColor = 'white';
        }
    }
    else {
        if (RemoveSpaces(txtRatePerKm).length == 0) {

            errorMessage = (isError ? errorMessage + '\n' : '') + AlertDriverConfigAmount;

            if (!isError) {
                txtRatePerKm.focus();
                isError = true;
            }
            txtRatePerKm.style.backgroundColor = 'lightyellow';
        }
        else {
            txtRatePerKm.style.backgroundColor = 'white';
        }
        if (!CheckIsSelected(ddlFromRange.value)) {
            errorMessage = (isError ? errorMessage + '\n' : '') + AlertDriverConfigFromRange;
            if (!isError) {
                ddlFromRange.focus();
                isError = true;
            }
            ddlFromRange.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlFromRange.style.backgroundColor = 'white';
        }
        if (!CheckIsSelected(ddlToRange.value)) {
            errorMessage = (isError ? errorMessage + '\n' : '') + AlertDriverConfigToRange;
            if (!isError) {
                ddlToRange.focus();
                isError = true;
            }
            ddlToRange.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlToRange.style.backgroundColor = 'white';
        }
        if (CheckIsSelected(ddlFromRange.value) && CheckIsSelected(ddlToRange.value)) {
            if (parseInt(ddlFromRange.value) >= parseInt(ddlToRange.value)) {
                errorMessage = (isError ? errorMessage + '\n' : '') + AlertDriverConfigGreaterrange;
                if (!isError) {
                    ddlToRange.focus();
                    isError = true;
                }
                ddlToRange.style.backgroundColor = 'lightyellow';
            }
            else {
                ddlToRange.style.backgroundColor = 'white';
            }
        }
    }

    if (isError) {
        alert(errorMessage);
        return false;
    }
    if (hdnIsAllowance == "true") {
        if (ValidateTime('ddlFromTime', 'ddlToTime', 'ddlFromTimeMin', 'ddlToTimeMin') != true) {
            return false;
        }
    }
    return true;
}
/******************************Validate Driver Details*******************************************************/
var AlertDriverName = 'Please enter the Driver Name.';
var AlertDisplayName = 'Please enter the Display Name.';
var AlertFutureDate = 'Please select a future date.';
var AlertPastDate = 'Please select current or past date.';
var AlertValidateJoining = 'Please select a valid Date of Joining.';
var AlertValidUpload = 'Please upload only JPG/JPEG files.';
var AlertLicenseNo = 'Please enter the License Number.';
var AlertDateOfJoining = 'Please enter the Date Of Joining.';
var AlertLicenseExpiryDate = 'Please enter the License Expiry Date';

function SetDriverMaster(AlertDriverNameMsg, AlertDisplayNameMsg, AlertFutureDateMsg, AlertPastDateMsg, AlertValidateJoiningMsg,AlertLicenseNoMsg,AlertDateOfJoiningMsg,AlertLicenseExpiryDateMsg, AlertValidUploadMsg) {
    AlertDriverName = AlertDriverNameMsg
    AlertDisplayName = AlertDisplayNameMsg
    AlertFutureDate = AlertFutureDateMsg
    AlertPastDate = AlertPastDateMsg
    AlertValidateJoining = AlertValidateJoiningMsg
    AlertLicenseNo = AlertLicenseNoMsg
    AlertDateOfJoining = AlertDateOfJoiningMsg
    AlertLicenseExpiryDate = AlertLicenseExpiryDateMsg
    AlertValidUpload = AlertValidUploadMsg
    
}
var Alert_Delete = "Do you want to really delete this driver?.";

function setAlertMessageDelete(Delete) {
    Alert_Delete = Delete;
}
function DeleteConfirm() {
    //    var Alert_Delete = "Do you want to really delete this driver?.";
    return confirm(Alert_Delete);
}


function ValidateDriverInfo() {
    var txtDriverName = document.getElementById('txtDriverName');
    var txtDisplayName = document.getElementById('txtDisplayName');
    var chkActive = document.getElementById('chkActive');
    var txtDateOfBirth = document.getElementById('txtDateOfBirth');
    var txtTempAddress = document.getElementById('txtTempAddress');
    //var txtPhoneNo = document.getElementById('txtPhoneNo');
    var txtMobileNo = document.getElementById('txtMobileNo');
    var txtLicenseNo = document.getElementById('txtLicenseNo');
    var txtLicenseValidity = document.getElementById('txtLicenseValidity');
    var txtDateOfJoin = document.getElementById('txtDateOfJoining');
    var errorMessage = '';
    var isError = false;
    if (RemoveSpaces(txtDriverName).length == 0) {
        isError = true;
        errorMessage = AlertDriverName;
        txtDriverName.focus();
        txtDriverName.style.backgroundColor = 'lightyellow';
    }
    else {
        txtDriverName.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(txtDisplayName).length == 0) {
        errorMessage = (isError ? errorMessage + '\n' : '') + AlertDisplayName;
        if (!isError) {
            txtDisplayName.focus();
            isError = true;
        }
        txtDisplayName.style.backgroundColor = 'lightyellow';
    }
    else {
        txtDisplayName.style.backgroundColor = 'white';
    }
    //    if (RemoveSpaces(txtDateOfBirth).length == 0) {
    //        errorMessage = (isError ? errorMessage + '\n' : '') + 'Please select the Date Of Birth.';
    //        if (!isError) {
    //            txtDateOfBirth.focus();
    //            isError = true;
    //        }
    //        txtDateOfBirth.style.backgroundColor = 'lightyellow';
    //    }
    //    else {
    //        txtDateOfBirth.style.backgroundColor = 'white';
    //    }
    //    if (RemoveSpaces(txtTempAddress).length == 0) {
    //        errorMessage = (isError ? errorMessage + '\n' : '') + 'Please enter the Mailing Address.';
    //        if (!isError) {
    //            txtTempAddress.focus();
    //            isError = true;
    //        }
    //        txtTempAddress.style.backgroundColor = 'lightyellow';
    //    }
    //    else {
    //        txtTempAddress.style.backgroundColor = 'white';
    //    }
    //    if (txtPhoneNo.value.length > 0) {
    //        if (phoneFormat(txtPhoneNo.value) == false) {
    //            errorMessage += (errorMessage.length > 0 ? '\n' : '') + 'Please enter a valid Phone Number.';
    //            txtPhoneNo.style.backgroundColor = 'lightyellow';

    //            if (!isError) {
    //                txtPhoneNo.focus();
    //                isError = true;
    //            }
    //        }
    //        else {
    //            txtPhoneNo.style.backgroundColor = 'white';
    //        }
    //    }
    //    else {
    //        txtPhoneNo.style.backgroundColor = 'white';
    //    }

    //    if (RemoveSpaces(txtMobileNo).length == 0) {
    //        errorMessage = (isError ? errorMessage + '\n' : '') + 'Please enter the Mobile Number.';
    //        if (!isError) {
    //            txtMobileNo.focus();
    //            isError = true;
    //        }
    //        txtMobileNo.style.backgroundColor = 'lightyellow';
    //    }
    //    else if (txtMobileNo.value.length > 0) {
    //        if (mobileFormat(txtMobileNo.value) == false) {
    //            errorMessage += (errorMessage.length > 0 ? '\n' : '') + 'Please enter a valid Mobile Number.';
    //            txtMobileNo.style.backgroundColor = 'lightyellow';

    //            if (!isError) {
    //                txtMobileNo.focus();
    //                isError = true;
    //            }
    //        }
    //        else {
    //            txtMobileNo.style.backgroundColor = 'white';
    //        }
    //    }
    //    else {
    //        txtMobileNo.style.backgroundColor = 'white';
    //    }

        if (RemoveSpaces(txtLicenseNo).length == 0) {
            errorMessage = (isError ? errorMessage + '\n' : '') + AlertLicenseNo;
            if (!isError) {
                txtLicenseNo.focus();
                isError = true;
            }
            txtLicenseNo.style.backgroundColor = 'lightyellow';
        }
        else {
            txtLicenseNo.style.backgroundColor = 'white';
        }

        if (RemoveSpaces(txtDateOfJoin).length == 0) {
            errorMessage = (isError ? errorMessage + '\n' : '') + AlertDateOfJoining;
            if (!isError) {
                txtDateOfJoin.focus();
                isError = true;
            }
            txtDateOfJoin.style.backgroundColor = 'lightyellow';
        }
        else if (RemoveSpaces(txtDateOfJoin).length > 0) {
            var join = txtDateOfJoin.value.split('/');
            var selecteddate = new Date(join[1] + "/" + join[0] + "/" + join[2]);
            var validdate = new Date((new Date().getMonth() + 2) + "/" + new Date().getDate() + "/" + new Date().getFullYear());
            if (selecteddate > validdate) {
                if (!isError) {
                    txtDateOfJoin.focus();
                    isError = true;
                }
                errorMessage += (errorMessage.length > 0 ? '\n' : '') + AlertValidateJoining;
                txtDateOfJoin.style.backgroundColor = 'lightyellow';
            }
            else {
                txtDateOfJoin.style.backgroundColor = 'white';
            }
        }
        else {
            txtDateOfJoin.style.backgroundColor = 'white';
        }
        if (RemoveSpaces(txtLicenseValidity).length == 0) {
            errorMessage = (isError ? errorMessage + '\n' : '') + AlertLicenseExpiryDate;
            if (!isError) {
                txtLicenseValidity.focus();
                isError = true;
            }
            txtLicenseValidity.style.backgroundColor = 'lightyellow';
        }
        else {
            txtLicenseValidity.style.backgroundColor = 'white';
        }
    if (isError) {
        alert(errorMessage);
    }
    else {
        ShowPopUp();
    }
    return !isError;
}

var AlertSelectDriver = 'Please select a Driver.';
var AlertSelectDiffDriver = 'Please select the different Driver.';
var AlertSelectVehicle = 'Please select a Vehicle.';
var AlertSelectFromTime = 'Please select the From Time.';
var AlertSelectToTime = 'Please select the To Time.';
var AlertSelectFromTimeFirst = 'Please select the From Time first.';
var AlertSelectFromTimeGreater = 'To Time should be greater than the From Time.';
var AlertSelectFutureDate = 'Please select Future Date.';
var AlertSelectDriverName = 'Please select the driver name.';



function SetDriverAssisnment(AlertSelectDriverMsg, AlertSelectDiffDriverMsg, AlertSelectVehicleMsg, AlertSelectFromTimeMsg, AlertSelectToTimeMsg, AlertSelectFromTimeFirstMsg, AlertSelectFromTimeGreaterMsg, AlertSelectDriverNameMsg, AlertSelectFutureDateMsg) {
    AlertSelectDriver = AlertSelectDriverMsg;
    AlertSelectDiffDriver = AlertSelectDiffDriverMsg
    AlertSelectVehicle = AlertSelectVehicleMsg
    AlertSelectFromTime = AlertSelectFromTimeMsg
    AlertSelectToTime = AlertSelectToTimeMsg
    AlertSelectFromTimeFirst = AlertSelectFromTimeMsg
    AlertSelectFromTimeGreater = AlertSelectFromTimeGreaterMsg
    AlertSelectDriverName = AlertSelectDriverNameMsg
    AlertSelectFutureDate = AlertSelectFutureDateMsg
}
function validateAssignmentDetails() {
    var ddlDriver = document.getElementById('ddlDriverName');
    var ddlDriver1 = document.getElementById('ddlSecondDriver');
    var ddlVehicle = document.getElementById('ddlVehicle');
    var ddlFromTime = document.getElementById('ddlFromTime');
    var ddlToTime = document.getElementById('ddlToTime');
    var errorMessage = '';
    var isError = false;

    if (!CheckIsSelected(ddlDriver.value)) {
        isError = true;
        ddlDriver.focus();
        errorMessage = AlertSelectDriver;
        ddlDriver.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlDriver.style.backgroundColor = 'white';
    }
    if (CheckIsSelected(ddlDriver1.value)) {
        if (ddlDriver.value == ddlDriver1.value) {
            isError = true;
            ddlDriver1.focus();
            errorMessage = (isError ? errorMessage + '\n' : '') + AlertSelectDiffDriver;
            ddlDriver1.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlDriver1.style.backgroundColor = 'white';
        }
    }
    else {
        ddlDriver1.style.backgroundColor = 'white';
    }
    if (!CheckIsSelected(ddlVehicle.value)) {
        errorMessage = (isError ? errorMessage + '\n' : '') + AlertSelectVehicle;
        if (!isError) {
            ddlVehicle.focus();
            isError = true;
        }
        ddlVehicle.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlVehicle.style.backgroundColor = 'white';
    }
    if (!CheckIsSelectedHr(ddlFromTime.value)) {
        errorMessage = (isError ? errorMessage + '\n' : '') + AlertSelectFromTime;
        if (!isError) {
            ddlFromTime.focus();
            isError = true;
        }
        ddlFromTime.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlFromTime.style.backgroundColor = 'white';
    }
    if (!CheckIsSelectedHr(ddlToTime.value)) {
        errorMessage = (isError ? errorMessage + '\n' : '') + AlertSelectToTime;
        if (!isError) {
            ddlToTime.focus();
            isError = true;
        }
        ddlToTime.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlToTime.style.backgroundColor = 'white';
    }

    if (isError) {
        alert(errorMessage);
        return false;
    }
    if (ValidateTime('ddlFromTime', 'ddlToTime', 'ddlFromMin', 'ddlToMin') != true) {
        return false;
    }
    return true;
}

function CheckIsSelectedHr(dropdownvalue) {
    return dropdownvalue != 'Hr' ? true : false;
}

function ValidateTime(FromTime, ToTime, FromMinutes, ToMinutes) {


    var ToTimeControl = ToTime;
    var currentTime = new Date().getHours();
    if (document.getElementById(FromTime).value == "Hr") {
        alert(AlertSelectDriverName);
        document.getElementById(ToTime).value = "Hr";
        document.getElementById(FromTime).focus();
        return false;
    }
    else if (document.getElementById(ToTime).value != "Hr") {
        FTime = document.getElementById(FromTime).value;
        FMinutes = document.getElementById(FromMinutes).value;
        TTime = document.getElementById(ToTime).value;
        TMinutes = document.getElementById(ToMinutes).value;
        FTime = eval(FTime) + "." + eval(FMinutes);
        TTime = eval(TTime) + "." + eval(TMinutes);
        if (eval(TTime) <= eval(FTime)) {
            alert(AlertSelectFromTimeGreater);
            document.getElementById(ToTimeControl).value = "Hr";
            document.getElementById(ToTimeControl).focus();
            return false;
        }
        return true;
    }
}

var AlertSelectDriver = 'Please select the driver name.';
var AlertSelectFromDate = 'Please select the From Date.';
var AlertSelectToDate = 'Please select the To Date.';

function DriverIncentiveScreen(AlertSelectDriverMsg, AlertSelectFromDateMsg, AlertSelectToMsg) {
    AlertSelectDriver = AlertSelectDriverMsg;
    AlertSelectFromDate = AlertSelectFromDateMsg
    AlertSelectToDate = AlertSelectToMsg
}

function ValidateDriverSchedule() {
    ddlDriverName = document.getElementById('ddlDriverName');
    txtFromDate = document.getElementById('txtFromDate');
    txtToDate = document.getElementById('txtToDate');
    var errorMessage = '';
    var isError = false;

    if (!CheckIsSelected(ddlDriverName.value)) {
        isError = true;
        ddlDriverName.focus();
        errorMessage = AlertSelectDriver;
        ddlDriverName.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlDriverName.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(txtFromDate).length == 0) {
        errorMessage = (isError ? errorMessage + '\n' : '') + AlertSelectFromDate;
        if (!isError) {
            txtFromDate.focus();
            isError = true;
        }
        txtFromDate.style.backgroundColor = 'lightyellow';
    }
    else {
        txtFromDate.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(txtToDate).length == 0) {
        errorMessage = (isError ? errorMessage + '\n' : '') + AlertSelectToDate;
        if (!isError) {
            txtToDate.focus();
            isError = true;
        }
        txtToDate.style.backgroundColor = 'lightyellow';
    }
    else {
        txtToDate.style.backgroundColor = 'white';
    }
    if (isError) {
        alert(errorMessage);
    }
    return !isError;
}

var AlertScheduleFleetName = "Please select the Fleet Name.";
var AlertScheduleVehicleName = "Please select the Vehicle Name.";
var AlertScheduleFromDate = "Please select the From Date.";
var AlertScheduleToDate = "Please select the To Date.";

//Set Alert message for ScheduleofCommands
function SetAlertMessageScheduleofCommands(ScheduleFleetName, ScheduleVehicleName, ScheduleFromDate, ScheduleToDate) {
    AlertScheduleFleetName = ScheduleFleetName;
    AlertScheduleVehicleName = ScheduleVehicleName;
    AlertScheduleFromDate = ScheduleFromDate;
    AlertScheduleToDate = ScheduleToDate;
}

function ValidateScheduleofCommands() {
    var ddlVehicle;
    ddlFleet = document.getElementById('ddlFleet');
    if (document.getElementById('ddlVehicle1') != null) {
        ddlVehicle = document.getElementById('ddlVehicle1');
    }
    else {
        ddlVehicle = document.getElementById('ddlVehicle');
    }
    txtFromDate = document.getElementById('txtFromDate');
    txtToDate = document.getElementById('txtToDate');

    var errorMessage = '';
    var isError = false;

    if (!CheckIsSelected(ddlFleet.value)) {
        isError = true;
        ddlFleet.focus();
        errorMessage = AlertScheduleFleetName;
        ddlFleet.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlFleet.style.backgroundColor = 'white';
    }

    if (!CheckIsSelected(ddlVehicle.value)) {
        isError = true;
        ddlVehicle.focus();
        errorMessage = AlertScheduleVehicleName;
        ddlVehicle.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlVehicle.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(txtFromDate).length == 0) {
        errorMessage = (isError ? errorMessage + '\n' : '') + AlertScheduleFromDate;
        if (!isError) {
            txtFromDate.focus();
            isError = true;
        }
        txtFromDate.style.backgroundColor = 'lightyellow';
    }
    else {
        txtFromDate.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(txtToDate).length == 0) {
        errorMessage = (isError ? errorMessage + '\n' : '') + AlertScheduleToDate;
        if (!isError) {
            txtToDate.focus();
            isError = true;
        }
        txtToDate.style.backgroundColor = 'lightyellow';
    }
    else {
        txtToDate.style.backgroundColor = 'white';
    }
    if (isError) {
        alert(errorMessage);
    }
    else {
        ShowPopUp();
    }
    return !isError;
}

var Alert_RouteName = "Please select the route name.";
var Alert_FromDate = "Please select the From Date.";
var Alert_ToDate = "Please select the To Date.";

function setAlertMessage(RouteName, FromDate, ToDate) {
    Alert_RouteName = RouteName;
    Alert_FromDate = FromDate;
    Alert_ToDate = ToDate;
}

function ValidateRouteDriverOrVehicleSchedule() {
    ddlRouteName = document.getElementById('ddlRouteName');
    txtFromDate = document.getElementById('txtFromDate');
    txtToDate = document.getElementById('txtToDate');
    var errorMessage = '';
    var isError = false;

    if (!CheckIsSelected(ddlRouteName.value)) {
        isError = true;
        ddlRouteName.focus();
        errorMessage = Alert_RouteName;
        ddlRouteName.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlRouteName.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtFromDate).length == 0) {
        errorMessage = (isError ? errorMessage + '\n' : '') + Alert_FromDate;
        if (!isError) {
            txtFromDate.focus();
            isError = true;
        }
        txtFromDate.style.backgroundColor = 'lightyellow';
    }
    else {
        txtFromDate.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(txtToDate).length == 0) {
        errorMessage = (isError ? errorMessage + '\n' : '') + Alert_ToDate;
        if (!isError) {
            txtToDate.focus();
            isError = true;
        }
        txtToDate.style.backgroundColor = 'lightyellow';
    }
    else {
        txtToDate.style.backgroundColor = 'white';
    }
    if (isError) {
        alert(errorMessage);
    }
    else {
        ShowPopUp();
    }
    return !isError;
}
function ValidateRouteDriverOrVehicleScheduleNew() {
    ddlRouteName = document.getElementById('ddlRouteName');
    txtFromDate = document.getElementById('txtStartDateRouteList');
    txtToDate = document.getElementById('txtEndDateRouteList');
    var errorMessage = '';
    var isError = false;

    if (!CheckIsSelected(ddlRouteName.value)) {
        isError = true;
        ddlRouteName.focus();
        errorMessage = Alert_RouteName;
        ddlRouteName.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlRouteName.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtFromDate).length == 0) {
        errorMessage = (isError ? errorMessage + '\n' : '') + Alert_FromDate;
        if (!isError) {
            txtFromDate.focus();
            isError = true;
        }
        txtFromDate.style.backgroundColor = 'lightyellow';
    }
    else {
        txtFromDate.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(txtToDate).length == 0) {
        errorMessage = (isError ? errorMessage + '\n' : '') + Alert_ToDate;
        if (!isError) {
            txtToDate.focus();
            isError = true;
        }
        txtToDate.style.backgroundColor = 'lightyellow';
    }
    else {
        txtToDate.style.backgroundColor = 'white';
    }
    if (isError) {
        alert(errorMessage);
    }
    else {
        ShowPopUp();
    }
    return !isError;
}

var AlertVehicleName = "Please select the Vehicle Name.";
var AlertVehicleFromDate = "Please select the From Date.";
var AlertVehicleToDate = "Please select the To Date.";

function SetAlertValidateVehicle(AlertVehicleNameMsg, AlertVehicleFromDateMsg, AlertVehicleToDateMsg) {
    AlertVehicleName = AlertVehicleNameMsg;
    AlertVehicleFromDate = AlertVehicleFromDateMsg;
    AlertVehicleToDate = AlertVehicleToDateMsg;
}
function ValidateVehicleSchedule() {
    ddlVehicleName = document.getElementById('ddlVehicleName');
    txtFromDate = document.getElementById('txtFromDate');
    txtToDate = document.getElementById('txtToDate');
    var errorMessage = '';
    var isError = false;

    if (!CheckIsSelected(ddlVehicleName.value)) {
        isError = true;
        ddlVehicleName.focus();
        errorMessage = AlertVehicleName;
        ddlVehicleName.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlVehicleName.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(txtFromDate).length == 0) {
        errorMessage = (isError ? errorMessage + '\n' : '') + AlertVehicleFromDate;
        if (!isError) {
            txtFromDate.focus();
            isError = true;
        }
        txtFromDate.style.backgroundColor = 'lightyellow';
    }
    else {
        txtFromDate.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(txtToDate).length == 0) {
        errorMessage = (isError ? errorMessage + '\n' : '') + AlertVehicleToDate;
        if (!isError) {
            txtToDate.focus();
            isError = true;
        }
        txtToDate.style.backgroundColor = 'lightyellow';
    }
    else {
        txtToDate.style.backgroundColor = 'white';
    }
    if (isError) {
        alert(errorMessage);
    }
    return !isError;
}
//Set Alert message to the variable.
var AlertGreaterThanFromDate = "Please select To date greater than From date..!";
function ScheduleDateValidation(GreaterThanFromDate) {
    AlertGreaterThanFromDate = GreaterThanFromDate;
}
function checkDate(sender, args) {
    if ((document.getElementById("txtFromDate").value != "" && document.getElementById("txtFromDate").value != null) && (document.getElementById("txtToDate").value != "" && document.getElementById("txtToDate").value != null)) {
        var FromdateStr = new Array(3);
        FromdateStr = String(document.getElementById("txtFromDate").value).split('/');
        ToDateStr = String(document.getElementById("txtToDate").value).split('/');
        if (ToDateStr.length > 2) {
            var day = FromdateStr[0];
            var month = FromdateStr[1];
            var year = FromdateStr[2];
            var tDay = ToDateStr[0];
            var tMonth = ToDateStr[1];
            var tYear = ToDateStr[2];
            var fromDate = new Date(month + "/" + day + "/" + year);
            var toDate = new Date(tMonth + "/" + tDay + "/" + tYear);
            if (fromDate > toDate) {
                alert(AlertGreaterThanFromDate);
                document.getElementById("txtToDate").value = "";
                document.getElementById("txtToDate").focus();
            }
            else {
                document.getElementById("txtToDate").focus();
            }
        }
    }
}

function CheckGreaterThanFromdate(sender, args) {
    if ((document.getElementById("txtFromDate").value != "" && document.getElementById("txtFromDate").value != null) && (document.getElementById("txtToDate").value != "" && document.getElementById("txtToDate").value != null)) {
        var FromdateStr = new Array(3);
        FromdateStr = String(document.getElementById("txtFromDate").value).split('/');
        var day = FromdateStr[0];
        var month = FromdateStr[1];
        var year = FromdateStr[2];
        var fromDate = new Date(month + "/" + day + "/" + year);
        if (fromDate > sender._selectedDate) {
            alert(AlertGreaterThanFromDate);
            document.getElementById("txtToDate").value = "";
            document.getElementById("txtToDate").focus();
        }
    }
}

function LoadImage(id) {
    if (validateFileUpload(id)) {
        document.getElementById('hdnDriverImage').value = '';
        document.getElementById('hdnDriverImage').value = document.getElementById('fpDriver').value;
        document.getElementById('btnLoadPhoto').click();
    }

}



function checkPastDate(sender, args) {
    if (sender._selectedDate <= new Date()) {
        alert(AlertFutureDate);
        sender._selectedDate = new Date();
        sender._textbox.set_Value("");
    }
}
function checkFutureDate(sender, args) {
    if (sender._selectedDate >= new Date()) {
        alert(AlertPastDate);
        sender._selectedDate = new Date();
        sender._textbox.set_Value("");
    }
    else {
        ValidateDOB();
    }
}
function FutureDate(sender, args) {
    if (sender._selectedDate >= new Date()) {
        alert(AlertPastDate);
        sender._selectedDate = new Date();
        sender._textbox.set_Value("");
    }
}

function chkCharWithDot(e) {
    var c = event.keyCode;
    // Checking if the Dot and White Space is in the beginning
    if ((c == 46 || c == 32) && e == '') {
        return false;
    }
    event.keyCode = (!((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c == 46) || (c == 32))) ? 0 : event.keyCode;
}
function Checkdate(txt) {
    var date = String(txt.value).split('/');
    var selectedDate = new Date(date[1] + '/' + date[0] + '/' + date[2]);
    var fromValidDate = new Date(new Date().getMonth() + '/' + new Date().getDate() + '/' + new Date().getFullYear());
    var toValidDate = new Date(new Date().getMonth() + 2 + '/' + new Date().getDate() + '/' + new Date().getFullYear())

    if ((selectedDate < fromValidDate) || (selectedDate > toValidDate)) {
        alert(AlertValidateJoining);
        txt.value = '';
        txt.focus();
    }
}
function doCheckBackSpaceOrDelete() {
    var keyCode = (event.which) ? event.which : event.keyCode;

    if (keyCode == 8 || keyCode == 46)

        event.returnValue = false;
}
//Comented by Jeyanthi on 04-Aug-2010
//    function chkAlphaNumericWithoutSpace(e, object, MaxLength) {
//        if (object.value.length > MaxLength) return false;
//        var c = event.keyCode;
//        event.keyCode = (!((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c > 47 && c < 58))) ? 0 : event.keyCode;
//    }
//End
function validateFileUpload(obj) {
    var fileName = new String();
    var fileExtension = new String();
    var validFile = ".jpg,.jpeg";
    var validFileExtensions = validFile.split(',');
    var flag = false;
    // store the file name into the variable
    fileName = document.getElementById(obj).value;
    // extract and store the file extension into another variable
    fileExtension = fileName.substr(fileName.lastIndexOf('.'), fileName.length);
    // Check over the valid file extensions to compare them with uploaded file
    for (var i = 0; i < validFileExtensions.length; i++) {
        if (fileExtension.toLowerCase() == validFileExtensions[i].toString().toLowerCase()) {
            flag = true;
        }
    }
    // display the alert message box according to the flag value
    if (flag == false) {
        alert(AlertValidUpload);
        var file = document.getElementById(obj);
        file.value = "";
        var file1 = file.cloneNode(false);
        file1.onchange = file.onchange;
        file.parentNode.replaceChild(file1, file);
        return false;
    }
    else {
        return true;
    }
}

function ValidateDOB() {
    var txtDateOfBirth = document.getElementById('txtDateOfBirth');
    var age = txtDateOfBirth.value.split('/');
    var checkYear = new Date().getFullYear() - 18;
    var selecteddate = new Date(age[1] + "/" + age[0] + "/" + age[2]);
    var validdate = new Date((new Date().getMonth() + 1) + "/" + new Date().getDate() + "/" + checkYear);
    if (selecteddate > validdate) {
        txtDateOfBirth.value = '';
        txtDateOfBirth.focus();
        alert('Please enter a valid Date of Birth.');
        txtDateOfBirth.style.backgroundColor = 'lightyellow';
        return true;
    }
    else {
        txtDateOfBirth.style.backgroundColor = 'white';
        return false;
    }
}
var AlertSelectRating = 'Please select the behavior rating.';

function DriverBehaviorRating(AlertSelectRatingMsg) {
    AlertSelectRating = AlertSelectRatingMsg;
}

function ValidateBehavior() {
    var ddlRating = document.getElementById('ddlRating');
    if (ddlRating.value == "- Select -") {
        alert(AlertSelectRating);
        ddlRating.focus();
        ddlRating.style.backgroundColor = 'lightyellow';
        return false;
    }
    ddlRating.style.backgroundColor = 'white';
    return true;
}
var isPopupClose = false;
var s1, e1;
function calSelection(s, e) {
    
    if (isPopupClose == true) {
        if (s != null) {
            isPopupClose = false;
            clearFields();
            s.SetSelectedDate(null);
            return;
        }
        else {
            document.getElementById('btnTest').click();
            clearFields();
            $find('modalView').hide();
            //document.getElementById('pnlViewSchedule').className = 'ControlHide';
        }
    }
    else {
        s1 = s;
        e1 = e;
        if (document.getElementById('hdnIsAdmin').value != 'true') {
            var selecteddate = new Date(s.GetSelectedDate());
            selecteddate = new Date(selecteddate.getFullYear(), selecteddate.getMonth(), selecteddate.getDate());
            var date = new Date();
            date = new Date(date.getFullYear(), date.getMonth(), date.getDate());
            if (selecteddate < date) {
                alert(AlertSelectFutureDate);
                return false;
            }
        }
        var driver = document.getElementById('ddlDriverName');
        if (!CheckIsSelected(driver.value)) {
            alert(AlertSelectDriverName);
            driver.focus();
        }
        else {
            $find('modalView').show();
            //document.getElementById('pnlViewSchedule').className = 'ControlShow';
        }
    }
}

var AlertDateareConflicted = 'The Selected date(s) are conflicted to the existing date(s).do you want to replace all.';

function DriverAssignmentDateConflict(AlertDateareConflictedMsg) {
    AlertDateareConflicted = AlertDateareConflictedMsg;
}

function confirmCon() {
    if (confirm(AlertDateareConflicted)) {
        document.getElementById('btnSaveConflict').click();
    }
    else {
        document.getElementById('btnTest').click();
    }
}
function ClosePopup() {
    //        document.getElementById('btnTest').click();
    isPopupClose = true;
    calSelection(s1, e1);
    $find('modalView').hide();
    //document.getElementById('pnlViewSchedule').className = 'ControlHide';
}
function clearFields() {
    //    document.getElementById('ddlVehicle').value = '- Select -' || '- اختر -';
    //    document.getElementById('ddlSecondDriver').value = '- Select -' || '- اختر -';
    document.getElementById('ddlFromTime').value = 'Hr';
    document.getElementById('ddlToMin').value = '00';
    document.getElementById('ddlFromMin').value = '00';
    document.getElementById('ddlToTime').value = 'Hr';
    document.getElementById('ddlFromPlace').selectedIndex = 0;
    document.getElementById('ddlToPlace').selectedIndex = 0;
    document.getElementById('ddlVehicle').selectedIndex = 0;
    document.getElementById('ddlSecondDriver').selectedIndex = 0;
    
    return false;
}

function CheckIsSelected(dropdownvalue) {
    if (dropdownvalue != '- Select -' && dropdownvalue != '- اختر -' && dropdownvalue != '- चयन करें -')
        return true;
    else
        return false;
}

function RemoveSpaces(fieldName) {
    var s;
    if (typeof (fieldName) == 'object') {
        s = fieldName.value;
    }
    else {
        s = fieldName;
    }
    s = s.replace(/(^\s*)|(\s*$)/gi, "");
    s = s.replace(/[ ]{2,}/gi, " ");
    s = s.replace(/\n /, "\n");
    if (typeof (fieldName) == 'object') {
        fieldName.value = s;
    }
    return s;
}