    /*
    The AJAX encapsulation invoker
    author : Chayakon PONGSIRI
    email: p.chayakon@hotmail.com

    EX.
    var ajax = new XMLHTTP();
    ajax.request('http://www.aaa.com', 'GET' ,);
    */
    function XMLHTTP() {
        var _xmlHttp = null;
        var _host = null;
        var _me = this;
        var _callback = null;
        //@access public
        //@desc			this function use for call stat processor to make stat request
        //@param type	type of stat [Content , Category , BannerAds , VideoAds , LogoAds]
        //@param id		the tracking id
        //@param option	the stat type
        //@param callback	the function to be revoke after call stat process success
        //@return 
        XMLHTTP.prototype.request = function(url , param ,method,callback){
            _callback = callback;
            _xmlHttp = this.createXmlHttp();
            if (_xmlHttp != null)
            {
                _xmlHttp.onreadystatechange=_me.onReadyStateChange;
                if (url.indexOf('?') > 0)
                {
                    url += "&r=" + _me.genHex();
                }else{
                    url += "?r=" + _me.genHex();
                }
                
                //alert(url);
                
                _xmlHttp.open(method,url,true);

                if (method == 'post' || method == 'POST')
                {
                    _xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                    _xmlHttp.setRequestHeader("Content-length", param.length);
                    _xmlHttp.setRequestHeader("Connection", "close");
                    _xmlHttp.send(param);
                }else{
                    _xmlHttp.send(null);
                }
                //alert(param);
            }else{
                //alert("error can not create httpRequest");
            }
        }
        
        //@access private
        //@desc			the default callback function
        //@return 
        XMLHTTP.prototype.onReadyStateChange = function(){
            if(_xmlHttp.readyState==4)
            {
                //alert('onReady State');
                if (_callback)
                {
                    _callback(_xmlHttp);
                }
                
            }
        }


        //@access private 
        //@desc			for create xml http request object
        //@return		the xml http request object
        XMLHTTP.prototype.createXmlHttp = function()
        {
            try{
              // Firefox, Opera 8.0+, Safari
              xmlHttp=new XMLHttpRequest();
            }catch (e){
              // Internet Explorer
                try{
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                }catch (e){
                    try{
                      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                    }catch (e){
                        return false;
                    }
                }
            }
            return xmlHttp;
        }

        //@access private 
        //@desc			generate ramdom value
        //@return		the string of random value
        XMLHTTP.prototype.genHex = function(){
            seed = new Array(14);
            seed[0]="0";
            seed[1]="1";
            seed[2]="2";
            seed[3]="3";
            seed[4]="4";
            seed[5]="5";
            seed[5]="6";
            seed[6]="7";
            seed[7]="8";
            seed[8]="9";
            seed[9]="a";
            seed[10]="b";
            seed[11]="c";
            seed[12]="d";
            seed[13]="e";
            seed[14]="f";

            digit = new Array(5);
            res="";
            for (i=0;i<6;i++){
                digit[i]=seed[Math.round(Math.random()*14)];
                res = res+digit[i];
            }
            return res;
        }
    }