﻿

function abrirVentana(ruta, nueva)
{
    /*var e = GE("enlace");
    alert(e.click);
    e.click();
    return;*/
    /*var f = GE("form2");
    f.action = ruta;
    //alert(f.action);
	f.submit();
    return;
    */
    //var tam = "width=400,height=300,";
    var tam = "width="+(screen.width-50)+",height="+(screen.height-100)+",";
    var n = "v";
    if(nueva)
    {
        var a = new Date();
        n += ((n.indexOf("?")>0)?"&":"?") + a.getUTCMilliseconds();
    }
	ventanaDescargas = window.open(ruta, n, tam+"scrollbars,resizable,top=100,left=100");
	ventanaDescargas.focus();
}




function abrirVentanaFlotante(url, nueva)
{
    var o = GE("iframeFicha");
    if(nueva)
    {
        var a = new Date();
        url += ((url.indexOf("?")>0)?"&":"?") + a.getUTCMilliseconds();
    }
    
    
    o.height = (FlotanteHeight+30)+"px";
    //o.height = FlotanteHeight;
    //alert(screen.height+"|"+document.documentElement.clientHeight+"|"+o.height);
    o.width = FlotanteWidth+"px";
    //$get("Button1").click();
    var capa= GE("panelframe2");
   capa.style.visibility="visible";
   capa.style.top="5%";
   capa= GE("capaT");
    capa.style.visibility="visible";
    o.src = url;
}

var urlaux=window.location.href;
urlaux=urlaux.split('/');

var url="";
for(var i=1; i<urlaux.length-1; i++)
    url+=urlaux[i]+"/";

var cX=-1;
var cy=-1;
var es=-1;
function cambiarEnlace(){

   var obj= GE("enlace");
   var centroX=parseFloat(LtnWebViewer1.getCenterUtmX());
       centroX=parseInt(centroX/1000);
      var centroY=parseFloat(LtnWebViewer1.getCenterUtmY());
       centroY=parseInt(centroY/1000);
   var escala=parseInt(LtnWebViewer1.getScale()/10);
   
   if(centroX!=cX || centroY!=cy || es!=escala){
        var salida="http:/"+url+"?x="+centroX+"&y="+centroY+"&scale="+escala;
        obj.innerHTML="Enlace: <a href='"+salida+"' target='_blank' style='color:black'>"+salida+"</a>";
    }
    centroX=cX ; centroY=cy ; es=escala;
}


function gup( name ){
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp ( regexS );
	var tmpURL = window.location.href;
	var results = regex.exec( tmpURL );
	if( results == null )
		return"";
	else
		return results[1];
}


function hola()
{
var o = GE("iframeFicha");
o.src = "loading.htm";
}

function q(obj)
{
    var s = "";
    for(i in obj)
    {
        s += i+"\t";
    }
    alert(s);
}
                   
function GE(id)
{
    return document.getElementById(id);
}

function devolverDecimales(valor, numDecimales)
{
	var n = Math.pow(10, numDecimales);
	var res = valor;
	res*=n;
	res=Math.round(res);
	res/=n;
	return res;
}

function mandarMail(titulo)
{
    var n = $get(titulo).innerHTML;
    var b = "Vea la ficha de '"+n+"': "+window.location;
    mail("Ciclo Hídrico - "+n, b);
}

function mail(subject, body)
{
    window.open("mailto:?subject="+subject+"&amp;body="+body);
}
function iprint()
{
    window.frames['iframeFicha'].focus(); 
    window.frames['iframeFicha'].print(); 
} 

function contains(array, element) 
{
    for (var i = 0; i < array.length; i++) 
    {
        if (array[i] == element) 
        {
            return true;
        }
    }
    return false;
}