/**
*
* @ joe is class Ajax  create  easy for use and understand easy easy ,it's javascript  object oriented (OOP)
*@  this joe  it's version 1.0 used had plobem  and recall  to  kunama_cs@hotmail.com 
*@ autore  joemodify  (kunama_cs@hotmail.com)  programer  novice *-*
*

function how to use
addvarform(formname); //send element form tag
addvar("name","value");//set value
joeProcess("URL","DIVID");
**/



function  joe(){//CLASS JOE 
	var self=this;
	this.joeXML="";
	this.joeParam="";
	this.joeArea="";
	this.joeURL="";
	this.method="POST";	
	this.joeResponseType="TEXT";
	this.joeResponseText="";
	this.joeReponseValue="";
	this.joePicProcess="<center><br><br>Loading ...<br><img src=images/indicator_arrows.gif><br><br><br></center>";
	this.joePicProcess_inputtext="<center><img src=images/indicator_arrows.gif></center>";

//Fuction Check Browser 
	this.checkbrowser=function(){
	this.joeXML="";
		try{ //try 1
		//alert("Microsoft");
				this.joeXML=new 	 ActiveXObject("Microsoft.XMLHTTP");			
				//return this.joeXML;
		}catch(e){
		try{//try 2
		//alert("Msxml2");
				this.joeXML=new ActiveXObject("Msxml2.XMLHTTP");		
				//return this.joeXML;
			}catch(e){
				try{//try 3				
				this.joeXML=new XMLHttpRequest();
				//return this.joeXML;
				//alert("fire fox");
					}catch(e){
						alert("joe not support this browser"); 
						return false;
						}//end try 3
				}//end try 2		
			}//end try 1
			
			return this.joeXML;
		}//end Function check browser 
	
/*Function set variable  most  form  and  every type   
ex
		addvarform(document.formname);
*/
this.addvarform = function(myForm) {
		var aParams = new Array();  
			for (var i=0 ; i < myForm.elements.length; i++) {
				var formElement = myForm.elements[i];
				if(formElement.type=='checkbox' && !formElement.checked){ continue;} 
				if(formElement.type=='radio' && !formElement.checked){ continue;} 
            	var sParam = encodeURIComponent(myForm.elements[i].name);
				//var sParam = myForm.elements[i].name;
               	sParam += "=";
               	sParam += encodeURIComponent(myForm.elements[i].value);
				//sParam += myForm.elements[i].value;
               	aParams.push(sParam);
           	}     
            this.joeParam=aParams.join("&");        
	}//end Function addvarform	
	
//Function addvar   for set variable	
this.addvar=function(name,value){
	if(this.joeParam.length==0){
		this.joeParam=name+"="+value;
		}else{
		this.joeParam+="&"+name+"="+value;	
		}
	}//end Function addvar	
//send random number  for url 		
this.gettmp=function(){	 this.addvar("tmp",Math.random());}
//Function send data  of method  GET or POST

this.SendTypeMethod=function(){	
		if(this.method=="GET"){
				var self=this;
				self.joeURL+="?"+this.joeParam;
				this.joeXML.open(this.method,self.joeURL,true);
				
			}else{
			//this.URLString = this.getRequestBody(this.formElement);
			this.joeXML.open(this.method,this.joeURL,true);			
						}
		if(this.method=="POST"){
		try{
			//application/x-www-form-urlencoded  ,  multipart/form-data		
			this.joeXML.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 
		}catch(e){}
						}
	}//end function SendTypeMethod
	
	
//Function  WaitFromServer  Call and  Wait from server 	 use Show data  from page call
	this.WaitFromServer_Process=function(){ 
		if(self.joeXML.readyState==4){
			this.joeResponseText=this.TextResponse();	
			if(this.joeResponseText!=""){ alert(this.joeResponseText);	}
			}
			}//end Function Wait from server 		

		
//Function  WaitFromServer   Call and  Wait from server 	 use Show data  from page call
	this.WaitFromServer_Showdata=function(){ 
		if(self.joeXML.readyState==4){				
			document.getElementById(this.joeArea).innerHTML=this.TextResponse();	
			}else{
			document.getElementById(this.joeArea).innerHTML=this.joePicProcess_inputtext;
				}	
			}//end Function Wait from server
			
	
	//Function  type responsse is reutrn value type  Text or XML
this.TextResponse=function(){
	var self=this;	
	if(self.joeResponseType=="TEXT"){	
		 return  self.joeXML.responseText;
		}else{//XML
		 return  self.joeXML.responseXML;
			}			
	}	//end Funtion typeresponse
	

/**       Function joeProcess  call this Function for user  
ex		addvar(name,value); set fix variable
			addvarform(formname);  //this.form  or document.formname  , send variable  form
			joeProcess(URL,divid);      			
**/		

this.joeProcess=function(url,divID){
	var self=this;
	self.checkbrowser();
	this.joeArea=divID;
	this.gettmp();
	this.joeURL=url;		
	this.SendTypeMethod();//open("GET OR POST","URL",true);  function SendTypeMethod	
	this.joeXML.onreadystatechange=function(){
	if(self.joeArea.length==0){		
		self.WaitFromServer_Process();
		}else{
		self.WaitFromServer_Showdata();
	}
	}

	this.joeXML.send(this.joeParam);
	}//end Function joeProcess		
	/*********************************/
		
	}//end class

	
/**********************************************************copy rigth @ joemodify **************************************************************************/

	
	