
// 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 Devices(s) to be assigned.';
var Alert_SelectVehciletobeUnassigned = 'Select Devices(s) to be unassigned.';
var Alert_SomeVehiclesExceedsGeozone = 'Some of the selected Devices(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;
    }


    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 ? '</br>' : '') + 'Please enter the Password.';
        //  password.style.backgroundColor = 'lightyellow';
        if (!isError) {
            errorField = password;
        }
        isError = true;
    }

    //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 ? '</br>' : '') + 'Please enter the Organization Code.';
    //    //  orgCode.style.backgroundColor = 'lightyellow';
    //    if (!isError) {
    //        errorField = orgCode;
    //    }
    //    isError = true;
    //}


    if (isError) {
        errorField.focus();
        TrinetraCustomAlerts(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;
    }


    //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 ? '</br>' : '') + 'Please enter the Organization Code.';
    //    // orgCode.style.backgroundColor = 'lightyellow';
    //    if (!isError) {
    //        errorField = orgCode;
    //    }
    //    isError = true;
    //}

    if (isError) {
        errorField.focus();
        TrinetraCustomAlerts(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 + '</br>') + 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 + '</br>') + 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 + '</br>') +
                      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 + '</br>') +
                      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 + '</br>') +
                      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 + '</br>') +
                      Alert_ConfirmpasswordMissMatch;
            if (!isError) {
                document.getElementById('txtConfirmNewPassword').focus();
            }
            isError = true;
            document.getElementById('txtConfirmNewPassword').style.backgroundColor = 'lightyellow';
        }
    }
    if (isError) {
        TrinetraCustomAlerts(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.</br>If 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
    var txtv = RemoveSpaces(txt.value);
    if (txtv != "")
        CallServer(txtval, txt)
    //    else
    //        TrinetraCustomAlerts(AlertEnterVehicleName); return false;
}

//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

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

    else if (arg1 == "onsf") {
        //        TrinetraCustomAlerts('Invalid ' + arg2);
        context.value = "";
        context.focus();
        document.getElementById('txtNewPassword').style.backgroundColor = 'lightyellow';
        TrinetraCustomAlerts(Alert_OldPassword);
    }

    else if (arg1 == "ouf") { // User name already exists while updating user info
        //context.value = "";
        context.focus();
        document.getElementById('txtUserName').style.backgroundColor = 'lightyellow';
        TrinetraCustomAlerts(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';
        TrinetraCustomAlerts(Alert_UsernameNotExist);
        //ValidateUserInformation(true, true);
    }

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

    }
    else if (arg1 == "sDf") { // Vehicle Display Name already exists      
        context.focus();
        document.getElementById('txtDisplayName').style.backgroundColor = 'lightyellow';
        TrinetraCustomAlerts("Sensor Display Name already exists.");
    }
    else if (arg1 == "vIf") { // VIN already exists
        //context.value = "";
        context.focus();
        document.getElementById('txtVIN').style.backgroundColor = 'lightyellow';
        TrinetraCustomAlerts("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';
        TrinetraCustomAlerts("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';
        TrinetraCustomAlerts("Device 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();
        TrinetraCustomAlerts('Category Name already exists.');
    }
    else if (arg1 == "mp") { //Sms notifications is set to this mobile no.
        TrinetraCustomAlerts(Alert_Sms);
    }
    else if (arg1 == "GNf") { //Geozone Name Already Exists
        context.value = "";
        context.focus();
        TrinetraCustomAlerts('Geozone Name already exists.');
    }
    else if (arg1 == "LNf") { //Landmark Name Already Exists
        context.value = "";
        context.focus();
        TrinetraCustomAlerts('Location Name already exists.');
    }
    else if (arg1 == "LCNf") { //Landmark Category Name Already Exists
        context.value = "";
        context.focus();
        TrinetraCustomAlerts('Category Name already exists.');
    }
    else if (arg1 == "mSNf") {  // Maintenance Service Name exists
        context.value = "";
        context.focus();
        TrinetraCustomAlerts('Maintenance Service Name already exists.');
    }
    else if (arg1 == "sCNf") {  // Maintenance Service Category Name exists
        context.value = "";
        context.focus();
        TrinetraCustomAlerts('Service Package Name already exists.');
    }
    else if (arg1 == "mPNf") { // Maintenance Plan Name Already Exists
        context.value = "";
        context.focus();
        TrinetraCustomAlerts('Maintenance Plan Name already exists.');
    }
    else if (arg1 == "ocf") { // Organization Code exists
        context.value = "";
        context.focus();
        TrinetraCustomAlerts('Organization Code already exists.');
    }
    else if (arg1 == "odf") { // Organization Display Name exists
        context.value = "";
        context.focus();
        TrinetraCustomAlerts('Display Name already exists.');
    } else if (arg1 == "ovf") {  // Organization VAT Number exists
        context.value = "";
        context.focus();
        TrinetraCustomAlerts('VAT Number already exists.');
    }
    else if (arg1 == "onf") {  // Organization Name exists
        context.value = "";
        context.focus();
        TrinetraCustomAlerts('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';
        TrinetraCustomAlerts("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';
        TrinetraCustomAlerts("Display Name already exists.");
    }
    else if (arg1 == "dLf") {  // Licenses number already exists
        context.focus();
        document.getElementById('txtLicenseNo').style.backgroundColor = 'lightyellow';
        TrinetraCustomAlerts("License Number already exists.");
    }
    else if (arg1 == "nf") {  // News already exists
        context.focus();
        document.getElementById('txtNewsName').style.backgroundColor = 'lightyellow';
        TrinetraCustomAlerts("News Name already exists.");
    }
    else if (arg1 == "tf") {  // Tips already exists
        context.focus();
        document.getElementById('txtTipsName').style.backgroundColor = 'lightyellow';
        TrinetraCustomAlerts("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';
        TrinetraCustomAlerts("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';
        TrinetraCustomAlerts("Severity TemplaterName already exists.");
    }
    else if (arg1 == "mMf") {  // MDTUserId already exists.
        context.focus();
        document.getElementById("tcManageMDT_tpMDTUsers_txtMDTUserId").style.backgroundColor = 'lightyellow';
        TrinetraCustomAlerts("MDTUserId already exists.");
    }
    else if (arg1 == "mTf") {  // Precanned message already exists.
        context.focus();
        context.style.backgroundColor = 'lightyellow';
        TrinetraCustomAlerts("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, UniqueID) {
    if (isDefault == 1) {
        TrinetraCustomAlerts(Alert_Noprivilege + Mode + Alert_UserGroup);
        return false;
    }
    else if (Mode == 'edit' && isOwnGroup == 1) {
        TrinetraCustomAlerts(Alert_EditOwnUserGroup);
        return false;
    }
    else if (Mode == 'delete' && assignedStatus == 1) {
        TrinetraCustomAlerts(Alert_UserGroupDelete);
        return false;
    }
    else {
        if (Mode == 'delete') {
            //return confirm(DeleteConfirm);
            TrinetraConfirm(UniqueID, DeleteConfirm);
            return false;

        }
        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) / Devices(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 Devices(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, UniqueID) {
    if (isFleet == 1) {
        if (FleetName == 'True') {
            TrinetraCustomAlerts(Alert_DefaultFleet);
            return false;
        }
        else if (assignedStatus == 1) {
            TrinetraCustomAlerts(Alert_FleetDelete);
            return false;
        }
        else {
            //return confirm(Alert_Confirm);
            TrinetraConfirm(UniqueID, Alert_Confirm);
            return false;
        }
    }
    else if (isFleet == 2) {
        if (FleetName == 'deletepackage' && assignedStatus == 1) {
            TrinetraCustomAlerts(Alert_package);
            return false;
        }
        else {
            if (FleetName == 'deletepackage') {
                //  return confirm(Alert_Confirm);
                TrinetraConfirm(UniqueID, Alert_Confirm);
            }
            else {
                return true;
            }
        }
    }
    else if (isFleet == 3) {
        if (assignedStatus == 1) {
            TrinetraCustomAlerts(Alert_GeoZone);
            return false;
        }
        else {
            //return confirm(Alert_Confirm);
            TrinetraConfirm(UniqueID, 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?";
var AlertEnterPowerplantRating = "Please enter the Powerplant Rating.";
var AlertEnterHVRRating = "Please enter the Rating of HVR Equipment.";


//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 txtPowerPlantRating = document.getElementById("txtPowerPlantRating");
    // var txtHVREquipRating = document.getElementById("txtHVREquipRating");
    // 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 ? '</br>' : '') + AlertDescription;
        txtDescription.style.backgroundColor = 'lightyellow';

        if (!isError) {
            controlToBeFocused = txtDescription
            isError = true;
        }
    }
    else if (RemoveSpaces(txtDescription).length > 250) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertLengthDescription;
        txtDescription.style.backgroundColor = 'lightyellow';

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

    //if (RemoveSpaces(txtPowerPlantRating).length == 0) {
    //    isError = true;
    //    alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterPowerplantRating;
    //    txtPowerPlantRating.style.backgroundColor = 'lightyellow';
    //    controlToBeFocused = txtPowerPlantRating;
    //}
    //else {
    //    txtPowerPlantRating.style.backgroundColor = 'white';
    //}

    //if (RemoveSpaces(txtHVREquipRating).length == 0) {
    //    isError = true;
    //    alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterHVRRating;
    //    txtHVREquipRating.style.backgroundColor = 'lightyellow';
    //    controlToBeFocused = txtHVREquipRating;
    //}
    //else {
    //    txtHVREquipRating.style.backgroundColor = 'white';
    //}

    if (!CheckSeveritySelection('chkEmailSeverities')) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 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 ? '</br>' : '') + 'Please select the timezone !';

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

    if (isError) {
        TrinetraCustomAlerts(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 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + '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();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        return true;
    }
}

/*********************************Vehicle Level Validations************************************/
var AlertSelectDeviceId = "Please select the Device Id.";
var AlertVehicleNameExist = "Device Name already exists";
var AlertEnterVehicleName = "Please enter the Device Name.";
var AlertVinExist = "VIN already exists.";
var AlertEnterVin = "Please enter a valid VIN.";
var AlertLicenceAlreadyExist = "License Plate Name already exists.";
var AlertEnterInternalNo = "Please enter Internal Device Number.";
var AlertEnterLicPalte = "Please enter the License Plate.";
var AlertValidLicPlate = "Please enter a valid License Plate.";
var AlertValidYearManufacture = "Please enter a valid Year of Manufacturing.";
var AlertSelectSeverityLevel = "Please select the Severity Level.";
var AlertVehicleType = "Please select the Device 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 Device.";
var AlertEnterPurchaseDate = "Please select the Purchase date.";
var AlertEnterLifeSpan = "Please enter the Life Span.";
var AlertEnterLeaseExpiry = "Please select the Lease Expiry Date.";
var AlertEnterWarrantyExpiry = "Please select the Warranty Expiry Date.";

//Set alert message to the variables
function SetAlertMessage(SelectDeviceId, VehicleNameExist, EnterVehicleName, VinExist, EnterVin, LicenceAlreadyExist, EnterLicPalte, ValidYearManufacture, SelectSeverityLevel, VehicleType, ValidColor, FuelCapacity, ValidLicPlate, DeleteConf, EnterInternalNo) {

    AlertSelectDeviceId = SelectDeviceId;
    AlertVehicleNameExist = VehicleNameExist;
    AlertEnterVehicleName = EnterVehicleName;
    AlertVinExist = VinExist;
    AlertEnterVin = EnterVin;
    AlertEnterInternalNo = EnterInternalNo;
    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 txtIntNo = document.getElementById('txtInternalNo');
    //    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');
    var txtPurchasedDate = document.getElementById('txtPurchasedDate');
    var txtLifeSpan = document.getElementById('txtLifeSpan');
    var radLeased = document.getElementById('rdblstVehicleOwnership');
    var txtLeaseExpiry = document.getElementById('txtLeaseExpiryDate');
    var chkIsUnderWarranty = document.getElementById('chkIsUnderWarranty');
    var txtWarrantyExpiryDate = document.getElementById('txtWarrantyExpiryDate');
    var chkVehicleDocsUpload = document.getElementById('chkVehicleDocsUpload');
    var fuRCUpload = document.getElementById('fuRCUpload');
    var fuFCUpload = document.getElementById('fuFCUpload');
    var fuInsuranceUpload = document.getElementById('fuInsuranceUpload');

    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 ? '</br>' : '') + AlertVehicleNameExist;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtVehName;
        }
        txtVehName.style.backgroundColor = 'lightyellow';
    }
    else if (RemoveSpaces(txtVehName).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 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 ? '</br>' : '') + '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 ? '</br>' : '') + AlertVinExist;
        if (!isError) {
            controlToBeFocused = txtVIN;
            isError = true;
        }
        txtVIN.style.backgroundColor = 'lightyellow';
    }
        /* else if (RemoveSpaces(txtVIN).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + '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 ? '</br>' : '') + AlertEnterVin;
        if (!isError) {
            controlToBeFocused = txtVIN;
            isError = true;
        }
        txtVIN.style.backgroundColor = 'lightyellow';
    }
    else {
        txtVIN.style.backgroundColor = 'white';
    }

    //    if (txtIntNo != null && txtIntNo.value.length == 0) {
    //        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterInternalNo;
    //        if (!isError) {
    //            controlToBeFocused = txtIntNo;
    //            isError = true;
    //        }
    //        txtIntNo.style.backgroundColor = 'lightyellow';
    //    }
    //    else if (reFieldValidations(txtIntNo.value, "AlphaNumericWithoutSpace") == false) {
    //        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterInternalNo;
    //        if (!isError) {
    //            controlToBeFocused = txtIntNo;
    //            isError = true;
    //        }
    //        txtIntNo.style.backgroundColor = 'lightyellow';
    //    }
    //    else {
    //        txtIntNo.style.backgroundColor = 'white';
    //    }

    /*if (!CheckIsSelected(ddlVehMake.value)) {
    alertMessage += (alertMessage.length > 0 ? '</br>' : '') + '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 ? '</br>' : '') + AlertLicenceAlreadyExist;
        if (!isError) {
            controlToBeFocused = txtLICPlate;
            isError = true;
        }
        txtLICPlate.style.backgroundColor = 'lightyellow';
    }
    else if (RemoveSpaces(txtLICPlate).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterLicPalte;
        if (!isError) {
            controlToBeFocused = txtLICPlate;
            isError = true;
        }
        txtLICPlate.style.backgroundColor = 'lightyellow';
    }
    else if (reFieldValidations(txtLICPlate.value, "AlphaNumericWithSpace") == false) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertValidLicPlate;
        if (!isError) {
            controlToBeFocused = txtLICPlate;
            isError = true;
        }
        txtLICPlate.style.backgroundColor = 'lightyellow';
    }
    else {
        txtLICPlate.style.backgroundColor = 'white';
    }

    /* if (!CheckIsSelected(ddlModel.value)) {
    alertMessage += (alertMessage.length > 0 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + AlertValidYearManufacture;
            if (!isError) {
                controlToBeFocused = txtYear;
                isError = true;
            }
            txtYear.style.backgroundColor = 'lightyellow';
        }
        else {
            txtYear.style.backgroundColor = 'white';
        }
    }

    if (!CheckSeveritySelection('chkSeverities')) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 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 ? '</br>' : '') + 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 ? '</br>' : '') + '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 ? '</br>' : '') + 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 ? '</br>' : '') + AlertFuelCapacity;
            if (!isError) {
                controlToBeFocused = txtFuelTankCapacity;
                isError = true;
            }
            txtFuelTankCapacity.style.backgroundColor = 'lightyellow';
        }
        else {
            txtFuelTankCapacity.style.backgroundColor = 'white';
        }
    }
    else {
        txtFuelTankCapacity.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtPurchasedDate).length == 0) {
        if (txtPurchasedDate.value == 0) {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterPurchaseDate;
            if (!isError) {
                controlToBeFocused = txtPurchasedDate;
                isError = true;
            }
            txtPurchasedDate.style.backgroundColor = 'lightyellow';
        }
        else {
            txtPurchasedDate.style.backgroundColor = 'white';
        }
    }
    else {
        txtPurchasedDate.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtLifeSpan).length == 0) {
        if (txtLifeSpan.value == 0) {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterLifeSpan;
            if (!isError) {
                controlToBeFocused = txtLifeSpan;
                isError = true;
            }
            txtLifeSpan.style.backgroundColor = 'lightyellow';
        }
        else {
            txtLifeSpan.style.backgroundColor = 'white';
        }
    }
    else {
        txtLifeSpan.style.backgroundColor = 'white';
    }

    if (radLeased.checked == true) {
        if (RemoveSpaces(txtLeaseExpiry).length == 0) {
            if (txtLeaseExpiry.value == 0) {
                alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterLeaseExpiry;
                if (!isError) {
                    controlToBeFocused = txtLeaseExpiry;
                    isError = true;
                }
                txtLeaseExpiry.style.backgroundColor = 'lightyellow';
            }
            else {
                txtLeaseExpiry.style.backgroundColor = 'white';
            }
        }
        else {
            txtLeaseExpiry.style.backgroundColor = 'white';
        }
    }

    if (chkIsUnderWarranty.checked == true) {
        if (RemoveSpaces(txtWarrantyExpiryDate).length == 0) {
            if (txtWarrantyExpiryDate.value == 0) {
                alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterWarrantyExpiry;
                if (!isError) {
                    controlToBeFocused = txtWarrantyExpiryDate;
                    isError = true;
                }
                txtWarrantyExpiryDate.style.backgroundColor = 'lightyellow';
            }
            else {
                txtWarrantyExpiryDate.style.backgroundColor = 'white';
            }
        }
        else {
            txtWarrantyExpiryDate.style.backgroundColor = 'white';
        }
    }

    if (chkVehicleDocsUpload.checked == true) {
        if (fuRCUpload.value == '' && fuFCUpload.value == '' && fuInsuranceUpload.value == '') {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 'Please select atleast one Device document for Upload';
            if (!isError) {
                controlToBeFocused = txtWarrantyExpiryDate;
                isError = true;
            }
            fuRCUpload.style.backgroundColor = fuFCUpload.style.backgroundColor = fuInsuranceUpload.style.backgroundColor = 'lightyellow';
        }
        else {
            fuRCUpload.style.backgroundColor = fuFCUpload.style.backgroundColor = fuInsuranceUpload.style.backgroundColor = 'white';
        }
    }

    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        ShowPopUp();
        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 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + '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) {
        TrinetraCustomAlerts(alertMessage);
    }
    return !isError;
}

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

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

var AlertSensorAlreadtExist = "Sensor Name already exists.";
var AlertValidSenorName = "Please enter a valid Sensor Name.";
var AlertValidActionOn = "Please enter a valid Action On Status.";
var AlertValidActionOff = "Please enter a valid Action Off Status.";
var AlertOnOffSame = "Action On and Off Status cannot be the same.";

function setAlertCheckSensorName(Alert_SensorAlreadtExist, Alert_ValidSenorName, Alert_ValidActionOn, Alert_ValidActionOff, Alert_OnOffSame) {
    AlertSensorAlreadtExist = Alert_SensorAlreadtExist;
    AlertValidSenorName = Alert_ValidSenorName;
    AlertValidActionOn = Alert_ValidActionOn;
    AlertValidActionOff = Alert_ValidActionOff;
    AlertOnOffSame = Alert_OnOffSame;
}

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 = AlertSensorAlreadtExist;
        sensorNameField.style.backgroundColor = 'lightyellow';
        sensorNameField.focus();
    }
    else if (sensorNameField != null) {
        s = RemoveSpaces(sensorNameField);
        if (s.length == 0) {
            isError = true;
            alertMessage = AlertValidSenorName;
            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 ? '</br>' : '') + AlertValidActionOn;
            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 ? '</br>' : '') + AlertValidActionOff;
            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 ? '</br>' : '') + AlertOnOffSame;
            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) {
        TrinetraCustomAlerts(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] + ',';
    }
}

var AlertNewPassword = "Please enter the New Password.";
var AlertPassword = "Password should have atleast ";
var AlertCh = " characters";
var AlertDifferentPassword = "Please provide a different password than the old password.";
var AlertConfirmPassword = "Please confirm the Password.";

function SetAlertValidateResetPwd(Alert_NewPassword, Alert_Password, Alert_Ch, Alert_DifferentPassword, Alert_ConfirmPassword) {
    AlertNewPassword = Alert_NewPassword;
    AlertPassword = Alert_Password;
    AlertCh = Alert_Ch;
    AlertDifferentPassword = Alert_DifferentPassword;
    AlertConfirmPassword = Alert_ConfirmPassword;
}


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 = AlertNewPassword; //'Please enter the New Password.';
        isError = true;
        newPwd.focus();
        newPwd.style.backgroundColor = 'lightyellow';
    }
    else if (s.length < minPasswordChar) {
        alertMessage = AlertPassword + minPasswordChar + AlertCh;
        isError = true;
        newPwd.focus();
        newPwd.style.backgroundColor = 'lightyellow';
    }
    else {
        newPwd.style.backgroundColor = 'white';
    }

    if (oldPassword != '' && oldPassword == s) {
        alertMessage += (alertMessage.length == 0 ? '' : '</br>') + AlertDifferentPassword;
        if (!isError) {
            newPwd.focus();
            isError = true;
        }
        newPwd.style.backgroundColor = 'lightyellow';
    }
    else {
        newPwd.style.backgroundColor = 'white';
    }

    if (confirmNewPwd.value != s) {
        alertMessage += (alertMessage.length == 0 ? '' : '</br>') + AlertConfirmPassword;
        if (!isError) {
            confirmNewPwd.focus();
            isError = true;
        }
        confirmNewPwd.style.backgroundColor = 'lightyellow';
    }
    else {
        confirmNewPwd.style.backgroundColor = 'white';
    }

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

function CheckUserGroup() {
    if ($get('<%=ddlUsrGroups.ClientID %>').value == 0) {
        TrinetraCustomAlerts("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 ? '' : '</br>') + Alert_OwnStatus;

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

    if (statusdropdown.value == 2 && lockeddropdown.value == 2 && usergroupdropdown.value == '- Select -') {
        alertMessage += (alertMessage.length == 0 ? '' : '</br>') + Alert_SelectOptionFormassUpdate;
        isError = true;
    }

    if (isError) {
        TrinetraCustomAlerts(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 CustomerName = document.getElementById('ddlCustomer');
    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 ? '</br>' : '') + Alert_FirstName;
        if (!isError) {
            controlToBeFocused = firstName;
        }
        firstName.style.backgroundColor = 'lightyellow';
        isError = true;
    }
    else if (reFieldValidations(firstName.value, "CharacterWithSpace") == false) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + Alert_ValidFirstName;
        if (!isError) {
            controlToBeFocused = firstName;
        }
        firstName.style.backgroundColor = 'lightyellow';
        isError = true;
    }
    else {
        firstName.style.backgroundColor = 'white';
    }


    //if (ddlCustomer.value == 0 || ddlCustomer.value == '- Select -') {
    //    //alertMessage += (alertMessage.length == 0 ? '</br>' : '\n') + 
    //    alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 'Please select Customer Name';
    //    if (!isError) {
    //        controlToBeFocused = ddlCustomer
    //        isError = true;
    //    }
    //    ddlCustomer.style.backgroundColor = 'lightyellow';
    //}
    //else {
    //    ddlCustomer.style.backgroundColor = 'white';
    //}
    //if (RemoveSpaces(lastName).length > 0 && reFieldValidations(lastName.value, "CharacterWithSpace") == false) {
    //    alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 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 ? '</br>' : '') + Alert_EnterMail;
        if (!isError) {
            controlToBeFocused = emailField;
        }
        isError = true;
        emailField.style.backgroundColor = 'lightyellow';
    }
    else if (!validateEmail(emailField.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 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 ? '</br>' : '') + 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 ? '</br>' : '') + 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 ? '</br>' : '') + Alert_UsernameNotExist;
        if (!isError) {
            controlToBeFocused = userNameField;
        }
        isError = true;
        userNameField.style.backgroundColor = 'lightyellow';
    }
    else if (RemoveSpaces(userNameField).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + Alert_EnterUsername;
        if (!isError) {
            controlToBeFocused = userNameField;
        }
        isError = true;
        userNameField.style.backgroundColor = 'lightyellow';
    }
    else if (reFieldValidations(userNameField.value, "AlphaNumericWithSpaceHypDotUnderScore") == false) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 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 ? '</br>' : '') + Alert_EnterDisplayName;
        if (!isError) {
            controlToBeFocused = displayNameField;
        }
        isError = true;
        displayNameField.style.backgroundColor = 'lightyellow';
    }
    else if (reFieldValidations(displayNameField.value, "AlphaNumericWithSpaceHypDotUnderScore") == false) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 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 ? '' : '</br>') + 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 ? '' : '</br>') + Alert_PwdAtlesat + ' ' + minPasswordChar + ' ' + AlertCh;
                if (!isError) {
                    controlToBeFocused = pwdField;
                }
                pwdField.style.backgroundColor = 'lightyellow';
            }
            else if (RemoveSpaces(pwdField).length < minPasswordChar) {
                alertMessage += (alertMessage.length == 0 ? '' : '</br>') + Alert_PasswordShouldatleast + ' ' + minPasswordChar + ' ' + AlertCh;
                if (!isError) {
                    controlToBeFocused = pwdField;
                }
                pwdField.style.backgroundColor = 'lightyellow';
            }
            else {
                pwdField.style.backgroundColor = 'white';
            }


            //            if (confirmpwdField.value != RemoveSpaces(pwdField)) {
            //                alertMessage += (alertMessage.length == 0 ? '' : '</br>') + 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 ? '' : '</br>') + Alert_SelectUserGroup;
        if (!isError) {
            controlToBeFocused = userGroupField
            isError = true;
        }
        userGroupField.style.backgroundColor = 'lightyellow';
    }
    else {
        userGroupField.style.backgroundColor = 'white';
    }

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

function validateEmail(elementValue) {
    var emailPattern = /^([a-zA-Z0-9])(([a-zA-Z0-9])*([\._-])?([a-zA-Z0-9]))*@(([a-zA-Z0-9\-])+(\.))+([a-zA-Z]{2,4})+$/;
    ///^[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.';
var Alert_ExffectiveToConfirm1 = 'This Schedule will expire on ';
var Alert_ExffectiveToConfirm2 = ' .Do you want to continue?';
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_ExffectiveToConfirm1, Alert_ExffectiveToConfirm2) {
    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;
    Alert_ExffectiveToConfirm1 = Alert_ExffectiveToConfirm1;
    Alert_ExffectiveToConfirm2 = Alert_ExffectiveToConfirm2;
}

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 ibtnSave = document.getElementById("ibtnSave");
    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 ? '</br>' : '') + 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 ? '</br>' : '') + 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 ? '</br>' : '') + 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 (frequency.value == "3") {

            if (effectiveToField != null && effectiveFromField != null) {
                dtfrom = effectiveFromField.value;
                dtfrom = dtfrom.replace("-", "/").replace("-", "/");
                dtTo = effectiveToField.value.replace("-", "/").replace("-", "/");
                dtTo = new Date(dtTo);
                var fortnight = new Date(dtfrom);
                fortnight.setDate(fortnight.getDate() + 13);
                if (dtTo < fortnight) {
                    alertMessage += "Please select the valid date range";
                    if (!isError) {
                        isError = true;
                    }
                }

            }
        }
    }

    if (schedulingEmailList != null) {
        if (schedulingEmailList.value == "") {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 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 ? '</br>' : '') + Alert_ValidDateRange;
            }
            else if (validity == 2) {
                isError = true;
                alertMessage += (alertMessage.length > 0 ? '</br>' : '') + Alert_ValidTimeRange;
            }
            else if (validity == 3) {
                isError = true;
                alertMessage += (alertMessage.length > 0 ? '</br>' : '') + Alert_SelectedDateRange + ' ' +
                (frequency.value == 1 ? Alert_Weekly : Alert_Monthly) + ' ' + Alert_Scheduling;
            }
            //            else if (validity == 3 && frequency.value == 2) {
            //                isError = true;
            //                alertMessage += (alertMessage.length > 0 ? '</br>' : '') + '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');
            var fromDate = $('input[id$=txtEffectiveFrom]').datepicker('getDate');
            var DateDiff = toDate - fromDate;
            if ((DateDiff / 86400000) < 30) {
                isError = true;
                alertMessage += "Please select the date range atleast 30 days.";
            }
            else if (toDate.getDate() > eval(dayOfMonth.value)) {
                return confirm(Alert_DayNotMatching + effectiveToField.value +
            '. \n ' + Alert_SureWantContinue + '?');
            }
        }
    }

    if (isError) {
        TrinetraCustomAlerts(alertMessage);
    }
    else if ((effectiveToField.value != null && effectiveToField.value != "") && frequency.value != 2) {

        if (confirm(Alert_ExffectiveToConfirm1 + " " + effectiveToField.value + Alert_ExffectiveToConfirm2))
            return !isError;
        else
            return isError;
    }
    else
        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, UniqueID) {
    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] == "") {
        TrinetraCustomAlerts(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 ? '' : '</br>') + Alert_AssignYourself;

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

        if (isError) {
            TrinetraCustomAlerts(alertMessage);
            return false;
        }
        else {
            ShowPopUp();
            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 ? '' : '</br>') + Alert_UnAssignYourself;

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

        if (isError) {
            TrinetraCustomAlerts(alertMessage);
            return false;
        }
        else {
            ShowPopUp();
            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, UniqueID) {

    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] == "") {
        TrinetraCustomAlerts(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 ? '' : '</br>') + Alert_AssignYourSelf;

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

        if (isError) {
            TrinetraCustomAlerts(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) {

                TrinetraConfirm(UniqueID, Alert_AlreadyAssigned);
                return false;
                //var IsConfirm = confirm(Alert_AlreadyAssigned);

                //                if (IsConfirm == true) {
                //                    return true;
                //                }
                //                else {
                //                    return false;
                //                }
            }
            else {
                ShowPopUp();
                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 ? '' : '</br>') + Alert_UnAssignYourSelf;

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

        if (isError) {
            TrinetraCustomAlerts(alertMessage);
            return false;
        }
        else {

            //    var IsConfirmed = confirm(Alert_RestrictFromLogin);

            TrinetraConfirm(UniqueID, Alert_RestrictFromLogin);
            return false;
            //            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' || s == 'اسم المنطقة الجغرافية') {
        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 ? '' : '</br>') + 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 ? '' : '</br>') + 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 ? '' : '</br>') + Alert_SelectCategory;
        if (!isError) {
            categoryField.focus();
            isError = true;
        }
        categoryField.style.backgroundColor = 'lightyellow';
    }
    else {
        categoryField.style.backgroundColor = 'white';
    }

    if (isError) {
        //TrinetraCustomAlerts(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 ? '' : '</br>') + '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 ? '' : '</br>') + '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 ? '' : '</br>') + 'Please select the Communication Mode.';
        if (!isError) {
            controlToBeFocused = CommMode;
            isError = true;
        }
        CommMode.style.backgroundColor = 'lightyellow';
    }
    else {
        CommMode.style.backgroundColor = 'white';
    }

    if (isError) {
        TrinetraCustomAlerts(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 ? '</br>' : '') + '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 ? '</br>' : '') + 'Please select the modules and operations for the package.';
        isError = true;
    }

    if (isError) {
        TrinetraCustomAlerts(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 ? '' : '</br>') + '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 ? '' : '</br>') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + 'Please enter a valid Expires On date1.';
            txtExpiresOn.style.backgroundColor = 'lightyellow';

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

    if (isError) {
        TrinetraCustomAlerts(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 ? '' : '</br>') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + 'Please enter a valid Expires On date.';
            txtExpiresOn.style.backgroundColor = 'lightyellow';

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

    if (isError) {
        TrinetraCustomAlerts(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 ? '</br>' : '') + 'Please select the Partner Name.';

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


    if (isError) {
        TrinetraCustomAlerts(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 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + 'Please enter the Email ID.';
        emailField.style.backgroundColor = 'lightyellow';
    }
    else if (!validateEmail(emailField.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + 'Please select the Report To.';
        userReportTo.style.backgroundColor = 'lightyellow';
    }
    else {
        userReportTo.style.backgroundColor = 'white';
    }

    if (isError) {
        TrinetraCustomAlerts(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 ? '</br>' : '') + 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 ? '</br>' : '') + Alert_SelectModuleOperation;
        isError = true;
    }

    if (isError) {
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        ShowPopUp();
        return true;
    }
}
var AlertDriverGroupName = 'Please enter the Driver Group Name.';
var AlertDriverGroupExists = 'Driver Group Name already exists.';
function SetDriverGroup(AlertDriverGroupNameMsg, AlertDriverGroupExistsMsg) {
    AlertDriverGroupName = AlertDriverGroupNameMsg;
    AlertDriverGroupExists = AlertDriverGroupExistsMsg;
}
function ValidateDriverGroupInformation(isDriverGroupNameValid) {
    var driverGroupName = document.getElementById('txtDriverGroupName');
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (!isDriverGroupNameValid) {
        isError = true;
        alertMessage = AlertDriverGroupExists;
        driverGroupName.style.backgroundColor = 'lightyellow';
        controlToBeFocused = driverGroupName;
    }

    if (RemoveSpaces(driverGroupName).length == 0) {
        isError = true;
        controlToBeFocused = driverGroupName;
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertDriverGroupName;
        driverGroupName.style.backgroundColor = 'lightyellow';
    }
    else {
        driverGroupName.style.backgroundColor = 'white';
    }

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

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

var Alert_RouteAlready = "Route Name already exists.";
var Alert_RouteName = "Please enter the Route Name.";

function setAlertMessageAddRoute(RouteAlready, RouteName) {
    Alert_RouteAlready = RouteAlready;
    Alert_RouteName = RouteName;
}

function ValidateRouteInformation(isRouteNameValid) {
    var routeName = document.getElementById('txtRouteName');

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

    if (!isRouteNameValid) {
        isError = true;
        alertMessage = Alert_RouteAlready;
        routeName.style.backgroundColor = 'lightyellow';
        controlToBeFocused = routeName;
    }

    if (RemoveSpaces(routeName).length == 0) {
        isError = true;
        controlToBeFocused = routeName;
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + Alert_RouteName;
        routeName.style.backgroundColor = 'lightyellow';
    }
    else {
        routeName.style.backgroundColor = 'white';
    }

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

    if (isError) {
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        ShowPopUp();
        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");
    }
}


function ShowLockUser() {
    var isIE = CheckBrowser();
    if (document.getElementById("chkLockUser").checked) {
        document.getElementById("tblLockUser").setAttribute(isIE ? "className" : "class", (isIE ? "ControlShow" : "ControlShowFF"));
    }
    else {
        document.getElementById("tblLockUser").setAttribute(isIE ? "className" : "class", "ControlHide");
        HidePopUp();
    }
}


/******************* 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();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        ShowPopUp();
        return true;
    }
}

// Maintenance Service Assignment
function ValidateServiceAssignment() {
    var serviceCategory = document.getElementById('ddlServiceCategory');
    var ServiceIDs = document.getElementById('hdnSelectedServices');
    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 (ServiceIDs.value == "") {
        isError = true;
        controlToBeFocused = ServiceIDs;
        alertMessage += (alertMessage.length > 0 ? '\n' : '') + 'Select atleast one Service Name to be assigned.';
        ServiceIDs.style.backgroundColor = 'lightyellow';
    }
    else {
    }
    //
    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        ShowPopUp();
        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();
        TrinetraCustomAlerts(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();
        }
        TrinetraCustomAlerts(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();
        TrinetraCustomAlerts(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 ? '' : '') + '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 select the Email Users for Notification List.';
    }

    if (isError) {
        if (controlToBeFocused != null) {
            controlToBeFocused.focus();
        }
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        ShowPopUp();
        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();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        return true;
    }
}

function ValidateUnregisteredUser(isUserNameExists) {

    var firstNameField = document.getElementById('txtFirstName');
    if (firstNameField == null) {
        firstNameField = document.getElementById('txtFirstName');
    }
    var userNameField = document.getElementById('txtUsername');
    if (userNameField == null) {
        userNameField = document.getElementById('txtUsername');
    }
    var displayNameField = document.getElementById('txtDispName');
    if (displayNameField == null) {
        displayNameField = document.getElementById('txtDispName');
    }
    var emailField = document.getElementById('txtEmail');
    if (emailField == null) {
        emailField = document.getElementById('txtEmail');
    }
    var mobileNo = document.getElementById('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 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + 'Please enter the Email.';
        if (!isError) {
            controlToBeFocused = emailField;
        }
        isError = true;
        emailField.style.backgroundColor = 'lightyellow';
    }
    else if (!validateEmail(emailField.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + '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 ? '</br>' : '') + '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) {
        TrinetraCustomAlerts(alertMessage);
        controlToBeFocused.focus();
        return false;
    }
    else {
        return true;
    }
}

function GetConfirmFleetMaintenance(type, Mode, assignedStatus) {
    if (Mode == 'delete' && assignedStatus == 1) {
        // If Maintenance Service
        if (type == 'ms') {
            TrinetraCustomAlerts('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') {
            TrinetraCustomAlerts('Maintenance Plan cannot be deleted as it has been assigned to one or more Device(s).');
        }
            // If Maintenance Plan Details
        else if (type == 'mpd') {
            TrinetraCustomAlerts('Maintenance Plan Details cannot be deleted as it has been assigned to one or more Device(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() {
    debugger;
    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 ddlServicedby = document.getElementById('ddlservicedby');

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

    if (RemoveSpaces(executedOn).length == 0) {
        isError = true;
        alertMessage += (alertMessage.length == 0 ? '' : '<br/>') + '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 ? '' : '<br/>') + 'Please select the maintenance services.';
        if (!isError) {
            controlToBeFocused = document.getElementById("gvServiceDetails");
            isError = true;
        }
    }

    if (RemoveSpaces(comments).length == 0) {
        alertMessage += (alertMessage.length == 0 ? '' : '<br/>') + 'Please enter the Comments.';
        if (!isError) {
            controlToBeFocused = comments;
            isError = true;
        }
        comments.style.backgroundColor = 'lightyellow';
    }
    else {
        comments.style.backgroundColor = 'white';
    }

    //if (!CheckIsSelected(ddlServicedby.value) || ddlServicedby.value=='')
    //{
    //    alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please select the Serviced User.';
    //    if (!isError)
    //    {
    //        controlToBeFocused = ddlServicedby;
    //        isError = true;
    //    }
    //    ddlServicedby.style.backgroundColor = 'lightyellow';
    //}
    //else
    //{
    //    ddlServicedby.style.backgroundColor = 'white';
    //}																	   
    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(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 Device.';
        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 Running 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();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        ShowPopUp();
        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();
        TrinetraCustomAlerts(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 GasStation = document.getElementById('txtGasStation');
    var FuelCost = document.getElementById('txtFuelCost');
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (document.getElementById("ddlVehicle").value == "- Select -") {
        alertMessage = 'Please select the Device.';
        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 > new date()) {

        //            alertMessage += (alertMessage.length == 0 ? '' : '</br>') + 'Please select Fuel Flled Date less than Todays 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 (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/ltr.';
        if (!isError) {
            isError = true;
            controlToBeFocused = FuelCost;
        }
        FuelCost.style.backgroundColor = 'lightyellow';
    }
    else {
        FuelCost.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(GasStation).length == 0) {
        alertMessage += (alertMessage.length == 0 ? '' : '\n') + 'Please enter the Fuel Station Name.';
        if (!isError) {
            controlToBeFocused = comments;
            isError = true;
        }
        GasStation.style.backgroundColor = 'lightyellow';
    }
    else {
        GasStation.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';
    }

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




var Alert_EntertMakeName = "Please enter the Make Name.";
var Alert_Confirmation = "Do you want to really delete this Record?";
var Alert_ConfirmationRoute = "This Landmark has been already assigned to routing process. Cannot be deleted.";
function setAlertValidationVehicleMakeEntry(EnterMakeName, DeleteConf) {
    Alert_EntertMakeName = EnterMakeName;
    Alert_Confirmation = DeleteConf;
}


function setAlertValidationDeleteLandmarkConfirmation(DeleteConf) {
    Alert_Confirmation = DeleteConf;
}
function setAlertValidationDeleteLandmarkConfirmationRoute(DeleteRouteConf) {
    Alert_ConfirmationRoute = DeleteRouteConf;
}

//Delete Confirmation
function DeleteConfirmation(btnId) {

    //return confirm(Alert_Confirmation);
    var hdnDelete = document.getElementById(btnId.id.substring(0, btnId.id.lastIndexOf("_")) + "_hdnDelete");
    if (hdnDelete.value == 0) {
        TrinetraCustomAlerts(Alert_ConfirmationRoute);
        return false;
    }
    else if (hdnDelete.value == 1) {
        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 ? '' : '</br>') + Alert_EntertMakeName;
        if (!isError) {
            isError = true;
            controlToBeFocused = makeName;
        }

        makeName.style.backgroundColor = 'lightyellow';
    }
    else {
        makeName.style.backgroundColor = 'white';
    }

    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(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;
    //    }

    if ((makeName.value == "- Select -") || (makeName.value == "- اختر -")) {
        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 ? '' : '</br>') + Alert_EntertModelName;
        if (!isError) {
            isError = true;
            controlToBeFocused = modelName;
        }

        modelName.style.backgroundColor = 'lightyellow';
    }
    else {
        modelName.style.backgroundColor = 'white';
    }

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

//Set Alert message to the variable.
var AlertGreaterThanFromDate = "Please select To date greater than 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) {
            TrinetraCustomAlerts(AlertGreaterThanFromDate);
            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 Device.';
        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 ? '' : '</br>') + '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 ? '' : '</br>') + '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 ? '' : '</br>') + '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 ? '' : '</br>') + '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 ? '' : '</br>') + '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 ? '' : '</br>') + '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();
        TrinetraCustomAlerts(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 + '</br>' : '') + Alert_EnterRadius;
        if (!isError) {
            txtRadius.focus();
        }
        isError = true;
        txtRadius.style.backgroundColor = 'lightyellow';
    }
    else if (txtRadius.value < 1) {
        errorMessage = (isError ? errorMessage + '</br>' : '') + Alert_EnterRadius;
        if (!isError) {
            txtRadius.focus();
        }
        isError = true;
        txtRadius.style.backgroundColor = 'lightyellow';
    }
    else {
        txtRadius.style.backgroundColor = 'white';
    }
    if (isError) {
        TrinetraCustomAlerts(errorMessage);
    }
    return !isError;
}

function Validate() {
    if (document.getElementById("ddlVehicle").value == 0) {
        TrinetraCustomAlerts("Please select a Device.");
        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) {
            TrinetraCustomAlerts(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, UniqueID) {
    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 = 'hdnVehicleIdsToBeUnassinged';
        alertMessage = Alert_SelectVehciletobeUnassigned;
    }
    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';
    }
    else if (type == 20) { // User List for emailing reports AlertEmailNotification

        hdnSelectedIDList = 'hdnUsersEmail';
        // alertMessage = 'Select user(s) to be Emailed.';
    }

    // 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;
                return TrinetraConfirm(UniqueID, AlertEmail);
                //return false;
                //                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.</br>Do you want to select it?')) {
            //          return false;
            //       }
            //       else {
            //           return true;
            //       }
            // }
            // else {
            //  isError = false;
            //}
            if (!isEmailSelected && !isSMSSelected) {
                isError = true;
                if (isEmailVisible && isSMSVisible) {

                    TrinetraConfirmNotification(UniqueID, AlertEmailSMS);
                    return false;
                    //                    if (confirm(AlertEmailSMS)) {
                    //                        return false;
                    //                    }
                    //                    else {
                    //                        return true;
                    //                    }
                }

                else if (isEmailVisible) {
                    TrinetraConfirmNotification(UniqueID, AlertEmailNotification);
                    return false;
                    //                    if (confirm(AlertEmailNotification)) {
                    //                        return false;
                    //                    }
                    //                    else {
                    //                        return true;
                    //                    }
                }
                else if (isSMSVisible) {
                    TrinetraConfirmNotification(UniqueID, AlertSMSNotification);
                    return false;
                    //                    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 (type == 1 && !isError) {

        if (UniqueID == 'btnAssignLeaseVehicles') {
            LoadLeaseAssignmentSettingsPopup();
        }
        if (UniqueID == 'btnAssignTUserVehicles') {
            LoadTUserVehAssignmentSettingsPopup();
        }
        if (UniqueID == 'btnAssignVehicles') {
            ShowPopUp();
        }

    }
    if (type == 2 && !isError) {
        if (UniqueID == 'btnUnassignTUserVehicles') {
            LoadTUserVehUnAssignmentSettingsPopup();
        }
        if (UniqueID == 'btnUnassignVehicles') {
            ShowPopUp();
        }

    }
    if (isError) {
        if (alertMessage != '') {
            TrinetraCustomAlerts(alertMessage);

        }
    }

    return !isError;
    //return false;
}

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 ? '</br>' : '') + 'Please enter the News Name.';
        newsName.style.backgroundColor = 'lightyellow';
    }
    else {
        newsName.style.backgroundColor = 'white';
    }

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

    if (isError) {
        TrinetraCustomAlerts(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 ? '</br>' : '') + 'Please enter the Tips Name.';
        tipsName.style.backgroundColor = 'lightyellow';
    }
    else {
        tipsName.style.backgroundColor = 'white';
    }

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

    if (isError) {
        TrinetraCustomAlerts(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) {
        TrinetraCustomAlerts(AlertSeverityTemplateCreation);
        return false;
    }
    controlToBeFocused = txtSeverityTempName;
    //    if (RemoveSpaces(hdnOutputIds).length == 0) {
    //        TrinetraCustomAlerts('Please Select Output for Severity Template Creation.');
    //        return false;
    //    }     


    if (isError) {
        TrinetraCustomAlerts(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) {
        TrinetraCustomAlerts(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 + '</br>') + '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 + '</br>') + '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 + '</br>') + 'Please select a Trip Mode.';

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

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

    }
    return true;

}
function checkFutureDate(sender, args) {
    if (sender._selectedDate >= new Date()) {
        TrinetraCustomAlerts("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 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + 'Please select the Wait & Move time.';
            if (!isError) {
                isError = true;
                controlToBeFocused = ddlTimeOfMove;
            }
            ddlTimeOfMove.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlTimeOfMove.style.backgroundColor = 'white';
        }
    }
    if (isError) {
        TrinetraCustomAlerts(alertMessage);
        controlToBeFocused.focus();
        return false;
    }
    else {
        return true;
    }
}


var AlertCommandsVehicleName = "Please select the Device 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);
}
//Sakthi - 14-Jan-2012
function ConfirmSelectOrNot(ddlVehicle) {
    var select = false;
    var checkboxCollection = ddlVehicle.getElementsByTagName('input');
    for (var i = 0; i < checkboxCollection.length; i++) {
        if (checkboxCollection[i].type.toString().toLowerCase() == "checkbox") {
            if (checkboxCollection[i].checked == true) { select = true; }
        }
    }
    return select;
}
function ValidateSchedulingOfCommands(IsCmdPage) {
    var dvVehicle = document.getElementById('dvVehicle');
    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 ? '</br>' : '') + AlertCommandsVehicleName;
            if (!isError) {
                isError = true;
                controlToBeFocused = ddlVehicle;
            }
            //dvVehicle.style.backgroundColor = 'lightyellow';
            ddlVehicle.style.backgroundColor = 'lightyellow';
        }
        else {
            //dvVehicle.style.backgroundColor = 'white';
            ddlVehicle.style.backgroundColor = 'white';
        }
    }
    else {
        document.getElementById('IsScheduleCmds').value = true;
    }
    //    if (!CheckIsSelected(ddlExecutionOn.value)) {
    //        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + '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 ? '</br>' : '') + 'Please select the No.ofRetries.';
    //        if (!isError) {
    //            isError = true;
    //            controlToBeFocused = ddlNoOfTries;
    //        }
    //        ddlNoOfTries.style.backgroundColor = 'lightyellow';
    //    }
    //    else {
    //        ddlNoOfTries.style.backgroundColor = 'white';
    //    }

    if (isError) {
        TrinetraCustomAlerts(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 ? '</br>' : '') + AlertCommandsVehicleName;
        if (!isError) {
            isError = true;
            controlToBeFocused = ddlVehicle;
        }
        ddlVehicle.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlVehicle.style.backgroundColor = 'white';
    }

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

function UpdateCommand(val) {



    if (val != 0) {
        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) {
            TrinetraCustomAlerts('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 -';
        TrinetraCustomAlerts("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;
//    }
//}

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] == '0' ? '1' : 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 = parseFloat(new Date().getMonth()) >= 9 ? (new Date().getMonth() + 1) : "0" + (new Date().getMonth() + 1);
        var d = parseFloat(new Date().getDate()) >= 10 ? new Date().getDate() : "0" + new Date().getDate();

        document.getElementById('txtFromDate').value = "01/" + month + "/" + new Date().getFullYear();
        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;
    }
}
function GetEnglishMonth(PasDate) {
    var PasProssedDate = "";
    var TmpENMonths = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec";
    var monthEn = String(TmpENMonths).split(',');
    date = PasDate.split('/');
    for (var i = 0; i <= 11; i++) {
        if (date[1] == i) {
            PasProssedDate = date[0] + '-' + monthEn[i - 1] + '-' + date[2];
        }
    }
    return PasProssedDate;
}
function GetArabicMonth(PasDate) {
    var PasProssedDate = "";
    //var TmpArMonths = document.getElementById("hdnArMonth").value; \\ not applicable 
    var TmpArMonths = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec";
    var monthAr = String(TmpArMonths).split(',');
    date = String(PasDate).split('/');
    for (var i = 0; i <= 11; i++) {
        if (date[1] == i) {
            PasProssedDate = date[0] + '-' + monthAr[i - 1] + '-' + date[2];
        }
    }
    return PasProssedDate;
}

function IntervalsNew() {
    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] + "/";
                }
            }
        }
        if (document.getElementById('Label1').innerHTML == 'Fleet') {
            document.getElementById('txtFromDate').value = GetEnglishMonth(val);
        }
        else {
            document.getElementById('txtFromDate').value = GetArabicMonth(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] + "/";
                }
            }
        }
        if (document.getElementById('Label1').innerHTML == 'Fleet') {
            document.getElementById('txtToDate').value = GetEnglishMonth(val);
        }
        else {
            document.getElementById('txtToDate').value = GetArabicMonth(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] == '0' ? '1' : 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] + "/";
                }
            }
        }
        if (document.getElementById('Label1').innerHTML == 'Fleet') {
            document.getElementById('txtFromDate').value = GetEnglishMonth(val);
        }
        else {
            document.getElementById('txtFromDate').value = GetArabicMonth(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);
                }
            }
            if (document.getElementById('Label1').innerHTML == 'Fleet') {
                document.getElementById('txtFromDate').value = GetEnglishMonth(val);
            }
            else {
                document.getElementById('txtFromDate').value = GetArabicMonth(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] + "/";
                }
            }
        }

        if (document.getElementById('Label1').innerHTML == 'Fleet') {
            document.getElementById('txtToDate').value = GetEnglishMonth(val);
        }
        else {
            document.getElementById('txtToDate').value = GetArabicMonth(val);
        }
        document.getElementById('txtFromDate').disabled = true;
        document.getElementById('txtToDate').disabled = true;
    }
    else if (interval == "4") {
        var month = parseFloat(new Date().getMonth()) >= 9 ? (new Date().getMonth() + 1) : "0" + (new Date().getMonth() + 1);
        var d = parseFloat(new Date().getDate()) >= 10 ? new Date().getDate() : "0" + new Date().getDate();
        if (document.getElementById('Label1').innerHTML == 'Fleet') {
            document.getElementById('txtFromDate').value = GetEnglishMonth("01/" + month + "/" + new Date().getFullYear());
            document.getElementById('txtToDate').value = GetEnglishMonth(d + "/" + month + "/" + new Date().getFullYear());
        }
        else {
            document.getElementById('txtFromDate').value = GetArabicMonth("01/" + month + "/" + new Date().getFullYear());
            document.getElementById('txtToDate').value = GetArabicMonth(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();
        if (document.getElementById('Label1').innerHTML == 'Fleet') {
            document.getElementById('txtFromDate').value = GetEnglishMonth("01/" + lastmonth + "/" + lastyear);
            document.getElementById('txtToDate').value = GetEnglishMonth(new Date(new Date().getFullYear(), new Date().getMonth(), 0).getDate() + "/" + lastmonth + "/" + lastyear);
        }
        else {
            document.getElementById('txtFromDate').value = GetArabicMonth("01/" + lastmonth + "/" + lastyear);
            document.getElementById('txtToDate').value = GetArabicMonth(new Date(new Date().getFullYear(), new Date().getMonth(), 0).getDate() + "/" + lastmonth + "/" + lastyear);
        }


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

//************************************Vendor management************************************

var AlertSelectDayHours = "Please select the Day Hours.";
var AlertEnterVendorName = "Please enter the Vendor Name.";
var AlertEntertxtLitKM = "Please enter the Mileage (Kms).";
var AlertEntertxtworkorder = "Please enter the Work Order.";
var AlertEntertxtFixRateMonth = "Please enter the Monthly Rate (INR).";
var AlertEntertxtcontractfrom = "Please enter the Contract Period From.";
var AlertEntertxtKmMonth = "Please enter the Monthly Distance (Kms).";
var AlertEntertxtContractTo = "Please enter the Contract Period To.";
var AlertEntertxtExtraCostHR = "Please enter the Cost / Extra Hour (INR).";
var AlertEntertxtExtraCostKM = "Please enter the Cost / Extra Km (INR).";
var AlertEntertxtFuelcostlit = "Please enter the Fuel Cost / Litre.";


function ValidateVendorInfo(isVendorNameValid, isVINValid, isLicensePlateValid) {

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

    var dtCurrentDate = new Date();

    var ddlDHT = document.getElementById('ddlDHT');
    var txtVenName = document.getElementById('txtVenName');
    var txtLitKM = document.getElementById('txtLitKM');
    var txtworkorder = document.getElementById('txtworkorder');
    var txtFixRateMonth = document.getElementById('txtFixRateMonth');
    var txtcontractfrom = document.getElementById('txtcontractfrom');
    var txtKmMonth = document.getElementById('txtKmMonth');
    var txtContractTo = document.getElementById('txtContractTo');
    var txtExtraCostHR = document.getElementById('txtExtraCostHR');
    var txtExtraCostKM = document.getElementById('txtExtraCostKM');
    var txtFuelcostlit = document.getElementById('txtFuelcostlit');
    $('#hdnCancelsts').val("SaveUpdate");

    if (RemoveSpaces(txtVenName).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterVendorName;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtVenName;
        }
        txtVenName.style.backgroundColor = 'lightyellow';
    }
    else {
        txtVenName.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtworkorder).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEntertxtworkorder;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtworkorder;
        }
        txtworkorder.style.backgroundColor = 'lightyellow';
    }
    else {
        txtworkorder.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtcontractfrom).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEntertxtcontractfrom;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtcontractfrom;
        }
        txtcontractfrom.style.backgroundColor = 'lightyellow';
    }
    else {
        txtcontractfrom.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtContractTo).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEntertxtContractTo;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtContractTo;
        }
        txtContractTo.style.backgroundColor = 'lightyellow';
    }
    else {
        txtContractTo.style.backgroundColor = 'white';
    }

    if (ddlDHT != null) {
        if (!CheckIsSelected(ddlDHT.value)) {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertSelectDayHours;
            isError = true;
            controlToBeFocused = ddlDHT;
            ddlDHT.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlDHT.style.backgroundColor = 'white';
        }
    }

    if (RemoveSpaces(txtKmMonth).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEntertxtKmMonth;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtKmMonth;
        }
        txtKmMonth.style.backgroundColor = 'lightyellow';
    }
    else {
        txtKmMonth.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtFixRateMonth).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEntertxtFixRateMonth;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtFixRateMonth;
        }
        txtFixRateMonth.style.backgroundColor = 'lightyellow';
    }
    else {
        txtFixRateMonth.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtExtraCostHR).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEntertxtExtraCostHR;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtExtraCostHR;
        }
        txtExtraCostHR.style.backgroundColor = 'lightyellow';
    }
    else {
        txtExtraCostHR.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtLitKM).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEntertxtLitKM;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtLitKM;
        }
        txtLitKM.style.backgroundColor = 'lightyellow';
    }
    else {
        txtLitKM.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtExtraCostKM).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEntertxtExtraCostKM;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtExtraCostKM;
        }
        txtExtraCostKM.style.backgroundColor = 'lightyellow';
    }
    else {
        txtExtraCostKM.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtFuelcostlit).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEntertxtFuelcostlit;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtFuelcostlit;
        }
        txtFuelcostlit.style.backgroundColor = 'lightyellow';
    }
    else {
        txtFuelcostlit.style.backgroundColor = 'white';
    }



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



//******************Fare Mgmt *********************

var AlertEnterPakage = "Please enter the Pakage / Locations.";
var AlertEnterDepartment = "Please enter the User / Department.";
var AlertEnterTotalDistance = "Please enter the Total Distance.";
var AlertEnterTollCharges = "Please enter the Toll Charges.";
var AlertEnterMaintenanceDaysfare = "Please enter the Maintenance Days Fare.";
var AlertEnterNewFuelRate = "Please enter the New Fuel Rate / Litre.";


function ValidateFareDetails() {

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

    var dtCurrentDate = new Date();


    var txtpkglocation = document.getElementById('txtpkglocation');
    var txtuserdept = document.getElementById('txtuserdept');
    var txttotdistance = document.getElementById('txttotdistance');
    var txtTollCharges = document.getElementById('txtTollCharges');
    var txtMaintenanceDay = document.getElementById('txtMaintenanceDay');
    var txtnewfuelrate = document.getElementById('txtnewfuelrate');
    var hdnismantenance = document.getElementById('hdnismantenance');

    if (RemoveSpaces(txtpkglocation).length == 0 || txtpkglocation.value == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterPakage;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtpkglocation;
        }
        txtpkglocation.style.backgroundColor = 'lightyellow';
    }
    else {
        txtpkglocation.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtuserdept).length == 0 || txtuserdept.value == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterDepartment;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtuserdept;
        }
        txtuserdept.style.backgroundColor = 'lightyellow';
    }
    else {
        txtuserdept.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txttotdistance).length == 0 || txttotdistance.value == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterTotalDistance;
        if (!isError) {
            isError = true;
            controlToBeFocused = txttotdistance;
        }
        txttotdistance.style.backgroundColor = 'lightyellow';
    }
    else {
        txttotdistance.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtTollCharges).length == 0 || txtTollCharges.value == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterTollCharges;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtTollCharges;
        }
        txtTollCharges.style.backgroundColor = 'lightyellow';
    }
    else {
        txtTollCharges.style.backgroundColor = 'white';
    }

    if (parseInt((hdnismantenance).value) != 0) {

        if (RemoveSpaces(txtMaintenanceDay).length == 0 || txtMaintenanceDay.value == 0) {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterMaintenanceDaysfare;
            if (!isError) {
                isError = true;
                controlToBeFocused = txtMaintenanceDay;
            }
            txtMaintenanceDay.style.backgroundColor = 'lightyellow';
        }
        else {
            txtMaintenanceDay.style.backgroundColor = 'white';
        }
    }
    if (RemoveSpaces(txtnewfuelrate).length == 0 || txtnewfuelrate.value == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterNewFuelRate;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtnewfuelrate;
        }
        txtnewfuelrate.style.backgroundColor = 'lightyellow';
    }
    else {
        txtnewfuelrate.style.backgroundColor = 'white';
    }

    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        return true;
    }
}
var AlertselectGeozone = "Please select the Geozone.";
var AlertVehicleType = "Please select Device type.";
var AlertEnterfare = "Please enter the Toll Gate Fare.";
var AlertEnterValidFrom = "Please enter the Valid From Date.";

function ValTollFare() {

    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';
    var ddlGeozone = document.getElementById('ddlGeozone');
    var ddlVehicleType = document.getElementById('ddlVehicleType');
    var txtValidFrom = document.getElementById('txtFareValidFrom');
    var txtfareAmt = document.getElementById('txtfare');

    if (!CheckIsSelected(ddlGeozone.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertselectGeozone;
        if (!isError) {
            isError = true;
        }
        ddlGeozone.style.backgroundColor = 'lightyellow';
    }
    if (!CheckIsSelected(ddlVehicleType.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertVehicleType;
        if (!isError) {
            isError = true;
        }

        ddlVehicleType.style.backgroundColor = 'lightyellow';
    }
    if (RemoveSpaces(txtfareAmt).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterfare;
        if (!isError) {
            txtfareAmt.focus();
            isError = true;
        }
        txtfareAmt.style.backgroundColor = 'lightyellow';
    }
    if (RemoveSpaces(txtValidFrom).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterValidFrom;
        if (!isError) {
            txtValidFrom.focus();
            isError = true;
        }
        txtValidFrom.style.backgroundColor = 'lightyellow';
    }

    if (isError) {
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        return !isError;
    }

}

//*************************************Lease Management*******************************************************************/

var AlertEntertxtcontractfrom = "Please enter the Contract Period From";
var AlertEntertxtContractTo = "Please enter the Contract Period To";
var AlertEnterExpNotifyLevel1 = "Please enter the Expiry Notification Level1.";
var AlertEnterExpNotifyLevel2 = "Please enter the Expiry Notification Level2";
var AlertEntertxtKmMonth = "Please enter the Monthly Running Distance Limit";
var AlertEntertxtEngineHrs = "Please enter the Monthly Running Hours Limit";

function ValidateLeaseAssignmentSettings() {
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    var txtcontractfrom = document.getElementById('txtEffectiveFrom');
    var txtContractTo = document.getElementById('txtEffectiveTo');
    var ddlExpNotificationType = document.getElementById('ddlExpNotificationType');
    var txtExpNotifyLevel1 = document.getElementById('txtExpNotifyLevel1');
    var txtExpNotifyLevel2 = document.getElementById('txtExpNotifyLevel2');
    var txtRunningDistLimit = document.getElementById('txtRunningDistLimit');
    var txtEngineHrsLimit = document.getElementById('txtEngineHrsLimit');

    if (RemoveSpaces(txtcontractfrom).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEntertxtcontractfrom;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtcontractfrom;
        }
        txtcontractfrom.style.backgroundColor = 'lightyellow';
    }
    else {
        txtcontractfrom.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtContractTo).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEntertxtContractTo;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtContractTo;
        }
        txtContractTo.style.backgroundColor = 'lightyellow';
    }
    else {
        txtContractTo.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtExpNotifyLevel1).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterExpNotifyLevel1;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtExpNotifyLevel1;
        }
        txtExpNotifyLevel1.style.backgroundColor = 'lightyellow';
    }
    else {
        txtExpNotifyLevel1.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtExpNotifyLevel2).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterExpNotifyLevel2;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtExpNotifyLevel2;
        }
        txtExpNotifyLevel2.style.backgroundColor = 'lightyellow';
    }
    else {
        txtExpNotifyLevel2.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtRunningDistLimit).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEntertxtKmMonth;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtRunningDistLimit;
        }
        txtRunningDistLimit.style.backgroundColor = 'lightyellow';
    }
    else {
        txtRunningDistLimit.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtEngineHrsLimit).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEntertxtEngineHrs;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtEngineHrsLimit;
        }
        txtEngineHrsLimit.style.backgroundColor = 'lightyellow';
    }
    else {
        txtEngineHrsLimit.style.backgroundColor = 'white';
    }

    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        return true;
    }
}
//*************************************Temp User vehicle tracking*******************************************************************/

var AlertEntertxtcontractfrom = "Please enter the Contract Period From";
var AlertEntertxtContractTo = "Please enter the Contract Period To";
var AlertEnterMobileNo = "Please enter the MobileNo.";
var AlertEnterEmail = "Please enter the EmailID";
var AlertEnterRemakrs = "Please enter the Remarks";

function ValidateTempUserVehicleAssignmentSettings() {
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    var txtcontractfrom = document.getElementById('txtEffectiveFrom');
    var txtContractTo = document.getElementById('txtRouteEndDate');
    var txtEmail = document.getElementById('txtEmail');
    var txtMobile = document.getElementById('txtMobile');
    var txtRemarks = document.getElementById('txtRemarks');


    if (RemoveSpaces(txtcontractfrom).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEntertxtcontractfrom;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtcontractfrom;
        }
        txtcontractfrom.style.backgroundColor = 'lightyellow';
    }
    else {
        txtcontractfrom.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtContractTo).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEntertxtContractTo;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtContractTo;
        }
        txtContractTo.style.backgroundColor = 'lightyellow';
    }
    else {
        txtContractTo.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(txtEmail).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEmailId;
        if (!isError) {
            txtEmail.focus();
            isError = true;
        }
        txtEmail.style.backgroundColor = 'lightyellow';
    }

    else if (!validateEmail(txtEmail.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + Alert_ValidEmail;
        if (!isError) {
            controlToBeFocused = txtEmail;
        }
        isError = true;
        txtEmail.style.backgroundColor = 'lightyellow';
    }
    else {
        txtEmail.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtMobile).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterMobileNo;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtMobile;
        }
        txtMobile.style.backgroundColor = 'lightyellow';
    }
    else {
        txtMobile.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtRemarks).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterRemakrs;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtRemarks;
        }
        txtRemarks.style.backgroundColor = 'lightyellow';
    }
    else {
        txtRemarks.style.backgroundColor = 'white';
    }


    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        return true;
    }
}
function ValidateTempUserVehicleUnAssignmentSettings() {
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    var txtRemarks = document.getElementById('txtVehUnassignRemarks');


    if (RemoveSpaces(txtRemarks).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterRemakrs;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtRemarks;
        }
        txtRemarks.style.backgroundColor = 'lightyellow';
    }
    else {
        txtRemarks.style.backgroundColor = 'white';
    }


    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        return true;
    }
}
//*************************************Refrigeration Management*******************************************************************/

function ValidateRefrigerationInformation() {

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

    var Refname = document.getElementById('txtRefrigName');
    var Purchasedate = document.getElementById('txtPurchasedDate1');
    var Purchasedate = document.getElementById('txtAverageFuel');

    if (RemoveSpaces(Refname).length == 0) {
        isError = true;
        controlToBeFocused = Refname;
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 'Please enter the Refrigeration Name.';
    }
    if (RemoveSpaces(Purchasedate).length == 0) {
        isError = true;
        controlToBeFocused = Purchasedate;
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 'Please enter the Average Fuel Consumption.';
    }
    if (RemoveSpaces(Purchasedate).length == 0) {
        isError = true;
        controlToBeFocused = Purchasedate;
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 'Please enter the Purchase Date.';
    }
    if (isError) {
        TrinetraCustomAlerts(alertMessage);
        controlToBeFocused.focus();
        return false;
    }
    else {
        return true;
    }
}

function ValidateRefDuplicate(btn) {

    var hdnRefVehicles = document.getElementById('hdnRefVehicles').value;
    //    var ddlVehicle = ddlVehicle.GetValueString();
    //  if (ddlVehicle != "- Select -") {
    if (hdnRefVehicles == "1") {

        return TrinetraConfirm(btn, 'Are you want to Re-Assign Refrigerator?');

    }
    else { return true; }
    //}
    //else { return true; } 

}

//******************Tyre Vendor Master *********************

var AlertselectVendorId = "Please VendorId Should not be empty";
var AlertTyreVenName = "Please enter Name.";
var AlertAddress = "Please enter Address.";
var AlertContactNo = "Please enter Contact Number.";
var AlertEmailId = "Please enter EmailId.";
var AlertValidContactNo = "Please enter valid Contact Number.";

function ValidateTyreVendor() {

    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';
    var txtVendorId = document.getElementById('txtVendorId');
    var txtVenName = document.getElementById('txtVenName');
    var txtAddress = document.getElementById('txtAddress');
    var txtContactNo = document.getElementById('txtContactNo');
    var txtEmailId = document.getElementById('txtEmailId');
    var txtEmailId1 = document.getElementById('txtEmailId1');
    var txtEmailId2 = document.getElementById('txtEmailId2');




    //    if (RemoveSpaces(txtVendorId).length == 0) {
    //        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertselectVendorId;
    //        if (!isError) {
    //            txtVendorId.focus();
    //            isError = true;
    //        }
    //        txtVendorId.style.backgroundColor = 'lightyellow';
    //    }
    if (RemoveSpaces(txtVenName).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertTyreVenName;
        if (!isError) {
            txtVenName.focus();
            isError = true;
        }
        txtVenName.style.backgroundColor = 'lightyellow';
    }
    else {
        txtVenName.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(txtAddress).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertAddress;
        if (!isError) {
            txtAddress.focus();
            isError = true;
        }
        txtAddress.style.backgroundColor = 'lightyellow';
    }
    else {
        txtAddress.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(txtContactNo).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertContactNo;
        if (!isError) {
            txtContactNo.focus();
            isError = true;
        }
        txtContactNo.style.backgroundColor = 'lightyellow';
    }
    else if (RemoveSpaces(txtContactNo).length < 10) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertValidContactNo;
        if (!isError) {
            txtContactNo.focus();
            isError = true;
        }
        txtContactNo.style.backgroundColor = 'lightyellow';
    }
    else {
        txtContactNo.style.backgroundColor = 'white';
    }


    if (RemoveSpaces(txtEmailId).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEmailId;
        if (!isError) {
            txtEmailId.focus();
            isError = true;
        }
        txtEmailId.style.backgroundColor = 'lightyellow';
    }

    else if (!validateEmail(txtEmailId.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + Alert_ValidEmail;
        if (!isError) {
            controlToBeFocused = txtEmailId;
        }
        isError = true;
        txtEmailId.style.backgroundColor = 'lightyellow';
    }
    else {
        txtEmailId.style.backgroundColor = 'white';
    }

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

        if (!validateEmail(txtEmailId1.value)) {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + Alert_ValidEmail;
            if (!isError) {
                controlToBeFocused = txtEmailId1;
            }
            isError = true;
            txtEmailId1.style.backgroundColor = 'lightyellow';
        }
        else {
            txtEmailId1.style.backgroundColor = 'white';
        }
    }
    else {

        txtEmailId1.style.backgroundColor = 'white';
    }

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

        if (!validateEmail(txtEmailId2.value)) {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + Alert_ValidEmail;
            if (!isError) {
                controlToBeFocused = txtEmailId2;
            }
            isError = true;
            txtEmailId2.style.backgroundColor = 'lightyellow';
        }
        else {
            txtEmailId2.style.backgroundColor = 'white';
        }
    }
    else {

        txtEmailId2.style.backgroundColor = 'white';
    }



    if (isError) {
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        return !isError;
    }


}


//******************Tyre Master *********************

var AlertselectTyreId = "Please TyreId Should not be empty";
var AlertVenName = "Please Select Vendor Name.";
var AlertBillNo = "Please enter Bill No.";
var AlertBrandName = "Please Select Brand Name.";
var AlertQuantity = "Please enter Quantity.";
var AlertPurcahseDate = "Please enter Purchase Date.";
var AlertCost = "Please enter Cost of the Tyre.";
var AlertQuantityValue = "Quantity Should not be 0."

//ddlVendorName
//txtBillNo
//txtBrandName
//txtQuantity
//txtCost
//txtDateOfJoining

function ValidateTyreMaster() {

    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';
    var txtTyreId = document.getElementById('txtTyreId');
    var ddlVendorName = document.getElementById('ddlVendorName');
    var txtBillNo = document.getElementById('txtBillNo');
    var ddlBrandName = document.getElementById('ddlBrandName');
    var txtQuantity = document.getElementById('txtQuantity');
    var txtCost = document.getElementById('txtCost');
    var PurcahseDate = document.getElementById('txtDateOfJoining');

    if (RemoveSpaces(txtTyreId).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertselectTyreId;
        if (!isError) {
            txtTyreId.focus();
            isError = true;
        }
        txtTyreId.style.backgroundColor = 'lightyellow';
    }
    else {
        txtTyreId.style.backgroundColor = 'white';
    }

    if (!CheckIsSelected(ddlVendorName.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertVenName;
        if (!isError) {
            isError = true;
        }

        ddlVendorName.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlVendorName.style.backgroundColor = 'white';
    }

    if (!CheckIsSelected(ddlBrandName.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertBrandName;
        if (!isError) {
            ddlBrandName.focus();
            isError = true;
        }
        ddlBrandName.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlBrandName.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(txtQuantity).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertQuantity;
        if (!isError) {
            txtQuantity.focus();
            isError = true;
        }
        txtQuantity.style.backgroundColor = 'lightyellow';
    }
    else if (document.getElementById('txtQuantity').value == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertQuantityValue;
        if (!isError) {
            controlToBeFocused = txtQuantity;
        }
        isError = true;
        txtQuantity.style.backgroundColor = 'lightyellow';
    }
    else {
        txtQuantity.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtCost).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertCost;
        if (!isError) {
            txtCost.focus();
            isError = true;
        }
        txtCost.style.backgroundColor = 'lightyellow';
    }
    else {
        txtCost.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(PurcahseDate).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertPurcahseDate;
        if (!isError) {
            PurcahseDate.focus();
            isError = true;
        }
        PurcahseDate.style.backgroundColor = 'lightyellow';
    }
    else {
        PurcahseDate.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtBillNo).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertBillNo;
        if (!isError) {
            txtBillNo.focus();
            isError = true;
        }
        txtBillNo.style.backgroundColor = 'lightyellow';
    }
    else {
        txtBillNo.style.backgroundColor = 'white';
    }

    if (isError) {
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        return !isError;
    }
}


//var AlertselectTyreId = "Please TyreId Should not be empty";
var AlertVehiclName = "Please Select Device Name.";
var AlertTyre = "Please Select TyreID.";
var AlertVendorName = "Please Select Vendor Name.";
var AlertBrandName = "Please Select Brand Name.";
var AlertModel = "Please Select Model.";
var AlertAxle = "Please Select Axle.";
var AlertLocation = "Please Select Tyre Location.";
var AlertPurcahseDate1 = "Please enter Tyre Mapped Date.";
var AlertTyreName = "Please enter Tyre Name";

function ValidateTyreMapping() {

    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';
    var ddlVendorName1 = document.getElementById('ddlVendorName');
    var txtTyreId = document.getElementById('ddlTyre');
    var ddlModelName = document.getElementById('ddlModel');
    var txtTyreName = document.getElementById('txtTyreName');
    var ddlVehicleName = document.getElementById('ddlVehicleName');
    var Axle = document.getElementById('ddlAxle');
    var Location = document.getElementById('ddlLocation');
    var PurcahseDate = document.getElementById('txtDateOfJoining');

    if (!CheckIsSelected(ddlVehicleName.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertVehiclName;
        if (!isError) {
            isError = true;
        }

        ddlVehicleName.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlVehicleName.style.backgroundColor = 'white';
    }

    if (!CheckIsSelected(ddlVendorName1.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertVendorName;
        if (!isError) {
            isError = true;
        }

        ddlVendorName1.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlVendorName1.style.backgroundColor = 'white';
    }

    if (!CheckIsSelected(txtTyreId.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertBrandName;
        if (!isError) {
            isError = true;
        }

        txtTyreId.style.backgroundColor = 'lightyellow';
    }
    else {
        txtTyreId.style.backgroundColor = 'white';
    }

    if (!CheckIsSelected(ddlModelName.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertModel;
        if (!isError) {
            isError = true;
        }

        ddlModelName.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlModelName.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtTyreName).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertTyreName;
        if (!isError) {
            txtTyreName.focus();
            isError = true;
        }
        txtTyreName.style.backgroundColor = 'lightyellow';
    }
    else {
        txtTyreName.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(PurcahseDate).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertPurcahseDate1;
        if (!isError) {
            PurcahseDate.focus();
            isError = true;
        }
        PurcahseDate.style.backgroundColor = 'lightyellow';
    }
    else {
        PurcahseDate.style.backgroundColor = 'white';
    }

    if (!CheckIsSelected(Axle.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertAxle;
        if (!isError) {
            isError = true;
        }

        Axle.style.backgroundColor = 'lightyellow';
    }
    else {
        Axle.style.backgroundColor = 'white';
    }


    if (!CheckIsSelected(Location.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertLocation;
        if (!isError) {
            isError = true;
        }

        Location.style.backgroundColor = 'lightyellow';
    }
    else {
        Location.style.backgroundColor = 'white';
    }



    if (isError) {
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        return !isError;
    }
}




function ValidateTyreSwapping() {


    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';
    //var txtTyreId = document.getElementById('ddlTyre');
    var ddlVehicleName = document.getElementById('ddlToVehicleNames');
    var Axle = document.getElementById('ddlToAxle');
    var Location = document.getElementById('ddlToLocation');
    //var PurcahseDate = document.getElementById('txtDateOfJoining');

    if (!CheckIsSelected(ddlVehicleName.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertVehiclName;
        if (!isError) {
            isError = true;
        }

        ddlVehicleName.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlVehicleName.style.backgroundColor = 'white';
    }

    if (!CheckIsSelected(Axle.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertAxle;
        if (!isError) {
            isError = true;
        }

        Axle.style.backgroundColor = 'lightyellow';
    }
    else {
        Axle.style.backgroundColor = 'white';
    }


    if (!CheckIsSelected(Location.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertLocation;
        if (!isError) {
            isError = true;
        }

        Location.style.backgroundColor = 'lightyellow';
    }
    else {
        Location.style.backgroundColor = 'white';
    }

    if (isError) {
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        return !isError;
    }




}

var Alert_EnterTyreMakeName = "Please enter the Brand Name."
function ValidationTyreMakeEntry() {
    var makeName = document.getElementById('txtMakeName');
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    if (RemoveSpaces(makeName).length == 0) {

        alertMessage += (alertMessage.length == 0 ? '' : '</br>') + Alert_EnterTyreMakeName;
        if (!isError) {
            isError = true;
            controlToBeFocused = makeName;
        }

        makeName.style.backgroundColor = 'lightyellow';
    }
    else {
        makeName.style.backgroundColor = 'white';
    }

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


var Alert_SelecTyreMakeName = "Please select the Brand Name.";
var Alert_EnterTyreModelName = "Please enter the Model Name.";

// Tyre Model
function ValidationTyreModelEntry() {

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

    if ((makeName.value == "- Select -") || (makeName.value == "- اختر -")) {
        alertMessage = Alert_SelecTyreMakeName;
        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 ? '' : '</br>') + Alert_EnterTyreModelName;
        if (!isError) {
            isError = true;
            controlToBeFocused = modelName;
        }

        modelName.style.backgroundColor = 'lightyellow';
    }
    else {
        modelName.style.backgroundColor = 'white';
    }

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

var Alert_RemoveComment = "Please enter the Reason for Removing Tyre.";

function ValidateRemoveComment() {

    var txtComment = document.getElementById('txtComment');

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

    if (RemoveSpaces(txtComment).length == 0) {

        alertMessage += (alertMessage.length == 0 ? '' : '</br>') + Alert_RemoveComment;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtComment;
        }

        txtComment.style.backgroundColor = 'lightyellow';
    }
    else {
        txtComment.style.backgroundColor = 'white';
    }

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

var Alert_LifetimeKM = "Please enter the Lifetime(KM) for Retreaded Tyre.";

function ValidateLifetimeKM() {

    var txtComment = document.getElementById('txtLifeTimeRethread');

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

    if (RemoveSpaces(txtComment).length == 0) {

        alertMessage += (alertMessage.length == 0 ? '' : '</br>') + Alert_LifetimeKM;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtComment;
        }

        txtComment.style.backgroundColor = 'lightyellow';
    }
    else {
        txtComment.style.backgroundColor = 'white';
    }

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

}


/******************************************************Fuelonsumption*********************************************/
function ValidateFuelInformation() {
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    var Mode = 2; //document.getElementById('ddlManageFuel').value;
    var ddl = document.getElementById('ddlRefrigerator').value;
    var ddlRefrigerator = document.getElementById('ddlRefrigerator');
    var meterReading = document.getElementById('txtmeterReading');
    var curCon = document.getElementById('txtCurrentConsumption');
    var varince = document.getElementById('txtVariance');
    var excess = document.getElementById('txtExcessLessQty');
    var FuelQty = document.getElementById('txtfuelQty');
    var date = document.getElementById('txtPurchasedDate1');

    if (ddl == "- Select -") {
        alertMessage = 'Please select the Refrigerator.';
        isError = true;
        document.getElementById("ddlRefrigerator").focus();
        // ddlVehicleName.style.backgroundColor = 'lightyellow';
        controlToBeFocused = ddlRefrigerator;
    }

    if (RemoveSpaces(meterReading).length == 0) {
        isError = true;
        controlToBeFocused = meterReading;
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 'Please enter the Meter Reading.';
    }
    if (RemoveSpaces(date).length == 0) {
        isError = true;
        controlToBeFocused = date;
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 'Please select the Date.';
    }


    if (RemoveSpaces(FuelQty).length == 0) {
        isError = true;
        controlToBeFocused = FuelQty;
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 'Please enter the Fuel Quantity.';
    }


    //    if (RemoveSpaces(curCon).length == 0) {
    //        isError = true;
    //        controlToBeFocused = curCon;
    //        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 'Current Consumption missing! please enter valid data';
    //    }

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


}

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

/* Advanced History Alerts */

var Alert_MaximumTrips, Alert_AtleastOneTrip;
function SetAdvanceHistoryAlerts(alertMaxTrips, alertOneTrip) {
    Alert_MaximumTrips = alertMaxTrips;
    Alert_AtleastOneTrip = alertOneTrip;
}

/*****************************************************************************************/
//************************************VOR Master Details************************************

var AlertSelectFleet = "Please select the Fleet";
var AlertSelectVehicle = "Please select the Device.";
var AlertEnterDateFrom = "Please select the Date From.";
var AlertEnterDateTo = "Please select the Date To.";
var AlertEnterReason = "Please enter the Reason.";


function ValidateVORDetails() {

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

    var dtCurrentDate = new Date();

    var ddlFleet = document.getElementById('ddlFleet');
    var ddlVehicle = document.getElementById('ddlVehicle');
    var txtcontractfrom = document.getElementById('txtcontractfrom');
    var txtContractTo = document.getElementById('txtContractTo');
    var txtReason = document.getElementById('txtReason');

    if (ddlFleet != null) {
        if (!CheckIsSelected(ddlFleet.value)) {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertSelectFleet;
            isError = true;
            controlToBeFocused = ddlFleet;
            ddlFleet.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlFleet.style.backgroundColor = 'white';
        }
    }
    if (ddlVehicle != null) {
        if (!CheckIsSelected(ddlVehicle.value)) {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertSelectVehicle;
            isError = true;
            controlToBeFocused = ddlVehicle;
            ddlVehicle.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlVehicle.style.backgroundColor = 'white';
        }
    }
    if (RemoveSpaces(txtcontractfrom).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterDateFrom;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtcontractfrom;
        }
        txtcontractfrom.style.backgroundColor = 'lightyellow';
    }
    else {
        txtcontractfrom.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtContractTo).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterDateTo;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtContractTo;
        }
        txtContractTo.style.backgroundColor = 'lightyellow';
    }
    else {
        txtContractTo.style.backgroundColor = 'white';
    }

    if (RemoveSpaces(txtReason).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterReason;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtReason;
        }
        txtReason.style.backgroundColor = 'lightyellow';
    }
    else {
        txtReason.style.backgroundColor = 'white';
    }
    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        return true;
    }
}

/*****************************************************************************************/
/* Ador Powertron Pages Validation */
/*****************************************************************************************/

function ValidateDeviceInfo(ctrl) {

    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';
    //  var ddlBoxId = document.getElementById('ddlBoxId');
    var txtEquipID = document.getElementById('txtdeviceID');
    var txtEquipName = document.getElementById('txtEquipName');
    var ddlEquiptype = document.getElementById('ddlEquiptype');
    //var ddlequipsubtype = document.getElementById('ddlequipsubtype');
    //var txtPurchase = document.getElementById('txtPurchasedDate');
    var ddlCategory = document.getElementById('ddlGateway');
    //  var txtEmail = document.getElementById('txtEmail');
    // var txtContactNo = document.getElementById('txtContactNo');
    //var rbnlAMC_0 = document.getElementById('rbnlAMC_0');
    //var txtAMCStrtDt = document.getElementById('txtAMCStrtDt');
    //var txtAMCEndDt = document.getElementById('txtAMCEndDt');
    //var txtWrntyStrtdt = document.getElementById('txtWrntyStrtdt');
    //var txtWrntyEndDt = document.getElementById('txtWrntyEndDt');
    //var rdlEnergy = document.getElementById('rdlenergy');
    //var btnshift = document.getElementById('lnkshiftdetails');



    //var ts1 = document.getElementById("txtsft1s");
    //var ts2 = document.getElementById("txtsft2s");
    //var ts3 = document.getElementById("txtsft3s");
    //var ts4 = document.getElementById("txtsft4s");
    //var ts5 = document.getElementById("txtsft5s");
    //var ts6 = document.getElementById("txtsft6s");

    //var S1 = document.getElementById("shift1");
    //var S2 = document.getElementById("shift2");
    //var S3 = document.getElementById("shift3");
    //var S4 = document.getElementById("shift4");
    //var S5 = document.getElementById("shift5");
    //var S6 = document.getElementById("shift6");

    var dtCurrentDate = new Date();

    //if (ddlBoxId != null) {
    //    if (ddlBoxId.value == '0') {
    //        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please select the Device ID.";
    //        isError = true;
    //        controlToBeFocused = ddlBoxId;
    //        ddlBoxId.style.backgroundColor = 'lightyellow';
    //    }
    //    else {
    //        ddlBoxId.style.backgroundColor = 'white';
    //    }
    //}
    if (txtEquipID.style.display == "block") {
        if (txtEquipID.value == 0) {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Device ID.";
            if (!isError) {
                isError = true;
                controlToBeFocused = txtEquipID;
            }
            txtEquipID.style.backgroundColor = 'lightyellow';
        }
            //else if (!txtEquipID.value.match(/^[a-zA-Z]{2}[0-9]{4}$/)) {
            //    alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter a valid Device ID (e.g AA0001)";
            //    if (!isError) {
            //        isError = true;
            //        controlToBeFocused = txtEquipID;
            //    }
            //}
        else {
            txtEquipID.style.backgroundColor = 'white';
        }
    }
    if (ddlEquiptype != null) {
        if (ddlEquiptype.value == '0') {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please select the Device Type.";
            isError = true;
            controlToBeFocused = ddlEquiptype;
            ddlEquiptype.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlEquiptype.style.backgroundColor = 'white';
        }
    }
    if (txtEquipName != null) {
        if (RemoveSpaces(txtEquipName).length == 0) {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Device Name.";
            if (!isError) {
                isError = true;
                controlToBeFocused = txtEquipName;
            }
            txtEquipName.style.backgroundColor = 'lightyellow';
        }
        else {
            txtEquipName.style.backgroundColor = 'white';
        }
    }
    //if (ddlequipsubtype != null) {
    //    if (!CheckIsSelected(ddlequipsubtype.value)) {
    //        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please select the ESP SubType.";
    //        isError = true;
    //        controlToBeFocused = ddlequipsubtype;
    //        ddlequipsubtype.style.backgroundColor = 'lightyellow';
    //    }
    //    else {
    //        ddlequipsubtype.style.backgroundColor = 'white';
    //    }
    //}

    //if (RemoveSpaces(txtPurchase).length == 0) {
    //    alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please select the Date of Commissioning.";
    //    if (!isError) {
    //        isError = true;
    //        controlToBeFocused = txtPurchase;
    //    }
    //    txtPurchase.style.backgroundColor = 'lightyellow';
    //}
    //else {
    //    txtPurchase.style.backgroundColor = 'white';
    //}
    if (ddlCategory != null) {
        if (ddlCategory.value == '0') {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please select the GateawayID.";
            isError = true;
            controlToBeFocused = ddlCategory;
            ddlCategory.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlCategory.style.backgroundColor = 'white';
        }
    }
    //if (RemoveSpaces(txtEmail).length == 0) {
    //    alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Email Id";
    //    if (!isError) {
    //        isError = true;
    //        //controlToBeFocused = txtEmail;
    //    }
    //    txtEmail.style.backgroundColor = 'lightyellow';
    //}
    //else {
    //    txtEmail.style.backgroundColor = 'white';
    //}
    //if (RemoveSpaces(txtContactNo).length == 0) {
    //    alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Contact no";
    //    if (!isError) {
    //        isError = true;
    //        controlToBeFocused = txtContactNo;
    //    }
    //    txtContactNo.style.backgroundColor = 'lightyellow';
    //}
    //else {
    //    txtContactNo.style.backgroundColor = 'white';
    //}
    //if (RemoveSpaces(txtWrntyStrtdt).length == 0) {
    //    alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Warranty Start Date";
    //    if (!isError) {
    //        isError = true;
    //        controlToBeFocused = txtWrntyStrtdt;
    //    }
    //    txtWrntyStrtdt.style.backgroundColor = 'lightyellow';
    //}
    //else {
    //    txtWrntyStrtdt.style.backgroundColor = 'white';
    //}
    //if (RemoveSpaces(txtWrntyEndDt).length == 0) {
    //    alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Warranty End Date";
    //    if (!isError) {
    //        isError = true;
    //        controlToBeFocused = txtWrntyEndDt;
    //    }
    //    txtWrntyEndDt.style.backgroundColor = 'lightyellow';
    //}
    //else {
    //    txtWrntyEndDt.style.backgroundColor = 'white';
    //}

    //if (RemoveSpaces(ts1).length == 0) {
    //    alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Shift details";
    //    if (!isError) {
    //        isError = true;
    //        controlToBeFocused = btnshift;
    //    }
    //    btnshift.style.backgroundColor = 'lightyellow';
    //}
    //else {
    //    btnshift.style.backgroundColor = 'white';
    //}

    //if (document.getElementById('rbnlAMC_0').checked) {
    //    if (RemoveSpaces(txtAMCStrtDt).length == 0) {
    //        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please select the AMC Start Date";
    //        if (!isError) {
    //            isError = true;
    //            controlToBeFocused = txtAMCStrtDt;
    //        }
    //        txtAMCStrtDt.style.backgroundColor = 'lightyellow';
    //    }
    //    else {
    //        txtAMCStrtDt.style.backgroundColor = 'white';
    //    }
    //    if (RemoveSpaces(txtAMCEndDt).length == 0) {
    //        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please select the AMC End Date";
    //        if (!isError) {
    //            isError = true;
    //            controlToBeFocused = txtAMCEndDt;
    //        }
    //        txtAMCEndDt.style.backgroundColor = 'lightyellow';
    //    }
    //    else {
    //        txtAMCEndDt.style.backgroundColor = 'white';
    //    }
    //}
    if (!CheckSeveritySelection('chkSeverities')) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 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 (document.getElementById("rdlenergy_0").checked == false && document.getElementById("rdlenergy_1").checked == false) {
    //    alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please select the energy consumption";
    //    if (!isError) {
    //        isError = true;
    //        controlToBeFocused = rdlEnergy;
    //    }
    //    rdlEnergy.style.backgroundColor = 'lightyellow';
    //}
    //else if (document.getElementById("rdlenergy_0").checked == true) {
    //    if (S1.style.display == "block") {
    //        if (RemoveSpaces(ts1).length == 0) {
    //            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Shift 1 Start Date";
    //            if (!isError) {
    //                isError = true;
    //                controlToBeFocused = ts1;
    //            }
    //            ts1.style.backgroundColor = 'lightyellow';
    //        }
    //    }

    //}
    if (isError) {
        if (controlToBeFocused != null)
            controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        return TrinetraConfirm(ctrl, "Are you sure you want to save this Device?");
    }
}
/********************************************/
//---Shift Validation -----------------------/
/********************************************/
function ValidateShift() {
    //lnkenergy
    var btnsave = document.getElementById("lnkenergy");
    var ts1 = document.getElementById("txtsft1s");
    var ts2 = document.getElementById("txtsft2s");
    var ts3 = document.getElementById("txtsft3s");
    var ts4 = document.getElementById("txtsft4s");
    var ts5 = document.getElementById("txtsft5s");
    var ts6 = document.getElementById("txtsft6s");

    var te1 = document.getElementById("txtsft1e");
    var te2 = document.getElementById("txtsft2e");
    var te3 = document.getElementById("txtsft3e");
    var te4 = document.getElementById("txtsft4e");
    var te5 = document.getElementById("txtsft5e");
    var te6 = document.getElementById("txtsft6e");
    var btn = document.getElementById("lnkenergy");


    var Shift1 = document.getElementById("shift1");
    var Shift2 = document.getElementById("shift2");
    var Shift3 = document.getElementById("shift3");
    var Shift4 = document.getElementById("shift4");
    var Shift5 = document.getElementById("shift5");
    var Shift6 = document.getElementById("shift6");
    var end, start; var diffDays;

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

    if (RemoveSpaces(ts1).length == 0 || RemoveSpaces(te1).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Shift 1 Start Time & End Time";
        if (!isError) {
            isError = true;
            //controlToBeFocused = ts1;
        }
        ts1.style.backgroundColor = 'lightyellow';
    }
    else {
        start = new Date("1/1/2018 " + ts1.value);
        end = new Date("1/1/2018 " + te1.value);
        diffDays = end.getTime() - start.getTime();
        if (diffDays < 0 || diffDays == 0) {
            //let alt = TrinetraConfirm(1, 'Shift 1 end time lesser then shift 1 start time, are your end time consider next day.');
            let alt = confirm('Shift 1 end time is lesser then Shift 1 start time. Are you sure you  want to set end time as next day?');
            if (alt == true) {
                end = new Date("1/2/2018 " + te1.value);
                diffDays = end.getTime() - start.getTime();
                //return true;
            }
            else {
                return false;
            }
        }
        let result = Math.abs(diffDays);
        if (result < 10800000) {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please provide 3 Hrs between the Shift 1 end time";
            if (!isError) {
                isError = true;
                //controlToBeFocused = ts1;
            }
            ts1.style.backgroundColor = 'lightyellow';
        }
    }
    if (Shift2.style.display == "block") {
        if (RemoveSpaces(ts2).length == 0 || RemoveSpaces(te2).length == 0) {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Shift 2 Start Time & End Time";
            if (!isError) {
                isError = true;
                //controlToBeFocused = ts2;
            }
            ts2.style.backgroundColor = 'lightyellow';
        }
        else if (ts1.value != te2.value) {
            var starts2 = new Date("1/1/2018 " + ts2.value);
            var ends2 = new Date("1/1/2018 " + te2.value);
            var diffDayss1 = ends2.getTime() - starts2.getTime();
            let result1 = Math.abs(diffDayss1);
            if (result1 < 10800000) {
                alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please provide 3 Hrs between the Shift 2 end time";
                if (!isError) {
                    isError = true;
                    //controlToBeFocused = ts1;
                }
                ts2.style.backgroundColor = 'lightyellow';
            }
        }
    }
    if (Shift3.style.display == "block") {
        if (RemoveSpaces(ts3).length == 0 || RemoveSpaces(te3).length == 0) {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Shift 3 Start Time & End Time";
            if (!isError) {
                isError = true;
                //controlToBeFocused = ts3;
            }
            ts3.style.backgroundColor = 'lightyellow';
        }
        else if (ts1.value != te3.value) {
            var starts3 = new Date("1/1/2018 " + ts3.value);
            var ends3 = new Date("1/1/2018 " + te3.value);
            var diffDayss2 = ends3.getTime() - starts3.getTime();
            let result2 = Math.abs(diffDayss2);
            if (result2 < 10800000) {
                alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please provide 3 Hrs between the Shift 3 end time";
                if (!isError) {
                    isError = true;
                    //controlToBeFocused = ts1;
                }
                ts3.style.backgroundColor = 'lightyellow';
            }
        }
    }
    if (Shift4.style.display == "block") {
        if (RemoveSpaces(ts4).length == 0 || RemoveSpaces(te4).length == 0) {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Shift 4 Start Time & End Time";
            if (!isError) {
                isError = true;
                //controlToBeFocused = ts4;
            }
            ts4.style.backgroundColor = 'lightyellow';
        }
        else if (ts1.value != te4.value) {
            var starts4 = new Date("1/1/2018 " + ts4.value);
            var ends4 = new Date("1/1/2018 " + te4.value);
            var diffDayss3 = ends4.getTime() - starts4.getTime();
            let result3 = Math.abs(diffDayss3);
            if (result3 < 10800000) {
                alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please provide 3 Hrs between the Shift 4 end time";
                if (!isError) {
                    isError = true;
                    //controlToBeFocused = ts1;
                }
                ts4.style.backgroundColor = 'lightyellow';
            }
        }
    }
    if (Shift5.style.display == "block") {
        if (RemoveSpaces(ts5).length == 0 || RemoveSpaces(te5).length == 0) {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Shift 5 Start Time & End Time";
            if (!isError) {
                isError = true;
                //controlToBeFocused = ts5;
            }
            ts5.style.backgroundColor = 'lightyellow';
        }
        else if (ts1.value != te5.value) {
            var starts5 = new Date("1/1/2018 " + ts4.value);
            var ends5 = new Date("1/1/2018 " + te4.value);
            var diffDayss4 = ends5.getTime() - starts5.getTime();
            let result4 = Math.abs(diffDayss4);
            if (result4 < 10800000) {
                alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please provide 3 Hrs between the Shift 5 end time";
                if (!isError) {
                    isError = true;
                    //controlToBeFocused = ts1;
                }
                ts5.style.backgroundColor = 'lightyellow';
            }
        }
    }
    if (Shift6.style.display == "block") {
        if (RemoveSpaces(ts6).length == 0 || RemoveSpaces(te6).length == 0) {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Shift 6 Start Time & End Time";
            if (!isError) {
                isError = true;
                //controlToBeFocused = ts6;
            }
            ts6.style.backgroundColor = 'lightyellow';
        }
        else if (ts1.value != te6.value) {
            var starts6 = new Date("1/1/2018 " + ts6.value);
            var ends6 = new Date("1/1/2018 " + te6.value);
            var diffDayss5 = ends6.getTime() - starts6.getTime();
            let result5 = Math.abs(diffDayss5);
            if (result5 < 10800000) {
                alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please provide 5 Hrs between the Shift 6 end time";
                if (!isError) {
                    isError = true;
                    //controlToBeFocused = ts1;
                }
                ts6.style.backgroundColor = 'lightyellow';
            }
        }
    }
    if (isError) {
        if (controlToBeFocused != null)
            controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }

}
var AlertSelectEquipment = "Please select the Equipment";
var AlertSelectPassage = "Please select the Passage";
var AlertSelectField = "Please select the Field";
var AlertSelectDCSIM = "Please select the DCSIM";
var AlertSelectControllerLoc = "Please select the Controller Location";
var AlertSelectControllerId = "Please select the Controller ld";
var AlertEnterControllerName = "Please enter the Controller Name";
var AlertEnterControllerSrNo = "Please enter the Controller Sr No";
var AlertEnterWrtyStDate = "Please choose Warranty Start Date";
var AlertEnterWrtyEndDate = "Please choose Warranty End Date";

function ValidateControllerInfo(control) {
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    var ddlEquipment = document.getElementById('ddlEquipmentId');
    var ddlPassage = document.getElementById('ddlPassage');
    var ddlField = document.getElementById('ddlField');
    var ddlDSCIM = document.getElementById('ddlDCSIM');
    //var ddlControllerLocation = document.getElementById('ddlControllerLocation');
    var ddlControllerId = document.getElementById('ddlControllerId');
    var txtControllerName = document.getElementById('txtControllerName');
    var txtControllerSrNo = document.getElementById('txtControllerSrNo');
    var txtWarrantyStartDate = document.getElementById('txtWrntyStrtdt');
    var txtWarrantyEndDate = document.getElementById('txtWrntyEndDt');

    if (ddlEquipment != null) {
        if (ddlEquipment.value == '0') {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertSelectEquipment;
            isError = true;
            controlToBeFocused = ddlEquipment;
            ddlEquipment.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlEquipment.style.backgroundColor = 'white';
        }
    }
    if (ddlPassage != null) {
        if (ddlPassage.value == '0') {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertSelectPassage;
            isError = true;
            controlToBeFocused = ddlPassage;
            ddlPassage.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlPassage.style.backgroundColor = 'white';
        }
    }
    if (ddlField != null) {
        if (ddlField.value == '0') {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertSelectField;
            isError = true;
            controlToBeFocused = ddlField;
            ddlField.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlField.style.backgroundColor = 'white';
        }
    }
    if (ddlDSCIM != null) {
        if (ddlDSCIM.value == '0') {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertSelectDCSIM;
            isError = true;
            controlToBeFocused = ddlDSCIM;
            ddlDSCIM.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlDSCIM.style.backgroundColor = 'white';
        }
    }
    //if (ddlControllerLocation != null) {
    //    if (ddlControllerLocation.value == '0') {
    //        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertSelectControllerLoc;
    //        isError = true;
    //        controlToBeFocused = ddlControllerLocation;
    //        ddlControllerLocation.style.backgroundColor = 'lightyellow';
    //    }
    //    else {
    //        ddlControllerLocation.style.backgroundColor = 'white';
    //    }
    //}
    if (ddlControllerId != null) {
        if (ddlControllerId.value == '0') {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertSelectControllerId;
            isError = true;
            controlToBeFocused = ddlControllerId;
            ddlControllerId.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlControllerId.style.backgroundColor = 'white';
        }
    }
    if (RemoveSpaces(txtControllerName).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterControllerName;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtControllerName;
        }
        txtControllerName.style.backgroundColor = 'lightyellow';
    }
    else {
        txtControllerName.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(txtControllerSrNo).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterControllerSrNo;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtControllerSrNo;
        }
        txtControllerSrNo.style.backgroundColor = 'lightyellow';
    }
    else {
        txtControllerSrNo.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(txtWarrantyStartDate).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterWrtyStDate;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtWarrantyStartDate;
        }
        txtWarrantyStartDate.style.backgroundColor = 'lightyellow';
    }
    else {
        txtWarrantyStartDate.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(txtWarrantyEndDate).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterWrtyEndDate;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtWarrantyEndDate;
        }
        txtWarrantyEndDate.style.backgroundColor = 'lightyellow';
    }
    else {
        txtWarrantyEndDate.style.backgroundColor = 'white';
    }

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

var AlertEnterPopupDataName = "Name field cannot be empty!";

function ValidateControllerPopupInfo(control) {
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    var txtPopupDataName = document.getElementById('txtPassageName');


    if (RemoveSpaces(txtPopupDataName).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertEnterPopupDataName;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtPopupDataName;
        }
        txtPopupDataName.style.backgroundColor = 'lightyellow';
    }
    else {
        txtPopupDataName.style.backgroundColor = 'white';
    }

    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        return true;
    }
}
function ValidateParam() {

    var Espname = document.getElementById('ddlESP');
    var Controllername = document.getElementById('ddlController')
    var Parameter = document.getElementById('ddlParam');
    var Maximum = document.getElementById('txtmax');
    var Minimum = document.getElementById('txtMinvalue');

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

    if (Espname.value == 0) {
        alertMessage += (alertMessage.length == 0 ? '' : '</br>') + "Please select the Equipment Name";
        if (!isError) {
            Espname.focus();
            isError = true;
        }
        Espname.style.backgroundColor = 'lightyellow';
    }
    else {
        Espname.style.backgroundColor = 'white';
    }

    if (Controllername.value == 0) {
        alertMessage += (alertMessage.length == 0 ? '' : '</br>') + "Please select the Controller Name";
        if (!isError) {
            Controllername.focus();
            isError = true;
        }
        Controllername.style.backgroundColor = 'lightyellow';
    }
    else {
        Controllername.style.backgroundColor = 'white';
    }
    if (Parameter.value == 0) {
        alertMessage += (alertMessage.length == 0 ? '' : '</br>') + "Please select the Parameter";
        if (!isError) {
            Parameter.focus();
            isError = true;
        }
        Parameter.style.backgroundColor = 'lightyellow';
    }
    else {
        Parameter.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(Maximum).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter maximum value";
        if (!isError) {
            isError = true;
            Maximum.focus();
        }
        Maximum.style.backgroundColor = 'lightyellow';
    }
    else {
        Maximum.style.backgroundColor = 'white';
        //if (Maximum.value < Minimum.value || Maximum.value == Minimum.value) {
        //    alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Maximum value must be greater than minimum value.";
        //    //document.getElementById("txtMinvalue").value = "";
        //    isError = true;
        //}
        //else {
        //    Maximum.style.backgroundColor = 'white';
        //}

    }
    if (RemoveSpaces(Minimum).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter minimum value";
        if (!isError) {
            isError = true;
            Minimum.focus();
        }
        Minimum.style.backgroundColor = 'lightyellow';
    }
    else {
        if (parseInt(Minimum.value) > parseInt(Maximum.value) || parseInt(Minimum.value) == parseInt(Maximum.value)) {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Minimum value must be lesser than maximum value.";
            //document.getElementById("txtMinvalue").value = "";
            isError = true;
            Minimum.style.backgroundColor = 'lightyellow';
            Maximum.style.backgroundColor = 'lightyellow';
        }
        else {
            Minimum.style.backgroundColor = 'white';
        }
    }

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

//-----------Validation for Compactor -----------------------//

function ValidationCompactor(Ctrl) {

    var txtcompaxtorMno1 = document.getElementById("txtcompaxtorMno1");
    var txtcompaxtorMno2 = document.getElementById("txtcompaxtorMno2");
    var txtcompaxtorMno3 = document.getElementById("txtcompaxtorMno3");
    var txtcompaxtorMno4 = document.getElementById("txtcompaxtorMno4");

    var divfan1 = document.getElementById("divfan1");
    var divfan2 = document.getElementById("divfan2");
    var divfan3 = document.getElementById("divfan3");
    var divfan4 = document.getElementById("divfan4");

    var isvfan1 = document.getElementById('chkvfan1');
    var isvfan2 = document.getElementById('chkvfan2');
    var isvfan3 = document.getElementById('chkvfan3');
    var isvfan4 = document.getElementById('chkvfan4');

    var txtvfmodelno1 = document.getElementById("txtvfmodelno1");
    var txtvfmodelno2 = document.getElementById("txtvfmodelno2");
    var txtvfmodelno3 = document.getElementById("txtvfmodelno3");
    var txtvfmodelno4 = document.getElementById("txtvfmodelno4");
    var ddlfan = document.getElementById('ddlfan');
    var isError = false;
    var alertMessage = '';
    var controlToBeFocused;

    if (divfan1 != null && divfan1.style.display == "block") {
        if (txtcompaxtorMno1.value == 0) {
            alertMessage += (alertMessage.length == 0 ? '' : '</br>') + "Please enter the compactor 1 model#.";
            if (!isError) {
                txtcompaxtorMno1.focus();
                isError = true;
            }
            txtcompaxtorMno1.style.backgroundColor = 'lightyellow';
        }
        else {
            txtcompaxtorMno1.style.backgroundColor = 'white';
        }
        if (isvfan1.checked == true) {
            if (txtvfmodelno1.value == 0) {
                alertMessage += (alertMessage.length == 0 ? '' : '</br>') + "Please enter the Ventilator 1 model#.";
                if (!isError) {
                    txtvfmodelno1.focus();
                    isError = true;
                }
                //txtvfmodelno1.style.backgroundColor = 'lightyellow';
            }
        }
    }
    if (divfan2 != null && divfan2.style.display == "block") {

        if (txtcompaxtorMno2.value == 0) {
            alertMessage += (alertMessage.length == 0 ? '' : '</br>') + "Please enter the compactor 2 model#.";
            if (!isError) {
                txtcompaxtorMno2.focus();
                isError = true;
            }
            txtcompaxtorMno2.style.backgroundColor = 'lightyellow';
        }
        else {
            txtcompaxtorMno2.style.backgroundColor = 'white';
        }
        if (isvfan2.checked == true) {
            if (txtvfmodelno2.value == 0) {
                alertMessage += (alertMessage.length == 0 ? '' : '</br>') + "Please enter the Ventilator 2 model#.";
                if (!isError) {
                    txtvfmodelno2.focus();
                    isError = true;
                }
                //txtvfmodelno2.style.backgroundColor = 'lightyellow';
            }
        }
    }
    if (divfan3 != null && divfan3.style.display == "block") {

        if (txtcompaxtorMno3.value == 0) {
            alertMessage += (alertMessage.length == 0 ? '' : '</br>') + "Please enter the compactor 3 model#.";
            if (!isError) {
                txtcompaxtorMno3.focus();
                isError = true;
            }
            txtcompaxtorMno3.style.backgroundColor = 'lightyellow';
        }
        else {
            txtcompaxtorMno3.style.backgroundColor = 'white';
        }
        if (isvfan3.checked == true) {
            if (txtvfmodelno3.value == 0) {
                alertMessage += (alertMessage.length == 0 ? '' : '</br>') + "Please enter the Ventilator 3 model#.";
                if (!isError) {
                    txtvfmodelno3.focus();
                    isError = true;
                }
                //txtvfmodelno3.style.backgroundColor = 'lightyellow';
            }
        }
    }
    if (divfan4 != null && divfan4.style.display == "block") {

        if (txtcompaxtorMno4.value == 0) {
            alertMessage += (alertMessage.length == 0 ? '' : '</br>') + "Please enter the compactor 4 model#.";
            if (!isError) {
                txtcompaxtorMno4.focus();
                isError = true;
            }
            txtcompaxtorMno4.style.backgroundColor = 'lightyellow';
        }
        else {
            txtcompaxtorMno4.style.backgroundColor = 'white';
        }
        if (isvfan4.checked == true) {
            if (txtvfmodelno4.value == 0) {
                alertMessage += (alertMessage.length == 0 ? '' : '</br>') + "Please enter the Ventilator 4 model#.";
                if (!isError) {
                    txtvfmodelno4.focus();
                    isError = true;
                }
                //txtvfmodelno4.style.backgroundColor = 'lightyellow';
            }
        }
    }
    if (isError) {
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
        //else if (ddlfan.value == "0") {

        //    return TrinetraConfirm(Ctrl, "Are you sure you want to save this Device?");
        //    return true;
        //}
    else {
        ShowPopUp();
        return true;
    }
}

function validateDev(cont, str) {
    if (str.length > 0) {
        if (!str.match(/^[a-zA-Z]{2}[0-9]{4}$/)) {
            TrinetraCustomAlerts('Please enter a valid Device ID (e.g AA0001)');
            document.getElementById('txtdeviceID').style.backgroundColor = 'lightyellow';
        }
        else {
            document.getElementById('txtdeviceID').style.backgroundColor = 'white';
        }
    }
    else {
        document.getElementById('txtdeviceID').style.backgroundColor = 'white';
        return false;
    }


}

