

tab_actual="menu_tab1";
tab_content_actual="tab1";
creandoComentario=false;
abiertoNuevoComentario = false;

image_actual=0;


function init_tab(t,c,pestanyas){
	tab_actual=t;
	tab_content_actual=c;
	
	if(pestanyas==1){
		div=document.getElementById(tab_actual);
		div.className="active";
	}
	
	div=document.getElementById(tab_content_actual);
	div.style.display='';
}
  
function select_tab(tab,content)
{
	if(tab!=tab_actual)
	{
		div=document.getElementById(tab);
		div.className="active";
		
		div=document.getElementById(tab_actual);
		div.className="no_active";
		
		div=document.getElementById(content);
		div.style.display="";
		
		div=document.getElementById(tab_content_actual);
		div.style.display='none';
		
		tab_actual=tab;
		tab_content_actual=content;
	}
    
   	     
	//no focus
	//div=document.getElementById("tab_focus");
	//div.focus();
    
}


function ocultarVideo()
{
    div=document.getElementById('video_1');
    if(div)
	    div.style.display = 'none';
}



// NOTICIA 
function addFavoritos(url,titulo){
   if ((navigator.appName=="Microsoft Internet Explorer") && 
		 (parseInt(navigator.appVersion)>=4)) {
	  window.external.AddFavorite(url,titulo);
   } else { 
	  if(navigator.appName == "Netscape") 
		 window.sidebar.addPanel(titulo, url, '');
   }
}
   
    
    
    
/**
 * Mostrar una imagen
 */
 
 
function showImage(num)
{
	var imagen2=image_actual;
	if(num!=image_actual)
	{
		// cambio estilos y eventos del anterior boton
		div=document.getElementById("photo_"+image_actual);
		div.className="photo_bt";
		div.onmouseover=function (){ this.className="photo_bt_onover"; };
		div.onmouseout=function (){ this.className="photo_bt"; };
		div.onclick=function(){ showImage(imagen2); }
		
		// cambio estilos y eventos del actual boton
		div=document.getElementById("photo_"+num);
		div.className="photo_bt_on";
		div.onmouseover=function (){ };
		div.onmouseout=function (){ };
		div.onclick=function(){ }
		
		// intercambio de las imagenes
		div=document.getElementById("photo_actual");
		div.style.opacity=0;
		
		
		/*
		document.getElementById("photo_a_"+image_actual).innerHTML=div.innerHTML;
		div.innerHTML=document.getElementById("photo_a_"+num).innerHTML;
		document.getElementById("photo_a_"+num).innerHTML='';
		*/
		
		document.getElementById("photo_a_"+image_actual).style.display="none";
		document.getElementById("photo_a_"+num).style.display="";
		
		
		//Lightbox.prototype.updateImageList();

		//div=document.getElementById("photo_actual");
		//div.style.opacity=0;
        //html='<a href="'+fotos[image_actual]["big"]+'" rel="ibox?height=1426&width=1500" title="'+fotos[image_actual]["pie"]+'" alt="'+fotos[image_actual]["pie"]+'"><img onload="tween_alpha(\'photo_actual\');" class="photo" src="'+fotos[image_actual]["path"]+'" width="'+fotos[image_actual]["width"]+'" height="'+fotos[image_actual]["height"]+'" /></a>'; 
		//div.innerHTML=html;

		//init_ibox();
		
		// intercambio de los pies
		div=document.getElementById("photo_footer");
		pie=document.getElementById("photo_pie_"+num).innerHTML;
		//div.innerHTML=fotos[image_actual]["pie"];
		div.innerHTML=pie;
		
		
		image_actual=num;
		
		tween_alpha('photo_actual');
	}
}

function tween_alpha(div){
	new Effect.Opacity(div, {duration:0.5, from:0, to:1});
}



// Efecto slide
function slide(div,modo)
   {
                            
    if(modo)
        Effect.SlideUp(div, {duration:0.5});
    else
        Effect.SlideDown(div, {duration:0.5});
                    
    }
    
    
    
// Enviar a un amigo la noticia


/**
 * Crear un comentario
 */  
function newComment(){
     
    if(!creandoComentario)
    {
    
    document.getElementById("comentario").value = "";
    document.getElementById("emailComentario").value = "";
    document.getElementById("nombreComentario").value = "";
    document.getElementById("privacidadComentario").checked = false;
    document.getElementById("error").style.display = "none";
    
    creandoComentario = true;
    div = "nuevoComentario";
    modo = abiertoNuevoComentario;    
    slide(div,modo);
    window.setTimeout("activarBotonComentario()",500);
    
    if(abiertoNuevoComentario)
        abiertoNuevoComentario = false;
        else
            abiertoNuevoComentario = true;    
    }
    
}

// Control del comentario desplegable
function activarBotonComentario()
{
	creandoComentario = false; 
	
	// actualizamos dimensiones del lightwindow
	if(abiertoNuevoComentario)
		new_height = myLightWindow.pageDimensions.height + 350;
	else
		new_height = myLightWindow.pageDimensions.height;
	
	document.getElementById("lightwindow_overlay").style.height=new_height+'px';
}

  

function reduceText() {
    //tamTexto=document.getElementById('cuerpoNoticia').style.fontSize;
    if(tamTexto > 7)
        tamTexto = tamTexto-2;
    
    tam = (tamTexto)+'px';    
    document.getElementById('cuerpoNoticia').style.fontSize = tam;            
}
			
function increaseText() {
	//tamTexto=document.getElementById('cuerpoNoticia').style.fontSize;
	if(tamTexto < 18)
		tamTexto = tamTexto+2;
	
	tam = (tamTexto)+'px';	
	document.getElementById('cuerpoNoticia').style.fontSize = tam;			
}


function errFunc()
    {
        alert("error");
        document.body.style.cursor="";
        document.getElementById("botonComentario").style.cursor="";
        document.getElementById("botonEnviar").style.cursor="";
    }
    
    
    
function mi_replace(a,b,c)
{
	return a.split(b).join(c);
}

function ord( string ) 
{
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: ord('K');
    // *     returns 1: 75
    // *     example 2: ord('\uD800\uDC00'); // surrogate pair to create a single Unicode character
    // *     returns 2: 65536
 
    var str = string + '';
    
    var code = str.charCodeAt(0);
    if (0xD800 <= code && code <= 0xDBFF) { // High surrogate (could change last hex to 0xDB7F to treat high private surrogates as single characters)
        var hi = code;
        if (str.length === 1) {
            return code; // This is just a high surrogate with no following low surrogate, so we return its value;
                                    // we could also throw an error as it is not a complete character, but someone may want to know
        }
        var low = str.charCodeAt(1);
        if (!low) {
            
        }
        return ((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
    }
    if (0xDC00 <= code && code <= 0xDFFF) { // Low surrogate
        return code; // This is just a low surrogate with no preceding high surrogate, so we return its value;
                                // we could also throw an error as it is not a complete character, but someone may want to know
    }
    return code;
}
function chr( codePt ) 
{
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: chr(75);
    // *     returns 1: 'K'
    // *     example 1: chr(65536) === '\uD800\uDC00';
    // *     returns 1: true
    
    if (codePt > 0xFFFF) { // Create a four-byte string (length 2) since this code point is high
                                             //   enough for the UTF-16 encoding (JavaScript internal use), to
                                             //   require representation with two surrogates (reserved non-characters
                                             //   used for building other characters; the first is "high" and the next "low")
        codePt -= 0x10000;
        return String.fromCharCode(0xD800 + (codePt >> 10), 0xDC00 + (codePt & 0x3FF));
    }
    else {
        return String.fromCharCode(codePt);
    }
}



function sendComment()
{
    
        
    var comentario = document.getElementById("comentario").value;
    var email = document.getElementById("emailComentario").value;
    var nombre = document.getElementById("nombreComentario").value;
    var numComentarios = document.getElementById("numComentarios").value;
    var privacidad = document.getElementById("privacidadComentario").checked;
    
    
    //if((comentario != "")&&(email != "")&&(nombre != "")&&(numComentarios != "")&&(privacidad == true))
    if(checkForm())
    {
	    document.body.style.cursor="wait";
	    document.getElementById("botonComentario").style.cursor="wait";
	    newComment();
	    
	    //alert(comentario);
	    //alert(ord(comentario));
	    //alert(chr(8364));
	    //chr(8364) => ?
	    
	    comentarioBD = mi_replace(comentario,chr(8364),"xxVxxeuroxxVxx");
	    
	    new Ajax.Request("../noticiaRequest.php", {method:"post", postBody:"opcion=comentario&comentario="+comentario+"&comentarioBD="+comentarioBD+"&email="+email+"&nombre="+nombre+"&idNoticia="+idNoticia+"&numComentarios="+numComentarios+"&privacidad="+privacidad, onSuccess:sendCommentOk, onFailure:errFunc});
    }/*
    else
    {
        document.getElementById("erroresComentario").innerHTML = textoErrorComentario;
    }*/

}
var error="";

function checkForm()
{	
	var _comentario            = document.getElementById('comentario').value;
	var _nombreComentario      = document.getElementById('nombreComentario').value;
	var _emailComentario       = document.getElementById('emailComentario').value;
	var _privacidadComentario  = document.getElementById('privacidadComentario').checked;

	var _ereg_email= /^[^@ ]+@[^@ ]+.[^@ .]+$/;
	var t1=_ereg_email.test(_emailComentario);
	
	var flag  = '- ';
	var error = '';
	
	if (_comentario == ""){
		document.getElementById('comentarioText').className = 'text error';
		document.getElementById('comentario').className = 'fieldFormAreaError';
		error+= flag+error1;//
		flag='<br>- ';
	}else{
		document.getElementById('comentarioText').className = 'text';
		document.getElementById('comentario').className = 'fieldFormArea';
	}
	
	if (_nombreComentario == ""){
		document.getElementById('nombreComentarioText').className = 'text error';
		document.getElementById('nombreComentario').className = 'fieldFormError';
		error+= flag+error2;//
		flag='<br>- ';
	}else{
		document.getElementById('nombreComentarioText').className = 'text';
		document.getElementById('nombreComentario').className = 'fieldForm';
	}
	
	if (_emailComentario == "" || !t1){
		document.getElementById('emailComentarioText').className = 'text error';
		document.getElementById('emailComentario').className = 'fieldFormError';
		error+= flag+error3;//EMAIL_ERROR_TXT
		flag='<br>- ';
	}else{
		document.getElementById('emailComentarioText').className = 'text';
		document.getElementById('emailComentario').className = 'fieldForm';
	}
	
	if (!_privacidadComentario){
		document.getElementById('privacidadComentarioText').className = 'text error';
		//document.getElementById('privacidadComentario').className = 'fieldForm';
		error+= flag+error4;//
		flag='<br>- ';
	}else{
		document.getElementById('privacidadComentarioText').className = 'text';
		//document.getElementById('privacidadComentario').className = 'fieldForm';
	}
	
	
	if (error != "")
	{	
		document.getElementById('error').style.display = '';
		document.getElementById('error').className = 'errorRojoCaja';
		document.getElementById('error').innerHTML = "<span> "+info_error+": <br> </span>";
		document.getElementById('error').innerHTML += error;
		
		return false;			
	}
	else
	{
		document.getElementById('error').style.display = '';
		document.getElementById('error').className = 'infoNaranjaCaja';
		document.getElementById('error').innerHTML = "<span> "+info_enviando+" <br> </span>";
		
		return true;
	}
	
}

function viewComment(pagina)
{
    
    document.body.style.cursor="wait";
    document.getElementById("listadoComentarios").innerHTML = "<table width='100%' height='250px' border='0' cellspacing='0' cellpadding='0'><tr><td align='center' valign='middle'><img src='../skin/loading.gif' /><tr><td>"; 
   
    new Ajax.Request("../noticiaRequest.php", {method:"post", postBody:"opcion=viewComentario&pagina="+pagina+"&idNoticia="+idNoticia, onSuccess:viewCommentOk, onFailure:errFunc});
  
}
    
            
function sendCommentOk(t)
{
      
    var xml = t.responseXML;
    var listado = xml.getElementsByTagName("listado")[0].childNodes[0].data;
    var numero = xml.getElementsByTagName("numero")[0].childNodes[0].data;
    var buttons = xml.getElementsByTagName("buttons")[0].childNodes[0].data;
    
    document.getElementById("listadoComentarios").innerHTML = listado; 
    document.getElementById("buttons").innerHTML = buttons;  
    
    document.body.style.cursor="";
    document.getElementById("botonComentario").style.cursor="";
    
    if(revisar)
    	{
    	//alert("se envio el comentario, y ahora esta siendo revisado para su publicacion");
    	//showBG();
		//showIbox('#revisarComentario','',{width:475, height:70} );
	     
	     myLightWindow.activateWindow({
			href: '../revisarComentario.php', 
			height:100,
			width:600,
			type:'external',
			title: '', 
			author: '', 
			caption: ''
		});
	     //myLightWindow.deactivate();
     
    	}
    	else
    	{
    	document.getElementById("nComentario").innerHTML = numero; 
    	}
      
}

function viewCommentOk(t)
{
      
    var xml = t.responseXML;
    var listado = xml.getElementsByTagName("listado")[0].childNodes[0].data;
    var buttons = xml.getElementsByTagName("buttons")[0].childNodes[0].data;
    document.getElementById("listadoComentarios").innerHTML = listado; 
    document.getElementById("buttons").innerHTML = buttons;

    document.body.style.cursor="";
      
}


function borrarAmigo()
{
   if(document.getElementById("correoAmigo"))
   {
	   document.getElementById("correoAmigo").value ="";
	   document.getElementById("nombreAmigo").value ="";
	   document.getElementById("correoTu").value ="";
	   document.getElementById("nombreTu").value="";
   }
	

}

function enviarAmigo()
    {

    	if(checkFormAmigo()){
		    document.body.style.cursor="wait";
		    new Ajax.Request("noticiaRequest.php", {method:"post", postBody:"opcion=enviarAmigo&correoDestino="+global_correoDestino+"&nombreDestino="+global_nombreDestino+"&correoOrigen="+global_correoOrigen+"&nombreOrigen="+global_nombreOrigen+"&idNoticia="+idNoticia, onSuccess:enviarAmigoOk, onFailure:errFunc});
    	}
    
    //alert("Faltan campos por rellenar");
    /*
    var correoDestino = document.getElementById("correoAmigo").value;
    var nombreDestino = document.getElementById("nombreAmigo").value;
    var correoOrigen = document.getElementById("correoTu").value;
    var nombreOrigen = document.getElementById("nombreTu").value;

            
    if((correoDestino=="")||(nombreDestino=="")||(correoOrigen=="")||(nombreOrigen==""))
    {
        alert("Faltan campos por rellenar");
    }
    else
    {
     
    document.body.style.cursor="wait";
    new Ajax.Request("../noticiaRequest.php", {method:"post", postBody:"opcion=enviarAmigo&correoDestino="+correoDestino+"&nombreDestino="+nombreDestino+"&correoOrigen="+correoOrigen+"&nombreOrigen="+nombreOrigen+"&idNoticia="+idNoticia, onSuccess:enviarAmigoOk, onFailure:errFunc});
     
    }*/
            

    }
    
function enviarAmigoOk(t)
{
     document.body.style.cursor="";
     //hideIbox();
     //alert("Holaaa");
     //alert(myLightWindow);
     //myLightWindow.deactivate();
     //myLightWindow.deactivate.bindAsEventListener(myLightWindow)
     
	_lw1 = window.parent.document.getElementById('lightwindow_overlay');
	_lw2 = window.parent.document.getElementById('lightwindow_container');
	
	document.getElementById('error_correo').className = 'okVerdeCaja';
	document.getElementById('error_correo').innerHTML = "<span> "+info_enviado_correctamente+" <a href='javascript:_lw1.style.display=\"none\";_lw2.style.display=\"none\";' style='color:#009999;'>[x]</a> <br> </span>";
     
     //alert("Adioss");
}

var global_correoDestino="";
var global_nombreDestino="";
var global_correoOrigen="";
var global_nombreOrigen="";

function guardarValor(nombre,valor)
{
	document.getElementById(nombre).value = valor;
	
	if(nombre=="correoAmigo")	global_correoDestino=valor;
	if(nombre=="nombreAmigo")	global_nombreDestino=valor;
	if(nombre=="correoTu")		global_correoOrigen=valor;
	if(nombre=="nombreTu")		global_nombreOrigen=valor;
}

function checkFormAmigo()
{	/*
    var correoDestino = document.getElementById("correoAmigo").value;
    var nombreDestino = document.getElementById("nombreAmigo").value;
    var correoOrigen  = document.getElementById("correoTu").value;
    var nombreOrigen  = document.getElementById("nombreTu").value;
    */
    var correoDestino = global_correoDestino;
    var nombreDestino = global_nombreDestino;
    var correoOrigen  = global_correoOrigen;
    var nombreOrigen  = global_nombreOrigen;

	var _ereg_email= /^[^@ ]+@[^@ ]+.[^@ .]+$/;
	var t1=_ereg_email.test(correoDestino);
	var t2=_ereg_email.test(correoOrigen);
	
	var flag  = '- ';
	var error = '';
	
	// r@r.com
	if (correoDestino == "" || !t1){
		//_enviar_amigo_2_r = _enviar_amigo_2.replace('','');
		//_enviar_amigo_2_r = _enviar_amigo_2.replace('class="fieldForm" id="correoAmigo" value=""','class="fieldFormError" id="correoAmigo" value="'+correoDestino+'"');
		document.getElementById('correoAmigoText').className = 'text error';
		document.getElementById('correoAmigo').className = 'fieldFormError';
		error+= flag+error3;//EMAIL_ERROR_TXT
		flag='<br>- ';
	}else{
		//_enviar_amigo_2_r = _enviar_amigo_2.replace('','');
		//_enviar_amigo_2_r = _enviar_amigo_2.replace('class="fieldForm" id="correoAmigo" value=""','class="fieldForm" id="correoAmigo" value="'+correoDestino+'"');
		document.getElementById('correoAmigoText').className = 'text';
		document.getElementById('correoAmigo').className = 'fieldForm';
	}
	
	if (nombreDestino == ""){
		//_enviar_amigo_2_r = _enviar_amigo_2.replace('','');
		//_enviar_amigo_2_r = _enviar_amigo_2_r.replace('class="fieldForm" id="nombreAmigo" value=""','class="fieldFormError" id="nombreAmigo" value="'+nombreDestino+'"');
		document.getElementById('nombreAmigoText').className = 'text error';
		document.getElementById('nombreAmigo').className = 'fieldFormError';
		error+= flag+error2;//
		flag='<br>- ';
	}else{
		//_enviar_amigo_2_r = _enviar_amigo_2.replace('','');
		//_enviar_amigo_2_r = _enviar_amigo_2_r.replace('class="fieldForm" id="nombreAmigo" value=""','class="fieldForm" id="nombreAmigo" value="'+nombreDestino+'"');
		document.getElementById('nombreAmigoText').className = 'text';
		document.getElementById('nombreAmigo').className = 'fieldForm';
	}
	
	if (correoOrigen == "" || !t2){
		//_enviar_amigo_2_r = _enviar_amigo_2.replace('','');
		//_enviar_amigo_2_r = _enviar_amigo_2_r.replace('class="fieldForm" id="correoTu" value=""','class="fieldFormError" id="correoTu" value="'+correoOrigen+'"');
		document.getElementById('correoTuText').className = 'text error';
		document.getElementById('correoTu').className = 'fieldFormError';
		error+= flag+error3;//EMAIL_ERROR_TXT
		flag='<br>- ';
	}else{
		//_enviar_amigo_2_r = _enviar_amigo_2.replace('','');
		//_enviar_amigo_2_r = _enviar_amigo_2_r.replace('class="fieldForm" id="correoTu" value=""','class="fieldForm" id="correoTu" value="'+correoOrigen+'"');
		document.getElementById('correoTuText').className = 'text';
		document.getElementById('correoTu').className = 'fieldForm';
	}
	
	if (nombreOrigen == ""){
		//_enviar_amigo_2_r = _enviar_amigo_2.replace('','');
		//_enviar_amigo_2_r = _enviar_amigo_2_r.replace('class="fieldForm" id="nombreTu" value=""','class="fieldFormError" id="nombreTu" value="'+nombreOrigen+'"');
		document.getElementById('nombreTuText').className = 'text error';
		document.getElementById('nombreTu').className = 'fieldFormError';
		error+= flag+error2;//
		flag='<br>- ';
	}else{
		//_enviar_amigo_2_r = _enviar_amigo_2.replace('','');
		//_enviar_amigo_2_r = _enviar_amigo_2_r.replace('class="fieldForm" id="nombreTu" value=""','class="fieldForm" id="nombreTu" value="'+nombreOrigen+'"');
		document.getElementById('nombreTuText').className = 'text';
		document.getElementById('nombreTu').className = 'fieldForm';
	}
	
	/*
    document.getElementById("correoAmigo").value = correoDestino;
    document.getElementById("nombreAmigo").value = nombreDestino;
    document.getElementById("correoTu").value  = correoOrigen;
    document.getElementById("nombreTu").value  = nombreOrigen;
	*/
	
	
	
	if (error != "")
	{	
		document.getElementById('error_correo').style.display = '';
		document.getElementById('error_correo').className = 'errorRojoCaja';
		document.getElementById('error_correo').innerHTML = "<span> "+info_error2+": <br> </span>";
		//document.getElementById('error_correo').innerHTML = "<span> "+info_error+": <br> </span>";
		//document.getElementById('error_correo').innerHTML += error;
		
		//var _show = _enviar_amigo_1+'<div id="error2" class="errorRojoCaja" style=" margin-top:20px;">molaaaa</div>'+_enviar_amigo_2;
		//var _show = _enviar_amigo_1+_enviar_amigo_2_r;
		
		//setIBoxContent(_show);
		
		return false;			
	}
	else
	{
		document.getElementById('error_correo').style.display = '';
		document.getElementById('error_correo').className = 'infoNaranjaCaja';
		document.getElementById('error_correo').innerHTML = "<span> "+info_enviando+" <br> </span>";
		
		//var _show = _enviar_amigo_1+'<div id="error2" class="infoNaranjaCaja" style=" margin-top:20px;">enviando</div>'+_enviar_amigo_2;
		//var _show = _enviar_amigo_1+_enviar_amigo_2_r;
		
		//setIBoxContent(_show);
		
		//setIBoxContent(document.getElementById('error').innerHTML);
					
		return true;
	}
	
}