/*

var Ajax_Queue=new Array();
var Callbacks=new Array();
var queue_id=0;

*/
function Ajax(url,div,callback) {
    this.request=null;
    this.div=div||null;
    this.use_div=true;
    this.url=url||null;
    this.callback=callback||null;
    this.exit_callback=null;
	this.priority=0;
	this.type=null;
	this.post_items=null;
	this.getItems=null;
	this.loading_callback=null;

    //	this.url+="?atu="+Math.random()*6000;
    ///////////////////////////////////////////////
    //  Sets URL for Ajax function               //
    ///////////////////////////////////////////////
    this.Priority=function(level) {
        this.priority=level;
    }
    ///////////////////////////////////////////////
    //  Gets Ajax Info							 //
    ///////////////////////////////////////////////
    this.Info=function() {
        return "Url: "+this.url+"\r\nDiv: "+this.div+"\r\n";
    }
    
    ///////////////////////////////////////////////
    //  Sets URL for Ajax function               //
    ///////////////////////////////////////////////
    this.Set_Url=function(_url) {
        //return function ()
        {
            this.url=_url;
            return this.url=_url; 
        };
    }
    ///////////////////////////////////////////////
    //  Sets URL for Ajax function               //
    ///////////////////////////////////////////////
    this.Dump_To_Div=function(val) {
        this.use_div=val;
    }
    
    ///////////////////////////////////////////////
    //  Sets div container for data              //
    ///////////////////////////////////////////////
    this.Set_Div=function (_div) {
        //return function ()
        {
            this.div=_div; 
            return this.div=_div; 
        };
    }
    
      
    ///////////////////////////////////////////////
    //  Displays error messages                  //
    ///////////////////////////////////////////////
    this.error=function(number) {
		switch(number) {
             case 1  : alert("Request not valid."); break;
             case 2  : alert("Request previously set."); break;
             case 3  : alert("General error creating XML Object."); break;
             case 4  : alert("Failed to init, or url null."); break;
             case 6  : alert("Ajax Callback Instance set to null."); break;
             case 7  : alert("Destination Element doesnt Exist."); break;
             default : alert(number); break;
        }
    }

    ////////////////////////////////////////////////////////
    //  Sets user function to call when call is finished  //
    ////////////////////////////////////////////////////////
    this.Set_Exit_Callback=function (callback) {
        if(typeof(callback)=="function")
        {
            this.exit_callback=callback;
        }
    }
    
    ///////////////////////////////////////////////
    //  Sets Ajax callback proc if custom        //
    ///////////////////////////////////////////////
    this.Set_Callback=function (callback) {
        if(typeof(callback)!="function")
        {
            this.request.onreadystatechange=this.Preform_Url_Callback(this);
        }
        else
        {
            this.request.onreadystatechange=callback;
        };
    }

    
    this.Loading_Callback=function(callback) {
		this.loading_callback=callback;
	}

	
    ///////////////////////////////////////////////
    //  Ajax callback proc for geturl request    //
    ///////////////////////////////////////////////
	this.OnLoading=function() {
	//	var target=window.document.getElementById('info');
	//	if(target) target.innerHTML="State: "+this.request.readyState;
	}

	this.OnLoaded=function() {
	//	var target=window.document.getElementById('info');
	//	if(target) target.innerHTML="State: "+this.request.readyState;
	}

    this.OnInteractive=function()
	{
		if(this.loading_callback) this.loading_callback(this.request.responseText);
	//	var target=window.document.getElementById('info');
	//	if(target) target.innerHTML="State: "+this.request.readyState;
	}
	
	this.OnComplete=function ()
	{
	//	var target=window.document.getElementById('info');
	//	if(target) target.innerHTML="State: "+this.request.readyState;
	    /******Login*****/
		if (this.request.status == 200)  {
		    if((this.div) && (this.use_div)){					/*If div provided put content in it*/
		         var target=window.document.getElementById(this.div);
		          if(!target){
					//instance.error(7);
		            return;
		         }
		        target.innerHTML = this.request.responseText;
		    }
		    if(this.exit_callback) {							/*if custom callback use it*/
		        //alert(this.exit_callback+"("+this.request.responseText+","+this+"),"+10);
		       // Callbacks.push({callback:this.exit_callback,data:this.request.responseText});
		        this.exit_callback(this.request.responseText,this);
		    }
		//	if(node1) node1=false; else if(node2) node2=null;	//now delete the thing... its done. toast
		//	Ajax_Send();            	               
		    //delete(instance);
		} 
		else {
		   this.error(instance.request.statusText);    
		}
	}
    
    this.Preform_Url_Callback=function(instance)  
    {
       return function () {
       /* if(!instance.div) {    
            instance.error(6);
            return;}
        */
        if(!instance.request){
            return;                                             /******Logout*****/
        }
    
	   // try{
	        switch(instance.request.readyState ){
        		case 1: instance.OnLoading();		break;
        		case 2: instance.OnLoaded(); 		break;
				case 3: instance.OnInteractive();	break;
				case 4: instance.OnComplete();		break;
			}//end switch
      //  }
   		//catch(ex){
		//alert(ex.toString());
		//}//end catch
       }; //end currying
    }//End ajax callback

    ///////////////////////////////////////////////////////
    //  Ajax XML object creation                        //
    /////////////////////////////////////////////////////
    this.Initialize= function () {
        if(this.request){               					/*is this a new request?*/
            //this.error(2);
            return true;
        }
        
        if (window.XMLHttpRequest) {    					/*reate new Object....*//*IE 7 and Mozilla*/
          try		{ this.request = new XMLHttpRequest();  }
          catch(e)	{ this.request=null;					}
        } 
	        else 
	        if (window.ActiveXObject) {						/*And Mozilla-ie7 IE6 or less*/
	            var ajaxMSversions=['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'];
	            for(var v=0; v<ajaxMSversions.length; v++){
	                try{
	                    this.request=new ActiveXObject(ajaxMSversions[v]); 
	                    //return this.request;
	                }
	                catch(e)	{	this.request=null;		};
	            }											/*End loop of ie types*/
	        }												/*End IE6 or less*/
		        else
		        if(window.createRequest){
		            try		{ this.request=window.createRequest();	}
		            catch(e){ this.request=null;					};
		        }											/*End */
        
        if(this.request) {									/*Return proper code....*/
            return true;
        }
	        else{
	            this.error(3);
	            return false;
	        }
    }//End Ajax Function
    
    ///////////////////////////////////////////////////////
    //  Ajax XML page request                           //
    /////////////////////////////////////////////////////
    this.Get= function (getItems) {
        this.type="GET";
		this.getItems=getItems;
        //Insert_Queue(this);
		this.Send();
    }//End Ajax Function
    
   
    ///////////////////////////////////////////////////////
    //  Ajax XML page request                           //
    /////////////////////////////////////////////////////
   this.Post= function (post_items) {
    	this.type="POST";
    	this.post_items=post_items+"&atu="+Math.random()*6000;
		//Insert_Queue(this);
		this.Send();
	}
	
	
	this.Send= function() {
        if(!this.url || !this.Initialize())
        {
            this.error(4);
            return false;
        };
        try 
        {
            if(this.request)
            {
	            if(this.type=="GET")
	            {
				    this.request.open('GET',this.url, true);
		            this.request.setRequestHeader('Content-Type', 'text/xml');
		            this.Set_Callback(this.callback);
		            this.request.send(this.getItems);
			   } else {
    			    this.request.open('POST',this.url, true);
		            this.request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		            this.Set_Callback(this.callback);
		            this.request.send(this.post_items);
			   }
		   }else{ alert("XML REQUEST BAD!"); }
		   
        } catch(e) {
            alert(e);
        }
    }//End Ajax Function    
    
    this.Cancel=function() {
    	if(this.request) { this.request.abort(); }
	}
}//End Ajax class.....
/*
function SortByPriority(a, b) {
    var x = a.instance.priority;
    var y = b.instance.priority;
    
   /* if(x == y)  return 0;
    if(x > y)  return 1;
    if(x < y)  return -1;
    */
	/*
	return y-x;
}


function Ajax_Instance(id,instance,priority){
    this.id=id;
	this.instance=instance;
	this.priority=priority;
}
var node1=null,node2=null;

function Insert_Queue(instance){
    Ajax_Queue[queue_id]=new Ajax_Instance(queue_id,instance,instance.priority);
	var e=window.document.getElementById('ajax_list');
	if(e) e.innerHTML+="\r\n"+queue_id+":"+instance.priority+" "+instance.url;
	queue_id++;
	if((node1==null) || node2==null) Ajax_Send();
}

function Ajax_Send(){
	var a=0,string="";
	var cur_priority=-1;
	//Ajax_Queue.sort();//SortByPriority);
	var item=null;
	var cur_pri=-10;
	for(x in Ajax_Queue){
		if(Ajax_Queue[x].priority>cur_pri) { cur_pri=Ajax_Queue[x].priority; item=x; }
	}
	if(!item) return;
	var arr=Ajax_Queue[item];
	Ajax_Queue.splice(item,1);
	if(arr)
	{
		if(node1==null) node1=true; else if(node2==null) node2=true;
		arr.instance.Send();
	}

	if(Ajax_Queue.length>0)	
		for(a in Ajax_Queue) 
		if(Ajax_Queue[a])
			{
				string+="\r\n"+a+"-"+Ajax_Queue[a].id+":"+Ajax_Queue[a].instance.url+" "+Ajax_Queue[a].priority;
			}
				

	var e=window.document.getElementById('ajax_order');
	if(e) e.innerHTML=string;
}

function ajaxTimer(){
	Ajax_Send();
	window.setTimeout("ajaxTimer();",1000);
}

ajaxTimer();
*/