/*******************************************************************************
* Author: Justin Barlow - www.netlobo.com
* Modified: Daniel Shreim - www.letsbuildasite.com  (May 2007)
*
* params:     Parameters for the requested url in the format p1=1&p2=0&p3=2
* meth:       The request method. Can be "get" or "post". Default is "post".
* noauthfunc: A function or list of functions to be called when the AJAX request
*             is not authenticated (http status code 403 is encountered). Uses
*             the same format as "startfunc".
*
* Returns true on success and false on failure.
*
* Example Usage:
* ajaxUpdate( "maindiv", "ajaxlookup.php?a=edit&id=3" );
*
*******************************************************************************/
function ajaxUpdate( elemid, url) {
        var d = new Date();
        var url = url + "&ajaxcurtime=" + d.getTime();
        var params = "";  //FOR POST ONLY
        var meth =  "get";
        var noauthfunc =  "";

        var req = false;

        if (window.XMLHttpRequest ) {
                req = new XMLHttpRequest();
        } else if( window.ActiveXObject ) {
                req = new ActiveXObject( "Microsoft.XMLHTTP" );
        } else {
                alert( "Your browser cannot perform the requested action. " );
                return false;
        }

        req.onreadystatechange = function()     {
                        if ( req.readyState == 4 )      {
                                if ( req.status == 200 )        {
                                        if( elemid != '' )
                                                document.getElementById(elemid).innerHTML = req.responseText;
                                                return true;
                                } else {
                                        if( req.status == 403 && noauthfunc != "" ) {
                                                eval( noauthfunc );
                                        } else {
                                                //error
                                        }
                                        return false;
                                }
                        }
                };

        if( meth == "get" )     {
                req.open( meth, url, true );
                req.send(null);
        } else {
                req.open( meth, url, true );
                req.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
                req.send( params );
        }
}


IE4 = (document.all) ? 1 : 0;
NS4 = (document.layers) ? 1 : 0;
VERSION4 = (IE4 | NS4) ? 1 : 0;

if (!VERSION4) event = null;

function helpGetOffset(obj, coord) {
    var val = obj["offset"+coord] ;
    if (coord == "Top") val += obj.offsetHeight;
    while ((obj = obj.offsetParent )!=null) {
        val += obj["offset"+coord];
        if (obj.border && obj.border != 0) val++;
    }
    return val;
}

function helpDown () {
    if (IE4) document.all.helpBox.style.visibility = "hidden";
    if (NS4) document.helpBox.visibility = "hidden";
}

function helpOver (event,texte) {
    if (!VERSION4) return;

    var ptrObj, ptrLayer;
    if (IE4) {
        ptrObj = event.srcElement;
        ptrLayer = document.all.helpBox;
    }
    if (NS4) {
        ptrObj = event.target;
        ptrLayer = document.helpBox;
    }

    if (!ptrObj.onmouseout) ptrObj.onmouseout = helpDown;

    var str = '<div class="helpBoxDIV">'+texte+'</div>';
    if (IE4) {
        ptrLayer.innerHTML = str;
        ptrLayer.style.top = helpGetOffset (ptrObj,"Top") -12;
        ptrLayer.style.left = helpGetOffset (ptrObj,"Left") +57;
        ptrLayer.style.visibility = "visible";
        ptrLayer.style.left = helpGetOffset (ptrObj,"Left") +57;
        ptrLayer.style.visibility = "visible";
    }
    if (NS4) {
        ptrLayer.document.write (str);
        ptrLayer.document.close ();
        ptrLayer.document.bgColor = "yellow";
        ptrLayer.top = ptrObj.y + 20 - 12;
        ptrLayer.left = ptrObj.x + 18;
        ptrLayer.visibility = "show";
    }
}


