
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function emailCheck (emailStr) {	
	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */
	
	var checkTLD=1;
	
	/* The following is the list of known TLDs that an e-mail address must end with. */
	
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	
	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */
	
	var emailPat=/^(.+)@(.+)$/;
	
	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */
	
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	
	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/
	
	var validChars="\[^\\s" + specialChars + "\]";
	
	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */
	
	var quotedUser="(\"[^\"]*\")";
	
	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */
	
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	
	/* The following string represents an atom (basically a series of non-special characters.) */
	
	var atom=validChars + '+';
	
	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */
	
	var word="(" + atom + "|" + quotedUser + ")";
	
	// The following pattern describes the structure of the user
	
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	
	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */
	
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	
	/* Finally, let's start trying to figure out if the supplied address is valid. */
	
	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */
	
	var matchArray=emailStr.match(emailPat);
	
	if (matchArray==null) {
	
	/* Too many/few @'s or something; basically, this address doesn't
	even fit the general mould of a valid e-mail address. */	
		//alert("La dirección de email parece incorrecta (comprueba @ y .)");
		return false;
	}else{
		return true;
	}
}

function getYear(d) { 
  return (d < 1000) ? d + 1900 : d;
  }

//Valida una fecha, viene acompañada de la funcion getYear
function isDate (day, month, year) {
  // month argument must be in the range 1 - 12
  month = month - 1;  // javascript month range : 0- 11
  var tempDate = new Date(year,month,day);
  if ( (getYear(tempDate.getYear()) == year) &&
     (month == tempDate.getMonth()) &&
     (day == tempDate.getDate()) )
      return true;
  else
     return false
  }

function entrar(src,color_entrada) {
src.bgColor=color_entrada;
src.style.cursor="hand";
}

function salir(src,color_default) {
src.bgColor=color_default;
src.style.cursor="default";
}

function ConfirmarBorrado(direccion,titular){
	if (confirm(titular)){
		window.location = direccion
	}	
}

//Esta función comprueba si un archivo es de algun tipo conocido de imagen PNG,GIF,JPG compatible con la web
function CompruebaImagenes(ruta){
	//Extraemos la extension del fichero
	var extension = ruta.substr(ruta.length-3,3)
	//Pasamos a MAY
	extension = extension.toUpperCase(extension)
	archivosConocidos = new Array ("GIF","PNG","JPG")
	for (i=0;i<archivosConocidos.length;i++){
		if (extension == archivosConocidos[i])
			return (true);
	}
	return (false)	
}

//Esta función comprueba si un archivo del tipo especificado
function CompruebaExtension(ruta,tipo){
	//Extraemos la extension del fichero
	var extension = ruta.substr(ruta.length-3,3)
	//Pasamos a MAY
	extension = extension.toUpperCase(extension)
	tipo = tipo.toUpperCase(tipo)
	if (extension == tipo){
		return (true);
	}else{
		return (false);
	}	
}

function OpenWindow(root,ancho,alto,properties){
	f = document.formulario	
	var y=screen.width
	var x=screen.height
	x=eval((x-alto)*0.5);
	y= eval((y-ancho)*0.5);
	window.open(root,'','top='+x+',left='+y+',width=' + ancho + ',height='+ alto +','+properties+' ')	
	
}

//Comprueba que tecla se pulsa en un campo.
//Se utiliza en la busqueda para que no salte el formulario
function checkIt(evt,campo){   
   evt = (evt) ? evt : event
   var charCode = (evt.which) ? evt.which : evt.keyCode   
   
   if (charCode == 13){          	  
	 return (false);
	  /*
	  if (campo.value.length < 3){
		alert('Debes introducir al menos 3 caracteres');
		campo.focus();
		return false
	  }	  
	  enviaFormulario(document.formulario.strBusqueda.value,'buscar');	  
	  */
   }
   
}

function CompruebastrBusqueda(strBusqueda){	
	if (strBusqueda.length < 3){
		alert ('Debes introducir al menos 3 caracteres');
		return (false);					
	}			 
}
//#############################################################################
function enviaFormulario(valor,accion){
	var f
	f = document.formulario;	
	var msg = null;			
	switch (accion){		
		case 'buscar':					
			if (valor.length < 3){
				msg = 'Debes introducir al menos 3 caracteres ';					
			}									
			break;
		case 'muestraProducto':
		case 'sumaProducto':
			f.action = "visualizarProducto.php?idProductos="+valor
			f.idProductos.value = valor			
			break;
		case 'muestraCategoria':
			f.idCategorias.value = valor
			break;
		case 'muestraSubcategoria':
			f.idSubcategorias.value = valor
			break;
		case 'muestraMarca':
			f.idMarcas.value = valor
			break;
		case 'mostrarCarrito':
		case 'eliminaProducto':
		case 'actualizarCarrito':
		case 'iniciaPedido':
			f.action = "cart.php"
			break;			
		
	}	
	
	f.valor.value = valor;
	f.accion.value = accion	
	if (msg != null){
		alert (msg)
	}else{		
		f.submit();		
	}	
}
//#############################################################################
function nuevoAjax(){
	var xmlhttp=false;
 	try {
 		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");			
 	} catch (e) {
 		try {
 			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");					
 		} catch (E) {
 			xmlhttp = false;			
 		}
  	}
    
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 		xmlhttp = new XMLHttpRequest();		
	}
	return xmlhttp;
}
//#############################################################################
function loadContain(ajax,capa,url){	
	var contenedor;
	var metodo = "POST";
	
	vArg =loadContain.arguments;
	if (vArg.length>3){
		metodo = vArg[3];
	}
	contenedor = document.getElementById(capa);	
	document.getElementById(capa).style.display = 'inline';			
	
	
	ajax.open(metodo,url,true);
	document.getElementById("loader").style.display = 'inline';	
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			contenedor.innerHTML = ajax.responseText;
			document.getElementById("loader").style.display = 'none';				
	 	}
	}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset:iso-8859-1");		
	strForm = "";
	for (i=0;i<document.forms[0].elements.length;i++){    	
	
		if (document.forms[0].elements[i]){
			
			switch (document.forms[0].elements[i].type){
				case "checkbox":					
				case "radio":
					if (document.forms[0].elements[i].checked == true){
						strForm += document.forms[0].elements[i].name+"="+document.formulario.elements[i].value+"&";	
					}
					break;
				default:
					strForm += document.forms[0].elements[i].name+"="+document.formulario.elements[i].value+"&";						
			} //switch						
		}				
	} 
	
	ajax.send(strForm);	
	
}
//#############################################################################
function showHideLayer(capa,estado){
	display = "inline";
	if (!estado){display="none";}
	document.getElementById(capa).style.display = display;	
}


function enviarLink(objeto,modo){	
	
	
	if (modo == 1){
		document.location=urlThisSite+"/producto/"+document.getElementById(objeto).value;
	}else{
		document.location=urlThisSite+"/marca/"+document.getElementById(objeto).value;		
	}
	
}
//#############################################################################

function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}


function showHelp(objeto,campo){	
	
	vTxtAyuda = new Array;
	vTxtAyuda["cheque"] = 'Al comprar este kayak se te descontará el <strong>ChequeRegalo</strong> a los complementos que necesites. <br/><br/>El <strong>ChequeRegalo</strong> se te descuenta en el mismo momento de la compra.<br/><br/>';

	
		
	document.getElementById(objeto).style.position="absolute";	
	ancho = document.getElementById(objeto).width;
	alto = document.getElementById(objeto).height;	
	x = document.getElementById(objeto).offsetLeft;	
	y = document.getElementById(objeto).offsetTop;			
	document.getElementById('lyrHelp').style.left = x-(248+ancho);
	document.getElementById('lyrHelp').style.top = y-150;
	document.getElementById("txtAyuda").innerHTML = vTxtAyuda[campo];		
	document.getElementById(objeto).style.position="relative";
	$("#lyrHelp").fadeIn();
	
}





