function validaCorreo(valor) {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
    return (true)
  } else {
    return (false);
  }
}


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 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;
			};
		}
	}
}

function cambiaFotos(){
	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').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))+7.5;
		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');
	}

}




window.addEvent('domready', function(){
	rutaActual=window.location.toString();
	redir=rutaActual.substring(0,rutaActual.length-1)+"1";
	if($('opcListadoTodos')){
		$('opcListadoTodos').addEvent('click', function(event) {	
			var myRequest = new Request({ 
				url: '/incs/opcionesListado.php?tipo=todos',   
				method:  'get',  
				data:  $('frmBuscador'),
					onSuccess: function(responseText, responseXML) {  window.location=redir;	}
				})  
			.send();
		});
	}
	if($('opcListadoHombre')){
		$('opcListadoHombre').addEvent('click', function(event) {	
			var myRequest = new Request({ 
				url: '/incs/opcionesListado.php?tipo=HOMBRE UNISEX',   
				method:  'get',  
				data:  $('frmBuscador'),
					onSuccess: function(responseText, responseXML) {  window.location=redir;	}
				})  
			.send();
		});
	}
	if($('opcListadoMujer')){
		$('opcListadoMujer').addEvent('click', function(event) {	
			var myRequest = new Request({ 
				url: '/incs/opcionesListado.php?tipo=MUJER',   
				method:  'get',  
				data:  $('frmBuscador'),
					onSuccess: function(responseText, responseXML) { window.location=redir;	}
				})  
			.send();
		});
	}
	if($('opcListadoNovedad')){
		$('opcListadoNovedad').addEvent('click', function(event) {	
			var myRequest = new Request({ 
				url: '/incs/opcionesListado.php?orden=fecha&tipo_orden=DESC',   
				method:  'get',  
				data:  $('frmBuscador'),
					onSuccess: function(responseText, responseXML) { window.location=redir;	}
				})  
			.send();
		});
	}
	if($('opcListadoMarca')){
		$('opcListadoMarca').addEvent('click', function(event) {	
			var myRequest = new Request({ 
				url: '/incs/opcionesListado.php?orden=marca&tipo_orden=ASC',   
				method:  'get',  
				data:  $('frmBuscador'),
					onSuccess: function(responseText, responseXML) { window.location=redir;	}
				})  
			.send();
		});
	}
	if($('opcListadoPrecio')){
		$('opcListadoPrecio').addEvent('click', function(event) {	
			var myRequest = new Request({ 
				url: '/incs/opcionesListado.php?orden=tarifa&tipo_orden=ASC',   
				method:  'get',  
				data:  $('frmBuscador'),
					onSuccess: function(responseText, responseXML) { window.location=redir;	}
				})  
			.send();
		});
	}
	if($('opcListadoCant12')){
		$('opcListadoCant12').addEvent('click', function(event) {	
			var myRequest = new Request({ 
				url: '/incs/opcionesListado.php?cantidad=12',   
				method:  'get',  
				data:  $('frmBuscador'),
					onSuccess: function(responseText, responseXML) { window.location=redir;	}
				})  
			.send();
		});
	}
	if($('opcListadoCant24')){
		$('opcListadoCant24').addEvent('click', function(event) {	
			var myRequest = new Request({ 
				url: '/incs/opcionesListado.php?cantidad=24',   
				method:  'get',  
				data:  $('frmBuscador'),
					onSuccess: function(responseText, responseXML) { window.location=redir;	}
				})  
			.send();
		});
	}
	if($('opcListadoCant36')){
		$('opcListadoCant36').addEvent('click', function(event) {	
			var myRequest = new Request({ 
				url: '/incs/opcionesListado.php?cantidad=36',   
				method:  'get',  
				data:  $('frmBuscador'),
					onSuccess: function(responseText, responseXML) { window.location=redir;	}
				})  
			.send();
		});
	}
	if($('opcListadoCant2000')){
		$('opcListadoCant2000').addEvent('click', function(event) {	
			var myRequest = new Request({ 
				url: '/incs/opcionesListado.php?cantidad=2000',   
				method:  'get',  
				data:  $('frmBuscador'),
					onSuccess: function(responseText, responseXML) { window.location=redir;	}
				})  
			.send();
		});
	}
	if($('frmProd_submit')){
		$('frmProd_submit').addEvent('click', function(event) {	
			window.location='/_buscador/'+$('frmProd_Categorias').value+'/'+$('frmProd_Marcas').value+'/'+$('frmProd_Perfil').value+'/'+$('frmProd_Modo').value+'/'+$('frmProd_Modelo').value+'/0';
			return false;
		});
	}
	if($('frm_ins_news_submit')){
		$('frm_ins_news_submit').addEvent('click', function(event) {	
			window.location='/_alta-nueva/-/'+$('frm_ins_newsletter').value;
			return false;
		});
	}
	if($$('.tallas a')){
		$$('.tallas a').each(function(el) {	
		  $(el).addEvent('click', function(e) { 
			  var myRequest = new Request({ 
				  url: '/incs/opcionesListado.php?talla='+this.title,   
				  method:  'get',  
				  data:  $('frmBuscador'),
					  onSuccess: function(responseText, responseXML) { window.location=redir; }
				  })  
			  .send();
		  });
	  });
	}
});	
