
// JavaScript Document
function anyadirArticuloCarrito(IDArticulo,Cantidad) {	
  //Cantidad = eval("document.miformulario.Cantidad_"+IDArticulo+".value");
  
  eval( "if (document.miformulario.Variante1_"+IDArticulo+") { Variante1 = eval('document.miformulario.Variante1_'+IDArticulo+'.value') }else{Variante1 = 0} " )
  eval( "if (document.miformulario.Variante2_"+IDArticulo+") { Variante2 = eval('document.miformulario.Variante2_'+IDArticulo+'.value') }else{Variante2 = 0} " )
  eval( "if (document.miformulario.Variante3_"+IDArticulo+") { Variante3 = eval('document.miformulario.Variante3_'+IDArticulo+'.value') }else{Variante3 = 0} " )

  document.location.href = "gestion/gestionCarrito.asp?Accion=Anyadir&IDArticulo="+IDArticulo+"&Cantidad="+Cantidad+"&Variante1="+Variante1+"&Variante2="+Variante2+"&Variante3="+Variante3+"&URL="+escape(document.location.href); 
}	

$(document).ready(function(){

	$('#input_buscador').keyup(function(e) {
		if(e.keyCode == 13) {
			Buscar();
		}
	});
	
	$('#input_boletin').keyup(function(e) {
		if(e.keyCode == 13) {
			Boletin();
		}
	});

});


function Buscar(){
	if (document.miformulario.textoBusqueda.value != ""){
		document.miformulario.action= "listadoBusqueda.asp?TextoBusqueda="+document.miformulario.textoBusqueda.value;
		document.miformulario.submit(); 
	}
	else{
		alert("Debe introducir algun criterio de busqueda");
		document.miformulario.textoBusqueda.focus();
	}
}

// Lanza la ventana de boletin
function Boletin(){
	h = 150;
	w = 350;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0; 
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resizable';	
	if (validateEmail(trim(document.miformulario.txtEmailSuscriptor.value)) ){	
		window.open("gestion/gestionBoletin.asp?Accion=Alta&txtEmailSuscriptor="+document.miformulario.txtEmailSuscriptor.value, 'Boletin', settings)
	}
	else{
		alert("Debe introducir un Email valido");
		document.miformulario.txtEmailSuscriptor.focus();
	}
}



// Lanza la ventana de CondicionesGenerales
function condicionesGenerales(){
	h = 400;
	w = 550;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0; 
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resizable';	
	window.open('pop_condicionesgenerales.asp', 'Condiciones', settings)

}

// Lanza la ventana de mas informacion de un articulo
function abrirMasinfo(IDSubCategoria,IDArticulo,NombreArticulo) {
	var SeleccionarImagen = null;	
	h = 350;
	w = 500;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0; 
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resizable';  
	SeleccionarImagen = window.open("pop_pedirMasInfo.asp?IDSubCategoria="+IDSubCategoria+"&IDArticulo="+IDArticulo+"&NombreArticulo="+NombreArticulo, 'MasInfo', settings)
	SeleccionarImagen.focus();
}


// Lanza la ventana de recomendar articulo
function abrirRecomendar(IDSubCategoria,IDArticulo,NombreArticulo) {
	var SeleccionarImagen = null;	
	h = 350;
	w = 500;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0; 
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resizable';  
	SeleccionarImagen = window.open("pop_recomendarAmigo.asp?IDSubCategoria="+IDSubCategoria+"&IDArticulo="+IDArticulo+"&NombreArticulo="+NombreArticulo, 'Recomendar', settings)
	SeleccionarImagen.focus();
}



// Lanza la ventana de recordar contraseņa
function abrirRecordar() {
	var SeleccionarImagen = null;	
	h = 150;
	w = 350;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0; 
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resizable';  
	SeleccionarImagen = window.open("pop_recordarContrasenya.asp", 'Recordar', settings)
	SeleccionarImagen.focus();
}		

// Lanza la ventana con la fotos de la tienda de contacto
function abrirFotoTienda(Imagen) {
	var SeleccionarImagen = null;	
	h = 340;
	w = 440;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0; 
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resizable';  
	SeleccionarImagen = window.open("imagenes/fotosTienda/"+Imagen, 'ImagenesTienda', settings)
	SeleccionarImagen.focus();
}	

// Lanza la ventana del recorrido virtual
function abrirPanorama() {
	var panorama = null;	
	h = 340;
	w = 440;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0; 
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resizable';  
	panorama = window.open("panorama/panorama.htm", 'panorama', settings)
	panorama.focus();
}	 

// Lanza la ventana de modificacion datos del cliente
function abrirModificarDatosCliente() {
	var modificarDatosCliente = null;	
	h = 400;
	w = 600;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0; 
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resizable';  
	modificarDatosCliente = window.open("pop_modificarDatosCliente.asp", 'modificarDatosCliente', settings)
	modificarDatosCliente.focus();
}	 

function trim(strText) { 
	// this will get rid of leading spaces 
	while (strText.substring(0,1) == ' ') 
		strText = strText.substring(1, strText.length);

	// this will get rid of trailing spaces 
	while (strText.substring(strText.length-1,strText.length) == ' ')
		strText = strText.substring(0, strText.length-1);

   return strText;
} 
			
			
function validateEmail( strValue) {
/************************************************
DESCRIPTION: Validates that a string contains a
  valid email pattern.

 PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS: Accounts for email with country appended
  does not validate that email contains valid URL
  type (.com, .gov, etc.) or valid country suffix.
*************************************************/
var objRegExp = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
//var objRegExp  = /(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;
  //check for valid email
  return objRegExp.test(strValue);
}
