//2006 11 28 15:18
var XMLHttpRequestObject = createXMLHttpRequestObject();

function GetXmlHttpObject() { 
	var objXMLHttp=null
	if (window.XMLHttpRequest)  {
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}

function createXMLHttpRequestObject()
{
  var XMLHttpRequestObject = false;
  
  try
  {
    XMLHttpRequestObject = new XMLHttpRequest();
  }
  catch(e)
  {
    var aryXmlHttp = new Array(
                               "MSXML2.XMLHTTP",
                               "Microsoft.XMLHTTP",
                               "MSXML2.XMLHTTP.6.0",
                               "MSXML2.XMLHTTP.5.0",
                               "MSXML2.XMLHTTP.4.0",
                               "MSXML2.XMLHTTP.3.0"
                               );
    for (var i=0; i<aryXmlHttp.length && !XMLHttpRequestObject; i++)
    {
      try
      {
        XMLHttpRequestObject = new ActiveXObject(aryXmlHttp[i]);
      } 
      catch(e){document.write("createXMLHttpRequestObject: XMLHttpRequestObject Error");}
    }
  }
  
  if (!XMLHttpRequestObject)
  {
    alert("Error: failed to create the XMLHttpRequest object.");
  }
  else 
  {
    return XMLHttpRequestObject;
  }
}


function totax(laid, cual, div) {
//valor a mandar a id, cual php lo procesa (sin.php) y en que div se muestra.
//Por fin se me ocurre una rutina AJAX generica
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("No se puede gestionar la web con este navegador: Usar Firefox o IExplorer")
		return false
	}
	
	var url=cual+".php"
	url=url+"?id="+laid
	url=url+"&amp;sid="+Math.random()
	

	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		stateChangeddi(xmlHttp, div);
	}

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	return true;
}


function ptotax(laid, cual, div) {
//valor a mandar a id, cual php lo procesa (sin.php) y en que div se muestra.
	var xmlHttp= new GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("No se puede gestionar la web con este navegador: Usar Firefox o IExplorer")
		return
	}
	var url=cual+".php"
	url=url+"?id="+laid
	url=url+"&amp;sid="+Math.random()
			
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		stateChangedpdi(xmlHttp, div);
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}


function stateChangedpdi(req,lid)
{
	parent.document.getElementById(lid).innerHTML = req.responseText;
}


function stateChangeddi(req,lid)
{
	document.getElementById(lid).innerHTML = req.responseText;
}




function jotax(laid, cual, div) {
//valor a mandar a id, cual php lo procesa (sin.php) y en que div se muestra.
//Por fin se me ocurre una rutina AJAX generica
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("No se puede gestionar la web con este navegador: Usar Firefox o IExplorer")
		return false
	}
	
	var url=cual+".php"
	url=url+"?id="+laid
	url=url+"&amp;sid="+Math.random()
	

	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		stateChangedji(xmlHttp, div);
	}

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	return true;
}

function stateChangedji(req,lid)
{
	document.getElementById(lid).innerHTML = req.responseText;
	eval(document.getElementById(lid).innerHTML);
}



function checkFormInput(keyEvent, dataSource, idForm)
{
  keyEvent = (keyEvent) ? keyEvent: window.event;
  input = (keyEvent.target) ? keyEvent.target : keyEvent.srcElement;
  
  if(keyEvent.type == "checkbox")
  {
    keyEvent.value = keyEvent.checked;
  }
  else if(keyEvent.type == "radio")
  {
    keyEvent.value = keyEvent.checked;
    if (keyEvent.value)
    {
      for(i=0; i<document.getElementById(idForm).elements.length - 1; i++)
      {
        if(document.getElementById(idForm).elements[i].name==keyEvent.name)
        {
          document.getElementById(idForm).elements[i].value = document.getElementById(idForm).elements[i].checked;
        }
      }
    }
  }
}

function sendFormData(idForm, dataSource, divID, ifLoading)
{
  var postData='';
  var strReplaceTemp;
  
  if(XMLHttpRequestObject)
  {
    XMLHttpRequestObject.open("POST", dataSource);
    XMLHttpRequestObject.setRequestHeader("Method", "POST " + dataSource + " HTTP/1.1");
	  XMLHttpRequestObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	  
    XMLHttpRequestObject.onreadystatechange = function()
    {
      if (XMLHttpRequestObject.readyState == 4 &&
          XMLHttpRequestObject.status == 200)
      {
        try
        {
          var objDiv = document.getElementById(divID);
          objDiv.innerHTML = XMLHttpRequestObject.responseText;
        }
        catch(e){document.write("sendFormData: getElementById(divID) Error");}
      }
      else
      {
        if(ifLoading)
        {
          try
          {
            var objDiv = document.getElementById(divID);
            objDiv.innerHTML = "<img src=loading.gif>";
          }
          catch(e){document.write("sendFormData->ifLoading: getElementById(divID) Error");}
        }
      }
    }
    
    for(i=0; i<document.getElementById(idForm).elements.length - 1; i++)
    {
      strReplaceTemp = document.getElementById(idForm).elements[i].name.replace(/\[\]/i, "");
      postData += "&aryFormData["+strReplaceTemp+"][]="+document.getElementById(idForm).elements[i].value;
    }
    
    postData += "&parm="+new Date().getTime();
    try
    {
      XMLHttpRequestObject.send(postData);
    }
    catch(e){document.write("sendFormData: XMLHttpRequestObject.send Error");}
  }
}

function privacidad() {
	document.body.style.cursor = 'wait';
	var xmlHttp;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp) {

		var url="obtenpresen.php";
		url=url+"?id=28";
		url=url+"&amp;sid="+Math.random();


		xmlHttp.onreadystatechange=function() {
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
				mensajea = xmlHttp.responseText;
				mensajek = mensajea.replace(/<br \/>/ig,"\n");

				mensajef = mensajek.replace(/\n\r/ig,"\n");
				mensajep = mensajef.replace(/\n\n/ig,"\n");

				document.body.style.cursor = 'default';
				priv = confirm(mensajep);
				if (priv == false) {
					document.getElementById("apd").checked = false;
				} else {
					document.getElementById("apd").checked = true;
				}
			}
		}


		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);

	}
}

function sinborde(cual) {
	document.getElementById(cual).style.border="2px inset #888888";
}

function envi() {
//Rutina de verificacion y envio al verificador de correo php
	document.body.style.cursor = 'wait';
	document.getElementById("Enviar").style.display = 'none';
	var apd;
	var txt;
	var asu;
	var ema;
	var nom;
	apd = document.getElementById("apd");
	txtp = document.getElementById("txt").value;
	txt = encodeURIComponent(txtp);
	asu = document.getElementById("asu").value;
	ema = document.getElementById("ema").value;
	nom = document.getElementById("nom").value;
	apdv = document.getElementById("apd").checked;
	romper = 0;
	
	if (apd.checked == false) {
		alert ("El mensaje no puede enviarse sin aceptar las condiciones de protección de datos");
		romper = 5;
		document.getElementById("apd").style.border="2px solid red";
		document.getElementById("apd").style.height="20px";
		document.getElementById("apd").style.width="20px";
	}
	
	if (romper == 0 & (txt.length == 0 || asu.length == 0 || ema.length == 0 || nom.length == 0)) {
		alert("Faltan campos por rellenar");
		
		if (txt.length == 0) {
			document.getElementById("txt").style.border="2px solid red";
			romper = 4;
			document.getElementById("txt").focus();	
		}		
		if (asu.length == 0) {
			document.getElementById("asu").style.border="2px solid red";
			romper = 3;
			document.getElementById("asu").focus();	
		}
		if (ema.length < 5) {
			document.getElementById("ema").style.border="2px solid red";
			romper = 2;
			document.getElementById("ema").focus();
		}
		
		if (nom.length < 2) {
			document.getElementById("nom").style.border="2px solid red";
			romper = 1;
			document.getElementById("nom").focus();
		}
	}
	
	apos=ema.indexOf("@")
	dotpos=ema.lastIndexOf(".")
	
	if (romper == 0 & (apos < 1 || dotpos-apos < 2)) {
		alert("Su dirección de correo no es correcta.");
		document.getElementById("ema").style.border="2px solid red";
		romper = 2;
		document.getElementById("ema").focus();
	}
	
	if (romper == 0 & ((txt.indexOf("href=") > -1) || (txt.indexOf("[url=") > -1))) {
		alert("El mensaje incluye enlaces no permitidos");
		romper = 4;
		document.getElementById("txt").style.border="2px solid red";
	}
	
	if (romper == 0)
	{
	//Si falla poner enlace absoluto
		var url = 'http://www.sensortr.com/';
		var postData='';
		url += 'f.php';
		var strReplaceTemp;
		url += '?sid='+Math.random();
		postData = '&aryFormdata[txt][]='+txt;
		postData += '&aryFormdata[ema][]='+ema;
		postData += '&aryFormdata[nom][]='+nom;
		postData += '&aryFormdata[apdv][]='+apdv;
		postData += '&aryFormdata[asu][]='+asu;
		postData += '&parm='+new Date().getTime();

		http_request = false;
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
			http_request = new XMLHttpRequest();
			if (http_request.overrideMimeType) {
				http_request.overrideMimeType('text/html');
			}
		} 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('Su navegador no puede comunicarse con esta sección. Actualícelo o reconfigúrelo.');
			return false;
			document.body.style.cursor = 'default';
			document.getElementById("Enviar").style.display = 'block';
		}

		http_request.onreadystatechange = alertContents;
		http_request.open('POST', url, true);
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http_request.setRequestHeader("Content-length", postData.length);
		http_request.setRequestHeader("Connection", "close");
		http_request.send(postData);
   } else {
		document.body.style.cursor = 'default';
		document.getElementById("Enviar").style.display = 'block';
   }

}

function alertContents() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			//alert(http_request.responseText);
			result = http_request.responseText;
			document.body.style.cursor = 'default';
			if ((result.length > 0) & (result.indexOf("El proceso ha fallado porque") == -1)) {
				document.getElementById('blon2').innerHTML = result;
				document.body.style.cursor = 'default';
			} else {
				document.getElementById('aviso').innerHTML = result;
				document.body.style.cursor = 'default';
				document.getElementById("Enviar").style.display = 'block';
			}
		} else {
			document.body.style.cursor = 'wait';
			alert('No hubo respuesta del servidor. Pruebe de nuevo.');
			document.body.style.cursor = 'default';
		}
	}

}



function sv(id, c) {
	var argu="&c=";
	oSajax.uri="sv.php?id="+id+argu+c;
	oSajax.do_call("nohacenada");
	
	var xmlHttp;
	xmlHttp=GetXmlHttpObject();
	var url="obtenpresen.php";
	url=url+"?id=1";
	url=url+"&amp;sid="+Math.random();

	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		stateChangec(xmlHttp);
	}

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
}


function cuenta(id, c) {
	var argu="&c=";
	oSajax.uri="sv.php?id="+id+argu+c;
	oSajax.do_call("nohacenada");

	var xmlHttp;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{       
		var respu = "Especialistas en electrónica, electricidad del automóvil,<br />vehículo asiático...";
		return
	}
	
	var url="obtenpresen.php";
	url=url+"?id=1";
	url=url+"&amp;sid="+Math.random();

	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		stateChangec(xmlHttp);
	}

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

}

function cuentac(id, c) {
	var argu="&c=";
	oSajax.uri="sv.php?id="+id+argu+c;
	oSajax.do_call("nohacenada");

	blancolor('blon2');
	var ximlHttp;
	ximlHttp=GetXmlHttpObject();
	if (ximlHttp==null)
	{
		var respu = "Especialistas en electrónica, electricidad del automóvil,<br />vehículo asiático...";
		return
	}
	
	var url="obtenpresen.php";
	url=url+"?id=1";
	url=url+"&amp;sid="+Math.random();

	ximlHttp.onreadystatechange=function() {
		if (ximlHttp.readyState==4 || ximlHttp.readyState=="complete")
		stateChangec(ximlHttp);
	}

	ximlHttp.open("GET",url,true);
	ximlHttp.send(null);

}



function clientes() {
	coxmlHttp=GetXmlHttpObject();
	
	var url="clifill.php";
	url=url+"?sid="+Math.random();
	
	coxmlHttp.onreadystatechange=function() {
		if (coxmlHttp.readyState==4 || coxmlHttp.readyState=="complete") {
			stateChangeca(coxmlHttp);
		}
	}

	coxmlHttp.open("GET",url,true);
	coxmlHttp.send(null);
}

function funcionacolor(elem) {
	document.getElementById(elem).style.backgroundColor='#555555';
}


function blancolor(elem) {
	document.getElementById(elem).style.backgroundColor='white';
}

function contactar() {
	document.body.style.cursor = 'wait';	
	retiHttp=GetXmlHttpObject();
	if (retiHttp==null)
	{
		alert ("Se requiere un navegador moderno para ver esta secci&oacute;n.");
		return
	}
	
	var url="obtenpresen.php"
	url=url+"?id=21";
	url=url+"&amp;sid="+Math.random();
	
	retiHttp.onreadystatechange=function() {
		if (retiHttp.readyState==4 || retiHttp.readyState=="complete")
		stateChangecc(retiHttp);
	}
	
	retiHttp.open("GET",url,true);
	retiHttp.send(null);
	
	funcionacolor('blon2');
	document.getElementById('blon2').style.width='654px';
	var conxmlHttp;
	conxmlHttp=GetXmlHttpObject();
	
	var url="confill.php";
	url=url+"?sid="+Math.random();
	
	conxmlHttp.onreadystatechange=function() {
		if (conxmlHttp.readyState==4 || conxmlHttp.readyState=="complete") {
			stateChangeca(conxmlHttp);
			document.body.style.cursor = 'default';
			document.getElementById("nom").focus();
		}
	}

	conxmlHttp.open("GET",url,true);
	conxmlHttp.send(null);
}


function cuentab() {
	oSajax.uri="sv.php";
	oSajax.do_call("nohacenada");

	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		var respu = "Especializados en electrónica, electricidad del automóvil,&lt;br /&gt;vehículo asiático...";
		return
	}
	
	var url="obtenpresen.php";
	url=url+"?id=1";
	url=url+"&amp;sid="+Math.random();

	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		stateChangec(xmlHttp);
	}

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

	oxmlHttp=GetXmlHttpObject();
	if (oxmlHttp==null)
	{
		var respu = "Especializados en electrónica, electricidad del automóvil&lt;br /&gt;vehiculo asiático...";
		return
	}
	
	var url="catfill.php";
	url=url+"?sid="+Math.random();
	
		oxmlHttp.onreadystatechange=function() {
		if (oxmlHttp.readyState==4 || oxmlHttp.readyState=="complete")
		stateChangeca(oxmlHttp);
	}

	oxmlHttp.open("GET",url,true);
	oxmlHttp.send(null);
}


function stateChangec(req) {
	document.getElementById("res1").innerHTML = req.responseText;
}


function stateChangeca(req) {
	if (document.getElementById("blon2")) {
		document.getElementById("blon2").innerHTML = req.responseText;
	} else {
		document.getElementById("blondue").innerHTML = req.responseText;
	}
}

function stateChangecc(req) {
	document.title = req.responseText;
	//funcionacolor('blon2');
	//alert (req.responseText);
	//alert (document.title = "cambio");
}

function GetXmlHttpObject() { 
	var objXMLHttp=null
	if (window.XMLHttpRequest)  {
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}


