/**
 *
 * XXX /!\ XXX this file is obsolete, please use  /v3files/www/js/ajax-lib-core.js instead XXX /!\ XXX
 *
 */

/*************************************************************************
 * AJAX browser_abstraction library
 *
 * an attempt to get rid of which browser is used in the code
 * using compatible function
 *
 * target browsers are :
 * IE 5.5+, IE 6, Firefox 1.X, Opera 8.X, Konqueror, Safari, ...
 *************************************************************************/

//CHANGELOG
//---------
//v0.1 added newXMLHttpRequest()
//v0.2   -   set_attribute() for 'class' and 'id'
//v0.3   -   set_attribute() for 'onclick'

//MEMO
//----
//IE. (document.all)

var IE = document.all && !window.opera;

/**
 * return a new XMLHttpRequest
 *
 * tested on : IE 6.0, Firefox 1.5, Opera 8.52, Konqueror 3.4.3, Netscape 7.1 
 */
function newXMLHttpRequest()
{
    var xhr = false;

    /*@cc_on
        @if (@_jscript_version >= 5)
            try
            {
                xhr = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e)
            {
                try
                {
                    xhr = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e2)
                {
                    xhr = false
                }
            }
        @else
            xmlhttp = false;
        @end
    @*/

    if (!xhr && typeof XMLHttpRequest != 'undefined')
    {
        try
        {
            xhr = new XMLHttpRequest();
        }
        catch (e3)
        {
            xhr = false;
        }
    }
    return xhr;
}

/**
 * set_attribute
 *
 * => generic abstract layer for setAttribute DOM function
 * => managed attributes : 'class', 'id', 'style', 'onclick', 'onmouseover', 'onmouseout'
 *
 * @param   object      the object which attributes is set
 * @param   name        the name of the attribute set
 * @param   value       the value of the attribute set
 *
 * XXX /!\ XXX special IE case  XXX /!\ XXX
 * when you want to use function pointer as attributes and that it do not work, try use this :
 * @param   ie_pointer  pointer to the function that gonna be called
 * @param   ie_param    param to pass to the ie_pointer function
 * XXX /!\ XXX if not given, those args values are marked undefined XXX /!\ XXX
 *
 * tested on: IE 6.0, Firefox 1.X/2
 */
function set_attribute( object, name, value, ie_pointer, ie_param )
{
    switch (name)
    {
        case "class":
        if (IE) { // IE
            object.setAttribute("className", value)
        } else {
            object.setAttribute("class", value)
        }
        break;
        
        case "id":
        if (IE) { // IE
            object.id = value;
        } else {
            object.setAttribute("id", value);
        }
        break;
        
        case "style":
        if (IE) { // IE
            object.style.setAttribute("cssText", value);
        } else {
            object.setAttribute("style", value);
        }
        break;

        case "onclick":
        if (IE) { // IE
            if( ie_pointer != undefined) {
                object.onclick = function(e) {
                    e=e || window.event;
                    ie_pointer( ie_param);
                };
            } else {
                object.onclick = function(e) {
                    eval( value);
                };
            }
        } else {
            object.setAttribute("onclick", value);
        }
        break;
 
        case "onmouseover":
        if (IE) { // IE
            if( ie_pointer != undefined) {
                object.onmouseover = function(e) {
                    e=e || window.event;
                    ie_pointer( ie_param);
                };
            } else {
                object.onmouseover = function(e) {
                    eval( value);
                };
            }
        } else {
            object.setAttribute("onmouseover", value);
        }
        break;

        case "onmouseout":
        if (IE) { // IE
            if( ie_pointer != undefined) {
                object.onmouseout = function(e) {
                    e=e || window.event;
                    ie_pointer( ie_param);
                };
            } else {
                object.onmouseout = function(e) {
                    eval( value);
                };
            }
        } else {
            object.setAttribute("onmouseout", value);
        }
        break;
     
        case "onblur":
        if (IE) { // IE
            if( ie_pointer != undefined) {
                object.onblur = function(e) {
                    e=e || window.event;
                    ie_pointer( ie_param);
                };
            } else {
                object.onblur = function(e) {
                    eval( value);
                };
            }
        } else {
            object.setAttribute("onblur", value);
        }
        break;

        case "onchange":
        if (IE) { // IE
            if( ie_pointer != undefined) {
                object.onchange = function(e) {
                    e=e || window.event;
                    ie_pointer( ie_param);
                };
            } else {
                object.onchange = function(e) {
                    eval( value);
                };
            }
        } else {
            object.setAttribute("onchange", value);
        }
        break;

        case "onfocus":
        if (IE) { // IE
            if( ie_pointer != undefined) {
                object.onfocus = function(e) {
                    e=e || window.event;
                    ie_pointer( ie_param);
                };
            } else {
                object.onfocus = function(e) {
                    eval( value);
                };
            }
        } else {
            object.setAttribute("onfocus", value);
        }
        break;

        default:
        object.setAttribute( name, value)
        break;
    }
}



