﻿function alertCommand(dockableObject, command)
{
    var adminpanel = document.getElementById(command.Name)
    if (adminpanel != null)
    {
        alert(adminpanel.value + " " + command.Name);
    }
    else
    {
        alert("Allowa " + command.Name);    
    }
}

function enterValue(target, value)
{
    var target = document.getElementById(target) 
    if (target != null)
    {
        target.value = value;
    }
}

function test()
{
    alert('hoi');
}

function dockStateChanged(dockableObject, command)
{
    alert('dockableObject id  = ' + dockableObject.id)
    alert('ParentDockingZone id  = ' + dockableObject.ParentDockingZone.id)
    alert('Position id  = ' + dockableObject.ParentDockingZone.GetPosition(dockableObject))
}

function myMax(anumber, another)
{
    if (anumber > another)
    {
        return anumber;
    }
    return another;
}
/*
function ResizeTextArea(txtBox)
{
    lines = txtBox.value.split("\n").length;
    if (lines > 5)
    {
        txtBox.setAttribute("rows",lines +1);
    }
    else
    {
        txtBox.setAttribute("rows",5);
    }
}
*/
function ResizeTextArea(txtBox)
{
    var lvmaxLength = txtBox.getAttribute('maxLength')
    if((lvmaxLength > 0) && (txtBox.value.length > lvmaxLength)){txtBox.value = txtBox.value.substring(0,lvmaxLength); return false};
    
    nCols = txtBox.cols;
    sVal = txtBox.value;
    nVal = sVal.length;
    nRowCnt = 1;
    for (i=0;i<nVal;i++)
        { 
        if (sVal.charAt(i).charCodeAt(0) == 13) 
            { 
                nRowCnt +=1; 
            } 
        }
    nRowCnt = Math.ceil(nRowCnt);
    txtBox.rows = nRowCnt;
    //window.defaultStatus = nRowCnt + ' x ' + nCols + ' (' + nVal + ') ' + sVal.charAt(i) ;
}

function bold(target,unbold)
{
    var target = document.getElementById(target) 
    if (target != null)
    {
        if (unbold != 'true')
        {
            if (target.style.fontWeight == 'bold')
            {
                target.style.fontWeight = 'normal';
            }
            else
            {
                target.style.fontWeight = 'bold';
            }
        }
        else
        {
            target.style.fontWeight = 'normal';
        }        
    }
}

function switchView(Sender, btnStrId, btnTxtId)
{
    var iFrame = document.getElementById('IfrCntEdt');
    var btnStr = document.getElementById(btnStrId);
    var btnTxt = document.getElementById(btnTxtId);
    if (iFrame && btnStr && btnTxt)
        {
        if (Sender == btnTxt)
            {
            iFrame.src = iFrame.getAttribute('txtview');
            btnTxt.style.display = 'none';
            btnStr.style.display = 'inline';
            }
        else
            {
            iFrame.src = iFrame.getAttribute('strview');
            btnStr.style.display = 'none';
            btnTxt.style.display = 'inline';
            }
        }
}

var m_Selected = null;
function ElemStyleChange(Sender, pvEvent)
{
    while ((!Sender.tagName) || (Sender.tagName.toLowerCase() != 'div'))
        {
        Sender = Sender.parentElement;
        }
    switch (pvEvent) {
        case "focus" : Sender.className = "core_element_focus";
                       if (m_Selected && Sender != m_Selected) { m_Selected.className = "core_element_out"; }
                       m_Selected = Sender;
                       break;
        case "blur" :  Sender.className = "core_element_out";
                       if (m_Selected) { m_Selected.className = "core_element_out"; m_Selected=null; }                       
                       break;
        case "over" :  if (Sender != m_Selected) Sender.className = "core_element_over";
                       break;
        case "out"  :  if (Sender != m_Selected) Sender.className = "core_element_out";
                       break; 
        default     :  alert(pvEvent);
                       break;
    }
}

