	/** ajax.js                                      **
	 ** (c) Nacex 2006                                   **
	 ** author : Pedro Puertas                           **/
	function ajax(sURL, sMethod,form,response,synchronous){
		var asynchronous=true;
		if(synchronous!=null)asynchronous=synchronous;
	  var xmlhttp, bComplete = false, sVars = "";
	  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
	  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
	  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
	  catch (e) { xmlhttp = false; }}}
	  if (!xmlhttp) {
	  	alert("No puedo ejecutar AJAX. Actualice su navegador");
		return null;
	  }
	
	  bComplete = false;
	  sMethod = sMethod.toUpperCase();
	
	    try {
	    if (form != null) {
			  	for (i = 0; i < form.elements.length; i++) {
							if (sVars.length > 0) sVars += "&";
							if ((form.elements[i].name!=null) && (form.elements[i].name!="")) {
								if ((form.elements[i].type!='checkbox') || (form.elements[i].type=='checkbox' && form.elements[i].checked==true)) {
										sVars += form.elements[i].name+"="+encodeURIComponent(form.elements[i].value);
								}
							} else {
								if ((form.elements[i].type!='checkbox') || (form.elements[i].type=='checkbox' && form.elements[i].checked==true)) {
									sVars += form.elements[i].id+"="+encodeURIComponent(form.elements[i].value);
								}
							}
						}
		  	}
		  	
	      if (sMethod == "GET"){
	        if (sVars != null && sVars.length > 0) sVars = "?"+sVars;
									xmlhttp.open(sMethod, sURL+sVars, asynchronous);
	        sVars = "";
	      }
	      else{
	        xmlhttp.open(sMethod, sURL, asynchronous);
	        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
	        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	      }
	      xmlhttp.onreadystatechange = function(){
	        if (xmlhttp.readyState == 4 && !bComplete){
	          bComplete = true;
	          if (response != null) response(xmlhttp.responseText);
	        }
		  };
	      xmlhttp.send(sVars);
	    }
	    catch(z) { 
		 return false; 
		}
	    return true;
	  }
	
	function ajaxPanel(sURL, sMethod, form, panel){
	  var xmlhttp, bComplete = false, sVars = "";
	  var aux = null;
	  if (typeof(panel) == 'string') {
	     aux = document.getElementById(panel);
	  }else if (typeof(panel) == 'object') {
	     aux = panel;
	  }
	  
	  if (!aux){
	    alert('Objeto incorrecto');
	    return null;
	  }else{
	     try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
	     catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
	     catch (e) { try { xmlhttp = new XMLHttpRequest(); }
	     catch (e) { xmlhttp = false; }}}
	     if (!xmlhttp) {
	  	     alert("No puedo ejecutar AJAX. Actualice su navegador");
		       return null;
	     }
	
	     bComplete = false;
	     sMethod = sMethod.toUpperCase();
	
	     try {
	       if (form != null) {
			  	    for (i = 0; i < form.elements.length; i++) {
							       if (sVars.length > 0) sVars += "&";
							       if ((form.elements[i].name!=null) && (form.elements[i].name!="")) {
								         if ((form.elements[i].type!='checkbox') || (form.elements[i].type=='checkbox' && form.elements[i].checked==true)) {
										           sVars += form.elements[i].name+"="+encodeURIComponent(form.elements[i].value);
								         }
							       } else {
								         if ((form.elements[i].type!='checkbox') || (form.elements[i].type=='checkbox' && form.elements[i].checked==true)) {
								            	sVars += form.elements[i].id+"="+encodeURIComponent(form.elements[i].value);
								         }
							       }
						    }
		  	   }
	       if (sMethod == "GET"){
	         if (sVars != null && sVars.length > 0) sVars = "?"+sVars;
									 xmlhttp.open(sMethod, sURL+sVars, true);
	         sVars = "";
	       }
	       else{
	         xmlhttp.open(sMethod, sURL, true);
	         xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
	         xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	       }
	       xmlhttp.onreadystatechange = function(){
	          if (xmlhttp.readyState == 4 && !bComplete)
	          {
	            bComplete = true;
	            //Escribimos el texto directamente en el panel.
	            aux.innerHTML = xmlhttp.responseText;
	          }
		       };
	        xmlhttp.send(sVars);
	     }catch(z) { 
		       return false; 
		    }
		 }
	  return true;
	}
	
	
	function ping() {
	 ajax('ping.do', "GET", null, null);
		setTimeout("ping()", 1000*60*10);
	}
