/// Menu /////////////////////////////////////////////////////////////

function menu_over( obj ) {
    arr = obj.src.split(".");
    obj.src = 'img/menu_' + obj.id + '_on.' + arr[arr.length - 1];
}

function menu_out( obj ) {
    arr = obj.src.split(".");
    obj.src = 'img/menu_' + obj.id + '.' + arr[arr.length - 1];
}


/// Pop Up /////////////////////////////////////////////////////////////

function newWindow( url, width, height )
{
    var left = ((window.screen.width) / 2) - (width / 2) ;
    var top = ((window.screen.height) / 2) - (height / 2) ;
    config = 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',resizable=no,scrollbars=yes,status=no,menubar=no';
    w = window.open(url, '1', config);
}

function messageDialog( title, message )
{
    url = '/messageDialog.do?message=' + message + "&title=" + title;
    newWindow(url, 420, 260);
}

/// Help Pop Up /////////////////////////////////////////////////////////////

function helpWindow( url )
{
    var width = 415;
    var height = 400;
    var left = ((window.screen.width) / 2) - (width / 2) ;
    var top = ((window.screen.height) / 2) - (height / 2) ;
    w = window.open(url, '1', 'width=' + width + 'px,height=' + height + 'px,left=' + left + 'px,top=' + top + 'px,resizable=no,scrollbars=yes,menubar=no,status=no');
}

/// About Pop Up /////////////////////////////////////////////////////////////

function aboutWindow( url, width, height )
{
    var left = ((window.screen.width) / 2) - (width / 2) ;
    var top = ((window.screen.height) / 2) - (height / 2) ;
    w = window.open(url, '1', 'width=' + width + 'px,height=' + height + 'px,left=' + left + 'px,top=' + top + 'px,resizable=no,scrollbars=no,menubar=no,status=no');
}

//shows "Select Folder" popup
function selectFolder( elementId ) {
    url = '/selectfolder.do?elementId=' + elementId + '&path=' + document.getElementById(elementId).value;
    newWindow(url, 435, 430);
}

//shows "Select Folder" popup. If empty folder is select confirmation is shown
function selectNotEmptyFolder( elementId ) {
    url = '/selectfolder.do?elementId=' + elementId + '&path=' + document.getElementById(elementId).value + '&emptyFolderRequired=true';
    newWindow(url, 435, 430);
}

function setFocus( id ) {
    var focusControl = document.getElementById(id);

    if( focusControl.type != "hidden" ) {
        focusControl.focus();
    }
}

function showElement( id ) {
    document.getElementById(id).style.display = '';
}

function hideElement( id ) {
    document.getElementById(id).style.display = 'none';
}

function textAreaLimit( textArea, maxLength ) {
    if( textArea.value.length > maxLength )
        textArea.value = textArea.value.substring(0, maxLength);
}


/// Change BG Color ////////////////////////////
function setOverColor( obj ) {
    obj.style.backgroundColor = "#FBF1DF";
}
function setOutColor( obj ) {
    obj.style.backgroundColor = "#ffffff";
}

/// Set Current Year ////////////////////////////
var curYear = 2005;

function escapeHtml( value )
{
    if( !value ) return "";
    return value.replace('&', '&amp;').replace('<', '&lt;').replace('>', "&gt;");
}

function positionOf( obj )
{
    var curleft = 0;
    var curtop = 0;
    if( obj.offsetParent )
        while( obj.offsetParent )
        {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
            obj = obj.offsetParent;
        }
    else
        if( obj.x )
        {
            curleft += obj.x;
            curtop += obj.y;
        }
    return {x: curleft, y:curtop};
}

