// VARIABLES --------------------------------------------------END

// AJAX ---------URLGET---------------------------

  function urlget(aval)
  {
    aval1=aval;
    var url1 = "proxy.aspx?url=http://www.servir.net/2010/imagesdata.php";
    var url2 = directorio;
    var date2 = todate;
    if(document.getElementById("numima")!=null){numimages=document.getElementById("numima").value;}
    
    if (directorio.indexOf("goesfull") >= 1){var sumi = "?direc1="+url2+"&fecha="+date2;}
    else{var sumi = "?direc="+url2+"&fecha="+date2;}
    url = url1 + sumi;
    url12 = "proxy.aspx?url=" + wwwinfo;
    // url12 = "proxy.aspx?url=http://www.servir.net/servir2/index2.php?option=com_content&task=view&id=74";
     loaderson("block");    
    //groundOverlay2.show();
    
    request(url);
    request1(url12);
  }
// AJAX ---------REQUEST---------------------------
//
  function request(urla) 
  {
  var preloader = document.getElementById('preloader');
  if (window.XMLHttpRequest)
    http_request = new XMLHttpRequest();
  else
    http_request = new ActiveXObject("Microsoft.XMLHTTP");
    http_request.onreadystatechange = function()
    {
        if(http_request.readyState==1)
          {
          
    //preloader.style.background = "url('loadinga.gif') no-repeat";
          }
            else
          {
      
    //preloader.style.background = "none";
    handle_json(http_request)
          }
      };
    http_request.open("GET", urla, true);
    http_request.send(null);
  }
  
  function request1(urla) 
  {
  var preloader = document.getElementById('preloader');
  if (window.XMLHttpRequest)
    http_request1 = new XMLHttpRequest();
  else
    http_request1 = new ActiveXObject("Microsoft.XMLHTTP");
    http_request1.onreadystatechange = function()
    {
        if(http_request1.readyState==1)
          {
          
    //preloader.style.background = "url('loadinga.gif') no-repeat";
          }
            else
          {
      
    handle_http(http_request1)
          }
      };
    http_request1.open("GET", urla, true);
    http_request1.send(null);
  }
  
  

// AJAX ---------LEER PHP---------------------------
  function handle_json(http_request) 
  {
    if (http_request.readyState == 4) 
      {
      var arayson=http_request.responseText+"\"\"";
      namefile.splice(0,tamano);
      namefile = arayson.split(",");
      tamanon = namefile.length;
      tamano=tamanon-1;
      }
  total();
  }
  
//... Texto desde Joomla ..........---//

function handle_http(http_request) 
  {
     if (http_request.readyState == 4) 
      {
      textx1=http_request.responseText;
      cadena1="";
      cadena2="";
      cadena3="";
      httpx="http://www.servir.net/servir2/";
      httpx2="http://www.servir.net/";
      httpx2i="http://www.servir.net/servir2/index2.php";
      textx1a=textx1.replace(/(<script)([^<]+)(<\/script>)/g,"");
      textx1b=textx1a.replace(/(<title>)([^<]+)(<\/title>)/g,"");
      textx2=textx1b.replace(/(mce([^>]+)\")/ig,"");
      textx3=textx2.replace(/<td/ig,"<span").replace(/<\/td/ig,"</span");
      textx4=textx3.replace(/(<t|<\/t)([abh]([^>]*)>)/ig,"");
      textx5=textx4.replace(/(target=([^>]+))/ig,"");
      //textx4a=textx4.replace(/(class=([^>]+))/ig,"");
      // Link en web
      //textx6=textx5.replace(/(href=\"http:\/\/www.servir([^>]+)\")/ig,"target=_top $1");
      //textx7=textx6.replace(/(href=\")(\?option([^>]+)\")/ig,"$1"+httpx+"$2 target=_top");
      // Link en DIV
      textx6=textx5.replace(/(href=\")(http:\/\/www.servir.net\/)(([^>]+)[a-z|0-9])/ig,"href=\"javascript:request1(\'proxy.aspx?url="+httpx2+"$3\')");
      textx7=textx6.replace(/(href=\")(\?option([^>]+)[a-z|0-9])/ig,"href=\"javascript:request1(\'proxy.aspx?url="+httpx2i+"$2\')");
      //
      textx8=textx7.replace(/(href=\"|src=\")(?!http)(?!javascript)(([^>]+)\")/ig,"$1"+httpx2+"$2 rel=\"lightbox\"");
      textx9=textx8.replace(/(href=\")(?!http:\/\/www.servir.net)(?!http:\/\/servir.net)(?!javascript)(([^>]+)\")/ig,"href=\"$2 target=_new");
      textx10=textx9.replace(/(<h([^>]+)>)/ig,"");
      textx11=textx10.replace(/(<\/h([^>]+)>)/ig,"");
      textx12=textx11.replace(/(<body([^>]+)>)/ig,"");
      textx13=textx12.replace(/(<meta([^>]+)>)/ig,"");
      textx14=textx13.replace(/(<link([^>]+)>)/ig,"");
      textx15=textx14.replace(/(index.php\?option=)/ig,"index2.php?option=");
      textx=textx15;
      document.getElementById("htmlinfo1").innerHTML=textx;
      }
  }


// Texto ..........---//

// AJAX ------------------------------------FIN

// FLEX SEND------------------------------------------
 
 function getFlexApp(appName) {
            if (navigator.appName.indexOf ("Microsoft") !=-1) {
                return window[appName];
            } else {
                return document[appName];
            }
        }
 
  
  function displayProductImages(product,getta)
        {
            if(getta == null) {getta=1}
            if(product == null){ 
                alert("Please select a product, or maybe I screwed up.");
            }
            else{
                directorio=product.Directory_Url;
                wwwinfo=product.Product_Description_Url.replace(/&amp;/ig,"&");
                //fromdate="2008.07.19";
                fromdate=product.DateFrom;
                todate=product.DateTo;
                //numflex=7;
                numflex=product.Images;
                Npoint=product.Norte;
                Spoint=product.Sur;
                Wpoint=product.Oeste;
                Epoint=product.Este;
                pointSW = new GLatLng(Spoint,Wpoint);
                pointNE = new GLatLng(Npoint,Epoint);
                //alert("DATA:::"+numflex);
                
                opacity1=product.Transparency;
                if (Spoint){
               
                urlget(getta);}
                }
                
        }
//  FUNCION CLASS NAME
      document.getElementsByClassName = function(){
      if(document.hasChildNodes && arguments[0]){
      var data = new Array();
      for(a=0;a<document.getElementsByTagName("*").length;a++){
      if(document.getElementsByTagName("*")[a].className == arguments[0]){
      data.push(document.getElementsByTagName("*")[a]);
      }
      }
      return data;
      }
      }

//*******************************
        
         
         function displayOpacity(product)
        {
            var elArr = new Array();
                     

            
            if(product == null){ 
                alert("Please select a opacity, or maybe I screwed up.");
            }
            else{
                opacity1=product;
                eesr=document.getElementsByClassName("gmnoprint");
                aaa=eesr.length;
                aaa0=0;
                 //eesr[0].parentNode.style.filter="alpha(opacity="+opacity1+")";
                 //eesr[0].parentNode.style.opacity=opacity1/100;
                for(aaa0>=0;aaa0<aaa;++aaa0)
                {
                  eesr1[aaa0]=eesr[aaa0].lastChild;
                  if (eesr1[aaa0])
                    {
                    img_es = eesr1[aaa0].tagName;
                    if(img_es == "IMG")
                        {
                        eesr1[aaa0].style.filter="alpha(opacity="+opacity1+")";
                        eesr1[aaa0].style.opacity=opacity1/100;
                        }
                     }
                 }
           }
        }
        
        
        function displayProductWMS(wl)
                  {
                    minlat=wl.MinLat;
                    maxlat=wl.MaxLat;
                    minlon=wl.MinLon; 
                    maxlon=wl.MaxLon;
                    
                    urlwms1=wl.urlWMS;
                    VALOR_SEGNA = urlwms1.indexOf("?");
                    if (VALOR_SEGNA == -1){urlwms1=wl.urlWMS+"?";}else{urlwms1=wl.urlWMS+"&";}
                    formaton=wl.formatImages;
                    capa=wl.NameLayer; 
                    checked=wl.Checked;
                    indice_wms=wl.Indice_wms;
                    wms_comienza(capa,formaton,urlwms1,checked,indice_wms);
                    
                    }
                    
  function displayProductRSS(wl){
                    iconimage ="http://maps.google.com/intl/es_ALL/mapfiles/marker.png";
                    titulo_rss = wl.title; //    --- titulo del item seleccionado
                    description_rss = wl.desc;     //  --- descripcion
                    date_rss = wl.pubDate;  //  --- fecha de publicacion
                    image_rss = wl.image; // --- link de imagen    
                    pais_rss = wl.gdas_country; // --country
                    lat_rss = wl.geoLat;  //
                    lon_rss = wl.geoLong; //
                    link_rss= wl.link;      //    -- link del item   
                    check_rss = wl.Checked;
                    titulo_rss_f = wl.titleChannel;// -- titulo del rss
                    var punto = new GLatLng(lat_rss,lon_rss);
                    rss_layerobject = createMarker(punto,titulo_rss,description_rss,date_rss,image_rss,pais_rss,link_rss,titulo_rss_f,iconimage);
                    rss_layer.push(rss_layerobject);
                     if (check_rss == true)
                          {
                          var mm = new GMarkerManager(map, {borderPadding:1});
                          mm.addMarkers(rss_layer,0,7);
                          mm.refresh();
                          map.panTo(punto);
                          }
                              
                              // createMarker(titulo_rss,description_rss,date_rss,image_rss,pais_rss,lat_rss,lon_rss,link_rss,titulo_rss_f);
                     
                    }
                    
    // Inicio LOAD RSS *********************       
      

      
        function createMarker(point,titulo,desc,fecha,imagen,pais,link,totaltitulo,imagen_icon) 
        {
          var letteredIcon = new GIcon(baseIcon);
         letteredIcon.image = imagen_icon;
         var hour = fecha;

            markerOptions = { icon:letteredIcon };
            var marca = new GMarker(point, markerOptions);  
            marca.tooltip = '<div class="tooltiprsstop">'+titulo+'</div><div class="tooltiprss"><img id="imgrss" src="'+imagen+'" style="float:left;text-align:center;opacity:1;padding:4px; border:0px;width:80px;height:80px;"><span class="fecharss"><b>Fecha/Date:</b> '+hour+'</span><div><span class="content_rss"><b>Detalle/Description:</b> '+desc+'</span></div></div>';
            
         // GEvent.addListener(marca,"click", function() {        
        //var myhtml="<div class=\"content_rss_google\" style=\"width:200px\"><span class=\"titulorss\">Título: "+titulo+"</span><br/><img id=\"imgrss\" src=\""+imagen+"\" style=\"float:none;text-align:center;opacity:1;border:0px;width:100px;height:100px;\"></div>";
        //var myhtml="<span class=\"fecharss\">Fecha/Date: "+hour+"</span><br/><span class=\"titulorss\">Título: "+titulo+"</span><img id=\"imgrss\" src=\""+imagen+"\" style=\"float:none;text-align:center;opacity:1;border:0px;width:100px;height:100px;\"><div class=\"content_rss\" style=\"width:250px\">Descripcion: "+desc+"</div><br>RSS:"+totaltitulo;
        //marca.openInfoWindowHtml(myhtml);})
        if (check_rss == false)
            {
            marca.hide();
           
            }else
              {
                 GEvent.addListener(marca,"click", function() {
 
                var load = window.open(link,'','scrollbars=yes,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');

                });        
                
                 GEvent.addListener(marca,"mouseover", function() {
                  showTooltip(marca);
                });        

                GEvent.addListener(marca,"mouseout", function() {
                tooltip.style.visibility="hidden"
                });        
              }
        return marca;

        }
     // FIN RSS   
        
    // RSS OTHERS             
    
     function showTooltip(marker) {
      	tooltip.innerHTML = marker.tooltip;
	var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getSouthWest(),map.getZoom());
	var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
	var anchor=marker.getIcon().iconAnchor;
	var width=marker.getIcon().iconSize.width;
	var pos = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(offset.x - point.x - anchor.x + width,- offset.y + point.y +anchor.y)); 
	pos.apply(tooltip);
	tooltip.style.visibility="visible";
      }


                    
      // RSS OTHERS FIN
    Array.prototype.indexOf = function(s) {
	for (var x=0;x<this.length;x++) if(this[x] == s) return x;
	return false;
}
    

  function wms_comienza(layerslist,formatimage,urlwms,checked1,wms_i)
           {
            if(checked1 == false)
              {
                       
                        var indexxx=layerWMS.indexOf(wmsmaps[wms_i]);
                        layerWMS.splice(indexxx,1);
                        
              }else{
           
                        wmsmaps[wms_i]=new GTileLayer(new GCopyrightCollection("SERVIR"),1,17);
                        wmsmaps[wms_i].myLayers=layerslist;          
                        wmsmaps[wms_i].myFormat=formatimage;
                        wmsmaps[wms_i].myBaseURL=urlwms;
                        wmsmaps[wms_i].myxval=256;
                        wmsmaps[wms_i].myyval=256;
                        wmsmaps[wms_i].mydegval=256;
                        wmsmaps[wms_i].getTileUrl=CustomGetTileUrl;
                        wmsmaps[wms_i].getOpacity = function(){return 0.9;}
                        layerWMS.shift();
                        layerWMS.unshift(eval(mapafondal+".getTileLayers()[0]"));
                        layerWMS.push(wmsmaps[wms_i]);
                        
                        }
                        refrescarmapa();
                        
	        }
	        
	        
function refrescarmapa(){
map.setMapType(eval(mapafondal));
map.setMapType(mapaSERVIR);
}

	      
 // FLEX SEND------------------------------------------



// FUNCIONES ------------------------------------GO!

function limpiar()
      {
      map.clearOverlays();
      //map.addOverlay(groundOverlay2);
      
      }
      
function limpiar2()
      {
      if (namefile == ''){
            namefile=namefile2;
            tamano=tamano2;
            map.addOverlay(geoXml_sismos);
            map.addOverlay(geoXml_volcano);
            map.addOverlay(geoXml_hurricanes); 
            // map.addOverlay(geoXml_firesmodis);
            total();
      }else{
      namefile2 = namefile;
      namefile = '';
      tamano2 = tamano;
      tamano = 1;
            map.removeOverlay(geoXml_sismos);
            map.removeOverlay(geoXml_volcano);
            map.removeOverlay(geoXml_hurricanes); 
            map.removeOverlay(geoXml_firesmodis);
            
      total();
      }
      }
      
      function loaderson(stata)
      {
      document.getElementById("preloader2").style.display=stata;
      }
      
      

function revisarmenu()
      {
      var menustatus=document.getElementById("layer1").style.left;
      if(menustatus=="10000px")
        {
            map.panTo(pointCenter);
            //map.panDirection(0.5,  0)
            //map.setCenter(pointCenter,4);
        }
        else
        {
            map.panTo(pointCenter2);
            //map.panDirection(-0.5,  0)
            //map.setCenter(pointCenter2,4);
        }
      }
      
function ImagenesNumeral(tamano1)
    {
    txt1="<form><p><b>Num Images: ";
    txt1+="<SELECT id=\"numima\" NAME=\"numima\" >";
    var numim=1;
    for(numim;numim<=tamano1;++numim)
       {
       txt1+="<OPTION VALUE=\""+numim+"\">"+numim+"</OPTION>";
       }
    txt1+="</SELECT> ";
    txt1+="<input type=\"button\" id=\"button2\" onclick=\"urlget(1,0)\" value='Go!'></p>";
    txt1+="</form> ";
    //document.getElementById("numdiv").innerHTML=txt1;
    //document.getElementById("numima").options[numimages-1].selected=true;
    }

function setToBlack()
    {
    if(indice==0)
          {
            groundOverlay[0].show();
            setTimeout ("setToBlack()",500); 
          }
    if ((indice>0))
        {
        i=i+1;
        k=i-1;
          if (i<=0){k=indice;}
                   
            if(i>=0 && i<=indice)
            {  
            groundOverlay[i].show();
            groundOverlay[k].hide();
            }
                    
          if(i>(indice-1)){i=-1;}
                 
        setTimeout ("setToBlack()",500); 
                     
        }
    }

function documento()
    {
    //alert("paso1");
    //document.write(txt);
    // document.getElementById("prod").options[url2].selected=true;
    //document.getElementById("datacion").value=hoydia;
    }

documento();

function total()
  {
     //alert("paso2");
    if(tamano>0)
      {
      //ImagenesNumeral(tamano);
      numimages=numflex;
      groundOverlay=new Array();
     //groundOverlay.splice(0,indice);
      valormax=tamano-1;
      valormin=0;
      if(valormax>numimages)
        {
        valormin=valormax-numimages+1;
        }
      var kkk=valormin;
      var indice1=0;
      for (kkk>=valormin;kkk<=valormax;++kkk)
        {
        imagenes_data[indice1] = new Image();
        imagenes_data[indice1].src=namefile[kkk];
        //groundOverlay[indice1]= new GGroundOverlay(imagenes_data[indice1].src,new GLatLngBounds(pointSW, pointNE));
        indice1=indice1+1;
        }

      indice=indice1-1;
      kkk=0;
      for (kkk>=0;kkk<=indice;++kkk)
        {
        groundOverlay[kkk]= new GGroundOverlay(imagenes_data[kkk].src,new GLatLngBounds(pointSW, pointNE));
        }

      
      var inx=tamano;
      var numpics=inx;

      ijj=ijj-1;
      if (inx<0)
          {
          msgerr1 ="<CENTER><h2>NO EXISTE DATA PARA ESTA FECHA / NOT DATA FOR THIS DATE:<br>--> "+diahoy+" <--</h2></center>";
          if(err1txt==1)
              {
              msgerr1 ="<CENTER><h2>NO EXISTE DATA PARA HOY / NOT DATA FOR TODAY:<br>--> "+diahoy+" <--</h2></center><br>Los productos diarios estan disponibles despues de las 00:00UTC";}
              document.write(msgerr1);
              document.write(txt);
              document.getElementById("prod").options[producto].selected=true;
              document.getElementById("datacion").value=diahoysel;
              exit;
              }
          final(aval1);
          }
      }
  
//
// ------------- END FUNCIONES ----------------
//
//-->
//