// JavaScript Document

	function enviar_baja(id){	
		var frm=document.getElementById("form_baja");
		//if(!confirm("Va a solicitar la baja al administrador. ¿Esta seguro?")) return;
		if(frm) {
			//frm.usuario.value=id;
			//frm.action="/v2/nuevo/asp/registro_usuario/baja.user.asp";
			frm.method="post";
			frm.target="_self";
			frm.submit();
		}
	}
	
	function login_onclick(){
		try{
			var target = document.getElementById("form_server_login");
			if(target){
				var password = document.getElementById("password_").value;
				var usuario = document.getElementById("usuario_").value;
				target.usuario.value = usuario;
				target.password.value = password;
				target.submit();
			}
		}catch(e){alert(e.description);};
	
	}
	
	function close_session()
	{
		try{
			var target = document.getElementById("form_server_login");
			var password = "";
			var usuario = "";
			target.usuario.value = usuario;
			target.password.value = password;
			target.accion.value = "CloseSession";	
			target.action = "/v2/nuevo/asp/individual/home.asp";
			target.submit();
		}catch(e){alert(e.description);};		
	}
	
// GetBounds(e): this returns, in absolute pixel coordinates,
// the bounding rectangle for element "e"

function GetBounds(e)
{ 
  // firefox: it's offsetLeft/offsetTop model is broken for tables that
  // are inline or absolutely positioned with margins. But it
  // supports getBoxObjectFor, which works better:
  /*if(!w)
				return {'left':0, 'top':0, 'right':0, 'bottom':0};
  if (w.document.getBoxObjectFor)
  { // just one problem: it gives the wrong answer for the table element of inline tables,
    // but the right answer for TBODY in all circumstances:
    if (e.tagName=='TABLE')
    { for (var i=0; i<e.childNodes.length; i++)
      { if (e.childNodes[i].tagName=='TBODY') {e=e.childNodes[i]; break;}
      }
    }
    try {
								var r=w.document.getBoxObjectFor(e);
								return {'left':r.x, 'top':r.y, 'right':r.x+r.width, 'bottom':r.y+r.height};
				}catch(exception) {
								return {'left':0, 'top':0, 'right':0, 'bottom':0};
				}
  }*/
  
  // IE: it's offsetLeft/offsetTop model is correct except in the case
  // of the last text node in a container, But getBoundingClientRect
  // works and is faster:
  /*if (e.getBoundingClientRect)
  { var r=e.getBoundingClientRect();
    var wx=document.documentElement.scrollLeft, wy=document.documentElement.scrollTop;
    return {'left':r.left+wx, 'top':r.top+wy, 'right':r.right+wx, 'bottom':r.bottom+wy};
  }*/

  // Other browsers: we'll trust and pray that their offsetLeft/offsetTop model is correct
  var x=0, y=0, w=e.offsetWidth, h=e.offsetHeight;
  while (e!=null) {x+=e.offsetLeft; y+=e.offsetTop; e=e.offsetParent;}
  return {'left':x, 'top':y, 'right':x+w, 'bottom':y+h};
}
	
	/*********************************************/
	function IframeResize(w){
	/*********************************************/
	/*
		Esta función ajusta todos los contenedores de los iframes a la altura natural del iframe.
		Se emplea el método recursivo descendente.
	*/
	 var iframe = null;
		try {
				var iframe=event.srcElement;/* Obtenemos el elemento que ha generado el evento....*/
		}catch(Exception) {
						if(!iframe) {
								iframe = document.getElementById("iframe_principal");
						}
		}
		/*alert(iframe.document.readyState);
		if(iframe.document.readyState!='complete') return;*//* Aún se está descargando....*/

		w=w? w:window;/* Tomamos la ventana actual */
		/* Seleccionamos los Iframes */
		
		var ifrs=w.document.getElementsByTagName("iframe");/* Tomamos los iframes de la ventana w*/
		var L=ifrs.length;
		
		for(var i=0;i<L;i++){
			 var iframe=ifrs[i];
		   /* Eliminamos los casos no interesantes */
			 if(!iframe.name) continue; /* Si no tiene nombre es que no sirve pa mucha cosa */
			 if(iframe.style.display=='none') continue;/* Es uno de nuestros iframes ocultos, no nos interesa */
			 if(!w.frames) continue;
			 
			 var wf=w.frames[iframe.name];/* es el window del iframe[i] de w*/
			 /* En este punto tenemos la ventana del iframe, vamos a indicarselo a la ventana */
	/* (1) */wf.IframePropietario=iframe;/* Hemos asociado el frame y su ventana hacia arriba, esta linea es la que permite ascender y descender,..., es la que hace que funcione la recursividad...*/
			 IframeResize(wf); /* descendemos a wf */ 
		}
		/* Ahora estamos en el iframe más bajo */
		if(!w.IframePropietario) return; /* Esta ventana no está en un iframe, no interesa.*/
		/* Gracias a (1) sabemos en que iframe se encuentra w */
	  	iframe=w.IframePropietario;
		/* Obtenemos el contenedor del iframe */
		//var td=iframe.parentElement;/* es un TD en nuestro caso.*/
		var td = iframe.parentNode;
		/* Ajustamos el alto del td al alto del contenido del iframe, esto es al contenido del body de la ventana que muestra el iframe */
		var body=w.document.body;
		if(!body) return;/* Si no hay body, paque seguir */
		
		
  var H = GetSize(w);
		var H2=(body.scrollHeight)+310;/*Obtenemos el alto, el +50 es para ajustar */
		
		H = Math.max(H, H2);
		
		//if(!td.originalHeight) td.originalHeight=H;/* Guardamos el alto original de la tabla....*/
		//if(H<td.originalHeight) H=td.originalHeight;/* COnservamos el alto mínimo del diseño....*/
		td.style.height=H + "px";
		iframe.style.height=H + "px";
		body.style.overflowX='hidden';
		//Math.floor(body.scrollHeight/2);
		/* Ya tá ajustada la última ventana, por la recursividad se empieza ajustando la ventana más interna hasta la superior.*/
		//	alert("window_resize_iframe2")	
	}
	/************************************************************************************/	
	
	function GetSize(w) {
		//try{
							var objdoc = w.document;
       var h=0;
       var N=objdoc.body.childNodes;
       var bodyH = objdoc.body.offsetHeight;
       var minH = bodyH;
       var maxH = 0;
       var tmpH = 0;
       var absoluteH = 0;
       var tmpH = GetSizeOfObject(objdoc.body, w);
       var L=N.length;
       for(var i=0;i<L;i++){
       	   var n=N[i];
           if(n.offsetHeight){
																tmpH = absoluteTop(n);
																/*var box = GetBounds(n, w);*/
																/*tmpH = box.Height;*/
                minH = (minH > tmpH?tmpH:minH);
                maxH = (maxH < tmpH?tmpH:maxH);
           }
       }
       absoluteH = maxH - minH;
       if(maxH <= minH || absoluteH == maxH) absoluteH = bodyH;
       else absoluteH = maxH - minH;
       
       if(absoluteH < 250) absoluteH = 2800;
   
       return absoluteH;
       
   /*}catch(ex){
				alert(ex.description);
       return 0;
   }  */ 
	}
	
	function GetSizeOfObject(obj, w) {
				/* Función Recursiva para obtener todo el tamaño de los objetos */
				var childsX = obj.childNodes;
				var totalsize = 0;
				for( var i = 0; i < childsX.length; i ++) {
								var box = GetBounds(childsX[i]);
								totalsize += box.height;
								if(childsX[i].childNodes.length > 0) {
												totalsize += GetSizeOfObject(childsX[i]);
								}
				}
				
				return totalsize;
	}
	
	function absoluteTop(obj){
//******************************************************************************/
    var curtop = 0;
    if (obj.offsetParent){
        while (obj.offsetParent){
            //curtop += obj.offsetTop
            curtop += obj.offsetHeight;
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}

	
	function ChangeLang(i)
	{
		try
		{
			//return true;
			var form_lng = document.getElementById("form_lang");
			if(!form_lng) return true;
			form_lng.lang.value = i;
			form_lng.submit();
			//window.open("/v2/nuevo/asp/change_lang.asp?lang="+i,"iframe_lang");
			return false;
		}
		catch(Exception)
		{
			alert(Exception.description);
			return true;
		}
	}	
	
	function vista_previa(id_guia){
		var frm=document.getElementById('form');
		if (frm)
		{
			frm.id_guia.value=id_guia;
			frm.lang.value="";
			frm.accion.value="VistaPrevia";
			frm.action="/v2/nuevo/asp/individual/plantilla.asp";
			frm.target="_self";
			frm.method="post";
			frm.submit();
		}
	}	
	
	function ChangeStyleSheet(browserName, browserVersion)
	{	
		switch(browserName)
		{
			case "Explorer":
				if(browserVersion < 7)
					setActiveStyleSheet("obsolete");
		}
	}
	
	function OpenHelp(lang)
	{
		try
		{	
			var opts = "width=780px,Height=705px,Scrollbars=yes,Resizable=yes,Statusbar=no,Menubar=no";
			var ref = "/v2/nuevo/asp/individual/ayuda/index.htm";
			var target = "_ayuda";
			window.open(ref, target, opts);
			return false;
		}catch(Exception)
		{
			return true;
		}
	}
	
	
    function window_resize(){
		try
		{
			var div=document.getElementById("div_externo");
			var h=-1;
			window.top.document.getElementById("iframe_principal").style.height = div.scrollHeight + 50 + "px";
		}
		catch(Exception)
		{	
			alert(Exception.description);
		}
    }	
	
	function OpenLegal(lang)
	{
		var lang_string = lang = 1 ? "" : "_gl";
		var target = "_legal";
		var opts = "Width=800px,Height=660px,Scrollbars=yes,Statusbar=no,Menubar=no,Resizable=yes";
		var ref = "/v2/nuevo/asp/registro_usuario/legal" + lang_string + ".htm";
		window.open(ref, target, opts);	
		return false;
	}
	
	function ImprimirListado()
	{
		try
		{
			var ref = "/v2/nuevo/asp/individual/imprimir_listado.html";
			var opts = "Toolbar=yes,Menubar=no,Resizable=yes,Scrollbars=yes,Statusbar=no";
			var target = "_imprimir";
			var w = window.open(ref, target, opts);	
			/*if(w)
			{
				var destSource = w.document.getElementById("id_left");
				if(!destSource) return;
				var Source = document.getElementById("destSource");
				if(!Source) return;
				destSource.innerHTML = Source.innerHTML;
			}*/
		}
		catch(Exception)
		{
			alert("Error[user.js]: " + Exception.description);
		}
	}
	
	function PrintHTML(id_dest, id_origin)	
	{
		try
		{

			var w = window.opener ? window.opener : (window.parent ? window.parent : window.top);
			if(!w) return;
			var destSource = document.getElementById(id_dest);
			if(!destSource) return;
			var Source = w.document.getElementById(id_origin);
			if(!Source) return;
			destSource.innerHTML = Source.innerHTML;
		}
		catch(Exception)
		{
			alert("Error[user.js]: " + Exception.description);
		}		
	}
	
	function ShowSectors(obj)
	{
		try
		{
			var div_sectors = document.getElementById("id_div_sectores");
			var to_hide = document.getElementById("id_id_directorio");
			to_hide.style.display = "none";
			if(!div_sectors) return false;
			var top = obj.offsetTop -22;
			var left = obj.offsetLeft - 332;
			div_sectors.style.left = left;
			div_sectors.style.top = top;
			div_sectors.style.display = "block";
			div_sectors.focus();
		}
		catch(Exception)
		{
			alert("Error[ShowSectors]: " + Exception.description);	
		}
	}
	
	function HideObj(id)
	{
		var target = document.getElementById(id);
		if(target) target.style.display = "none";
		var to_hide = document.getElementById("id_id_directorio");
		to_hide.style.display = "";		
	}
	
	function SelectSector(obj)
	{
		try
		{
			//añadir el sector seleccionado al combo... o buscar directamente...
			var target = document.getElementById('form_oportunidades');
			target.id_directorio.value = obj.getAttribute("value");
			target.submit();
		}
		catch(Exception)
		{
			
		}
	}
	