function OnGridSelectionChanged(Type) {
    
    if (Type == 1) {
        gvUnAssignedVehicles.GetSelectedFieldValues('BoxId', OnGridSelectionCompleteUnAssVeh);
    }
    if (Type == 2) {
        gvAssignedVehicles.GetSelectedFieldValues('BoxId', OnGridSelectionCompleteAssVeh);
    }
}

function OnGridSelectionCompleteUnAssVeh(values) {
    var counter = document.getElementById("hdnVehicleIdsToBeAssinged");
    counter.value = '';

    var assignedVehicles = document.getElementById("hdnAssignedVehicleIds").value;
    var result = '';

    for (var i = 0; i < values.length; i++) {
        counter.value = counter.value + values[i] + ',';

        if (result == null || result == '') {
            result = assignedVehicles.match(values[i]);
        }
    }
    document.getElementById("hdnIsAssigned").value = (result != null && result != '') ? 1 : 0;
}

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

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


//Check selected item in checkbox.
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';
}