function validaCorreo(valor) {
  return (/^(\w{1}[\+\.\-\w^@]*)@(\w+[\.\-\w]*)\.([a-z]{2,5})/.test(valor));
}


function validaForm()
{
	if (document.formulario.txtEmail.value == "")
	{
	alert("Debe indicar un e-mail");
	document.formulario.txtEmail.focus();
	document.formulario.txtEmail.select();
	}
	else  if (document.formulario.txtEmail.value > " " && !validaCorreo(document.formulario.txtEmail.value))
	{
	alert("Debe introducir un correo electrónico correcto.");
	document.formulario.txtEmail.focus();
	document.formulario.txtEmail.select();
	}
	else
	{
	document.formulario.submit();
	}
}
 

function Abrir(theURL) {
	var leftmargin = (screen.width - 500) / 2;
	var topmargin = (screen.height - 450) / 2;
	var features = 'width=520,height=450,scrollbars=yes';
	features=features + ',top=' + topmargin + ',left='+ leftmargin;
	window.open(theURL,'Productos',features);
}


function calcRest(difActual){
	restante=(30-parseInt(difActual));	
	$('tiemporestcont').set('html','Tienes <span>'+restante+' minutos</span> hasta que caduque tu cesta de la compra.');
}

function cambiaLinks(){
	var links = document.getElementsByTagName('a');
	for (var i=0;i < links.length;i++) {
		if (links[i].rel == 'external') {
			links[i].onclick = function() { window.open(this.href); return false;};
		}
		if (links[i].rel == 'popup') {
			links[i].onclick = function() {
			window.open(this.href, "ventana", "location=0,status=0,scrollbars=1,width=600,height=540");
			return false;
			};
		}
		if (links[i].rel == 'popup-galeria') {
			links[i].onclick = function() {
			var opcionesPopup = "height=570,width=620,location=no,status=0,scrollbars=0,toolbar=0,directories=0,resizable=0,titlebar=0,menubar=0"; 
			window.open(this.href, "galeria", opcionesPopup);
			return false;
			};
		}
	}
}

function cambiaFotos(){
	try{
		
		/*
		Shadowbox.setup("a[rel='foto-miniatura']", {
            gallery: "Detalle-foto",
            width: 500,
            height: 500,
            title: ""
        });*/
		
		var links = document.getElementsByTagName('a');
		for (var i=0;i < links.length;i++) {
			if (links[i].rel == 'foto-miniatura') {
				links[i].onclick = function() {
					//$('link-ampliada').href=this.rev;				
					$('foto-ampliada').src=this.href; 

					return false;
				};
			}
		}
		$('link-ampliada').onclick = function() {
			Shadowbox.open({content:this.href,language:'es',player:'iframe',height:570, width:630});
			return false;
		};
	}catch(e){
		return false;
	}
}



function cambiaFotosBig(){
	try{		
		var links = document.getElementsByTagName('a');
		for (var i=0;i < links.length;i++) {
			if (links[i].rel == 'foto-miniatura') {
				links[i].onclick = function() {		
					$('foto-ampliada-det').src=this.href; 
					return false;
				};
			}
		}
	}catch(e){
		return false;
	}
}


function cargaAcordeon(){
	try{
	    var obj = $('menuseleccionado').value;
	    var ac = new Accordion($$('.toggler'), $$('.element'),{display: obj});
	}catch(e){
	    var ac = new Accordion($$('.toggler'), $$('.element'),{start: 'all-closed'});
	}
}



function updatePrecios(obj){
	
	subTotal=parseFloat($('subTotal').value).toFixed(2);
	gastosEnvio=parseFloat($('gastosEnvio').value).toFixed(2);
	descuentoAcu=parseFloat($('aplicarBono').value).toFixed(2);
	descuento=parseFloat(obj.value).toFixed(2);	
	nombre=(obj.id).substring(11);
	
	
	if(obj.checked){
		tst=subTotal-(eval(descuentoAcu)+eval(descuento));
		if(tst>0){
			descuentoAcu=eval(descuentoAcu)+eval(descuento);
			valores.push(nombre);
		}else{
			obj.checked=false;
			alert('No puede aplicar mas bonos');
			return false;
		}
	}else{
		descuentoAcu=eval(descuentoAcu)-eval(descuento);
		for(x=0;x<valores.length;x++){
			if(valores[x]==nombre){
				valores.splice(x,1);
			}
		}
	}
	
	cadenaID='';
	for(x=0;x<valores.length;x++){
		if(x>0) cadenaID=cadenaID+',';
		cadenaID=cadenaID+valores[x].toString();
	}
	
	
	$('valorTotal').value=(parseFloat(subTotal)+parseFloat(gastosEnvio)-parseFloat(descuentoAcu)).toFixed(2);
	$('descuentoTotal').value=parseFloat(descuentoAcu).toFixed(2);
	$('descuentoAplicado').set('html',parseFloat(descuentoAcu).toFixed(2));
	$('totobonos').set('html',(descuentoAcu).toFixed(2));
	$('aplicarBono').value=descuentoAcu;
	$('idBonos').value=cadenaID;
	
	$('valorFinal').set('html',$('valorTotal').value);
	
	
}

var actual=0;
var totalGal=0;
function generaGaleria(){
	var total	= 0;
	var contador=0;
	var imgs = document.getElementsByTagName('img');
	
	for (var i=0;i < imgs.length-2;i++) {
	  	if (imgs[i].title == 'galeria') {
		 	contador++;
		  	total+=(imgs[i].offsetWidth+10);
	  	}
	}
	
	if((contador*5707)-total>570)
	  	total=contador*570;
	totalGal=total;
	$('lista-promociones').setStyle('width',total+'px');

	actual=0;
	timer=setInterval(mueveGaleria,40);	 		  
    	
}

function mueveGaleria(){
	if((totalGal-(3*570)-452)*-1<actual){
		actual=actual-2;
		$('lista-promociones').setStyle('margin-left',actual+'px');
	}else{
		actual=0;
		$('lista-promociones').setStyle('margin-left',actual+'px');
	}
}



