// JavaScript Document

var nComment = 0;
var contColOriginal = 0;
var tipoComment = 0;

$(function(){

				$('#lblSendMail').click(function() {
						$('#dialogSendFriend').removeClass('ocultaFormulario');
						$('#dialogSendFriend').addClass('muestraFormulario');
						$('#dialogSendFriend').dialog('open');

						return false;
				});				

				//   ******************* S E N D   M A I L **************

				$("#dialogSendFriend").dialog({
					bgiframe: true,
					autoOpen: false,
					width:310,
					height: 390,
					modal: true,
					show:'slide',
					zIndex: 1000,
					buttons: {
						    'Enviar': function() {
									if (validatorFormSendMail()) {
									    var Vars = "De="+$("#txtDe").val()+"&Para="+$("#txtPara").val()+"&EMailPara="+$("#txtEMailPara").val()+
										            "&ComentarioPara="+$("#txtComentarioPara").val()+"&URL="+document.location.href+"&Id="+pIdNota+"&Tipo=1";
										getXML("http://www.diariopresente.com.mx/php/sendMail.php?"+Vars,x=6,800);
										$(this).dialog('close');
									}
						},
						'Cerrar': function() {
							$(this).removeClass('muestraFormulario');
							$(this).addClass('ocultaFormulario');
							$(this).dialog('close');
						    //allFields.val('').removeClass('ui-state-error');
						}
					}
				});

				//   ******************* C O M M E N T **************
				$("#dialogForm").dialog({
					bgiframe: true,
					autoOpen: false,
					width:310,
					height: 340,
					modal: true,
					show:'slide',
					zIndex: 999,
					buttons: {
						    'Enviar': function() {
									if (validatorFormNewAcount()) {
									    var Vars = "";
										switch(tipoComment){
											   case 0:
									    			Vars = "Id="+pIdNota+"&User="+$("#txtNombre").val()+"&EMail="+$("#txtEMail").val()+"&Comentario="+$("#txtComentario").val()+"&Tipo=1";
													break;
											   case 1:
												    Vars = "Id=-1&User="+$("#txtNombre").val()+"&EMail="+$("#txtEMail").val()+"&Comentario="+$("#txtComentario").val()+"&Tipo=3";
													break;
										}
													
										getXML("http://www.diariopresente.com.mx/php/setComment.php?"+Vars,x=5,888);
										$(this).dialog('close');
									}
						},
						'Cerrar': function() {
							$(this).removeClass('muestraFormulario');
							$(this).addClass('ocultaFormulario');
							$(this).dialog('close');
						   // allFields.val('').removeClass('ui-state-error');
						}
					}
				});


});

function setFontSize(){
	      if (fontInit==0) {
		      $('#bodyNota').css({'font-size':'125%'});
			  fontInit = 1;
		  	  setAjustaNota1();
			  
		  } else {
			     $('#bodyNota').css({'font-size':'100%'});
			     $("#c1IzquierdoNota").height(contColOriginal);
				 fontInit = 0;
		  }

}

function setAjustaNota1(){
		var K = $("#encabNota").height();
		var L = $("#contenedorNota").height();
		var M = $("#cComentarios").height();
		var total = K+L+M+100;
		if (total<=contColOriginal){
			total = contColOriginal; 
		}
		$("#c1IzquierdoNota").height(total);
		
		
}

function getFormComment(){
				$('#lblRegInit').click(function() {
						$('#dialogForm').removeClass('ocultaFormulario');
						$('#dialogForm').addClass('muestraFormulario');
						$('#txtNombre').focus();
						$('#dialogForm').dialog('open');
						$('#txtNombre').focus();
						tipoComment = 1;
						return false;
				});				

}
function getFormulario(){
				$('#lblReg').click(function() {
						$('#dialogForm').removeClass('ocultaFormulario');
						$('#dialogForm').addClass('muestraFormulario');
						$('#txtNombre').focus();
						$('#dialogForm').dialog('open');
						$('#txtNombre').focus();
						tipoComment = 0;
						return false;
				});				

}


function getNotaPrincipal(xml)
{       
		var init=0;
		var MMM =0;
		
		var c1IzqHtml = "";
		var cURL = "";
        var xC = "";

		var arrMedia = new Array(15);
		for(var i=0;i<5;i++) { arrMedia[i]=new Array(5); }
		if ($("status",xml).text() == "2") return;
		//document.getElementById("c1Izquierdo").innerHTML = "";
		var i = 0;
		$("nota",xml).each(function(id) {
					var nota = $("nota",xml).get(id);

					    $("#tituloNota").html($("titulo",nota).text());
						$("#detalleNotaPrincipal").html($("intronota",nota).text());
						$("#reportero").html($("reportero",nota).text());
						$("#lugar").html($("lugar",nota).text()+ ", "+$("fecha",nota).text()+" "+$("hora",nota).text());
						$("#agencia").html($("agencia",nota).text());
						$("#cuerponota").html($("cuerponota",nota).text());

						var c="";
						for (var k=0;k<15;k++){
							 if ($("idimg"+k,nota).text()>0){
                				c += "<img id='notaImgPrincipal' class='notaImgPrincipal2' src='http://www.diariopresente.com.mx/images/"+$("root"+k,nota).text()+"' alt='"+$("alt"+k,nota).text()+"' />";
                        		c += "<p id='pINP' class='pINP2'>"+$("comment"+k,nota).text()+"</p>";
							 }
						}
						
						$("#cImgNotaPrincipal").html(c);
						c="";
							
					    for (var k=0;k<15;k++){
						    if ($("idmedia"+i,nota).text()>0){
								arrMedia[i][0] = $("archivo"+i,nota).text();				
								arrMedia[i][1] = $("imagen"+i,nota).text();
								arrMedia[i][2] = $("tipo"+i,nota).text();
								arrMedia[i][3] = $("duracion"+i,nota).text();
								arrMedia[i][4] = $("nombrecontenedor"+i,nota).text();
								arrMedia[i][5] = $("titulom"+i,nota).text();
								arrMedia[i][6] = $("descripcionm"+i,nota).text();
								c += "<p id='"+arrMedia[i][4]+"'></p>";
								c += "<p class='tMedia2' >"+arrMedia[i][5]+"</p>";
								c += "<p class='dMedia2' >"+arrMedia[i][6]+"</p>";
							i++;
							}
						}
											
											
					   $("#vMedia2").html(c);
					   c="";



					for (var k=0;k<15;k++){
						 if ($("idnotanr"+k,nota).text()!=0){
							 c += "<li class='liNotaRelPrincipal2'>";
							 var x1 = "";
							 if ($("idgrupo"+k,nota).text()!=1){
							    x1 += "<strong>"+$("nombregn"+k,nota).text()+" </strong>";
							 }
							 MMM = $("idgrupo"+k,nota).text();
							 if (MMM==-1){
								c += "<a href=javascript:abrirVentana("+$("idnotanr"+k,nota).text()+") class='aFotoGal' >"+$("nombregn"+k,nota).text()+": "+$("titulonr"+k,nota).text()+"</a> ";
							}else if (MMM==-2){
								var enlace = "javascript:abrirGrafico('"+$("maing"+k,nota).text()+"',"+$("ancho"+k,nota).text()+","+$("alto"+k,nota).text()+")";
								c += "<a href="+enlace+"  class='aFotoGal' >"+$("nombregn"+k,nota).text()+": "+$("titulonr"+k,nota).text()+"</a> ";
							}else if (MMM==-3){
								var enlace = "javascript:abrirEncuesta("+$("idnotanr"+k,nota).text()+")";
								c += "<a href="+enlace+"  class='aFotoGal' >"+$("nombregn"+k,nota).text()+": "+$("titulonr"+k,nota).text()+"</a> ";
							 }else{
							 		//c += "<a href='http://www.diariopresente.com.mx/tabasco/"+$("idnotanr"+k,nota).text()+"/' class='linkNota'>"+x1+$("titulonr"+k,nota).text()+"</a> ";
									cURL = getURLIdNotaWeb("section",$("seccion_nr_u"+k,nota).text(),$("idnotanr"+k,nota).text(),$("tit_nr_hidde"+k,nota).text());

							 		//c += "<a href='http://www.diariopresente.com.mx/section/"+$("seccion_nr_u"+k,nota).text()+"/"+$("tit_nr_hidde"+k,nota).text()+"-t"+$("idnotanr"+k,nota).text()+"/' class='linkNota'>"+x1+$("titulonr"+k,nota).text()+"</a> ";

							 		c += "<a href='"+cURL+"' class='linkNota'>"+x1+$("titulonr"+k,nota).text()+"</a> ";
							 }
						     c += "</li>";
		
						  }
					 }

					   $("#ulNotasPrincipales2").html(c);
					   c="";
        
					xC = "";
					for (var k=0;k<100;k++){
						 if ($("idcomment"+k,nota).text()>0){
							 xC += "<li style='list-style:none;'>";
							 xC += "<div>";
							 xC += "<img class='commentImg' src='http://www.diariopresente.com.mx/images/core/comentario_min_0.png'/>";
							 xC += "<div class='commentContainerInto'>";

							 xC += "<div class='commentContainerIntoPlus'>";
							 xC += "<a class='commentUser'>"+$("usuario"+k,nota).text()+";  </a>";
							 xC += "<a class='commentFecha'>"+$("fcomment"+k,nota).text()+"</a>";
							 xC += "</div>";
            				 xC += "<p class='commentComent'>"+$("comentario"+k,nota).text()+"</p>";
						     //c1IzqHtml += "<a class='aHora'>"+$("hora"+k,nota).text()+" </a>";
							 xC += "</div>";
							 xC += "</div>";
						     xC += "</li>";
							 nComment++;
		
						  }
						  
					 }


		});
		$("#uComentario").html(xC);
		getXML("http://www.diariopresente.com.mx/php/getMedia.php","x=0",2);
		getXML("http://www.diariopresente.com.mx/php/getColumns.php?IdColumna=0&Tipo=2","x=7",5);

		getXML("http://www.diariopresente.com.mx/php/getPubRight.php?ref=-1","x=1",9);
		
		for (var j=0;j<i;j++){
			getMediaPlus(arrMedia[j][0],arrMedia[j][1],arrMedia[j][2],arrMedia[j][3],arrMedia[j][4],"320","290");
		}
		ajustaDivContenedor2();
/*		if (altoDef==""){
           altoDef=$('#base').html();
		}
*/

// alert(1);

}

function ajustaDivContenedor2(){

		  getFormulario();
		  getFormComment();
		  
		  $('#initializing').remove();
			//alert("Contenedor " + $("#c1IzquierdoNota").height());
			//alert("Largo depues de consulta " + largo_bdp);
		  if ($("#c1IzquierdoNota").height() < largo_bdp) {
			  $("#c1IzquierdoNota").height(largo_bdp);
		  }
		  $('#base').css({'visibility':'visible'});
		  contColOriginal = $('#c1IzquierdoNota').height();
		  
		  getFormComment();

		    
}

function printHTML(){
	
	document.location.href ="http://www.diariopresente.com.mx/http://www.diariopresente.com.mx/php/printHTML.php?IdNota="+pIdNota;

}

function getConfigNota(xml){
          var sHTML  = "";
	      var i = 1;
		  var nota;
//		  alert(1);
		  
		  largo_bdp = 0;
		  if ($("status",xml).text() == "2") return;
		  	  $("response",xml).each(function(id) {
			  	nota = $("response",xml).get(id);
					largo_bdp = parseInt($("largo_contenedor1_nota",nota).text());
					//getXML("http://www.diariopresente.com.mx/php/getMenuPrincipal.php","x=1",10);	
					getXML("http://www.diariopresente.com.mx/php/getNotaPrincipal.php?IdNota="+pIdNota+"&Tipo=1",x=4,999);
					//alert(largo_bdp);
					
			  });

}

function tableHighlightRow() {
  if (document.getElementById && document.createTextNode) {
    var tables=document.getElementsByTagName('table');
    for (var i=0;i<tables.length;i++)
    {
      //if (tables[i].className=='MyTabla' || tables[i].className=='MyTabPaises') {
         var trs=tables[i].getElementsByTagName('tr');
         for (var j=0;j<trs.length;j++) {
              if (trs[j].parentNode.nodeName=='TBODY' || trs[j].parentNode.nodeName=='tbody') {
                  trs[j].onmouseover=function(){this.className='hilight';return false}
                  trs[j].onmouseout=function(){this.className='';return false}
             }
             if (trs[j].parentNode.nodeName=='THEAD' || trs[j].parentNode.nodeName=='thead') {
                 trs[j].className ='hilightHG';
             }
        }
      //}
    }
  }
}


