String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function enviar_bus()
{
	bus = new String(document.frm.buscar.value);
    	bus = bus.trim()
	/* caracteres minimos para la busqueda */
	CHARS_MIN = 3; 
	if (bus.length < CHARS_MIN)
	{
		alert("Para realizar una búsqueda debe introducir al menos " +
              CHARS_MIN + " caracteres");
		return false;
	}
	else
	{
		return true;
	}
}

var n4 = (document.layers)? true:false
var ie = (document.all)? true:false
var n6 = (document.getElementById)? true:false

function showDiv(id)
{
     if (n4)
	     document.ventana.document.layers[id].visibility = "show"
     else if (ie)
         document.all[id].style.visibility = "visible"
     else if (n6)
         document.getElementById(id).style.visibility = "visible"
}

function hideDiv(id)
{
	if (n4)
		document.ventana.document.layers[id].visibility = "hide"
	else if (ie)
		document.all[id].style.visibility = "hidden"
	else if (n6)
		document.getElementById(id).style.visibility = "hidden"
}

/**
 * Permite solo numeros en campos de form. El campo que llame a esta función
 * debe acerle a través del 'onKeyPress'
 */
function onlyNumbers(val)
{
    charCode = val.charCodeAt(0)
	if (charCode >= 48 && charCode <= 57)
	{
		return val;
	}
	else
	{
		return '';
	}
}

/**
 * Comprueba si es válida una direccion de e-mail
 */
function check_email(email)
{
	var ex_Mail = /^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/;	
	return ex_Mail.test(email);
}

/**
* Add a new book to the cart
*/
function add_book(id_libro, url,anchor)
{	
	last_page(anchor);
	document.location.href = url + "/add?id=" + id_libro + "&units=1";
}
/**
* Muestra el carrito
*/
function show_cart(url_cart,anchor)
{
	if (anchor == undefined) anchor="";
	last_page(anchor);
	document.location.href = url_cart;
}

/**
* Go to last_page store in a cookie
*/
function seguir_comprando()
{
	last_page = get_cookie('last_page');
	if (last_page == null || last_page == "")
	{
		last_page = "http://www.librosaulamagna.com/home";
	}
	document.location.href = last_page;
	
}

/**
* Crea la cookie last_page 
*/

function last_page(anchor)
{
	url = document.location.href;
	/*se elimina el ancla*/
	url2 = url.split("#");
	url2[1] = "";
	url = url2.join("");
	/**/
	fincar = url.charAt(url.length-1);
	if (fincar == "/") url = url.substring(0,url.length-1);
	set_cookie('last_page', url + anchor, 1);
}

/**
 *
 */
	
function last_page_frm(id, anchor)
{
	
	last_page(anchor);
	document.frm.action = id;
	document.frm.submit();	
}



/**
* Efecto de parpadeo (blink). MS IE no soporta 'blink' de CSS
* Autores originales: Eric Greenblatt, Martin Honnen
*/
function blink(elId) 
{
  var html = '';
  var frecuency = 700;
  if (document.all)
    html += 'var el = document.all.' + elId + ';';
  else if (document.getElementById)
    html += 'var el = document.getElementById("' + elId + '");';
  html += 'el.style.visibility = ' + 'el.style.visibility == "hidden" ? "visible" : "hidden"';
  if (document.all || document.getElementById)
    setInterval(html, frecuency);
}

