
// Alerts

var selectGeozonesToAssign = "Select geozone(s) to be assigned !";
var maxGeozonesCount = "No. of geozones which has to be assigned should not exceed <#maxGeozones#> !";

// Set the alert messages from the Resource File
function SetAlertMessages(selectGeozonesToAssignAlert, maxGeozonesAlert) {
    selectGeozonesToAssign = selectGeozonesToAssignAlert;
    maxGeozonesCount = maxGeozonesAlert;
}

function OnGridSelectionChanged() {
    // if (counter != null) setInnerText(counter, grid.GetSelectedRowCount().toString());
    gvData.GetSelectedFieldValues('GeozoneNo', OnGridSelectionComplete);
}
function OnGridSelectionChangedRFID() {
    // if (counter != null) setInnerText(counter, grid.GetSelectedRowCount().toString());
    gvData.GetSelectedFieldValues('IButtonId', OnGridSelectionComplete);
}
function OnGridSelectionComplete(values) {
    var counter = document.getElementById("hdnGeozoneNosToBeAssinged");
    counter.value = '';
    for (var i = 0; i < values.length; i++) {
        counter.value = counter.value + values[i] + ',';
    }
   // alert(counter.value);
}



function OnGridSelectionChangedUnAssignRFID() {
    // if (counter != null) setInnerText(counter, grid.GetSelectedRowCount().toString());
    gvAssigne.GetSelectedFieldValues('IButtonId', OnGridSelectionCompleteUnAssign);
}

function OnGridSelectionChangedUnAssign() {    
    // if (counter != null) setInnerText(counter, grid.GetSelectedRowCount().toString());
    gvAssigne.GetSelectedFieldValues('GeozoneNo', OnGridSelectionCompleteUnAssign);
}

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

function CheckSelectionForManipulation() {
    var counter = document.getElementById("hdnGeozoneIDs");
    if (counter.value.length == 0) {
        TrinetraCustomAlerts('Select the alarm(s) that needs to be updated !');
        return false;
        return false;
    }
    if (document.getElementById('ddlMassUpdateStatus').value == 0) {
        TrinetraCustomAlerts('Select the status to be changed for the selected alarm(s) !');
        return false;
    }
    return true;
}

// Function to check the maximum geozones that can be assigned for vehicles
// Included by Kumuthini. L on 18-Dec-09
function checkMaxGeozones(maxGeozones, assignedGeozones) {
    if (gvData.GetSelectedRowCount() == 0) {// document.getElementById('hdnGeozoneNosToBeAssinged').value == '') {
        TrinetraCustomAlerts(selectGeozonesToAssign);
        return false;
    }
    else {
        var aSelectedGeozones = document.getElementById('hdnGeozoneNosToBeAssinged').value.split(',');

        if ((assignedGeozones + (aSelectedGeozones.length - 1)) > maxGeozones) {
            TrinetraCustomAlerts(maxGeozonesCount.replace("<#maxGeozones#>", maxGeozones));
            return false;
        }
    }

    return true;
}


function CheckItem(checkBoxList) {
    var options = checkBoxList.getElementsByTagName('input');
    var arrayOfCheckBoxLabels = checkBoxList.getElementsByTagName("label");
    var s = "";
    var len = '';
    for (i = 0; i < options.length; i++) {
        var opt = options[i];
        if (opt.checked) {

            var value = arrayOfCheckBoxLabels[i].innerText;
            var chkvalue = value == "Sun" ? "1" : value == "Mon" ? "2" : value == "Tue" ? "3" : value == "Wed" ? "4" : value == "Thu" ? "5" : value == "Fri" ? "6" : value == "Sat" ? "7" : "";
            s = s + "," + chkvalue;
        }
    }
    if (s.length > 0) {
        s = s.substring(1, s.length); //sacar la primer 'coma'
        document.getElementById("hdnRecurrenceDays").value = s;
    }
    len = s.split(',');

    if (len.length == 7) {
        document.getElementById('chkSelectAll').checked = true;
    }
    else {
        document.getElementById('chkSelectAll').checked = false;
    }
}

function CheckItemDelay(checkBoxList) {
    var options = checkBoxList.getElementsByTagName('input');
    var arrayOfCheckBoxLabels = checkBoxList.getElementsByTagName("label");
    var s = "";
    var len = '';
    for (i = 0; i < options.length; i++) {
        var opt = options[i];
        if (opt.checked) {

            var value = arrayOfCheckBoxLabels[i].innerHTML;  //innerText;
            var chkvalue = value == "Sun" ? "1" : value == "Mon" ? "2" : value == "Tue" ? "3" : value == "Wed" ? "4" : value == "Thu" ? "5" : value == "Fri" ? "6" : value == "Sat" ? "7" : "";
            s = s + "," + chkvalue;
        }
    }
    if (s.length > 0) {
        s = s.substring(1, s.length); //sacar la primer 'coma'
        document.getElementById("hdnRecurrenceDaysDelay").value = s;
    }
    len = s.split(',');

    if (len.length == 7) {
        document.getElementById('chkSelectAllDelay').checked = true;
    }
    else {
        document.getElementById('chkSelectAllDelay').checked = false;
    }
}

function selectAll(object) {
    var checkboxCollection = document.getElementById('ddlDays').getElementsByTagName('input');
    for (var i = 0; i < checkboxCollection.length; i++) {
        if (checkboxCollection[i].type.toString().toLowerCase() == "checkbox") {
            checkboxCollection[i].checked = object;
        }
    }
    document.getElementById("hdnRecurrenceDays").value = object == true ? "1,2,3,4,5,6,7" : "";
}

function selectAllDelay(object) {
    var checkboxCollection = document.getElementById('chkRecurringDelay').getElementsByTagName('input');
    for (var i = 0; i < checkboxCollection.length; i++) {
        if (checkboxCollection[i].type.toString().toLowerCase() == "checkbox") {
            checkboxCollection[i].checked = object;
        }
    }
    document.getElementById("hdnRecurrenceDaysDelay").value = object == true ? "1,2,3,4,5,6,7" : "";
}

function validateSelectAll() {
    var checkboxCollection = document.getElementById('ddlDays').getElementsByTagName('input');
    var valid = true;
    for (var i = 0; i < checkboxCollection.length; i++) {
        if (checkboxCollection[i].type.toString().toLowerCase() == "checkbox") {
            if (checkboxCollection[i].checked == false) {
                valid = false;
            }
        }
    }
    if (valid == true) {
        document.getElementById('chkSelectAll').checked = true;
    }
    else {
        document.getElementById('chkSelectAll').checked = false;
    }
}
function ChangePanel() {
    var ddlRestrict = document.getElementById('ddlRestrict');
    var PnlDateRange = document.getElementById('PnlDateRange');
    var PnlRecurrence = document.getElementById('PnlRecurrence');
    if (ddlRestrict.value == 'DateRange') {
        PnlDateRange.style.display = 'block';
        PnlRecurrence.style.display = 'none';
    }
    else {
        //PnlDateRange.style.display = 'none';
        PnlRecurrence.style.display = 'block';
    }
}
function LoadRestrictPopup() {
    var PnlRestrict = document.getElementById('PnlRestrict');
    PnlRestrict.style.display = 'block';
}
function CloseRestrictPopup() {
    var PnlRestrict = document.getElementById('PnlRestrict');
    PnlRestrict.style.display = 'none';
}

function LoadDelayNotifyPopup() {
    var PnlRestrict = document.getElementById('pnlDelayNotify');
    PnlRestrict.style.display = 'block';
}
function CloseDelayNotifyPopup() {
    var PnlRestrict = document.getElementById('pnlDelayNotify');
    PnlRestrict.style.display = 'none';
}