// JScript File

var TimeOut;
function DisplaySpinner(ProgressContainer, ProgressImage)
{
    try
    {
        if (document.getElementById(ProgressContainer) != null)
        {
            document.getElementById(ProgressContainer).style.visibility = "visible";
        }
        TimeOut = setTimeout("ProgressBar('" + ProgressImage + "', '" + ProgressContainer + "')", 50);
    }
    catch(err)
    {
        alert(err.message);
    }
    return true;
}
function ProgressBar(ProgressImage, ProgressContainer)
{
    clearTimeout(TimeOut);
    if (document.getElementById(ProgressImage) != null)
    {
        document.getElementById(ProgressImage).src = "../_admin/images/cms/bar_upload.gif";
    }
}

function ShowHidingPanel(HidingPanel, TargetControlID) {
    var pnl = $get(HidingPanel);
    // show hiding panel
    pnl.style.display = '';
    // get target control
    var target = $get(TargetControlID);
    // get bounds
    var pnlBounds = Sys.UI.DomElement.getBounds(pnl);  
    var targetBounds = Sys.UI.DomElement.getBounds(target);
    // find center
    var x = targetBounds.x + Math.round(targetBounds.width / 2) - Math.round(pnlBounds.width / 2);
    var y = targetBounds.y + Math.round(targetBounds.height / 2) - Math.round(pnlBounds.height / 2);
    //	set the hiding panel to this position
    Sys.UI.DomElement.setLocation (pnl, x, y); 
}

function HideHidingPanel(HidingPanel) {
    // get the update progress div
    var pnl = $get(HidingPanel); 
    // make it invisible
    pnl.style.display = 'none';
}

function OpenWindow(url, val, height, width, ShowHeader)
{
    docwidth = width;
    docheight = height;
    leftVal = (screen.width - docwidth) / 2;
    topVal = (screen.height - docheight) / 2;
    var args = 'toolbar=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1';
    if (ShowHeader != true)
    {
        args = 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1';
    }
    printWin = window.open(url + val, "printWin","height=" + docheight + ",width=" + docwidth + ",left=" + leftVal + ",top=" + topVal + "toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");  
    printWin.focus();
}

function CharCountDisplay(txtBox, divCountDisplay, maxLength) {
    var charCount = GetTextCount(txtBox);
    var divC = $get(divCountDisplay);
    var remainingC = maxLength - charCount;
    var outText = '';
    if (remainingC > 0) {
        outText = remainingC + ' character';
        if (remainingC != 1) {
            outText = outText + 's';
    }
    outText = outText + ' remaining';
    divC.className = 'CharNormal';
    } else {
        outText = 'You are over the character limit (' + maxLength + ')';
        divC.className = 'CharError';
    }
    divC.innerHTML = outText;
}

function GetTextCount(txt) {
    try {
        var txtDisplay = $get(txt);
        return txtDisplay.value.length;
    } catch(err) { 
        alert(err.message); 
    }
}

function CheckNewTags(txtPgTags, btnAddPgTag) {
    var txtTags = $get(txtPgTags);
    var btnOk = $get(btnAddPgTag);
    var tagText = txtTags.value.replace(/^\s+/, '').replace(/\s+$/, '');
    if(tagText != '') {
        btnOk.disabled = false;
    } else {
        btnOk.disabled = true;
    }
}

function ClearNewTags(txtPgTags, btnAddPgTag) {
    var txtTags = $get(txtPgTags);
    var btnOk = $get(btnAddPgTag);
    txtTags.value = '';
    btnOk.disabled = true;
}