var ajax=
{
	IE:null,
	curObj:null,
	data:null,
	xml:null,
	startload:null,
	endload:null,
	loadtime:null,
	status:0,
	returntype:"text/xml",
	success:false,
	remid:null,
	callback:null,
	callbacknotify:null,
  notify:false,	
  passobj:null,
	cErr:null,
	showerrors:false,
    setXML:function(x)
    {
        var xmlDoc,pe;
        x=x==undefined?this.data:x;
        try
        {
            if (window.ActiveXObject)
            {
                xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
                xmlDoc.async="false";
                xmlDoc.loadXML(x);
            }
            else
            {
                var errorNS='http://www.mozilla.org/newlayout/xml/parsererror.xml';
                var p=new DOMParser();
                xmlDoc=p.parseFromString(x,"text/xml");
                xmlDoc.parseError=new Object({errorCode:0,line:0,srcText:null,reason:null});
                if (xmlDoc.documentElement.nodeName == 'parsererror' && xmlDoc.documentElement.namespaceURI==errorNS)
                {
                    xmlDoc.parseError.errorCode = 1;
                    var s=xmlDoc.documentElement.getElementsByTagNameNS(errorNamespace, 'sourcetext')[0];
                    if (s != null) xmlDoc.parseError.srcText = s.firstChild.data
                    xmlDoc.parseError.reason = xmlDoc.documentElement.firstChild.data;
                }
            }
            if (xmlDoc.parseError.errorCode!=0)
            {                
                this.xml=null;
                if (this.showerrors) alert("parse error line(" + xmlDoc.parseError.line + ")"+ xmlDoc.parseError.srcText);
            }
            else
            {    
                this.xml=xmlDoc.documentElement;
            }
        }
        catch(e)
        {
            this.xml=null;
            if (this.showerrors) alert(e.description);
        }
    },
	createXMLObj:function(showerror,rt)
	{
		var r;
		this.cErr=null;
		rt=rt==undefined?this.returntype:rt;
		if (this.curObj!=null) return this.curObj;
		if( typeof(XMLHttpRequest) != 'undefined' )
		{
			try 
			{
				this.curObj = new XMLHttpRequest();
				if (this.curObj.overrideMimeType) this.curObj.overrideMimeType(rt);
				return this.curObj;
			}
			catch(e)
			{
        		this.cErr=e.description;
			}
		}
		else
		{		
    		var axo = ['Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'], i;
    		for( i=0; i < axo.length; i++ )
    		{
    			try
    			{ 
    			    this.cErr=null;
    				this.curObj=new ActiveXObject(axo[i]);
    				//this.curObj.setRequestHeader("Content-Type",rt);
    				return this.curObj;
    			}
    			catch(e)
    			{
            		this.cErr=e.description;
    			}
    		} 
        }
		this.curObj=null;
		if (this.showerrors || showerror)  alert('Could not create XML object');
		return null;
	},
	shouldsend:function(milli,lastrec)
	{
	    return (this.elapsed()>milli || lastrec!=this.remid);
	},
	elapsed:function()
	{
	    return this.endload==null?0:(ajfuncs.getTimer()-this.endload);
	},
	send:function(page,query,usepost,user,pw,rid,obj,cb,rt)
	{
    this.startload=ajfuncs.getTimer();
    this.cErr=null;
    this.remid=rid;
    this.success=false;
    this.data=this.xml=null;
    this.callback=cb==undefined?null:cb;
    this.passobj=obj==undefined?null:obj;
		if (page==undefined || page==null) return false;
		user=user==undefined || user==null?undefined:user;
		pw=pw==undefined || pw==null?undefined:pw;
		usepost=usepost==undefined || usepost==null?false:usepost;
		query=query==undefined || query==null?"":query;
		if (this.createXMLObj(true,rt)==null) return false;
		if (query.length!=0)
		{
			query=(query.substr(0,1)=="&" || query.substr(0,1)=="?")?query.substring(1):query;
			query="?"+query;
		}
		try
    {
      var op=(!usepost|| this.IE);
		  this.curObj.onreadystatechange=this.returnevent;
	    this.curObj.open(op?"GET":"POST", page+(op?query:""), (this.callback!=null),user,pw);
	    this.curObj.send(op?null:query);
      if (this.callback==null)
      {
        this.setreturn();
        return this.success;
      }
      else
      {
        return true;
      }		
    }
    catch(e)
    {
  		this.cErr=e.description;
      return false;
    }
	},
	setreturn:function()
	{
    this.endload=ajfuncs.getTimer();
    this.loadtime=this.endload-this.startload;
		this.status=this.curObj.status;
		this.data=this.curObj.responseText;
		this.setXML();
		this.success=this.status==200;
		if (this.callback!=null) 
		{
		    this.callback(this.success,this.passobj);
		}
  },
	returnevent:function()
	{
	    if (ajax.notify && ajax.callback!=null) 
	    {
	        if (ajax.callbacknotify!=null)
	        {
	            ajax.callbacknotify(ajax.curObj.readyState,ajax.passobj);
	        }
	        else
	        {
	            ajax.callback(null,ajax.curObj.readyState);
	        }
	    }
	    if (ajax.curObj.readyState==4) ajax.setreturn();
    },
	loadElement:function(id,doClear,def)
	{
	    var e;
        this.cErr=null;
	    if (typeof(id)=="string") e=document.getElementById(id); else e=id;
	    if (e)
	    {
    	    if (this.success || doClear)
            {
                def=this.data==""?(def==undefined?"":def):this.data;
                e.innerHTML=doClear?"&nbsp;":def;
                return true;
            }
            else
            {
                this.cErr.description="Could not load from server error code:"+this.status;
            }
        }
        else
        {
            this.cErr.description="Could not load into element specified ("+id+")";
        }
        return false;
    },
    fixNode:function(node)
    {
	      var dc=document;
	      if (!this.IE) 
	      {
	        dc = document.implementation.createDocument("", "", null);
	      }
	      var wnode=dc.importNode(node,true);
	      dc.appendChild(wnode);
	      return {doc:dc,node:wnode};
    },
    isU:function(v)
    {
      return v==undefined || v==null;
    },
    XPath:function(expr, node) 
    {
      node=this.isU(node)?this.xml:node;
      expr=this.isU(expr)?"/":expr;
      if (this.isU(node)) return null;
	    if (document.evaluate) 
	    {
	      var fn=this.fixNode(node);
		    var ro= new Object ({nodes:fn.doc.evaluate(expr,fn.node,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),i:0,
		      count:function()
		      {
		        return this.nodes.snapshotLength;
		      },
			    next:function() 
			    { 
			      return (this.i > this.nodes.snapshotLength)?null:this.nodes.snapshotItem(this.i++);
			    },first:function()
			    {
			      this.i=0;
			      return this.next();
			    },item:function(id)
			    {
			      this.id=0;
			      return this.next();
			    }});
			    return ro;
	    }
	    else 
	    {
		    return new Object({nodes:node.selectNodes(expr),
		        i:0,
		      count:function()
		      {
		        return this.nodes.length;
		      },
    			next: function() 
    			{
    				return (this.i > this.nodes.length)?null:this.nodes[this.i++];
    			},first:function()
			    {
			      this.i=0;
			      return this.next();
			    },item:function(id)
			    {
			      this.i=id;
			      return this.next();
			    }});
		}
	},
	XPItem:function(expr,node)
	{
	    var nd=this.XPath(expr,node);
	    if (nd!=null) if (nd.count()==1) nd=nd.first();
	    return nd;
	},
	GNN:function()
	{
	    //alert(ajfuncs.enumObj(this));
	    return this.xml.nodeName;
    },
    GN:function(expr,node)
    {
        return this.XPItem(expr,node);
    },
	GNT:function(expr,node)
	{
	    try
	    {
	      var nd=this.XPItem(expr,node);
	      return nd!=null?nd.firstChild.nodeValue:null;
	    }
	    catch(e)
	    {
	      return null;
	    }
    },
	GNA:function(expr,node,att)
	{
	  expr=expr==""?null:expr;
    try
    {
      return node.getAttribute(att);
    }
    catch(e)
    {  
	    try
	    {
  	    var nd=this.XPItem(expr,node);
        return nd!=null?nd.getAttribute(att):null;
	    }
	    catch(e)
	    {
	      return null;
	    }
	  }
  },
  Node2Obj:function(mnd)
  {
    var ob=new Object();
    while (mnd!=null)
    {
        ob[mnd.nodeName]=mnd.firstChild==null ? "" : mnd.firstChild.nodeValue;
        mnd=mnd.nextSibling;
    }
    return ob;
  },
  Atts2Obj:function(mnd)
  {
    var ob=new Object();
    for (var c=0;c<mnd.attributes.length;c++)
    {
      var atr=mnd.attributes[c];
      ob[atr.nodeName]=atr.nodeValue;
    }
    return ob;
  }
  
}
ajax.IE=(navigator.appName.indexOf("Internet Explorer")!=-1?true:false);
