﻿//FUNCIONES LAMICHAPA:

function politica(){
window.open("Lamichapa-politica.html","","width=630,height=450,top=214,left=297,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=yes,resizable=yes");
}


///FUNCIONES COMERSA /////////////


function  VerProductos(){
}


function VerNoticias(){
}

function VerContacto(){
}


function VerClientes(){
}



//////////////////FUNCIONES TOY PLANET /////////////////////


///VIDEO BANNER PUBLICITARIO
function Videop(){
window.open("Videop.html","","width=660,height=525,top=200,left=297,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no");
}

//funciones formatos:
function decimal(valor, rlength){
	//alert(valor+"-"+rlength);
v=Math.round(valor*Math.pow(10,rlength))/Math.pow(10,rlength);
//alert(v);
return v;
}
function calc() { 
vent=window.open('','tpv','width=725,height=600,scrollbars=no,resizable=yes,status=yes,menubar=no,location=no');
document.forms[0].submit();
}

///funciones para sumar a una fecha un numero de días que se le pasa por variable:
//SumaFecha(fecha, dias)

 var aFinMes = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); 

  function findeMes(nMes, nAno){ 
   return aFinMes[nMes - 1] + (((nMes == 2) && (nAno % 4) == 0)? 1: 0); 
  } 

   function padNmb(nStr, nLen, sChr){ 
    var sRes = String(nStr); 
    for (var i = 0; i < nLen - String(nStr).length; i++) 
     sRes = sChr + sRes; 
    return sRes; 
   } 

   function makeDateFormat(nDay, nMonth, nYear){ 
    var sRes; 
    sRes = padNmb(nDay, 2, "0") + "/" + padNmb(nMonth, 2, "0") + "/" + padNmb(nYear, 4, "0"); 
   return sRes; 
	
   } 
    
  function incDate(sFec0){ 
   var nDia = parseInt(sFec0.substr(0, 2), 10); 
   var nMes = parseInt(sFec0.substr(3, 2), 10); 
   var nAno = parseInt(sFec0.substr(6, 4), 10); 
   nDia += 1; 
   if (nDia > findeMes(nMes, nAno)){ 
    nDia = 1; 
    nMes += 1; 
    if (nMes == 13){ 
     nMes = 1; 
     nAno += 1; 
    } 
   } 
   return makeDateFormat(nDia, nMes, nAno); 
  } 

  function decDate(sFec0){ 
   var nDia = Number(sFec0.substr(0, 2)); 
   var nMes = Number(sFec0.substr(3, 2)); 
   var nAno = Number(sFec0.substr(6, 4)); 
   nDia -= 1; 
   if (nDia == 0){ 
    nMes -= 1; 
    if (nMes == 0){ 
     nMes = 12; 
     nAno -= 1; 
    } 
    nDia = findeMes(nMes, nAno); 
   } 
   return makeDateFormat(nDia, nMes, nAno); 
  } 

  function SumaFecha(sFec0, sInc){ 
   var nInc = Math.abs(parseInt(sInc)); 
   var sRes = sFec0; 
   if (parseInt(sInc) >= 0) 
    for (var i = 0; i < nInc; i++) sRes = incDate(sRes); 
   else 
    for (var i = 0; i < nInc; i++) sRes = decDate(sRes); 
     return sRes; 
  } 





///fin funcion suma dias a fecha.


function cambiames(cuadro , dia , mes , ano){
	alert("Aqui llega");
url="Php/calendario.php?cuadro="+cuadro+"&dia=1&nuevo_mes="+mes+"&nuevo_ano="+ano;
alert("Hola, la url es:"+url);
capa=document.getElementById("calendario");	
var ajax=nuevoAjax();
		ajax.open("GET",url, true);
		
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4)
			{
				//alert("Esta preparado " +ajax.responseText);
				capa.innerHTML=ajax.responseText;				
			} 
		}
		ajax.send(null);	
}



function modificado(){
document.getElementById("modificado").value=-1;	
}



function mostrar(i){
capa=document.getElementById("Cont");
var ajax=nuevoAjax();

ajax.open("GET", "Php/Mostrar.php?id="+i, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
			capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";			
			}
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 		
		}
ajax.send(null);
}

//FUNCIONES LOGIN:
function Login(anexo){
capa=document.getElementById("Botonera");
contenidoHTML="<img src="+'"'+"images/NoticiaPaso2de3.jpg"+'"'+" onclick="+'"';
contenidoHTML=contenidoHTML+"CompruebaLogin(";
contenidoHTML=contenidoHTML+"'login'";
contenidoHTML=contenidoHTML+")"+'"';																			 
contenidoHTML=contenidoHTML+" onmouseover="+'"'+"ponmanita()"+'"'+ " onmouseout="+'"'+"quitamanita()"+'"'+">";
capa.innerHTML=contenidoHTML;
//alert(contenidoHTML);	
capa=document.getElementById("Cont");
var ajax=nuevoAjax();
if(anexo=="" || anexo=="undefined"){
ajax.open("GET", "Php/Login.php", true);
}else{
ajax.open("GET", "Php/Login.php?Anexo="+anexo, true);	
}
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);
}

function NoLogin(email, clave, anexo){
capa=document.getElementById("Botonera");
contenidoHTML="<img src='images/NoticiaPaso3de3.jpg'>";
capa.innerHTML=contenidoHTML;
capa=document.getElementById("Cont");
var ajax=nuevoAjax();
if(anexo=="" || anexo=="undefined"){
ajax.open("GET", "Php/AltaCliente.php?Email="+email+"&Clave="+clave+"&accion=login", true);
}else{
ajax.open("GET", "Php/AltaCliente.php?Email="+email+"&Clave="+clave+"&accion=login&Anexo="+anexo, true);
	
}

ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);
}

function VerTiendas(num){
	
capa=document.getElementById("Lista");
var ajax=nuevoAjax();

ajax.open("GET", "Php/VerTiendas.php?num="+num, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						//capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			document.location.href="#ListaTiendas";
			} 
					
		}
ajax.send(null);
}

function VerMapa(){
	
capa=document.getElementById("Cont");
var ajax=nuevoAjax();

ajax.open("GET", "Mapa.html", true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);
}
function CatalogosPDF(){
capa=document.getElementById("Cont");
var ajax=nuevoAjax();

ajax.open("GET", "Catalogos.html", true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);
	
	
}

function Registro(){
capa=document.getElementById("Cont");
var ajax=nuevoAjax();

ajax.open("GET", "Php/Registro.php", true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);
}

function CortaNoticia(Id,i){
	
Not="Noticia"+i;
capa=document.getElementById(Not);
var ajax=nuevoAjax();
ajax.open("GET", "Php/CortaNoticia.php?IdNoticia="+Id+"&i="+i, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						//capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);

}

function CargaNoticia(Id, i){
Not="Noticia"+i;
capa=document.getElementById(Not);
var ajax=nuevoAjax();
//alert("Php/CargaNoticia.php?IdNoticia="+Id+"&i="+i);
ajax.open("GET", "Php/CargaNoticia.php?IdNoticia="+Id+"&i="+i, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						//capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);
}

function VerResumen(Id){
capa=document.getElementById("Cont");
var ajax=nuevoAjax();
ajax.open("GET", "Php/VerResumen.php?IdPedido="+Id, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						//capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);
}



function cargaprovincias(Bultos,Importe, num, p){
pais=document.getElementById('Pais').value;
//alert(pais);
if(pais!=""){
var ajax=nuevoAjax();
dirurl="Php/cargaprovincias.php?idpais="+pais+"&B="+Bultos+"&imp="+Importe+"&N="+num;
capa=document.getElementById("ListaProvincias");
//la linea de abajo se muestra como linea 352 en el error de internet explorer.

ajax.open("GET", dirurl, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;

			} 
					
		}
ajax.send(null);		
}
}

function cargaprovincias0(Bultos,Importe, c1, p){
pais=document.getElementById('Pais0').value;
//alert(pais);
if(pais!=""){
var ajax=nuevoAjax();
dirurl="Php/cargaprovincias0.php?idpais="+pais+"&B="+Bultos+"&imp="+Importe+"&N="+num;
capa=document.getElementById("ListaProvincias0");
//la linea de abajo se muestra como linea 352 en el error de internet explorer.

ajax.open("GET", dirurl, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;

			} 
					
		}
ajax.send(null);		
}
}



function cargaprovinciasF(){
pais=document.getElementById('PaisF').value;
//alert(pais);
if(pais!=""){
var ajax=nuevoAjax();
dirurl="Php/cargaprovinciasF.php?idpais="+pais;
capa=document.getElementById("ListaProvinciasF");
//la linea de abajo se muestra como linea 352 en el error de internet explorer.

ajax.open("GET", dirurl, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;

			} 
					
		}
ajax.send(null);		
}
}




//FUNCIONES CATALOGO:

function ActualizaUnidades(i){
	//alert(i);
St="Stock"+i;	
Uni="Unidades"+i;
UniA="UniAntes"+i;
stock=document.getElementById(St).value;

Uniantes=document.getElementById(UniA).value;
Unit=document.getElementById(Uni).value;
Unit=parseInt(Unit);
UnidadesA=parseInt(Uniantes);

if(Unit>0){
document.getElementById(Uni).value=Unit;
}else{
document.getElementById(Uni).value=1;
Unit=1;
}

if(Unit>UnidadesA){
	if(stock+UnidadesA-Unit<0){
		alert("No hay suficiente stock para modificar las unidades");
		document.getElementById(Uni).value=UnidadesA;
		return;
}

Dif=Unit-UnidadesA;
	//alert(Dif);
	//alert(document.getElementById("unidadestotal").value);
	v=document.getElementById("unidadestotal").value*1+Dif;
	//alert(v);
	document.getElementById("unidadestotal").value=v;

	NewStock=stock-Dif;
	//Ha aumentado la cifra, compruebo si hay stock

}else{
	Dif=UnidadesA-Unit;
	NewStock=stock*1+Dif*1;
		//alert(Dif);
		//alert(document.getElementById("unidadestotal").value);
		v=document.getElementById("unidadestotal").value*1-Dif;
		//alert(v);
		document.getElementById("unidadestotal").value=v;

}

Unid=0;
//Unidadestotal=document.getElementById("unidadestotal").value;
Lineas=document.getElementById("lineas").value;
//alert("Al principio Unit vale "+Unit);
Uni="Unidades0";
Unid=document.getElementById(Uni).value;
for(x=1;x<Lineas;x++){
	Uni="Unidades"+x;
	//alert("La "+x+"ª vuelta Unit vale "+Unit);
	Unid=Unid*1+document.getElementById(Uni).value*1;
}
//document.getElementById("unidadestotal").value=Unit;
document.getElementById("TablaCompra").innerHTML="<table width='150' border='0' cellspacing='0' cellpadding='0'><tr><td width='38'>&nbsp;</td><td width='50'>&nbsp;</td><td width='32'>&nbsp;</td><td width='30'>&nbsp;</td></tr><tr><td>&nbsp;</td><td rowspan='2'><div align='left' id='UniCompra' class='Unidades'>"+Unid+" UDS.</div></td><td rowspan='2'><div align='right' id='Bolsa'><img src='images/bolsallena.png' alt='Ver mi compra' width='32' height='44' longdesc='http://www.toyplanet.es' onclick='VerCompra()' onmouseover='ponmanita()' onmouseout='quitamanita()'></div></td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td height='30'>&nbsp;</td></tr></table>";

//alert(Unit);
Sub="Subtotal"+i;
Subt=document.getElementById(Sub).value;
//alert(Subt);
T="Total";
Tt=document.getElementById(T).value;
document.getElementById(St).value=NewStock;

//alert(Tt);
Prec="Precio"+i;
Prect=document.getElementById(Prec).value;
//alert(Prect)
CapaSubTotal=document.getElementById(Sub);
CapaSubTotal.value=(Unit*Prect).toFixed(2);
CapaTotal=document.getElementById(T);
CapaTotal.value=(CapaTotal.value*1-Subt+Unit*Prect).toFixed(2);
P="IdProducto"+i;
IdProducto=document.getElementById(P).value;
id="IdCompra"+i;
Idpedido=document.getElementById(id).value;

var ajax=nuevoAjax();
//alert("Php/ActualizaUnidades.php?IdProducto="+IdProducto+"&Id="+Idpedido+"&Unidades="+Unit+"&Stock="+NewStock);
ajax.open("GET", "Php/ActualizaUnidades.php?IdProducto="+IdProducto+"&Id="+Idpedido+"&Unidades="+Unit+"&Stock="+NewStock, true);
ajax.onreadystatechange=function() 
	{ 
		}
ajax.send(null);

}

function EliminaArticulo(id, i){
	
//////////////
pedidos=document.getElementById("lineas").value;
pedidos=(pedidos*1-1);
if(pedidos<=0){

capa=document.getElementById("Botonera");
capa.innerHTML=	"<img src='images/NoticiasCatalogo.jpg'>";	
	
document.getElementById("TablaCompra").innerHTML="<table width='150' border='0' cellspacing='0' cellpadding='0'><tr><td width='38'>&nbsp;</td><td width='50'>&nbsp;</td><td width='32'>&nbsp;</td><td width='30'>&nbsp;</td></tr><tr><td>&nbsp;</td><td rowspan='2'><div align='left' id='UniCompra' class='Unidades'></div></td><td rowspan='2'><div align='right' id='Bolsa'><img src='images/bolsavacia.png' alt='Tu bolsa está vacía' width='32' height='44' longdesc='http://www.toyplanet.es'></div></td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td height='30'>&nbsp;</td></tr></table>";
}else{
Uni="Unidades"+i;
Unit=document.getElementById(Uni).value;
Unit=parseInt(Unit);
Unidadestotal=document.getElementById("unidadestotal").value;
U=Unidadestotal-Unit;
document.getElementById("TablaCompra").innerHTML="<table width='150' border='0' cellspacing='0' cellpadding='0'><tr><td width='38'>&nbsp;</td><td width='50'>&nbsp;</td><td width='32'>&nbsp;</td><td width='30'>&nbsp;</td></tr><tr><td>&nbsp;</td><td rowspan='2'><div align='left' id='UniCompra' class='Unidades'>"+U+" UDS.</div></td><td rowspan='2'><div align='right' id='Bolsa'><img src='images/bolsallena.png' alt='Ver mi compra' width='32' height='44' longdesc='http://www.toyplanet.es' onclick='VerCompra()' onmouseover='ponmanita()' onmouseout='quitamanita()'></div></td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td height='30'>&nbsp;</td></tr></table>";
document.getElementById("unidadestotal").value=U;

}

////////////
capa=document.getElementById("Cont");
var ajax=nuevoAjax();
ajax.open("GET", "Php/EliminaArticulo.php?Id="+id, true);
ajax.onreadystatechange=function() 
	{ 
	
	if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
				
	
		}
ajax.send(null);	

}

function Catalogo(){

nombre=document.getElementById("NomProducto").value;
edad=document.getElementById("Edad").value;
marca=document.getElementById("Marca").value;
tipo=document.getElementById("Tipo").value;
precio=document.getElementById("Precio").value;


capa=document.getElementById("Botonera");
capa.innerHTML=	"<img src='images/NoticiasCatalogo.jpg'>";	
	
capa=document.getElementById("Cont");
var ajax=nuevoAjax();

//alert("Php/Catalogo.php?nombre="+nombre+"&edad="+edad+"&marca="+marca+"&tipo="+tipo+"&precio="+precio);
ajax.open("GET", "Php/Catalogo.php?nombre="+nombre+"&edad="+edad+"&marca="+marca+"&tipo="+tipo+"&precio="+precio, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);	
}

function VerClipping(historico){
capa=document.getElementById("Cont");
var ajax=nuevoAjax();

//alert("Php/Catalogo.php?nombre="+nombre+"&edad="+edad+"&marca="+marca+"&tipo="+tipo+"&precio="+precio);
ajax.open("GET", "Php/Clipping.php?Historico="+historico, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);	



}


function Prensa(){

capa2=document.getElementById("Botonera");
var ajax2=nuevoAjax();
ajax2.open("GET", "BotoneraPrensa.html", true);
ajax2.onreadystatechange=function() 
	{ 
				
		if(ajax2.readyState==1)
			{
						
						capa2.innerHTML="<div align='center'><img src='images/cargandomini.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax2.readyState==4)
			{
			
			capa2.innerHTML=ajax2.responseText;
			} 
					
		}

ajax2.send(null);	
	
capa=document.getElementById("Cont");
var ajax=nuevoAjax();

//alert("Php/Catalogo.php?nombre="+nombre+"&edad="+edad+"&marca="+marca+"&tipo="+tipo+"&precio="+precio);
ajax.open("GET", "Dossier.html", true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);	
}

function VerDossier(){
capa=document.getElementById("Cont");
var ajax=nuevoAjax();

ajax.open("GET", "Dossier.html", true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);	
}

function VerContacto(){
capa=document.getElementById("Cont");
var ajax=nuevoAjax();

ajax.open("GET", "ContMedios.html", true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);	
}







function Buscar(){

nombre=document.getElementById("NomProducto").value;
edad=document.getElementById("Edad").value;
marca=document.getElementById("Marca").value;
tipo=document.getElementById("Tipo").value;
precio=document.getElementById("Precio").value;

capa=document.getElementById("Botonera");
capa.innerHTML=	"<img src='images/NoticiasCatalogo.jpg'>";	
	
capa=document.getElementById("Cont");
var ajax=nuevoAjax();


ajax.open("GET", "Php/Catalogo.php?nombre="+nombre+"&edad="+edad+"&marca="+marca+"&tipo="+tipo+"&precio="+precio, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);	
}


//función que mira en la sesión si hay alguna compra realizada para el usuario activo, por si recarga la página mostrar la bolsa llena y las unidades.

function BuscaCompra(){
capa=document.getElementById("TablaCompra");
var ajax=nuevoAjax();


ajax.open("GET", "Php/BuscaCompra.php", true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);	
}

function BorraCompra(){
//alert("Al recargar la página los datos de tu compra serán descartados.");
//alert("Se va a cerrar la Página");
//window.document.href.location="http://www.toyplanet.es/desarrollo/Php/BorraCompra.php";	
var ajax=nuevoAjax();
ajax.open("GET", "Php/BorraCompra.php", true);
ajax.onreadystatechange=function() 
	{ 
	if (ajax.readyState==4)
			{
	alert(ajax.responseText);
			}
		}
ajax.send(null);

}

function BorraCompraMsj(){
//alert("Al recargar la página los datos de tu compra serán descartados.");
//alert("Se va a cerrar la Página");
//window.document.href.location="http://www.toyplanet.es/desarrollo/Php/BorraCompra.php";	
var ajax=nuevoAjax();
ajax.open("GET", "Php/BorraCompra.php", true);
ajax.onreadystatechange=function() 
	{ 
	if (ajax.readyState==4)
			{
	alert(ajax.responseText);
			}
		}
ajax.send(null);

}


function Compra(id, anexo){
	
capa0=document.getElementById("Botonera");

if(anexo=="" || anexo=='undefined'){
	capa0.innerHTML="<img src='images/NoticiasCatalogoCompra.jpg' onclick='VerCompra()' onmouseover='ponmanita()' onmouseout='quitamanita()'>";	
}else{
	var ajax2=nuevoAjax();
	ajax2.open("GET", "Php/BanerCompra.php?Anexo="+anexo, true);
	ajax2.onreadystatechange=function() 
	{ 
				
		if(ajax2.readyState==1)
			{
						
			}
				
			if (ajax2.readyState==4)
			{
			capa0.innerHTML=ajax2.responseText;
			
			} 
					
		}
ajax2.send(null);		
}
	
uni=document.getElementById("unidades").innerHTML;
capa=document.getElementById("BotonCompra");
var ajax=nuevoAjax();
capauni=document.getElementById("TablaCompra");
if(anexo=="" || anexo=='undefined'){
	ajax.open("GET", "Php/RegistraCompra.php?IdProducto="+id+"&Unidades="+uni, true);
}else{
	ajax.open("GET", "Php/RegistraCompra.php?IdProducto="+id+"&Unidades="+uni+"&Anexo="+anexo, true);
	
}
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						
			}
				
			if (ajax.readyState==4)
			{
			capauni.innerHTML=ajax.responseText;
			capa.innerHTML="<img src='images/BotonCompra2.jpg' alt='Añadido a mi compra' width='134' height='41' longdesc='http://www.toyplanet.es'/>";
			} 
					
		}
ajax.send(null);		
}



function VerCompra(anexo){
capa=document.getElementById("Botonera");
capa.innerHTML=	"<img src='images/NoticiaPaso1de3.jpg' onclick='Login()' onmouseover='ponmanita()' onmouseout='quitamanita()'>"
	
capa=document.getElementById("Cont");
var ajax=nuevoAjax();
if(anexo=="" || anexo=='undefined'){
	ajax.open("GET", "Php/VerCompra.php", true);
}else{
//alert("Php/VerCompra.php?Anexo="+anexo);
ajax.open("GET", "Php/VerCompra.php?Anexo="+anexo, true);
}
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);
}


function sumauno(objeto, stock){
	valor=document.getElementById(objeto).innerHTML;
	//alert(valor);
	valor=valor*1;
	
	if(valor<100){
	valor=valor*1+1;
		if(stock-valor>=0){	
			document.getElementById(objeto).innerHTML=valor;	
		}else{
			alert("Actualemente no hay stock suficiente para comprar "+valor+" unidades online");
			document.getElementById(objeto).innerHTML=valor-1;
		}
	}
	
}

function restauno(objeto, stock){
	valor=document.getElementById(objeto).innerHTML;
	valor=valor*1;
	if(valor>1){
document.getElementById(objeto).innerHTML=valor*1-1;	
	}
}
//Paginacion:

function VerNoticiasMas(ini,pag){
capa=document.getElementById("Cont");
var ajax=nuevoAjax();
ini=ini*1+4;
pag=pag*1+1;
ajax.open("GET", "Php/NoticiasGen.php?ini="+ini+"&pag="+pag, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						//capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);	
}
function Index(){	
document.location.href="http://www.toyplanet.es/Desarrollo/index.php";

}
function VerNoticias(ini,pag){
capa=document.getElementById("Cont");
var ajax=nuevoAjax();

ajax.open("GET", "Php/NoticiasGen.php?ini="+ini+"&pag="+pag, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						//capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);	
}

function VerNoticiasMenos(ini,pag){
capa=document.getElementById("Cont");
var ajax=nuevoAjax();
ini=ini*1-4;
pag=pag*1-1;
if(ini>=0){
	
ajax.open("GET", "Php/NoticiasGen.php?ini="+ini+"&pag="+pag, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						//capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);
}
}


function VerCatalogoMas(ini, pag, anexo){
	
nombre=document.getElementById("NomProducto").value;
edad=document.getElementById("Edad").value;
marca=document.getElementById("Marca").value;
tipo=document.getElementById("Tipo").value;
precio=document.getElementById("Precio").value;
	
	
capa=document.getElementById("Cont");
var ajax=nuevoAjax();

ini=ini*1+4;

pag=pag*1+1;
//if(anexo=="" || anexo=='undefined'){
	ajax.open("GET", "Php/Catalogo.php?ini="+ini+"&pag="+pag+"&nombre="+nombre+"&edad="+edad+"&marca="+marca+"&tipo="+tipo+"&precio="+precio, true);
//}else{
	//ajax.open("GET", "Php/Catalogo.php?ini="+ini+"&pag="+pag+"&nombre="+nombre+"&edad="+edad+"&marca="+marca+"&tipo="+tipo+"&precio="+precio+"&Anexo="+anexo, true);
//}
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);	
}

function VerCatalogoMenos(ini, pag, anexo){
	
nombre=document.getElementById("NomProducto").value;
edad=document.getElementById("Edad").value;
marca=document.getElementById("Marca").value;
tipo=document.getElementById("Tipo").value;
precio=document.getElementById("Precio").value;


capa=document.getElementById("Cont");
var ajax=nuevoAjax();
ini=ini*1-4;
pag=pag*1-1;
if(ini>=0){
	
	ajax.open("GET", "Php/Catalogo.php?ini="+ini+"&pag="+pag+"&nombre="+nombre+"&edad="+edad+"&marca="+marca+"&tipo="+tipo+"&precio="+precio, true);
	
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);
}
}

function VerCatalogo(ini, pag, anexo){
	
nombre=document.getElementById("NomProducto").value;
edad=document.getElementById("Edad").value;
marca=document.getElementById("Marca").value;
tipo=document.getElementById("Tipo").value;
precio=document.getElementById("Precio").value;
	
	
//alert("Php/Catalogo.php?ini="+ini+"&pag="+pag+"&nombre="+nombre+"&edad="+edad+"&marca="+marca+"&tipo="+tipo+"&precio="+precio);
capa=document.getElementById("Cont");
var ajax=nuevoAjax();
//alert(ini);
	ajax.open("GET", "Php/Catalogo.php?ini="+ini+"&pag="+pag+"&nombre="+nombre+"&edad="+edad+"&marca="+marca+"&tipo="+tipo+"&precio="+precio, true);
	
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);
}

//detalle de producto:
function VerDetalle(id, ini, pag, anexo){
nombre=document.getElementById("NomProducto").value;
edad=document.getElementById("Edad").value;
marca=document.getElementById("Marca").value;
tipo=document.getElementById("Tipo").value;
precio=document.getElementById("Precio").value;


capa=document.getElementById("Botonera");
capa.innerHTML=	"<img src='images/NoticiasCatalogoDetalle.jpg'>";	
	
	//alert("Inicio="+ini+" página es "+pag);
	//pag=pag-1;
capa=document.getElementById("Cont");
var ajax=nuevoAjax();

//alert(ini);	
		//alert("Php/Detalle.php?id="+id+"&ini="+ini+"&pag="+pag+"&Anexo="+anexo);
		ajax.open("GET", "Php/Detalle.php?id="+id+"&ini="+ini+"&pag="+pag+"&nombre="+nombre+"&edad="+edad+"&marca="+marca+"&tipo="+tipo+"&precio="+precio, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);
}

function cargafoto(contenedor, imagen, nombre, enlace){
capa=document.getElementById(contenedor);
capa.innerHTML="<a href='"+enlace+"' target='_blank'><img src='"+imagen+"' alt='"+nombre+"' width='173' height='173' border='0' longdesc='http://www.toyplanet.es' /></a>";	
}

//FUNCIONES CONTACTO:
function Contacto1(){
capa=document.getElementById("Cont");
var ajax=nuevoAjax();

ajax.open("GET", "Contacto.html", true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);		
}
function Contacto2(){
capa=document.getElementById("Cont");
var ajax=nuevoAjax();

ajax.open("GET", "EnDesarrollo.html", true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);		
}
function Contacto3(){
capa=document.getElementById("Cont");
var ajax=nuevoAjax();

ajax.open("GET", "RedesSociales.html", true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);		
}


function Contacto4(){

capa=document.getElementById("Cont");
var ajax=nuevoAjax();

ajax.open("GET", "Php/enviaCV.php", true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);		
}

function Contacto5(){
capa=document.getElementById("Cont");
var ajax=nuevoAjax();

ajax.open("GET", "Contacto2.html", true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);		
}
function AgregaContacto(){
capa=document.getElementById("mensaje");
Email=document.getElementById("email").value;
Nombre=document.getElementById("nombre").value;
Movil=document.getElementById("movil").value;
var ajax=nuevoAjax();

ajax.open("GET", "Php/AgregaContacto.php?Email="+Email+"&Nombre="+Nombre+"&Movil="+Movil, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						//capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);		
}


function Contacto(){
capa=document.getElementById("Cont");
var ajax=nuevoAjax();


///////////

capa2=document.getElementById("Botonera");
var ajax2=nuevoAjax();
ajax2.open("GET", "BotoneraContacto.html", true);
ajax2.onreadystatechange=function() 
	{ 
				
		if(ajax2.readyState==1)
			{
						
						capa2.innerHTML="<div align='center'><img src='images/cargandomini.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax2.readyState==4)
			{
			
			capa2.innerHTML=ajax2.responseText;
			} 
					
		}

ajax2.send(null);	



////////////
ajax.open("GET", "Contacto.html", true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);		
}

//funciones Compromiso Social:
function CompromisoSocial(){
capa=document.getElementById("Cont");
var ajax=nuevoAjax();


///////////

capa2=document.getElementById("Botonera");
var ajax2=nuevoAjax();
ajax2.open("GET", "BotoneraCompromisoSocial.html", true);
ajax2.onreadystatechange=function() 
	{ 
				
		if(ajax2.readyState==1)
			{
						
						capa2.innerHTML="<div align='center'><img src='images/cargandomini.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax2.readyState==4)
			{
			
			capa2.innerHTML=ajax2.responseText;
			} 
					
		}

ajax2.send(null);	



////////////
ajax.open("GET", "Compromiso.html", true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);		
}



function NoticiasCompromiso(){
capa=document.getElementById("Cont");
var ajax=nuevoAjax();

ajax.open("GET", "Php/Noticias.php?t=4", true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);		
}



//Funciones Empresa:
function Empresa(){
capa=document.getElementById("Cont");
capa2=document.getElementById("Botonera");
var ajax=nuevoAjax();
ajax.open("GET", "Mision.html", true);
var ajax2=nuevoAjax();
ajax2.open("GET", "BotoneraEmpresa.html", true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			
			} 
					
		}
ajax.send(null);
ajax2.onreadystatechange=function() 
	{ 
				
		if(ajax2.readyState==1)
			{
						
						capa2.innerHTML="<div align='center'><img src='images/cargandomini.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax2.readyState==4)
			{
			
			capa2.innerHTML=ajax2.responseText;
			} 
					
		}

ajax2.send(null);	
}

function Mision(){
capa=document.getElementById("Cont");
var ajax=nuevoAjax();


ajax.open("GET", "Mision.html", true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);		
}

/////FUNCIONES INDEX///////////////

function inicia(){
	Destacados();
}


function NoticiaPortada(){
capa=document.getElementById("Botonera");
var ajax=nuevoAjax();


ajax.open("GET", "Php/NoticiaPortada.php", true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);
BuscaCompra();
}

function Destacados(){
capa=document.getElementById("Destacados");
var ajax=nuevoAjax();


ajax.open("GET", "Php/Destacados.php", true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);	
}


function Producto(){
capa=document.getElementById("Cont");
var ajax=nuevoAjax();


ajax.open("GET", "EmpProducto.html", true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			} 
					
		}
ajax.send(null);		
}




///////////FUNCIONES DE REGISTRO.PHP//////////////////////////





function cargasubfamilias(){
familia=document.getElementById('Familia').value;
//alert(pais);
if(familia!=""){
var ajax=nuevoAjax();
dirurl="cargasubfamilias.php?id="+familia;
capa=document.getElementById("capasubfamilias");
capa2=document.getElementById("capamarcas");
capa3=document.getElementById("capaformatos");
//la linea de abajo se muestra como linea 352 en el error de internet explorer.

ajax.open("GET", dirurl, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						//capa2.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
						//capa3.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			capa2.innerHTML="<select name='Marca' class='FormularioCaja' id='Marca' tabindex='3' onchange='cargaformatos()'><option value=''>Seleccione___________________</option></select>";
			capa3.innerHTML="<select name='Envase' class='FormularioCaja' id='Envase' tabindex='4'><option value=''>Seleccione___________________</option></select>";
			} 
					
		}
ajax.send(null);		
}
}

function cargamarcas(){
subfamilia=document.getElementById('SubFamilia').value;
//alert(pais);
if(subfamilia!=""){
var ajax=nuevoAjax();
dirurl="cargamarcas.php?id="+subfamilia;
capa=document.getElementById("capamarcas");
capa3=document.getElementById("capaformatos");
//la linea de abajo se muestra como linea 352 en el error de internet explorer.

ajax.open("GET", dirurl, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;
			capa3.innerHTML="<select name='Envase' class='FormularioCaja' id='Envase' tabindex='4'><option value=''>Seleccione___________________</option></select>";
			} 
					
		}
ajax.send(null);		
}
}

function cargaformatos(){
marca=document.getElementById('Marca').value;
//alert(pais);
if(marca!=""){
var ajax=nuevoAjax();
dirurl="cargaformatos.php?id="+marca;
capa=document.getElementById("capaformatos");
//la linea de abajo se muestra como linea 352 en el error de internet explorer.

ajax.open("GET", dirurl, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;

			} 
					
		}
ajax.send(null);		
}
}


function compruebadisponible(U){
U1=document.getElementById(U).value;
var ajax=nuevoAjax();
dirurl="CompruebaUsuarioDisponible.php?Usuario="+U1;
capa=document.getElementById("disponible");
//la linea de abajo se muestra como linea 352 en el error de internet explorer.

ajax.open("GET", dirurl, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;

			} 
					
		}
ajax.send(null);	
}

//CompruebaOferta

function CompruebaOferta(){
camposobligatorios=12
i=0;
foco=0;
salir=0;

if(document.getElementById("Familia").value!=""){
document.getElementById("EtiquetaFamilia").className="FormularioGris";
i=i+1;
}else{
	if(foco==0){
foco=1;
document.getElementById("Familia").focus();
	}
document.getElementById("EtiquetaFamilia").className="FormularioCajaMal";
}

if(document.getElementById("SubFamilia").value!=""){
document.getElementById("EtiquetaSubFamilia").className="FormularioGris";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("SubFamilia").focus();
}
document.getElementById("EtiquetaSubFamilia").className="FormularioCajaMal";
}
if(document.getElementById("Marca").value!=""){
document.getElementById("EtiquetaMarca").className="FormularioGris";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("Marca").focus();
}
document.getElementById("EtiquetaMarca").className="FormularioCajaMal";
}


if(document.getElementById("Envase").value!=""){
document.getElementById("EtiquetaEnvase").className="FormularioGris";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("Envase").focus();
}
document.getElementById("EtiquetaEnvase").className="FormularioCajaMal";
}
FCad=document.getElementById("FCaducidad").value;
caducado=0;
if(FCad+15<=hoy()){
	alert("No se puede publicar una oferta de productos caducados o que caduquen en quince días");
	caducado=-1;
}
if(ValidaFecha(FCad) && caducado==0){
document.getElementById("EtiquetaFCaducidad").className="FormularioGris";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("FCaducidad").focus();
}
document.getElementById("EtiquetaFCaducidad").className="FormularioCajaMal";
}

FVenc=document.getElementById("FVencimiento").value;

caducado=0;
if(FVenc+15<=hoy()){
	alert("No se puede publicar una oferta con vencimiento inferior a 16 días");
	caducado=-1;
}
if(ValidaFecha(FVenc) && caducado==0){
document.getElementById("EtiquetaFVencimiento").className="FormularioGris";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("FVencimiento").focus();
}
document.getElementById("EtiquetaFVencimiento").className="FormularioCajaMal";
}

if(document.getElementById("Pais").value!=""){
document.getElementById("EtiquetaPais").className="FormularioGris";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("Pais").focus();
}
document.getElementById("EtiquetaPais").className="FormularioCajaMal";
}

if(document.getElementById("Provincia").value!=""){
document.getElementById("EtiquetaProvincia").className="FormularioGris";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("Provincia").focus();
}
document.getElementById("EtiquetaProvincia").className="FormularioCajaMal";
}

Pent=document.getElementById("PEntrega").value;
esnum=-1;
if(isNaN(Pent)){
	esnum=0;
}
if(document.getElementById("PEntrega").value!="" && esnum==-1){
document.getElementById("EtiquetaPEntrega").className="FormularioGris";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("PEntrega").focus();
}
document.getElementById("EtiquetaPEntrega").className="FormularioCajaMal";
}

Precio=document.getElementById("PrecioCaja").value;
esnum=-1;
if(isNaN(Precio)){
	esnum=0;
}
if(document.getElementById("PrecioCaja").value!="" && esnum==-1){
document.getElementById("EtiquetaPrecioCaja").className="FormularioGris";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("PrecioCaja").focus();
}
document.getElementById("EtiquetaPrecioCaja").className="FormularioCajaMal";
}

Unidades=document.getElementById("UnidadesxCaja").value;
esnum=-1;
if(isNaN(Unidades)){
	esnum=0;
}
if(document.getElementById("UnidadesxCaja").value!="" && esnum==-1){
document.getElementById("EtiquetaUnidadesxCaja").className="FormularioGris";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("UnidadesxCaja").focus();
}
document.getElementById("EtiquetaUnidadesxCaja").className="FormularioCajaMal";
}

Palets=document.getElementById("PaletsenStock").value;
esnum=-1;
if(isNaN(Palets)){
	esnum=0;
}
if(document.getElementById("PaletsenStock").value!="" && esnum==-1){
document.getElementById("EtiquetaPaletsenStock").className="FormularioGris";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("PaletsenStock").focus();
}
document.getElementById("EtiquetaPaletsenStock").className="FormularioCajaMal";
}

if(i>=camposobligatorios){
document.getElementById("Advertencia").className="FormularioGris";
document.alta.submit();
}
else{
document.getElementById("Advertencia").className="FormularioCajaMal";
}
}


function hoy()
{
    var fechaActual = new Date();
 
    dia = fechaActual.getDate();
    mes = fechaActual.getMonth() +1;
    anno = fechaActual.getYear();
    
 
    if (dia <10) dia = "0" + dia;
    if (mes <10) mes = "0" + mes;   
 
    fechaHoy = dia + "/" + mes + "/" + anno;
    
    return fechaHoy;
}

function EnviaCV(){
nombre=document.getElementById("nomcompleto").value;
mail=document.getElementById("email").value;
telf=document.getElementById("telefono").value;
file=document.getElementById("archivo").value;

//if(nombre!="" && mail!="" && telf!="" && file!=""){
vent=window.open('','tpv','width=100,height=100,scrollbars=no,resizable=yes,status=yes,menubar=no,location=no');
document.forms['fenviocv'].submit();

//}else{
	//alert("Por favor revise el formulario, hay alguna información que no ha rellenado");
//}
}
function ReintentarPago(){
		
url="Php/FinalizaPedido.php?IdPedido="+document.getElementById("IdPedido").value+"&Importe="+document.getElementById("Total").value+"&GastosEnvio="+document.getElementById("GastosEnvio").value+"&APagar="+document.getElementById("APagar").value+"&accion=reintento";	

vent=window.open('','tpv','width=725,height=600,scrollbars=no,resizable=yes,status=yes,menubar=no,location=no');
document.forms[0].submit();

var ajax=nuevoAjax();
capa=document.getElementById("Cont");
ajax.open("GET", url, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;

			} 
					
		}
ajax.send(null);	
	
}


function FinalizarPedido(accion, anexo){
i=0;
foco=0;
salir=0;

//alert(accion);
if(accion=='alta'){

//NOMBRE 1

N1=document.getElementById("Nombre").value;
largo=N1.length;
if(document.getElementById("Nombre").value!="" && largo<=200){
document.getElementById("EtiquetaNombre").className="NoticiaTxt";
i=i+1;
}else{
if(largo>200){
alert("El nombre no debe tener más de 200 caracteres");
i=i-1;
salir=1;
}
foco=1;
document.getElementById("Nombre").focus();
document.getElementById("EtiquetaNombre").className="FormularioCajaMal";
}

//APELLIDOS 2

A1=document.getElementById("Apellidos").value;
largo=A1.length;
if(document.getElementById("Apellidos").value!="" && largo<=300){
document.getElementById("EtiquetaApellidos").className="NoticiaTxt";
i=i+1;
}else{
if(largo>300 ){
if(salir!=1){
alert("Los Apellidos no deben tener más de 300 caracteres");
}
i=i-1;
salir=1;
}
if(foco==0){
foco=1;
document.getElementById("Apellidos").focus();
}
document.getElementById("EtiquetaApellidos").className="FormularioCajaMal";
}

//RAZON SOCIAL 3

RS=document.getElementById("RazonSocial").value;
largo=RS.length;
if(document.getElementById("RazonSocial").value!="" && largo<=300){
document.getElementById("EtiquetaRazonSocial").className="NoticiaTxt";
i=i+1;
}else{
if(largo>200 ){
if(salir!=1){
alert("La razón social no deben tener más de 300 caracteres");
}
i=i-1;
salir=1;
}
if(foco==0){
foco=1;
document.getElementById("RazonSocial").focus();
}
document.getElementById("EtiquetaRazonSocial").className="FormularioCajaMal";
}

//CIF 4

dni=document.getElementById("CIF").value;
if(document.getElementById("CIF").value!="" && dni.length==9){
document.getElementById("EtiquetaCIF").className="NoticiaTxt";
i=i+1;
}else{
if(dni.length>9 ){
if(salir!=1){
alert("El CIF debe tener 9 caracteres, no escriba espacios ni guiones, ejemplo: B150204450");
}
i=i-1;
salir=1;
}
if(foco==0){
foco=1;
document.getElementById("CIF").focus();
}
document.getElementById("EtiquetaCIF").className="FormularioCajaMal";
}

//PAIS 5

P1=document.getElementById("Pais").value;
largo=P1.length;
if(document.getElementById("Pais").value!=""){
document.getElementById("EtiquetaPais").className="NoticiaTxt";
i=i+1;
}else{
foco=1;
document.getElementById("Pais").focus();
document.getElementById("EtiquetaPais").className="FormularioCajaMal";
}

//PAISF 6

P1F=document.getElementById("PaisF").value;
largo=P1F.length;
if(document.getElementById("PaisF").value!=""){
document.getElementById("EtiquetaPaisF").className="NoticiaTxt";
i=i+1;
}else{
foco=1;
document.getElementById("PaisF").focus();
document.getElementById("EtiquetaPaisF").className="FormularioCajaMal";
}

//PROVINCIA 7

if(document.getElementById("Provincia").value!=""){
document.getElementById("EtiquetaProvincia").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("Provincia").focus();
}
document.getElementById("EtiquetaProvincia").className="FormularioCajaMal";
}

//PROVINCIAF 8

if(document.getElementById("ProvinciaF").value!=""){
document.getElementById("EtiquetaProvinciaF").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("ProvinciaF").focus();
}
document.getElementById("EtiquetaProvinciaF").className="FormularioCajaMal";
}

//POBLACION 9

if(document.getElementById("Poblacion").value!=""){
document.getElementById("EtiquetaPoblacion").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("Poblacion").focus();
}
document.getElementById("EtiquetaPoblacion").className="FormularioCajaMal";
}

//POBLACIONF 10

if(document.getElementById("PoblacionF").value!=""){
document.getElementById("EtiquetaPoblacionF").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("PoblacionF").focus();
}
document.getElementById("EtiquetaPoblacionF").className="FormularioCajaMal";
}

//DIRECCION 11

if(document.getElementById("Direccion").value!=""){
document.getElementById("EtiquetaDireccion").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("Direccion").focus();
}
document.getElementById("EtiquetaDireccion").className="FormularioCajaMal";
}

//DIRECCIONF 12

if(document.getElementById("DireccionF").value!=""){
document.getElementById("EtiquetaDireccionF").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("DireccionF").focus();
}
document.getElementById("EtiquetaDireccionF").className="FormularioCajaMal";
}

//CP 13

if(document.getElementById("CP").value!=""){
document.getElementById("EtiquetaCP").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("CP").focus();
}
document.getElementById("EtiquetaCP").className="FormularioCajaMal";
}

//COF 14

if(document.getElementById("CPF").value!=""){
document.getElementById("EtiquetaCPF").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("CPF").focus();
}
document.getElementById("EtiquetaCPF").className="FormularioCajaMal";
}

//TELF1 15

Telf=document.getElementById("Telf1").value;
if(document.getElementById("Telf1").value!="" && Telf.length>=9){
document.getElementById("EtiquetaTelf1").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("Telf1").focus();
}
document.getElementById("EtiquetaTelf1").className="FormularioCajaMal";
}


//alert(i);
if(i>=15){

var ajax=nuevoAjax();
nombre=document.getElementById("Nombre").value;
nombre=nombre.replace("&","-apersand-");
apellidos=document.getElementById("Apellidos").value;
apellidos=apellidos.replace("&","-apersand-");
Cif=document.getElementById("CIF").value;
Cif=Cif.replace("&","-apersand-");
telf1=document.getElementById("Telf1").value;
telf1=telf1.replace("&","-apersand-");
telf2=document.getElementById("Telf2").value;
telf2=telf2.replace("&","-apersand-");
poblacion=document.getElementById("Poblacion").value;
poblacion=poblacion.replace("&","-apersand-");
direccion=document.getElementById("Direccion").value;
direccion=direccion.replace("&","-apersand-");
cp=document.getElementById("Cp").value;
cp=cp.replace("&","-apersand-");
poblacionF=document.getElementById("PoblacionF").value;
poblacionF=poblacionF.replace("&","-apersand-");
direccionF=document.getElementById("DireccionF").value;
direccionF=direccionF.replace("&","-apersand-");
cpF=document.getElementById("CpF").value;
cpF=cpF.replace("&","-apersand-");
razonSocial=document.getElementById("RazonSocial").value;
razonSocial=razonSocial.replace("&","-apersand-");
comentarios=document.getElementById("Comentarios").value;
comentarios=comentarios.replace("&","-apersand-");


if(anexo=="" || anexo=="undefined"){
url="Php/FinalizaPedido.php?IdPedido="+document.getElementById("IdPedido").value+"&Nombre="+nombre+"&Apellidos="+apellidos+"&CIF="+Cif+"&Telf1="+telf1+"&Telf2="+telf2+"&Pais="+document.getElementById("Pais").value+"&Provincia="+document.getElementById("Provincia").value+"&Poblacion="+poblacion+"&Direccion="+direccion+"&Cp="+cp+"&PaisF="+document.getElementById("PaisF").value+"&ProvinciaF="+document.getElementById("ProvinciaF").value+"&PoblacionF="+poblacionF+"&DireccionF="+direccionF+"&CpF="+cpF+"&RazonSocial="+razonSocial+"&Comentarios="+comentarios+"&Importe="+document.getElementById("Total").value+"&GastosEnvio="+document.getElementById("GastosEnvio").value+"&APagar="+document.getElementById("APagar").value+"&accion=alta";
}else{
url="Php/FinalizaPedido.php?IdPedido="+document.getElementById("IdPedido").value+"&Nombre="+nombre+"&Apellidos="+apellidos+"&CIF="+Cif+"&Telf1="+telf1+"&Telf2="+telf2+"&Pais="+document.getElementById("Pais").value+"&Provincia="+document.getElementById("Provincia").value+"&Poblacion="+poblacion+"&Direccion="+direccion+"&Cp="+cp+"&PaisF="+document.getElementById("PaisF").value+"&ProvinciaF="+document.getElementById("ProvinciaF").value+"&PoblacionF="+poblacionF+"&DireccionF="+direccionF+"&CpF="+cpF+"&RazonSocial="+razonSocial+"&Comentarios="+comentarios+"&Importe="+document.getElementById("Total").value+"&GastosEnvio="+document.getElementById("GastosEnvio").value+"&APagar="+document.getElementById("APagar").value+"&accion=alta&Anexo="+anexo;	

}//alert(url);

vent=window.open('','tpv','width=725,height=600,scrollbars=no,resizable=yes,status=yes,menubar=no,location=no');
document.forms[0].submit();

document.getElementById("TablaCompra").innerHTML="<table width='150' border='0' cellspacing='0' cellpadding='0'><tr><td width='38'>&nbsp;</td><td width='50'>&nbsp;</td><td width='32'>&nbsp;</td><td width='30'>&nbsp;</td></tr><tr><td>&nbsp;</td><td rowspan='2'><div align='left' id='UniCompra' class='Unidades'></div></td><td rowspan='2'><div align='right' id='Bolsa'><img src='images/bolsavacia.png' alt='Tu bolsa está vacía' width='32' height='44' longdesc='http://www.toyplanet.es'></div></td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td height='30'>&nbsp;</td></tr></table>";

var ajax=nuevoAjax();
capa=document.getElementById("Cont");
ajax.open("GET", url, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;

			} 
					
		}
ajax.send(null);



}

}else{
//NOMBRE 1
//alert("Comprobando antes de enviar el pedido");
N0=document.getElementById("Nombre0").value;
largo=N0.length;
if(document.getElementById("Nombre0").value!="" && largo<=200){
document.getElementById("EtiquetaNombre0").className="NoticiaTxt";
i=i+1;
}else{
if(largo>200){
alert("El nombre no debe tener más de 200 caracteres");
i=i-1;
salir=1;
}
foco=1;
document.getElementById("Nombre0").focus();
document.getElementById("EtiquetaNombre0").className="FormularioCajaMal";
}

//APELLIDOS 2

A0=document.getElementById("Apellidos0").value;
largo=A0.length;
if(document.getElementById("Apellidos0").value!="" && largo<=300){
document.getElementById("EtiquetaApellidos0").className="NoticiaTxt";
i=i+1;
}else{
if(largo>300 ){
if(salir!=1){
alert("Los Apellidos no deben tener más de 300 caracteres");
}
i=i-1;
salir=1;
}
if(foco==0){
foco=1;
document.getElementById("Apellidos0").focus();
}
document.getElementById("EtiquetaApellidos0").className="FormularioCajaMal";
}

//FECHA NACIMIENTO 3

F=document.getElementById("FNac").value;
if(F=='dd/mm/aaaa' || ValidaFecha(F)==false){
	if(foco==0){
		foco=1;
		document.getElementById("FNac").focus();
	}
	document.getElementById("EtiquetaFNac").className="FormularioCajaMal";
}else{
	document.getElementById("EtiquetaFNac").className="NoticiaTxt";
	i=i+1;	
}

//DNI 4

dni=document.getElementById("DNI").value;
if(document.getElementById("DNI").value!="" && dni.length==9){
document.getElementById("EtiquetaDNI").className="NoticiaTxt";
i=i+1;
}else{
if(dni.length>9 ){
if(salir!=1){
alert("El NIF/NIE debe tener 9 caracteres, no escriba espacios ni guiones, ejemplo: 450204450M");
}
i=i-1;
salir=1;
}
if(foco==0){
foco=1;
document.getElementById("DNI").focus();
}
document.getElementById("EtiquetaDNI").className="FormularioCajaMal";
}


//SEXO 5

if(document.getElementById("Sexo").value!=""){
document.getElementById("EtiquetaSexo").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("Sexo").focus();
}
document.getElementById("EtiquetaSexo").className="FormularioCajaMal";
}


//TELF MOVIL 6

movil=document.getElementById("Movil").value;
if(document.getElementById("Movil").value!="" && movil.length>=9){
document.getElementById("EtiquetaMovil").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("Movil").focus();
}
document.getElementById("EtiquetaMovil").className="FormularioCajaMal";
}

//PAIS 7

P0=document.getElementById("Pais0").value;
largo=P0.length;
if(document.getElementById("Pais0").value!=""){
document.getElementById("EtiquetaPais0").className="NoticiaTxt";
i=i+1;
}else{
foco=1;
document.getElementById("Pais0").focus();
document.getElementById("EtiquetaPais0").className="FormularioCajaMal";
}

//PROVINCIA 8

if(document.getElementById("Provincia0").value!=""){
document.getElementById("EtiquetaProvincia0").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("Provincia0").focus();
}
document.getElementById("EtiquetaProvincia0").className="FormularioCajaMal";
}


//POBLACION 9

if(document.getElementById("Poblacion0").value!=""){
document.getElementById("EtiquetaPoblacion0").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("Poblacion0").focus();
}
document.getElementById("EtiquetaPoblacion0").className="FormularioCajaMal";
}

//DIRECCION 11

if(document.getElementById("Direccion0").value!=""){
document.getElementById("EtiquetaDireccion0").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("Direccion0").focus();
}
document.getElementById("EtiquetaDireccion0").className="FormularioCajaMal";
}

//CP 12

if(document.getElementById("CP0").value!=""){
document.getElementById("EtiquetaCP0").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("CP0").focus();
}
document.getElementById("EtiquetaCP0").className="FormularioCajaMal";
}




//NOMBRE 13

N1=document.getElementById("Nombre").value;
largo=N1.length;
if(document.getElementById("Nombre").value!="" && largo<=200){
document.getElementById("EtiquetaNombre").className="NoticiaTxt";
i=i+1;
}else{
if(largo>200){
alert("El nombre no debe tener más de 200 caracteres");
i=i-1;
salir=1;
}
foco=1;
document.getElementById("Nombre").focus();
document.getElementById("EtiquetaNombre").className="FormularioCajaMal";
}

//APELLIDOS 14

A1=document.getElementById("Apellidos").value;
largo=A1.length;
if(document.getElementById("Apellidos").value!="" && largo<=300){
document.getElementById("EtiquetaApellidos").className="NoticiaTxt";
i=i+1;
}else{
if(largo>300 ){
if(salir!=1){
alert("Los Apellidos no deben tener más de 300 caracteres");
}
i=i-1;
salir=1;
}
if(foco==0){
foco=1;
document.getElementById("Apellidos").focus();
}
document.getElementById("EtiquetaApellidos").className="FormularioCajaMal";
}

//RAZON SOCIAL 15

RS=document.getElementById("RazonSocial").value;
largo=RS.length;
if(document.getElementById("RazonSocial").value!="" && largo<=300){
document.getElementById("EtiquetaRazonSocial").className="NoticiaTxt";
i=i+1;
}else{
if(largo>200 ){
if(salir!=1){
alert("La razón social no deben tener más de 300 caracteres");
}
i=i-1;
salir=1;
}
if(foco==0){
foco=1;
document.getElementById("RazonSocial").focus();
}
document.getElementById("EtiquetaRazonSocial").className="FormularioCajaMal";
}

//CIF 16

dni=document.getElementById("CIF").value;
if(document.getElementById("CIF").value!="" && dni.length==9){
document.getElementById("EtiquetaCIF").className="NoticiaTxt";
i=i+1;
}else{
if(dni.length>9 ){
if(salir!=1){
alert("El CIF debe tener 9 caracteres, no escriba espacios ni guiones, ejemplo: B150204450");
}
i=i-1;
salir=1;
}
if(foco==0){
foco=1;
document.getElementById("CIF").focus();
}
document.getElementById("EtiquetaCIF").className="FormularioCajaMal";
}

//PAIS 17

P1=document.getElementById("Pais").value;
largo=P1.length;
if(document.getElementById("Pais").value!=""){
document.getElementById("EtiquetaPais").className="NoticiaTxt";
i=i+1;
}else{
foco=1;
document.getElementById("Pais").focus();
document.getElementById("EtiquetaPais").className="FormularioCajaMal";
}

//PAISF 18

P1F=document.getElementById("PaisF").value;
largo=P1F.length;
if(document.getElementById("PaisF").value!=""){
document.getElementById("EtiquetaPaisF").className="NoticiaTxt";
i=i+1;
}else{
foco=1;
document.getElementById("PaisF").focus();
document.getElementById("EtiquetaPaisF").className="FormularioCajaMal";
}

//PROVINCIA 19

if(document.getElementById("Provincia").value!=""){
document.getElementById("EtiquetaProvincia").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("Provincia").focus();
}
document.getElementById("EtiquetaProvincia").className="FormularioCajaMal";
}

//PROVINCIAF 20

if(document.getElementById("ProvinciaF").value!=""){
document.getElementById("EtiquetaProvinciaF").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("ProvinciaF").focus();
}
document.getElementById("EtiquetaProvinciaF").className="FormularioCajaMal";
}

//POBLACION 21

if(document.getElementById("Poblacion").value!=""){
document.getElementById("EtiquetaPoblacion").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("Poblacion").focus();
}
document.getElementById("EtiquetaPoblacion").className="FormularioCajaMal";
}

//POBLACIONF 22

if(document.getElementById("PoblacionF").value!=""){
document.getElementById("EtiquetaPoblacionF").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("PoblacionF").focus();
}
document.getElementById("EtiquetaPoblacionF").className="FormularioCajaMal";
}

//DIRECCION 23

if(document.getElementById("Direccion").value!=""){
document.getElementById("EtiquetaDireccion").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("Direccion").focus();
}
document.getElementById("EtiquetaDireccion").className="FormularioCajaMal";
}

//DIRECCIONF 24

if(document.getElementById("DireccionF").value!=""){
document.getElementById("EtiquetaDireccionF").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("DireccionF").focus();
}
document.getElementById("EtiquetaDireccionF").className="FormularioCajaMal";
}

//CP 25

if(document.getElementById("CP").value!=""){
document.getElementById("EtiquetaCP").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("CP").focus();
}
document.getElementById("EtiquetaCP").className="FormularioCajaMal";
}

//COF 26

if(document.getElementById("CPF").value!=""){
document.getElementById("EtiquetaCPF").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("CPF").focus();
}
document.getElementById("EtiquetaCPF").className="FormularioCajaMal";
}

//TELF1 27

Telf=document.getElementById("Telf1").value;
if(document.getElementById("Telf1").value!="" && Telf.length>=9){
document.getElementById("EtiquetaTelf1").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("Telf1").focus();
}
document.getElementById("EtiquetaTelf1").className="FormularioCajaMal";
}


//alert(i);
//alert(i);
if(i>=26){
nombre0=document.getElementById("Nombre0").value;
nombre0=nombre0.replace("&","-apersand-");
apellidos0=document.getElementById("Apellidos0").value;
apellidos0=apellidos0.replace("&","-apersand-");
dni=document.getElementById("DNI").value;
dni=dni.replace("&","-apersand-");
sexo=document.getElementById("Sexo").value;
sexo=sexo.replace("&","-apersand-");
fnac=document.getElementById("FNac").value;
movil=document.getElementById("Movil").value;
movil=movil.replace("&","-apersand-");
fijo=document.getElementById("Fijo").value;
fijo=fijo.replace("&","-apersand-");
poblacion0=document.getElementById("Poblacion0").value;
poblacion0=poblacion0.replace("&","-apersand-");
direccion0=document.getElementById("Direccion0").value;
direccion0=direccion0.replace("&","-apersand-");
cp0=document.getElementById("Cp0").value;
cp0=cp0.replace("&","-apersand-");

nombre=document.getElementById("Nombre").value;
nombre=nombre.replace("&","-apersand-");
apellidos=document.getElementById("Apellidos").value;
apellidos=apellidos.replace("&","-apersand-");
Cif=document.getElementById("CIF").value;
Cif=Cif.replace("&","-apersand-");
telf1=document.getElementById("Telf1").value;
telf1=telf1.replace("&","-apersand-");
telf2=document.getElementById("Telf2").value;
telf2=telf2.replace("&","-apersand-");
poblacion=document.getElementById("Poblacion").value;
poblacion=poblacion.replace("&","-apersand-");
direccion=document.getElementById("Direccion").value;
direccion=direccion.replace("&","-apersand-");
cp=document.getElementById("Cp").value;
cp=cp.replace("&","-apersand-");
poblacionF=document.getElementById("PoblacionF").value;
poblacionF=poblacionF.replace("&","-apersand-");
direccionF=document.getElementById("DireccionF").value;
direccionF=direccionF.replace("&","-apersand-");
cpF=document.getElementById("CpF").value;
cpF=cpF.replace("&","-apersand-");
razonSocial=document.getElementById("RazonSocial").value;
razonSocial=razonSocial.replace("&","-apersand-");
comentarios=document.getElementById("Comentarios").value;
comentarios=comentarios.replace("&","-apersand-");
Tot=document.getElementById("APagar").value;
IdPed=document.getElementById("IdPedido").value;


if(anexo=="" || anexo=="undefined"){
url="Php/FinalizaPedido.php?IdPedido="+document.getElementById("IdPedido").value+"&Nombre0="+nombre0+"&Apellidos0="+apellidos0+"&DNI="+dni+"&Movil="+movil+"&Fijo="+fijo+"&Pais0="+document.getElementById("Pais0").value+"&Provincia0="+document.getElementById("Provincia0").value+"&Poblacion0="+poblacion0+"&Direccion0="+direccion0+"&Cp0="+cp0+"&Nombre="+nombre+"&Apellidos="+apellidos+"&CIF="+Cif+"&Telf1="+telf1+"&Telf2="+telf2+"&Pais="+document.getElementById("Pais").value+"&Provincia="+document.getElementById("Provincia").value+"&Poblacion="+poblacion+"&Direccion="+direccion+"&Cp="+cp+"&PaisF="+document.getElementById("PaisF").value+"&ProvinciaF="+document.getElementById("ProvinciaF").value+"&PoblacionF="+poblacionF+"&DireccionF="+direccionF+"&CpF="+cpF+"&RazonSocial="+razonSocial+"&Comentarios="+comentarios+"&Importe="+document.getElementById("Total").value+"&GastosEnvio="+document.getElementById("GastosEnvio").value+"&APagar="+document.getElementById("APagar").value+"&accion=login";
}else{
url="Php/FinalizaPedido.php?IdPedido="+document.getElementById("IdPedido").value+"&Nombre0="+nombre0+"&Apellidos0="+apellidos0+"&DNI="+dni+"&Movil="+movil+"&Fijo="+fijo+"&Pais0="+document.getElementById("Pais0").value+"&Provincia0="+document.getElementById("Provincia0").value+"&Poblacion0="+poblacion0+"&Direccion0="+direccion0+"&Cp0="+cp0+"&Nombre="+nombre+"&Apellidos="+apellidos+"&CIF="+Cif+"&Telf1="+telf1+"&Telf2="+telf2+"&Pais="+document.getElementById("Pais").value+"&Provincia="+document.getElementById("Provincia").value+"&Poblacion="+poblacion+"&Direccion="+direccion+"&Cp="+cp+"&PaisF="+document.getElementById("PaisF").value+"&ProvinciaF="+document.getElementById("ProvinciaF").value+"&PoblacionF="+poblacionF+"&DireccionF="+direccionF+"&CpF="+cpF+"&RazonSocial="+razonSocial+"&Comentarios="+comentarios+"&Importe="+document.getElementById("Total").value+"&GastosEnvio="+document.getElementById("GastosEnvio").value+"&APagar="+document.getElementById("APagar").value+"&accion=login&Anexo="+anexo;	
	
}

//alert(url);

vent=window.open('','tpv','width=725,height=600,scrollbars=no,resizable=yes,status=yes,menubar=no,location=no');
document.forms[0].submit();

document.getElementById("TablaCompra").innerHTML="<table width='150' border='0' cellspacing='0' cellpadding='0'><tr><td width='38'>&nbsp;</td><td width='50'>&nbsp;</td><td width='32'>&nbsp;</td><td width='30'>&nbsp;</td></tr><tr><td>&nbsp;</td><td rowspan='2'><div align='left' id='UniCompra' class='Unidades'></div></td><td rowspan='2'><div align='right' id='Bolsa'><img src='images/bolsavacia.png' alt='Tu bolsa está vacía' width='32' height='44' longdesc='http://www.toyplanet.es'></div></td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td height='30'>&nbsp;</td></tr></table>";

var ajax=nuevoAjax();
capa=document.getElementById("Cont");
ajax.open("GET", url, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;

			} 
					
		}
ajax.send(null);



//var ajax2=nuevoAjax();
//Capa=document.getElementById("Cont");
//URL2="https://sis-t.sermepa.es:25443/sis/realizarPago";
//ajax2.open("POST", URL2, true);
   //ajax2.onreadystatechange=function()
    //{
        //if (ajax2.readyState==4)
        //{
            //Capa.innerHTML = ajax2.responseText
        //}
   // }
   // ajax2.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
   // ajax2.send("Ds_Merchant_Amount="+Tot+"&Ds_Merchant_Currency=978&Ds_Merchant_Order="+IdPed+"&Ds_Merchant_ProductDescription=Artículos de la tienda Online ToyPlanet&Ds_Merchant_Titular=Nombre&Ds_Merchant_MerchantCode=22633028&Ds_Merchant_MerchantURL=http://www.toyplanet.es/Desarrollo/TPV/Confirmacion.php&Ds_Merchant_MerchantName=T. Planet Shops, S.L.&Ds_Merchant_ConsumerLanguage=001&Ds_Merchant_MerchantSignature=1CA69D99C1B11B04C895D016E398BCB32E0B6870&Ds_Merchant_Terminal=1&Ds_Merchant_TransactionType=0");   

}

}
}

//////////////////////////////////////**************************************************************************************

function NuevoPost(url,name,keys,values)
{
var newWindow = window.open(url, name); 
if (!newWindow) return false;
var html = "";
html += "<html><head></head><body><form id='formid' method='post' action='" + url + "'>";
if (keys && values && (keys.length == values.length))
for (var i=0; i < keys.length; i++)
html += "<input type='hidden' name='" + keys[i] + "' value='" + values[i] + "'/>";
html += "</form><script type='text/javascript'>document.getElementById(\"formid\").submit()</script></body></html>";
newWindow.document.write(html);
return newWindow;
}


function objetus(file) {

xmlhttp=false;

this.AjaxFailedAlert = "Su navegador no soporta las funcionalidades de este sitio y podria experimentarlo de forma diferente a la que fue pensada. Por favor habilite javascript en su navegador para verlo normalmente.\n";

this.requestFile = file;

this.encodeURIString = true;

this.execute = false;

if (window.XMLHttpRequest) { 

this.xmlhttp = new XMLHttpRequest();

if (this.xmlhttp.overrideMimeType) {

this.xmlhttp.overrideMimeType('text/xml');

}

}

else if (window.ActiveXObject) { // IE

try {

this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

}catch (e) {

try {

this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

} catch (e) {

this.xmlhttp = null;

}

}

if (!this.xmlhttp && typeof XMLHttpRequest!='undefined') {

this.xmlhttp = new XMLHttpRequest();

if (!this.xmlhttp){

this.failed = true;

}

}

}

return this.xmlhttp ;

}

function recibeid(_pagina,valorget,valorpost,capa){

ajax=objetus(_pagina);

if(valorpost!=""){

ajax.open("POST", _pagina+"?"+valorget+"&tiempo="+new Date().getTime(),true);

} else {

ajax.open("GET", _pagina+"?"+valorget+"&tiempo="+new Date().getTime(),true);

}

ajax.onreadystatechange=function() {

if (ajax.readyState==1){

document.getElementById(capa).innerHTML = "<img src='loadingcircle.gif' align='center'> Aguarde por favor...";

}

if (ajax.readyState==4) {

if(ajax.status==200)

{document.getElementById(capa).innerHTML = ajax.responseText;}

else if(ajax.status==404)

{

capa.innerHTML = "La direccion no existe";

}

else

{

capa.innerHTML = "Error: ".ajax.status;

}

}

}

if(valorpost!=""){

ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

ajax.send(valorpost);

} else {

ajax.send(null);

}

}







/////////////////////////////////////////////////////****************************************************************************
function enviaform(){
document.Forms[0].submit();	
}

function comprueba(){
i=0;
foco=0;
salir=0;

D=document.getElementById("dNac").value;
M=document.getElementById("mNac").value;
A=document.getElementById("aNac").value;
fnac=D+"/"+M+"/"+A;
if(D=='dd' || M=='mm' || A=='yyyy' || !ValidaFecha(fnac)){
	if(foco==0){
		foco=1;
		document.getElementById("dNac").focus();
	}
	document.getElementById("EtiquetaFNac").className="FormularioCajaMal";
}else{
	document.getElementById("EtiquetaFNac").className="NoticiaTxt";
	fnac=D+"/"+M+"/"+A;
	i=i+1;	
}



N1=document.getElementById("Nombre").value;
largo=N1.length;
if(document.getElementById("Nombre").value!="" && largo<=200){
document.getElementById("EtiquetaNombre").className="NoticiaTxt";
i=i+1;
}else{
if(largo>200){
alert("El nombre no debe tener más de 200 caracteres");
i=i-1;
salir=1;
}
foco=1;
document.getElementById("Nombre").focus();

document.getElementById("EtiquetaNombre").className="FormularioCajaMal";
}

P1=document.getElementById("Pais").value;
largo=P1.length;
if(document.getElementById("Pais").value!=""){
document.getElementById("EtiquetaPais").className="NoticiaTxt";
i=i+1;
}else{
foco=1;
document.getElementById("Pais").focus();
document.getElementById("EtiquetaPais").className="FormularioCajaMal";
}


A1=document.getElementById("Apellidos").value;
largo=A1.length;

if(document.getElementById("Apellidos").value!="" && largo<=200){
document.getElementById("EtiquetaApellidos").className="NoticiaTxt";
i=i+1;
}else{
if(largo>200 ){
if(salir!=1){
alert("Los Apellidos no deben tener más de 200 caracteres");
}
i=i-1;
salir=1;
}


if(foco==0){
foco=1;
document.getElementById("Apellidos").focus();
}
document.getElementById("EtiquetaApellidos").className="FormularioCajaMal";
}


dni=document.getElementById("DNI").value;
if(document.getElementById("DNI").value!="" && dni.length==9){
document.getElementById("EtiquetaDNI").className="NoticiaTxt";
i=i+1;
}else{
if(dni.length>9 ){
if(salir!=1){
alert("El NIF/NIE debe tener 9 caracteres, no escriba espacios ni guiones, ejemplo: 450204450M");
}
i=i-1;
salir=1;
}



if(foco==0){
foco=1;
document.getElementById("DNI").focus();
}
document.getElementById("EtiquetaDNI").className="FormularioCajaMal";
}

if(document.getElementById("Direccion").value!=""){
document.getElementById("EtiquetaDireccion").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("Direccion").focus();
}
document.getElementById("EtiquetaDireccion").className="FormularioCajaMal";
}

if(document.getElementById("CP").value!=""){
document.getElementById("EtiquetaCP").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("CP").focus();
}
document.getElementById("EtiquetaCP").className="FormularioCajaMal";

}
if(document.getElementById("Poblacion").value!=""){
document.getElementById("EtiquetaPoblacion").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("Poblacion").focus();
}
document.getElementById("EtiquetaPoblacion").className="FormularioCajaMal";
}
if(document.getElementById("Provincia").value!=""){
document.getElementById("EtiquetaProvincia").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("Provincia").focus();
}
document.getElementById("EtiquetaProvincia").className="FormularioCajaMal";
}

if(document.getElementById("Sexo").value!=""){
document.getElementById("EtiquetaSexo").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("Sexo").focus();
}
document.getElementById("EtiquetaSexo").className="FormularioCajaMal";

}

Telf=document.getElementById("Telf1").value;
if(document.getElementById("Telf1").value!="" && Telf.length>=9){
document.getElementById("EtiquetaTelf1").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("Telf1").focus();
}
document.getElementById("EtiquetaTelf1").className="FormularioCajaMal";
}

if(document.getElementById("Email").value!="" && compruebamail(document.getElementById("Email").value)){
document.getElementById("EtiquetaEmail").className="NoticiaTxt";
i=i+1;
}else{
if(foco==0){
foco=1;
document.getElementById("Email").focus();
}
document.getElementById("EtiquetaEmail").className="FormularioCajaMal";
}

clave=document.getElementById("Clave").value;
if(document.getElementById("Clave").value!="" && clave.length>=7 && clave.length<=10){
document.getElementById("EtiquetaClave").className="NoticiaTxt";
i=i+1;
}else{
if(clave.length>9 ){
if(salir!=1){
alert("La clave debe tener entre 7 y 10 caracteres");
}
i=i-1;
salir=1;
}

if(foco==0){
foco=1;
document.getElementById("Clave").focus();
}
document.getElementById("EtiquetaClave").className="FormularioCajaMal";
}
reClave=document.getElementById("ReClave").value;
if(document.getElementById("ReClave").value!="" && reClave.length>=7 && reClave==clave){
document.getElementById("EtiquetaReClave").className="NoticiaTxt";
i=i+1;
}else{
if(document.getElementById("ReClave").value!=document.getElementById("Clave").value){
alert("Las contraseñas no son iguales, por favor vuelva a escribirlas");
}
if(foco==0){
foco=1;
document.getElementById("ReClave").focus();
}
document.getElementById("EtiquetaReClave").className="FormularioCajaMal";
}
//alert(i);

FH1=document.getElementById('dH1').value+"/"+document.getElementById('mH1').value+"/"+document.getElementById('aH1').value;

if(document.getElementById('dH1').value!="dd" && document.getElementById('mH1').value!="mm" && document.getElementById('aH1').value!="yyyy" && ValidaFecha(FH1)){
	FH1=document.getElementById('dH1').value+"/"+document.getElementById('mH1').value+"/"+document.getElementById('aH1').value;
}else{
	FH1="dd/mm/aaaa";
}

FH2=document.getElementById('dH2').value+"/"+document.getElementById('mH2').value+"/"+document.getElementById('aH2').value;

if(document.getElementById('dH2').value!="dd" && document.getElementById('mH2').value!="mm" && document.getElementById('aH2').value!="yyyy" && ValidaFecha(FH2)){
	FH2=document.getElementById('dH2').value+"/"+document.getElementById('mH2').value+"/"+document.getElementById('aH2').value;
}else{
	FH2="dd/mm/aaaa";
}

FH3=document.getElementById('dH3').value+"/"+document.getElementById('mH3').value+"/"+document.getElementById('aH3').value;

if(document.getElementById('dH3').value!="dd" && document.getElementById('mH3').value!="mm" && document.getElementById('aH3').value!="yyyy" && ValidaFecha(FH3)){
	FH3=document.getElementById('dH3').value+"/"+document.getElementById('mH3').value+"/"+document.getElementById('aH3').value;
}else{
	FH3="dd/mm/aaaa";
}

FH4=document.getElementById('dH4').value+"/"+document.getElementById('mH4').value+"/"+document.getElementById('aH4').value;

if(document.getElementById('dH4').value!="dd" && document.getElementById('mH4').value!="mm" && document.getElementById('aH4').value!="yyyy" && ValidaFecha(FH4)){
	FH4=document.getElementById('dH4').value+"/"+document.getElementById('mH4').value+"/"+document.getElementById('aH4').value;
}else{
	FH4="dd/mm/aaaa";
}

FH5=document.getElementById('dH5').value+"/"+document.getElementById('mH5').value+"/"+document.getElementById('aH5').value;

if(document.getElementById('dH5').value!="dd" && document.getElementById('mH5').value!="mm" && document.getElementById('aH5').value!="yyyy" && ValidaFecha(FH5)){
	FH5=document.getElementById('dH5').value+"/"+document.getElementById('mH5').value+"/"+document.getElementById('aH5').value;
}else{
	FH5="dd/mm/aaaa";
}

FH6=document.getElementById('dH6').value+"/"+document.getElementById('mH6').value+"/"+document.getElementById('aH6').value;

if(document.getElementById('dH6').value!="dd" && document.getElementById('mH6').value!="mm" && document.getElementById('aH6').value!="yyyy" && ValidaFecha(FH6)){
	FH6=document.getElementById('dH6').value+"/"+document.getElementById('mH6').value+"/"+document.getElementById('aH6').value;
}else{
	FH6="dd/mm/aaaa";
}




if(i>=14){
document.getElementById("Advertencia").className="NoticiaTxt";


var ajax=nuevoAjax();
if(document.getElementById("Newsletter").checked){
	News=-1;
}else{
	News=0;
}
capa=document.getElementById("Botonera");
contenidoHTML="<img src='images/NoticiaPaso3de3.jpg'>";
capa.innerHTML=contenidoHTML;


url="Php/AltaCliente.php?News="+News+"&Nombre="+document.getElementById("Nombre").value+"&Apellidos="+document.getElementById("Apellidos").value+"&NIF="+document.getElementById("DNI").value+"&FNac="+fnac+"&Sexo="+document.getElementById("Sexo").value+"&Email="+document.getElementById("Email").value+"&Telf1="+document.getElementById("Telf1").value+"&Telf2="+document.getElementById("Telf2").value+"&Pais="+document.getElementById("Pais").value+"&Provincia="+document.getElementById("Provincia").value+"&Poblacion="+document.getElementById("Poblacion").value+"&Direccion="+document.getElementById("Direccion").value+"&Cp="+document.getElementById("Cp").value+"&Clave="+document.getElementById("Clave").value+"&Hijo1="+document.getElementById("NombreH1").value
+"&FNacH1="+FH1+"&SexoH1="+document.getElementById("SexoH1").value+"&Hijo2="+document.getElementById("NombreH2").value
+"&FNacH2="+FH2+"&SexoH2="+document.getElementById("SexoH2").value+"&Hijo3="+document.getElementById("NombreH3").value
+"&FNacH3="+FH3+"&SexoH3="+document.getElementById("SexoH3").value+"$Hijo4="+document.getElementById("NombreH4").value
+"&FNacH4="+FH4+"&SexoH4="+document.getElementById("SexoH4").value+"&Hijo5="+document.getElementById("NombreH5").value
+"&FNacH5="+FH5+"&SexoH5="+document.getElementById("SexoH5").value+"&Hijo6="+document.getElementById("NombreH6").value
+"&FNacH6="+FH6+"&SexoH6="+document.getElementById("SexoH6").value;
//alert(url);

capa=document.getElementById("Cont");
ajax.open("GET", url, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;

			} 
					
		}
ajax.send(null);
}
else{
document.getElementById("Advertencia").className="FormularioCajaMal";
}
}



function CreaUser(){
var now = new Date();
//alert(now);
var monthday    = now.getDate();
//alert(monthday);
var Ap = new String();
var Nom = new String();
var Nombre = new String();
var Apellidos = new String();

Nombre=document.getElementById("Nombre").value;
Apellidos=document.getElementById("Apellidos").value;
Nombre=acentos(Nombre);
Apellidos=acentos(Apellidos);
espacio=Apellidos.indexOf(' ');
if(espacio>0){
Apellidos=Apellidos.substring(0,espacio); 
}
espacio=Nombre.indexOf(' ');
if(espacio>0){
Nombre=Nombre.substring(0,espacio); 
}
Usuario=Nombre.substring(0,3)+Apellidos.substring(0,3);
Usuario=Usuario.toLowerCase();
Usuario=Usuario+monthday;
document.getElementById("Usuario").value=Usuario;
compruebadisponible('Usuario');
}
function acentos(palabra){
var linea = new String();
linea=palabra; 
limpia = linea.replace(/á/g, "a"); 
linea=limpia;
limpia = linea.replace(/é/g, "e"); 
linea=limpia;
limpia = linea.replace(/í/g, "i"); 
linea=limpia;
limpia = linea.replace(/ó/g, "o"); 
linea=limpia;
limpia = linea.replace(/ú/g, "u"); 
linea=limpia;
limpia = linea.replace(/ñ/g, "n"); 
linea=palabra; 
limpia = linea.replace(/Á/g, "A"); 
linea=palabra; 
limpia = linea.replace(/É/g, "E"); 
linea=palabra; 
limpia = linea.replace(/Í/g, "I"); 
linea=palabra; 
limpia = linea.replace(/Ó/g, "O"); 
linea=palabra; 
limpia = linea.replace(/Ú/g, "U"); 
linea=palabra; 
limpia = linea.replace(/Ñ/g, "N"); 
linea=limpia;

return linea;
}

function limpiacadena(contenedor){
var linea= new String();
linea=document.getElementById(contenedor).value;
linea = linea.replace(/&/g, ""); 
linea = linea.replace(/\./g, ""); 
linea = linea.replace(/\,/g, ""); 

linea = linea.replace(/\;/g, ""); 

linea = linea.replace(/\'/g, ""); 

linea = linea.replace(/\,/g, ""); 

linea = linea.replace(/\=/g, ""); 

linea = linea.replace(/\!/g, ""); 

linea = linea.replace(/\?/g, ""); 

linea = linea.replace(/\¿/g, ""); 

linea = linea.replace(/\!/g, ""); 

linea = linea.replace(/\"/g, ""); 
 
linea = linea.replace(/\%/g, ""); 
 
linea = linea.replace(/\//g, ""); 

linea = linea.replace(/\(/g, ""); 

linea = linea.replace(/\)/g, "");

linea = linea.replace(/\}/g, "");

linea = linea.replace(/\{/g, "");

linea = linea.replace(/\*/g, "");

linea = linea.replace(/\+/g, "");
 
linea = linea.replace(/\@/g, "");

linea = linea.replace(/\$/g, "");

limpia = linea.replace(/\|/g, "");

document.getElementById(contenedor).value=linea;
}

///////////////////////////////////////////////////fin registro.php////////////////////////////////////////////////
//la fecha se pasa como dd-mm-aaaa
function ValidaFecha(Cadena){ 
//alert(Cadena)
    var Fecha= new String(Cadena)   // Crea un string   
    var RealFecha= new Date()   //Para sacar la fecha de hoy   
    //Cadena Año   
    var Ano= new String(Fecha.substring(Fecha.lastIndexOf("/")+1,Fecha.length))   
    //Cadena Mes  
	//alert("Año:"+Ano)
    var Mes= new String(Fecha.substring(Fecha.indexOf("/")+1,Fecha.lastIndexOf("/")))   
   // Cadena Día
   //alert("Mes:"+Mes)
    var Dia= new String(Fecha.substring(0,Fecha.indexOf("/")))   
  //alert("Dia:"+Dia)
    //Valido el año   
    if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900){   
            //alert('Año inválido')   
        return false   
    }   
    // Valido el Mes   
    if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12){ 
       // alert('Mes inválido')   
        return false   
    }   
    // Valido el Dia   
    if (isNaN(Dia) || parseInt(Dia, 10)<1 || parseInt(Dia, 10)>31){   
       // alert('Día inválido')   
        return false   
    }   
    if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {   
        if (Mes==2 && Dia > 28 || Dia>30) {   
           // alert('Día inválido')   
            return false   
        }   
    }   
       
  //para que envie los datos, quitar las  2 lineas siguientes   
 // alert("Fecha correcta.")   
  return true     
}   




function VerRegistro(){
var ajax=nuevoAjax();
dirurl="Registro.php";
capa=document.getElementById("Registro");
//la linea de abajo se muestra como linea 352 en el error de internet explorer.

ajax.open("GET", dirurl, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='images/cargando.gif' align='absmiddle'></div>";
			}
				
			if (ajax.readyState==4)
			{
			capa.innerHTML=ajax.responseText;

			} 
					
		}
ajax.send(null);
}





function cargacont(){
capa=document.getElementById("Cont");
var ajax=nuevoAjax();
ajax.open("GET", "Registro.php", true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='imagenes/cargando.gif' align='absmiddle'></div>";
			}
				
			if (ajax.readyState==4)
			{
						//alert("Esta preparado " +ajax.responseText);
			capa.innerHTML=ajax.responseText;

			} 
					
		}
		
ajax.send(null);
}

function cform(){
window.open("../contacto.html","","width=430,height=340,top=214,left=297,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no");
}

function clic(dirurl, pelicula){
capa=document.getElementById("cont");
var ajax=nuevoAjax();
ajax.open("GET", dirurl, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='imagenes/cargando.gif' align='absmiddle'></div>";
			}
				
			if (ajax.readyState==4)
			{
						//alert("Esta preparado " +ajax.responseText);
			capa.innerHTML=ajax.responseText;

			} 
					
		}
ajax.send(null);

if(pelicula!=""){
capa2=document.getElementById("flash");
peli=pelicula+".php"
var ajax2=nuevoAjax();
ajax2.open("GET", peli, true);
ajax2.onreadystatechange=function() 
	{ 
				
		if(ajax2.readyState==1)
			{
						//capa2.innerHTML="<div align='center'><img src='imagenes/cargando.gif' align='absmiddle'></div>";
			}
				
			if (ajax2.readyState==4)
			{
						//alert("Esta preparado " +ajax.responseText);
			capa2.innerHTML=ajax2.responseText;

			} 
					
		}

ajax2.send(null);
}
}
	
function vercurriculum (CodNoticia, dirurl){
capa=document.getElementById("cont");
var ajax=nuevoAjax();
ajax.open("GET", dirurl+"?CodNoticia="+CodNoticia, true);
ajax.onreadystatechange=function() 
	{ 
				
		if(ajax.readyState==1)
			{
						capa.innerHTML="<div align='center'><img src='imagenes/cargando.gif' align='absmiddle'></div>";
			}
				
			if (ajax.readyState==4)
			{
						//alert("Esta preparado " +ajax.responseText);
			capa.innerHTML=ajax.responseText;

			} 
					
		}
		
ajax.send(null);
}

function encabezado_familias(){
capa=document.getElementById("encabezado").innerHTML="Listado de Familias, haga clic en una familia para ver los productos:";		
}
function encabezado_carrito(){
capa=document.getElementById("encabezado").innerHTML="<br>Actualmente tiene los siguientes artículos en su carrito:";		
}

function encabezado_pedido(){
capa=document.getElementById("encabezado").innerHTML="<br>Resumen del Pedido";		
}

function encabezado_familias(){
capa=document.getElementById("encabezado").innerHTML="Listado de Familias, haga clic en una familia para ver los productos:";		
}

function enviapedido(){
		if(confirm("Ha pulsado el botón para enviar su pedido a www.duch-arte.com, al enviar el pedido acepta las condiciones de solicitud y entrega de pedidos de www.duch-arte.com, si es correcto pulse Aceptar para enviar el pedido")){
		capa=document.getElementById("abajo");
		var ajax=nuevoAjax();
				//alert("ruta= " + ruta);	
				//alert("verarticulos.php?fam="+fam+"&id="+id+"&descfam="+descfam);
				ajax.open("GET", "enviapedido.php", true);
				ajax.onreadystatechange=function() 
				{ 
				
					if(ajax.readyState==1)
					{
						//capa.innerHTML="<div align='center'><img src='imagenes/cargando.gif' align='absmiddle'></div>";
					}
				
					if (ajax.readyState==4)
					{
						//alert("Esta preparado " +ajax.responseText);
						capa.innerHTML=ajax.responseText;
						ocultacarrito();
						encabezado_pedido();
					} 
					
				}
		
				ajax.send(null);
		}
}
	


function vercarrito(){
capa=document.getElementById("abajo");
var ajax=nuevoAjax();
		//alert("ruta= " + ruta);	
		//alert("verarticulos.php?fam="+fam+"&id="+id+"&descfam="+descfam);
		ajax.open("GET", "vercarrito.php", true);
		ajax.onreadystatechange=function() 
		{ 
		
			if(ajax.readyState==1)
			{
				//capa.innerHTML="<div align='center'><img src='imagenes/cargando.gif' align='absmiddle'></div>";
			}
		
			if (ajax.readyState==4)
			{
				//alert("Esta preparado " +ajax.responseText);
				capa.innerHTML=ajax.responseText;
				encabezado_carrito();
			} 
			
		}

		ajax.send(null);


}

function cambiaunidades(uni, linea){
unidades=document.getElementById(uni).value;
capa=document.getElementById("abajo");
var ajax=nuevoAjax();
		//alert("ruta= " + ruta);	
		//alert("cambiaunidades.php?uni="+unidades+"&linea="+linea);
		ajax.open("GET", "cambiaunidades.php?uni="+unidades+"&linea="+linea, true);
		ajax.onreadystatechange=function() 
		{ 
		
			if(ajax.readyState==1)
			{
				//capa.innerHTML="<div align='center'><img src='imagenes/cargando.gif' align='absmiddle'></div>";
			}
		
			if (ajax.readyState==4)
			{
				//alert("Esta preparado " +ajax.responseText);
				capa.innerHTML=ajax.responseText;	
				
			} 
			
		}

		ajax.send(null);


}


function eliminalinea(linea){
	if(confirm("Va a eliminar una línea de su pedido, ¿Es correcto?")){
		capa=document.getElementById("abajo");
		var ajax=nuevoAjax();
				//alert("ruta= " + ruta);	
				//alert("verarticulos.php?fam="+fam+"&id="+id+"&descfam="+descfam);
				ajax.open("GET", "eliminalinea.php?IdLinea="+linea, true);
				ajax.onreadystatechange=function() 
				{ 
				
					if(ajax.readyState==1)
					{
						capa.innerHTML="<div align='center'><img src='imagenes/cargando.gif' align='absmiddle'></div>";
					}
				
					if (ajax.readyState==4)
					{
						//alert("Esta preparado " +ajax.responseText);
						capa.innerHTML=ajax.responseText;
						
					} 
					
				}
		
				ajax.send(null);
			}
		
}



function compraamalia(art, precio, des){
capa=document.getElementById(art);
capa2=document.getElementById("pedido");
var ajax=nuevoAjax();
		//alert("ruta= " + ruta);	
		//alert("verarticulos.php?fam="+fam+"&id="+id+"&descfam="+descfam);
		ajax.open("GET", "compra.php?art="+art+"&precio="+precio+"&des="+des, true);
		ajax.onreadystatechange=function() 
		{ 
		
			if(ajax.readyState==1)
			{
				//capa.innerHTML="<div align='center'><img src='imagenes/cargando.gif' align='absmiddle'></div>";
			}
		
			if (ajax.readyState==4)
			{
				//alert("Esta preparado " +ajax.responseText);
				capa.innerHTML=ajax.responseText;
				muestracarrito();
				
			} 
			
		}

		ajax.send(null);


}

function ocultacarrito(){
capa2=document.getElementById("pedido");
capa2.innerHTML="<img src='imagenes/carrito_vacio.jpg' alt='Carrito vacío' border='0' />";	
}
function muestracarrito(){
capa2=document.getElementById("pedido");
capa2.innerHTML="<a href='#' onclick='vercarrito()'><img src='imagenes/ver_carrito.gif' alt='Ver Carrito' border='0' /></a>";	
}

function go(numDonde)
{
switch (numDonde)
{
case 0:
tablaPrueba.firstPage();
break;
case 1:
tablaPrueba.previousPage();
break;
case 2:
tablaPrueba.nextPage();
break;
case 3:
tablaPrueba.lastPage();
break;
default:
alert("Opción de navegación incorrecta. Fallo de programación");
}
}




function verarticulos(fam, id, descfam){
quitamanita();
capa=document.getElementById("articulos");


	var ajax=nuevoAjax();
		//alert("ruta= " + ruta);	
		//alert("verarticulos.php?fam="+fam+"&id="+id+"&descfam="+descfam);
		ajax.open("GET", "verarticulos.php?fam="+fam+"&id="+id+"&descfam="+descfam, true);
		ajax.onreadystatechange=function() 
		{ 
		
			if(ajax.readyState==1)
			{
				capa.innerHTML="<div align='center'><img src='imagenes/cargando.gif' align='absmiddle'></div>";
			}
		
			if (ajax.readyState==4)
			{
				//alert("Esta preparado " +ajax.responseText);
				capa.innerHTML=ajax.responseText;				
			} 
			
		}

		ajax.send(null);
}	
function Mantenimientoarticulos(fam, id){
quitamanita();
capa=document.getElementById("articulos");
fam=document.getElementById("IdFamilia").value

	var ajax=nuevoAjax();
		//alert("ruta= " + ruta);	
		//alert("MantenimientoFotos.php?fam="+fam+"&id="+id);
		ajax.open("GET", "MantenimientoFotos.php?fam="+fam+"&id="+id, true);
		ajax.onreadystatechange=function() 
		{ 
		
			if(ajax.readyState==1)
			{
				capa.innerHTML="<div align='center'><img src='imagenes/cargando.gif' align='absmiddle'></div>";
			}
		
			if (ajax.readyState==4)
			{
				//alert("Esta preparado " +ajax.responseText);
				capa.innerHTML=ajax.responseText;				
			} 
			
		}

		ajax.send(null);
}	

function verarticulosmas(fam, id, descfam, c, pag){
quitamanita();
capa=document.getElementById("articulos");


	var ajax=nuevoAjax();
		//alert("ruta= " + ruta);	
		//alert("verarticulos.php?fam="+fam+"&id="+id+"&descfam="+descfam+"&tipo=mas&c="+c);
		ajax.open("GET", pag+"?fam="+fam+"&id="+id+"&descfam="+descfam+"&tipo=mas&c="+c, true);
		ajax.onreadystatechange=function() 
		{ 
		
			if(ajax.readyState==1)
			{
				capa.innerHTML="<div align='center'><img src='imagenes/cargando.gif' align='absmiddle'></div>";
			}
		
			if (ajax.readyState==4)
			{
				//alert("Esta preparado " +ajax.responseText);
				capa.innerHTML=ajax.responseText;				
			} 
			
		}

		ajax.send(null);
}	

function verarticulosmenos(fam, id, descfam, c, pag){
quitamanita();
capa=document.getElementById("articulos");


	var ajax=nuevoAjax();
		//alert("ruta= " + ruta);	
		//alert("verarticulos.php?fam="+fam+"&id="+id+"&descfam="+descfam);
		ajax.open("GET", pag+"?fam="+fam+"&id="+id+"&descfam="+descfam+"&tipo=menos&c="+c, true);
		ajax.onreadystatechange=function() 
		{ 
		
			if(ajax.readyState==1)
			{
				capa.innerHTML="<div align='center'><img src='imagenes/cargando.gif' align='absmiddle'></div>";
			}
		
			if (ajax.readyState==4)
			{
				//alert("Esta preparado " +ajax.responseText);
				capa.innerHTML=ajax.responseText;				
			} 
			
		}

		ajax.send(null);
}	


function ponmanita(){
document.body.style.cursor="hand";
}
function quitamanita(){
	document.body.style.cursor="default"
}

function borrarBoton(IdReserva){

document.getElementById("boton").innerHTML="<div align='left'><a href='#'><img src='../../imagenes/Disponibilidad.jpg' border='0' id='disponibilidad' name='disponibilidad' onClick=compruebaDisp('"+IdReserva+"')> </a></div>";	
}
function horas_a_minutos(horas){
	H="";
	M="";
	Min=false;
	//alert("Tiene "+horas.length+" caracteres");
	for(i=0;i<horas.length;i++){
		//alert("Evaluando "+horas.charAt(i));
		if(horas.charAt(i)==":"){
			Min=true;
		}
		else{
			if(Min==false){
				H=H+horas.charAt(i);
				//alert("H vale "+H);
			}else{
				M=M+horas.charAt(i);
				//alert("M vale "+M);
			}
		}
	}
	Minutos=H*60+M*1;
	//alert(Minutos);
	return Minutos;
}
	
function minutos_a_horas(min)
{
var hrs = Math.floor(min/60);
min = min % 60;
if(min<10) min = "0" + min;
return hrs + ":" + min;
}


function impre() {
		document.getElementById('cabecera').style.visibility = 'hidden'; 
		document.getElementById('menu').style.visibility = 'hidden'; 
	
    print();
		document.getElementById('cabecera').style.visibility = 'visible'; 
		document.getElementById('menu').style.visibility = 'visible'; 
}




////////////////////////////hacia abajo funciones generales de la Web////////////////////////////////////
function politica2(){
window.open("politica2.html","","width=580,height=450,top=214,left=297,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=yes,resizable=yes");
}
function abrecalendario(){
window.open("calendario.php","","width=375,height=300,top=214,left=297,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no");
}

function abreventana(pag){
window.open(pag,"miventana","width=600,height=600,top=214,left=297,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no");
}
function abreventana2(pag){
window.open(pag,"miventana","width=800,height=600,top=214,left=297,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes");
}

function alerta(){
alert("Por favor acepte las condiciones de política de privacidad y condiciones generales de venta para poder realizar el alta y la compra");
}

//-->
function habilitaboton(){
if(document.getElementById("acepto").checked==true){
document.getElementById("boton").innerHTML="<img src='images/EnviarA.jpg' width='100' height='30' style='color:#CCCCCC' onmouseover='ponmanita()' onmouseout='quitamanita()' onClick='comprueba()'>";
}else{
document.getElementById("boton").innerHTML="<img src='images/EnviarB.jpg' width='100' height='30' style='color:#CCCCCC' onmouseover='ponmanita()' onmouseout='quitamanita()' onClick='alerta();'>";
}
}

function marca(fila, hora, horafin, cuartos, sala){

horatxt="<input name='HMasaje' id='HMasaje' type='text' readonly='true' class='FormularioGris' value='"+hora+"' size='1'>";
horafintxt="<input name='HFinMasaje' id='HFinMasaje' type='text' readonly='true' class='FormularioGris' value='"+horafin+"' size='1'>";
var ajax=nuevoAjax();
IdMasaje=document.getElementById("IdMasaje").value;
//alert(IdMasaje);
		ajax.open("GET", "Empleados.php?IdMasaje="+IdMasaje, true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4)
			{
				//alert("Esta preparado " +ajax.responseText);
				document.getElementById("TxtHora").innerHTML="<table width='350' border='0' cellpadding='0' cellspacing='0'><tr><td width='120'><div align='right' class='FormularioGris'>Hora:</div></td><td width='5'>&nbsp;</td><td width='225' align='left' class='FormularioNaranja'>"+horatxt+"-"+horafintxt+"</div></td></tr><tr><td width='120' align='right' class='FormularioGris'>Masajista*:</td><td width=5>&nbsp;</td><td width='225' class='FormularioNaranja'>"+ajax.responseText+"</td></tr><tr><td colspan='3'>&nbsp;</td></tr><tr><td colspan='3' align='center' class='FormularioGris'>*Se le asignará este masajista siempre que no tenga ya asignado otra masaje en esa franja horaria.</td></tr></table>";
			} 
			
		}

		ajax.send(null);




//Para volver a poner verde si ya se había marcado alguna antes.
//alert(cuartos);
s=sala;
//alert("s vale "+s);
//alert(document.getElementById("sala").value);
if(document.getElementById("sala").value!=""){
	s=document.getElementById("sala").value;
	totalsala="total"+s;
	tot=document.getElementById(totalsala).value;
	//alert("tot es "+tot);
for(i=0;i<tot;i++){

lacasilla="C"+s+i;
lafila="Fila"+s+i;
//alert(lacasilla);
//alert(lafila);
if(document.getElementById(lacasilla).checked==true){
	document.getElementById(lafila).className="Verde";
}	
}
}
//Para marcar de naranja la franja seleccionada.
mifila=fila;
for(i=0;i<=cuartos-1;i++){
lafila="Fila"+sala+mifila;
lacasilla="C"+sala+mifila;
document.getElementById(lafila).className="Preseleccion";
document.getElementById(lacasilla).checked=true;
mifila=mifila*1+1*1;
}
document.getElementById("boton").innerHTML="<img src='../imagenes/Disponibilidad.jpg' id='disponibilidad' name='disponibilidad' onClick='cargadisponibilidad2();'><img src='../imagenes/ReservarA.jpg' onClick='verlogin();'>";
document.getElementById("sala").value=sala;
//alert("Estoy escribiendo "+sala+" en la casilla sala");
}
function borrar(){
document.getElementById("boton").innerHTML="<img src='../imagenes/Disponibilidad.jpg' id='disponibilidad' name='disponibilidad' onClick='cargadisponibilidad2();'><img src='../imagenes/ReservarB.jpg'>";
capa=document.getElementById("sala1");
capa.innerHTML="";
textoHora=document.getElementById("txtHora");


THora='<table width="350" border="0" align="left" cellpadding="0" cellspacing="0" bgcolor="#EBEBEB">';
THora=THora+'<tr>';
THora=THora+'<td width="120" height="15"><div align="right" class="FormularioGris">Hora:</div></td>';
THora=THora+'<td width="5" height="15"> </td>';
THora=THora+'<td width="225" height="15" class="FormularioNaranja">Seleccione la Hora</td>';
THora=THora+'</tr>';
THora=THora+'<tr>';
THora=THora+'<td width="120" height="15"> </td>';
THora=THora+'<td width="5" height="15"> </td>';
THora=THora+'<td width="225" height="15"> </td>';
THora=THora+'</tr>';
THora=THora+'<tr>';
THora=THora+'<td width="120" height="15"> </td>';
THora=THora+'<td width="5" height="15"> </td>';
THora=THora+'<td width="225" height="15"> </td>';
THora=THora+'</tr>';
THora=THora+'</table>';
textoHora.innerHTML=THora;

}
function pago(){
window.open("PreReservar.php?Email="+Email+"&Clave="+Clave+"&Sala="+Sala+"&FMasaje="+FMasaje+"&HMasaje="+HMasaje+"&IdMasaje="+IdMasaje+"&IdEmpleado="+IdEmpleado,"","width=512,height=550,top=214,left=297,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no");	
}
function reservar(){
document.getElementById("boton").innerHTML="<img src='../../imagenes/Disponibilidad.jpg' id='disponibilidad' name='disponibilidad' onClick='cargadisponibilidad2();'><img src='../../images/ReservarB.jpg'>";
capa=document.getElementById("sala1");
if(document.getElementById("Email").value!="" && document.getElementById("Clave").value!=""){
	var ajax=nuevoAjax();
		//alert("id= " + id);	
		
		Email=document.getElementById("Email").value;
		Clave=document.getElementById("Clave").value;
		Sala=document.getElementById("sala").value;
		IdMasaje=document.getElementById("IdMasaje").value;
		FMasaje=document.getElementById("FMasaje").value;
		HMasaje=document.getElementById("HMasaje").value;
		IdEmpleado=document.getElementById("IdEmpleado").value;
		//alert("Reservar.php?Email="+Email+"&Clave="+Clave+"&Sala="+Sala+"&FMasaje="+FMasaje+"&HMasaje="+HMasaje+"&IdMasaje="+IdMasaje+"&IdEmpleado="+IdEmpleado);
		
		//if(Email=="laura@i-vento.info" or Email=="reservas@maitaim.es"){
			
			//window.open("PreReservar.php?Email="+Email+"&Clave="+Clave+"&Sala="+Sala+"&FMasaje="+FMasaje+"&HMasaje="+HMasaje+"&IdMasaje="+IdMasaje+"&IdEmpleado="+IdEmpleado,"","width=512,height=550,top=214,left=297,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no");
		//}else{
		ajax.open("GET", "Reservar.php?Email="+Email+"&Clave="+Clave+"&Sala="+Sala+"&FMasaje="+FMasaje+"&HMasaje="+HMasaje+"&IdMasaje="+IdMasaje+"&IdEmpleado="+IdEmpleado, true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4)
			{
				//alert("Esta preparado " +ajax.responseText);
				capa.innerHTML=ajax.responseText;				
			} 
			
		}
	//}
		ajax.send(null);

}
else{
tablalogin="<table width='500'  border='0' cellspacing='0' cellpadding='0'><tr height='50'><td colspan='2' valign='middle' align='center' class='FormularioGris'>Por favor identifíquese con sus datos</td></tr><td width='284' align='right' class='FormularioGris' id='EtiquetaEmail'>E-mail*:</td><td align='right'><div align='left'><input name='Email' type='text' id='Email' class='FormularioCaja' size='15'></div></td></tr><tr><td width='284' align='right' class='FormularioGris' id='EtiquetaClave'><div align='right'>Clave*:</div></td><td align='right'><div align='left'><input name='Clave' type='password' id='Clave' class='FormularioCaja' size='15'></div></td><tr><td width='179' align='right'>&nbsp;</td><td width='154' onClick=reservar();><p align='right'><b> <font color='#FF6E00' face='Arial'> <a href='#'>enviar</a></font></b></td></tr><tr><td colspan='2' align='right'><div align='center' class='FormularioNaranja'><br>";
tablalogin=tablalogin+"Por favor escriba su email y clave de acceso<br></div></td></tr><tr><td colspan='2' align='center' class='FormularioGris'>¿Todavía no es un usuario registrado?, regístrese <a href='#' onClick='alta()' class='FormularioNaranja'>aquí.</a></td></tr>";
tablalogin=tablalogin+"<tr><td colspan='2' align='center' class='FormularioGris'>Si ya es usuario registrado pero no recuerda su clave haga clic <a href='recuerdaclave.php' target='_blank'>aquí.</a></td>";
tablalogin=tablalogin+"</tr></table>";
	
	
capa.innerHTML=tablalogin;
}	
	
}


function verlogin(){
document.getElementById("boton").innerHTML="<img src='../../images/Disponibilidad.jpg' onClick='cargadisponibilidad2()' id='disponibilidad' name='disponibilidad'><img src='../../images/ReservarB.jpg'>";

tablalogin="<table width='500'  border='0' cellspacing='0' cellpadding='0'><tr height='50'><td colspan='2' valign='middle' align='center' class='FormularioGris'>Por favor identifíquese con sus datos</td></tr><td width='284' align='right' class='FormularioGris' id='EtiquetaEmail'>E-mail*:</td><td align='right'><div align='left'><input name='Email' type='text' id='Email' class='FormularioCaja' size='15'></div></td></tr><tr><td width='284' align='right' class='FormularioGris' id='EtiquetaClave'><div align='right'>Clave*:</div></td><td align='right'><div align='left'><input name='Clave' type='password' id='Clave' class='FormularioCaja' size='15'></div></td><tr><td width='179' align='right'>&nbsp;</td><td width='154' onClick=reservar();><p align='right'><b> <font color='#FF6E00' face='Arial'> <a href='#'>enviar</a></font></b></td></tr><tr><td colspan='2' align='right'><div align='center' class='FormularioNaranja'><br>";
tablalogin=tablalogin+"<br></div></td></tr><tr><td colspan='2' align='center' class='FormularioGris'>¿Todavía no es un usuario registrado?, regístrese <a href='#' onClick='alta()' class='FormularioNaranja'>aquí.</a></td></tr>";
tablalogin=tablalogin+"<tr><td colspan='2' align='center' class='FormularioGris'>Si ya es usuario registrado pero no recuerda su clave haga clic <a href='recuerdaclave.php' target='_blank'>aquí.</a></td>";
tablalogin=tablalogin+"</tr></table>";
document.getElementById("sala1").innerHTML=tablalogin;
}
function alta(){

var ajax=nuevoAjax();	
//ajax.open("GET","FAlta.php", true);
		
		
		ajax.open("GET", "FAlta.php", true);
		
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4)
			{
				//alert("Esta preparado " +ajax.responseText);
				document.getElementById("sala1").innerHTML=ajax.responseText;				
			} 
		}
		ajax.send(null);	
}



function RecuerdaClave(){

mail=document.getElementById("Email2").value;
capa=document.getElementById("mensaje");


var ajax=nuevoAjax();	
//ajax.open("GET","FAlta.php", true);
		
		
		ajax.open("GET", "Php/RecuerdaClave.php?mail="+mail, true);
		
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4)
			{
				//alert("Esta preparado " +ajax.responseText);
				capa.innerHTML=ajax.responseText;				
			} 
		}
		ajax.send(null);	
}



function nuevoAjax()
{ 
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
	var xmlhttp=false;
	try
	{
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			// Creacion del objet AJAX para IE
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(E)
		{
			if (!xmlhttp && typeof XMLHttpRequest!='undefined') xmlhttp=new XMLHttpRequest();
		}
	}
	return xmlhttp; 
}

function fuera(fila){
	document.getElementById(fila).className="FormularioGris";
}
function calendariofiltro(cuadro){
	//alert(cuadro);
window.open("calendariofiltros.php?cuadro="+cuadro,"","width=350,height=300,top=214,left=297,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no");
}

function VerCalendario(cuadro){
	//alert(cuadro);
window.open("Php/calendario.php?cuadro="+cuadro,"","width=350,height=300,top=214,left=297,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no");
}


function calendario(){
	var cal=document.getElementById("cal");
	
	var ajax=nuevoAjax();
	ajax.open("GET", "calendario.php", true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4)
			{
				//alert("Esta preparado " +ajax.responseText);
				cal.innerHTML=ajax.responseText;				
			} 
			
		}

		ajax.send(null);
}

function esDigito(sChr){
var sCod = sChr.charCodeAt(0);
return ((sCod > 47) && (sCod < 58));
}
function valSep(oTxt){
var bOk = false;
//bOk = bOk || ((oTxt.value.charAt(2) == "-") && (oTxt.value.charAt(5) == "-"));
bOk = bOk || ((oTxt.charAt(2) == "/") && (oTxt.charAt(5) == "/"));
return bOk;
}
function finMes(oTxt){
var nMes = parseInt(oTxt.substr(3, 2), 10);
var nRes = 0;
switch (nMes){
case 1: nRes = 31; break;
case 2: nRes = 29; break;
case 3: nRes = 31; break;
case 4: nRes = 30; break;
case 5: nRes = 31; break;
case 6: nRes = 30; break;
case 7: nRes = 31; break;
case 8: nRes = 31; break;
case 9: nRes = 30; break;
case 10: nRes = 31; break;
case 11: nRes = 30; break;
case 12: nRes = 31; break;
}
return nRes;
}
function valDia(oTxt){
var bOk = false;
var nDia = parseInt(oTxt.substr(0, 2), 10);
bOk = bOk || ((nDia >= 1) && (nDia <= finMes(oTxt)));
return bOk;
}
function valMes(oTxt){
var bOk = false;
var nMes = parseInt(oTxt.substr(3, 2), 10);
bOk = bOk || ((nMes >= 1) && (nMes <= 12));
return bOk;
}
function valAno(oTxt){
var bOk = true;
var nAno = oTxt.substr(6);
bOk = bOk && ((nAno.length == 2) || (nAno.length == 4));
if (bOk){
for (var i = 0; i < nAno.length; i++){
bOk = bOk && esDigito(nAno.charAt(i));
}
}
return bOk;
}
function valFecha(oTxt){
var bOk = true;
if (oTxt != ""){
bOk = bOk && (valAno(oTxt));
bOk = bOk && (valMes(oTxt));
bOk = bOk && (valDia(oTxt));
bOk = bOk && (valSep(oTxt));
}
return bOk;
}

function compruebamail(texto){ 

    var mailres = true;             
    var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-"; 
     
    var arroba = texto.indexOf("@",0); 
    if ((texto.lastIndexOf("@")) != arroba) arroba = -1; 
     
    var punto = texto.lastIndexOf("."); 
                 
     for (var contador = 0 ; contador < texto.length ; contador++){ 
        if (cadena.indexOf(texto.substr(contador, 1),0) == -1){ 
            mailres = false; 
            break; 
     } 
    } 

    if ((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1)) 
     mailres = true; 
    else 
     mailres = false;            
    return mailres; 
} 




function cambiaclic(casilla){
	//alert("CambiaClic");
document.getElementById(casilla).checked=false;
}

function ActualizaGastoEnvio(bultos, importe, num, p){

var IdProv;
var GEnvio;
var IdProv;
var val;
var j;

GEnvio=0;
Tot=0;
IdProv=0;
val=0;
j=0;

GEnvio=document.getElementById("GastosEnvio").value;
Tot=document.getElementById("Total").value;
IdProv=document.getElementById(p).value;
Mensaje=document.getElementById("mensajegastoenvio");

//alert("Php/ActualizaGastoEnvio.php?idprovincia="+IdProv+"&B="+bultos+"&imp="+Tot);
	
	var ajax=nuevoAjax();	
	ajax.open("GET","Php/ActualizaGastoEnvio.php?idprovincia="+IdProv+"&B="+bultos+"&imp="+Tot, true);
	ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4)
			{
				document.getElementById("GastosEnvio").value=ajax.responseText;
				val=ajax.responseText;	
				
				if(Tot<150){
				val=val*1+Tot*1;
				j=decimal(val*1.00,2);
				}
				else{
				val=Tot
				j=decimal(Tot*1.00,2);
				document.getElementById("APagar").value=j;	
				}
			document.getElementById("APagar").value=j;
			if(j!=GEnvio){
				Mensaje.innerHTML="<br>Los gastos de envío han sido modificados al cambiar la provincia de envío, consulte el nuevo importe en el resúmen de la compra más arriba.<br><br>";
			}
		} 
		}
ajax.send(null);
j=document.getElementById("APagar").value;
//alert("Php/FPago.php?apagar="+j);
var ajax2=nuevoAjax();

	ajax2.open("GET", "Php/FPago.php?apagar="+j, true);
	ajax2.onreadystatechange=function() 
		{ 
			if (ajax2.readyState==4)
			{
				//alert("Esta preparado " +ajax.responseText);
				document.getElementById("FPago").innerHTML=ajax2.responseText;
			}
	
		} 
ajax2.send(null);	

}

function CompruebaLogin(anexo){
user=document.getElementById("Email").value;
pass=document.getElementById("Clave").value;

capa=document.getElementById("Botonera");
contenidoHTML="<img src='images/NoticiaPaso3de3.jpg'>";
capa.innerHTML=contenidoHTML;


if(user!="" && pass!="" && compruebamail(user)){
	//alert("Comprobando datos");
Capa=document.getElementById("Cont");
		var ajax=nuevoAjax();
		

		ajax.open("GET", "Php/AltaCliente.php?Email="+user+"&Clave="+pass+"&accion=login", true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==4)
			{
				//alert("Esta preparado " +ajax.responseText);
				Capa.innerHTML=ajax.responseText;				
			} 
			
		}

		ajax.send(null);
}
else{
	alert("Los datos que ha escrito no son correctos, por favor verifique sus datos de acceso y pruebe de nuevo");
}
}


