
function objetoAjax(){
        var xmlhttp=false;
        try {
               xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
               try {
                  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
               } catch (E) {
                       xmlhttp = false;
               }
        }

        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
               xmlhttp = new XMLHttpRequest();
        }
        return xmlhttp;
}


function EjecutarScript(Script,Capa,OnLoadCapa)
{
        //alert(Script);
		var ajax=objetoAjax();
        ajax.open("GET",Script);
        ajax.onreadystatechange=function()
			{
				if (ajax.readyState==4)
						{
						if (typeof OnLoadCapa != "undefined") {OnLoadCapa();} //ESTA FUNCION ME SIMULA EL EVENTO ONLOAD CAPA. SE PUEDE PASAR O NO POR PARAMETRO. SI NO ME LA PASAN TODOS TAN CONTENTOS
						document.getElementById(Capa).innerHTML=ajax.responseText;
						}
      		}
        ajax.send(null);
}

function actualizarFiltro(obj)
{
		var ajax=objetoAjax();
		Sec=new Date();
        ajax.open("GET","proc/ajaxActualizaFiltro.php?obj="+obj.name+"&value="+(obj.checked?"1":"0")+'&'+Sec.getTime());
        ajax.onreadystatechange=function() {if (ajax.readyState==4) a=1;}
        ajax.send(null);
}


function AbrePagina(Pagina)
{
if(Pagina!="CAPAS/PORTADA/index.php") window.location.hash="#top";
document.getElementById('Contenido').innerHTML="<br><br><br><br><br><br><br><br><br><br><br><div align=center class=TituloFicha></div>";
EjecutarScript(Pagina,'Contenido',CargandoPagina('Contenido'));
}

function EnviarConsulta(IdArt,Cons)
{
Pagina="CAPAS/FICHA/AjaxConsulta.php?IdArt="+IdArt+"&Consulta="+Cons;
EjecutarScript(Pagina,'CampoConsulta');
}

function EnviarPeticion(Peticion)
{
Sec=new Date();
Pagina="CAPAS/LISTADOS/ProcesaPeticion.php?Peticion="+Peticion+'&'+Sec.getTime();
EjecutarScript(Pagina,'SinDatos');
}

function EventoCategoria(Categ,SubCat)
{
if(document.getElementById('Fila'+Categ).style.display=='none')
	{
	document.getElementById('Fila'+Categ).style.display='';
	EjecutarScript('CAPAS/CATEGORIAS/AjaxGeneraSubCat'+SubCat+'.php?Id='+Categ,'div'+Categ,CargandoCategoria('div'+Categ));
	}
else {document.getElementById('Fila'+Categ).style.display='none';}
}

function CargandoCategoria(Capa)
{
document.getElementById(Capa).innerHTML="<div align=center><font color=000000><img src=MULTIMEDIA/imagenes/loading_peque.gif border=0 width=10>&nbsp;Cargando...</font></div>";
}

function CargandoPagina(Capa)
{
document.getElementById(Capa).innerHTML="<br><br><br><br><br><br><br><br><br><br><br><div align=center class=TituloFicha><img src=MULTIMEDIA/imagenes/loading_grande.gif border=0></div>";
}

function AddCarrito(Id)
{
Sec=new Date();
document.getElementById('Carrito').innerHTML="<div align=center>Actualizando...</div>";
EjecutarScript('CAPAS/CARRITO/AjaxAdd.php?Id='+Id+'&Cantidad='+document.getElementById(Id).value+'&'+Sec.getTime(),'Carrito');
}

function QuitarCarrito(Id)
{
Sec=new Date();
document.getElementById('Carrito').innerHTML="<div align=center>Actualizando...</div>";
EjecutarScript('CAPAS/CARRITO/AjaxQuitar.php?Id='+Id+'&'+Sec.getTime(),'Carrito');
}

function IntroCantidad(Tag,IdArticulo)
{
TagCantidad="<table width=80 border=0 cellspacing=0 cellpadding=0><tr><td align=center><span class=LetraCantidad>Cantidad:<br><input id=Cantidad type=text size=3 maxlength=3 class=CampoCantidad value=1><br><strong><a href=javascript:AddCarrito('"+IdArticulo+"')>[Comprar]</strong></span></td></tr></table>";
//alert(TagCantidad);
//document.getElementById(Tag).innerHTML=TagCantidad;
}

function ActualizaNumeroPaso(Paso,Titulo)
{
document.getElementById('NumPaso').innerHTML=Paso;
document.getElementById('TituloPaso').innerHTML=Titulo;
}

function EnviarConsultaPrecio(Id)
{
AbrePagina('CAPAS/CARRITO/ConsultarPrecio_Procesa.php?Id='+Id+'&Preguntar='+document.getElementById('PreguntarPor').value+'&Tlf='+document.getElementById('Tlf').value);
}


function SelectFormaPago(Formulario)
{
if(Formulario.TipoDePago[0].checked || Formulario.TipoDePago[2].checked) {document.getElementById('FormPaypal').submit();}
else {EjecutarScript('CAPAS/FINALIZAR/PASO_4.php','Pasos',ActualizaNumeroPaso(4,'Información bancaria'));}
}

function ValidarForm()
{
datos="RazonSocial="+document.getElementById('RazonSocial').value;
datos+="&CIF="+document.getElementById('CIF').value;
datos+="&Direccion="+document.getElementById('Direccion').value;
datos+="&Poblacion="+document.getElementById('Poblacion').value;
datos+="&Provincia="+document.getElementById('Provincia').value;
datos+="&CodigoPostal="+document.getElementById('CodigoPostal').value;
datos+="&Pais="+document.getElementById('Pais').value;
datos+="&Telefono1="+document.getElementById('Telefono1').value;
//datos+="&Telefono2="+document.getElementById('Telefono2').value;
datos+="&Fax="+document.getElementById('Fax').value;
datos+="&E-mail="+document.getElementById('E-mail').value;
//datos+="&Skype="+document.getElementById('Skype').value;
EjecutarScript('CAPAS/FINALIZAR/PASO_3.php?'+datos,'Pasos',ActualizaNumeroPaso(3,'Elegir forma de pago'))
}


function ReturnPaypal()
{
AbrePagina('CAPAS/FINALIZAR/index.php');
setTimeout("EjecutarScript('CAPAS/FINALIZAR/PASO_5.php','Pasos', ActualizaNumeroPaso(5,'Finalizar pedido'))",150);
}

//me pasa a session un input por ajax
function input2Session(nombre,valor){
		var ajax=objetoAjax();
		Sec=new Date();
        ajax.open("GET","http://main.intermotor.es/lmcarrera/ajax/input2Session.php?nombre="+nombre+"&valor="+valor+"&"+Sec.getTime());
        //ajax.onreadystatechange=function() {alert()}
        ajax.send(null);
}

function validarnewUserForm(obj){
	var msg="Los siguientes campos son obligatorios:\n";
	var valido=true;
	if(obj.RazonSocial.value.replace(" ","")=="") {valido=false; msg+="-Nombre\n";}
	if(obj.Mail.value.replace(" ","")=="") {valido=false; msg+="-E-mail\n";}
	if(obj.Password.value.replace(" ","")=="") {valido=false; msg+="-Password\n";}
	if(!obj.AceptoLOPD.checked) {valido=false; msg+="-Debes aceptar la política de protección de datos\n";}
	if(valido) return true; else{alert(msg); return false;}
}

function procPaisDestino(pais){
if(pais=="Espa&ntilde;a"||pais=="espa&ntilde;a"||pais=="Spain"||pais=="spain"){
	document.getElementById('formaPago_visa').disabled="";
	document.getElementById('formaPago_domiciliacion').disabled="";
	document.getElementById('formaPago_transferencia').disabled="";
	document.getElementById('formaPago_contrareenvolso').disabled="";
	
	document.getElementById('formaEnvio_correos').disabled="";	
	document.getElementById('formaEnvio_agencia').disabled="";	
	
	document.getElementById('consultarFormaPago').innerHTML="";	
		document.getElementById('consultarFormaPago2').innerHTML="";
	}
else if(pais=="Portugal"||pais=="portugal"){
	document.getElementById('formaPago_visa').disabled="";	
	document.getElementById('formaPago_domiciliacion').disabled="disabled";
	document.getElementById('formaPago_transferencia').disabled="disabled";
	document.getElementById('formaPago_contrareenvolso').disabled="disabled";
		
	document.getElementById('formaEnvio_correos').disabled="";	
	document.getElementById('formaEnvio_agencia').disabled="";	
		
	document.getElementById('consultarFormaPago').innerHTML="";	
		document.getElementById('consultarFormaPago2').innerHTML="";
	}
	
else{
	document.getElementById('formaPago_visa').disabled="disabled";
	document.getElementById('formaPago_domiciliacion').disabled="disabled";
	document.getElementById('formaPago_transferencia').disabled="disabled";
	document.getElementById('formaPago_contrareenvolso').disabled="disabled";
	
	document.getElementById('formaEnvio_correos').disabled="disabled";	
	document.getElementById('formaEnvio_agencia').disabled="disabled";	
	
	document.getElementById('consultarFormaPago').innerHTML="consultar";
	document.getElementById('consultarFormaPago2').innerHTML="consultar";
	}
}

function popupLaboratorios(id){window.open('secretarias.php?id='+id,'popup' ,'width=700,height=500,scrollbars=YES')}
function popupSecretarias(){window.open('delegacion.php','solicitud','menubar=0,resizable=0,width=1,height=1');}


