/**
*  javascript/utils.js
*
*  Module Article (js) Funciones javascript de las interfaces
*
*  Este archivo contiene variables y funciones de uso general que permiten gestionar las interfaces del sistema. 
*  Este es usado por tadas las interfaces y modulos del sistema.
*  Fecha de Actulizacion 05/05/2009
*  @author Franklin Alexander Archila <archila_franklin@hotmail.com>
*  @copyright  
*  @version 1.0
*  @access public
*  @package js
*/


/**
*  loadContentArticle(pageIni)
*
*  funcion para generar consultas de arcticulos con AJAX
*
*  Fecha de Actualizacion   05/11/2008
*  @author Franklin Alexander Archila   <archila_franklin@hotmail.com>
*  @param integer pageIni  Pagina de inicio.
* <br/> Esto es un ejemplo del uso de la funcion
* <code>
*  <script>loadContentArticle(1);<script>
* </code>
*/
function loadContentArticle(pageIni){
	campoRespuesta="contentArticle";
		 ajax=nuevoAjax();  
		 ajax.open("GET","lib/lib.php?action=contentArticlePage&pageIni="+pageIni, true);
		 ajax.onreadystatechange=function() 
		  { 	
				  if(ajax.readyState!=4)  document.getElementById(campoRespuesta).innerHTML='<img src="../imagen/indicator.gif" width="16" height="16">';
				  else  document.getElementById(campoRespuesta).innerHTML=ajax.responseText; 
		  }
		 ajax.send(null);
}

/**
*  loadContentArticle(pageIni)
*
*  funcion para generar una consulta sobre un arcticulo con AJAX
*
*  Fecha de Actualizacion   05/11/2008
*  @author Franklin Alexander Archila  <archila_franklin@hotmail.com>
*  @param integer idArt  Identificador del articulo.
* <br/> Esto es un ejemplo del uso de la funcion
* <code>
*  <script>loadArticle(23);<script>
* </code>
*/
function loadArticle2(idArt){
	campoRespuesta="articulo_"+idArt;
		 ajax=nuevoAjax();  
		 ajax.open("GET","lib2.php?action=articlePage&pageIni="+idArt, true);
		 ajax.onreadystatechange=function() 
		  { 	
				  if(ajax.readyState!=4)  document.getElementById(campoRespuesta).innerHTML='<img src="../imagen/indicator.gif" width="16" height="16">';
				  else  document.getElementById(campoRespuesta).innerHTML=ajax.responseText; 
		  }
		 ajax.send(null);
}

/**
*  loadPaginador(page)
*
*  funcion para listar los numeros de paginas del paginador con AJAX
*
*  Fecha de Actualizacion  05/11/2008
*  @author Franklin Alexander Archila  <archila_franklin@hotmail.com>
*  @param integer page  Numero de inicio de la pagina a generar.
* <br/> Esto es un ejemplo del uso de la funcion
* <code>
*  <script>loadPaginador(10);<script>
* </code>
*/
function loadPaginador(page){
	     campoRespuesta="contentPaginador";
		 ajax=nuevoAjax();  
		 ajax.open("GET","lib/lib.php?action=paginador&pageIni="+page, true);
		 ajax.onreadystatechange=function() 
		  { 	
				  if(ajax.readyState!=4)  document.getElementById(campoRespuesta).innerHTML='<img src="../imagen/indicator.gif" width="16" height="16">';
				  else  document.getElementById(campoRespuesta).innerHTML=ajax.responseText; 
		  }
		 ajax.send(null);
}

//----------------------------------------------------------------------------------------------------
function cargarIndex(id) { // url="viewMarca.php?action=1&edit=10"
		 parent.location.href="../index.php?idSeccion="+id;
}


function clicksPub(id){
    ajax=nuevoAjax();
    ajax.open("GET","../libreria/libPortal.php?action=clickPub&id="+id,true);  
    ajax.onreadystatechange=function() 
    { 	
               if(ajax.readyState==4)  {
				    numClick=document.getElementById('votosIcon').innerHTML;
					numClick++;
				 document.getElementById('votosIcon').innerHTML=numClick;
				 document.getElementById("iconVotar").setAttribute('onclick','');
				 document.getElementById("iconVotar").src="../imagen/icons/icon_favouritesOff.gif";
               }   
    }
    ajax.send(null);
}


function clicksPor(id){
    ajax=nuevoAjax();
    ajax.open("GET","../libreria/libPortal.php?action=clickPor&id="+id,true);  
    ajax.onreadystatechange=function() 
    { 	
               if(ajax.readyState==4)  {
				   
				    numClick=document.getElementById('votosIcon').innerHTML;
					numClick++;
				 document.getElementById('votosIcon').innerHTML=numClick;
				 document.getElementById("iconVotar").setAttribute('onclick','');
				 document.getElementById("iconVotar").src="../imagen/icons/icon_favouritesOff.gif";
               }   
    }
    ajax.send(null);
}
function cargarIconoEmail(id){
  document.getElementById("divEmail").style.display='block';
  
}
function enviarEmailPub(id){
	if(validarEmail(document.getElementById("email").value)){
	var datos=document.getElementById("cuerpo").value;
	enviarCorreo("","4&id="+id+"&email="+document.getElementById("email").value+"&data="+datos,""); 	cancelarEmailPub();
	}
	else{
		alert("Campo email Invalido");
		document.getElementById("email").focus();
		return;
	}
		
}
function cancelarEmailPub(){
	document.getElementById("email").value="";
	document.getElementById("cuerpo").value="";
	document.getElementById("divEmail").style.display='none';
}
function cargarIconoPrint(id){
  var ficha = document.getElementById("articulo_"+id);
  var ventimp = window.open(' ', 'popimpr');
  ventimp.document.write("<link rel='stylesheet' href='../estilos/style.css' type='text/css' />");
  ventimp.document.write( "<div class='contentArticulo'>" );
  ventimp.document.write( ficha.innerHTML );
  ventimp.document.write( "</div>" );
  ventimp.document.close();
  ventimp.print( );
  ventimp.close();
}
function cargarIconoPdf(id){
    var ventimp = window.open('../utilidades/html2fpdf/pdf.php?tipo=1&data='+id, 'popimpr');
  
}




function cargarIconoComentar(){
	document.getElementById('divComent').style.display="block";
}

function enviarComent(id){
	    ajax=nuevoAjax();
		tit=document.getElementById('titComent').value;
		des=document.getElementById('desComent').value;
		if(tit=="" || des=="")  { 
			document.getElementById('men_coment').innerHTML="Debe ingresar titulo y descripcion";  
			return; 
		}
		tipo=document.getElementById('idComent').value;
		pack="../libreria/libPortal.php";
		if(tipo!=1) pack="../../../libreria/libPortal.php";
    ajax.open("GET",pack+"?action=coment&tipo="+tipo+"&id="+id+"&titulo="+tit+"&descripcion="+des,true);  
    ajax.onreadystatechange=function() 
    { 	
               if(ajax.readyState==4)  {

				 document.getElementById('new_coment').innerHTML=ajax.responseText;
				 document.getElementById("iconComent").setAttribute('onclick','');
				 if(tipo==1)  document.getElementById("iconComent").src="../imagen/icons/icon_commentOff.gif";
				 else document.getElementById("iconComent").src="../../../imagen/icons/icon_commentOff.gif";
				 document.getElementById('divComent').style.display="none";
               }   
    }
    ajax.send(null);
}

function cerrarComent(){
	document.getElementById('titComent').value="";
	document.getElementById('desComent').value="";
	document.getElementById('divComent').style.display="none";
	document.getElementById('men_coment').innerHTML="";
}

function verDiv() {

div = document.getElementById('div1');
if(div.style.display=='none') div.style.display='';
else div.style.display='none';

}


function redimensionarImg(obj,tam){
jQuery(document).ready(function(){
jQuery('#'+obj+' img').each(function(){
jQuery(this).removeAttr("width");
jQuery(this).removeAttr("height");	
var width = jQuery(this).width();
var height = jQuery(this).height();
var new_width = 225; //nuevo tamaño 680
var new_height = 160;
if(width < height){
  new_width = 160;
  new_height = 225;
}


jQuery(this).css( {
width : new_width+'px',
height : new_height+'px'
} );

});
});
}
