// JavaScript Document



/*



############################################



# Created by Jonathan Ellis 2/19/08



# Version 1



#Methods



#	get(url,container)--the url to send the request to and the id of the element to place the results.



#	post(url,container)--the url to send the request to and the id of the element to place the results.



#	-- Call before get or post --



#	setPostInfo(info)--sets the post info to send in the post request. ex setPostInfo("name=value&job=value")



#	setLoadHtml(html)--sets the loading html to appear in the container spcified in get or post



#	



#	to crate object place the following code inside <script></script> tags



#	var ajax = new Ajaxobj();



#	to use a method type



#	ajax.methodname(argument); For example to use the get method type



#	ajax.get("default.asp","ajaxid");



#	the container in the example ajaxid needs to be the id of an html element.



#	<span id="ajaxid"></span>



############################################



*/


function ajaxobj()

{

    var me = this;

    this.postInfo=null;

    this.loadingHtml="";

    this.onFinish="";
	this.onReady=function(){};

    

    this.setPostInfo=function(info){me.postInfo = info;}

    this.setLoadHtml=function(html){me.loadingHtml=html;}

    this.setOnFinish=function(job){me.onFinish=job;}

    

    this.GetXmlHttpObject = function()

        {var xmlHttp=null;

          try{

            // Firefox, Opera 8.0+, Safari

            xmlHttp=new XMLHttpRequest();}

          catch (e){

            // Internet Explorer

            try{

              xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}

            catch (e){

              xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}

            }

          return xmlHttp;

        } 

    

    this.stateListen=function(xho,target){

        if(xho.readyState==4){

            var response = xho.responseText;

            if(target!=null){

            target.innerHTML=response;

            }

            if(me.onFinish!=""){eval(me.onFinish);}
			me.onReady(response);

        }

    }
    this.get=function(string){

        return document.getElementById(string);

    }


    

    this.send=function(url,container){

            var xho =me.GetXmlHttpObject();

            if(xho==null){alert("No object.");}

            var target =me.get(container);

            if(container==null){container="";}

            if(me.loadingHtml!=""){

                if(target!=null){

                target.innerHTML = me.loadingHtml;

                }

            }

            if(url.indexOf("?")>=0){url+="&rid=" + Math.random();}

            else{url+="?rid=" + Math.random();}

            //if(container==""){alert("There is no container.");}

            xho.onreadystatechange=function(){

                me.stateListen(xho,target);

                }

            if(me.postInfo==null){

                xho.open("GET",url,true);

                xho.send(null);

            }else{

                xho.open("POST",url,true);

                xho.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

                xho.send(me.postInfo);

            }

            

        }//end send

        

    this.getFormInfo=function(oForm){

        if(oForm==null){oForm=document.forms[0];}    

        if(oForm!=null){

            var strReturn='';

            var elementType='';

            for(i=0;i<oForm.length;i++)

            {

                if(oForm.elements[i].name !=''){

                        elementType=oForm.elements[i].type;

                        if(elementType!='radio' && elementType!='checkbox'){

                            if(i>0 && i+1 <oForm.length){strReturn+="&";}

                            strReturn+=oForm.elements[i].name +"="+    oForm.elements[i].value;

                        }

                        else if((elementType=='radio'||elementType=='checkbox') && oForm.elements[i].checked==true)

                        {//is radio

                            if(i>0 && i+1 <oForm.length){strReturn+="&";}

                            strReturn+=oForm.elements[i].name +"="+    oForm.elements[i].value;

                        }

                }//end if name !=''

            }//end for

            return strReturn;

        }

        else{//oForm ==null

            return false;

        }

    }//end getFormInfo

        

}//end ajaxobj







function Ajaxobj()



{



	var postInfo="";



	var loadingHtml="";



	this.GetXmlHttpObject = function()



		{var xmlHttp=null;



		  try{



			// Firefox, Opera 8.0+, Safari



			xmlHttp=new XMLHttpRequest();}



		  catch (e){



			// Internet Explorer



			try{



			  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}



			catch (e){



			  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}



			}



		  return xmlHttp;



		} 



	var xho =this.GetXmlHttpObject();



	if(xho==null){alert("No object.");}



	this.get=function(url,container){



			var target = document.getElementById(container);



			if(loadingHtml!=""){



				if(target!=null){



				target.innerHTML = loadingHtml;



				}



			}



			if(url.indexOf("?")>=0){url+="&rid=" + Math.random();}



			else{url+="?rid=" + Math.random();}



			if(container==""){alert("There is no container.");}



			



			xho.onreadystatechange=function()



				{



						if(xho.readyState==4){



							var response = xho.responseText;



							if(target!=null){



							target.innerHTML=response;



							}



						}



				}



			xho.open("GET",url,true);



			xho.send(null);



		}//end get



		



	this.setPostInfo=function(info){postInfo = info;}



	this.setLoadHtml=function(html){loadingHtml=html;}



	



	this.post=function(url,container)



		{



			var target = document.getElementById(container);



			if(loadingHtml!=""){



				if(target!=null){



				target.innerHTML = loadingHtml;



				}



			}



			if(url.indexOf("?")>=0){url+="&rid=" + Math.random();}



			else{url+="?rid=" + Math.random();}



			if(container==""){alert("There is no container.");}



			



			xho.onreadystatechange=function()



				{



						if(xho.readyState==4){



							var response = xho.responseText;



							if(target!=null){



							target.innerHTML=response;



							}



						}



				}



			xho.open("POST",url,true);



			xho.setRequestHeader("Content-type", "application/x-www-form-urlencoded")



			xho.send(postInfo);



		}//end post



}//end class







//class functions



