function eliminarEspacios(cadena){return cadena.replace(/^\s*([a-z0-9\-\.@_]+)\s*$/i,"$1");}

function Panel(_id,_titulo,_mensaje,_opciones,cargar)
{
   
    this.id = _id;
    this.titulo = _titulo;
    this.mensaje = _mensaje;
    this.opciones = _opciones;
    this.destino = document.body;
    this._header = "";
    this._body = "";
    this._footer = "";
    
    this.ajax = null;
    
    if (window.paneles == null)
    {
        window.paneles = Array();
    }

    this.cargar = function()
    {
        this.cargarOpciones();

   	    this.panel = new YAHOO.widget.Panel(this.id,this.opciones);
        var kl = new YAHOO.util.KeyListener(document, { keys:27}, { fn:this.panel.hide, scope:this.panel, correctScope:true } );
        this.panel.cfg.queueProperty("keylisteners", kl);
        
   	    window.paneles[this.id] = this.panel;
    };
    
    this.cargarOpciones = function()
    {
    
        var opDef = {fixedcenter:true,constraintoviewport:true,underlay:'shadow',close:true,visible:false,draggable:true};
    	for (a in this.opciones)
	    {
		    opDef[a]=this.opciones[a]
	    }
        this.opciones = opDef;
    }; 
    
    this.procesar = function()
    {
    };
    this._armarHeader = function()
    {
        return "<span class='color'>"+this.titulo+"</span>";
    };
    this._armarBody = function()
    {
        this._body = "";
        switch(typeof this.mensaje)
        {
	        case "function":
	        {
		        this._body = this.mensaje();
			    this.panel.setBody(this._body);
	        }
	        break;
	        case "object":
	        {
			    var idLoading = 'pnl'+this.id+'_loading';
			    this._body = '<div id="'+idLoading+'" class="loading" style="display:block;"></div>';
			    this.panel.setBody(this._body);

	            this.ajax = new Ajax(this.mensaje.url);
	            this.ajax.datos["panel"] = this.panel;
	            
	            this.ajax.ocultar(this.panel.footer);

	            this.ajax.setLoading(idLoading);

                this.ajax.setForm(this.opciones.form);

	            this.ajax.handlerOk = function(o)
	            {
	                o.argument.datos.panel.setBody(o.responseText);
                }
	            this.ajax.postHandlerOk = function(o)
	            {
	                o.argument.mostrar(o.argument.datos.panel.footer);
                }
                
                return this.ajax;
	        }
	        break;
	        default:
	        {
		        this._body = this.mensaje;
			    this.panel.setBody(this._body);
	        }
        }
        
        return null;
        
    };
    this._armarFooter = function()
    {
        if (this.opciones.mostrarFooter != false)
        {
	        var botones;
	        botones="<center>";
	        for (bot in this.opciones.botonera)
	        {
		        botones = botones + '<a href="javascript:'+this.opciones.botonera[bot].click+';" class="'+this.opciones.botonera[bot].clase+'" id="'+this.opciones.botonera[bot].id+'"'+(this.opciones.botonera[bot].style!=null?'style="'+this.opciones.botonera[bot].style+'"':'')+'></a>&nbsp;&nbsp;';
	        }
	        botones = botones + "</center>";
		    if (this.opciones["leyendaPie"]!=null && this.opciones["leyendaPie"]!="" )
		    {
			    botones = botones + this.opciones["leyendaPie"];
		    }
	    
    	    return botones;
        }
        else
        {
            return "";
        }
    };
    
    this.mostrar = function()
    {
	    this.panel.setHeader(this._armarHeader());
	    this.panel.setFooter(this._armarFooter());
	    this._armarBody();
		
        this.panel.render(this.destino);
		this.panel.show();
		if (this.opciones.accionJavaScript!=null && this.opciones.accionJavaScript!="")
		{
			eval(this.opciones.accionJavaScript);
		}

	    if (this.ajax != null && typeof this.ajax == 'object')
	        this.ajax.enviar();
		
    };
    
    if (cargar == null || cargar != false){this.cargar();}
}

function showPanel(id,titulo,mensaje,opciones) 
{
    new Panel(id,titulo,mensaje,opciones).mostrar();    
}

function showModalPanel(id,titulo,mensaje,opciones) 
{

	var opDef ={modal:true}
	
	for (a in opDef)
	{
		opciones[a]=opDef[a];
	}
	
	return showPanel(id,titulo,mensaje,opciones);
}

function panelCaptcha()
{
    var comentario = document.getElementById("txtArea_comentario");
    if (comentario != null)
    {
        comentario.value = eliminarEspacios(comentario.value);
        
        if (comentario.value.length == 0)
        {
            alert("Por favor ingrese su comentario");
            comentario.focus();
            comentario = null;
            return false;
        }
            
        var calificaciones = document.getElementsByName("rd_calificacion");
        if (calificaciones != null && calificaciones.length > 0)
        {
            var calificacion = false;

            for (var i=0; i < calificaciones.length && ! calificacion ; i++)
            {
                calificacion = calificaciones[i].checked;
            }

            if (! calificacion)
            {
                alert("Por favor ingrese su calificación");
                return;
            }
        }

        showModalPanel
        (
            "panelCaptcha",
            "Modalidad de participacion",
            {url:"/_common/includes/xformEnvioComentario_v2.ajax"},
            {
                mostrarFooter:false,
                form:"_formComentario",
                method:"Post",
                modal:true,
                width:"350px",
                zindex:"1000"
            }
        );

    }
}

// Funcion de panel para agregar el codigo de la nota en un textarea
function panelPublicarEnTuSitio(id,volanta,titulo,bajada,subCanal,fecha)
{
    showModalPanel(
        "panelPublicarEnTuSitio",
        "Publicar en tu sitio",
        getBodyPublicarEnTuSitio(id,volanta,titulo,bajada,subCanal,fecha),
        {
                    modal:true,
                    width:"320px",
                    zindex:"1000",
					accionJavaScript:"document.getElementById('area').select();"
        }
    );
}

// Funcion para panel envio de notas
function panelEmail(nota_id,nota_titulo,nota_volanta)
{
        showModalPanel
        (
            "panelEmail",
            "Enviar por email",
            {url:"/_common/includes/xFormEnvioEmail_v2.ajax?nota_id="+nota_id+"&nota_titulo="+nota_titulo+"&nota_volanta="+nota_volanta},
            {
				leyendaPie:"<p class='gray'>Revista OH! LaLá mantendrá absoluta confidencialidad de los datos personales brindados por nuestros visitantes. Los servicios de información por correo electrónico que ofrecemos se realizan con el expreso consentimiento de los usuarios. <a href='http://www.lanacion.com.ar/registracion/PoliticaConfidencialidad.asp'><br /><span class='bullet'>></span> Política de confidencialidad</a></p>",
                form:"_formEmail",
                method:"Post",
                modal:true,
                width:"450px",
                height:"532px",
                zindex:"1500"
            }
        );
}

// Funcion de panel para envio de frases a un mail especifico
function panelEnvioAmigo(nota_id,nota_titulo)
{
        showModalPanel
        (
            "panelEmail",
            "Recomendá a un amigo",
            {url:"/_common/includes/xFormEnvioAmigo.ajax?nota_id="+nota_id+"&nota_titulo="+nota_titulo},
            {
				leyendaPie:"",
                form:"_formEmail",
                method:"Post",
                modal:true,
                width:"450px",
                height:"420px",
                zindex:"1500"
            }
        );
}

// Funcion de panel para envio de frases a un moderadora publicar en el sector frases que inspiran
function panelEnvioFrase(nota_id,nota_titulo)
{
        showModalPanel
        (
            "panelEmail",
            "Enviá tu frase",
            {url:"/_common/includes/xFormFrase.ajax?nota_id="+nota_id+"&nota_titulo="+nota_titulo},
            {
				leyendaPie:"",
                form:"_formEmail",
                method:"Post",
                modal:true,
                width:"450px",
                height:"275px",
                zindex:"1500"
            }
        );
}

// Funcion de panel para envio de foto a moderador a publicar en el sector cool hunter
function panelEnvioFoto()
{
        showModalPanel
        (
            "panelEmail",
            "Subi tu foto",
            {url:"/_common/includes/xFormEnvioFoto.ajax"},
            {
				leyendaPie:"",
                form:"_formEmail",
                method:"Post",
                modal:true,
                width:"450px",
                height:"200px",
                zindex:"1500"
            }
        );
}

// Funcion para panel de look del dia
function panelLookEmail(nota_dia,nota_titulo)
{
        showModalPanel
        (
            "panelEmail",
            "Enviar por email",
            {url:"/_common/includes/xFormLook.ajax?nota_dia="+nota_dia+"&nota_titulo="+nota_titulo},
            {
				leyendaPie:"",
                form:"_formEmail",
                method:"Post",
                modal:true,
                width:"450px",
                height:"400px",
                zindex:"1500"
            }
        );
}

// Funcion para panel de look del dia
function panelObjetoEmail(nota_dia,nota_titulo)
{
        showModalPanel
        (
            "panelEmail",
            "Enviar por email",
            {url:"/_common/includes/xFormObjeto.ajax?nota_dia="+nota_dia+"&nota_titulo="+nota_titulo},
            {
				leyendaPie:"",
                form:"_formEmail",
                method:"Post",
                modal:true,
                width:"450px",
                height:"400px",
                zindex:"1500"
            }
        );
}


function getBodyPublicarEnTuSitio(id,volanta,titulo,bajada,subCanal,fecha)
{
	var str = "";
	str ='Copiando este código (Ctrl+C) e insertándolo en tu página podrás visualizar la nota en tu sitio: ';
	str = str + '<div><textarea name="area" id="area" style="width:280px;height:170px;font:11px/14px tahoma;margin:8px 0 0 0;"><div style="width:100%;" align="center"><div style="background-color:#FEF200;height:44px;"><div style="float:left;"><a href="http://www.revistaohlala.com/nota.asp?nota_id='+ id + '"><img src="http://www.revistaohlala.com/_common/images/logo-small-mail.gif" border="0" style="margin:5px;"></a></div></div>';
	if (volanta!="")
	{
		str = str + '<div align="left" style="font-family:Arial;font-size:11px;color:#000000;padding-top:18px;padding-left:14px;">'+volanta+'</div>';
	}
	if (titulo!="") 
	{
		str = str + '<div align="left" style="font-family: Georgia;font-size:23px;color:#000000;padding: 10px 0px 10px 14px;"><a href="http://www.revistaohlala.com/nota.asp?nota_id='+ id + '" target="_blank" title="Ir a la nota" style="text-decoration:none;color:#124679;">'+ titulo+ ' </a></div>';
	}
	if (bajada!="")
	{
		str = str + '<div align="left" style="font-family: Arial;font-size:14px;color:#000000;padding: 0px 0px 10px 14px;">'+ bajada +'</div>';
	}
	str = str + '<div align="left" style="font-family: Arial;font-size:11px;text-decoration:underline;color:#00adef;padding-left:14px;padding-bottom:0px;"><a href="http://www.revistaohlala.com/nota.asp?nota_id='+ id + '" style="font-family: Arial;font-size:11px;text-decoration:underline;color:#00ADEF;">http://www.revistaohlala.com/nota.asp?nota_id='+ id + '</a></div>';
	str = str + '<div align="left" style="width:100%;border-bottom:1px solid #E5E5E5;padding: 0px 24px 0px 15px;font-family:Arial;font-size:11px;color:#4C4C4C;"></div>';
	str = str + '<div align="left" style="font-family:Arial;font-size:11px;color:#4C4C4C;padding-left:14px;padding-top:8px;">Copyright Publirevistas S. A. 2008. Todos los derechos reservados.</div>';
	return str;
}

function getBodyPublicarEnTuSitioOld(id,volanta,titulo,bajada,subCanal,fecha)
{
	var str = "";
	str ='Copiando este código (Ctrl+C) e insertándolo en tu página podrás visualizar la nota en tu sitio: ';
	str = str + '<div><textarea name="area" id="area" style="width:280px;height:170px;font:11px/14px tahoma;margin:8px 0 0 0;"><div style="padding:8px 5px 10px 5px;background-color:#fff;"><div style="border-bottom:1px dashed #ccc;padding-bottom:5px;margin-bottom:7px;">';
	if (volanta!="")
	{
		str = str + '<div style="font:normal 11px/14px tahoma, arial;color:#808080;margin-bottom:5px;">'+volanta+'</div>';
	}
	if (titulo!="") 
	{
		str = str + '<div style="font:normal 18px/21px arial;color:#333;margin-bottom:7px;"><a href="http://www.lanacion.com.ar/'+ id + '" target="_blank" title="Ir a la nota en LANACION.com" style="text-decoration:none;color:#124679;">'+ titulo+ ' </a></div>';
	}
	
	if (bajada!="")
	{
		str = str + '<div style="font:normal 13px/17px trebuchet ms, arial;color:#333;margin-bottom:7px;">'+ bajada +'</div>';
	}
	
	str = str + '</div><div style="font:normal 11px/14px tahoma, arial;color:#808080;margin-bottom:5px;"><div style="float:left;"><b>LANACION.com </b>| ' + subCanal+ ' | ' + fecha + '</div><div style="float:right;"><span style="font:bold 11px/14px Comic Sans Ms;color:#124679;text-decoration:none;">></span> <a href="http://www.lanacion.com.ar/'+id+'" target="_blank" title="Ir a la nota en LANACION.com" style="text-decoration:none;color:#124679;"><b>Ir a la nota</b></a></div><br clear="all" /></div></div></textarea></div>';
	
	return str;
}

function panelLinkPermanente(linkCorto)
{ 
    showModalPanel(
		"panelLinkPermanente",
        "Link Permanente",
        getBodyLinkPermanente(linkCorto),
        
        {
                    modal:true,
                    width:"320px",
                    zindex:"1000",
					accionJavaScript:"document.getElementById('areaLink').select();"
         }
    );
}

function getBodyLinkPermanente(linkCorto)
{
	var str = "";
	str = "Copiá (Ctrl+C) y guardá esta dirección para poder ingresar directamente a esta nota: ";
	str = str + "<textarea name='areaLink' id='areaLink' style='width:270px;height:50px;font:11px/14px tahoma;margin:8px 0;'>"+ linkCorto+"</textarea>";	
	return str;
}


function panelReportarAbuso(comentario_id,entrada_id,nota_id,categoria_id,esPadre)
{
	//var valorCookieLogin = LeerCookie("cookieLogin");
	
	//eliminar
	var valorCookieLogin = "sesion=%7B8441B70F%2D9F99%2D4C7B%2D90D5%2D3D140044E264%7D&timstam=2008%2D04%2D25+12%3A14%3A51%2E370&usuario_id=1242731&aplicacion_id=&pwd=%2EZ2cT%28&estado_id=1&horaImagenActualizacion=3132008111502&nacimiento=5%2F1%2F1908";
	var valor_usuario_ID = "1242731";
	var valor_usuario_nombre = "jose%5Fhernandez2";

	if(valorCookieLogin != "")
	{
		showModalPanel
		(
			"panelReportarAbuso",
			"Reporte de abuso",
			{url:"/frontend/Ajax/xComentarioDenunciar.aspx?usuario_id="+ valor_usuario_ID +"&usuario_nombre="+valor_usuario_nombre+"&comentario_id=" + comentario_id + "&entrada_id="+ entrada_id +"&nota_id="+nota_id+"&categoria_id="+categoria_id+"&rnd="+Math.random()*100},
			{
				mostrarFooter:false,
				modal:true,
				width:"320px",
				zindex:"1000"
			}
		);
	}else
		{
			window.location = getUrlRegistracion();
		//	alert("Debe estar loguedo para poder reportar.");
		}
}

function panelVideoCast(titulo,cuerpo)
{
    showModalPanel
    (
        "panelVideoCast",
        titulo,
		cuerpo,
        {
            mostrarFooter:false,
            modal:true,
            width:"730px",
            height:"400px",
            zindex:"1000"
        }
	);
}

function panelGaleria(nota_id,nota_titulo,nota_epigrafe,imagen_id)
{
        showModalPanel
        (
            "panelGaleria",
            nota_titulo,
            {url:"/_common/includes/xCajaGaleria.ajax?nota_id="+nota_id+"&nota_epigrafe="+nota_epigrafe+"&imagen_id="+imagen_id},
            {
                form:"_formEmail",
                method:"Post",
                modal:true,
                width:"710px",
                height:"500px",
                zindex:"1500"
            }
        );
}