



function obtenerElemento(nombre) {
    return document.getElementById(nombre);
}


//valida un email
function validarEmail(valor) { 
	valor = trim(valor);

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

//saco blancos al principio y al final
function trim(cadena) {
   cadena = cadena.replace(/^\s+/, '');
   cadena = cadena.replace(/\s+$/, '');
	return cadena;
}

//---------------------------------------------------------------------//
// Limpia los spans de verificacion del form_login
function limpiarContacto() {
    var verif;
    
    verif = obtenerElemento("verif_email");
    verif.innerHTML = "";
    verif = obtenerElemento("verif_usuario");
    verif.innerHTML = "";
    verif = obtenerElemento("verif_comentario");
    verif.innerHTML = "";
}
function validarContacto(){
	
	var bool = false;	
	//var oMsjCto = document.getElementById("msjContacto");
	var oNombre = document.getElementById("nombre");
	var oEmail = document.getElementById("email");
	var oComentario = document.getElementById("comentario");
	
	
	if(trim(oNombre.value) == ""){
		bool = true;
		verif = obtenerElemento("verif_usuario");
        verif.innerHTML = "ingrese su nombre de usuario";
	}
	
	if(!validarEmail(oEmail.value) || trim(oEmail.value) == ""){
		bool = true;
		verif = obtenerElemento("verif_email");
        verif.innerHTML = "El e-mail está vac&iacute;o o su formato es incorrecto<br>";
		
	}
	
	if(trim(oComentario.value) == ""){
		bool = true;
		verif = obtenerElemento("verif_comentario");
        verif.innerHTML = "Por favor ingrese un comentario";
	}
	
    if (bool) return false
	else return true;
	}


//---------------------------------------------------------------------//
function validarLogin(){
	var oUsr = document.getElementById("usuario");
	var oPsw = document.getElementById("contrasenia");
	var oMsjLogin = document.getElementById("msjIngresar");
	
	if(trim(oUsr.value) == "" || trim(oPsw.value) == "" || trim(oUsr.value) == "usuario" || trim(oPsw.value) == "contraseña"){
		oMsjLogin.style.display = "block";
		oMsjLogin.innerHTML = "Por favor, ingrese su usuario y contraseña.";
		
		return false;
	}else{/*
		if(document.getElementById("recordar_usr").checked == true)	
			setNamedCookie( "ACCOUNT_USER_PUNTOBIZ", oUsr.value+"|"+oPsw.value );//guarda en la cookie usr y pass
		else
			deleteCookie("ACCOUNT_USER_PUNTOBIZ");//elimina la cookie para recordar usr y pass
           */
		return true;
	}
}
//---------------------------------------------------------------------//
function validarDesuscripcion(){
	var oUsr = document.getElementById("user");
	var oPsw = document.getElementById("pass");
	var oMsjLogin = document.getElementById("msjDesuscripcion");
	
	if(trim(oUsr.value) == "" || trim(oPsw.value) == ""){
		oMsjLogin.style.display = "block";
		oMsjLogin.innerHTML = "Por favor, ingrese su usuario y contraseña.";
		
		return false;
	}else	return true;
}

//---------------------------------------------------------------------//
function tratarLogin(c_o,c_n){
	var caj_o = document.getElementById(c_o);
    var caj_n = document.getElementById(c_n);
    
    caj_o.style.display = "none";
    caj_n.style.display = "block";
    caj_o.style.visibility = "hidden";
	caj_n.style.visibility = "visible";
    caj_n.focus();
}

//---------------------------------------------------------------------//
function validarSubscNresletter(){
	var oCad = "";
	var bool = true;	
	var oMsjCto = document.getElementById("msjSubscNew");
	var oNombre = document.getElementById("nombre");
	var oApellido = document.getElementById("apellido");
	var oEmail = document.getElementById("email");
		
	
	if(trim(oNombre.value) == ""){
		oCad += "Por favor complete su nombre<br>";
		bool = false;
	}
	
	if(trim(oApellido.value) == ""){
		oCad += "Por favor ingrese su apellido<br>";
		bool = false;
	}
	
	
	if(!validarEmail(oEmail.value) || trim(oEmail.value) == ""){
		oCad += "El e-mail está vac&iacute;o o su formato es incorrecto<br>";
		bool = false;
	}
		
	if(bool){
		return true;
	}
	else{
		if(document.getElementById("estadoEnvio"))
			document.getElementById("estadoEnvio").innerHTML = "";
		oMsjCto.style.display = "block";
		oMsjCto.innerHTML = oCad;
		return false;
	}
}






//--------------------------------------------------------------------------------------------------------------------//
function loadUsr(){
	if(document.getElementById("recordar_usr")){
		var datosUsr = fetchNamedCookie("ACCOUNT_USER_PUNTOBIZ");
		if(datosUsr != ''){
			var splitDatos = datosUsr.split("|");
			document.getElementById("recordar_usr").checked = true;
			
			if(splitDatos[1] != ''){
				//muestro el campo contraseña
				document.getElementById("contrasenia_old").style.display = "none";
				document.getElementById("contrasenia_old").style.visibility = "hidden";
			    document.getElementById("contrasenia").style.display = "block";
				document.getElementById("contrasenia").style.visibility = "visible";
		
				document.getElementById("usuario").value = splitDatos[0];
				document.getElementById("contrasenia").value = splitDatos[1];
			}
		}
	}	
}


//-----------------------------------------------------
 var contador = 0;
 var contadorAviso = 0;
 
//cierro la sesion dado cierta cantidad de tiempo de inactividad, primero le aviso
function tiempoSesionAviso(val2)
{
	contadorAviso = val2;
	contadorAviso++;
	
	if (contadorAviso==1200) { document.getElementById("avisoSesion").innerHTML =  ""; 
		                     location.href = "/salir.html";
	                         }
	
	if (contadorAviso==900){    
		    
		aviso = "<div align='center' style='width:700px; position:absolute; z-index:1000; padding:20px; background:red; color:#ECECED;' ><b>¿Desea prolongar el tiempo de su sesion?<br><a href='/actual.html' style='color:#FFF;'>ACEPTAR</a></b></div>"
            
        document.getElementById("avisoSesion").innerHTML =  aviso; 
       }
       
	
	                   
	                  
	
       
    setTimeout("tiempoSesionAviso(contadorAviso)", 1000);   
}


//------------------------------------------

function crearObjetoAjax(){
	var obj;
	if(window.XMLHttpRequest){ // no es IE
		obj = new XMLHttpRequest();
	}
	else{ // Es IE o no tiene el objeto
		try {
			obj = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e) {
			alert('El navegador utilizado no está soportado');
		}
	}
	return obj;
}

//------------------------------------------


function agregar_favoritos(value1,value2,value3){
	
	oXML2 = crearObjetoAjax();
	oXML2.open("GET","../../favoritos/agregar_favoritos.php?fecha="+value1+"&articulo="+value2+"&titulo="+value3);
	oXML2.onreadystatechange = function(){
		if (oXML2.readyState == 4 ){			
			var resp2 = oXML2.responseText;
			alert(resp2)
			
		}						
	}
	oXML2.send(null);
	
 
}
//------------------------------------------


function eliminar_favoritos(value1,value2,value3){
	
	oXML2 = crearObjetoAjax();
	oXML2.open("GET","../../favoritos/eliminar_favoritos.php?fecha="+value1+"&articulo="+value2+"&titulo="+value3);
	oXML2.onreadystatechange = function(){
		if (oXML2.readyState == 4 ){			
			var resp2 = oXML2.responseText;
			alert(resp2);
			location.href = "/actual.html";
		}						
	}
	oXML2.send(null);
	
 
}


//---------------------------------------------------------------------//
function marqueeStop(){
	document.getElementById("marq").stop();
	//document.getElementById("marqueeplay").style.display = "block";
	//document.getElementById("marqueestop").style.display = "none";
}
function marqueePlay(){
	document.getElementById("marq").start();
	//document.getElementById("marqueeplay").style.display = "none";
	//document.getElementById("marqueestop").style.display = "block";
}
//---------------------------------------------------------------------//
//------------------------------------------


function agregar_pdf(value1){
	
	
	var destino = document.getElementById("pdf_carrito");
	if(typeof(document.getElementById("pdf_icono_"+value1)) != 'undefined') var icono = document.getElementById("pdf_icono_"+value1);
	oXML2 = crearObjetoAjax();
	oXML2.open("GET","../../../../../pdf/agregar_pdf.php?id_pdf="+value1);
	oXML2.onreadystatechange = function(){
		if (oXML2.readyState == 4 ){			
			var resp2 = oXML2.responseText;
			destino.innerHTML=resp2 ;
			if(icono != null) icono.innerHTML = '<img src="/global/img/icons/cart_delete.gif" style="cursor:pointer;" alt="Eliminar del carrito PDF" width="16" title="Eliminar del carrito PDF" onclick="eliminar_pdf('+value1+')"/>';
		}						
	}
	oXML2.send(null);
	
 
}
//------------------------------------------


function eliminar_pdf(value1){
	
	var destino = document.getElementById("pdf_carrito");
	if(typeof(document.getElementById("pdf_icono_"+value1)) != 'undefined' ) var icono = document.getElementById("pdf_icono_"+value1);
    
	oXML2 = crearObjetoAjax();
	oXML2.open("GET","../../../../../pdf/eliminar_pdf.php?id_pdf="+value1);
	oXML2.onreadystatechange = function(){
		if (oXML2.readyState == 4 ){			
			var resp2 = oXML2.responseText;
			destino.innerHTML=resp2 ;
			if(icono != null) icono.innerHTML = '<img src="/global/img/icons/cart_add.gif" style="cursor:pointer;" alt="Agregar a carrito PDF" width="16"  title="Agregar a carrito PDF" onclick="agregar_pdf('+value1+')"/>';
			
		}						
	}
	oXML2.send(null);
	
 
}

//-------------------------------------------------------------//
function muestra_imagen(archivo,ancho,alto){
	//xInnerHtml('c1','')
	xWidth ('ampliacion',ancho + 6)
	xHeight ('ampliacion',alto + 6 + 20)
	xWidth ('c1',ancho)
	xHeight ('c1',alto)
	xWidth ('cerrarampliacion',ancho)
	
	
	xInnerHtml('c1','<img src="' + archivo + '" width="' + ancho + '" height="' + alto + '" border="0">')	
	xShow('ampliacion');
}
//-------------------------------------------------------------//
function muestra_texto(texto,titulo){
	//xInnerHtml('c1','')
	
	
	
	xInnerHtml('c1',"<h2>"+titulo+"</h2>"+"<br>"+texto)	
	xShow('ampliacion');
}

function cerrar_ampliacion(){
	xHide('ampliacion');
	
}

window.onload = function(){

}
//------------------------------------------------------------//
function showdiv(event,id)
{
	//determina un margen de pixels del div al raton
	margin=5;

	//La variable IE determina si estamos utilizando IE
	var IE = document.all?true:false;
	//Si no utilizamos IE capturamos el evento del mouse
	if (!IE) document.captureEvents(Event.MOUSEMOVE)

	var tempX = 0;
	var tempY = 0;

	if(IE)
	{ //para IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	}else{ //para netscape
		tempX = event.pageX;
		tempY = event.pageY;
	}
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}

	//modificamos el valor del id "posicion" para indicar la posicion del mouse
	//document.getElementById('posicion').innerHTML="PosX = "+tempX+" | PosY = "+tempY;

	//document.getElementById(''+id).style.top = (tempY+margin);
	//document.getElementById(''+id).style.left = (tempX+margin);
	document.getElementById(''+id).style.display='block';
	return;
}

function wordWrap(){
/******
* wordWrap to firefox for big words
* Creative Commons license * Version: 1.0 - 26/04/2006
* Autor: Micox - Náiron J.C.G - micoxjcg@yahoo.com.br - http://elmicoxcodes.blogspot.com
* Uso: call the function on onload of body element.
* put the class "word-wrap" on elements to wordwrap
*******/
    var larg_total,larg_carac,quant_quebra,pos_quebra;
    var elementos,quem, caracs, texto, display_orig;
    
    elementos = document.getElementsByTagName("p")
    
    for(var i=0; i<elementos.length;i++){
        if(elementos[i].className=="word-wrap"){
            quem = elementos[i];
            
            quem.innerHTML = String(quem.innerHTML).replace(/ /g,"Ø")
            texto = String(quem.innerHTML)
            
            quem.innerHTML = " "
            
            display_orig = quem.style.display;
            quem.style.display="block";
            larg_oficial = quem.offsetWidth;
            //alert("oficial: " + larg_oficial)
            //alert("display " + quem.style.display)
            if(!document.all) quem.style.display="table";
            //alert("display " + quem.style.display)
            quem.innerHTML = texto;
            larg_total = quem.offsetWidth;
            //alert("total: " + larg_total)
            
            pos_quebra = 0;
            caracs = texto.length;
            texto = texto.replace(/Ø/g," ")
            larg_carac = larg_total / caracs
            if(larg_total>larg_oficial){
                quant_quebra = parseInt(larg_oficial/larg_carac)
                quant_quebra = quant_quebra - (parseInt(quant_quebra/6)) //quanto menor o num, maior a garantia;
                quem.innerHTML = ""
                while(pos_quebra<=caracs){
                    quem.innerHTML = quem.innerHTML + texto.substring(pos_quebra,pos_quebra + quant_quebra) + " "
                    pos_quebra = pos_quebra + quant_quebra;
                }
            }else{
                quem.innerHTML = texto;
            }//end if do larg_total>larg_oficial
            quem.style.display = display_orig;
        }//end if do word wrap
    }//end for loop dos elementos
}