function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
  
function logit( msg )
{
    if( document.getElementById('log') )
    {
        document.getElementById('log').innerHTML += msg + '<br />';
    }
}

String.prototype.replaceAll = function(pcFrom, pcTo)
{
    var i = this.indexOf(pcFrom);
    var c = this;
    while (i > -1)
    {
        c = c.replace(pcFrom, pcTo);
        i = c.indexOf(pcFrom);
    }
    return c;
}

function  tog_display(a,label)
{
    var b = document.getElementById(a);
    if( b.style.display == 'none')
    {
        b.style.display = '';
        document.getElementById(label).innerHTML = 'hide';
    }
    else
    {
        b.style.display = 'none';
        document.getElementById(label).innerHTML = 'show';
    }
}

function getKeyNum(e)
{
    var keynum = -1;
    if(window.event) // IE
    {
        keynum = e.keyCode;
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
        keynum = e.which;
    }
    return keynum;
}

String.prototype.trim = function ()
{
    return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};

function ajax_post( url, callback, postdata )
{
    var CT = 'application/x-www-form-urlencoded;charset=UTF-8';
    logit('POST: ' +  postdata );
    var myCallback = callback;
    var xmlhttp = null;
    if (window.XMLHttpRequest)  {  xmlhttp = new XMLHttpRequest();  }
    else if (window.ActiveXObject)  {   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
    if (xmlhttp != null)
    {
        xmlhttp.onreadystatechange=function()
        {
            if (xmlhttp.readyState == 4)
            {
                if (xmlhttp.status == 200)
                {
                    logit('GOT: '+xmlhttp.responseText );
                     myCallback( xmlhttp.responseText);
                }
            }
        }
        xmlhttp.open('POST', url, true);
        xmlhttp.setRequestHeader('Content-Type', CT );
        xmlhttp.send(postdata);
    }
    else  {  logit('Cannot continue, your browser does not support ajax!');  }
}

