//******************* CODIGO AJAX ************************************
   var http_request = false;
   var tipo_resp = 0; //xml
   var funcion_resp = 0; // alert
   var nom1 = '';     
   function ajaxRequest(valores, url, op, funcion) {
      tipo_resp = op;
	  funcion_resp = funcion;
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('No se pudo crear la instancia XMLHTTP');
         return false;
      }
      document.getElementById("warning").style.visibility = "visible";
      http_request.onreadystatechange = accion;
      http_request.open('POST', url, true);
	  http_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  	  http_request.send(valores);
   }

	// OP 0-XML, 1-Text
	// FUNCION segun el numero usaremos el valor obtenido pasandolo a una funcion especifica
   function accion() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
			if (tipo_resp == 0) {
				var xmldoc = http_request.responseXML;
			} else {
				var xmldoc = http_request.responseText;
			}            
			switch (funcion_resp){
			 	// Actualizar
				case 0 : alert(xmldoc); break;
				case 1 : after_send(xmldoc); break;
			}
		    document.getElementById("warning").style.visibility = "hidden";
         } else {
            alert('Hubo un problema con la petición.');
      		document.getElementById("warning").style.visibility = "hidden";
         } // 200 
      } // 4
   } // fin function
//******************* CODIGO AJAX ************************************
//***********************************************************************

function after_send(resp)
{
	document.getElementById("forma_contacto").innerHTML = resp;
}

function formaGET(form){
var cad = '';
	try{
	    for (var i = 0; i < form.length; i++) {
	    	
	        cad = cad + form.campo[i].id+'='+encodeURIComponent(form.campo[i].value) + '&';
	    }
    }
	catch (e) {}
    var l = cad.length;
	return cad.substr(0,l-1);
}

function enviar(){

	var valores = formaGET(document.forms[0])+"&_envio=1";
	//alert (valores);
	ajaxRequest(valores,'index.php',1,1);
	return false;
}

function al_cargar(){
	var id = document.getElementById('id_cont').value;
	var t = document.getElementById('tipo').value;
	if (id > 0) {
		var params = "_irc="+id+"&tipo="+t;
		ajaxRequest('index.php?'+params,1,2);
	}
	return false;
}

function get_value(str, tag){
	//var str = indexOf()
	var i = str.indexOf('<'+tag+'>');
	var f = str.indexOf('</'+tag+'>');
	if (i==-1) return false; 
	
	var t = '<'+tag+'>';
	i = i + (t.length*1);
	return str.substring(i,f);
}
