
/* funcion favoritos*/
function bookmarksite(title, url)
	{
	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "");
}

function valida_login_portada(){
	if(document.getElementById("usuario").value.length<5){
		alert("Introduzca su nombre de usuario");
		document.getElementById("usuario").focus();
		return false;
	}

	if(document.getElementById("contrasena").value.length<5){
		alert("Introduzca su contraseña");
		document.getElementById("contrasena").focus();
		return false;
	}
}


function emailCheck (emailStr) 
{
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		alert("Email incorrecto")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	if (user.match(userPat)==null) {
		alert("Email incorrecto")
		return false
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		  for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Email incorrecto")
			return false
			}
		}
		return true
	}

	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("Email incorrecto")
		return false;
	}
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>3) {
		 alert("Email incorrecto")
	   return false
	}

	if (len<2) {
	   var errStr="Email incorrecto"
	   alert(errStr)
	   return false
	}
}

function validar(){
	if(document.getElementById("nombre").value.length<3){
		alert("Introduzca su nombre");
		document.getElementById("nombre").focus();
		return false;
	}
	/*
	if(document.getElementById("apellidos").value.length<3){
		alert("Introduzca sus apellidos");
		document.getElementById("apellidos").focus();
		return false;
	}
	*/
	/*
	if((document.getElementById("telefono").value.length>1)&&(document.getElementById("telefono").value.length>9)){
		alert("Su teléfono no es correcto");
		document.getElementById("telefono").focus();
		return false;
	}
	*/
	if(document.getElementById("email").value.length<1){
		alert("Introduzca su email");
		document.getElementById("email").focus();
		return false;
	}else{
		var resu=emailCheck (document.getElementById("email").value);
		if(resu ==false){
			 document.getElementById("email").focus();
			 return resu;
		}
	
	}

	if(document.getElementById("asunto").value.length<3){
		alert("Introduzca el asunto");
		document.getElementById("asunto").focus();
		return false;
	}

	if((document.getElementById("mensaje").value.length<3)||(document.getElementById("mensaje").value=="Introduzca su mensaje")){
		alert("Introduzca el mensaje");
		document.getElementById("mensaje").focus();
		return false;
	}
	
	if(document.getElementById("passCap").value.length<5){
		alert("Introduzca los números de la imagen");
		document.getElementById("passCap").focus();
		return false;
	}
	
	return true;
}




function valida_recomendar_web(){
	if(document.getElementById("su_nombre").value.length<3){
		alert("Introduzca su nombre");
		document.getElementById("su_nombre").focus();
		return false;
	}

	if(document.getElementById("su_email").value.length<5){
		alert("Introduzca su email");
		document.getElementById("su_email").focus();
		return false;
	}else{
		var resu=emailCheck (document.getElementById("su_email").value);
		if(resu ==false){
			 document.getElementById("su_email").focus();
			 return resu;
		}
	
	}
	if(document.getElementById("nombre_amigo").value.length<3){
		alert("Introduzca el nombre de su amigo");
		document.getElementById("nombre_amigo").focus();
		return false;
	}

	if(document.getElementById("email_amigo").value.length<5){
		alert("Introduzca el email de su amigo");
		document.getElementById("email_amigo").focus();
		return false;
	}else{
		var resu=emailCheck (document.getElementById("email_amigo").value);
		if(resu ==false){
			 document.getElementById("email_amigo").focus();
			 return resu;
		}
	
	}

	if((document.getElementById("mensaje").value.length<3)||(document.getElementById("mensaje").value=="Introduzca su mensaje")){
		alert("Introduzca el mensaje");
		document.getElementById("mensaje").focus();
		return false;
	}

	

	if(document.getElementById("passCap").value.length<5){
		alert("Introduzca los números de la imagen");
		document.getElementById("passCap").focus();
		return false;
	}

	
}



function suma_cesta(articulo,precio,cuantos,accion)
{  
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}


	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			var div_carga="div_mi_carrito";
			document.getElementById(div_carga).innerHTML=xmlHttp.responseText;
		}
	}
	var url="principales/ajax/box_mi_carrito.php" ;
	url=url+"?articulo="+articulo+"&precio="+precio+"&cuantos="+cuantos+"&accion="+accion;
	url=url+"&sid="+Math.random();
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);  
}

function muestra_capa(nombre_capa,genv)
{  

	if(genv*1==genv){
		genv=genv;
	}else{
		genv=0;
	}

	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}


	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			var div_carga="div_"+ nombre_capa;
			document.getElementById(div_carga).innerHTML=xmlHttp.responseText;
		}
	}
	var url="principales/ajax/" + nombre_capa +".php" ;
	url=url+"?p=1&genv=" + genv;
	url=url+"&sid="+Math.random();
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);  
}

function esconde_capa(nombre_capa)
{  
	var div_carga="div_"+ nombre_capa;
	document.getElementById(div_carga).innerHTML="&nbsp;";
}



function anade_lista(articulo,accion)
{  
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}


	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			var div_carga="div_mis_favoritos";
			document.getElementById(div_carga).innerHTML=xmlHttp.responseText;
		}
	}
	var url="principales/ajax/box_mis_favoritos.php" ;
	url=url+"?articulo="+articulo+"&accion="+accion;
	url=url+"&sid="+Math.random();
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);  
}


function lista_favoritos(articulo,posicion)
{  
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}


	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			var div_carga="div_lista_favoritos";
			document.getElementById(div_carga).innerHTML=xmlHttp.responseText;
		}
	}
	var url="principales/ajax/lista_favoritos.php" ;
	url=url+"?articulo="+articulo+"&posicion="+posicion;
	url=url+"&sid="+Math.random();
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);  
}

function guarda_coockie_favoritos()
{  
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}


	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
		}
	}
	var url="principales/ajax/coockie_favoritos.php" ;
	url=url+"?sid="+Math.random();
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);  
}


function carga_part_emp(valor)
{  
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}


	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			var div_carga="div_part_emp";
			document.getElementById(div_carga).innerHTML=xmlHttp.responseText;
		}
	}
	var url="principales/ajax/part_emp.php" ;
	url=url+"?valor="+valor;
	url=url+"&sid="+Math.random();
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);  
}

function valida_usu(valor,modi)
{  
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}


	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			var div_carga="div_email";
			document.getElementById(div_carga).innerHTML=xmlHttp.responseText;
		}
	}
	var url="principales/ajax/valida_usu.php" ;
	url=url+"?valor="+valor+"&modi="+modi;
	url=url+"&sid="+Math.random();
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);  
}


function ver_pedidos(valor)
{  

	var td_carga="td_pedidos_"+ valor;
	if(document.getElementById(td_carga).className=='mis_pedidos_carga'){

		var xmlHttp=null;
		try
		{
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		}
		catch (e)
		{
			// Internet Explorer
			try
			{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		}


		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				var div_carga="div_pedidos_"+ valor;
				document.getElementById(div_carga).innerHTML=xmlHttp.responseText;
			}
		}
		
		var td_carga="td_pedidos_"+ valor;
		document.getElementById(td_carga).className='mis_pedidos_carga2';

		var img_carga="img_pedidos_"+ valor;
		document.getElementById(img_carga).src='imagenes/icono_volver.gif';
		document.getElementById(img_carga).alt='volver';


		var url="principales/ajax/pedidos.php" ;
		url=url+"?valor="+valor;
		url=url+"&sid="+Math.random();
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);  
	}else{
		document.getElementById(td_carga).className='mis_pedidos_carga';
		var img_carga="img_pedidos_"+ valor;
		document.getElementById(img_carga).src='imagenes/icono_ver_favorito.gif';
		document.getElementById(img_carga).alt='ver';

		var div_carga="div_pedidos_"+ valor;
		document.getElementById(div_carga).innerHTML="&nbsp;";
	
	}
}


function comprueba_quedan_articulos()
{  
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}


	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			//alert(xmlHttp.responseText);
			if(xmlHttp.responseText.length>10){
				var div_carga="div_contenido_cesta";
				document.getElementById(div_carga).innerHTML=xmlHttp.responseText;
				window.location.reload();
			}
		}
	}
	var url="principales/ajax/comprueba_quedan_articulos.php" ;
	url=url+"?id=1";
	url=url+"&sid="+Math.random();
	//alert(url);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);  
}