var xmlhttp
var xmlhttp2
var xmlhttp3
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  xmlhttp2=new ActiveXObject("Msxml2.XMLHTTP");
  xmlhttp3=new ActiveXObject("Msxml2.XMLHTTP");
  tipo ='firefox';
 } catch (e) {
  try {
  	tipo = 'explorer';
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	 xmlhttp2=new ActiveXObject("Msxml2.XMLHTTP");
  xmlhttp3=new ActiveXObject("Msxml2.XMLHTTP");
  } catch (E) {
   xmlhttp=false;
    xmlhttp2=false;
  xmlhttp3=false;
  }
 }
@else
 xmlhttp=false
 xmlhttp2=false;
  xmlhttp3=false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 try {
  xmlhttp = new XMLHttpRequest();
 } catch (e) {
  xmlhttp=false
 }
}
if (!xmlhttp2 && typeof XMLHttpRequest!='undefined') {
 try {
  xmlhttp2 = new XMLHttpRequest();
 } catch (e) {
  xmlhttp2=false
 }
}
if (!xmlhttp3 && typeof XMLHttpRequest!='undefined') {
 try {
  xmlhttp3 = new XMLHttpRequest();
 } catch (e) {
  xmlhttp3=false
 }
}

function Decimales(Numero, Decimales) {
pot = Math.pow(10,Decimales);
num = parseInt(Numero * pot) / pot;
nume = num.toString().split('.');
if(nume.length==1) {
  var deci='';
  for(i=0;i<Decimales;i++)
    deci+=String.fromCharCode(48);
  num=nume+'.'+deci;
}
return num;
}

function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

function calcular(){
	var cantidad= document.getElementById('cantidad');
	var resultado= document.getElementById('resultado');
	var meses= document.getElementById('meses');
	if (cantidad.value=='')
	resultado.innerHTML='';
	else
	{
	if (meses.value!=0)
	{
	
	if (IsNumeric(meses.value) || (IsNumeric(cantidad.value)))
	{
		var cuota = meses.value*cantidad.value;
		cuota = cuota.toFixed(2);
		if (cuota>18)
		resultado.innerHTML='Cuota mensual:<br /><strong>'+cuota+' &euro;/mes</strong>'
		else
		resultado.innerHTML='Cuota mensual:<br /><strong style="color:red">Lo sentimos, la cuota mínima es de 18 &euro;/mes</strong>'
	}
	}
	else
	resultado.innerHTML='';
	}
}


function financi(){
	if (document.getElementById('cantidad'))
		{
			if (parseFloat(document.getElementById('metrosx').value))
			{
			var precio=(document.getElementById('precio').value*document.getElementById('metrosx').value);
			document.getElementById('cantidad').value=Decimales(precio,2);
			}
		}
}
function enlace(web)
{
	location.href=web;
}
function cargarcesta(ruta){
	var url = ruta +'vercesta.php'  ;
//	window.open (url);
	
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function() {
	if (xmlhttp.readyState==4) {
		data = xmlhttp.responseText;
		document.getElementById("cesta").innerHTML=data;
		}
	}
	xmlhttp.setRequestHeader('Accept','message/x-jl-formresult');
	xmlhttp.send(null);
	return false;
document.getElementById('cesta').innerHTML="<strong>Mi Cesta</strong>";
}
function eliminarcesta(registro){
	var talla="";
	var numero = "";
	if (document.getElementById('talla'))
		talla = document.getElementById('talla').value;
	color = document.getElementById('colorx').value;
	if (document.getElementById('numero'))
		numero = document.getElementById('numero').value;
	cantidad = document.getElementById('cantidadx').value;
	var url = '../eliminarcesta.php?registro=' + registro  ;
	//window.open (url);
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function() {
	if (xmlhttp.readyState==4) {
		data = xmlhttp.responseText;
		cargarcesta('../');
		}
	}
	xmlhttp.setRequestHeader('Accept','message/x-jl-formresult');
	xmlhttp.send(null);
	return false;
}
function anadircesta(idarticulo){
	
	var talla="";
	var numero = "";
	if (document.getElementById('talla'))
		talla = document.getElementById('talla').value;
	
	color = document.getElementById('colorx').value;

	
	if (document.getElementById('numero'))
		numero = document.getElementById('numero').value;

	
	cantidad = document.getElementById('cantidadx').value;

	
	var url = '../addcesta.php?talla='+talla+'&color=' + color +'&numero=' + numero +'&cantidad=' + cantidad +'&idarticulo=' + idarticulo  ;
	//window.open (url);
	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange=function() {
	if (xmlhttp.readyState==4) {
		data = xmlhttp.responseText;
		cargarcesta('../');
		}
	}
	xmlhttp.setRequestHeader('Accept','message/x-jl-formresult');
	xmlhttp.send(null);
	return false;	
}

function trim(stringToTrim) {
			return stringToTrim.replace(/^\s+|\s+$/g,"");
		}
function ltrim(stringToTrim) {
			return stringToTrim.replace(/^\s+/,"");
		}
function rtrim(stringToTrim) {
			return stringToTrim.replace(/\s+$/,"");
		}
		
		function validarEmail(valor) {
			  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
			   return (true)
			  } else {
			      return (false);
			  }
			 }
							
function comprobar(){
var msgerror='';
var telefono = trim(document.contacto.telefono.value);



if (document.contacto.nombre.value=='') 
	msgerror = '* Nombre completo\n';
	
if (document.contacto.direccion.value=='') 
		msgerror += '* Dirección de envío\n';



	
if (telefono=='') 
	{
	msgerror += '* Teléfono\n';
	}



	
if (document.contacto.email.value=='') 
	msgerror += '* Email\n';
else
	{
	if (validarEmail(document.contacto.email.value)==false)
		msgerror = msgerror +'* El Email parece incorrecto\n';
	}
	
if (!document.contacto.acepto.checked) 
	msgerror = msgerror +'* Aceptar política de privacidad\n';
	
if (msgerror==''){
 if ((telefono.length)<9)
 	msgerror = '* El teléfono ha de tener 9 cifras como mínimo\n';
	document.contacto.telefono.focus();
}
if (msgerror!=''){
	alert('Los siguientes campos son obligatorios:\n\n'+msgerror);
	return false;
	}
else{
	return true;

}
}

function comprobar2(){
var msgerror='';
var telefono = trim(document.contacto.telefono.value);



if (document.contacto.nombre.value=='') 
	msgerror = '* Nombre completo\n';
	


	
if (document.contacto.email.value=='') 
	msgerror += '* Email\n';
else
	{
	if (validarEmail(document.contacto.email.value)==false)
		msgerror = msgerror +'* El Email parece incorrecto\n';
	}
	
if (!document.contacto.acepto.checked) 
	msgerror = msgerror +'* Aceptar política de privacidad\n';
	
if (msgerror==''){
 if ((telefono.length)<9)
 	msgerror = '* El teléfono ha de tener 9 cifras como mínimo\n';
	document.contacto.telefono.focus();
}
if (msgerror!=''){
	alert('Los siguientes campos son obligatorios:\n\n'+msgerror);
	return false;
	}
else{
	document.contacto.action="enviarmensaje.php";
	document.contacto.submit();
	return true;

}
}

	function votar(tipo,id)
				{
					var url = '../votar.php?tipo='+tipo+'&id=' + id  ;
					//window.open (url);
					xmlhttp.open("GET",url,true);
					xmlhttp.onreadystatechange=function() {
					if (xmlhttp.readyState==4) {
						data = xmlhttp.responseText;
						alert('Gracias por votar!!!\nHemos tomado nota.');

					}
					}
					xmlhttp.setRequestHeader('Accept','message/x-jl-formresult');
					xmlhttp.send(null);

					return false;	
				}
				
				function enviarcomentario(){
				var msgerror='';

				if (document.forms['contacto'].nombre.value=='') 
					msgerror = '* Nombre o apodo\n';

				if (document.forms['contacto'].comentario.value=='') 
						msgerror += '* Tu comentario\n';

				if (document.forms['contacto'].email.value=='') 
					msgerror += '* Email\n';
				else
					if (validarEmail(document.forms['contacto'].email.value)==false)
						msgerror = msgerror +'* El Email parece incorrecto\n';


				 	if (msgerror!='')
					{
						alert('Los siguientes campos son obligatorios:\n\n'+msgerror);
						return false;
					}
					else
					{
						document.forms['contacto'].action='enviaropinion.php';
						return true;

						}

					}
