// FORM VALIDATIONS

/************************Login Validations *******************************/
function ValidateLoginValues() {
    var loginName = document.getElementById('txtUserName');
    var password = document.getElementById('txtPassword');
    //var orgCode = document.getElementById('txtOrganizationCode');

    var isError = false;
    var errorField;
    var alertMessage = '';

    s = loginName.value.replace(/(^\s*)|(\s*$)/gi, "");
    s = s.replace(/[ ]{2,}/gi, " ");
    s = s.replace(/\n /, "\n");

    if (s.length == 0) {
        alertMessage = 'Please enter your user name!';
        isError = true;
        loginName.style.backgroundColor = 'lightyellow';
        errorField = loginName;
    }
    else {
        loginName.style.backgroundColor = 'white';
    }

    s = password.value.replace(/(^\s*)|(\s*$)/gi, "");
    s = s.replace(/[ ]{2,}/gi, " ");
    s = s.replace(/\n /, "\n");

    if (s.length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter your password!';
        password.style.backgroundColor = 'lightyellow';
        if (!isError) {
            errorField = password;
        }
        isError = true;
    }
    else {
        password.style.backgroundColor = 'white';
    }
    //s = orgCode.value.replace(/(^\s*)|(\s*$)/gi, "");
    //s = s.replace(/[ ]{2,}/gi, " ");
    //s = s.replace(/\n /, "\n");

    //if (s.length == 0) {
    //    alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter your organization code!';
    //    orgCode.style.backgroundColor = 'lightyellow';
    //    if (!isError) {
    //        errorField = orgCode;
    //    }
    //    isError = true;
    //}
    //else {
    //    orgCode.style.backgroundColor = 'white';
    //}

    if (isError) {
        errorField.focus();
        alert(alertMessage);
        return false;
    }
    return true;
}

function ValidateForgotPwdValues() {
    var loginName = document.getElementById('txtUserNameFP');
    //var orgCode = document.getElementById('txtOrganizationCodeFP');

    var isError = false;
    var errorField;
    var alertMessage = '';

    s = loginName.value.replace(/(^\s*)|(\s*$)/gi, "");
    s = s.replace(/[ ]{2,}/gi, " ");
    s = s.replace(/\n /, "\n");

    if (s.length == 0) {
        alertMessage = 'Please enter your user name!';
        isError = true;
        loginName.style.backgroundColor = 'lightyellow';
        errorField = loginName;
    }
    else {
        loginName.style.backgroundColor = 'white';
    }

    //s = orgCode.value.replace(/(^\s*)|(\s*$)/gi, "");
    //s = s.replace(/[ ]{2,}/gi, " ");
    //s = s.replace(/\n /, "\n");

    //if (s.length == 0) {
    //    alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter your organization code!';
    //    orgCode.style.backgroundColor = 'lightyellow';
    //    if (!isError) {
    //        errorField = orgCode;
    //    }
    //    isError = true;
    //}
    //else {
    //    orgCode.style.backgroundColor = 'white';
    //}

    if (isError) {
        errorField.focus();
        alert(alertMessage);
        return false;
    }
    return true;
}
/*************************************************************************/

function Validation(incorrectPwdMessage, minPasswordChar) {
    var oldPassword = RemoveSpaces(document.getElementById('txtOldPassword'));
    var NewPassword = RemoveSpaces(document.getElementById('txtNewPassword'));
    var confirmPassword = RemoveSpaces(document.getElementById('txtConfirmNewPassword'));

    var isError = false;
    var alertMessage = '';

    if (incorrectPwdMessage.length != 0) {
        alertMessage = 'Password entered is invalid!';
    }

    if (oldPassword.length == 0) {
        isError = true;
        alertMessage = (alertMessage.length == 0 ? '' : alertMessage + '\n') + 'Please enter your old password !';
        document.getElementById('txtOldPassword').focus();
        document.getElementById('txtOldPassword').style.backgroundColor = 'lightyellow';
    }
    else {
        document.getElementById('txtOldPassword').style.backgroundColor = 'white';
    }



    if (NewPassword.length == 0) {
        alertMessage = (alertMessage.length == 0 ? '' : alertMessage + '\n') + 'Please enter your new password without spaces !';
        if (!isError) {
            document.getElementById('txtNewPassword').focus();
        }
        document.getElementById('txtNewPassword').style.backgroundColor = 'lightyellow';
        isError = true;
    }

    else if (NewPassword.length < minPasswordChar) {
        alertMessage = (alertMessage.length == 0 ? '' : alertMessage + '\n') +
                      'Password should have atleast ' + minPasswordChar + ' characters !';
        if (!isError) {
            document.getElementById('txtNewPassword').focus();
        }
        isError = true;
        document.getElementById('txtNewPassword').style.backgroundColor = 'lightyellow';
    }

    if (oldPassword == NewPassword && NewPassword.length > 0) {
        alertMessage = (alertMessage.length == 0 ? '' : alertMessage + '\n') +
                      'New password cannot be same as the old password !';
        if (!isError) {
            document.getElementById('txtNewPassword').focus();
        }
        isError = true;
        document.getElementById('txtNewPassword').style.backgroundColor = 'lightyellow';
    }
    else {


        confirmPassword = confirmPassword.replace(/(^\s*)|(\s*$)/gi, "");
        confirmPassword = confirmPassword.replace(/[ ]{2,}/gi, " ");
        confirmPassword = confirmPassword.replace(/\n /, "\n");

        if (confirmPassword.length == 0) {
            alertMessage = (alertMessage.length == 0 ? '' : alertMessage + '\n') +
                      'Please confirm your new password !';
            if (!isError) {
                document.getElementById('txtConfirmNewPassword').focus();
            }
            isError = true;
            document.getElementById('txtConfirmNewPassword').style.backgroundColor = 'lightyellow';
        }

        else if (confirmPassword != NewPassword) {
            alertMessage = (alertMessage.length == 0 ? '' : alertMessage + '\n') +
                      'Password confirmation is not valid !';
            if (!isError) {
                document.getElementById('txtConfirmNewPassword').focus();
            }
            isError = true;
            document.getElementById('txtConfirmNewPassword').style.backgroundColor = 'lightyellow';
        }
    }
    if (isError) {
        alert(alertMessage);
        return false;
    }
    else {
        return true;
    }
}

/*********************************** Call Back Function *********************************/
//return the value to the Call Server
function ClientCallback(txt, IdentifierName) {
    var txtval = txt.value + '|' + IdentifierName
    CallServer(txtval, txt)
}

//return the results

function ReceiveServerData(arg, context) {

    //Split the arg, it contains pass/fail & its Identifier Name
    var arr = arg.split('|')
    var arg1 = arr[0]
    var arg2 = arr[1]

    if (arg1 == "f") {  // Invalid Password while changing the password

        //        alert('Invalid ' + arg2);
        context.value = "";
        context.focus();
        document.getElementById('txtOldPassword').style.backgroundColor = 'lightyellow';
        alert("Password entered is invalid !");
        //Validation('Invalid ' + arg2);
    }

    else if (arg1 == "onsf") {
        //        alert('Invalid ' + arg2);
        context.value = "";
        context.focus();
        document.getElementById('txtNewPassword').style.backgroundColor = 'lightyellow';
        alert("New password cannot be same as the old password !");
    }

    else if (arg1 == "ouf") { // User name already exists while updating user info
        //context.value = "";
        context.focus();
        document.getElementById('txtUserName').style.backgroundColor = 'lightyellow';
        alert("User name already exists !");
        //ValidateUserInformation(false, true);
    }
    else if (arg1 == "nuf") { // User name already exists while adding user
        //context.value = "";
        context.focus();
        document.getElementById('txtUserName').style.backgroundColor = 'lightyellow';
        alert("User name already exists !");
        //ValidateUserInformation(true, true);
    }

    else if (arg1 == "vNf") { // Vehicle Name already exists
        //context.value = "";
        context.focus();
        document.getElementById('txtVehName').style.backgroundColor = 'lightyellow';
        alert("Sensor name already exists !");
        //ValidateVehicleInfo(false, true, true);
    }
    else if (arg1 == "sNf") { // Vehicle Name already exists      
        context.focus();
        document.getElementById('txtSensorName').style.backgroundColor = 'lightyellow';
        alert("Sensor name already exists !");

    }
    else if (arg1 == "sDf") { // Vehicle Display Name already exists      
        context.focus();
        document.getElementById('txtDisplayName').style.backgroundColor = 'lightyellow';
        alert("Sensor Display Name already exists !");
    }
    else if (arg1 == "vIf") { // VIN already exists
        //context.value = "";
        context.focus();
        document.getElementById('txtVIN').style.backgroundColor = 'lightyellow';
        alert("VIN already exists !");
        //ValidateVehicleInfo(true, false, true);
    }
    else if (arg1 == "vLf") { // Licence Plate already exists
        //context.value = "";
        context.focus();
        document.getElementById('txtLICPlate').style.backgroundColor = 'lightyellow';
        alert("License Plate Name already exists !");
        //ValidateVehicleInfo(true, true, false);
    }

    else if (arg1 == "vDf") { // Vehicle Display Name already exists
        //context.value = "";
        context.focus();
        document.getElementById('txtDisplayName').style.backgroundColor = 'lightyellow';
        alert("Sensor Display Name already exists !");
    }

    else if (arg1 == "fNf") { // Fleet name already exists
        context.focus();
        FleetValidation(false);
    }
    else if (arg1 == "snf") {  // Sensor Name invalid / duplicated
        context.focus();
        CheckSensorName(false, 'txtSensorNameEdit', 'txtActionOnEdit', 'txtActionOffEdit');
    }
    else if (arg1 == "opnf") {  // Output Name invalid / duplicated
        context.focus();
        CheckOutputName(false, 'txtOutputName', 'txtOutputActionOn', 'txtOutputActionOff');
    }
    else if (arg1 == "fGC") { // Geozone Category name invalid.
        context.value = "";
        context.focus();
        alert('Category name already exists !');
    }
    else if (arg1 == "mp") { //Sms notifications is set to this mobile no.
        alert('The user is set for receiving SMS notification.\nIf the mobile number is not specified then no notification will be given !');
    }
    else if (arg1 == "GNf") { //Geozone Name Already Exists
        context.value = "";
        context.focus();
        alert('Geozone name already exists !');
    }
    else if (arg1 == "LNf") { //Landmark Name Already Exists
        context.value = "";
        context.focus();
        alert('Location name already exists !');
    }
    else if (arg1 == "LCNf") { //Landmark Category Name Already Exists
        context.value = "";
        context.focus();
        alert('Category name already exists !');
    }
    else if (arg1 == "mSNf") {  // Maintenance Service Name exists
        context.value = "";
        context.focus();
        alert('Maintenance Service Name already exists.');
    }
    else if (arg1 == "sCNf") {  // Maintenance Service Category Name exists
        context.value = "";
        context.focus();
        alert('Service Package Name already exists.');
    }
    else if (arg1 == "mPNf") { // Maintenance Plan Name Already Exists
        context.value = "";
        context.focus();
        alert('Maintenance Plan Name already exists.');
    }
    else if (arg1 == "ocf") { // Organization Code exists
        context.value = "";
        context.focus();
        alert('Organization code already exists !');
    }
    else if (arg1 == "odf") { // Organization Display Name exists
        context.value = "";
        context.focus();
        alert('Display name already exists !');
    } else if (arg1 == "ovf") {  // Organization VAT Number exists
        context.value = "";
        context.focus();
        alert('VAT Number already exists !');
    }
    else if (arg1 == "onf") {  // Organization Name exists
        context.value = "";
        context.focus();
        alert('Organization name already exists !');
    }
    else if (arg1 == "pNf") {  // Package Name exists
        context.focus();
        ValidatePackageCreation(false);
    }
    else if (arg1 == "uGf") {  // User Group Name exists
        context.focus();
        ValidateUserGroupInformation(false);
    }
}

/*******************************************************************************************/

/********************************Fleet Validations******************************************/

function GetConfirmationforUG(Mode, isOwnGroup, isDefault, assignedStatus) {
    if (isDefault == 1) {
        alert('Cannot ' + Mode + ' the default user group !');
        return false;
    }
    else if (Mode == 'edit' && isOwnGroup == 1) {
        alert('Cannot edit your own user group !');
        return false;
    }
    else if (Mode == 'delete' && assignedStatus == 1) {
        alert('Cannot delete the user group as it is assigned to user(s) !');
        return false;
    }
    else {
        if (Mode == 'delete') {
            return confirm('Are you sure you want to delete this entry?');
        }
        else {
            return true;
        }
    }
}

function GetConfirmation(FleetName, assignedStatus, isFleet) {
    if (isFleet == 1) {
        if (FleetName == 'True') {
            alert('Cannot delete the default sensor group !');
            return false;
        }
        else if (assignedStatus == 1) {
            alert('User(s) / Sensor(s) have been allocated to this sensor group so unable to delete !');
            return false;
        }
        else {
            return confirm('Are you sure you want to delete this entry?');
        }
    }
    else if (isFleet == 2) {
        if (FleetName == 'deletepackage' && assignedStatus == 1) {
            alert('Cannot delete the package as it is assigned to organization(s) !');
            return false;
        }
        else {
            if (FleetName == 'deletepackage') {
                return confirm('Are you sure you want to delete this entry?');
            }
            else {
                return true;
            }
        }
    }
    else if (isFleet == 3) {
        if (assignedStatus == 1) {
            alert('Cannot delete the geozone as it is assigned to sensor(s) !');
            return false;
        }
        else {
            return confirm('Are you sure you want to delete this entry?');
        }
    }
}

// Function to check for Mandatory Field and Email & SMS Validation
function FleetValidation(isFleetNameValid) {
    var txtFleetName = document.getElementById("txtFleetName");
    var txtDescription = document.getElementById("txtDescription");
    // var ddlTimeZone = document.getElementById('ddlTimeZone');

    var isError = false;
    var alertMessage = '';
    var controlToBeFocused;

    if (!isFleetNameValid) {
        isError = true;
        alertMessage = 'Sensor group name already exists!';
        txtFleetName.style.backgroundColor = 'lightyellow';
        controlToBeFocused = txtFleetName;
    }
    else if (RemoveSpaces(txtFleetName).length == 0) {
        isError = true;
        alertMessage = 'Please enter the sensor group name !';
        txtFleetName.style.backgroundColor = 'lightyellow';
        controlToBeFocused = txtFleetName;
    }
    else if (reFieldValidations(txtFleetName.value, "AlphaNumericWithSpace") == false) {
        isError = true;
        alertMessage = 'Please enter valid sensor group name !';
        txtFleetName.style.backgroundColor = 'lightyellow';
        controlToBeFocused = txtFleetName;
    }
    else {
        txtFleetName.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtDescription).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the description !';
        txtDescription.style.backgroundColor = 'lightyellow';

        if (!isError) {
            controlToBeFocused = txtDescription
            isError = true;
        }
    }
    else if (RemoveSpaces(txtDescription).length > 250) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Length of the description should not be greater than 250 !';
        txtDescription.style.backgroundColor = 'lightyellow';

        if (!isError) {
            controlToBeFocused = txtDescription
            isError = true;
        }
    }
    else {
        txtDescription.style.backgroundColor = 'white';
    }

    if (!CheckSeveritySelection('chkEmailSeverities')) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select any one of the severity level !';
        document.getElementById('chkEmailSeverities').style.backgroundColor = 'lightyellow';
        if (!isError) {
            controlToBeFocused = document.getElementById("chkEmailSeverities_0");
            isError = true;
        }
    }
    else {
        document.getElementById('chkEmailSeverities').setAttribute('style', ''); //.style.backgroundColor = 'white';
    }
    /* if (!CheckIsSelected(ddlTimeZone.value)) {
    alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select the timezone !';

        if (!isError) {
    controlToBeFocused = ddlTimeZone;
    isError = true;
    }
    ddlTimeZone.style.backgroundColor = 'lightyellow';
    }
    else {
    ddlTimeZone.style.backgroundColor = 'white';
    }*/

    if (isError) {
        alert(alertMessage);
        controlToBeFocused.focus();
        return false;
    }
    return true;
}
/**********************************************************************************************/
function ValidateSensorInfo(BoxStatus) {
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';
    var ddlBoxId = document.getElementById('ddlBoxId');
    var txtSensorName = document.getElementById('txtSensorName');
    //var txtDisplayName = document.getElementById('txtDisplayName');
    var txtSensorLocation = document.getElementById('txtSensorLocation');

    if (BoxStatus == true) {
        if (!CheckIsSelected(ddlBoxId.value)) {
            alertMessage = 'Please select the Box Id !';
            isError = true;
            controlToBeFocused = ddlBoxId;
            ddlBoxId.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlBoxId.style.backgroundColor = 'white';
        }
    }
    if (RemoveSpaces(txtSensorName).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the sensor name !';
        if (!isError) {
            isError = true;
            controlToBeFocused = txtSensorName;
        }
        txtSensorName.style.backgroundColor = 'lightyellow';
    }
    else {
        txtSensorName.style.backgroundColor = 'white';
    }

//    if (RemoveSpaces(txtDisplayName).length == 0) {
//        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the sensor display name !';
//        if (!isError) {
//            isError = true;
//            controlToBeFocused = txtDisplayName;
//        }
//        txtDisplayName.style.backgroundColor = 'lightyellow';
//    }
//    else {
//        txtDisplayName.style.backgroundColor = 'white';
//    }
    //    if (RemoveSpaces(txtSensorLocation).length == 0) {
    //        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the sensor location !';
    //        if (!isError) {
    //            isError = true;
    //            controlToBeFocused = txtSensorLocation;
    //        }
    //        txtSensorLocation.style.backgroundColor = 'lightyellow';
    //    }
    //    else {
    //        txtSensorLocation.style.backgroundColor = 'white';
    //    }
    if (!CheckSeveritySelection('chkSeverities')) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select any one of the severity level !';
        document.getElementById('chkSeverities').style.backgroundColor = 'lightyellow';
        if (!isError) {
            controlToBeFocused = document.getElementById('chkSeverities_0');
            isError = true;
        }
    }
    else {
        document.getElementById('chkSeverities').setAttribute('style', ''); //.style.backgroundColor = 'white';
    }
    if (isError) {
        controlToBeFocused.focus();
        alert(alertMessage);
        return false;
    }
    else {
        return true;
    }
}

/*********************************Vehicle Level Validations************************************/
function ValidateVehicleInfo(isVehicleNameValid, isVINValid, isLicensePlateValid) {
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    var dtCurrentDate = new Date();

    var ddlBoxId = document.getElementById('ddlBoxId');
    var txtVehName = document.getElementById('txtVehName');
    //var txtDisplayName = document.getElementById('txtDisplayName');
    var ddlVehType = document.getElementById('ddlVehType');
    var txtVIN = document.getElementById('txtVIN');
    var ddlVehMake = document.getElementById('ddlVehMake');
    var txtLICPlate = document.getElementById('txtLICPlate');
    var ddlModel = document.getElementById('ddlModel');
    //var ddlTimezone = document.getElementById('ddlTimezone');
    var txtYear = document.getElementById('txtYear');
    //    var chkSeverities = document.getElementById('chkSeverities');
    var txtColor = document.getElementById('txtColor');

    if (ddlBoxId != null) {
        if (!CheckIsSelected(ddlBoxId.value)) {
            alertMessage = 'Please select the Box Id !';
            isError = true;
            controlToBeFocused = ddlBoxId;
            ddlBoxId.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlBoxId.style.backgroundColor = 'white';
        }
    }

    if (!isVehicleNameValid) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Sensor Name already exists !';
        if (!isError) {
            isError = true;
            controlToBeFocused = txtVehName;
        }
        txtVehName.style.backgroundColor = 'lightyellow';
    }
    else if (RemoveSpaces(txtVehName).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the sensor name !';
        if (!isError) {
            isError = true;
            controlToBeFocused = txtVehName;
        }
        txtVehName.style.backgroundColor = 'lightyellow';
    }
    else {
        txtVehName.style.backgroundColor = 'white';
    }

//    if (RemoveSpaces(txtDisplayName).length == 0) {
//        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the sensor display name !';
//        if (!isError) {
//            isError = true;
//            controlToBeFocused = txtDisplayName;
//        }
//        txtDisplayName.style.backgroundColor = 'lightyellow';
//    }
//    else {
//        txtDisplayName.style.backgroundColor = 'white';
//    }

    if (!isVINValid) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'VIN already exists !';
        if (!isError) {
            controlToBeFocused = txtVIN;
            isError = true;
        }
        txtVIN.style.backgroundColor = 'lightyellow';
    }
    else if (RemoveSpaces(txtVIN).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the VIN !';
        if (!isError) {
            controlToBeFocused = txtVIN;
            isError = true;
        }
        txtVIN.style.backgroundColor = 'lightyellow';
    }
    else if (reFieldValidations(txtVIN.value, "AlphaNumericWithoutSpace") == false) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter valid VIN !';
        if (!isError) {
            controlToBeFocused = txtVIN;
            isError = true;
        }
        txtVIN.style.backgroundColor = 'lightyellow';
    }
    else {
        txtVIN.style.backgroundColor = 'white';
    }

    if (!CheckIsSelected(ddlVehMake.value)) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select the sensor make !';
        if (!isError) {
            controlToBeFocused = ddlVehMake;
            isError = true;
        }
        ddlVehMake.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlVehMake.style.backgroundColor = 'white';
    }

    if (!isLicensePlateValid) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'License Plate Name already exists !';
        if (!isError) {
            controlToBeFocused = txtLICPlate;
            isError = true;
        }
        txtLICPlate.style.backgroundColor = 'lightyellow';
    }
    else if (RemoveSpaces(txtLICPlate).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the LIC Plate !';
        if (!isError) {
            controlToBeFocused = txtLICPlate;
            isError = true;
        }
        txtLICPlate.style.backgroundColor = 'lightyellow';
    }
    else if (reFieldValidations(txtLICPlate.value, "AlphaNumericWithSpace") == false) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the valid LIC Plate !';
        if (!isError) {
            controlToBeFocused = txtLICPlate;
            isError = true;
        }
        txtLICPlate.style.backgroundColor = 'lightyellow';
    }
    else {
        txtLICPlate.style.backgroundColor = 'white';
    }

    if (!CheckIsSelected(ddlModel.value)) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select the sensor model !';
        if (!isError) {
            controlToBeFocused = ddlModel;
            isError = true;
        }
        ddlModel.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlModel.style.backgroundColor = 'white';
    }

    /* if (!CheckIsSelected(ddlTimezone.value)) {
    alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select the timezone !';
    if (!isError) {
    controlToBeFocused = ddlTimezone;
    isError = true;
    }
    ddlTimezone.style.backgroundColor = 'lightyellow';
    }
    else {
    ddlTimezone.style.backgroundColor = 'white';
    } */

    if (RemoveSpaces(txtYear).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the year of manufacturing !';
        if (!isError) {
            controlToBeFocused = txtYear;
            isError = true;
        }
        txtYear.style.backgroundColor = 'lightyellow';
    }
    else if (!(txtYear.value >= 1950 && txtYear.value <= dtCurrentDate.getFullYear())) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter valid year of manufacturing !';
        if (!isError) {
            controlToBeFocused = txtYear;
            isError = true;
        }
        txtYear.style.backgroundColor = 'lightyellow';
    }
    else {
        txtYear.style.backgroundColor = 'white';
    }

    if (!CheckSeveritySelection('chkSeverities')) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select any one of the severity level !';
        document.getElementById('chkSeverities').style.backgroundColor = 'lightyellow';
        if (!isError) {
            controlToBeFocused = document.getElementById('chkSeverities_0');
            isError = true;
        }
    }
    else {
        document.getElementById('chkSeverities').setAttribute('style', ''); //.style.backgroundColor = 'white';
    }

    if (!CheckIsSelected(ddlVehType.value)) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select the sensor type !';
        if (!isError) {
            controlToBeFocused = ddlVehType;
            isError = true;
        }
        ddlVehType.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlVehType.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtColor).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the color !';
        if (!isError) {
            controlToBeFocused = txtColor;
            isError = true;
        }
        txtColor.style.backgroundColor = 'lightyellow';
    }
    else if (reFieldValidations(txtColor.value, "CharacterWithSpace") == false) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter valid color !';
        if (!isError) {
            controlToBeFocused = txtColor;
            isError = true;
        }
        txtColor.style.backgroundColor = 'lightyellow';
    }
    else {
        txtColor.style.backgroundColor = 'white';
    }

    if (isError) {
        controlToBeFocused.focus();
        alert(alertMessage);
        return false;
    }
    else {
        return true;
    }
}

function CheckSeveritySelection(controlPrefix) {
    var i = 0;
    var element = document.getElementById(controlPrefix + "_" + i);
    while (element != null) {
        if (element.checked) {
            return true;
        }
        element = document.getElementById(controlPrefix + "_" + i++)
    }
    return false;
}

/**************** Vehicle Outputs *******************/

function CheckOutputName(isOutputNameValid, textFieldName, textActionOn, textActionOff) {
    var outputNameField = document.getElementById(textFieldName)
    var actionOnField = document.getElementById(textActionOn);
    var actionOffField = document.getElementById(textActionOff);

    var isError = false;
    var errorField;
    var alertMessage = '';
    var isActionOnError = false;
    var isActionOffError = false;
    var s;
    if (!isOutputNameValid) {
        isError = true;
        alertMessage = 'Output Name already exists.';
        outputNameField.style.backgroundColor = 'lightyellow';
        outputNameField.focus();
    }
    else if (outputNameField != null) {
        s = RemoveSpaces(outputNameField);
        if (s.length == 0) {
            isError = true;
            alertMessage = 'Please enter a valid Output Name.';
            outputNameField.style.backgroundColor = 'lightyellow';
            outputNameField.focus();
        }
        else {
            outputNameField.style.backgroundColor = 'white';
        }
    }

    if (actionOnField != null) {
        s = RemoveSpaces(actionOnField);
        if (s.length == 0) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter a valid Action On Status.';
            actionOnField.style.backgroundColor = 'lightyellow';
            if (!isError) {
                actionOnField.focus();
                isError = true;
                isActionOnError = true;
            }
        }
        else {
            actionOnField.style.backgroundColor = 'white';
        }
    }

    if (actionOffField != null) {
        s = RemoveSpaces(actionOffField);
        if (s.length == 0) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter a valid Action Off Status.';
            actionOffField.style.backgroundColor = 'lightyellow';
            if (!isError) {
                actionOffField.focus();
                isError = true;
                isActionOffError = true;
            }
        }
        else {
            actionOffField.style.backgroundColor = 'white';
        }
    }

    if (actionOnField != null && actionOffField != null) {
        if (RemoveSpaces(actionOnField).length > 0 && RemoveSpaces(actionOffField).toString().toLowerCase()
            == RemoveSpaces(actionOnField).toString().toLowerCase()) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Action On and Off Status cannot be the same.';
            if (!isError) {
                actionOnField.focus();
                isError = true;
                actionOnField.style.backgroundColor = 'lightyellow';
                actionOffField.style.backgroundColor = 'lightyellow';
            }
        }
        else {
            if (!isActionOnError) {
                actionOnField.style.backgroundColor = 'white';
            }
            if (!isActionOffError) {
                actionOffField.style.backgroundColor = 'white';
            }
        }
    }

    if (isError) {
        alert(alertMessage);
    }
    return !isError;
}

/*************************************************************/

/**************** Vehicle Message Severity *******************/

function CheckSensorName(isSensorNameValid, textFieldName, textActionOn, textActionOff) {

    var sensorNameField = document.getElementById(textFieldName)
    var actionOnField = document.getElementById(textActionOn);
    var actionOffField = document.getElementById(textActionOff);

    var isError = false;
    var errorField;
    var alertMessage = '';
    var isActionOnError = false;
    var isActionOffError = false;
    var s;
    if (!isSensorNameValid) {
        isError = true;
        alertMessage = 'Sensor name already exists !';
        sensorNameField.style.backgroundColor = 'lightyellow';
        sensorNameField.focus();
    }
    else if (sensorNameField != null) {
        s = RemoveSpaces(sensorNameField);
        if (s.length == 0) {
            isError = true;
            alertMessage = 'Please enter a valid sensor name!';
            sensorNameField.style.backgroundColor = 'lightyellow';
            sensorNameField.focus();
        }
    }
    else if (sensorNameField != null) {
        sensorNameField.style.backgroundColor = 'white';
    }

    if (actionOnField != null) {
        s = RemoveSpaces(actionOnField);
        if (s.length == 0) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter a valid action on status !';
            actionOnField.style.backgroundColor = 'lightyellow';
            if (!isError) {
                actionOnField.focus();
                isError = true;
                isActionOnError = true;
            }
        }
    }
    else if (actionOnField != null) {
        actionOnField.style.backgroundColor = 'white';
    }

    if (actionOffField != null) {
        s = RemoveSpaces(actionOffField);
        if (s.length == 0) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter a valid action off status!';
            actionOffField.style.backgroundColor = 'lightyellow';
            if (!isError) {
                actionOffField.focus();
                isError = true;
                isActionOffError = true;
            }
        }
    }
    else if (actionOffField != null) {
        actionOffField.style.backgroundColor = 'white';
    }

    if (actionOnField != null && actionOffField != null) {
        if (RemoveSpaces(actionOnField).length > 0 && RemoveSpaces(actionOffField).toString().toLowerCase()
            == RemoveSpaces(actionOnField).toString().toLowerCase()) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Action on and off status cannot be the same !';
            if (!isError) {
                actionOnField.focus();
                isError = true;
                actionOnField.style.backgroundColor = 'lightyellow';
                actionOffField.style.backgroundColor = 'lightyellow';
            }
        }
        else {
            if (!isActionOnError) {
                actionOnField.style.backgroundColor = 'white';
            }
            if (!isActionOffError) {
                actionOffField.style.backgroundColor = 'white';
            }
        }
    }

    if (isError) {
        alert(alertMessage);
    }
    return !isError;
}

/*************************************************************/

/************** User Manipulations ***************/

function OnGridSelectionChanged(Type) {
    if (Type == 1) {
        gvUsers.GetSelectedFieldValues('UserId', OnGridSelectionCompleteUser);
    }
    if (Type == 2) {
        gvUnAssignedUsers.GetSelectedFieldValues('UserId', OnGridSelectionCompleteUnAssUsr);
    }
    if (Type == 3) {
        gvAssignedUsers.GetSelectedFieldValues('UserId', OnGridSelectionCompleteAssUsr);
    }
}

function OnGridSelectionCompleteUser(values) {
    var counter = document.getElementById("hdnSelectedUserIds");
    counter.value = '';
    for (var i = 0; i < values.length; i++) {
        counter.value = counter.value + values[i] + ',';
    }
}

function OnGridSelectionCompleteUnAssUsr(values) {
    var counter = document.getElementById("hdnUsersToBeAssigned");
    counter.value = '';
    for (var i = 0; i < values.length; i++) {
        counter.value = counter.value + values[i] + ',';
    }
}

function OnGridSelectionCompleteAssUsr(values) {
    var counter = document.getElementById("hdnUsersToBeUnassinged");
    counter.value = '';
    for (var i = 0; i < values.length; i++) {
        counter.value = counter.value + values[i] + ',';
    }
}

function ValidateResetPwd(oldPassword, txtNewPwd, txtConfirmPwd, minPasswordChar) {
    var newPwd = document.getElementById(txtNewPwd);
    var confirmNewPwd = document.getElementById(txtConfirmPwd);
    s = newPwd.value.replace(/(^\s*)|(\s*$)/gi, "");
    s = s.replace(/[ ]{2,}/gi, " ");
    s = s.replace(/\n /, "\n");

    var isError = false;
    var alertMessage = '';

    if (s.length == 0) {
        alertMessage = 'Please enter the new password !';
        isError = true;
        newPwd.focus();
        newPwd.style.backgroundColor = 'lightyellow';
    }
    else if (s.length < minPasswordChar) {
        alertMessage = 'Password must have atleast ' + minPasswordChar + ' characters !';
        isError = true;
        newPwd.focus();
        newPwd.style.backgroundColor = 'lightyellow';
    }
    else {
        newPwd.style.backgroundColor = 'white';
    }

    if (oldPassword != '' && oldPassword == s) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Old password & new password should not be same !';
        if (!isError) {
            newPwd.focus();
            isError = true;
        }
        newPwd.style.backgroundColor = 'lightyellow';
    }
    else {
        newPwd.style.backgroundColor = 'white';
    }

    if (confirmNewPwd.value != s) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please confirm the password !';
        if (!isError) {
            confirmNewPwd.focus();
            isError = true;
        }
        confirmNewPwd.style.backgroundColor = 'lightyellow';
    }
    else {
        confirmNewPwd.style.backgroundColor = 'white';
    }

    if (isError) {
        alert(alertMessage);
        return false;
    }
    else {
        return true;
    }
}

function CheckUserGroup() {
    if ($get('<%=ddlUsrGroups.ClientID %>').value == 0) {
        alert("Select the User Group !");
        return false;
    }
    else {
        return true;
    }
}

function MassUpdateValidation(adminUserID, loggedinUserID) {
    var isError;
    var alertMessage = '';
    var hdnSelectedIDList = document.getElementById('hdnSelectedUserIds');
    var statusdropdown = document.getElementById('ddlStatusMU');
    var lockeddropdown = document.getElementById('ddlLockStatusMU');
    var usergroupdropdown = document.getElementById('ddlUserGroupMU');
    var arrHiddenField = hdnSelectedIDList.value.split(",");

    if (gvUsers.GetSelectedRowCount() == 0) {
        alertMessage = 'Select user(s) who has to be updated!';
        isError = true;
    }

    if (adminUserID != loggedinUserID && adminUserID != 0 && Array.contains(arrHiddenField, adminUserID.toString())) {
        alertMessage = 'Status and user group of the user,\'Administrator\' cannot be changed !';
        isError = true;
    }

    if (loggedinUserID != 0 && Array.contains(arrHiddenField, loggedinUserID.toString())) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Status and user group of yours cannot be changed !';

        if (!isError) {
            isError = true;
        }
    }

    if (statusdropdown.value == 2 && lockeddropdown.value == 2 && usergroupdropdown.value == '- Select -') {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + "Select any of the options that has to be updated!";
        isError = true;
    }

    if (isError) {
        alert(alertMessage);
        return false;
    }
    else {
        return true;
    }
}


function ValidateUserInformation(isNew, isUserNameExists, minPasswordChar) {
    var titleField = document.getElementById('ddlTitle');
    var firstName = document.getElementById('txtFirstName');
    var lastName = document.getElementById('txtLastName');
    var emailField = document.getElementById('txtEmail');
    var userNameField = document.getElementById('txtUsername');
    var displayNameField = document.getElementById('txtDispName');
    var userGroupField = document.getElementById('ddlUsrGroups');
    var pwdField = document.getElementById('txtPwd');
    var confirmpwdField = document.getElementById('txtConPwd');
    var phoneNo = document.getElementById('txtPhone');
    var mobileNo = document.getElementById('txtMobile');

    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (!CheckIsSelected(titleField.value)) {
        isError = true;
        controlToBeFocused = titleField;
        alertMessage = 'Please select the title !';
        titleField.style.backgroundColor = 'lightyellow';
    }
    else {
        titleField.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(firstName).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the first name !';
        if (!isError) {
            controlToBeFocused = firstName;
        }
        firstName.style.backgroundColor = 'lightyellow';
        isError = true;
    }
    else if (reFieldValidations(firstName.value, "CharacterWithSpace") == false) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter valid first name !';
        if (!isError) {
            controlToBeFocused = firstName;
        }
        firstName.style.backgroundColor = 'lightyellow';
        isError = true;
    }
    else {
        firstName.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(lastName).length > 0 && reFieldValidations(lastName.value, "CharacterWithSpace") == false) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter valid last name !';
        if (!isError) {
            controlToBeFocused = lastName;
        }
        lastName.style.backgroundColor = 'lightyellow';
        isError = true;
    }
    else {
        lastName.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(emailField).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the email !';
        if (!isError) {
            controlToBeFocused = emailField;
        }
        isError = true;
        emailField.style.backgroundColor = 'lightyellow';
    }
    else if (!validateEmail(emailField.value)) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter a valid email address !';
        if (!isError) {
            controlToBeFocused = emailField;
        }
        isError = true;
        emailField.style.backgroundColor = 'lightyellow';
    }
    else {
        emailField.style.backgroundColor = 'white';
    }

    if (phoneNo.value.length > 0) {
        if (phoneFormat(phoneNo.value) == false) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter valid phone number !';
            phoneNo.style.backgroundColor = 'lightyellow';

            if (!isError) {
                controlToBeFocused = phoneNo;
                isError = true;
            }
        }
        else {
            phoneNo.style.backgroundColor = 'white';
        }
    }
    else {
        phoneNo.style.backgroundColor = 'white';
    }

    if (mobileNo.value.length > 0) {
        if (mobileFormat(mobileNo.value) == false) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter valid mobile number !';
            mobileNo.style.backgroundColor = 'lightyellow';

            if (!isError) {
                controlToBeFocused = mobileNo;
                isError = true;
            }
        }
        else {
            mobileNo.style.backgroundColor = 'white';
        }
    }
    else {
        mobileNo.style.backgroundColor = 'white';
    }

    if (isUserNameExists) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'User name already exists !';
        if (!isError) {
            controlToBeFocused = userNameField;
        }
        isError = true;
        userNameField.style.backgroundColor = 'lightyellow';
    }
    else if (RemoveSpaces(userNameField).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the User name !';
        if (!isError) {
            controlToBeFocused = userNameField;
        }
        isError = true;
        userNameField.style.backgroundColor = 'lightyellow';
    }
    else if (reFieldValidations(userNameField.value, "AlphaNumericWithSpaceHypDotUnderScore") == false) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter valid User name !';
        if (!isError) {
            controlToBeFocused = userNameField;
        }
        isError = true;
        userNameField.style.backgroundColor = 'lightyellow';
    }
    else {
        userNameField.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(displayNameField).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the display name !';
        if (!isError) {
            controlToBeFocused = displayNameField;
        }
        isError = true;
        displayNameField.style.backgroundColor = 'lightyellow';
    }
    else if (reFieldValidations(displayNameField.value, "AlphaNumericWithSpaceHypDotUnderScore") == false) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter valid display name !';
        if (!isError) {
            controlToBeFocused = displayNameField;
        }
        isError = true;
        displayNameField.style.backgroundColor = 'lightyellow';
    }
    else {
        displayNameField.style.backgroundColor = 'white';
    }

    var conPass = new String(confirmpwdField.value);
    var pass = new String(pwdField.value);

    if (conPass.localeCompare(pass) != 0) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please confirm your password !';
        if (!isError) {
            controlToBeFocused = confirmpwdField
            isError = true;
        }
        confirmpwdField.style.backgroundColor = 'lightyellow';
    }
    else {
        confirmpwdField.style.backgroundColor = 'white';
    }

    if (isNew) {

        if (RemoveSpaces(pwdField).length == 0) {
            alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please enter the password with atleast ' + minPasswordChar + ' characters!';
            if (!isError) {
                controlToBeFocused = pwdField;
            }
            pwdField.style.backgroundColor = 'lightyellow';
        }
        else if (RemoveSpaces(pwdField).length < minPasswordChar) {
            alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Password should have atleast ' + minPasswordChar + ' characters !';
            if (!isError) {
                controlToBeFocused = pwdField;
            }
            pwdField.style.backgroundColor = 'lightyellow';
        }
        else {
            pwdField.style.backgroundColor = 'white';
        }


        if (confirmpwdField.value != RemoveSpaces(pwdField)) {
            alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please confirm the password !';
            if (!isError) {
                controlToBeFocused = confirmpwdField
                isError = true;
            }
            confirmpwdField.style.backgroundColor = 'lightyellow';
        }

        else {
            confirmpwdField.style.backgroundColor = 'white';
        }

    }



    if (!CheckIsSelected(userGroupField.value)) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please select a user group !';
        if (!isError) {
            controlToBeFocused = userGroupField
            isError = true;
        }
        userGroupField.style.backgroundColor = 'lightyellow';
    }
    else {
        userGroupField.style.backgroundColor = 'white';
    }

    if (isError) {
        alert(alertMessage);
        controlToBeFocused.focus();
        return false;
    }
    else {
        return true;
    }
}

function validateEmail(elementValue) {
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
    return emailPattern.test(elementValue);
}

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;
}

function CheckIsSelected(dropdownvalue) {
    return dropdownvalue != '- Select -' ? true : false;
}


/**************** Reports Scheduling Settings *******************/
// Validations for Reports Scheduling Settings included by Kumuthini. L on 10-Mar-10

function ValidateScheduleReports() {

    var effectiveFromField = document.getElementById("txtEffectiveFrom")
    var effectiveToField = document.getElementById("txtEffectiveTo");
    var frequency = document.getElementById("ddlFrequency");
    var dayOfMonth = document.getElementById("txtFrequencyMonthlyDay");
    var schedulingEmailList = document.getElementById("hdnSchedulingEmailList");

    var isError = false;
    var errorField;
    var alertMessage = '';
    var s;

    if (effectiveFromField != null) {
        s = RemoveSpaces(effectiveFromField);
        if (s.length == 0) {
            isError = true;
            alertMessage = 'Please select the effective from date !';
            effectiveFromField.style.backgroundColor = 'lightyellow';
            effectiveFromField.focus();
        }
        else {
            effectiveFromField.style.backgroundColor = 'white';
        }
    }
    else if (effectiveFromField != null) {
        effectiveFromField.style.backgroundColor = 'white';
    }

    if (document.getElementById("chkNoEndDate") != null && document.getElementById("chkNoEndDate").checked == false) {
        if (effectiveToField != null) {
            s = RemoveSpaces(effectiveToField);
            if (s.length == 0) {
                alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select the effective till date !';
                effectiveToField.style.backgroundColor = 'lightyellow';
                if (!isError) {
                    effectiveToField.focus();
                    isError = true;
                }
            }
            else {
                effectiveToField.style.backgroundColor = 'white';
            }
        }
        else if (effectiveToField != null) {
            effectiveToField.style.backgroundColor = 'white';
        }
    }
    else {
        effectiveToField.style.backgroundColor = 'white';
    }
    var monthly_Day = 0;

    if (frequency != null) {
        if (frequency.value == "2") {
            if (dayOfMonth != null) {
                s = RemoveSpaces(dayOfMonth);
                if (s.length == 0) {
                    alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the day of month !';
                    dayOfMonth.style.backgroundColor = 'lightyellow';
                    if (!isError) {
                        dayOfMonth.focus();
                        isError = true;
                    }
                }
                else {
                    if (dayOfMonth.value == "00" || dayOfMonth.value <= 0 || dayOfMonth.value > 31) {
                        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Day of month should be between 1 to 31 !';
                        dayOfMonth.style.backgroundColor = 'lightyellow';
                        if (!isError) {
                            dayOfMonth.focus();
                            isError = true;
                        }
                    }
                    else {
                        monthly_Day = dayOfMonth.value;
                        dayOfMonth.style.backgroundColor = 'white';
                    }
                }
            }
            else if (dayOfMonth != null) {
                dayOfMonth.style.backgroundColor = 'white';
            }
        }
    }

    if (schedulingEmailList != null) {
        if (schedulingEmailList.value == "") {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select the user(s) for emailing !';
            if (!isError) {
                isError = true;
            }
        }
    }

    if (!isError) {

        if (document.getElementById("chkNoEndDate") != null && document.getElementById("chkNoEndDate").checked == false) {
            var validity = CheckEffectiveFromTo();
            if (validity == 1) {
                isError = true;
                alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select a valid date range !';
            }
            else if (validity == 2) {
                isError = true;
                alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select a valid time range !';
            }
            else if (validity == 3) {
                isError = true;
                alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'The date range is not valid for the ' +
                (frequency.value == 1 ? 'weekly' : 'monthly') + ' scheduling !';
            }
            //            else if (validity == 3 && frequency.value == 2) {
            //                isError = true;
            //                alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'The date range is not valid for the monthly scheduling !';
            //            }
        }

        if (!CheckShowOption()) {
            return false;
        }
    }

    if (!isError) {
        if (monthly_Day > 28) {
            return confirm("Some months have fewer than " + monthly_Day + " days. For these months, the occurrence will fall on the last day of the month !");
        }
    }
    if (!isError && frequency.value == 2 && !document.getElementById("chkNoEndDate").checked) {
        //Commented by Jeyanthi on 11-Aug-2010
        //var toDate = new Date($find("ceEndDate")._selectedDate);
        //End
        var toDate = $('input[id$=txtEffectiveTo]').datepicker('getDate');
        if (toDate.getDate() != eval(dayOfMonth.value)) {
            return confirm('Report generation day is not matching with the end date so the final report will be generated on ' + effectiveToField.value +
            '\nAre you sure you want to continue !');
        }
    }
    if (isError) {
        alert(alertMessage);
    }

    return !isError;
}

/*************************************************************/


/************************************************************/

// Included by Kumuthini on 01-Oct-09
// Regular Expression Validations

// Checks for Characters and Numbers with white spaces inbetween
function reFieldValidations(ValidationString, ValidationType) {
    ValidationString = RemoveSpaces(ValidationString);
    var charNumRE;

    switch (ValidationType) {
        case "AlphaNumericWithSpace":
            charNumRE = new RegExp(/^(?! )([A-Za-z 0-9\.])*$/);
            break;
        case "AlphaNumericWithoutSpace":
            charNumRE = new RegExp(/^[A-Za-z0-9]*$/);
            break;
        case "NumericWithoutStartingZero":
            charNumRE = new RegExp(/^[1-9][0-9]*$/);
            break;
        case "CharacterWithSpace":
            charNumRE = new RegExp(/^(?! )([A-Za-z \.])*$/);
            break;
        case "AlphaNumericWithSpaceHypDotUnderScore":
            charNumRE = new RegExp(/^[A-Za-z0-9][A-Za-z0-9 ._-]*$/);
            break;
        case "Description":
            charNumRE = new RegExp(/^<*$/);
            break;
    }

    if (ValidationType == "Description") {
        var charIdx = ValidationString.indexOf("<");

        if (charIdx > -1) {
            return false;
        }
    }
    else {
        if (!charNumRE.test(ValidationString)) {
            return false;
        }
    }

    return true;
}

/************************************************************/

function FleetUserAssignment(Type, hiddenFieldName, adminUserID, loggedinUserID) {
    var hiddenField = document.getElementById(hiddenFieldName);
    var arrHiddenField = hiddenField.value.split(",");

    var alertMessage = '';
    var isError = false;

    alertMessage = (Type == "Assign") ? 'Select user(s) to be assigned !' : 'Select user(s) to be unassigned !';

    if (arrHiddenField.length == 0 || arrHiddenField[0] == "") {
        alert(alertMessage);
        return false;
    }

    alertMessage = '';

    if (Type == "Assign") {
        if (adminUserID != loggedinUserID && adminUserID != 0 && Array.contains(arrHiddenField, adminUserID.toString())) {
            alertMessage = 'Assigning of the user,\'Administrator\' is not allowed !';
            isError = true;
        }

        if (loggedinUserID != 0 && Array.contains(arrHiddenField, loggedinUserID.toString())) {
            alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Assigning of the currently logged in user is not allowed !';

            if (!isError) {
                isError = true;
            }
        }

        if (isError) {
            alert(alertMessage);
            return false;
        }
        else {
            return true;
        }
    }
    else {

        if (adminUserID != loggedinUserID && document.getElementById('ddlFleetUser').selectedIndex == 0 && adminUserID != 0 && Array.contains(arrHiddenField, adminUserID.toString())) {
            alertMessage = 'Unassigning of the user,\'Administrator\' is not allowed !';
            isError = true;
        }

        if (((adminUserID == loggedinUserID && document.getElementById('ddlFleetUser').selectedIndex == 0) || adminUserID != loggedinUserID) && loggedinUserID != 0 && Array.contains(arrHiddenField, loggedinUserID.toString())) {
            alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Unassigning of the currently logged in user is not allowed !';

            if (!isError) {
                isError = true;
            }
        }

        if (isError) {
            alert(alertMessage);
            return false;
        }
        else {
            return true;
        }
    }
}


/************************************************************/

function UserGroupAssignmentValidation(Type, hiddenFieldName, adminUserID, loggedinUserID) {
    var hiddenField = document.getElementById(hiddenFieldName);
    var arrHiddenField = hiddenField.value.split(",");
    //var gridControlName = 
    var alertMessage = '';
    var isError = false;

    alertMessage = (Type == "Assign") ? 'Select user(s) to be assigned !' : 'Select user(s) to be unassigned !';

    if (arrHiddenField.length == 0 || arrHiddenField[0] == "") {
        alert(alertMessage);
        return false;
    }

    alertMessage = '';

    if (Type == "Assign") {
        if (adminUserID != loggedinUserID && adminUserID != 0 && Array.contains(arrHiddenField, adminUserID.toString())) {
            alertMessage = 'Assigning of the user,\'Administrator\' is not allowed !';
            isError = true;
        }

        if (loggedinUserID != 0 && Array.contains(arrHiddenField, loggedinUserID.toString())) {
            alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Assigning of the currently logged in user is not allowed !';

            if (!isError) {
                isError = true;
            }
        }

        if (isError) {
            alert(alertMessage);
            return false;
        }
        else {
            var hdnAssignedUsr = document.getElementById('hdnAssignedGroupUser');
            var arrUsrToBeAssigned = hiddenField.value.split(",");
            var arrAssignedUsr = hdnAssignedUsr.value.split(",");

            var iLoop = 0;
            var IsAssigned = false;

            while (iLoop < arrUsrToBeAssigned.length) {
                if (Array.contains(arrAssignedUsr, arrUsrToBeAssigned[iLoop])) {
                    IsAssigned = true;
                    break;
                }
                iLoop++;
            }

            if (IsAssigned == true) {
                var IsConfirm = confirm("Some of the User(s) were already assigned User Group. Do u want to overwrite?");

                if (IsConfirm == true) {
                    return true;
                }
                else {
                    return false;
                }
            }
            else {
                return true;
            }
        }
    }
    else {

        if (adminUserID != loggedinUserID && adminUserID != 0 && Array.contains(arrHiddenField, adminUserID.toString())) {
            alertMessage = 'Unassigning of the user,\'Administrator\' is not allowed !';
            isError = true;
        }

        if (loggedinUserID != 0 && Array.contains(arrHiddenField, loggedinUserID.toString())) {
            alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Unassigning of the currently logged in user is not allowed !';

            if (!isError) {
                isError = true;
            }
        }

        if (isError) {
            alert(alertMessage);
            return false;
        }
        else {
            var IsConfirmed = confirm("Unassigning the user(s) from the group will restrict their login.\nDo you want to continue?");
            if (IsConfirmed == true) {
                return true;
            }
            else {
                return false;
            }
        }
    }
}

function checkPhone(str) {
    var phone2 = /^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/;
    if (str.match(phone2)) {
        return true;
    } else {
        return false;
    }
}

function EnableOrDisableSeverities(prefix, clickedCheckBox) {
    var i = 0;
    var iLoop = 0;
    var clickedItemId = clickedCheckBox.id;
    var arrClickedItemId = clickedItemId.split('_');

    var element = document.getElementById(prefix + i);

    if (arrClickedItemId[1] == 3 && clickedCheckBox.checked == true) {
        while (element != null && i < 3) {
            if (i <= 2) {
                element.checked = false;
            }

            i = i + 1;
            element = document.getElementById(prefix + i);
        }
    }
    else {
        document.getElementById(prefix + "3").checked = false;
    }
}


/****************** Geozone Validations ********************/
function ValidateGeozoneEntries() {
    var geozoneNameField = document.getElementById('txtGeozoneName');
    var directionField = document.getElementById('ddlDirection')
    var severityField = document.getElementById('ddlSeverity');
    var categoryField = document.getElementById('ddlCategory');
    s = geozoneNameField.value.replace(/(^\s*)|(\s*$)/gi, "");
    s = s.replace(/[ ]{2,}/gi, " ");
    s = s.replace(/\n /, "\n");

    var isError = false;
    var alertMessage = '';

    if (s.length == 0 || s == 'Geozone Name') {
        alertMessage = 'Please enter the geozone name !';
        isError = true;
        geozoneNameField.focus();
        geozoneNameField.style.backgroundColor = 'lightyellow';
    }
    else {
        geozoneNameField.style.backgroundColor = 'white';
    }

    if (severityField.value == '- Select Severity -') {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please select the severity level !';
        if (!isError) {
            severityField.focus();
            isError = true;
        }
        severityField.style.backgroundColor = 'lightyellow';
    }
    else {
        severityField.style.backgroundColor = 'white';
    }

    if (directionField.value == '- Select Direction -') {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please select the direction !';
        if (!isError) {
            directionField.focus();
            isError = true;
        }
        directionField.style.backgroundColor = 'lightyellow';
    }
    else {
        directionField.style.backgroundColor = 'white';
    }



    if (categoryField.value == '- Select Category -') {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please select the category !';
        if (!isError) {
            categoryField.focus();
            isError = true;
        }
        categoryField.style.backgroundColor = 'lightyellow';
    }
    else {
        categoryField.style.backgroundColor = 'white';
    }

    if (isError) {
        //alert(alertMessage);
        return alertMessage;
    }
    else {
        return 'NoError';
    }
}
/***********************************************************/
//// Function to check whether the Severity has been selected 
//function CheckSeverity() {
//	var i = 0;
//	var Loop = 0;
//	var state = false;

//	var element = document.getElementById("chkEmailSeverities_" + i);

//	while (element != null) {
//		Loop = (element.checked == true) ? Loop + 1 : Loop;
//		i = i + 1;
//		element = document.getElementById("chkEmailSeverities_" + i)
//	}

//	return (Loop == 0) ? false : true;
//}

/********************************Device Validations******************************************/
// Included by Kumuthini.L on 13-Nov-09
// Function to check for Mandatory Fields
function DeviceValidation(isBoxIdValid) {
    var txtBoxId = document.getElementById("txtBoxId");
    var FirmwareVersion = document.getElementById('ddlFirmwareVersion');
    var BoxProtocolType = document.getElementById('ddlBoxProtocolType');
    var CommMode = document.getElementById('ddlCommMode');

    var isError = false;
    var alertMessage = '';
    var controlToBeFocused;

    if (!CheckIsSelected(FirmwareVersion.value)) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please select the Firmware Version !';
        if (!isError) {
            controlToBeFocused = FirmwareVersion;
            isError = true;
        }
        FirmwareVersion.style.backgroundColor = 'lightyellow';
    }
    else {
        FirmwareVersion.style.backgroundColor = 'white';
    }

    if (!CheckIsSelected(BoxProtocolType.value)) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please select the Protocol Type !';
        if (!isError) {
            controlToBeFocused = BoxProtocolType;
            isError = true;
        }
        BoxProtocolType.style.backgroundColor = 'lightyellow';
    }
    else {
        BoxProtocolType.style.backgroundColor = 'white';
    }

    if (!CheckIsSelected(CommMode.value)) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please select the Communication Mode !';
        if (!isError) {
            controlToBeFocused = CommMode;
            isError = true;
        }
        CommMode.style.backgroundColor = 'lightyellow';
    }
    else {
        CommMode.style.backgroundColor = 'white';
    }

    if (isError) {
        alert(alertMessage);
        controlToBeFocused.focus();
        return false;
    }
    return true;
}
/**********************************************************************************************/

/***************************Licensing - Package Creation************************/
// Included by Kumuthini.L on 27-Nov-09
// Function to check for Mandatory Fields
function ValidatePackageCreation(isPackageNameValid) {
    var txtPackageName = document.getElementById('txtPackageName');
    var txtPackageDesc = document.getElementById('txtPackageDesc');
    var hdnSelectedModules = document.getElementById('hdnSelectedModuleList');
    var hdnSelectedOperations = document.getElementById('hdnSelectedOperationList');

    var isError = false;
    var alertMessage = '';
    var controlToBeFocused;

    if (!isPackageNameValid) {
        isError = true;
        alertMessage = 'Package name already exists!';
        txtPackageName.style.backgroundColor = 'lightyellow';
        controlToBeFocused = txtPackageName;
    }
    else if (RemoveSpaces(txtPackageName).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the Package Name !';
        txtPackageName.style.backgroundColor = 'lightyellow';

        if (!isError) {
            controlToBeFocused = txtPackageName;
            isError = true;
        }
    }
    else {
        txtPackageName.style.backgroundColor = 'white';
    }

    if (txtPackageDesc.value != '' && reFieldValidations(txtPackageDesc.value, "Description") == false) {
        if (!isError) {
            controlToBeFocused = txtPackageDesc;
            isError = true;
        }
        alertMessage = 'Please enter valid package description !';
        txtPackageDesc.style.backgroundColor = 'lightyellow';
    }
    else {
        txtPackageDesc.style.backgroundColor = 'white';
    }

    if (isError) {
        controlToBeFocused.focus();
    }

    if (RemoveSpaces(hdnSelectedModules).length == 0 && RemoveSpaces(hdnSelectedOperations).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select any of the Modules and Operations !';
        isError = true;
    }

    if (isError) {
        alert(alertMessage);
        return false;
    }
    return true;
}

////function GetConfirmation(Mode, assignedStatus) {

////}
/**********************************************************************************************/

/***************************Licensing - Organization Package Assignment************************/
// Included by Kumuthini.L on 26-Nov-09
// Function to check for Mandatory Fields
function ValidatePackageAssignment() {
    var Organization = document.getElementById("ddlOrganization");
    var Package = document.getElementById('ddlPackage');
    var txtPurchasedOn = document.getElementById('txtPurchasedOn');
    var txtExpiresOn = document.getElementById('txtExpiresOn');

    var isError = false;
    var alertMessage = '';
    var controlToBeFocused;

    if (Organization != null) {
        if (!CheckIsSelected(Organization.value)) {
            alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please select the Organization !';
            if (!isError) {
                controlToBeFocused = Organization;
                isError = true;
            }
            Organization.style.backgroundColor = 'lightyellow';
        }
        else {
            Organization.style.backgroundColor = 'white';
        }
    }

    if (!CheckIsSelected(Package.value)) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please select the Package !';
        if (!isError) {
            controlToBeFocused = Package;
            isError = true;
        }
        Package.style.backgroundColor = 'lightyellow';
    }
    else {
        Package.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtPurchasedOn).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the Purchased On !';
        txtPurchasedOn.style.backgroundColor = 'lightyellow';

        if (!isError) {
            controlToBeFocused = txtPurchasedOn;
            isError = true;
        }
    }
    else {
        txtPurchasedOn.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtExpiresOn).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the expires On date !';
        txtExpiresOn.style.backgroundColor = 'lightyellow';

        if (!isError) {
            controlToBeFocused = txtExpiresOn;
            isError = true;
        }
    }
    else {
        txtExpiresOn.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtExpiresOn).length > 0) {

        var arrPurchasedOn = RemoveSpaces(txtPurchasedOn.value).split('/');
        var arrExpiresOn = RemoveSpaces(txtExpiresOn.value).split('/');

        var purchasedOnYear = 0, expiresOnYear = 0;
        var purchasedOnMonth = 0, expiresOnMonth = 0;
        var purchasedOnDate = 0, expiresOnDate = 0;
        var IsValid = false;

        purchasedOnYear = arrPurchasedOn[2];
        expiresOnYear = arrExpiresOn[2];
        purchasedOnMonth = arrPurchasedOn[1];
        expiresOnMonth = arrExpiresOn[1];
        purchasedOnDate = arrPurchasedOn[0];
        expiresOnDate = arrExpiresOn[0];

        if (expiresOnYear > purchasedOnYear) {
            IsValid = true;
        }
        else if (expiresOnYear == purchasedOnYear) {
            if (expiresOnMonth > purchasedOnMonth) {
                IsValid = true;
            }
            else if (expiresOnMonth == purchasedOnMonth) {
                if (expiresOnDate > purchasedOnDate) {
                    IsValid = true;
                }
            }
        }

        if (IsValid == false) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the valid expires On date!';
            txtExpiresOn.style.backgroundColor = 'lightyellow';

            if (!isError) {
                controlToBeFocused = txtExpiresOn;
                isError = true;
            }
        }
    }
    else {
        txtExpiresOn.style.backgroundColor = 'white';
    }

    if (isError) {
        alert(alertMessage);
        controlToBeFocused.focus();
        return false;
    }
    return true;
}
/**********************************************************************************************/

/********************************Organization Validations******************************************/
function OrganizationValidation() {
    var txtOrgName = document.getElementById("txtOrgName");
    var txtOrgDisplayName = document.getElementById("txtOrgDisplayName");
    var txtOrgCode = document.getElementById("txtOrgCode");
    var txtDescription = document.getElementById("txtDescription");
    var txtAddress = document.getElementById("txtAddress");
    var txtOrgEmail = document.getElementById("txtOrgEmail");
    var ddlCountry = document.getElementById("ddlCountry");
    var txtContactPersonName = document.getElementById("txtContactPersonName");
    var txtDesignation = document.getElementById("txtDesignation");
    var txtContactEmail = document.getElementById("txtContactEmail");
    var phoneNo = document.getElementById('txtOrgPhoneNo');
    var contactPhoneNo = document.getElementById('txtContactPhoneNo');
    var mobileNo = document.getElementById('txtOrgMobileNo');
    var webAddress = document.getElementById('txtOrgWebSiteURL');
    var chkEnableLocking = document.getElementById('chkEnableLocking');
    var totalNoOfEmails = document.getElementById('txtTotalNoOfEmails');
    var totalNoOfSMS = document.getElementById('txtTotalNoOfSMS');
    var totalNoOfFleet = document.getElementById('txtNoOfFleet');
    var totalNoOfVehicles = document.getElementById('txtNoOfVehicles');
    var totalNoOfUsers = document.getElementById('txtNoOfUsers');
    var chkLockIP = document.getElementById('chkLockIp');
    var chkLockUser = document.getElementById('chkLockUser');
    var chkBelongsTo = document.getElementById('chkBelongsTo');
    var ddlPartnerName = document.getElementById("ddlPartnerName");
    
    var isError = false;
    var alertMessage = '';
    var controlToBeFocused;

    if (RemoveSpaces(txtOrgName).length == 0) {
        isError = true;
        alertMessage = 'Please enter the organization name !';
        txtOrgName.style.backgroundColor = 'lightyellow';
        controlToBeFocused = txtOrgName;
    }
    else if (reFieldValidations(txtOrgName.value, "AlphaNumericWithSpaceHypDotUnderScore") == false) {
        if (!isError) {
            controlToBeFocused = txtOrgName;
            isError = true;
        }
        alertMessage = 'Please enter valid organization name !';
        txtOrgName.style.backgroundColor = 'lightyellow';
    }
    else {
        txtOrgName.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtOrgDisplayName).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the display name for the organization !';
        txtOrgDisplayName.style.backgroundColor = 'lightyellow';

        if (!isError) {
            controlToBeFocused = txtOrgDisplayName;
            isError = true;
        }
    }
    else if (reFieldValidations(txtOrgDisplayName.value, "AlphaNumericWithSpaceHypDotUnderScore") == false) {
        if (!isError) {
            controlToBeFocused = txtOrgDisplayName;
            isError = true;
        }
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the valid display name for the organization !';
        txtOrgDisplayName.style.backgroundColor = 'lightyellow';
    }
    else {
        txtOrgDisplayName.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtOrgCode).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the organization code !';
        txtOrgCode.style.backgroundColor = 'lightyellow';

        if (!isError) {
            controlToBeFocused = txtOrgCode;
            isError = true;
        }
    }
    else if (reFieldValidations(txtOrgCode.value, "AlphaNumericWithSpace") == false) {
        if (!isError) {
            controlToBeFocused = txtOrgCode;
            isError = true;
        }
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the valid display name for the organization !';
        txtOrgCode.style.backgroundColor = 'lightyellow';
    }
    else {
        txtOrgCode.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtDescription).length > 250) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the description only of 250 characters !';
        txtDescription.style.backgroundColor = 'lightyellow';

        if (!isError) {
            controlToBeFocused = txtDescription;
            isError = true;
        }
    }
    else {
        txtDescription.style.backgroundColor = 'white';
    }


    if (RemoveSpaces(txtAddress).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the address !';
        txtAddress.style.backgroundColor = 'lightyellow';

        if (!isError) {
            controlToBeFocused = txtAddress;
            isError = true;
        }
    }

    else {
        txtAddress.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtOrgEmail).length > 0) {
        if (!validateEmail(txtOrgEmail.value)) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter a valid email ID !';
            txtOrgEmail.style.backgroundColor = 'lightyellow';

            if (!isError) {
                controlToBeFocused = txtOrgEmail;
                isError = true;
            }
        }
        else {
            txtOrgEmail.style.backgroundColor = 'white';
        }
    }

    if (phoneNo.value.length > 0) {
        if (phoneFormat(phoneNo.value) == false) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter valid phone number !';
            phoneNo.style.backgroundColor = 'lightyellow';

            if (!isError) {
                controlToBeFocused = phoneNo;
                isError = true;
            }
        }
        else {
            phoneNo.style.backgroundColor = 'white';
        }
    }
    else {
        phoneNo.style.backgroundColor = 'white';
    }

    if (mobileNo.value.length > 0) {
        if (mobileFormat(mobileNo.value) == false) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter valid mobile number !';
            mobileNo.style.backgroundColor = 'lightyellow';

            if (!isError) {
                controlToBeFocused = mobileNo;
                isError = true;
            }
        }
        else {
            mobileNo.style.backgroundColor = 'white';
        }
    }
    else {
        mobileNo.style.backgroundColor = 'white';
    }

    if (!CheckIsSelected(ddlCountry.value)) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select the country !';

        if (!isError) {
            controlToBeFocused = ddlCountry;
            isError = true;
        }
        ddlCountry.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlCountry.style.backgroundColor = 'white';
    }

    if (webAddress.value.length > 0) {
        if (websiteFormat(webAddress.value) == false) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the valid website address !';

            if (!isError) {
                controlToBeFocused = webAddress;
                isError = true;
            }
            webAddress.style.backgroundColor = 'lightyellow';
        }
        else {
            webAddress.style.backgroundColor = 'white';
        }

    }
    else {
        webAddress.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtContactPersonName).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the contact person name !';
        txtContactPersonName.style.backgroundColor = 'lightyellow';

        if (!isError) {
            controlToBeFocused = txtContactPersonName;
            isError = true;
        }
    }
    else if (reFieldValidations(txtContactPersonName.value, "AlphaNumericWithSpace") == false) {
        if (!isError) {
            controlToBeFocused = txtContactPersonName;
            isError = true;
        }
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the valid contact person name !';
        txtContactPersonName.style.backgroundColor = 'lightyellow';
    }
    else {
        txtContactPersonName.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtDesignation).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the designation of the contact person !';
        txtDesignation.style.backgroundColor = 'lightyellow';

        if (!isError) {
            controlToBeFocused = txtDesignation;
            isError = true;
        }
    }
    else if (reFieldValidations(txtDesignation.value, "AlphaNumericWithSpace") == false) {
        if (!isError) {
            controlToBeFocused = txtDesignation;
            isError = true;
        }
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the valid designation of the contact person !';
        txtDesignation.style.backgroundColor = 'lightyellow';
    }
    else {
        txtDesignation.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(txtContactEmail).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the email ID for the contact person !';
        txtContactEmail.style.backgroundColor = 'lightyellow';

        if (!isError) {
            controlToBeFocused = txtContactEmail;
            isError = true;
        }
    }
    else if (!validateEmail(txtContactEmail.value)) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter a valid email ID for the contact person !';
        txtContactEmail.style.backgroundColor = 'lightyellow';

        if (!isError) {
            controlToBeFocused = txtContactEmail;
            isError = true;
        }
    }
    else {
        txtContactEmail.style.backgroundColor = 'white';
    }

    if (contactPhoneNo.value.length > 0) {
        if (phoneFormat(contactPhoneNo.value) == false) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter valid contact phone number !';
            contactPhoneNo.style.backgroundColor = 'lightyellow';

            if (!isError) {
                controlToBeFocused = contactPhoneNo;
                isError = true;
            }
        }
        else {
            contactPhoneNo.style.backgroundColor = 'white';
        }
    }
    else {
        contactPhoneNo.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(totalNoOfEmails).length > 0) {
        if (totalNoOfEmails.value < 1 || totalNoOfEmails.value > 5) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the no of Email tries between 1 to 5!';
            totalNoOfEmails.style.backgroundColor = 'lightyellow';

            if (!isError) {
                controlToBeFocused = totalNoOfEmails;
                isError = true;
            }
        }
    }
    else {
        totalNoOfEmails.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(totalNoOfSMS).length > 0) {
        if (totalNoOfSMS.value < 1 || totalNoOfSMS.value > 3) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the no of SMS tries between 1 to 3 !';
            totalNoOfSMS.style.backgroundColor = 'lightyellow';

            if (!isError) {
                controlToBeFocused = totalNoOfSMS;
                isError = true;
            }
        }
    }
    else {
        totalNoOfSMS.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(totalNoOfFleet).length > 0) {
        if (totalNoOfFleet.value < 1 || totalNoOfFleet.value > 100) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the no of sensor groups between 1-100 !';
            totalNoOfFleet.style.backgroundColor = 'lightyellow';

            if (!isError) {
                controlToBeFocused = totalNoOfFleet;
                isError = true;
            }
        }
    }
    else {
        totalNoOfFleet.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(totalNoOfVehicles).length > 0) {
        if (totalNoOfVehicles.value < 1) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the no of sensors between > 1 !';
            totalNoOfVehicles.style.backgroundColor = 'lightyellow';

            if (!isError) {
                controlToBeFocused = totalNoOfVehicles;
                isError = true;
            }
        }
    }
    else {
        totalNoOfVehicles.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(totalNoOfUsers).length > 0) {
        if (totalNoOfUsers.value < 1) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the no of users between > 1 !';
            totalNoOfUsers.style.backgroundColor = 'lightyellow';

            if (!isError) {
                controlToBeFocused = totalNoOfUsers;
                isError = true;
            }
        }
    }
    else {
        totalNoOfUsers.style.backgroundColor = 'white';
    }

    if (chkEnableLocking.checked) {
        if ((!chkLockIP.checked) && (!chkLockUser.checked)) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select any one of the lock option !';
            chkEnableLocking.style.backgroundColor = 'lightyellow';

            if (!isError) {
                controlToBeFocused = chkEnableLocking;
                isError = true;
            }
        }
    }
    else {
        chkEnableLocking.style.backgroundColor = 'white';
    }

    if (chkBelongsTo.checked) {
        if (!CheckIsSelected(ddlPartnerName.value)) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select the Partner Name.';

            if (!isError) {
                controlToBeFocused = ddlPartnerName;
                isError = true;
            }
            ddlPartnerName.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlPartnerName.style.backgroundColor = 'white';
        }
    }

    if (isError) {
        alert(alertMessage);
        controlToBeFocused.focus();
        return false;
    }
    return true;
}


function checkBDE(value) {
    if (value.checked) {
        document.getElementById('lbPartnerName').style.display = "block";
    }
    else {
        document.getElementById('lbPartnerName').style.display = "none";
    }
}
//********************************************************************************************************/

function ValidateEmployeeInformation() {
    var titleField = document.getElementById('ddlTitle');
    var firstName = document.getElementById('txtFirstName');
    var emailField = document.getElementById('txtEmail');
    var userAge = document.getElementById('txtAge');
    var dateOfJoin = document.getElementById('txtDateOfJoining');
    var userDivision = document.getElementById('ddlDivision');
    var userDepartment = document.getElementById('ddlDepartment');
    var userShift = document.getElementById('ddlShift');
    var userReportTo = document.getElementById('ddlReportTo');
    var longitude = document.getElementById('txtlongitude');
    var latitude = document.getElementById('txtLatitude');
    var mobileNo = document.getElementById('txtMobile');
    var phoneNo = document.getElementById('txtPhone');
    var contactMobile1 = document.getElementById('txtContactMobile1');
    var contactMobile2 = document.getElementById('txtContactMobile2');
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (!CheckIsSelected(titleField.value)) {
        isError = true;
        controlToBeFocused = titleField;
        alertMessage = 'Please select the Title !';
        titleField.style.backgroundColor = 'lightyellow';
    }
    else {
        titleField.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(firstName).length == 0) {
        isError = true;
        controlToBeFocused = firstName;
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the firstName !';
        firstName.style.backgroundColor = 'lightyellow';
    }
    else {
        firstName.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(userAge).length == 0) {
        isError = true;
        controlToBeFocused = userAge;
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please Enter the Age !';
        userAge.style.backgroundColor = 'lightyellow';
    }
    else {
        userAge.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(mobileNo).length == 0) {
        isError = true;
        controlToBeFocused = mobileNo;
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the mobile number !';
        mobileNo.style.backgroundColor = 'lightyellow';
    }
    else {
        mobileNo.style.backgroundColor = 'white';
    }

    if (mobileNo.value.length > 0) {
        if (mobileFormat(mobileNo.value) == false) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter valid mobile number !';
            mobileNo.style.backgroundColor = 'lightyellow';

            if (!isError) {
                controlToBeFocused = mobileNo;
                isError = true;
            }
        }
        else {
            mobileNo.style.backgroundColor = 'white';
        }
    }
    else {
        mobileNo.style.backgroundColor = 'white';
    }

    if (phoneNo.value.length > 0) {
        if (phoneFormat(phoneNo.value) == false) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter valid phone number !';
            phoneNo.style.backgroundColor = 'lightyellow';

            if (!isError) {
                controlToBeFocused = phoneNo;
                isError = true;
            }
        }
        else {
            phoneNo.style.backgroundColor = 'white';
        }
    }
    else {
        phoneNo.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(emailField).length == 0) {
        isError = true;
        controlToBeFocused = emailField;
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the emailid !';
        emailField.style.backgroundColor = 'lightyellow';
    }
    else if (!validateEmail(emailField.value)) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter a valid email address !';
        if (!isError) {
            controlToBeFocused = emailField;
        }
        isError = true;
        emailField.style.backgroundColor = 'lightyellow';
    }
    else {
        emailField.style.backgroundColor = 'white';
    }

    if (contactMobile1.value.length > 0) {
        if (mobileFormat(contactMobile1.value) == false) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter valid contact mobile number1 !';
            contactMobile1.style.backgroundColor = 'lightyellow';

            if (!isError) {
                controlToBeFocused = contactMobile1;
                isError = true;
            }
        }
        else {
            contactMobile1.style.backgroundColor = 'white';
        }
    }
    else {
        contactMobile1.style.backgroundColor = 'white';
    }

    if (contactMobile2.value.length > 0) {
        if (mobileFormat(contactMobile2.value) == false) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter valid contact mobile number2 !';
            contactMobile2.style.backgroundColor = 'lightyellow';

            if (!isError) {
                controlToBeFocused = contactMobile2;
                isError = true;
            }
        }
        else {
            contactMobile1.style.backgroundColor = 'white';
        }
    }
    else {
        contactMobile1.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(dateOfJoin).length == 0) {
        isError = true;
        controlToBeFocused = dateOfJoin;
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select the date of join !';
        dateOfJoin.style.backgroundColor = 'lightyellow';
    }
    else {
        dateOfJoin.style.backgroundColor = 'white';
    }

    if (!CheckIsSelected(userDivision.value)) {
        isError = true;
        controlToBeFocused = userDivision;
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select the division !';
        userDivision.style.backgroundColor = 'lightyellow';
    }
    else {
        userDivision.style.backgroundColor = 'white';
    }

    if (!CheckIsSelected(userDepartment.value)) {
        isError = true;
        controlToBeFocused = userDepartment;
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select the department !';
        userDepartment.style.backgroundColor = 'lightyellow';
    }
    else {
        userDepartment.style.backgroundColor = 'white';
    }

    if (!CheckIsSelected(userShift.value)) {
        isError = true;
        controlToBeFocused = userShift;
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select the shift !';
        userShift.style.backgroundColor = 'lightyellow';
    }
    else {
        userShift.style.backgroundColor = 'white';
    }

    if (!CheckIsSelected(userReportTo.value)) {
        isError = true;
        controlToBeFocused = userReportTo;
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select the report to !';
        userReportTo.style.backgroundColor = 'lightyellow';
    }
    else {
        userReportTo.style.backgroundColor = 'white';
    }

    if (isError) {
        alert(alertMessage);
        controlToBeFocused.focus();
        return false;
    }
    else {
        return true;
    }

}
//format is +91-04252-267604 or +91-(04252)-267921
function phoneFormat(value) {
    var phoneReg = /^((\+)?(\d{2})[-])?(([\(])?((\d){3,5})([\)])?[-])|(\d{3,5})(\d{5,8}){1}?$/;

    if (phoneReg.test(value) == false) {
        return false;
    }
    else {
        return true;
    }
}

//format is +91-9047790266 or 9047790266    
function mobileFormat(value) {
    var mobileReg = /^((\d{2}))?(\d{10}){1}?$/;
    if ((mobileReg.test(value) == false) || (value.length < 12)) {
        return false;
    }
    else {
        return true;
    }
}

//website validation this allowed only WWW.YAHOO.COM
function websiteFormat(value) {

    var websiteReg = /^([a-z0-9_-]+\.)*[a-z0-9_-]+\.((com)|(info)|(edu)|(biz)|(net)|(org)|(pro)|(name)|(co\.us))$/;

    if (websiteReg.test(value) == false) {
        return false;
    }
    else {
        return true;
    }
}
//Phone and Mobile key press event
//only allowed numbers and +-()sings only
function chkPhone(e) {
    if ((event.keyCode > 47 && event.keyCode < 58) || (event.keyCode == 45) || (event.keyCode == 43) ||
    (event.keyCode == 41) || (event.keyCode == 40)) {
        return true;
    }
    else
        return false;
}

//Mobile key press event
//only allowed numbers 
function chkMobile(e) {
    if ((event.keyCode > 47 && event.keyCode < 58)) {
        return true;
    }
    else
        return false;
}

//check numbers with dot
function chkNumericwithdot(e) {
    if ((event.keyCode > 47 && event.keyCode < 58) || (event.keyCode == 46)) {
        return true;
    }
    else
        return false;
}

//***********************************************************************************************************

function ValidateUserGroupInformation(isUserGroupNameValid) {
    var userGroupName = document.getElementById('txtUserGroupName');
    var hdnSelectedModules = document.getElementById('hdnSelectedModuleList');
    var hdnSelectedOperations = document.getElementById('hdnSelectedOperationList');
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (!isUserGroupNameValid) {
        isError = true;
        alertMessage = 'User group name already exists!';
        userGroupName.style.backgroundColor = 'lightyellow';
        controlToBeFocused = userGroupName;
    }

    if (RemoveSpaces(userGroupName).length == 0) {
        isError = true;
        controlToBeFocused = userGroupName;
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the user group name !';
        userGroupName.style.backgroundColor = 'lightyellow';
    }
    else {
        userGroupName.style.backgroundColor = 'white';
    }

    if (isError) {
        controlToBeFocused.focus();
    }

    if (RemoveSpaces(hdnSelectedModules).length == 0 && RemoveSpaces(hdnSelectedOperations).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select any of the Modules and Operations !';
        isError = true;
    }

    if (isError) {
        alert(alertMessage);
        return false;
    }
    else {
        return true;
    }
}

function ShowLock() {
    var isIE = CheckBrowser();
    if (document.getElementById("chkEnforcedPassword").checked) {
        document.getElementById("tblPasswordPolicy").setAttribute(isIE ? "className" : "class", (isIE ? "ControlShow" : "ControlShowFF"));
    }
    else {
        document.getElementById("tblPasswordPolicy").setAttribute(isIE ? "className" : "class", "ControlHide");
    }
    if (document.getElementById("chkEnableLocking").checked) {
        document.getElementById("tblLocking").setAttribute(isIE ? "className" : "class", (isIE ? "ControlShow" : "ControlShowFF"));
    }
    else {
        document.getElementById("tblLocking").setAttribute(isIE ? "className" : "class", "ControlHide");
    }

    if (document.getElementById("chkLockIp").checked) {
        document.getElementById("tblLockIP").setAttribute(isIE ? "className" : "class", (isIE ? "ControlShow" : "ControlShowFF"));
    }
    else {
        document.getElementById("tblLockIP").setAttribute(isIE ? "className" : "class", "ControlHide");
    }
    if (document.getElementById("chkLockUser").checked) {
        document.getElementById("tblLockUser").setAttribute(isIE ? "className" : "class", (isIE ? "ControlShow" : "ControlShowFF"));
    }
    else {
        document.getElementById("tblLockUser").setAttribute(isIE ? "className" : "class", "ControlHide");
    }
}

/******************* FLEET MAINTENANCE MODULE ***********************************/
// Included by Kumuthini. L on 09-Jun-10

// Maintenance Service
function ValidateMaintenanceService(isServiceNameValid) {
    var serviceName = document.getElementById('txtMainServiceName');
    var serviceCategory = document.getElementById('ddlServiceCategory');
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (!isServiceNameValid) {
        isError = true;
        alertMessage = 'Maintenance Service Name already exists.';
        serviceName.value = '';
        serviceName.style.backgroundColor = 'lightyellow';
        controlToBeFocused = serviceName;
    }

    if (RemoveSpaces(serviceName).length == 0) {
        isError = true;
        controlToBeFocused = serviceName;
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the Maintenance Service Name.';
        serviceName.style.backgroundColor = 'lightyellow';
    }
    else {
        serviceName.style.backgroundColor = 'white';
    }

    if (isError) {
        controlToBeFocused.focus();
        alert(alertMessage);
        return false;
    }
    else {
        return true;
    }
}

// Maintenance Service Assignment
function ValidateServiceAssignment() {
    var serviceCategory = document.getElementById('ddlServiceCategory');
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (!CheckIsSelected(serviceCategory.value)) {
        alertMessage = 'Please select the Service Package.';
        if (!isError) {
            controlToBeFocused = serviceCategory;
            isError = true;
        }
        serviceCategory.style.backgroundColor = 'lightyellow';
    }
    else {
        serviceCategory.style.backgroundColor = 'white';
    }

    if (isError) {
        controlToBeFocused.focus();
        alert(alertMessage);
        return false;
    }
    else {
        return true;
    }
}

// Maintenance Service Category
function ValidateMaintenanceServiceCategory(isServiceCategoryNameValid) {
    var serviceCategoryName = document.getElementById('txtCategoryName');
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (!isServiceCategoryNameValid) {
        isError = true;
        alertMessage = 'Service Package Name already exists.';
        serviceCategoryName.value = '';
        serviceCategoryName.style.backgroundColor = 'lightyellow';
        controlToBeFocused = serviceCategoryName;
    }

    if (RemoveSpaces(serviceCategoryName).length == 0) {
        isError = true;
        controlToBeFocused = serviceCategoryName;
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the Service Package Name.';
        serviceCategoryName.style.backgroundColor = 'lightyellow';
    }
    else {
        serviceCategoryName.style.backgroundColor = 'white';
    }

    if (isError) {
        controlToBeFocused.focus();
        alert(alertMessage);
        return false;
    }
    else {
        return true;
    }
}

function setMaintenancePlanNotificationStatus(isSet) {
    var isNotificationSet = document.getElementById('hdnIsNotificationSet');
    isNotificationSet.value = isSet ? 'Y' : 'N';
}

// Maintenance Plan
function ValidateMaintenancePlan() {
    var planName = document.getElementById('txtPlanName');
    var isNotificationSet = document.getElementById('hdnIsNotificationSet');
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (RemoveSpaces(planName).length == 0) {
        isError = true;
        controlToBeFocused = planName;
        alertMessage = 'Please enter the Plan Name.';
        planName.style.backgroundColor = 'lightyellow';
    }
    else {
        planName.style.backgroundColor = 'white';
    }

    if (isNotificationSet.value == 'N') {
        isError = true;
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please click Manage Notification to select the Email/SMS Users.';
    }

    if (isError) {
        if (controlToBeFocused != null) {
            controlToBeFocused.focus();
        }
        alert(alertMessage);
        return false;
    }
    else {
        return true;
    }
}

// Maintenance Plan Details
function ValidateMaintenancePlanDetails() {
    var serviceInterval = document.getElementById('txtServiceInterval');
    var serviceCategory = document.getElementById('ddlServiceCategory');
    var services = document.getElementById('lbServices');
    var notification1 = document.getElementById('ddlPercentageR1');
    var notification2 = document.getElementById('ddlPercentageR2');
    var notification3 = document.getElementById('ddlPercentageR3');
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (RemoveSpaces(serviceInterval).length == 0) {
        isError = true;
        alertMessage = 'Please enter the Service Interval.';
        serviceInterval.value = '';
        serviceInterval.style.backgroundColor = 'lightyellow';
        controlToBeFocused = serviceInterval;
    }
    else {
        if (RemoveSpaces(serviceInterval) == 0) {
            isError = true;
            alertMessage = 'Service Interval cannot be Zero.';
            serviceInterval.style.backgroundColor = 'lightyellow';
            controlToBeFocused = serviceInterval;
        }
        else {
            serviceInterval.style.backgroundColor = 'white';
        }
    }

    if (!CheckIsSelected(serviceCategory.value)) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please select the Service Package.';
        if (!isError) {
            controlToBeFocused = serviceCategory;
            isError = true;
        }
        serviceCategory.style.backgroundColor = 'lightyellow';
    }
    else {
        if (services.length == 0) {
            alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Selected Service Package does not have Services.';
            if (!isError) {
                controlToBeFocused = serviceCategory;
                isError = true;
            }
            serviceCategory.style.backgroundColor = 'lightyellow';
        }
        else {
            serviceCategory.style.backgroundColor = 'white';
        }
    }

    if (notification2.value != 0 && notification2.value <= notification1.value) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Remainder 2 should be greater than Remainder 1.';
        if (!isError) {
            controlToBeFocused = notification2;
            isError = true;
        }
        notification2.style.backgroundColor = 'lightyellow';
    }
    else {
        notification2.style.backgroundColor = 'white';
    }

    if (notification3.value != 0 && notification3.value <= notification1.value) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Remainder 3 should be greater than Remainder 1.';
        if (!isError) {
            controlToBeFocused = notification3;
            isError = true;
        }
        notification3.style.backgroundColor = 'lightyellow';
    }
    else {
        notification3.style.backgroundColor = 'white';
    }

    if (notification3.value != 0 && notification3.value <= notification2.value) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Remainder 3 should be greater than Remainder 2.';
        if (!isError) {
            controlToBeFocused = notification3;
            isError = true;
        }
        notification3.style.backgroundColor = 'lightyellow';
    }
    else {
        notification3.style.backgroundColor = 'white';
    }

    if (isError) {
        controlToBeFocused.focus();
        alert(alertMessage);
        return false;
    }
    else {
        return true;
    }
}

function GetConfirmFleetMaintenance(type, Mode, assignedStatus) {
    if (Mode == 'delete' && assignedStatus == 1) {
        // If Maintenance Service
        if (type == 'ms') {
            alert('Maintenance Service cannot be deleted as it has been assigned to one or more maintenance service package(s).');
        }
        // If Maintenance Plan
        else if (type == 'mp') {
            alert('Maintenance Plan cannot be deleted as it has been assigned to one or more vehicle(s).');
        }
        // If Maintenance Plan Details
        else if (type == 'mpd') {
            alert('Maintenance Plan Details cannot be deleted as it has been assigned to one or more vehicle(s).');
        }
        return false;
    }
    else {
        if (Mode == 'delete') {
            return confirm('Are you sure you want to delete this entry?');
        }
        else {
            return true;
        }
    }
}

// Nearing Maintenance
function ValidateNearingMaintenance(status) {
    var serviceInterval = document.getElementById('txtServiceInterval');
    var dueOnDate = document.getElementById('txtDueOnDate');
    var comments = document.getElementById('txtComments');
    var startDate = document.getElementById('hdnTimeBasedStartDate');

    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (status == 1) {
        //        if (RemoveSpaces(servicedOn).length == 0) {
        //            isError = true;
        //            alertMessage = 'Please enter the Serviced On.';
        //            servicedOn.style.backgroundColor = 'lightyellow';
        //            controlToBeFocused = servicedOn;
        //        }
        //        else {

        //            var msg = checkDateGreaterThanCurrentDate($find('ceServiceOnDate'), null, startDate.value);

        //            if (msg != "") {
        //                isError = true;
        //                alertMessage = msg;
        //                servicedOn.style.backgroundColor = 'lightyellow';
        //                controlToBeFocused = servicedOn;
        //            }
        //            else {
        //                servicedOn.style.backgroundColor = 'white';
        //            }
        //        }

        if (document.getElementById("hdnServiced") != null && document.getElementById("hdnServiced").value == '') {
            alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please select the maintenance services.';
            if (!isError) {
                controlToBeFocused = document.getElementById("gvServiceDetails");
                isError = true;
            }
        }
    }
    else if (status == 4) {
        if (serviceInterval != null && serviceInterval.style.display == "block") {
            if (RemoveSpaces(serviceInterval).length == 0) {
                alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please enter the Service Interval.';
                if (!isError) {
                    controlToBeFocused = serviceInterval;
                    isError = true;
                }
                serviceInterval.style.backgroundColor = 'lightyellow';
            }
            else {
                if (RemoveSpaces(serviceInterval) == 0) {
                    alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please enter a valid Service Interval.';
                    if (!isError) {
                        controlToBeFocused = serviceInterval;
                        isError = true;
                    }
                    serviceInterval.style.backgroundColor = 'lightyellow';
                }
                serviceInterval.style.backgroundColor = 'white';
            }
        }

        if (dueOnDate != null && dueOnDate.style.display == "block") {
            if (RemoveSpaces(dueOnDate).length == 0) {
                alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please enter the Due On Date.';
                if (!isError) {
                    controlToBeFocused = dueOnDate;
                    isError = true;
                }
                dueOnDate.style.backgroundColor = 'lightyellow';
            }
            else {
                var msg = checkRescheduleDueOnDate($find('ceDueOnDate'), null)

                if (msg != 'error' && msg != 'valid') {
                    alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Due On Date should be greater than current date.';
                    if (!isError) {
                        controlToBeFocused = dueOnDate;
                        isError = true;
                    }
                    dueOnDate.style.backgroundColor = 'lightyellow';
                }
                else {
                    dueOnDate.style.backgroundColor = 'white';
                }
            }
        }
    }

    if (status != 1 && RemoveSpaces(comments).length == 0) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please enter the Comments.';
        if (!isError) {
            controlToBeFocused = comments;
            isError = true;
        }
        comments.style.backgroundColor = 'lightyellow';
    }
    else {
        comments.style.backgroundColor = 'white';
    }

    if (isError) {
        controlToBeFocused.focus();
        alert(alertMessage);
        return false;
    }
    else {
        return true;
    }
}

// Get the Service Done Count
function getServicesDoneCount() {
    var i = 0;
    var qtyChk = 0;

    objItem = document.getElementById('clbServices_' + 0);

    while (objItem != null) {
        qtyChk = (objItem.checked) ? (qtyChk + 1) : qtyChk;
        i++;
        objItem = document.getElementById('clbServices_' + i);
    }

    return qtyChk;
}

// Vehicle Service History
function ValidateServiceHistory() {
    var vehicle = document.getElementById('ddlVehicle');
    var startDate = document.getElementById('txtStartDate');
    var endDate = document.getElementById('txtEndDate');

    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (vehicle.value == "- Select -") {
        isError = true;
        alertMessage = 'Please select the Vehicle.';
        vehicle.style.backgroundColor = 'lightyellow';
        controlToBeFocused = vehicle;
    }
    else {
        vehicle.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(startDate).length == 0) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please enter the From Date.';
        if (!isError) {
            controlToBeFocused = startDate;
            isError = true;
        }
        startDate.style.backgroundColor = 'lightyellow';
    }
    else {
        if (checkStartEndDate($find('ceStartDate'), 0)) {
            alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please enter a valid From Date.';
            if (!isError) {
                controlToBeFocused = startDate;
                isError = true;
            }
            startDate.style.backgroundColor = 'lightyellow';
        }
        else {
            startDate.style.backgroundColor = 'white';
        }
    }

    if (RemoveSpaces(endDate).length == 0) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please enter the To Date.';
        if (!isError) {
            controlToBeFocused = endDate;
            isError = true;
        }
        endDate.style.backgroundColor = 'lightyellow';
    }
    else {
        if (checkStartEndDate($find('ceEndDate'), 1)) {
            alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please enter a valid To Date.';
            if (!isError) {
                controlToBeFocused = endDate;
                isError = true;
            }
            endDate.style.backgroundColor = 'lightyellow';
        }
        else {
            endDate.style.backgroundColor = 'white';
        }
    }

    if (checkStartEndDate($find('ceEndDate'), 2)) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please enter a valid date range.';
        if (!isError) {
            controlToBeFocused = endDate;
            isError = true;
        }
        endDate.style.backgroundColor = 'lightyellow';
    }
    else {
        endDate.style.backgroundColor = 'white';
    }

    if (isError) {
        controlToBeFocused.focus();
        alert(alertMessage);
        return false;
    }
    else {
        return true;
    }
}

/****************************************************************************************************************/

/****************************************************************************************************************/
//diable the enter key 
function DisableEnterkey(event) {
    if (event.keyCode == 13) {
        event.returnValue = false;
        event.cancel = true;
    }
}

/****************************************************************************************************************/

function CheckTimePicker(control, controlName) {
    if (control == null)
        return;
    var selectedAMPMOption = document.getElementById(controlName).options[document.getElementById(controlName).selectedIndex].value;
    switch (control.value) {
        case '00':
            document.getElementById(controlName).innerHTML = "";
            var option = document.createElement("OPTION");
            option.innerHTML = 'AM';
            option.value = 'AM';
            document.getElementById(controlName).appendChild(option);
            break;
        case '12':
            document.getElementById(controlName).innerHTML = "";
            var option = document.createElement("OPTION");
            option.innerHTML = 'PM';
            option.value = 'PM';
            document.getElementById(controlName).appendChild(option);
            break;
        default:
            document.getElementById(controlName).innerHTML = "";
            var option = document.createElement("OPTION");
            var option1 = document.createElement("OPTION");
            option.innerHTML = 'AM';
            option1.innerHTML = 'PM';
            option.value = 'AM';
            option1.value = 'PM';
            document.getElementById(controlName).appendChild(option);
            document.getElementById(controlName).appendChild(option1);
            document.getElementById(controlName).selectedIndex = selectedAMPMOption == "AM" ? 0 : 1
            break;
    }
}

/****************************************************************************************************************/
/****************** Report Checking ****************/
function ShowOrHideOptions() {
    var isIE = CheckBrowser();
    var checkBoxItem = document.getElementById('chkShowDetail');
    if (checkBoxItem != null) {
        if (checkBoxItem.checked) {
            document.getElementById('cblShowHideOptions').setAttribute(isIE ? 'className' : 'class', 'ControlShow Chkinput');
        }
        else {
            document.getElementById('cblShowHideOptions').setAttribute(isIE ? 'className' : 'class', 'ControlHide');
        }
    }
}

function HideLabel() {
    var isIE = CheckBrowser();
    var msgLabel = document.getElementById('lblNoRecords');
    if (msgLabel != null) {
        msgLabel.setAttribute(isIE ? 'className' : 'class', 'ControlHide');
    }
}

/******************* Landmark Validation for History Page *****************************/
function ValidateLandmarkFields() {
    var txtLocationName = document.getElementById('txtLocationName');
    var txtRadius = document.getElementById('txtRadius');
    var isError = false;
    var errorMessage = '';
    if (RemoveSpaces(txtLocationName).length == 0) {
        isError = true;
        errorMessage = 'Please enter the name for the landmark !';
        txtLocationName.focus();
        txtLocationName.style.backgroundColor = 'lightyellow';
    }
    else {
        txtLocationName.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtRadius).length == 0) {
        errorMessage = (isError ? errorMessage + '\n' : '') + 'Please enter the radius for the landmark !';
        if (!isError) {
            txtRadius.focus();
        }
        isError = true;
        txtRadius.style.backgroundColor = 'lightyellow';
    }
    else {
        txtRadius.style.backgroundColor = 'white';
    }
    if (isError) {
        alert(errorMessage);
    }
    return !isError;
}

function Validate() {
    if (document.getElementById("ddlVehicle").value == 0) {
        alert("Select any of the vehicle !");
        document.getElementById("ddlVehicle").focus();
        return false;
    }

    return true;
}
// Vehicle Geozone Assignment Validation
// Included by Kumuthini. L
function VehGeoAsmtValidation() {
    if (CheckSelectionForManipulation(1)) {
        if (document.getElementById("hdnIsAssigned").value == 1) {
            alert("Some of the selected sensor(s) exceeds maximum geozone limit !");
            return false;
        }
    }
    else {
        return false;
    }
    return true;
}

function CheckSelectionForManipulation(type) {

    var alertMessage = '';
    var gridControlName
    var isError = false;
    if (type == 1) { // Un Assigned Vehicles
        gridControlName = gvUnAssignedVehicles;
        hdnSelectedIDList = 'hdnVehicleIdsToBeAssinged';
        alertMessage = 'Select sensor(s) to be assigned !';
    }
    else if (type == 2) { // Assigned Vehicles
        gridControlName = gvAssignedVehicles;
        hdnSelectedIDList = 'hdnVehicleIdsToBeUnassinged';
        alertMessage = 'Select sensor(s) to be unassigned !';
    }
    else if (type == 3) { // Unassinged Users
        gridControlName = gvUnAssignedUsers;
        hdnSelectedIDList = 'hdnUsersToBeAssigned';
        alertMessage = 'Select user(s) to be assigned !';
    }
    else if (type == 4) {// Assigned Users
        gridControlName = gvAssignedUsers;
        hdnSelectedIDList = 'hdnUsersToBeUnassinged';
        alertMessage = 'Select user(s) to be unassigned !';
    }
    else if (type == 5) { // Alerts
        hdnSelectedIDList = 'hdnAlarmIDs';
        alertMessage = 'Select alarm(s) that has to be updated !';
    }
    else if (type == 6) { // User Information
        hdnSelectedIDList = 'hdnSelectedUserIds';
        alertMessage = 'Select user(s) that has to be updated !';
    }

    else if (type == 7) { // User List for Email notifications
        hdnSelectedIDList = 'ucNotificationList_hdnEmailUsers';
    }

    else if (type == 8) { // User List for SMS notifications
        hdnSelectedIDList = 'ucNotificationList_hdnSMSUsers';
    }

    else if (type == 9) { // Assign Sensors to Devices 
        hdnSelectedIDList = 'hdnSelectedSensorUnAssignIds';
        alertMessage = 'Select sensor(s) to be assigned !';
    }

    else if (type == 10) { // Unassign Sensors to Devices 
        hdnSelectedIDList = 'hdnSelectedSensorAssignIds';
        alertMessage = 'Select sensor(s) to be unassigned !';
    }

    else if (type == 11) { // Assign Outputs to Devices
        hdnSelectedIDList = 'hdnSelectedOutputUnAssignIds';
        alertMessage = 'Select output(s) to be assigned !';
    }

    else if (type == 12) { // Unassign Outputs to Devices
        hdnSelectedIDList = 'hdnSelectedOutputAssignIds';
        alertMessage = 'Select output(s) to be unassigned !';
    }
    else if (type == 13) { // User List for emailing reports
        hdnSelectedIDList = 'ucNotificationList_hdnEmailUsers';
    }


    // To check whether the items in the grid were selected or not
    if (gridControlName != null) {
        isError = gridControlName.GetSelectedRowCount() == 0 ? true : false;
    }

    else if (type != 7 && type != 8 && type != 13) {
        var test = document.getElementById(hdnSelectedIDList).value.split(",");
        if (test.length > 0) {
            if (test.length == 1 && test[0] == "") {
                isError = true;
            }
        }
    }
    else {
        //Included by Jeyanthi on-Aug-2010 for handling Email and SMS Previlege
        var isEmailVisible = true;
        var isSMSVisible = true;
        if (document.getElementById('ucNotificationList_hdnIsEmailVisible') != null && document.getElementById('ucNotificationList_hdnIsEmailVisible').value == 'False') {
            isEmailVisible = false;
        }

        if (document.getElementById('ucNotificationList_hdnIsSMSVisible') != null && document.getElementById('ucNotificationList_hdnIsSMSVisible').value == 'False') {
            isSMSVisible = false;
        }
        //End handling Email and SMS Previlege 
        var isEmailSelected = true;
        var isSMSSelected = true;

        if (document.getElementById('ucNotificationList_hdnNotificationType') != null && document.getElementById('ucNotificationList_hdnNotificationType').value == '5') {
            type = 13;
        }

        var test = document.getElementById('ucNotificationList_hdnEmailUsers').value.split(",");

        if (test.length > 0) {
            if (test.length == 1 && test[0] == "") {
                isEmailSelected = false;
            }
        }

        if (type == 13) {
            if (!isEmailSelected) {
                isError = true;
                if (confirm('No Email is selected.\nDo you want to select it?')) {
                    return false;
                }
                else {
                    return true;
                }
            }
            else {
                isError = false;
            }
        }
        else {

            test = document.getElementById('ucNotificationList_hdnSMSUsers').value.split(",");

            if (test.length > 0) {
                if (test.length == 1 && test[0] == "") {
                    isSMSSelected = false;
                }
            }
            //Modified by Jeyanthi on-Aug- 2010
            // if (!isEmailSelected && !isSMSSelected) {
            //          isError = true;
            //       if (confirm('No Email / SMS notification is selected.\nDo you want to select it?')) {
            //          return false;
            //       }
            //       else {
            //           return true;
            //       }
            // }
            // else {
            //  isError = false;
            //}
            if (!isEmailSelected && !isSMSSelected) {
                isError = true;
                if (isEmailVisible && isSMSVisible) {
                    if (confirm('No Email / SMS notification is selected.\nDo you want to select it?')) {
                        return false;
                    }
                    else {
                        return true;
                    }
                }
                else if (isEmailVisible) {
                    if (confirm('No Email notification is selected.\nDo you want to select it?')) {
                        return false;
                    }
                    else {
                        return true;
                    }
                }
                else if (isSMSVisible) {
                    if (confirm('No SMS notification is selected.\nDo you want to select it?')) {
                        return false;
                    }
                    else {
                        return true;
                    }
                }
            }
            else {
                isError = false;
            }
            //End
        }
    }

    if (type == 5 && !isError) {
        if ($get('ctl05$ddlMassUpdateStatus').value == 0) {
            isError = true;
            alertMessage = 'Select the status to be changed for the selected alarm(s) !';
        }
    }

    if (isError) {
        alert(alertMessage);
    }

    return !isError;
}

function setFocus(event, control) {
    if (event.keyCode == 9) {
        document.getElementById(control).focus();
        return false;
    }
    else {
        return true;
    }
}

function setFocusToControl(controlName) {
    var control = document.getElementById(controlName);

    if (control != null) {
        control.focus();
    }
}

/*****************************Validate the Route Planning************************************************************/

function ValidateRoutePlanning() {
    var txtDate = document.getElementById("txtDate");
    var ddlShiftinTime = document.getElementById("ddlShiftinTime");
    var ddlShiftinTimeMinutes = document.getElementById("ddlShiftinTimeMinutes");
    var ddlShiftOutTime = document.getElementById("ddlShiftOutTime");
    var ddlShiftOutTimeMinutes = document.getElementById("ddlShiftOutTimeMinutes");
    var ddlTripMode = document.getElementById("ddlTripMode");
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (RemoveSpaces(txtDate).length == 0) {
        alertMessage = 'Please select a Date.';

        if (!isError) {
            controlToBeFocused = txtDate;
            isError = true;
        }
        txtDate.style.backgroundColor = 'lightyellow';
    }
    else {
        txtDate.style.backgroundColor = 'white';
    }

    //    if (!CheckIsSelectedTime(ddlShiftinTime.value)) {
    //        alertMessage = (alertMessage.length == 0 ? '' : alertMessage + '\n') + 'Please select shiftin time..!';

    //        if (!isError) {
    //            controlToBeFocused = ddlShiftinTime;
    //            isError = true;
    //        }
    //        ddlShiftinTime.style.backgroundColor = 'lightyellow';
    //    }
    //    else {
    //        ddlShiftinTime.style.backgroundColor = 'white';
    //    }

    //    if (!CheckIsSelectedTime(ddlShiftOutTime.value)) {
    //        alertMessage = (alertMessage.length == 0 ? '' : alertMessage + '\n') + 'Please select shiftout time..!';

    //        if (!isError) {
    //            isError = true;
    //            controlToBeFocused = ddlShiftOutTime;
    //        }
    //        ddlShiftOutTime.style.backgroundColor = 'lightyellow';
    //    }
    //    else {
    //        ddlShiftOutTime.style.backgroundColor = 'white';
    //    }

    if (!CheckIsSelected(ddlTripMode.value)) {
        alertMessage = (alertMessage.length == 0 ? '' : alertMessage + '\n') + 'Please select a Trip Mode.';

        if (!isError) {
            isError = true;
            controlToBeFocused = ddlTripMode;
        }
        ddlTripMode.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlTripMode.style.backgroundColor = 'white';
    }

    if (isError) {
        controlToBeFocused.focus();
        alert(alertMessage);
        return false;

    }
    return true;

}

function checkFutureDate(sender, args) {
    if (sender._selectedDate >= new Date()) {
        alert("Please select less than today..!");
        sender._selectedDate = new Date();
        sender._textbox.set_Value("");
    }
}


//***********************************************************************************************************

//move up and down
var rowStatus = 0;
var currentRowId = 0;
var isFemale = false;
var isMultiRow = false;
var gridControl;

function SelectRow(controlId, rowControls) {
    if (event.keyCode == 40)
        MarkRow((currentRowId + 1), controlId, rowControls);
    else if (event.keyCode == 38)
        MarkRow((currentRowId - 1), controlId, rowControls);
    else if (event.keyCode == 13) {
        var gridView = document.getElementById(controlId);
        var gridRow = gridView.rows[currentRowId + 1];
        gridRow.className = 'fleetCon';
        currentRowId = 0;
        rowStatus = 1;
    }
}

function MarkRow(rowId, controlId, rowControls) {
    if (gridControl == null) {
        gridControl = controlId;
    }
    else if (gridControl != controlId) {
        currentRowId = 0;
        rowStatus = 1;
        var gridView = document.getElementById(gridControl);
        for (var i = 1; i < gridView.rows.length; i++) {
            var gridRow = gridView.rows[i];
            gridRow.className = 'fleetCon';
        }
        var selectedcontrols = document.getElementById('hdnSelectedControls').value.split('#');
        var selectedRows = document.getElementById('hdnSelectedRows').value.split('#');

        for (var i = 0; i < selectedRows.length - 1; i++) {
            var controldetails = selectedcontrols[i].split(',');
            document.getElementById(controldetails[0]).checked = false;
            var gridRow = gridView.rows[parseInt(controldetails[1]) + 1];
            gridRow.className = 'fleetCon';
        }
        gridControl = controlId;
        document.getElementById('hdnSelectedRows').value = '';
        document.getElementById('hdnSelectedControls').value = '';
    }

    if (isMultiRow) {
        isMultiRow = false;
        currentRowId = 1;
        return;
    }
    var gridView = document.getElementById(controlId);
    if (document.getElementById("hdnId1").value == 'Yes') {
        rowStatus = 1;
        document.getElementById("hdnId1").value = '';
    }
    if (rowStatus == 1) {
        rowStatus = 0;
    }
    else {
        if (document.getElementById(rowId) == null)
            return;
        if (document.getElementById(currentRowId) != null) {
            var gridRow = gridView.rows[currentRowId + 1];
            gridRow.className = 'fleetCon';
        }
        if ((currentRowId == 0) && (rowId == 0)) {
        }
        else {
            var selectedRows = document.getElementById('hdnSelectedRows').value.split('#');
            if (selectedRows.length - 1 > 0) {
                for (var k = 0; k < selectedRows.length - 1; k++) {
                    currentRowId = parseInt(selectedRows[k]);
                    for (var l = k + 1; l < selectedRows.length - 1; l++) {
                        if (selectedRows[k] < selectedRows[l])
                            selectedRows[l] = parseInt(selectedRows[l]) - 1;
                        else
                            selectedRows[l] = parseInt(selectedRows[l]) + 1;
                    }
                    if (k > 0) {
                        currentRowId = parseInt(selectedRows[k]);
                    }
                    if ((currentRowId == (rowId + 1))) {
                        var gridRow = gridView.rows[currentRowId + 1];
                        var gridUpRow = gridView.rows[rowId + 1];
                        var selectedRowValue = '';
                        for (var i = 0; i < 6; i++) {
                            var gridcolumn = gridRow.cells[i];
                            selectedRowValue = gridcolumn.innerText;
                            var gridUpColumn = gridUpRow.cells[i];
                            gridcolumn.innerText = gridUpColumn.innerText;
                            gridUpColumn.innerText = selectedRowValue;
                        }
                    }
                    else if ((rowId == (currentRowId + 1))) {
                        var gridRow = gridView.rows[currentRowId + 1];
                        var gridUpRow = gridView.rows[rowId + 1];
                        var selectedRowValue = '';
                        for (var i = 0; i < 6; i++) {
                            var gridcolumn = gridRow.cells[i];
                            selectedRowValue = gridcolumn.innerText;
                            var gridUpColumn = gridUpRow.cells[i];
                            gridcolumn.innerText = gridUpColumn.innerText;
                            gridUpColumn.innerText = selectedRowValue;
                        }
                    }

                    else if (currentRowId > rowId) {
                        for (var j = rowId; j <= (currentRowId); j++) {
                            var gridRow = gridView.rows[currentRowId + 1];
                            var gridUpRow = gridView.rows[j + 1];
                            var selectedRowValue = '';
                            for (var i = 0; i < 6; i++) {
                                var gridcolumn = gridRow.cells[i];
                                selectedRowValue = gridcolumn.innerText;
                                var gridUpColumn = gridUpRow.cells[i];
                                gridcolumn.innerText = gridUpColumn.innerText;
                                gridUpColumn.innerText = selectedRowValue;
                            }
                        }
                    }
                    else if (rowId > currentRowId) {
                        for (var j = currentRowId; j <= (rowId); j++) {
                            var gridRow = gridView.rows[j + 1];
                            if (j == rowId)
                                var gridUpRow = gridView.rows[j + 1];
                            else
                                var gridUpRow = gridView.rows[(j + 1) + 1];
                            var selectedRowValue = '';
                            for (var i = 0; i < 6; i++) {
                                var gridcolumn = gridUpRow.cells[i];
                                selectedRowValue = gridcolumn.innerText;
                                var gridUpColumn = gridRow.cells[i];
                                gridcolumn.innerText = gridUpColumn.innerText;
                                gridUpColumn.innerText = selectedRowValue;
                            }
                        }
                    }
                }
                var selectedcontrols = document.getElementById('hdnSelectedControls').value.split('#');

                for (var i = 0; i < selectedRows.length - 1; i++) {
                    var controldetails = selectedcontrols[i].split(',');
                    document.getElementById(controldetails[0]).checked = false;
                    var gridRow = gridView.rows[parseInt(controldetails[1]) + 1];
                    gridRow.className = 'fleetCon';
                }
                document.getElementById('hdnSelectedRows').value = '';
                document.getElementById('hdnSelectedControls').value = '';
            }
            else {
                if ((currentRowId == (rowId + 1))) {
                    var gridRow = gridView.rows[currentRowId + 1];
                    var gridUpRow = gridView.rows[rowId + 1];
                    var selectedRowValue = '';
                    for (var i = 0; i < 6; i++) {
                        var gridcolumn = gridRow.cells[i];
                        selectedRowValue = gridcolumn.innerText;
                        var gridUpColumn = gridUpRow.cells[i];
                        gridcolumn.innerText = gridUpColumn.innerText;
                        gridUpColumn.innerText = selectedRowValue;
                    }
                }
                else if ((rowId == (currentRowId + 1))) {
                    var gridRow = gridView.rows[currentRowId + 1];
                    var gridUpRow = gridView.rows[rowId + 1];
                    var selectedRowValue = '';
                    for (var i = 0; i < 6; i++) {
                        var gridcolumn = gridRow.cells[i];
                        selectedRowValue = gridcolumn.innerText;
                        var gridUpColumn = gridUpRow.cells[i];
                        gridcolumn.innerText = gridUpColumn.innerText;
                        gridUpColumn.innerText = selectedRowValue;
                    }
                }

                else if (currentRowId > rowId) {
                    for (var j = rowId; j <= (currentRowId); j++) {
                        var gridRow = gridView.rows[currentRowId + 1];
                        var gridUpRow = gridView.rows[j + 1];
                        var selectedRowValue = '';
                        for (var i = 0; i < 6; i++) {
                            var gridcolumn = gridRow.cells[i];
                            selectedRowValue = gridcolumn.innerText;
                            var gridUpColumn = gridUpRow.cells[i];
                            gridcolumn.innerText = gridUpColumn.innerText;
                            gridUpColumn.innerText = selectedRowValue;
                        }
                    }
                }
                else if (rowId > currentRowId) {
                    for (var j = currentRowId; j <= (rowId); j++) {
                        var gridRow = gridView.rows[j + 1];
                        if (j == rowId)
                            var gridUpRow = gridView.rows[j + 1];
                        else
                            var gridUpRow = gridView.rows[(j + 1) + 1];
                        var selectedRowValue = '';
                        for (var i = 0; i < 6; i++) {
                            var gridcolumn = gridUpRow.cells[i];
                            selectedRowValue = gridcolumn.innerText;
                            var gridUpColumn = gridRow.cells[i];
                            gridcolumn.innerText = gridUpColumn.innerText;
                            gridUpColumn.innerText = selectedRowValue;
                        }
                    }
                }
            }

        }
    }
    currentRowId = rowId;
    var gridRow = gridView.rows[rowId + 1];
    gridRow.className = 'fleetRowd';
    var movedEmps = document.getElementById('hdnMovedEmps');
    movedEmps.value = '';
    for (var i = 1; i < gridView.rows.length; i++) {
        var gridRow = gridView.rows[i];
        var gridCell = gridRow.cells[0];
        movedEmps.value = movedEmps.value + gridCell.innerText + ",";
    }

    if (document.getElementById('hdnTripMode').value == "Pickup") {
        gridRow = gridView.rows[1];
        gridCell = gridRow.cells[2];
        if (gridCell.innerText == "Female ") {
            isFemale = true;
        }
        else {
            isFemale = false;
        }
    }
    else {
        gridRow = gridView.rows[gridView.rows.length - 1];
        gridCell = gridRow.cells[2];
        if (gridCell.innerText == "Female ") {
            isFemale = true;
        }
        else {
            isFemale = false;
        }
    }

    if (isFemale) {
        var controls = rowControls.toString().split('#');
        for (var i = 0; i < controls.length - 1; i++) {

            document.getElementById(controls[i]).style.color = "red";
        }
    }
    else {
        var controls = rowControls.toString().split('#');
        for (var i = 0; i < controls.length - 1; i++) {
            if (i == 0) {
                document.getElementById(controls[i]).style.color = "blue";
            }
            else {
                document.getElementById(controls[i]).style.color = "black";
            }
        }
    }

    CallServer(movedEmps.value, '');
}

function MoveRows(currentRowId, controlId, chkMove) {
    if (document.getElementById(chkMove).checked) {
        document.getElementById('hdnSelectedControls').value = document.getElementById('hdnSelectedControls').value + chkMove + "," + currentRowId + "#";
        document.getElementById('hdnSelectedRows').value = document.getElementById('hdnSelectedRows').value + currentRowId + "#";
        var selectedRows = document.getElementById('hdnSelectedRows').value.split('#');
        for (var i = 0; i < selectedRows.length - 1; i++) {
            var gridView = document.getElementById(controlId);
            var gridRow = gridView.rows[parseInt(selectedRows[i]) + 1];
            gridRow.className = 'fleetRowd';
        }
        rowStatus = 0;
    }
    else {
        document.getElementById('hdnSelectedRows').value = String(document.getElementById('hdnSelectedRows').value).replace(currentRowId + "#", '');
        document.getElementById('hdnSelectedControls').value = String(document.getElementById('hdnSelectedControls').value).replace(chkMove + "," + currentRowId + "#", '');
        var selectedRows = document.getElementById('hdnSelectedRows').value.split('#');
        var gridView = document.getElementById(controlId);
        var gridRow = gridView.rows[currentRowId + 1];
        gridRow.className = 'fleetCon';
    }
    isMultiRow = true;
    document.getElementById('hdnId1').value = '';
}


/*****************************************Tracking details validation******************************/
function ValidateTracking() {
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';
    var rbtNoShow = document.getElementById('rbtNoShow');
    var rbtPicked = document.getElementById('rbtPicked');
    var rbtWaitMove = document.getElementById('rbtWaitMove');
    var txtDateofPicked = document.getElementById('txtDateofPicked');
    var ddlTimeOfPicked = document.getElementById('ddlTimeOfPicked');
    var txtDateOfMove = document.getElementById('txtDateOfMove');
    var ddlTimeOfMove = document.getElementById('ddlTimeOfMove');
    if ((!rbtNoShow.checked) && (!rbtPicked.checked) && (!rbtWaitMove.checked)) {
        alertMessage = 'Please select any one of the tracking options.';
        if (!isError) {
            isError = true;
            controlToBeFocused = rbtNoShow;
        }
        rbtNoShow.style.backgroundColor = 'lightyellow';
    }
    else {
        rbtNoShow.style.backgroundColor = 'white';
    }
    if (rbtPicked.checked) {
        if (RemoveSpaces(txtDateofPicked).length == 0) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select the pickup date.';
            if (!isError) {
                isError = true;
                controlToBeFocused = txtDateofPicked;
            }
            txtDateofPicked.style.backgroundColor = 'lightyellow';
        }
        else {
            txtDateofPicked.style.backgroundColor = 'white';
        }
        if (!CheckIsSelectedTime(ddlTimeOfPicked.value)) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select the pickup time.';
            if (!isError) {
                isError = true;
                controlToBeFocused = ddlTimeOfPicked;
            }
            ddlTimeOfPicked.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlTimeOfPicked.style.backgroundColor = 'white';
        }
    }
    if (rbtWaitMove.checked) {
        if (RemoveSpaces(txtDateOfMove).length == 0) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select the Wait & Move date.';
            if (!isError) {
                isError = true;
                controlToBeFocused = txtDateOfMove;
            }
            txtDateOfMove.style.backgroundColor = 'lightyellow';
        }
        else {
            txtDateOfMove.style.backgroundColor = 'white';
        }
        if (!CheckIsSelectedTime(ddlTimeOfMove.value)) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select the Wait & Move time.';
            if (!isError) {
                isError = true;
                controlToBeFocused = ddlTimeOfMove;
            }
            ddlTimeOfMove.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlTimeOfMove.style.backgroundColor = 'white';
        }
    }
    if (isError) {
        alert(alertMessage);
        controlToBeFocused.focus();
        return false;
    }
    else {
        return true;
    }
}


function CheckddlFrequency() {
    var from = document.getElementById('txtEffectiveFrom').value;
    var to = document.getElementById('txtEffectiveTo').value;
    document.getElementById('ddlFrequencyCommands');
    if ((from != null && from != "") && (to != null && to != "")) {

        var one_day = 1000 * 60 * 60 * 24;
        var months = 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec';
        var month = String(months).split(',');
        var date = String(from).split('-');
        for (var i = 0; i < month.length; i++) {
            if (date[1] == month[i]) {
                from = new Date(date[2], i, date[0]);
                break;
            }
        }
        var date = String(to).split('-');
        for (var i = 0; i < month.length; i++) {
            if (date[1] == month[i]) {
                to = new Date(date[2], i, date[0]);
                break;
            }
        }

        var totaldays = Math.ceil((to.getTime() - from.getTime()) / (one_day)) + 1;
        if (totaldays < 0) {
            alert('Please Select the valid date range.');
            document.getElementById('txtEffectiveTo').value = "";
            document.getElementById('txtEffectiveTo').focus();
            return;
        }
        if (totaldays == 1) {
            clearDropdown(document.getElementById('ddlFrequencyCommands'));
            addOption(document.getElementById('ddlFrequencyCommands'), '- Select -', '- Select -');
            addOption(document.getElementById('ddlFrequencyCommands'), 'Only Once', '0');
        }
        else if (totaldays >= 1 && totaldays < 3) {
            clearDropdown(document.getElementById('ddlFrequencyCommands'));
            addOption(document.getElementById('ddlFrequencyCommands'), '- Select -', '- Select -');
            addOption(document.getElementById('ddlFrequencyCommands'), 'Only Once', '0');
            addOption(document.getElementById('ddlFrequencyCommands'), 'Daily Once', '1');
        }
        else if (totaldays >= 3 && totaldays < 7) {
            clearDropdown(document.getElementById('ddlFrequencyCommands'));
            addOption(document.getElementById('ddlFrequencyCommands'), '- Select -', '- Select -');
            addOption(document.getElementById('ddlFrequencyCommands'), 'Only Once', '0');
            addOption(document.getElementById('ddlFrequencyCommands'), 'Daily Once', '1');
            addOption(document.getElementById('ddlFrequencyCommands'), '3 Days Once', '2');
        }
        else {
            if (document.getElementById('ddlFrequencyCommands').options.length < 5) {
                clearDropdown(document.getElementById('ddlFrequencyCommands'));
                addOption(document.getElementById('ddlFrequencyCommands'), '- Select -', '- Select -');
                addOption(document.getElementById('ddlFrequencyCommands'), 'Only Once', '0');
                addOption(document.getElementById('ddlFrequencyCommands'), 'Daily Once', '1');
                addOption(document.getElementById('ddlFrequencyCommands'), '3 Days Once', '2');
                addOption(document.getElementById('ddlFrequencyCommands'), 'Weekly Once', '3');
            }
        }
    }
    else if (document.getElementById('chkNoEndDate').checked) {
        if (document.getElementById('ddlFrequencyCommands').options.length < 5) {
            clearDropdown(document.getElementById('ddlFrequencyCommands'));
            addOption(document.getElementById('ddlFrequencyCommands'), '- Select -', '- Select -');
            addOption(document.getElementById('ddlFrequencyCommands'), 'Only Once', '0');
            addOption(document.getElementById('ddlFrequencyCommands'), 'Daily Once', '1');
            addOption(document.getElementById('ddlFrequencyCommands'), '3 Days Once', '2');
            addOption(document.getElementById('ddlFrequencyCommands'), 'Weekly Once', '3');
        }
    }
}
function addOption(selectbox, text, value) {
    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
    selectbox.options.add(optn);
}
function clearDropdown(control) {
    for (i = control.options.length - 1; i >= 0; i--) {
        control.options.remove(i);
    }
}
function Checkdates() {
    var from = document.getElementById('txtEffectiveFrom').value;
    var to = document.getElementById('txtEffectiveTo').value;
    document.getElementById('ddlFrequencyCommands');
    if ((from != null && from != "") && (to != null && to != "")) {
    }
    else if ((from != null && from != "") && (document.getElementById('chkNoEndDate').checked)) {
    }
    else {
        document.getElementById('ddlFrequencyCommands').value = '- Select -';
        alert("Please select the EffectiveFrom & To first.");

    }
}

function Intervals() {
    var interval = document.getElementById('ddlRepType').value;
    var day = new Date().getDay == "0" ? 0 : 1;
    if (interval == "1") {
        document.getElementById('txtFromDate').value = "";
        document.getElementById('txtToDate').value = "";
        document.getElementById('txtFromDate').disabled = false;
        document.getElementById('txtToDate').disabled = false;
    }
    else if (interval == "2") {
        var val = "";
        var days = new Date().getDate() - new Date().getDay();
        var str;
        str = "";
        if (parseInt(days) < 0) {
            str = String(new Date(new Date().getFullYear(), new Date().getMonth(), 0).getDate() + "/" + new Date().getMonth() + "/" + new Date().getFullYear()).split('/');

        }
        else {
            str = String((new Date().getDate() - new Date().getDay()) + day + "/" + (new Date().getMonth() + 1) + "/" + new Date().getFullYear()).split('/');
        }

        for (var i = 0; i < str.length; i++) {
            if (str[i].length < 2) {
                val = val + "0" + str[i] + "/";
            }
            else {
                if (i == 2)
                    val = val + str[i];
                else {
                    if (i == 0)
                        if (parseInt(str[i]) < 0) {
                        val = new Date(new Date().getFullYear(), new Date().getMonth(), 0).getDate() + parseInt(str[i]) + "/" + (new Date().getMonth()) + "/" + new Date().getFullYear();
                        break;
                    }
                    val = val + str[i] + "/";
                }
            }
        }
        document.getElementById('txtFromDate').value = val;
        str = "";
        val = "";
        str = String((new Date().getDate()) + "/" + (new Date().getMonth() + 1) + "/" + new Date().getFullYear()).split('/');
        for (var i = 0; i < str.length; i++) {
            if (str[i].length < 2) {
                val = val + "0" + str[i] + "/";
            }
            else {
                if (i == 2)
                    val = val + str[i];
                else {
                    if (i == 0)
                        if (parseInt(str[i]) < 0) {
                        val = new Date(new Date().getFullYear(), new Date().getMonth(), 0).getDate() + parseInt(str[i]) + "/" + (new Date().getMonth()) + "/" + new Date().getFullYear();
                        break;
                    }
                    val = val + str[i] + "/";
                }
            }
        }
        document.getElementById('txtToDate').value = val;
        document.getElementById('txtFromDate').disabled = true;
        document.getElementById('txtToDate').disabled = true;
    }
    else if (interval == "3") {

        var d = ((new Date().getDate() + 7) - new Date().getDate());
        var val = "";
        var isNegative = 0;
        str = "";
        var str;
        str = "";
        if (parseInt(d) < 0) {
            str = String(new Date(new Date().getFullYear(), new Date().getMonth(), 0).getDate() + "/" + new Date().getMonth() + "/" + new Date().getFullYear()).split('/');

        }
        else {
            str = String((new Date().getDate() - (new Date().getDay() + 7)) + day + "/" + (new Date().getMonth() + 1) + "/" + new Date().getFullYear()).split('/');
        }
        for (var i = 0; i < str.length; i++) {
            if (str[i].length < 2) {
                val = val + "0" + str[i] + "/";
            }
            else {
                if (i == 2)
                    val = val + str[i];
                else {
                    if (i == 0)
                        if (parseInt(str[i]) < 0) {
                        val = new Date(new Date().getFullYear(), new Date().getMonth(), 0).getDate() + parseInt(str[i]) + "/" + (new Date().getMonth()) + "/" + new Date().getFullYear();
                        break;
                    }
                    val = val + str[i] + "/";
                }
            }
        }
        document.getElementById('txtFromDate').value = val;
        str = "";
        val = "";
        str = String((new Date().getDate() - new Date().getDay()) + "/" + (new Date().getMonth() + 1) + "/" + new Date().getFullYear()).split('/');

        if (str[0] < 7 && str[1] == 1) {
            var modifieddate = String(document.getElementById('txtFromDate').value).split('/');
            for (var i = 0; i < modifieddate.length; i++) {
                if (i == 0) {
                    val = val + modifieddate[i] + "/";
                }
                else if (i == 1) {
                    val = val + "12/";
                }
                else if (i == 2) {
                    val = val + (parseInt(modifieddate[i]) - 1);
                }
            }
            document.getElementById('txtFromDate').value = val;
            val = "";
        }

        for (var i = 0; i < str.length; i++) {
            if (str[i].length < 2) {
                val = val + "0" + str[i] + "/";
            }
            else {
                if (i == 2)
                    val = val + str[i];
                else {
                    if (i == 0)
                        if (parseInt(str[i]) < 0) {
                        val = new Date(new Date().getFullYear(), new Date().getMonth(), 0).getDate() + parseInt(str[i]) + "/" + (new Date().getMonth()) + "/" + new Date().getFullYear();
                        break;
                    }
                    val = val + str[i] + "/";
                }
            }
        }

        document.getElementById('txtToDate').value = val;
        document.getElementById('txtFromDate').disabled = true;
        document.getElementById('txtToDate').disabled = true;
    }
    else if (interval == "4") {
        var month = new Date().getMonth().length > 1 ? (new Date().getMonth() + 1) : "0" + (new Date().getMonth() + 1);
        document.getElementById('txtFromDate').value = "01/" + month + "/" + new Date().getFullYear();
        var d = new Date().getDate().toString().length > 1 ? new Date().getDate() : "0" + new Date().getDate();
        document.getElementById('txtToDate').value = d + "/" + month + "/" + new Date().getFullYear();
        document.getElementById('txtFromDate').disabled = true;
        document.getElementById('txtToDate').disabled = true;
    }
    else if (interval == "5") {
        var lastmonth = new Date().getMonth() == '0' ? '12' : new Date().getMonth();
        lastmonth = lastmonth.length > 1 ? lastmonth : '0' + lastmonth;
        var lastyear = new Date().getMonth() == '0' ? (parseInt(new Date().getFullYear()) - 1) : new Date().getFullYear();
        document.getElementById('txtFromDate').value = "01/" + lastmonth + "/" + lastyear;
        document.getElementById('txtToDate').value = new Date(new Date().getFullYear(), new Date().getMonth(), 0).getDate() + "/" + lastmonth + "/" + lastyear;

        document.getElementById('txtFromDate').disabled = true;
        document.getElementById('txtToDate').disabled = true;
    }
}