﻿// FORM VALIDATIONS

//Code inclueded by Ranjith for multilingual functionality
var AlertEmail = 'No Email is selected.\nDo you want to select it?';
var AlertEmailSMS = 'No Email / SMS notification is selected.\nDo you want to select it?';
var AlertEmailNotification = 'No Email notification is selected.\nDo you want to select it?';
var AlertSMSNotification = 'No SMS notification is selected.\nDo you want to select it?';

function SetAlertManageNotificationText(AlertEmailMessage, AlertEmailSMSMessgae, AlertEmailNotificationMessage, AlertSMSNotificationMessage) {
    AlertEmail = AlertEmailMessage;
    AlertEmailSMS = AlertEmailSMSMessgae;
    AlertEmailNotification = AlertEmailNotificationMessage;
    AlertSMSNotification = AlertSMSNotificationMessage;
}


var Alert_EnterGeozone = 'Please enter the Geozone Name.';
var Alert_SelectSeverity = 'Please select the Severity Level.';
var Alert_SelectDirection = 'Please select the Direction.';
var Alert_SelectCategory = 'Please select the Category.';
var controlToBeFocused;

function SetAlertMessagesManageGeozone(Alert_EnterGeozoneMessage, Alert_SelectSeverityMessgae, Alert_SelectDirectionMessage, Alert_SelectCategoryMessage) {
    Alert_EnterGeozone = Alert_EnterGeozoneMessage;
    Alert_SelectSeverity = Alert_SelectSeverityMessgae;
    Alert_SelectDirection = Alert_SelectDirectionMessage;
    Alert_SelectCategory = Alert_SelectCategoryMessage;
}
var Alert_SelectVehciletobeAssigned = 'Select vehicle(s) to be assigned.';
var Alert_SelectVehciletobeUnassigned = 'Select vehicle(s) to be unassigned.';
var Alert_SomeVehiclesExceedsGeozone = 'Some of the selected vehicle(s) exceeds maximum geozone limit.';

function SetGeozoneVehicleAssignment(Alert_SelectVehciletobeAssignedMessage, Alert_SelectVehciletobeUnassignedMessage, Alert_SomeVehiclesExceedsGeozoneMessage) {
    Alert_SelectVehciletobeAssigned = Alert_SelectVehciletobeAssignedMessage;
    Alert_SelectVehciletobeUnassigned = Alert_SelectVehciletobeUnassignedMessage;
    Alert_SomeVehiclesExceedsGeozone = Alert_SomeVehiclesExceedsGeozoneMessage;
}

var Alert_SelectTitle = 'Please select the Title.';
var Alert_FirstName = 'Please enter the First Name.';
var Alert_ValidFirstName = 'Please enter a valid First Name.';
var Alert_ValidLastName = 'Please enter a valid Last Name.';
var Alert_EnterMail = 'Please enter the Email.';
var Alert_ValidEmail = 'Please enter a valid Email Address.';
var Alert_ValidPhno = 'Please enter a valid Phone Number.';
var Alert_ValidMobile = 'Please enter a valid Mobile Number.';
var Alert_UsernameNotExist = 'User Name already exists.';
var Alert_EnterUsername = 'Please enter the User Name.';
var Alert_EnterValidUserName = 'Please enter a valid User Name.';
var Alert_EnterDisplayName = 'Please enter the Display Name.';
var Alert_EnterValidDisplayName = 'Please enter a valid Display Name.';
var Alert_ConfirmYourPwd = 'Please confirm your Password.';
var Alert_PwdAtlesat = 'Please enter the password with atleast ';
var Alert_PasswordShouldatleast = 'Password should have atleast ';
var Alert_ConfirmthePwd = 'Please confirm the Password.';
var Alert_SelectUserGroup = 'Please select a User Group.';

function SetUserManipulation(Alert_SelectTitleMessage, Alert_FirstNameMessage, Alert_ValidFirstNameMessage, Alert_ValidLastNameMessage, Alert_EnterMailMessage, Alert_ValidEmailMessage, Alert_ValidPhnoMessage, Alert_ValidMobileMessage, Alert_UsernameNotExistMessage, Alert_EnterUsernameMessage, Alert_EnterValidUserNameMessage, Alert_EnterDisplayNameMessage, Alert_EnterValidDisplayName, Alert_EnterValidDisplayNameMessage, Alert_ConfirmYourPwdMessage, Alert_PwdAtlesatMessage, Alert_PasswordShouldatleastMessage, Alert_ConfirmthePwdMessage, Alert_SelectUserGroupMessage) {
    Alert_SelectTitle = Alert_SelectTitleMessage;
    Alert_FirstName = Alert_FirstNameMessage;
    Alert_ValidFirstName = Alert_ValidFirstNameMessage;
    Alert_ValidLastName = Alert_ValidLastNameMessage;
    Alert_EnterMail = Alert_EnterMailMessage;
    Alert_ValidEmail = Alert_ValidEmailMessage;
    Alert_ValidPhno = Alert_ValidPhnoMessage;
    Alert_ValidMobile = Alert_ValidMobileMessage;
    Alert_UsernameNotExist = Alert_UsernameNotExistMessage;
    Alert_EnterUsername = Alert_EnterUsernameMessage;
    Alert_EnterValidUserName = Alert_EnterValidUserNameMessage;
    Alert_EnterDisplayName = Alert_EnterDisplayNameMessage;
    Alert_EnterValidDisplayName = Alert_EnterValidDisplayNameMessage;
    Alert_ConfirmYourPwd = Alert_ConfirmYourPwdMessage;
    Alert_PwdAtlesat = Alert_PwdAtlesatMessage;
    Alert_PasswordShouldatleast = Alert_PasswordShouldatleastMessage;
    Alert_ConfirmthePwd = Alert_ConfirmthePwdMessage;
    Alert_SelectUserGroup = Alert_SelectUserGroupMessage;

}
var Alert_EnterLandmarkName = 'Please enter the Landmark Name.';
var Alert_EnterRadius = 'Please enter the Radius.';
function SetLandmarkAlertText(Alert_EnterLandmarkNameMessgae, Alert_EnterRadiusMessage) {
    Alert_EnterLandmarkName = Alert_EnterLandmarkNameMessgae;
    Alert_EnterRadius = Alert_EnterRadiusMessage;
}

//var  Credentials you have entered are invalid.
//Please enter the Current Password.
//Please enter the New Password without spaces.
//Password should have atleast
//Please provide a different password than the old password.
//Please confirm the New Password.
//Confirm Password do not match with New Password.

/************************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 the 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 the 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 the 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 the 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 the 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;
}
/*************************************************************************/

var Alert_InvalidCredentials = "Credentials you have entered are invalid.";
var Alert_EnterCurrentPassword = "Please enter the Current Password.";
var Alert_NewPassword = "Please enter the New Password without spaces.";
var Alert_MinChar = "Password should have atleast";
var Alert_character = "characters";
var Alert_DifferentPassword = "Please provide a different password than the old password.";
var Alert_ConfirmPassWord = "Please confirm the New Password.";
var Alert_ConfirmpasswordMissMatch = "Confirm Password do not match with New Password.";

//Set Alert message.
function SetAlertMessageValidation(InvalidCredentials, EnterCurrentPassword, NewPassword, MinChar, character, DifferentPassword, ConfirmPassWord, ConfirmpasswordMissMatch) {
    Alert_InvalidCredentials = InvalidCredentials;
    Alert_EnterCurrentPassword = EnterCurrentPassword;
    Alert_NewPassword = NewPassword;
    Alert_MinChar = MinChar;
    Alert_character = character;
    Alert_DifferentPassword = DifferentPassword;
    Alert_ConfirmPassWord = ConfirmPassWord;
    Alert_ConfirmpasswordMissMatch = ConfirmpasswordMissMatch;
}

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!';
        alertMessage = Alert_InvalidCredentials;
    }

    if (oldPassword.length == 0) {
        isError = true;
        alertMessage = (alertMessage.length == 0 ? '' : alertMessage + '\n') + Alert_EnterCurrentPassword;
        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') + Alert_NewPassword;
        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') +
                      Alert_MinChar + minPasswordChar + Alert_character;
        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') +
                      Alert_DifferentPassword;
        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') +
                      Alert_ConfirmPassWord;
            if (!isError) {
                document.getElementById('txtConfirmNewPassword').focus();
            }
            isError = true;
            document.getElementById('txtConfirmNewPassword').style.backgroundColor = 'lightyellow';
        }

        else if (confirmPassword != NewPassword) {
            alertMessage = (alertMessage.length == 0 ? '' : alertMessage + '\n') +
                      Alert_ConfirmpasswordMissMatch;
            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 *********************************/

var Alert_InvalidCredential = "Credentials you have entered are invalid.";
var Alert_OldPassword = "Please provide a different password than the old password.";
var Alert_UsernameNotExist = "User Name already exists.";
var Alert_Sms = "The user is set for receiving SMS notification.\nIf the mobile number is not specified then no notification will be given.";
function SetAlertMessageReceiveServerData(InvalidCredential, OldPassword) {
    Alert_InvalidCredential = InvalidCredential;
    Alert_OldPassword = OldPassword;
}
function SetAlertUserManipulation(UsernameNotExist,sms) {
    Alert_UsernameNotExist = UsernameNotExist;
    Alert_Sms = sms;
}

//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.");
        alert(Alert_InvalidCredential);
        //Validation('Invalid ' + arg2);
    }

    else if (arg1 == "onsf") {
        //        alert('Invalid ' + arg2);
        context.value = "";
        context.focus();
        document.getElementById('txtNewPassword').style.backgroundColor = 'lightyellow';
        alert(Alert_OldPassword);
    }

    else if (arg1 == "ouf") { // User name already exists while updating user info
        //context.value = "";
        context.focus();
        document.getElementById('txtUserName').style.backgroundColor = 'lightyellow';
        alert(Alert_UsernameNotExist);
        //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(Alert_UsernameNotExist);
        //ValidateUserInformation(true, true);
    }

    else if (arg1 == "vNf") { // Vehicle Name already exists
        //context.value = "";
        context.focus();
        document.getElementById('txtVehName').style.backgroundColor = 'lightyellow';
        alert("Vehicle 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("Vehicle 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(Alert_Sms);
    }
    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);
    }
    else if (arg1 == "dGf") {  // Driver Group Name exists
        context.focus();
        ValidateDriverGroupInformation(false);
    }
    else if (arg1 == "INf") {  // Incentive Name exists
        context.focus();
        document.getElementById('txtDescription').style.backgroundColor = 'lightyellow';
        alert("Incentive (or) Allowance Name already exists.");
    }
    else if (arg1 == "rGf") {  // Route Name exists
        context.focus();
        ValidateRouteInformation(false);
    }
    else if (arg1 == "dNf") {  // Driver Name already exists
        context.focus();
        document.getElementById('txtDisPlayName').style.backgroundColor = 'lightyellow';
        alert("Display Name already exists.");
    }
    else if (arg1 == "dLf") {  // Licenses number already exists
        context.focus();
        document.getElementById('txtLicenseNo').style.backgroundColor = 'lightyellow';
        alert("License Number already exists.");
    }
    else if (arg1 == "nf") {  // News already exists
        context.focus();
        document.getElementById('txtNewsName').style.backgroundColor = 'lightyellow';
        alert("News Name already exists.");
    }
    else if (arg1 == "tf") {  // Tips already exists
        context.focus();
        document.getElementById('txtTipsName').style.backgroundColor = 'lightyellow';
        alert("Tips Name already exists.");
    }
    else if (arg1 == "ovcf") {  // Vehcicles are created already. Can't able to modify
        context.focus();
        document.getElementById('txtNoOfVehicles').style.backgroundColor = 'lightyellow';
        alert("Vehicles are already created. Can't able to modify");
        document.getElementById('txtNoOfVehicles').value = document.getElementById('hdnNoOfVehicles').value;
    }
    else if (arg1 == "stf") {  // Template already exists
        context.focus();
        document.getElementById('txtSeverityTempName').style.backgroundColor = 'lightyellow';
        alert("Severity TemplaterName already exists.");
    }
    else if (arg1 == "mMf") {  // MDTUserId already exists.
        context.focus();
        document.getElementById("tcManageMDT_tpMDTUsers_txtMDTUserId").style.backgroundColor = 'lightyellow';
        alert("MDTUserId already exists.");
    }
    else if (arg1 == "mTf") {  // Precanned message already exists.
        context.focus();
        context.style.backgroundColor = 'lightyellow';
        alert("Precanned message already exists.");
    }

}

/*******************************************************************************************/

/********************************Fleet Validations******************************************/


var Alert_Noprivilege = "You do not have the privilege to";
var Alert_UserGroup = " the default user group.";
var Alert_EditOwnUserGroup = "You cannot edit your own user group.";
var Alert_UserGroupDelete = "User Group cannot be deleted as it has been assigned to one or more user(s).";
var DeleteConfirm = "Are you sure you want to delete this entry?";

//Set Alert Message to the variables for the GetConfirmationforUG.
function SetAlertMessageGetConfirmationforUG(Noprivilege, UserGroup, EditOwnUserGroup, UserGroupDelete, Confirm) {
    Alert_Noprivilege = Noprivilege;
    Alert_UserGroup = UserGroup;
    Alert_EditOwnUserGroup = EditOwnUserGroup;
    Alert_UserGroupDelete = UserGroupDelete;
    DeleteConfirm = Confirm;
}


function GetConfirmationforUG(Mode, isOwnGroup, isDefault, assignedStatus) {
    if (isDefault == 1) {
        alert(Alert_Noprivilege + Mode + Alert_UserGroup);
        return false;
    }
    else if (Mode == 'edit' && isOwnGroup == 1) {
        alert(Alert_EditOwnUserGroup);
        return false;
    }
    else if (Mode == 'delete' && assignedStatus == 1) {
        alert(Alert_UserGroupDelete);
        return false;
    }
    else {
        if (Mode == 'delete') {
            return confirm(DeleteConfirm);
        }
        else {
            return true;
        }
    }
}

var Alert_DefaultFleet = "You do not have the privilege to delete the default fleet.";
var Alert_FleetDelete = "Fleet cannot be deleted as it has been assigned to one or more user(s) / vehicle(s).";
var Alert_Confirm = "Are you sure you want to delete this entry?";
var Alert_package = "Package cannot be deleted as it has been assigned to one or more organization(s).";
var Alert_GeoZone = "Geozone cannot be deleted as it has been assigned to one or more vehicle(s).";

//Ste the alert message to the function GetConfirmation.
function SetAlertMessageGetConfirmation(DefaultFleet, FleetDelete, Confirm, packag, GeoZone) {
    Alert_DefaultFleet = DefaultFleet;
    Alert_FleetDelete = FleetDelete;
    Alert_Confirm = Confirm;
    Alert_package = packag;
    Alert_GeoZone = GeoZone;
}

function GetConfirmation(FleetName, assignedStatus, isFleet) {
    if (isFleet == 1) {
        if (FleetName == 'True') {
            alert(Alert_DefaultFleet);
            return false;
        }
        else if (assignedStatus == 1) {
            alert(Alert_FleetDelete);
            return false;
        }
        else {
            return confirm(Alert_Confirm);
        }
    }
    else if (isFleet == 2) {
        if (FleetName == 'deletepackage' && assignedStatus == 1) {
            alert(Alert_package);
            return false;
        }
        else {
            if (FleetName == 'deletepackage') {
                return confirm(Alert_Confirm);
            }
            else {
                return true;
            }
        }
    }
    else if (isFleet == 3) {
        if (assignedStatus == 1) {
            alert(Alert_GeoZone);
            return false;
        }
        else {
            return confirm(Alert_Confirm);
        }
    }
}


var AlertFleetNameExist = "Fleet Name already exists.";
var AlertEnterFleetName = "Please enter the Fleet Name.";
var AlertValidFleetName = "Please enter a valid Fleet Name.";
var AlertDescription = "Please enter the Description.";
var AlertLengthDescription = "Length of the Description should not be greater than 250 characters.";
var AlertSeverityLevel = "Please select the Severity Level.";
var AlertDeleteEntry = "Are you sure want to delete this entry?";

//Set Alert Message.
function SetAlertMessageFleetValidation(FleetNameExist, EnterFleetName, ValidFleetName, Description, LengthDescription, SeverityLevel, ComnfirmDeleteEntry) {
    AlertFleetNameExist = FleetNameExist;
    AlertEnterFleetName = EnterFleetName;
    AlertValidFleetName = ValidFleetName;
    AlertDescription = Description;
    AlertLengthDescription = LengthDescription;
    AlertSeverityLevel = SeverityLevel;
    AlertDeleteEntry = ComnfirmDeleteEntry;
}

function DeleteEntry() {
    return confirm(AlertDeleteEntry);    
}

// 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 = AlertFleetNameExist;
        txtFleetName.style.backgroundColor = 'lightyellow';
        controlToBeFocused = txtFleetName;
    }
    else if (RemoveSpaces(txtFleetName).length == 0) {
        isError = true;
        alertMessage = AlertEnterFleetName;
        txtFleetName.style.backgroundColor = 'lightyellow';
        controlToBeFocused = txtFleetName;
    }
    else if (reFieldValidations(txtFleetName.value, "AlphaNumericWithSpace") == false) {
        isError = true;
        alertMessage = AlertValidFleetName;
        txtFleetName.style.backgroundColor = 'lightyellow';
        controlToBeFocused = txtFleetName;
    }
    else {
        txtFleetName.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtDescription).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + AlertDescription;
        txtDescription.style.backgroundColor = 'lightyellow';

        if (!isError) {
            controlToBeFocused = txtDescription
            isError = true;
        }
    }
    else if (RemoveSpaces(txtDescription).length > 250) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + AlertLengthDescription;
        txtDescription.style.backgroundColor = 'lightyellow';

        if (!isError) {
            controlToBeFocused = txtDescription
            isError = true;
        }
    }
    else {
        txtDescription.style.backgroundColor = 'white';
    }

    if (!CheckSeveritySelection('chkEmailSeverities')) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + AlertSeverityLevel;
        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;
    }
    ShowPopUp();
    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 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************************************/
var AlertSelectDeviceId = "Please select the Device Id.";
var AlertVehicleNameExist = "Vehicle Name already exists";
var AlertEnterVehicleName = "Please enter the Vehicle Name.";
var AlertVinExist = "VIN already exists.";
var AlertEnterVin = "Please enter a valid VIN.";
var AlertLicenceAlreadyExist = "License Plate Name already exists.";
var AlertEnterLicPalte = "Please enter the LIC Plate.";
var AlertValidLicPlate = "Please enter a valid LIC Plate.";
var AlertValidYearManufacture = "Please enter a valid Year of Manufacturing.";
var AlertSelectSeverityLevel = "Please select the Severity Level.";
var AlertVehicleType = "Please select the Vehicle Type.";
var AlertValidColor = "Please enter a valid Color.";
var AlertFuelCapacity = "Fuel Tank Capacity cannot be 0.";
var AlertDeleteConfirm = "do you want to really delete this vehicle.";

//Set alert message to the variables
function SetAlertMessage(SelectDeviceId, VehicleNameExist, EnterVehicleName, VinExist, EnterVin, LicenceAlreadyExist, EnterLicPalte, ValidYearManufacture, SelectSeverityLevel, VehicleType, ValidColor, FuelCapacity, ValidLicPlate, DeleteConf) {

    AlertSelectDeviceId = SelectDeviceId;
    AlertVehicleNameExist = VehicleNameExist;
    AlertEnterVehicleName = EnterVehicleName;
    AlertVinExist = VinExist;
    AlertEnterVin = EnterVin;
    AlertLicenceAlreadyExist = LicenceAlreadyExist;
    AlertEnterLicPalte = EnterLicPalte;
    AlertValidYearManufacture = ValidYearManufacture;
    AlertSelectSeverityLevel = SelectSeverityLevel;
    AlertVehicleType = VehicleType;
    AlertValidColor = ValidColor;
    AlertFuelCapacity = FuelCapacity;
    AlertValidLicPlate = ValidLicPlate;
    AlertDeleteConfirm = DeleteConf;
}

function Delete() {
    return confirm(AlertDeleteConfirm);
}


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 txtLICPlate = document.getElementById('txtLICPlate');
    //var ddlTimezone = document.getElementById('ddlTimezone');
    //var chkSeverities = document.getElementById('chkSeverities');
    //Commented on 20-Jul-10 for removing mandatory of the following fields
    var txtVIN = document.getElementById('txtVIN');
    //    var ddlVehMake = document.getElementById('ddlVehMake');
    //    var ddlModel = document.getElementById('ddlModel');
    var txtYear = document.getElementById('txtYear');
    var txtColor = document.getElementById('txtColor');
    var txtFuelTankCapacity = document.getElementById('txtFuelTankCapacity');

    if (ddlBoxId != null) {
        if (!CheckIsSelected(ddlBoxId.value)) {
            alertMessage = AlertSelectDeviceId;
            isError = true;
            controlToBeFocused = ddlBoxId;
            ddlBoxId.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlBoxId.style.backgroundColor = 'white';
        }
    }

    if (!isVehicleNameValid) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + AlertVehicleNameExist;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtVehName;
        }
        txtVehName.style.backgroundColor = 'lightyellow';
    }
    else if (RemoveSpaces(txtVehName).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + AlertEnterVehicleName;
        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 Vehicle Display Name.';
    //        if (!isError) {
    //            isError = true;
    //            controlToBeFocused = txtDisplayName;
    //        }
    //        txtDisplayName.style.backgroundColor = 'lightyellow';
    //    }
    //    else {
    //        txtDisplayName.style.backgroundColor = 'white';
    //    }

    if (!isVINValid) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + AlertVinExist;
        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' : '') + AlertEnterVin;
        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 Vehicle Make.';
    if (!isError) {
    controlToBeFocused = ddlVehMake;
    isError = true;
    }
    ddlVehMake.style.backgroundColor = 'lightyellow';
    }
    else {
    ddlVehMake.style.backgroundColor = 'white';
    }*/

    if (!isLicensePlateValid) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + AlertLicenceAlreadyExist;
        if (!isError) {
            controlToBeFocused = txtLICPlate;
            isError = true;
        }
        txtLICPlate.style.backgroundColor = 'lightyellow';
    }
    else if (RemoveSpaces(txtLICPlate).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + AlertEnterLicPalte;
        if (!isError) {
            controlToBeFocused = txtLICPlate;
            isError = true;
        }
        txtLICPlate.style.backgroundColor = 'lightyellow';
    }
    else if (reFieldValidations(txtLICPlate.value, "AlphaNumericWithSpace") == false) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + AlertValidLicPlate;
        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 Vehicle 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 a valid Year of Manufacturing.';
    if (!isError) {
    controlToBeFocused = txtYear;
    isError = true;
    }
    txtYear.style.backgroundColor = 'lightyellow';
    }
    else {
    txtYear.style.backgroundColor = 'white';
    }*/
    if (RemoveSpaces(txtYear).length > 0) {
        if (!(txtYear.value >= 1950 && txtYear.value <= dtCurrentDate.getFullYear())) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + AlertValidYearManufacture;
            if (!isError) {
                controlToBeFocused = txtYear;
                isError = true;
            }
            txtYear.style.backgroundColor = 'lightyellow';
        }
        else {
            txtYear.style.backgroundColor = 'white';
        }
    }

    if (!CheckSeveritySelection('chkSeverities')) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + AlertSelectSeverityLevel;
        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' : '') + AlertVehicleType;
        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' : '') + AlertValidColor;
        if (!isError) {
            controlToBeFocused = txtColor;
            isError = true;
        }
        txtColor.style.backgroundColor = 'lightyellow';
    }
    else {
        txtColor.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtFuelTankCapacity).length > 0) {
        if (txtFuelTankCapacity.value == 0) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + AlertFuelCapacity;
            if (!isError) {
                controlToBeFocused = txtFuelTankCapacity;
                isError = true;
            }
            txtFuelTankCapacity.style.backgroundColor = 'lightyellow';
        }
        else {
            txtFuelTankCapacity.style.backgroundColor = 'white';
        }
    }
    else {
        txtFuelTankCapacity.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 should 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') + 'Please provide a different password than the old password.';
        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("Please select the User Group.");
        return false;
    }
    else {
        return true;
    }
}

var Alert_UserForMassUpdate = "Select the user(s) for the Mass Update.";
var Alert_Noprivilege = "You have no privilege to change the Status & User Group for Administrator.";
var Alert_OwnStatus = "You cannot change your own Status & User Group.";
var Alert_SelectOptionFormassUpdate = "Select any of the options for the Mass Update.";
var Alert_DeleteMessage = "Do you want to really delete this user?";

//Set Alert Message
function SetAlertMessageMassUpdateValidation(UserForMassUpdate, Noprivilege, OwnStatus, SelectOptionFormassUpdate, DeleteMsg) {
    Alert_UserForMassUpdate = UserForMassUpdate;
    Alert_Noprivilege = Noprivilege;
    Alert_OwnStatus = OwnStatus;
    Alert_SelectOptionFormassUpdate = SelectOptionFormassUpdate;
    Alert_DeleteMessage = DeleteMsg;
}

function DeleteConf() {
    return confirm(Alert_DeleteMessage);
}

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 = Alert_UserForMassUpdate;
        isError = true;
    }

    if (adminUserID != loggedinUserID && adminUserID != 0 && Array.contains(arrHiddenField, adminUserID.toString())) {
        alertMessage = Alert_Noprivilege;
        isError = true;
    }

    if (loggedinUserID != 0 && Array.contains(arrHiddenField, loggedinUserID.toString())) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + Alert_OwnStatus;

        if (!isError) {
            isError = true;
        }
    }

    if (statusdropdown.value == 2 && lockeddropdown.value == 2 && usergroupdropdown.value == '- Select -') {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + Alert_SelectOptionFormassUpdate;
        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 = Alert_SelectTitle;
        titleField.style.backgroundColor = 'lightyellow';
    }
    else {
        titleField.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(firstName).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + Alert_FirstName;
        if (!isError) {
            controlToBeFocused = firstName;
        }
        firstName.style.backgroundColor = 'lightyellow';
        isError = true;
    }
    else if (reFieldValidations(firstName.value, "CharacterWithSpace") == false) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + Alert_ValidFirstName;
        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' : '') + Alert_ValidLastName;
        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' : '') + Alert_EnterMail;
        if (!isError) {
            controlToBeFocused = emailField;
        }
        isError = true;
        emailField.style.backgroundColor = 'lightyellow';
    }
    else if (!validateEmail(emailField.value)) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + Alert_ValidEmail;
        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' : '') + Alert_ValidPhno;
            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' : '') + Alert_ValidMobile;
            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' : '') + Alert_UsernameNotExist;
        if (!isError) {
            controlToBeFocused = userNameField;
        }
        isError = true;
        userNameField.style.backgroundColor = 'lightyellow';
    }
    else if (RemoveSpaces(userNameField).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + Alert_EnterUsername;
        if (!isError) {
            controlToBeFocused = userNameField;
        }
        isError = true;
        userNameField.style.backgroundColor = 'lightyellow';
    }
    else if (reFieldValidations(userNameField.value, "AlphaNumericWithSpaceHypDotUnderScore") == false) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + Alert_EnterValidUserName;
        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' : '') + Alert_EnterDisplayName;
        if (!isError) {
            controlToBeFocused = displayNameField;
        }
        isError = true;
        displayNameField.style.backgroundColor = 'lightyellow';
    }
    else if (reFieldValidations(displayNameField.value, "AlphaNumericWithSpaceHypDotUnderScore") == false) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + Alert_EnterValidDisplayName;
        if (!isError) {
            controlToBeFocused = displayNameField;
        }
        isError = true;
        displayNameField.style.backgroundColor = 'lightyellow';
    }
    else {
        displayNameField.style.backgroundColor = 'white';
    }
    if (pwdField != null) {
        var conPass = new String(confirmpwdField.value);
        var pass = new String(pwdField.value);

        if (conPass.localeCompare(pass) != 0) {
            alertMessage += (alertMessage.length == 0 ? '' : '\n') + Alert_ConfirmYourPwd;
            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') + Alert_PwdAtlesat + minPasswordChar + ' characters.';
                if (!isError) {
                    controlToBeFocused = pwdField;
                }
                pwdField.style.backgroundColor = 'lightyellow';
            }
            else if (RemoveSpaces(pwdField).length < minPasswordChar) {
                alertMessage += (alertMessage.length == 0 ? '' : '\n') + Alert_PasswordShouldatleast + 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') + Alert_ConfirmthePwd;
                if (!isError) {
                    controlToBeFocused = confirmpwdField
                    isError = true;
                }
                confirmpwdField.style.backgroundColor = 'lightyellow';
            }

            else {
                confirmpwdField.style.backgroundColor = 'white';
            }

        }

    }

    if (!CheckIsSelected(userGroupField.value)) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + Alert_SelectUserGroup;
        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

var Alert_EffectiveTillDate = 'Please select the Effective Till Date.';
var Alert_MailingUser = 'Please select the user(s) for mailing';
var Alert_SelectMonth = 'Please enter the Day of Month.';
var Alert_DateBetween = 'Please enter the date between 1 to 31.';
var Alert_ValidDateRange = 'Please select a valid date range.';
var Alert_ValidTimeRange = 'Please select a valid time range.';
var Alert_SelectedDateRange = 'The selected date range is not valid for the';
var Alert_Weekly = 'weekly';
var Alert_Monthly = 'monthly';
var Alert_Scheduling = 'scheduling.';
var Alert_SomeMonthsFewerthan = 'Some months have fewer than';
var Alert_lastDayMonth = 'days. For these months, the report generation will fall on the last day of the month.';
var Alert_DayNotMatching = 'Report generation day is not matching with the end date. So, the final report will be generated on';
var Alert_SureWantContinue = 'Are you sure you want to continue';
var Alert_EffectiveFromDate = 'Please select the Effective From Date.';
function SetReportAlerts(Alert_EffectiveTillDateMsg, Alert_MailingUserMsg, Alert_SelectMonthMsg, Alert_DateBetweenMsg, Alert_ValidDateRangeMsg, Alert_ValidTimeRangeMsg, Alert_SelectedDateRangeMsg, Alert_WeeklyMsg, Alert_MonthlyMsg, Alert_SchedulingMsg, Alert_SomeMonthsFewerthanMsg, Alert_lastDayMonthMsg, Alert_DayNotMatchingMsg, Alert_SureWantContinueMsg, Alert_EffectiveFromDateMsg) {
    Alert_EffectiveTillDate=Alert_EffectiveTillDateMsg;
    Alert_MailingUser = Alert_MailingUserMsg;
    Alert_SelectMonth = Alert_SelectMonthMsg;
    Alert_DateBetween = Alert_DateBetweenMsg;
    Alert_ValidDateRange = Alert_ValidDateRangeMsg;
    Alert_ValidTimeRange = Alert_ValidTimeRangeMsg;
    Alert_SelectedDateRange = Alert_SelectedDateRangeMsg;
    Alert_Weekly = Alert_WeeklyMsg;
    Alert_Monthly = Alert_MonthlyMsg;
    Alert_Scheduling = Alert_SchedulingMsg;
    Alert_SomeMonthsFewerthan = Alert_SomeMonthsFewerthanMsg;
    Alert_lastDayMonth = Alert_lastDayMonthMsg;
    Alert_DayNotMatching = Alert_DayNotMatchingMsg;
    Alert_SureWantContinue = Alert_SureWantContinueMsg;
    Alert_EffectiveFromDate = Alert_EffectiveFromDateMsg;
} 
 
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 = Alert_EffectiveFromDate;
            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' : '') + Alert_EffectiveTillDate;
                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' : '') + Alert_SelectMonth;
                    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' : '') + Alert_DateBetween;
                        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' : '') + Alert_MailingUser;
            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' : '') + Alert_ValidDateRange;
            }
            else if (validity == 2) {
                isError = true;
                alertMessage += (alertMessage.length > 0 ? '\n' : '') + Alert_ValidTimeRange;
            }
            else if (validity == 3) {
                isError = true;
                alertMessage += (alertMessage.length > 0 ? '\n' : '') + Alert_SelectedDateRange + ' ' +
                (frequency.value == 1 ? Alert_Weekly : Alert_Monthly) + ' '+ Alert_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(Alert_SomeMonthsFewerthan + " " + monthly_Day + " "+ Alert_lastDayMonth);
        }
    }
    if (frequency != null) {
        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(Alert_DayNotMatching + effectiveToField.value +
            '.\n' + Alert_SureWantContinue +'?');
            }
        }
    }

    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;
}

/************************************************************/


var Alert_UserToBeAssigned = "Select the user(s) to be assigned to the fleet.";
var Alert_UserToBeUnAssigned = "Select the user(s) to be unassigned from the fleet.";
var Alert_NoPrivilegeToAssign = "You have no privilege to assign the Administrator.";
var Alert_AssignYourself = "You cannot assign yourself to a fleet.";
var Alert_NoPrivilegeToUnAssign = "You have no privilege to unassign the Administrator.";
var Alert_UnAssignYourself = "You cannot unassign yourself from a fleet.";

//set Alert Message
function SetAlertMessageFleetUserAssignment(UserToBeAssigned, UserToBeUnAssigned, NoPrivilegeToAssign, AssignYourself, NoPrivilegeToUnAssign, UnAssignYourself) {
    Alert_UserToBeAssigned = UserToBeAssigned;
    Alert_UserToBeUnAssigned = UserToBeUnAssigned;
    Alert_NoPrivilegeToAssign = NoPrivilegeToAssign;
    Alert_AssignYourself = AssignYourself;
    Alert_NoPrivilegeToUnAssign = NoPrivilegeToUnAssign;
    Alert_UnAssignYourself = UnAssignYourself;
}

function FleetUserAssignment(Type, hiddenFieldName, adminUserID, loggedinUserID) {
    var hiddenField = document.getElementById(hiddenFieldName);
    var arrHiddenField = hiddenField.value.split(",");

    var alertMessage = '';
    var isError = false;

    alertMessage = (Type == "Assign") ? Alert_UserToBeAssigned : Alert_UserToBeUnAssigned;

    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 = Alert_NoPrivilegeToAssign;
            isError = true;
        }

        if (loggedinUserID != 0 && Array.contains(arrHiddenField, loggedinUserID.toString())) {
            alertMessage += (alertMessage.length == 0 ? '' : '\n') + Alert_AssignYourself;

            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 = Alert_NoPrivilegeToUnAssign;
            isError = true;
        }

        if (((adminUserID == loggedinUserID && document.getElementById('ddlFleetUser').selectedIndex == 0) || adminUserID != loggedinUserID) && loggedinUserID != 0 && Array.contains(arrHiddenField, loggedinUserID.toString())) {
            alertMessage += (alertMessage.length == 0 ? '' : '\n') + Alert_UnAssignYourself;

            if (!isError) {
                isError = true;
            }
        }

        if (isError) {
            alert(alertMessage);
            return false;
        }
        else {
            return true;
        }
    }
}

/************************************************************/

var Alert_SelectUserToAssign = "Select the user(s) to be assigned to the user group.";
var Alert_SelectuserToUnAssign = "Select user(s) to be unassigned from the user group.";
var Alert_noPriviledgeToAssignAdmin = "You have no privilege to assign the Administrator.";
var Alert_AssignYourSelf = "You cannot assign yourself to a user group.";
var Alert_AlreadyAssigned = "Some of the user(s) are already assigned to a user group. Do u want to re-assign them?";
var Alert_NoPrivilege = "You have no privilege to unassign the Administrator.";
var Alert_UnAssignYourSelf = "You cannot unassign yourself from a user group.";
var Alert_RestrictFromLogin = "Unassigning the user(s) from the group will restrict them from logging in.\nDo you want to continue?";

function SetAlertMessageUserGroupAssignmentValidation(SelectUserToAssign, SelectuserToUnAssign, noPriviledgeToAssignAdmin, AssignYourSelf, AlreadyAssigned, NoPrivilege, UnAssignYourSelf, RestrictFromLogin) {
    Alert_SelectUserToAssign = SelectUserToAssign;
    Alert_SelectuserToUnAssign = SelectuserToUnAssign;
    Alert_noPriviledgeToAssignAdmin = noPriviledgeToAssignAdmin;
    Alert_AssignYourSelf = AssignYourSelf;
    Alert_AlreadyAssigned = AlreadyAssigned;
    Alert_NoPrivilege = NoPrivilege;
    Alert_UnAssignYourSelf = UnAssignYourSelf;
    Alert_RestrictFromLogin = RestrictFromLogin;
}

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") ? Alert_SelectUserToAssign : Alert_SelectuserToUnAssign;

    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 = Alert_noPriviledgeToAssignAdmin;
            isError = true;
        }

        if (loggedinUserID != 0 && Array.contains(arrHiddenField, loggedinUserID.toString())) {
            alertMessage += (alertMessage.length == 0 ? '' : '\n') + Alert_AssignYourSelf;

            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(Alert_AlreadyAssigned);

                if (IsConfirm == true) {
                    return true;
                }
                else {
                    return false;
                }
            }
            else {
                return true;
            }
        }
    }
    else {

        if (adminUserID != loggedinUserID && adminUserID != 0 && Array.contains(arrHiddenField, adminUserID.toString())) {
            alertMessage = Alert_NoPrivilege;
            isError = true;
        }

        if (loggedinUserID != 0 && Array.contains(arrHiddenField, loggedinUserID.toString())) {
            alertMessage += (alertMessage.length == 0 ? '' : '\n') + Alert_UnAssignYourSelf;

            if (!isError) {
                isError = true;
            }
        }

        if (isError) {
            alert(alertMessage);
            return false;
        }
        else {
            var IsConfirmed = confirm(Alert_RestrictFromLogin);
            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 = Alert_EnterGeozone;
        isError = true;
        geozoneNameField.focus();
        geozoneNameField.style.backgroundColor = 'lightyellow';
    }
    else {
        geozoneNameField.style.backgroundColor = 'white';
    }

    if (severityField.value == '- Select Severity -') {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + Alert_SelectSeverity;
        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') + Alert_SelectDirection;
        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') + Alert_SelectCategory;
        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 a 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 the modules and operations for the package.';
        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 a 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;
}


var AlertSelectpackage = "Please select the Package.";
var AlertEnterPurchasedOn = "Please enter the Purchased On";
var AlertExpiryOnDate = "Please enter the Expires On date.";
var AlertValidExpiryOn = "Please enter a valid Expires On date.";

var AlertOrganizationName = "Please enter the Organization Name.";
var AlertValidOrgName = "Please enter a valid Organization Name.";
var AlertDisplayName = "Please enter the Display Name.";
var AlertValidDisplayName = "Please enter a valid Display Name.";
var AlertEnterOrganizationCode = "Please enter the Organization Code.";
var AlertEnterDescription = "Please enter the Description (max. 250 characters).";
var AlertEnterAddress = "Please enter the Address.";
var AlertValidEmailID = "Please enter a valid Email ID.";
var AlertValidPhoneNo = "Please enter a valid Phone Number.";
var AlertValidmobileNo = "Please enter a valid Mobile Number.";
var AlertSelectCountry = "Please select the Country.";
var AlertValidWebAddress = "Please enter a valid Website Address.";
var AlertContactperson = "Please enter the Contact Person Name.";
var AlertValidContactperson = "Please enter a valid Contact Person Name.";
var AlertDesignation = "Please enter the Designation of the contact person.";
var AlertValidDesignation = "Please enter a valid Designation of the contact person.";
var AlertMailIdContactperson = "Please enter the Email ID for the contact person.";
var AlertValidMailIdContactperson = "Please enter a valid Email ID for the contact person.";
var AlertValidContactPh = "Please enter a valid Contact Phone Number.";
var AlertEmailTries = "Please enter the No of Email Tries between 1 to 5.";
var AlertSMSTries = "Please enter the No of SMS Tries between 1 to 3.";
var AlertNoOfFleets = "Please enter the No. of Fleets between 1-100.";
var AlertNoOfVehicles = "No. of Vehicles cannot be zero";
var AlertNoOfUsers = "No. of Users cannot be zero.";
var AlertLockOption = "Please select any one of the lock option.";
var AlertDeleteOrganization = "do you want to really delete this organization.";

//Set Alert Mesage to the variables for ValidateOrgPackageAssignment function and OrganizationValidation function.
function SetAlertMessageOrgPackageAssignment(Selectpackage, EnterPurchasedOn, ExpiryOnDate
, ValidExpiryOn, OrganizationName, ValidOrgName, DisplayName, ValidDisplayName, EnterOrganizationCode
, EnterDescription, EnterAddress, ValidEmailID, ValidPhoneNo, ValidmobileNo, SelectCountry, ValidWebAddress
, Contactperson, ValidContactperson, Designation, ValidDesignation, MailIdContactperson, ValidMailIdContactperson
, ValidContactPh, EmailTries, SMSTries, NoOfFleets, NoOfVehicles, NoOfUsers, LockOption, DeletingOrganization) {

    AlertSelectpackage = Selectpackage;
    AlertEnterPurchasedOn = EnterPurchasedOn;
    AlertExpiryOnDate = ExpiryOnDate;
    AlertValidExpiryOn = ValidExpiryOn;

    AlertOrganizationName = OrganizationName;
    AlertValidOrgName = ValidOrgName;
    AlertDisplayName = DisplayName;
    AlertValidDisplayName = ValidDisplayName;
    AlertEnterOrganizationCode = EnterOrganizationCode;
    AlertEnterDescription = EnterDescription;
    AlertEnterAddress = EnterAddress;
    AlertValidEmailID = ValidEmailID;
    AlertValidPhoneNo = ValidPhoneNo;
    AlertValidmobileNo = ValidmobileNo;
    AlertSelectCountry = SelectCountry;
    AlertValidWebAddress = ValidWebAddress;
    AlertContactperson = Contactperson;
    AlertValidContactperson = ValidContactperson;
    AlertDesignation = Designation;
    AlertValidDesignation = ValidDesignation;
    AlertMailIdContactperson = MailIdContactperson;
    AlertValidMailIdContactperson = ValidMailIdContactperson;
    AlertValidContactPh = ValidContactPh;
    AlertEmailTries = EmailTries;
    AlertSMSTries = SMSTries;
    AlertNoOfFleets = NoOfFleets;
    AlertNoOfVehicles = NoOfVehicles;
    AlertNoOfUsers = NoOfUsers;
    AlertLockOption = LockOption;
    AlertDeleteOrganization = DeletingOrganization;
}
//Delete organization in Organization management.
function DeleteOrganization() {
    return confirm(AlertDeleteOrganization);
}

function ValidateOrgPackageAssignment() {
    var Package = document.getElementById('ddlPackage');
    var txtPurchasedOn = document.getElementById('txtPurchasedOn');
    var txtExpiresOn = document.getElementById('txtExpiresOn');

    var isError = false;
    var alertMessage = '';
    var controlToBeFocused;

    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 a 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 = AlertOrganizationName;
        txtOrgName.style.backgroundColor = 'lightyellow';
        controlToBeFocused = txtOrgName;
    }
    else if (reFieldValidations(txtOrgName.value, "AlphaNumericWithSpaceHypDotUnderScore") == false) {
        if (!isError) {
            controlToBeFocused = txtOrgName;
            isError = true;
        }
        alertMessage = AlertValidOrgName;
        txtOrgName.style.backgroundColor = 'lightyellow';
    }
    else {
        txtOrgName.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtOrgDisplayName).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + AlertDisplayName;
        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' : '') + AlertValidDisplayName;
        txtOrgDisplayName.style.backgroundColor = 'lightyellow';
    }
    else {
        txtOrgDisplayName.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtOrgCode).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + AlertEnterOrganizationCode;
        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' : '') + AlertValidDisplayName;
        txtOrgCode.style.backgroundColor = 'lightyellow';
    }
    else {
        txtOrgCode.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtDescription).length > 250) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + AlertEnterDescription;
        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' : '') + AlertEnterAddress;
        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' : '') + AlertValidEmailID;
            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' : '') + AlertValidPhoneNo;
            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' : '') + AlertValidmobileNo;
            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' : '') + AlertSelectCountry;

        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' : '') + AlertValidWebAddress;

            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' : '') + AlertContactperson;
        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' : '') + AlertValidContactperson;
        txtContactPersonName.style.backgroundColor = 'lightyellow';
    }
    else {
        txtContactPersonName.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtDesignation).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + AlertDesignation;
        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' : '') + AlertValidDesignation;
        txtDesignation.style.backgroundColor = 'lightyellow';
    }
    else {
        txtDesignation.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(txtContactEmail).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + AlertMailIdContactperson;
        txtContactEmail.style.backgroundColor = 'lightyellow';

        if (!isError) {
            controlToBeFocused = txtContactEmail;
            isError = true;
        }
    }
    else if (!validateEmail(txtContactEmail.value)) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + AlertValidMailIdContactperson;
        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' : '') + AlertValidContactPh;
            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' : '') + AlertEmailTries;
            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' : '') + AlertSMSTries;
            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' : '') + AlertNoOfFleets;
            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' : '') + AlertNoOfVehicles;
            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' : '') + AlertNoOfUsers;
            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' : '') + AlertLockOption;
            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 First Name.';
        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 a 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 a 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 Email ID.';
        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 a valid Contact Mobile Number 1.';
            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 a valid Contact Mobile Number 2.';
            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 Joining.';
        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}[0-9])([\)])?[-])|(\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) {
    // Checking if the Hyphen (-) is at the beginning
    if (event.keyCode == 45 && e.value == '') {
        return false;
    }

    // Checking if the Plus (+) is in the middle
    if (event.keyCode == 43 && e.value != '') {
        return false;
    }

    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;
}

//***********************************************************************************************************

var Alert_UserGroupExist = "User Group Name already exists.";
var Alert_EnterUserGroupName = "Please enter the User Group Name.";
var Alert_SelectModuleOperation = "Please select the modules and operations for the user group.";

function SetAlertValidateUserGroupInformation(UserGroupExist, EnterUserGroupName, SelectModuleOperation) {
    Alert_UserGroupExist = UserGroupExist;
    Alert_EnterUserGroupName = EnterUserGroupName;
    Alert_SelectModuleOperation = SelectModuleOperation;
}
//Set Alert Message
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 = Alert_UserGroupExist;
        userGroupName.style.backgroundColor = 'lightyellow';
        controlToBeFocused = userGroupName;
    }

    if (RemoveSpaces(userGroupName).length == 0) {
        isError = true;
        controlToBeFocused = userGroupName;
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + Alert_EnterUserGroupName;
        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' : '') + Alert_SelectModuleOperation;
        isError = true;
    }

    if (isError) {
        alert(alertMessage);
        return false;
    }
    else {
        return true;
    }
}

function ValidateDriverGroupInformation(isDriverGroupNameValid) {
    var driverGroupName = document.getElementById('txtDriverGroupName');
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (!isDriverGroupNameValid) {
        isError = true;
        alertMessage = 'Driver Group Name already exists.';
        driverGroupName.style.backgroundColor = 'lightyellow';
        controlToBeFocused = driverGroupName;
    }

    if (RemoveSpaces(driverGroupName).length == 0) {
        isError = true;
        controlToBeFocused = driverGroupName;
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the Driver Group Name.';
        driverGroupName.style.backgroundColor = 'lightyellow';
    }
    else {
        driverGroupName.style.backgroundColor = 'white';
    }

    if (isError) {
        controlToBeFocused.focus();
    }

    if (isError) {
        alert(alertMessage);
        return false;
    }
    else {
        return true;
    }
}

function ValidateRouteInformation(isRouteNameValid) {
    var routeName = document.getElementById('txtRouteName');

    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (!isRouteNameValid) {
        isError = true;
        alertMessage = 'Route Name already exists.';
        routeName.style.backgroundColor = 'lightyellow';
        controlToBeFocused = routeName;
    }

    if (RemoveSpaces(routeName).length == 0) {
        isError = true;
        controlToBeFocused = routeName;
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the Route Name.';
        routeName.style.backgroundColor = 'lightyellow';
    }
    else {
        routeName.style.backgroundColor = 'white';
    }

    if (isError) {
        controlToBeFocused.focus();
    }

    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 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';
}

function setMaintenancePlanDetails(isSet) {
    var isMainPlanDetailsSet = document.getElementById('hdnIsMainPlanDetailsSet');
    isMainPlanDetailsSet.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;
    }
}

// Maintenance Plan
function ValidateMaintenancePlan1() {
    var planName = document.getElementById('txtPlanName');
    var overdueReminderInterval = document.getElementById('txtOverdueReminderInterval');
    var selectedServiceIds = document.getElementById('hdnSelectedServiceIds');
    var isNotificationSet = document.getElementById('hdnIsNotificationSet');
    var isMainPlanDetailsSet = document.getElementById('hdnIsMainPlanDetailsSet');
    var emailUsers = document.getElementById('hdnEmailUsers');
    var smsUsers = document.getElementById('hdnSMSUsers');
    var assignedEmailUsers = document.getElementById('hdnAssignedEmailUsers');
    var assignedSmsUsers = document.getElementById('hdnAssignedSMSUsers');

    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 (RemoveSpaces(overdueReminderInterval).length == 0) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please enter the Overdue Reminder Interval.';
        if (!isError) {
            controlToBeFocused = overdueReminderInterval;
            isError = true;
        }
        overdueReminderInterval.style.backgroundColor = 'lightyellow';
    }
    else {
        overdueReminderInterval.style.backgroundColor = 'white';
    }

    if (isMainPlanDetailsSet.value == 'N') {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please enter the maintenance plan details in the Maintenance Plan Details Tab.';
        if (!isError) {
            isError = true;
        }
    }

    if (selectedServiceIds.value == "") {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please select the service details from the Service Details Tab.';
        if (!isError) {
            isError = true;
        }
    }

    if (emailUsers.value == "" && smsUsers.value == "" && assignedEmailUsers.value == "" && assignedSmsUsers.value == "") {
        isError = true;
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please click Manage Notification to select the Email Users.';
    }

    if (isError) {
        if (controlToBeFocused != null) {
            controlToBeFocused.focus();
        }
        alert(alertMessage);
        return false;
    }
    else {
        return true;
    }
}

// Maintenance Plan Details
function ValidateMaintenancePlanDetails1(serviceInterval, notification1, notification2, notification3) {
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (RemoveSpaces(serviceInterval).length == 0 && document.getElementById('chkIsRecurring').checked) {
        isError = true;
        alertMessage = 'Please enter the Service Interval.';
        serviceInterval.value = '';
        serviceInterval.style.backgroundColor = 'lightyellow';
        controlToBeFocused = serviceInterval;
    }
    else {
        if (RemoveSpaces(serviceInterval) == 0 && document.getElementById('chkIsRecurring').checked) {
            isError = true;
            alertMessage = 'Service Interval cannot be Zero.';
            serviceInterval.style.backgroundColor = 'lightyellow';
            controlToBeFocused = serviceInterval;
        }
        else {
            serviceInterval.style.backgroundColor = 'white';
        }
    }

    if (notification2.value != 0 && notification2.value <= notification1.value) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Reminder 2 should be greater than Reminder 1.';
        if (!isError) {
            controlToBeFocused = notification2;
            isError = true;
        }
        notification2.style.backgroundColor = 'lightyellow';
    }
    else {
        notification2.style.backgroundColor = 'white';
    }

    if (notification2.value == 0 && notification3.value != 0) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please select the Reminder 2.';
        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') + 'Reminder 3 should be greater than Reminder 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') + 'Reminder 3 should be greater than Reminder 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 ValidateUnregisteredUser(isUserNameExists) {
    var firstNameField = document.getElementById('tcMaintenancePlan_tpNotifications_txtFirstName');
    if (firstNameField == null) {
        firstNameField = document.getElementById('txtFirstName');
    }
    var userNameField = document.getElementById('tcMaintenancePlan_tpNotifications_txtUsername');
    if (userNameField == null) {
        userNameField = document.getElementById('txtUsername');
    }
    var displayNameField = document.getElementById('tcMaintenancePlan_tpNotifications_txtDispName');
    if (displayNameField == null) {
        displayNameField = document.getElementById('txtDispName');
    }
    var emailField = document.getElementById('tcMaintenancePlan_tpNotifications_txtEmail');
    if (emailField == null) {
        emailField = document.getElementById('txtEmail');
    }
    var mobileNo = document.getElementById('tcMaintenancePlan_tpNotifications_txtMobile');
    if (mobileNo == null) {
        mobileNo = document.getElementById('txtMobile');
    }

    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (RemoveSpaces(firstNameField).length == 0) {
        alertMessage = 'Please enter the First Name.';
        controlToBeFocused = firstNameField;
        isError = true;
        firstNameField.style.backgroundColor = 'lightyellow';
    }
    else {
        firstNameField.style.backgroundColor = 'white';
    }

    if (isUserNameExists) {
        alertMessage = '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 a 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 a valid Display Name.';
        if (!isError) {
            controlToBeFocused = displayNameField;
        }
        isError = true;
        displayNameField.style.backgroundColor = 'lightyellow';
    }
    else {
        displayNameField.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 (mobileNo.value.length > 0) {
        if (mobileFormat(mobileNo.value) == false) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter a valid Mobile Number.';
            mobileNo.style.backgroundColor = 'lightyellow';

            if (!isError) {
                controlToBeFocused = mobileNo;
                isError = true;
            }
        }
        else {
            mobileNo.style.backgroundColor = 'white';
        }
    }
    else {
        mobileNo.style.backgroundColor = 'white';
    }

    if (isError) {
        alert(alertMessage);
        controlToBeFocused.focus();
        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() {
    var status = document.getElementById('hdnOprType').value;
    var executionOnDate = document.getElementById('txtExecutedOn');
    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(executionOnDate).length == 0) {
            isError = true;
            alertMessage = 'Please enter the Execution On.';
            executionOnDate.style.backgroundColor = 'lightyellow';
            controlToBeFocused = executionOnDate;
        }
        else {
            executionOnDate.style.backgroundColor = 'white';
        }

        if (document.getElementById("hdnServiced") != null && document.getElementById("hdnServiced").value == '') {
            var isAlert = false;

            if (document.getElementById("hdnCloseServices").value == "0") {
                isAlert = true;
            }
            else if (document.getElementById("hdnCloseServices").value != "0" && !document.getElementById("chkIsCompleted").checked) {
                isAlert = true;
            }
            else {
                isAlert = false;
            }

            if (isAlert) {
                alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please select the maintenance services.';
                if (!isError) {
                    controlToBeFocused = document.getElementById("gvServiceDetails");
                    isError = true;
                }
            }
        }
    }
    else if (status == "4") {
        if (dueOnDate != null) {
            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(dueOnDate)

                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;
}

// Adhoc Services
function ValidationAdhocServices() {
    var executedOn = document.getElementById('txtExecutedOn');
    var selectedServices = document.getElementById('hdnServiced');
    var comments = document.getElementById('txtComments');

    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (RemoveSpaces(executedOn).length == 0) {
        isError = true;
        alertMessage = 'Please enter the Execution On.';
        executedOn.style.backgroundColor = 'lightyellow';
        controlToBeFocused = executedOn;
    }
    else {
        executedOn.style.backgroundColor = 'white';
    }

    if (selectedServices != null && selectedServices.value == '') {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please select the maintenance services.';
        if (!isError) {
            controlToBeFocused = document.getElementById("gvServiceDetails");
            isError = true;
        }
    }

    if (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;
    }
}


// Manual Entry
function ValidationManualEntry() {

    var fromDate = document.getElementById('txtStartDate');
    var toDate = document.getElementById('txtEndDate');
    var comments = document.getElementById('txtComments');
    var engineHours = document.getElementById('txtEngineHours');
    var distanceTravelled = document.getElementById('txtDistanceTravelled');
    var vehicle = document.getElementById('ddlVehicle');
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (document.getElementById("ddlVehicle").value == "- Select -") {
        alertMessage = 'Please select the vehicle.';
        isError = true;
        document.getElementById("ddlVehicle").focus();
        vehicle.style.backgroundColor = 'lightyellow';
        controlToBeFocused = vehicle;
    }
    else {
        vehicle.style.backgroundColor = 'white';
    }

    if ((fromDate.value != "" && fromDate.value != null) && (toDate.value != "" && toDate.value != null)) {

        var FromdateStr = String(document.getElementById("txtStartDate").value);
        var TodateStr = String(document.getElementById("txtEndDate").value);
        var months = 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec';
        var month = String(months).split(',');
        var date = String(FromdateStr).split('-');
        for (var i = 0; i < month.length; i++) {
            if (date[1] == month[i]) {
                FromdateStr = new Date(date[2], i, date[0]);
                break;
            }
        }
        var date = String(TodateStr).split('-');
        for (var i = 0; i < month.length; i++) {
            if (date[1] == month[i]) {
                TodateStr = new Date(date[2], i, date[0]);
                break;
            }
        }

        if (FromdateStr > TodateStr) {

            alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please select To Date greater than From Date.';
            if (!isError) {
                document.getElementById("txtStartDate").value = "";
                isError = true;
                controlToBeFocused = toDate;
            }
        }
    }
    if (RemoveSpaces(fromDate).length == 0) {

        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please enter the From Date.';
        if (!isError) {
            isError = true;
            controlToBeFocused = fromDate;
        }

        fromDate.style.backgroundColor = 'lightyellow';
    }
    else {
        fromDate.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(toDate).length == 0) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please enter the To Date.';
        if (!isError) {
            isError = true;
            controlToBeFocused = toDate;
        }
        toDate.style.backgroundColor = 'lightyellow';
    }
    else {
        toDate.style.backgroundColor = 'white';
    }

    if (engineHours.value.length == 0) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please enter the Engine Hours.';
        if (!isError) {
            isError = true;
            controlToBeFocused = engineHours;
        }
        engineHours.style.backgroundColor = 'lightyellow';
    }
    else {
        engineHours.style.backgroundColor = 'white';
    }
    if (distanceTravelled.value.length == 0) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please enter the Distance Travelled.';
        if (!isError) {
            isError = true;
            controlToBeFocused = distanceTravelled;
        }

        distanceTravelled.style.backgroundColor = 'lightyellow';
    }
    else {
        distanceTravelled.style.backgroundColor = 'white';
    }
    if (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;
    }
}

//Fuel Entry Search

function ValidationFuelEntrySearch() {

    var fromDate = document.getElementById('txtStartDate');
    var toDate = document.getElementById('txtEndDate');
    var isError = false;
    var check = "";
    var controlToBeFocused;
    var alertMessage = '';


    if ((fromDate.value != "" && fromDate.value != null) && (toDate.value != "" && toDate.value != null)) {

        var FromdateStr = String(document.getElementById("txtStartDate").value);
        var TodateStr = String(document.getElementById("txtEndDate").value);
        var months = 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec';
        var month = String(months).split(',');
        var date = String(FromdateStr).split('-');
        for (var i = 0; i < month.length; i++) {
            if (date[1] == month[i]) {
                FromdateStr = new Date(date[2], i, date[0]);
                break;
            }
        }
        var date = String(TodateStr).split('-');
        for (var i = 0; i < month.length; i++) {
            if (date[1] == month[i]) {
                TodateStr = new Date(date[2], i, date[0]);
                break;
            }
        }

        if (FromdateStr > TodateStr) {

            alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please select To Date greater than From Date.';
            if (!isError) {
                document.getElementById("txtEndDate").value = "";
                check = 'false';
                isError = true;
                controlToBeFocused = toDate;
            }
        }
    }
    if (RemoveSpaces(fromDate).length == 0) {

        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please enter the From Date.';
        if (!isError) {
            isError = true;
            controlToBeFocused = fromDate;
        }

        fromDate.style.backgroundColor = 'lightyellow';
    }
    else {
        fromDate.style.backgroundColor = 'white';
    }

    if ((RemoveSpaces(toDate).length == 0) && (check.length == 0)) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please enter the To Date.';
        if (!isError) {
            isError = true;
            controlToBeFocused = toDate;
        }
        toDate.style.backgroundColor = 'lightyellow';
    }
    else {
        toDate.style.backgroundColor = 'white';
    }

    if (isError) {
        controlToBeFocused.focus();
        alert(alertMessage);
        return false;
    }
    else {
        return true;
    }
}


// Fuel Entry
function ValidationFuelEntry() {

    var fromDate = document.getElementById('txtStartDate');
    var toDate = document.getElementById('txtEndDate');
    var comments = document.getElementById('txtComments');
    var Fuel = document.getElementById('txtFuel');
    var FuelCost = document.getElementById('txtFuelCost');
    var vehicle = document.getElementById('ddlVehicle');
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (document.getElementById("ddlVehicle").value == "- Select -") {
        alertMessage = 'Please select the vehicle.';
        isError = true;
        document.getElementById("ddlVehicle").focus();
        vehicle.style.backgroundColor = 'lightyellow';
        controlToBeFocused = vehicle;
    }
    else {
        vehicle.style.backgroundColor = 'white';
    }

    if ((fromDate.value != "" && fromDate.value != null) && (toDate.value != "" && toDate.value != null)) {

        var FromdateStr = String(document.getElementById("txtStartDate").value);
        var TodateStr = String(document.getElementById("txtEndDate").value);
        var months = 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec';
        var month = String(months).split(',');
        var date = String(FromdateStr).split('-');
        for (var i = 0; i < month.length; i++) {
            if (date[1] == month[i]) {
                FromdateStr = new Date(date[2], i, date[0]);
                break;
            }
        }
        var date = String(TodateStr).split('-');
        for (var i = 0; i < month.length; i++) {
            if (date[1] == month[i]) {
                TodateStr = new Date(date[2], i, date[0]);
                break;
            }
        }

        if (FromdateStr > TodateStr) {

            alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please select To Date greater than From Date.';
            if (!isError) {
                document.getElementById("txtEndDate").value = "";
                isError = true;
                controlToBeFocused = toDate;
            }
        }
    }
    if (RemoveSpaces(fromDate).length == 0) {

        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please enter the From Date.';
        if (!isError) {
            isError = true;
            controlToBeFocused = fromDate;
        }

        fromDate.style.backgroundColor = 'lightyellow';
    }
    else {
        fromDate.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(toDate).length == 0) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please enter the To Date.';
        if (!isError) {
            isError = true;
            controlToBeFocused = toDate;
        }
        toDate.style.backgroundColor = 'lightyellow';
    }
    else {
        toDate.style.backgroundColor = 'white';
    }

    if (Fuel.value.length == 0) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please enter the Fuel.';
        if (!isError) {
            isError = true;
            controlToBeFocused = Fuel;
        }
        Fuel.style.backgroundColor = 'lightyellow';
    }
    else {
        Fuel.style.backgroundColor = 'white';
    }

    //    if (FuelCost.value.length == 0) {
    //        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please enter the Fuel Cost.';
    //        if (!isError) {
    //        isError = true;
    //        controlToBeFocused = FuelCost;
    //        }
    //        FuelCost.style.backgroundColor = 'lightyellow';            
    //    }
    //     else {
    //        FuelCost.style.backgroundColor = 'white';
    //    } 

    if (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;
    }
}




var Alert_EntertMakeName = "Please enter the Make Name.";
var Alert_Confirmation = "Do you want to really delete this Record?";
function setAlertValidationVehicleMakeEntry(EnterMakeName, DeleteConf) {
    Alert_EntertMakeName = EnterMakeName;
    Alert_Confirmation = DeleteConf;
}

function setAlertValidationDeleteLandmarkConfirmation(DeleteConf) {
    Alert_Confirmation = DeleteConf;
}


//Delete Confirmation
function DeleteConfirmation() {
    return confirm(Alert_Confirmation);
}

// Vehicle Make
function ValidationVehicleMakeEntry() {


    var makeName = document.getElementById('txtMakeName');

    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (RemoveSpaces(makeName).length == 0) {

        alertMessage += (alertMessage.length == 0 ? '' : '\n') + Alert_EntertMakeName;
        if (!isError) {
            isError = true;
            controlToBeFocused = makeName;
        }

        makeName.style.backgroundColor = 'lightyellow';
    }
    else {
        makeName.style.backgroundColor = 'white';
    }

    if (isError) {
        controlToBeFocused.focus();
        alert(alertMessage);
        return false;
    }
    else {
        ShowPopup();
        return true;
    }
}

var Alert_SelectMakeName = "Please select the Make Name.";
var Alert_EntertModelName = "Please enter the Model Name.";

function setAlertValidationVehicleModelEntry(SelectMakeName, SelectModelName) {
    Alert_SelectMakeName = SelectMakeName;
    Alert_EntertModelName = SelectModelName;
}

// Vehicle Model
function ValidationVehicleModelEntry() {

    var makeName = document.getElementById('ddlMakeName');
    var vehicleType = document.getElementById('ddlVehicleType');
    var modelName = document.getElementById('txtModelName');

    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (document.getElementById("ddlMakeName").value == "Select") {
        alertMessage = Alert_SelectMakeName;
        isError = true;
        document.getElementById("ddlMakeName").focus();
        makeName.style.backgroundColor = 'lightyellow';
        controlToBeFocused = makeName;
    }
    else {
        makeName.style.backgroundColor = 'white';
    }


    if (RemoveSpaces(modelName).length == 0) {

        alertMessage += (alertMessage.length == 0 ? '' : '\n') + Alert_EntertModelName;
        if (!isError) {
            isError = true;
            controlToBeFocused = modelName;
        }

        modelName.style.backgroundColor = 'lightyellow';
    }
    else {
        modelName.style.backgroundColor = 'white';
    }

    if (isError) {
        controlToBeFocused.focus();
        alert(alertMessage);
        return false;
    }
    else {
        ShowPopUp();
        return true;
    }
}

//Set Alert message to the variable.
var AlertGreaterThanFromDate = "Please select To date greater then From date..!";
function ScheduleDateValidation(GreaterThanFromDate) {
    AlertGreaterThanFromDate = GreaterThanFromDate;
}

function CheckGreaterThanFromdate() {
    if ((document.getElementById("txtFromDate").value != "" && document.getElementById("txtFromDate").value != null) && (document.getElementById("txtToDate").value != "" && document.getElementById("txtToDate").value != null)) {
        var FromdateStr = new Array(3);
        FromdateStr = String(document.getElementById("txtFromDate").value).split('/');
        var day = FromdateStr[0];
        var month = FromdateStr[1];
        var year = FromdateStr[2];
        var fromDate = new Date(month + "/" + day + "/" + year);
        if (fromDate > sender._selectedDate) {
            alert("Please select To date greater then From date..!");
            document.getElementById("txtToDate").value = "";
            document.getElementById("txtToDate").focus();
        }
    }
}

// Vehicle Service History
function ValidateServiceHistory() {
    var vehicle = document.getElementById('ddlVehicle');
    var startDate = document.getElementById('txtHistoryStartDate');
    var endDate = document.getElementById('txtHistoryEndDate');

    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) {
    }
    else {
        if (RemoveSpaces(startDate).length == 0 && RemoveSpaces(endDate).length != 0) {
            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';
                }
            }
        }
        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 (document.getElementById('cblShowHideOptions') != 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.innerHTML = '';
        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 = Alert_EnterLandmarkName;
        txtLocationName.focus();
        txtLocationName.style.backgroundColor = 'lightyellow';
    }
    else {
        txtLocationName.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtRadius).length == 0) {
        errorMessage = (isError ? errorMessage + '\n' : '') + Alert_EnterRadius;
        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("Please select a 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(Alert_SomeVehiclesExceedsGeozone);
            return false;
        }
    }
    else {
        return false;
    }
    return true;
}

var Alert_UserAssign = "Select user(s) to be assigned.";
var Alert_UserUnAssign = "Select user(s) to be unassigned.";

//Set Alert Message.
function SetAlertMessageSelectionForManipulation(UserAssign, UserUnAssign) {
    Alert_UserAssign = UserAssign;
    Alert_UserUnAssign = UserUnAssign;
}

function CheckSelectionForManipulation(type) {

    var alertMessage = '';
    var gridControlName
    var isError = false;
    if (type == 1) { // Un Assigned Vehicles
        gridControlName = gvUnAssignedVehicles;
        hdnSelectedIDList = 'hdnVehicleIdsToBeAssinged';
        alertMessage = Alert_SelectVehciletobeAssigned;
    }
    else if (type == 2) { // Assigned Vehicles
        gridControlName = gvAssignedVehicles;
        hdnSelectedIDList = Alert_SelectVehciletobeUnassigned;
        alertMessage = '';
    }
    else if (type == 3) { // Unassinged Users
        gridControlName = gvUnAssignedUsers;
        hdnSelectedIDList = 'hdnUsersToBeAssigned';
        alertMessage = Alert_UserAssign;
    }
    else if (type == 4) {// Assigned Users
        gridControlName = gvAssignedUsers;
        hdnSelectedIDList = 'hdnUsersToBeUnassinged';
        alertMessage = Alert_UserUnAssign;
    }
    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(AlertEmail)) {
                    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(AlertEmailSMS)) {
                        return false;
                    }
                    else {
                        return true;
                    }
                }
                else if (isEmailVisible) {
                    if (confirm(AlertEmailNotification)) {
                        return false;
                    }
                    else {
                        return true;
                    }
                }
                else if (isSMSVisible) {
                    if (confirm(AlertSMSNotification)) {
                        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).';
        }
        //document.getElementById('ctl05$ddlMassUpdateStatus').selectedIndex
    }

    if (isError) {
        if (alertMessage != '') {
            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) {
        if (!control.disabled) {
            control.focus();
        }
    }
}


function ValidateNewsInfo(isNewsNameValid) {
    var newsName = document.getElementById('txtNewsName');
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (!isNewsNameValid) {
        isError = true;
        alertMessage = 'News Name already exists.';
        newsName.style.backgroundColor = 'lightyellow';
        controlToBeFocused = newsName;
    }

    if (RemoveSpaces(newsName).length == 0) {
        isError = true;
        controlToBeFocused = newsName;
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the News Name.';
        newsName.style.backgroundColor = 'lightyellow';
    }
    else {
        newsName.style.backgroundColor = 'white';
    }

    if (isError) {
        controlToBeFocused.focus();
    }

    if (isError) {
        alert(alertMessage);
        return false;
    }
    else {
        return true;
    }
}


function ValidateTipsInfo(isTipsNameValid) {
    var tipsName = document.getElementById('txtTipsName');
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (!isTipsNameValid) {
        isError = true;
        alertMessage = 'Tips Name already exists.';
        tipsName.style.backgroundColor = 'lightyellow';
        controlToBeFocused = tipsName;
    }

    if (RemoveSpaces(tipsName).length == 0) {
        isError = true;
        controlToBeFocused = tipsName;
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please enter the Tips Name.';
        tipsName.style.backgroundColor = 'lightyellow';
    }
    else {
        tipsName.style.backgroundColor = 'white';
    }

    if (isError) {
        controlToBeFocused.focus();
    }

    if (isError) {
        alert(alertMessage);
        return false;
    }
    else {
        return true;
    }
}

//Alert variables.
var AlertSeverityTemplateName = "Please enter the Severity Template Name.";
var AlertSeverityTemplateCreation = "Please Select Sensor(s) for Severity Template Creation.";
var AlertDeleteConfirm = "do you want to really delete this Severity Template";

//Assign alert content to the variables.
function setAlertMessage(SeverityTemplateName, SeverityTemplateCreation, DeleteConfirm) {
    AlertSeverityTemplateName = SeverityTemplateName;
    AlertSeverityTemplateCreation = SeverityTemplateCreation;
    AlertDeleteConfirm = DeleteConfirm;
}

function ConfirmDelete() {
    return confirm(AlertDeleteConfirm)
}

function SeverityTemplateValidation() {
    var txtSeverityTempName = document.getElementById("txtSeverityTempName");
    var hdnSensorIds = document.getElementById("hdnSelectedSensorUnAssignIds");
    var hdnOutputIds = document.getElementById("hdnSelectedOutputUnAssignIds");
    var isError = false;
    var errorMessage = '';
    if (RemoveSpaces(txtSeverityTempName).length == 0) {
        isError = true;
        errorMessage = AlertSeverityTemplateName;
        txtSeverityTempName.focus();
        txtSeverityTempName.style.backgroundColor = 'lightyellow';
    }
    else {
        txtSeverityTempName.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(hdnSensorIds).length == 0) {
        alert(AlertSeverityTemplateCreation);
        return false;
    }
    controlToBeFocused = txtSeverityTempName;
    //    if (RemoveSpaces(hdnOutputIds).length == 0) {
    //        alert('Please Select Output for Severity Template Creation.');
    //        return false;
    //    }     


    if (isError) {
        alert(errorMessage);
        controlToBeFocused.focus();
        return false;
    }
    return true;
}


var AlertNoOfdevice = "Please enter the No of Devices to be created.";
var AlertFirWareCategory = "Please select the Firmware Category.";
var AlertFirWareVersion = "Please select the Firmware Version.";
var AlertProtocoltype = "Please select the Protocol Type.";
var AlertCommunicationMode = "Please select the Communication Mode.";
var AlertSeverityTemplate = "Please select the Severity Template.";

//Set Alert message for MessageBulkDeviceValidationin organization management
function SetAlertMessageBulkDeviceValidation(NoOfdevice, FirWareCategory, FirWareVersion, Protocoltype, CommunicationMode, SeverityTemplate) {
    AlertNoOfdevice = NoOfdevice;
    AlertFirWareCategory = FirWareCategory;
    AlertFirWareVersion = FirWareVersion;
    AlertProtocoltype = Protocoltype;
    AlertCommunicationMode = CommunicationMode;
    AlertSeverityTemplate = SeverityTemplate;
}

function BulkDeviceValidation() {
    var txtNoOfDevices = document.getElementById("txtNoOfDevices");
    var FirmwareCategory = document.getElementById('ddlFirmwareCategory');
    var FirmwareVersion = document.getElementById('ddlFirmwareVersion');
    var BoxProtocolType = document.getElementById('ddlBoxProtocolType');
    var CommMode = document.getElementById('ddlCommMode');
    var severityTemplate = document.getElementById('ddlSeverityTemplate');

    var isError = false;
    var alertMessage = '';
    var controlToBeFocused;

    if (RemoveSpaces(txtNoOfDevices).length == 0 || eval(txtNoOfDevices.value) == 0) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + AlertNoOfdevice;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtNoOfDevices;
        }
        txtNoOfDevices.style.backgroundColor = 'lightyellow';
    }
    else {
        txtNoOfDevices.style.backgroundColor = 'white';
    }

    if (!CheckIsSelected(FirmwareCategory.value)) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + AlertFirWareCategory;
        if (!isError) {
            controlToBeFocused = FirmwareCategory;
            isError = true;
        }
        FirmwareCategory.style.backgroundColor = 'lightyellow';
    }
    else {
        FirmwareVersion.style.backgroundColor = 'white';
    }

    if (!CheckIsSelected(FirmwareVersion.value)) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + AlertFirWareVersion;
        if (!isError) {
            controlToBeFocused = FirmwareVersion;
            isError = true;
        }
        FirmwareVersion.style.backgroundColor = 'lightyellow';
    }
    else {
        FirmwareVersion.style.backgroundColor = 'white';
    }

    if (!CheckIsSelected(BoxProtocolType.value)) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + AlertProtocoltype;
        if (!isError) {
            controlToBeFocused = BoxProtocolType;
            isError = true;
        }
        BoxProtocolType.style.backgroundColor = 'lightyellow';
    }
    else {
        BoxProtocolType.style.backgroundColor = 'white';
    }

    if (!CheckIsSelected(CommMode.value)) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + AlertCommunicationMode;
        if (!isError) {
            controlToBeFocused = CommMode;
            isError = true;
        }
        CommMode.style.backgroundColor = 'lightyellow';
    }
    else {
        CommMode.style.backgroundColor = 'white';
    }

    if (!CheckIsSelected(severityTemplate.value)) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + AlertSeverityTemplate;
        if (!isError) {
            controlToBeFocused = severityTemplate;
            isError = true;
        }
        severityTemplate.style.backgroundColor = 'lightyellow';
    }
    else {
        severityTemplate.style.backgroundColor = 'white';
    }

    if (isError) {
        alert(alertMessage);
        controlToBeFocused.focus();
        return false;
    }
    return true;
}

/*****************************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;
    }
}


var AlertCommandsVehicleName = "Please select the Vehicle Name.";
var AlertScheduleDelete = "Are you sure you want to delete this schedule?";

// Set Alert message to the variables.
function SetAlertMessageSchedulingOfCommands(CommandsVehicleName, DeleteConfirm) {
    AlertCommandsVehicleName = CommandsVehicleName;
    AlertScheduleDelete = DeleteConfirm;
}

function ConfirmScheduleDelete() {
    return confirm(AlertScheduleDelete);
}

function ValidateSchedulingOfCommands(IsCmdPage) {
    var ddlVehicle = document.getElementById('ddlVehicle');
    var ddlExecutionOn = document.getElementById('ddlExecutionOn');
    var txtEffectiveFrom = document.getElementById('txtEffectiveFrom');
    var txtEffectiveTo = document.getElementById('txtEffectiveTo');
    var chkNoEndDate = document.getElementById('chkNoEndDate');
    var ddlFrequency = document.getElementById('ddlFrequencyCommands');
    var ddlNoOfTries = document.getElementById('ddlNoOfTries');
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (IsCmdPage == false) {
        if (!CheckIsSelected(ddlVehicle.value)) {
            alertMessage += (alertMessage.length > 0 ? '\n' : '') + AlertCommandsVehicleName;
            if (!isError) {
                isError = true;
                controlToBeFocused = ddlVehicle;
            }
            ddlVehicle.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlVehicle.style.backgroundColor = 'white';
        }
    }
    else {
        document.getElementById('IsScheduleCmds').value = true;
    }
    //    if (!CheckIsSelected(ddlExecutionOn.value)) {
    //        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select the Execution Type.';
    //        if (!isError) {
    //            isError = true;
    //            controlToBeFocused = ddlExecutionOn;
    //        }
    //        ddlExecutionOn.style.backgroundColor = 'lightyellow';
    //    }
    //    else {
    //        ddlExecutionOn.style.backgroundColor = 'white';
    //    }


    //    if (RemoveSpaces(txtEffectiveFrom.value).length == 0) {
    //        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select the Effective FromDate.';
    //        if (!isError) {
    //            isError = true;
    //            controlToBeFocused = txtEffectiveFrom;
    //        }
    //        txtEffectiveFrom.style.backgroundColor = 'lightyellow';
    //    }
    //    else {
    //        txtEffectiveFrom.style.backgroundColor = 'white';
    //    }

    //    if ((RemoveSpaces(txtEffectiveTo.value).length == 0) && (!chkNoEndDate.checked)) {
    //        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select the Effective ToDate.';
    //        if (!isError) {
    //            isError = true;
    //            controlToBeFocused = txtEffectiveTo;
    //        }
    //        txtEffectiveTo.style.backgroundColor = 'lightyellow';
    //    }
    //    else {
    //        txtEffectiveTo.style.backgroundColor = 'white';
    //    }


    //    if (!CheckIsSelected(ddlFrequency.value)) {
    //        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select the Frequency Level.';
    //        if (!isError) {
    //            isError = true;
    //            controlToBeFocused = ddlFrequency;
    //        }
    //        ddlFrequency.style.backgroundColor = 'lightyellow';
    //    }
    //    else {
    //        ddlFrequency.style.backgroundColor = 'white';
    //    }


    //    if (!CheckIsSelected(ddlNoOfTries.value)) {
    //        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Please select the No.ofRetries.';
    //        if (!isError) {
    //            isError = true;
    //            controlToBeFocused = ddlNoOfTries;
    //        }
    //        ddlNoOfTries.style.backgroundColor = 'lightyellow';
    //    }
    //    else {
    //        ddlNoOfTries.style.backgroundColor = 'white';
    //    }

    if (isError) {
        alert(alertMessage);
        controlToBeFocused.focus();
        return false;
    }
    else {
        ShowPopUp();
        return true;
    }

}

function ShowHideToDate() {
    var chkNoEndDate = document.getElementById('chkNoEndDate');
    var txtEffectiveTo = document.getElementById('txtEffectiveTo');
    if (chkNoEndDate.checked) {
        txtEffectiveTo.value = '';
        txtEffectiveTo.disabled = true;
    }
    else {
        txtEffectiveTo.disabled = false;
    }
}



function CheckVehicles() {
    var ddlVehicle = document.getElementById('ddlVehicle');
    var isError = false;
    var alertMessage = '';

    if (!CheckIsSelected(ddlVehicle.value)) {
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + AlertCommandsVehicleName;
        if (!isError) {
            isError = true;
            controlToBeFocused = ddlVehicle;
        }
        ddlVehicle.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlVehicle.style.backgroundColor = 'white';
    }

    if (isError) {
        alert(alertMessage);
        controlToBeFocused.focus();
        return false;
    }
    else {
        return true;
    }
}

function UpdateCommand(val) {
    opener.document.getElementById('lblCommandName').innerHTML = val;
    //    __doPostBack(opener.document.getElementById('lblCommandName'), "");
}

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 CheckWeeklySchedule(isSchedule) {
    //    if (isSchedule == true) {
    //        clearDropdown(document.getElementById('ddlFrequency'));
    //        addOption(document.getElementById('ddlFrequency'), 'Weekly', '1');
    //    }
    //    else {
    //        clearDropdown(document.getElementById('ddlFrequency'));
    //        addOption(document.getElementById('ddlFrequency'), 'Daily', '0');
    //        addOption(document.getElementById('ddlFrequency'), 'Weekly', '1');
    //        addOption(document.getElementById('ddlFrequency'), 'Monthly', '2');
    //    }
}
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.removeChild(control.options[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() >= 10 ? (new Date().getMonth() + 1) : "0" + (new Date().getMonth() + 1);
        document.getElementById('txtFromDate').value = "01/" + month + "/" + new Date().getFullYear();
        var d = new Date().getDate() >= 10 ? 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 >= 10 ? 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;
    }
}
