// JavaScript Document

function sendRequestAjax(){
	var ajaxFunction;
	var xmlHttp = null;	
	var  bComplete = false;
	
	addCarga();
	
// Get the HTTP Object
	try{	  // Internet Explorer
	    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	catch (e){	  // Firefox, Opera 8.0+, Safari
	  try{
	    xmlHttp=new XMLHttpRequest();
	    }
	  catch (e){
	    try{
	      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	      }
	    catch (e){
	      alert("Your browser does not support AJAX!");
	      return false;
	      }
	    }
	  }
	
	if (!xmlHttp) return null;
	
	this.connect = function(urlDesti, funcioReb,paramPost){
		paramPost=paramPost||'';
		if (xmlHttp != null) {
			bComplete = false;
			 if(paramPost!=''){
		        xmlHttp.open("POST", urlDesti, true);
		    } else {
		        xmlHttp.open("GET", urlDesti, true);
		    }
//			xmlHttp.open("POST", urlDesti, true);
			//xmlHttp.open("GET", urlDesti, true);
			//quan rebem la resposta
			xmlHttp.onreadystatechange = function(){
        		if (xmlHttp.readyState == 4 && !bComplete){// && xmlHttp.status == 200
          			bComplete = true;
					remCarga();
          			funcioReb(xmlHttp);
					//xmlHttp.onreadystatechange=null;
    			}
			};
			//si li pasem algun parametre per post
			if(paramPost!=''){
		        xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		        xmlHttp.send(paramPost);
				
		    } else {
		       	xmlHttp.send(null);
		    }
//				xmlHttp.send(null);
		}
	};
	return this;
}
 
// Change the value of the outputText field
function setOutput(){
	//xmlHttp.overrideMimeType('html/xml');
    if(xmlHttp.readyState == 4){
	
		//var responseText = xmlHttp.responseText;
		var responseXML = xmlHttp.responseXML;
		if(ajaxFunction=="upperCase"){
			try{
				//var document1 = (new DOMParser()).parseFromString(responseText, "text/xml");	
				var response_stat = responseXML.getElementsByTagName('pet')[0].firstChild.data;
			 	document.getElementById('outputText').value = "0-"+response_stat;
			}catch(e){
				  document.getElementById('outputText').value = e.description ; 
			}
		}else{
			document.getElementById('outputText').value = "not upercase-"+xmlHttp.responseText;
		}	
    }
}

//AJAX IMPLEMENTATION
// Implement business logic    
/*
var ajaxFunction;
var xmlHttp = null;

function callAjaxFunction(urlDesti){    
    xmlHttp = getXMLHttpObject();
	ajaxFunction=accio;
    if (xmlHttp != null) {
		 xmlHttp.open("GET", urlDesti, true);
		xmlHttp.onreadystatechange = setOutput;
      
        xmlHttp.send(null);    
    }	
}
*/
// Get the HTTP Object
/*
function getXMLHttpObject(){
	//var xmlHttp;
	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){
	      alert("Your browser does not support AJAX!");
	      return false;
	      }
	    }
	  }
	  return xmlHttp;
}
 */







