// JavaScript Document

//************************ COMUNES *********************** /
var ajax = new Ajax();

//Cacheamos las imagenes de rollover
//Menu lateral
var pic1= new Image(198,22); 
pic1.src="/images/menu_opcion1_gris.gif"; 
var pic2= new Image(198,22);
pic2.src="/images/menu_opcion2_gris.gif";
var pic3= new Image(200,23);
pic3.src="/images/menu_final_gris.gif";
var pic4= new Image(200,23);
pic4.src="/images/menu_final_grisover.gif";

var pic5= new Image(198,22); 
pic5.src="/images/menu_opcion1_azul.gif"; 
var pic6= new Image(198,22);
pic6.src="/images/menu_opcion1_azul.gif";
var pic7= new Image(200,23);
pic7.src="/images/menu_final_azul.gif";
var pic8= new Image(200,23);
pic8.src="/images/menu_final_azulover.gif";

//Menu top
var pic10= new Image(158,40); 
pic10.src="/images/menu_01_over.jpg"; 
var pic11= new Image(203,40); 
pic11.src="/images/menu_02_over.jpg"; 
var pic12= new Image(219,40); 
pic12.src="/images/menu_03_over.jpg"; 
var pic13= new Image(158,40); 
pic13.src="/images/menu_04_over.jpg"; 
var pic14= new Image(142,40); 
pic14.src="/images/menu_05_over.jpg"; 

//Mas Vendidos
var pic20= new Image(304,21); 
pic20.src="/images/masvendidos_fondoover.gif"; 

function Mail(direc)
{
	var er_email = /^(.+\@.+\..+)$/;
    if(!er_email.test(direc)) {
       return false
    }
    return true
}

function trim(texto) 
{
   return texto.replace(/^\s*|\s*$/g,"");
}

function $$(id)
{
	return document.getElementById(id);
}

//Tooltip
var theObj="";
function toolTip(text,me) {
   theObj=me;
   theObj.onmousemove=updatePos;
   document.getElementById('globo').innerHTML=text;
   document.getElementById('globo').style.display="block";
   window.onscroll=updatePos;
}
function updatePos() {
       var ev=arguments[0]?arguments[0]:event;
       var x=ev.clientX;
       var y=ev.clientY;
       diffX=40;
       diffY=0;

	   var capa = document.getElementById('globo');
	  
	   var navegador = navigator.appName;
	   if (navegador == "Microsoft Internet Explorer")
       {
			var pantallaX = document.body.clientWidth;

			if (pantallaX == 0)
				pantallaX = document.body.clientWidth;

			capa.style.top = y + document.body.scrollTop;
			capa.style.left = x + diffX + document.body.scrollLeft;
		}
		else
		{

			var pantallaX = window.innerWidth;
	   		capa.style.top = y + document.body.scrollTop  + 'px';
	   		capa.style.left = x+diffX+ 'px';
		}

       theObj.onmouseout=hideMe;
}
function hideMe() {
       document.getElementById('globo').style.display="none";
}

//Fin Tooltip
function RecordarDatos()
{
	var dire = document.getElementById('crecordar').value;
	if (dire != "")
	{
		ajax.url="/comun/login_recordar_xml.php?mail="+dire+"&rnd="+Math.random();
		ajax.f = "RecordarDatosAjax()";
		ajax.run();
	}
	else
		alert("Escriba una dirección correcta");
}

function RecordarDatosAjax()
{
	var nodos = ajax.xmlDoc.responseXML.documentElement.getElementsByTagName('resultado');
	valor = nodos[0].getAttribute('valor');
	if (valor == 'ok')
		alert("Datos enviados a la dirección de correo");	
	else
		alert("No existe el correo en nuestra base de datos");
}


function Cambiar_estado(objeto,estado)
{
	if (estado == "0")
	{ document.getElementById(objeto).disabled = true; }
	else
	{ document.getElementById(objeto).disabled = false;	}
}


// Enviar formulario con el Intro
function iSubmitEnter(oEvento){ 
     var iAscii; 

     if (oEvento.keyCode) 
         iAscii = oEvento.keyCode; 
     else if (oEvento.which) 
         iAscii = oEvento.which; 
     else 
         return false; 

     if (iAscii == 13) Login(); 

     return true; 
} 

function Ventana(url,x,y)
{
	nueva=window.open("","","scrollbars=yes,toolbar=no,directories=no,menubar=no,status=no,width="+x+",height="+y+"");
	Encoger(nueva,x,y);
	nueva.location.href=url;
	nueva.focus();
}

function Ventana_Scroll(url,x,y)
{
	nueva=window.open("","","scrollbars=yes,toolbar=no,directories=no,menubar=no,status=no,width="+x+",height="+y+"");
	Encoger(nueva,x,y);
	nueva.location.href=url;
	nueva.focus();
}


function Encoger(Ventana,ancho,alto)
{
x = screen.width;
y = screen.height;
xfin = (x/2) - (ancho/2);
yfin = (y/2) - (alto/2);
Ventana.moveTo(xfin,yfin);
}

function MaximoCaracteres(campo,limite)
{
	var texto = campo.value;
	limite = parseInt(limite,"10");
	if (texto.length>limite)
	{
		texto = texto.substring(0,limite);
		campo.value = texto;
	}
}

function isNumeric(elem){
	var numericExpression = /^[0-9]+$/;
	if(elem.match(numericExpression)){
		return true;
	}else{
		return false;
	}
}

function crearInput(f,nombre,valor)
{
	var inpt = document.createElement('input');
	inpt.type="hidden";
	inpt.name=nombre;
	inpt.id=nombre;
	inpt.value=valor;
	f.appendChild(inpt);
}


//************************ FIN COMUNES *********************** /

//************************ DESCANSUM *********************** /

//Funciones para el Menu
function Over(id,clase) {
	$$(id).className = clase;
}
function Out(id,clase) {
	$$(id).className = clase;	
}

function addProduct() {
 var params="";
 params = '&name='+document.cart.name.value;
 params += '&description='+document.cart.description.value;
 params += '&price='+document.cart.price.value;
 top.location.href = 'demo2.php?paso=2&action=add'+params;
}

function BusquedaPorMedidas(rango)
{
	if (rango!='0')
		location.href='/productos/?r='+rango;
}

function FormatearNumero(numero)
{
	var num = Number(numero).toFixed(2);
	return Number(num).toLocaleString();
}
