﻿function toggleTableView(linkObject, tableId, minCount) {
    var linkText = linkObject.innerHTML;
    var tableInfo = document.getElementById(tableId);
    
    if(linkText == "more") {
        linkObject.innerHTML = "less";
        
        for(i=minCount; i<tableInfo.rows.length; i++) {
            tableInfo.rows[i].style.display = "";
        }
    }
    else {
        linkObject.innerHTML = "more";
        
        for(i=minCount; i<tableInfo.rows.length; i++) {
            tableInfo.rows[i].style.display = "none";
        }
    }
    return false;
}

function PopUp(linkToPage, pageWidth, pageHeight) {
    var winOptions = "toolbar=0,resizable=1,scrollbars=1,width=" + pageWidth + ",height=" + pageHeight + "," + centerScreenCoordinates(pageWidth, pageHeight);
    var day = new Date();
    var id = day.getTime();
    window.open(linkToPage, id, winOptions);
    return false;
}

function centerScreenCoordinates(pageWidth, pageHeight) {
    var winLeft = parseInt((screen.width - pageWidth)/2);
    var winTop = parseInt((screen.height - pageHeight)/2);
    
    var txt = "left=" + winLeft + ",top=" + winTop;
    return txt;
}

function togglePanelVisibility(panelName) {
    var panel = document.getElementById(panelName);
    
    if(panel.style.display == "none") {
        panel.style.display = "";
    }
    else {
        panel.style.display = "none";
    }
}

function toggleControlBody(bodyId, labelId) {
    var divBody = document.getElementById(bodyId);
    var labelText = document.getElementById(labelId);
    
    if(divBody.style.display == '') {
        divBody.style.display = 'none';
        labelText.innerHTML = "[+]";
    }
    else if(divBody.style.display == 'none') {
        divBody.style.display = '';
        labelText.innerHTML = "[-]";
    }
}

function setCheckBoxListStatus(chkListName, state) {
    var checkboxList = document.getElementById(chkListName);
    var actualCheckboxes = checkboxList.getElementsByTagName("input");
    
    for(var i=0; i<actualCheckboxes.length; i++) {
        actualCheckboxes[i].checked = state;
    }
    
    return false;
}

function maxLength(field, maxChars) {
   if(field.value.length >= maxChars) {
        field.value = field.value.substring(0, maxChars);
   }
}
