var  xmlHttp;
var vllave;
var xmlDoccf;
var flag;
var ctrrowid;
var padre;
var xmlPeticioncf;
var objectid;
var error;
var extension=".aspx";
var htmlgaleria;
 function openMyModal( rowactual ) {
    
    
    var url='hveimagenindividual'+extension+'?'+rowactual+',Visor de imagenes,'+objectid+','+forma; 	   	   
	
    var strFeatures = "dialogTop=20px; dialogLeft=125px; dialogWidth=680px;" +
                            "dialogHeight=800px; center=yes; help=no; font-family:Arial;" +
                            "font-size:12px  unadorned=yes";
							
     var w = window.showModalDialog(url,"mantenimiento",strFeatures);
 };
 
 function  cargaEntidades(categoria,componente,categoriaquellama,componenteimagen)
 {
     //alert("categoria de maestro"+categoria);
   var parametros = { peticion:"E",categoria:categoria,categoriaquellama:categoriaquellama,componente:componenteimagen};
   
   var urlServer = "../objetos/leeimagen.php" 
   jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "txt",
				   async:false,
				    error: function (xhr, desc, exceptionobj) {
                                   alert(xhr.responseText);
                     },

				   success: function(data) 
	                {
					  
					 recogegaleria( data,"E",componente);
                      
					}         
                  });
	// SI ES PERIODICO
	
	if (categoria==1 || categoria==2 || categoria==3 || categoria==4 || categoria==5 || categoria==6 )
	{
	  var parametros = { peticion:"RECIENTE",categoria:categoria,siguiente:1};
  
	 jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "txt",
				   async:false,
				    error: function (xhr, desc, exceptionobj) {
                                   alert(xhr.responseText);
                     },

				   success: function(data) 
	                {
						 
				      if (categoriaquellama==7)
					   cargagaleria3(data,"imagenthumbail",categoriaquellama);
					   if (categoriaquellama==5)
					    cargagaleria3(data,"photos",categoriaquellama);
					  
					}         
                  }); 
	
	
	}

 }
 
 function  cargaEntidadesthumbs(categoria,componente,categoriaquellama,componenteimagen)  // entidades en thumbails
 {
     //alert("categoria de maestro"+categoria);
   var parametros = { peticion:"ET",categoria:categoria,categoriaquellama:categoriaquellama,componente:componenteimagen};
   
   var urlServer = "../objetos/leeimagen.php" 
   jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "txt",
				   async:false,
				    error: function (xhr, desc, exceptionobj) {
                                   alert(xhr.responseText);
                     },

				   success: function(data) 
	                {
					// alert(data);
					 recogegaleria( data,"E",componente);
                      
					}         
                  });
	// SI ES PERIODICO
	
	if (categoria==1 || categoria==2 || categoria==3 || categoria==4 || categoria==5 || categoria==6 )
	{
	  var parametros = { peticion:"RECIENTE",categoria:categoria,siguiente:1};
  
	 jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "txt",
				   async:false,
				    error: function (xhr, desc, exceptionobj) {
                                   alert(xhr.responseText);
                     },

				   success: function(data) 
	                {
						 
				      if (categoriaquellama==7)
					   cargagaleria3(data,"imagenthumbail",categoriaquellama);
					   if (categoriaquellama==5)
					    cargagaleria3(data,"photos",categoriaquellama);
					  
					}         
                  }); 
	
	
	}

 }
 
 function  cargacatalogo(categoria)
 {
   var parametros = { peticion:"C",categoria:categoria};
   
   var urlServer = "leeimagen.php" 
   jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "txt",
				   async:false,
				   success: function(data) 
	                {
                     recogecatalogo( data,categoria);
					}         
                  });

 }
 function recogecatalogo(valorretornado,categoria){ 
   if (categoria=='01')
      document.getElementById("categoria01").innerHTML=valorretornado;
    if (categoria=='02')
      document.getElementById("categoria02").innerHTML=valorretornado;
   } 
   
   
function  cargallave(llave)
 { 
   var parametros = {llave:llave};
   top.frames['workspace'].location.href='basellave.php?llave='+llave;top.frames['workspace'].location.href='basellave.php?llave='+llave;
 }

function  cargainicial(){
 var llave=jQuery("#llave").val();
  
 
 if (llave==null ||llave=="")
     { 
	 // busca la que esta por defecto
	 
	  var urlServer = "leeimagen.php" 
	  var parametros = {peticion:"DEFAULT"};
      jQuery.ajax({type: "POST", 
	  url: urlServer,
				   data: parametros,
				   dataType: "txt",
				   async:false,
				   success: function(data) 
	                {
                     recogegaleria( data,"DEFAULT");
					}         
                  });
	llave=vllave;
	 }

  
 document.getElementById("galeria2").innerHTML="INICIANDO";
 
 var parametros = {llave:llave,peticion:"G"};
  
 var urlServer = "leeimagen.php" 
   jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "txt",
				   async:false,
				   success: function(data) 
	                {
                     recogegaleria( data,"G","galeria2");
					}         
                  });

   parametros = {llave:llave,peticion:"I",categoria:1};
  
  
   jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "txt",
				   async:false,
				   success: function(data) 
	                {
                     recogegaleria( data,"I");
					}         
                  }); 
				  
	 parametros = {llave:llave,peticion:"I",categoria:2};			  
	jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "txt",
				   async:false,
				   success: function(data) 
	                {
                     recogegaleria( data,"I2");
					}         
                  }); 
	 parametros = {llave:llave,peticion:"D",tipodetalle:"DET"};			  
	jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "txt",
				   async:false,
				   success: function(data) 
	                {
                     recogegaleria( data,"D");
					}         
                  }); 
	parametros = {llave:llave,peticion:"D",tipodetalle:"DES"};			  
	jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "txt",
				   async:false,
				   success: function(data) 
	                {
                     recogegaleria( data,"DES");
					}         
                  }); 
	parametros = {llave:llave,peticion:"D",tipodetalle:"FIC"};			  
	jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "txt",
				   async:false,
				   success: function(data) 
	                {
                     recogegaleria( data,"FIC");
					}         
                  }); 
 
 /*parametros = {llave:llave,peticion:"MAP" };			  
	jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "json",
				   async:false,
				   success: function(data) 
	                {
                     recogegaleria( data,"MAP");
					}         
                  }); */
}

// carga galeria 3
function  cargagaleria3(llave,componente,galeria){
     //alert(llave+" "+componente+" "+galeria);
 if (llave!=null )
     { 
	 if (galeria==3)
	   var tipogaleria="G3";
	 if (galeria==4)
	   var tipogaleria="G4";
	if (galeria==5)
	   var tipogaleria="G5";
	if (galeria==6)
	   var tipogaleria="G6";
	   
	if (galeria==7 ||galeria==71 )
	   var tipogaleria="G7";
	 
	componente="#"+componente; 
	  		  
  // alert(llave+" "+componente+" "+galeria);
 var parametros = {llave:llave,peticion:tipogaleria}; 
 var urlServer = "../objetos/leeimagen.php"; 
    jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "txt",
				   async:false,
				   error: function (xhr, desc, exceptionobj) {
                                   alert(xhr.responseText);
                     },
				   success: function(data) 
	                { 
					recogegaleria( data,tipogaleria,componente);
					}         
                  });

 
if (galeria==5 ||galeria==4 )	
  {
   
	var urlServer = "../objetos/leeimagen.php"; 
	parametros = {llave:llave,peticion:"D",tipodetalle:"DET"};			  
	jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "txt",
				   async:true,
				   error: function (xhr, desc, exceptionobj) {
                                   alert(xhr.responseText);
                     },
				   success: function(data) 
	                {
					
                     recogegaleria( data,"DET1");
					}         
                  });
				  
    parametros = {llave:llave,peticion:"D",tipodetalle:"DES"};			  
	jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "txt",
				   async:false,
				   error: function (xhr, desc, exceptionobj) {
                                   alert(xhr.responseText);
                     },
				   error: function (xhr, desc, exceptionobj) {
                                   alert(xhr.responseText);
                     },
				   success: function(data) 
	                {
                     recogegaleria( data,"DES1");
					}         
                  }); 
				  
    parametros = {llave:llave,peticion:"TIT",tipodetalle:"TIT"};			  
	jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "txt",
				   async:false,
				    
				   error: function (xhr, desc, exceptionobj) {
                                   alert(xhr.responseText);
                     },
				   success: function(data) 
	                {
                     recogegaleria( data,"TIT");
					}         
                  });	
  // busca los videos disponibles
  //alert("llamando videos"+llave);
  parametros = {llave:llave,peticion:"VIDEOS",tipodetalle:""};			  
	jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "txt",
				   async:false,
				   success: function(data) 
	                {
                     recogegaleria( data,"VIDEOS");
					}         
                  });	
			
  }
  // es el periodico
  if (galeria=7)	
    {
  
    var parametros = {llave:llave,peticion:"MAP" };			  
	jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "json",
				   async:false,
				   success: function(data) 
	                {
                     recogegaleria( data,"GENERAL");
					}         
                  }); 
  
     
	// busca el curpo de la noticia
	 parametros = {llave:llave,peticion:"CUERPO",tipodetalle:"CUERPO"};			  
	jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "txt",
				   async:false,
				    
				   error: function (xhr, desc, exceptionobj) {
                                   alert(xhr.responseText);
                     },
				   success: function(data) 
	                {
                     recogegaleria( data,"CUERPO");
					}         
                  }); 	
   				  
				  
   // trae las fotos en grande
    tipogaleria="G7G";
    var parametros = {llave:llave,peticion:tipogaleria}; 
    
    jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "txt",
				   async:false,
				   error: function (xhr, desc, exceptionobj) {
                                   alert(xhr.responseText);
                     },
				   success: function(data) 
	                {
					 
                     recogegaleria( data,tipogaleria,componente);
					}         
                  });
  // busca los videos disponibles
  //alert("llamando videos"+llave);
  parametros = {llave:llave,peticion:"VIDEOS",tipodetalle:""};			  
	jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "txt",
				   async:false,
				   success: function(data) 
	                {
                     recogegaleria( data,"VIDEOS");
					}         
                  });	
			
  }
  
  if (galeria=71)	
    {
    // trae las fotos en grande
    tipogaleria="G7G";
    var parametros = {llave:llave,peticion:tipogaleria}; 
    
    jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "txt",
				   async:false,
				   error: function (xhr, desc, exceptionobj) {
                                   alert(xhr.responseText);
                     },
				   success: function(data) 
	                {
					 
                     recogegaleria( data,"G71",componente);
					}         
                  });
   
  }
 } 
}

function mapa(){ 
     
    var urlServer = "leeimagen.php";
    var llave=jQuery("#llave").val();
    var parametros = {llave:llave,peticion:"MAP" };			  
	jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "json",
				   async:false,
				   success: function(data) 
	                {
                     recogegaleria( data,"MAP");
					}         
                  }); 


}
function video(){ 

    var urlServer = "leeimagen.php";
    var llave=jQuery("#llave").val();
	 
	var parametros = {llave:llave,peticion:"VIDEO",categoria:8};
    			  
	jQuery.ajax({type: "POST", 
		 url: urlServer,
				   data: parametros,
				   dataType: "txt",
				   async:false,
				   success: function(data) 
	                {
                     recogegaleria( data,"VIDEO");
					}         
                  }); 


}
function recogegaleria(valorretornado,tipo,componente){ 
   var titulo;
   if (tipo=='G')
   {
     
     document.getElementById(componente).innerHTML=valorretornado;
     jQuery('#galeria2').val(valorretornado);
	 
    //sfHover;
	if (window.attachEvent) window.attachEvent("onload", sfHover);
   }
   if (tipo=='G3')
   {
     
       
    // document.getElementById("galeria3").innerHTML=valorretornado;
      jQuery(componente).html(valorretornado);
	  jQuery('.thumbs').piroBox({
			border: 10,
			borderColor : '#222',
			mySpeed: 700,
			bg_alpha: 0.3,
			cap_op_start : 0.4,
			cap_op_end: 0.8,
			pathLoader : '#000 url(css/ajax-loader.gif) center center no-repeat;',
			gallery : '.gallery_in li a',
			gallery_li : '.gallery_in li',
			next_class : '.next_in',
			previous_class : '.previous_in'
	});
	jQuery('.thumbs').piroBox({

<!--David this OPTIONS are for outside box navigation-->

			border: 1,
			mySpeed: 700,
			borderColor : '#444',
			bg_alpha: 0.5,
			cap_op_start : 0.4,
			cap_op_end: 0.8,
			pathLoader : '#000 url(css/ajax-loader.gif) center center no-repeat;',
			gallery : '.gallery li a',
			gallery_li : '.gallery li',
			single : '.single  a',
			next_class : '.next',
			previous_class : '.previous'
	});
	  
   }
   
   if (tipo=='G4')
   {
     
     
	 // componente="#"+componente;
    // alert(valorretornado);
      jQuery(componente).html(valorretornado);
	  
	  	// We only want these styles applied when javascript is enabled
			jQuery('div.navigation').css({'width' : '300px', 'float' : 'left'});
			jQuery('div.content').css('display', 'block');

			// Initially set opacity on thumbs and add
			// additional styling for hover effect on thumbs
			var onMouseOutOpacity = 0.67;
				// We only want these styles applied when javascript is enabled
			jQuery('div.navigation').css({'width' : '300px', 'float' : 'left'});
			jQuery('div.content').css('display', 'block');

			// Initially set opacity on thumbs and add
			// additional styling for hover effect on thumbs
			var onMouseOutOpacity = 0.67;
			jQuery('#thumbs ul.thumbs li').css('opacity', onMouseOutOpacity)
				.hover(
					function () {
						jQuery(this).not('.selected').fadeTo('fast', 1.0);
					}, 
					function () {
						jQuery(this).not('.selected').fadeTo('fast', onMouseOutOpacity);
					}
				);

			jQuery(document).ready(function() {
				// Initialize Advanced Galleriffic Gallery
				var galleryAdv = jQuery('#gallery').galleriffic('#thumbs', {
					delay:                  2000,
					numThumbs:              12,
					preloadAhead:           10,
					enableTopPager:         true,
					enableBottomPager:      true,
					imageContainerSel:      '#slideshow',
					controlsContainerSel:   '#controls',
					captionContainerSel:    '#caption',
					loadingContainerSel:    '#loading',
					renderSSControls:       true,
					renderNavControls:      true,
					playLinkText:           'Iniciar Slide ',
					pauseLinkText:          'Detener Slide ',
					prevLinkText:           '&lsaquo; Previous Photo',
					nextLinkText:           'Next Photo &rsaquo;',
					nextPageLinkText:       'Next &rsaquo;',
					prevPageLinkText:       '&lsaquo; Prev',
					enableHistory:          true,
					autoStart:              false,
					onChange:               function(prevIndex, nextIndex) {
						jQuery('#thumbs ul.thumbs').children()
							.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
							.eq(nextIndex).fadeTo('fast', 1.0);
					},
					onTransitionOut:        function(callback) {
						jQuery('#caption').fadeTo('fast', 0.0);
						jQuery('#slideshow').fadeTo('fast', 0.0, callback);
					},
					onTransitionIn:         function() {
						jQuery('#slideshow').fadeTo('fast', 1.0);
						jQuery('#caption').fadeTo('fast', 1.0);
					},
					onPageTransitionOut:    function(callback) {
						jQuery('#thumbs ul.thumbs').fadeTo('fast', 0.0, callback);
					},
					onPageTransitionIn:     function() {
						jQuery('#thumbs ul.thumbs').fadeTo('fast', 1.0);
					}
				});
			});
			
   }
   
// GALERIA 5 PARA LOS ARTICULOS

 if (tipo=='G5')
   {
      // componente="#"+componente;
      //alert(valorretornado);
      jQuery(componente).html(valorretornado);
	  jQuery('#photos').galleryView({
				panel_width: 500,
				panel_height: 350,
				frame_width: 75,
				frame_height: 75
			});
	  
 }
 
 if (tipo=='G7' ) {
 jQuery(componente).html(valorretornado);  
 //alert("componente:"+componente+" "+valorretornado);
 var $fotoPrev = jQuery('#fotonavwrapper img.prev'),//prev button
								$fotoNext = jQuery('#fotonavwrapper img.next');//next button

							jQuery('.fotonav').serialScroll({
								items:'li',
								prev:'#fotonavwrapper img.prev',
								next:'#fotonavwrapper img.next',
								duration:700,
								step:3,
								cycle:false,
								onBefore:function(e, elem, $pane, $items, pos ){
									$fotoPrev.add($fotoNext).fadeIn();
									if ( pos == 0 ) {
										$fotoPrev.fadeOut();
									} else if( pos == $items.length - 1 ) {
										$fotoNext.fadeOut();
									}
								}
							});
 
 jQuery('.ademasPagesContainer').serialScroll({
							items:'div',
							axis: 'y',
							prev:'.caja-ademas img.prev',
							next:'.caja-ademas img.next',
							duration:700,
							step:5,
							cycle:false
						});
 }  
 if (tipo=='G7G'){ 
     jQuery('#fotosgrandes').html(valorretornado);  
	// alert(valorretornado);
	 jQuery('.fotopage').serialScroll({
							items:'li',
							navigation:'#fotonavwrapper li',
							duration:0
						});
	 
	 }  
  if (tipo=='G71'){ 
     jQuery('#fotosgrandes71').html(valorretornado);  
	// alert(valorretornado);
	 jQuery('.fotopage').serialScroll({
							items:'li',
							navigation:'#fotonavwrapper li',
							duration:0
						});
	 
	 }     	 
   if (tipo=='E')
   {
      //alert("retorno "+valorretornado); 
     componente="#"+componente;
    jQuery(componente).html(valorretornado); 
	
	   }
   
   
    if (tipo=='I') document.getElementById("imagen1").innerHTML=valorretornado; 
    if (tipo=='I2') document.getElementById("imagen2").innerHTML=valorretornado; 
    if (tipo=='D') document.getElementById("detallellave").innerHTML=valorretornado; 
	if (tipo=='DET1') jQuery('#parte2').html(valorretornado); 
	if (tipo=='DES1') jQuery('#parte1').html(valorretornado);
	if (tipo=='CUERPO') jQuery('#noticiaperiodico').html(valorretornado);
	
	if (tipo=='GENERAL')
	  {
	      jQuery('#titulonoticia').html('<h1 class="titulo">'+valorretornado["titulo"]+'</h1>');
		  jQuery('#autor').html("publicado por:"+valorretornado["autor"]);
		  jQuery('#fechapublicacion').html(valorretornado["fecha"]);
    	 
	  }
	if (tipo=='G6') 
	{
	//alert(valorretornado);
	jQuery('#mooflow').html(valorretornado);
	var mf = new MooFlow(jQuery('mooflow'), {
				useSlider: true,
				useAutoPlay: true,
				useCaption: true,
				useResize: true,
				useMouseWheel: true,
				useKeyInput: true,
				useViewer: true
			});
	}
	if (tipo=='VIDEOS') jQuery('#videos').html(valorretornado);
	
	if (tipo=='TIT')
	 {
   	  jQuery('#titulotop').html('<p class="titulo-secundario">'+valorretornado+'</p>');
	  jQuery('#titulobotton').html( '<p class="titulo-secundario">'+valorretornado+'</p>');
	
	}
	if (tipo=='FIC')  document.getElementById("ficha").innerHTML=valorretornado;
    if (tipo=='DEFAULT')  vllave=valorretornado; 
    if (tipo=='DES')
    {
   
    document.getElementById("titulo").innerHTML=valorretornado;
	titulo=valorretornado;
   }
   
   
   if (tipo=='MAP')  {
     titulo=valorretornado["descripcion"]; 
     var html1= '<div id="map1"  style="width: 500px; height: 500px;"></div> <div class="geo" title="'+titulo+'">';
     html1+= '<abbr class="latitude" title="'+valorretornado["latitud"]+'"> </abbr> <abbr class="longitude" title="'+valorretornado["longitud"]+'"> </abbr> ';
	 //document.getElementById("mapa").innerHTML=html1;
	  jQuery('#mapa').show('slow'); 
	  jQuery('#video').hide('slow');
     jQuery('#mapa').html(html1);
	 if (valorretornado["longitud"])
	   {
		 jQuery("#map1").googleMap(valorretornado["latitud"], valorretornado["longitud"], 10, {
			controls: ["GSmallMapControl", "GMapTypeControl"],
			markers: jQuery(".geo")
		  });
	   }
	}
	
	if (tipo=='VIDEO')  {
	  jQuery('#mapa').hide('slow');
	  jQuery('#video').show('slow');
	  
	 var pos=valorretornado.indexOf("XX1");
	 
	  valorretornado=valorretornado.substring(0,pos);
	   
	  so.addParam('flashvars','&file='+valorretornado+'&autostart=true&fullscreen=true');
      so.write('player');
 
	 }

}

function muestraVideo(nombrevideo){ 
 jQuery('#photos').hide('slow');
 jQuery('#video').show('slow');
  jQuery('#volergaleria').show('slow');
 so.addParam('flashvars','&file='+nombrevideo+'&autostart=true&fullscreen=true');
 so.write('player');
}

function muestragaleriadenuevo(){ 
 jQuery('#video').hide('slow');
 jQuery('#photos').show('slow');
 jQuery('#volergaleria').hide('slow');
  
}
function  cargaleria1php(llave,categoria)
 { 
   var parametros = {llave:llave};
   
 // alert("llave"+llave+" categoria"+categoria);
   //top.frames[''].location.href='galeria3.php?llave='+llave;
   if (categoria=='01')
      window.open('servicios_imagenes.php?llave='+llave,'mywindow');
   if (categoria=='02')
      window.open('productos_imagenes.php?llave='+llave,'mywindow');
	if (categoria=='03')
      window.open('trabajos_imagenes.php?llave='+llave,'mywindow');  
 }
 
  function  cargaleria3php(llave)
 { 
   var parametros = {llave:llave};
   //top.frames[''].location.href='galeria3.php?llave='+llave;
   window.open('galeria3.php?llave='+llave,'mywindow','width=900,height=700');
 }
 function  cargaleria4php(llave)
 { 
   var parametros = {llave:llave};
   //top.frames[''].location.href='galeria3.php?llave='+llave;
   window.open('galeria4.php?llave='+llave,'mywindow','width=900,height=700');
 }
 
 
 function regreso(){ 
  document.location.href="../index.php";
  return true;
} 