﻿//SingleItemSelected
function SingleItemSelected(PagePrefix, CurrentRow, ItemDescription,txtSavedValuesName) {
    var chkItem = document.getElementById(PagePrefix + '_chkItem_' + CurrentRow);
    var txtItemID = document.getElementById(PagePrefix + '_txtItemID_' + CurrentRow);    
    var txtValues =  document.getElementById(PagePrefix + '_txtItemsSelected')
    var txtValuesSelected = document.getElementById(PagePrefix + '_txtValuesSelected');
    var txtSavedValues = document.getElementById(txtSavedValuesName);    
    var txtDescriptionsSelected = document.getElementById(PagePrefix + '_txtDescriptionsSelected')
    
    txtSavedValues.value = ',' + txtItemID.value + ','
    chkItem.checked = true
    txtValues.value = ',' + txtItemID.value + ','
    
    document.getElementById(PagePrefix + '_txtTotal').value = 1;    
    document.getElementById(PagePrefix + '_txtSearchItem').value = ItemDescription;
    txtDescriptionsSelected.value = ItemDescription
           
//    HideNavPanel(PagePrefix + '_pnlDropDownItems');
//    document.getElementById(PagePrefix + '_cmdOnClose').click();
}

//Dropdown RowClicked
function DropdownRowClicked(PagePrefix, DropDownBoxTitle, CurrentRow, txtItemID, txtItemDescription, txtSavedValuesName, lblSelectedItemsName, NoValue) {
var chkItem = document.getElementById(PagePrefix + '_chkItem_' + CurrentRow);
if (chkItem.checked == true) {
    chkItem.checked = false;
    } 
else{
    chkItem.checked = true;
    }        
DropdownCheckBoxChecked(chkItem, PagePrefix, DropDownBoxTitle, CurrentRow, txtItemID, txtItemDescription, txtSavedValuesName, lblSelectedItemsName, NoValue)
}

//Checkbox in list is checked

function DropdownCheckBoxChecked(o,PagePrefix,DropDownBoxTitle, CurrentRow, txtItemID, txtItemDescription, txtSavedValuesName, lblSelectedItemsName, NoValue) {
var i = document.getElementById(PagePrefix + '_txtItemsSelected').value;
var txtSearchItem = document.getElementById(PagePrefix + '_txtSearchItem');
var txtSavedValues = document.getElementById(txtSavedValuesName);
//var lblSelectedItems = document.getElementById(lblSelectedItemsName);
var txtValuesSelected = document.getElementById(PagePrefix + '_txtValuesSelected');
var txtDescriptionsSelected = document.getElementById(PagePrefix + '_txtDescriptionsSelected')
if (o.checked == true) {
    txtSearchItem.style.backgroundColor ="#ffffff";
    txtSearchItem.style.border = 'solid 1px #DEDEDE';
    if (txtSavedValues.value == '' || txtSavedValues.value == '0') {
        txtSavedValues.value += ',' + txtItemID + ','
        } else {
        txtSavedValues.value += txtItemID + ','
        } 
    if (i == "") {
        i = 1
        }
    else{
        i = parseInt(i) + 1 
        }
    txtValuesSelected.value += CurrentRow + '|'
   
    if (txtDescriptionsSelected.value == "") {
        txtDescriptionsSelected.value = txtItemDescription
        } else {
        txtDescriptionsSelected.value += ', ' + txtItemDescription
        }
    } 
if (o.checked == false) {
    var t = txtDescriptionsSelected.value
    t = t.replace(txtItemDescription + ', ', '')   
    t = t.replace(', ' + txtItemDescription, '')        
    txtDescriptionsSelected.value = t  
    if (i == "") {
        i = 1
        }
    else{
        i = parseInt(i) - 1        
        }
    
    var u = txtValuesSelected.value 
    var s = txtItemID + '|' + txtItemDescription + '|' + txtItemID + ']';
    u = u.replace(CurrentRow + '|','');
   
    txtSavedValues.value = txtSavedValues.value.replace(',' + txtItemID + ',', ',')
    if (txtSavedValues.value == ',') {
        txtSavedValues.value = ''
        }
    
    txtValuesSelected.value = u     
    }
document.getElementById(PagePrefix + '_txtItemsSelected').value = i
if (i == 0) {
    txtSearchItem.value = "Select " + DropDownBoxTitle
    }
else
    {
    txtSearchItem.value = i + " " + DropDownBoxTitle + " Selected"
    }    
}

// Unselect all checkboxes for the given group.
function DropdownUnSelectAll(PagePrefix, DropDownBoxTitle, txtSavedValuesName, lblSelectedItemsName, NoValue) {
    var Totalcount = document.getElementById(PagePrefix + '_txtTotal').value
    var i = 0;
    var txtSavedValues = document.getElementById(txtSavedValuesName)
    //var lblSelectedItems = document.getElementById(lblSelectedItemsName)
    var txtSearchItem = document.getElementById(PagePrefix + '_txtSearchItem')
    var txtValuesSelected = document.getElementById(PagePrefix + '_txtValuesSelected');
    var txtDescriptionsSelected = document.getElementById(PagePrefix + '_txtDescriptionsSelected')

    //lblSelectedItems.innerHTML = "";
    
    var i = 0;
    var rows = txtValuesSelected.value.split('|');
    var r = '';
    for (var i=0;i<rows.length-1;i++) {
        var chkItem = document.getElementById(PagePrefix + '_chkItem_' + rows[i]);
        chkItem.checked = false
        }        
                
    txtSavedValues.value = '';
    txtValuesSelected.value = '';
    txtDescriptionsSelected.value = '';
        
    document.getElementById(PagePrefix + '_txtSearchItem').value = "0 " + DropDownBoxTitle + " Selected"
    document.getElementById(PagePrefix + '_txtItemsSelected').value = "0"

}

//Refresh data for dropdown on postback
function RefreshDropdown(PagePrefix, lblSelectedItemsName, DropDownBoxTitle) {
    var txtDescriptionsSelected = document.getElementById(PagePrefix + '_txtDescriptionsSelected').value
    var lblSelectedItems = document.getElementById(lblSelectedItemsName)
    var txtValuesSelected = document.getElementById(PagePrefix + '_txtValuesSelected');
    var txtDescriptionsSelected = document.getElementById(PagePrefix + '_txtDescriptionsSelected')
    var txtSearchItem = document.getElementById(PagePrefix + '_txtSearchItem')

    var s = txtDescriptionsSelected.value;
    s = replaceAll(s, '[|]', ', ')
    lblSelectedItems.innerHTML = s.substring(0, (s.length - 2))

    var i = 0;
    var rows = txtValuesSelected.value.split('|');
    var r = '';
    for (var i=0;i<rows.length-1;i++) {
        var chkItem = document.getElementById(PagePrefix + '_chkItem_' + rows[i]);
        chkItem.checked = true
        }        
        
    txtSearchItem.value = document.getElementById(PagePrefix + '_txtItemsSelected').value + " " + DropDownBoxTitle + " Selected"
}

function PopulateDropdown(IDCurrent, IDNext, Title) {    
    var txtSavedValuesName = ''
    switch (IDCurrent) {
        case 1: txtSavedValuesName='txtIndustryCategories'; break;
        case 2: txtSavedValuesName='txtIndustries'; break;
        case 3: txtSavedValuesName='txtJobTitleCategories'; break;
        case 4: txtSavedValuesName='txtJobTitles'; break;
        case 5: txtSavedValuesName='txtSpecialtyCategories'; break;
        case 6: txtSavedValuesName='txtSpecialties'; break;        
        default: txtSavedValuesName='';
        }
        
    var txtSavedValues = document.getElementById(txtSavedValuesName);
    if (txtSavedValues.value != '') {
        if (IDNext < 2) {document.getElementById('Industry_DropDown_txtSearchItem').value = 'Select Above'; PopulateIndustryDropdown('');}
        if (IDNext < 3) {document.getElementById('JobTitleCategory_DropDown_txtSearchItem').value = 'Select Above'; PopulateJobTitleCategoryDropdown('');}
        if (IDNext < 4) {document.getElementById('JobTitle_DropDown_txtSearchItem').value = 'Select Above'; PopulateJobTitleDropdown('');}
        if (IDNext < 5) {document.getElementById('SpecialtyCategory_DropDown_txtSearchItem').value = 'Select Above'; PopulateSpecialtyCategoryDropdown('');}
        if (IDNext < 6) {document.getElementById('Specialty_DropDown_txtSearchItem').value = 'Select Above'; PopulateSpecialtyDropdown('');}
   
        switch (IDNext) {
            case 1: document.getElementById('IndustryCategory_DropDown_txtSearchItem').value = Title;RS.Execute("RemoteMonitor.aspx","PopulateIndustryCategoriesListBox",IDCurrent,txtSavedValues.value,"1","",PopulateIndustryCategoryDropdown); break;
            case 2: document.getElementById('Industry_DropDown_txtSearchItem').value = Title;RS.Execute("RemoteMonitor.aspx","PopulateIndustriesListBox",IDCurrent,txtSavedValues.value,"1","",PopulateIndustryDropdown); break;
            case 3: document.getElementById('JobTitleCategory_DropDown_txtSearchItem').value = Title;RS.Execute("RemoteMonitor.aspx","PopulateJobTitleCategoriesListBox",IDCurrent,txtSavedValues.value,"1","",PopulateJobTitleCategoryDropdown); break;
            case 4: document.getElementById('JobTitle_DropDown_txtSearchItem').value = Title;RS.Execute("RemoteMonitor.aspx","PopulateJobTitlesListBox",IDCurrent,txtSavedValues.value,"1","",PopulateJobTitleDropdown); break;
            case 5: document.getElementById('SpecialtyCategory_DropDown_txtSearchItem').value = Title;RS.Execute("RemoteMonitor.aspx","PopulateSpecialtyCategoriesListBox",IDCurrent,txtSavedValues.value,"1","",PopulateSpecialtyCategoryDropdown); break;
            case 6: document.getElementById('Specialty_DropDown_txtSearchItem').value = Title;RS.Execute("RemoteMonitor.aspx","PopulateSpecialtiesListBox",IDCurrent,txtSavedValues.value,"1","",PopulateSpecialtyDropdown); break;        
            default: txtSavedValuesName='';            
            }        
        }
}

function PopulateIndustryCategoryDropdown(results) {
    var arrResults = results.split('|')
    if (document.getElementById('dIndustryCategory_DropDown') != null) {
        document.getElementById('dIndustryCategory_DropDown').innerHTML = arrResults[0]
        }
}
function PopulateIndustryDropdown(results) {
    var arrResults = results.split('|')
    if (document.getElementById('dIndustry_DropDown') != null) {
        document.getElementById('dIndustry_DropDown').innerHTML = arrResults[0]
        }
}
function PopulateJobTitleCategoryDropdown(results) {
    var arrResults = results.split('|')
    if (document.getElementById('dJobTitleCategory_DropDown') != null) {
        document.getElementById('dJobTitleCategory_DropDown').innerHTML = arrResults[0]
        }
}
function PopulateJobTitleDropdown(results) {
    var arrResults = results.split('|')
    if (document.getElementById('dJobTitle_DropDown') != null) {
        document.getElementById('dJobTitle_DropDown').innerHTML = arrResults[0]
        }
}
function PopulateSpecialtyCategoryDropdown(results) {
    var arrResults = results.split('|')
    if (document.getElementById('dSpecialtyCategory_DropDown') != null) {
        document.getElementById('dSpecialtyCategory_DropDown').innerHTML = arrResults[0]
        }
}
function PopulateSpecialtyDropdown(results) {
    var arrResults = results.split('|')
    if (document.getElementById('dSpecialty_DropDown') != null) {
        document.getElementById('dSpecialty_DropDown').innerHTML = arrResults[0]
        }
}

function ClearValues(IDCurrent){
    switch (IDCurrent) {
        case 1: 
            ClearDropDownValue('Industry_DropDown','txtIndustries');            
            ClearDropDownValue('JobTitleCategory_DropDown','txtJobTitleCategories');        
            ClearDropDownValue('JobTitle_DropDown','txtJobTitles');
            ClearDropDownValue('SpecialtyCategory_DropDown','txtSpecialtyCategories');
            ClearDropDownValue('Specialty_DropDown','txtSpecialties');
            break;
        case 2: 
            ClearDropDownValue('JobTitleCategory_DropDown','txtJobTitleCategories');        
            ClearDropDownValue('JobTitle_DropDown','txtJobTitles');
            ClearDropDownValue('SpecialtyCategory_DropDown','txtSpecialtyCategories');
            ClearDropDownValue('Specialty_DropDown','txtSpecialties');
            break;
        case 3: 
            ClearDropDownValue('JobTitle_DropDown','txtJobTitles');
            ClearDropDownValue('SpecialtyCategory_DropDown','txtSpecialtyCategories');
            ClearDropDownValue('Specialty_DropDown','txtSpecialties');
            break;
        case 4:
            ClearDropDownValue('SpecialtyCategory_DropDown','txtSpecialtyCategories');
            ClearDropDownValue('Specialty_DropDown','txtSpecialties');
            break;
        case 5:
             ClearDropDownValue('Specialty_DropDown','txtSpecialties');
             break;
        case 6: break;        
        default: ;
        }
 }
 
 function ClearDropDownValue(PagePrefix,txtSavedValuesName) {
    var Totalcount = document.getElementById(PagePrefix + '_txtTotal').value
    var i = 0;
    var txtSavedValues = document.getElementById(txtSavedValuesName)
    var txtSearchItem = document.getElementById(PagePrefix + '_txtSearchItem')
    var txtValuesSelected = document.getElementById(PagePrefix + '_txtValuesSelected');
    var txtDescriptionsSelected = document.getElementById(PagePrefix + '_txtDescriptionsSelected')
    
    var i = 0;
    var rows = txtValuesSelected.value.split('|');
    var r = '';
    for (var i=0;i<rows.length-1;i++) {
        var chkItem = document.getElementById(PagePrefix + '_chkItem_' + rows[i]);
        if (chkItem != null) {
            chkItem.checked = false
            }
        }        
                
    txtSavedValues.value = '';
    txtValuesSelected.value = '';
    txtDescriptionsSelected.value = '';
        
    document.getElementById(PagePrefix + '_txtSearchItem').value = "Select Above"
    document.getElementById(PagePrefix + '_txtItemsSelected').value = "0"
}

//Show the appropriate panel in the left navigation menu.
function ShowDropdownPanel(ControlName) {
if (document.getElementById(ControlName).style.display == 'inline') {
HideAllDropdownPanels("pnlDropDownItems");
} else {
HideAllDropdownPanels("pnlDropDownItems");
document.getElementById(ControlName).style.display = 'inline';
}
//document.getElementById(ControlName).focus();
}

//Hide the appropriate panel in the left navigation menu.
function HideDropdownPanel(ControlName) {
  document.getElementById(ControlName).style.display = 'none';
}

//Hide all panels in the left navigation menu.
function HideAllDropdownPanels() {
    if (document.getElementById('pnlIndustryCategory_DropDown') != null) {
       document.getElementById('pnlIndustryCategory_DropDown').style.display = 'none'
    }
    if (document.getElementById('pnlIndustry_DropDown') != null) {
       document.getElementById('pnlIndustry_DropDown').style.display = 'none'
    }    
    if (document.getElementById('pnlJobTitleCategory_DropDown') != null) {
       document.getElementById('pnlJobTitleCategory_DropDown').style.display = 'none'
    }
    if (document.getElementById('pnlJobTitle_DropDown') != null) {
       document.getElementById('pnlJobTitle_DropDown').style.display = 'none'
    }
    if (document.getElementById('pnlSpecialtyCategory_DropDown') != null) {
       document.getElementById('pnlSpecialtyCategory_DropDown').style.display = 'none'
    }
    if (document.getElementById('pnlSpecialty_DropDown') != null) {
       document.getElementById('pnlSpecialty_DropDown').style.display = 'none'
    }
    if (document.getElementById('pnlState_DropDown') != null) {
       document.getElementById('pnlState_DropDown').style.display = 'none'
    }
}