// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

var popupHeight = 0;

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
    
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  //document.Show.MouseX.value = tempX
  //document.Show.MouseY.value = tempY
  return true
}


function dropDownValue(id)
{
    var retval = document.getElementById(id).options[document.getElementById(id).options.selectedIndex].value;
    return retval;
}

function dropDownText(id)
{
    var retval = document.getElementById(id).options[document.getElementById(id).options.selectedIndex].text;
    return retval;
}

function show(divid)
{
    var obj = document.getElementById(divid);

    obj.style.visibility = 'visible';
    obj.style.display = '';
}


function hide(divid)
{
    var obj = document.getElementById(divid);

    obj.style.visibility = 'hidden';
    obj.style.display = 'none';
    
}



function ChangeVisibility(objname, folder, folderOn)
{
    var obj = document.getElementById(objname);

    if(obj.style.visibility == 'hidden')
    {
        obj.style.visibility = 'visible';
        obj.style.display = '';

        if(folderOn.length > 0)
        {
            document.getElementById(objname+"_img").src = folderOn;
        }
    } else
    {
        obj.style.visibility = 'hidden';
        obj.style.display = 'none';

        if(folderOn.length > 0)
        {
            document.getElementById(objname+"_img").src = folder;
        }
    }

}

function IsNumeric(sText)
{
    var ValidChars = "0123456789.";
    var IsNumber=true;
    var Char;


    for (i = 0; i < sText.length && IsNumber == true; i++)
    {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1)
        {
            IsNumber = false;
        }
    }
    if(sText.length == 0)
    {
        return false;
    }
    return IsNumber;

}


function checkIntegerField(obj)
{
    var classStyle = obj.getAttribute("class");
    var classError = "";
    var classOk = "";



    if(classStyle.indexOf('Error') == -1)
    {
        classOk = classStyle;
        classError = classStyle+"Error";

    } else
    {
        classOk = classStyle.replace(/Error/, '');
        classError = classStyle;
    }

    //alert(classError);



    if(IsNumeric(obj.value) == true)
    {

        obj.setAttribute("class", classOk);
    } else
    {

        obj.setAttribute("class", classError);
    }

}

function highlight(objId)
{
    var obj = document.getElementById(objId);



    if(obj.style.borderColor == 'white white white white' || obj.style.borderColor == '')
    {
        obj.style.border = 'solid 1px #888888';
        obj.style.backgroundColor = '#dddddd';
    } else
    {
        obj.style.border = 'solid 1px white';
        obj.style.backgroundColor = '#ffffff';
    }
 
}


function startMovePanel(id)
{
    
    //var obj = document.getElementbyId(id);


}

/**
 * @todo doesnt work for checkboxes, select ...
 */
function GetValue(formId, elementId)
{
    var value = document.forms[formId][elementId].value;

    return value;
    
}

function stopMovePanel(id)
{
    //var obj = document.getElementbyId(id);

    //alert('sok');
    //obj.style.left = tempX;
    //obj.style.top = tempY;
    //alert('sok');
}
