miajax = new isiAJAX(); 

function abrirPopup(direccion){ 
     var opciones = "fullscreen=" + 0 + 
                 ",toolbar=" + 0 + 
                 ",location=" + 0 + 
                 ",status=" + 0 + 
                 ",menubar=" + 0 + 
                 ",scrollbars=" + 0 + 
                 ",resizable=" + 0 + 
                 ",width=" + 505 + 
                 ",height=" + 360 + 
                 ",left=" + 300 + 
                 ",top=" + 400; 
     var ventana = window.open(direccion,"Reenviar",opciones); 
 
}




function inicializar()
{	
	miajax.Cargador(false, 'seccionCargadorLoMas');
}


var imagen="";
var numAleatorio="";
var estaAbierto=true;
function enviar_comentario()
{
	miajax = new isiAJAX();
	
	var formulario=document.getElementById("formulario");
	var mensaje="";
	formatoOk=true;
	
	if (!isName(document.getElementById('nombre').value)){
		
		mensaje += feedBack("@@310@@",false,"Nombre")+"\n";
		formatoOk=false;
	}

		if (!isEmail(document.getElementById('email').value) 
	&& document.getElementById('email').value != ""){
		
		mensaje += feedBack("@@509@@",false)+"\n";
		formatoOk=false;
	}
	
	
	if (document.getElementById('email').value == ""){
		
		mensaje += feedBack("@@310@@",false,"Email")+"\n";
		formatoOk=false;
	}
	
	if (document.getElementById('web').value  != '' && !isUrl(document.getElementById('web').value))
	{				
		mensaje += feedBack("@@314@@",false,"Pagina web")+"\n";
		formatoOk= false;
		
	}
	
	
	if (document.getElementById('letraVal').value == ""){
		
		mensaje += feedBack("@@511@@",false)+"\n";
		formatoOk=false;
	}
	
	
	
	if (!isCommentary(document.getElementById('comentario').value)
	&& document.getElementById('comentario').value != ""){
		
		mensaje += feedBack("@@313@@",false,"Comentario")+"\n";
		formatoOk=false;
	}
	
	if (document.getElementById('comentario').value == ""){
		
		mensaje += feedBack("@@310@@",false,"Comentario")+"\n";
		formatoOk=false;
	}
	
	
	
	if (document.getElementById('clausula').checked != true){
		
		mensaje += feedBack("@@508@@",false)+"\n";
		formatoOk=false;
	}
	
	imagen=document.getElementById("imagenSeguridad");
	if (formatoOk == true){

		datos = miajax.DataForm($('formulario'));		
			//miajax.Form('formulario', 'div_formulario');
			miajax.Request({
				url: formulario.action,
				method: 'POST',	
				param: datos,
				onOK: validarContenidoFormulario			
			 });

	}else{

		imagen.src=RAIZ_SITIO+"includes/generar_imagen_seguridad.php5?v="+numAleatorio;
		alert(mensaje);			
	};
	 
	 
	 
};

	var validarContenidoFormulario= function(ajax,data){
	  var numAleatorio=aleatorio(0,1000000);
	  if(ajax.responseText==1){
		feedBack("@@513@@",true);
		
			if(document.getElementById('recDato').checked == false)
			{
				document.getElementById('letraVal').value="";
				document.getElementById('comentario').value="";
				imagen.src=RAIZ_SITIO+"includes/generar_imagen_seguridad.php5?v="+numAleatorio;
			}
			else
			{
				document.getElementById('comentario').value="";
				document.getElementById('letraVal').value="";
				imagen.src=RAIZ_SITIO+"includes/generar_imagen_seguridad.php5?v="+numAleatorio;
			}
			document.getElementById('formulario').action=RAIZ_SITIO+"noticia_comentario_cookie.php5";
			miajax.Form('formulario');
			document.getElementById('formulario').action=RAIZ_SITIO+"noticia_ampliada.php5";
		}else{
		  feedBack("@@372@@",true);
		  imagen.src=RAIZ_SITIO+"includes/generar_imagen_seguridad.php5?v="+numAleatorio;
	      document.getElementById('letraVal').value ="";
		  }
	}


function mostrar_formulario(accion) {
	
	if(estaAbierto==false){
		var hiper=document.getElementById('mostrarFormulario');
		
		var contenedor = document.getElementById('div_formulario');
		contenedor.style.display ='';
		hiper.className = 'active';
		estaAbierto=true;
	}else if(accion==2){
	   ocultar_formulario();
	}
}

function ocultar_formulario() {	
	
	document.getElementById('letraVal').value="";
	document.getElementById('comentario').value="";
	
	var div = document.getElementById('div_formulario');
	var hiper=document.getElementById('mostrarFormulario');
	
	div.style.display='none';
	hiper.className = 'none';
	hiper.onclick = 'javascript:mostrar_formulario(2);';
	estaAbierto=false;
}

function aleatorio(inferior,superior){
var numPosibilidades = superior - inferior
var aleat = Math.random() * numPosibilidades
aleat = Math.round(aleat)
return parseInt(inferior) + aleat
} 


function paginarAjax(inicio, cantidad)
{		
	document.getElementById("inicio").value = inicio;
	document.getElementById("cantidad").value = cantidad;	
	buscarComentarios();
}
function buscarComentarios()
{
		miajax.Form('formBuscarComentarios','comentarios');
}

function incrementarVotacionEncuestaNot(contEnc)
{
	var numsR = document.getElementById("frm_encuesta_"+contEnc).elements.length - 1;
	var auxCont = 0;
	var codRespuesta = 0;
	
	
	//Cual es la opcion seleccionada?
	for(i=0; i <= numsR; i++)
	{	
		if( document.getElementById("frm_encuesta_"+contEnc)[i].type=="radio" )
		{
			if( document.getElementById("frm_encuesta_"+contEnc)[i].checked == true )
			{
			   codRespuesta = document.getElementById("frm_encuesta_"+contEnc)[i].value; 			 
			   break;		   
			}

		}

    }
	
	//Se ha seleccionado una opcion?
	if(codRespuesta != 0)
	{		
		miajax.Request({
			url: RAIZ_SITIO+"gestorEncuestasNoticias.php5",
			method: "POST",
			indiceLimit: contEnc,
			//param: "resEncuesta="+codRespuesta+"&encCodigo="+encCodigo,
			param: miajax.DataForm($("frm_encuesta_"+contEnc))+"&indLimite="+contEnc,
			onOK: pintarEncuestaEncuestaNot					
		});
	}
	else
	{
		feedBack("@@324@@",true,"una opci\u00F3n");
	}		
}
var pintarEncuestaEncuestaNot = function(ajax,data)
{
	var script = ajax.responseText.split("/*limitescript_"+data.indiceLimit+"*/");
	eval(script[1]);
	
	if(typeof loader != "undefined")
		$(loader).style.display='none';	
};

function changeImage(){
 var numAleatorio=aleatorio(0,1000000);
document.getElementById('imagenSeguridad').src = RAIZ_SITIO+'includes/generar_imagen_seguridad.php5?v='+numAleatorio;
}
