var initialwidth,initialheight
var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all

function iecompattest(){
   return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ocultarla(){
   parent.document.getElementById("dwindow").style.display="none";
}


function loadwindow(url,width,height){
   if (!ie5&&!ns6)
      window.open(url,"","width=width,height=height,scrollbars=1")
   else {
      document.getElementById("dwindow").style.display=''
      document.getElementById("dwindow").style.width=initialwidth=width+"px"
      document.getElementById("dwindow").style.height=initialheight=height+"px"
      document.getElementById("dwindow").style.left="30px"
      document.getElementById("dwindow").style.top=ns6? window.pageYOffset*1+30+"px" : iecompattest().scrollTop*1+30+"px"
      //document.getElementById("cframe").contentWindow.document.body.innerHTML='<img src="'+url+'" border=0 onClick="parent.window.dwindow.style.display=\'none\';" style="cursor:hand;">';
      document.getElementById("cframe").src=url;
   }
}

function init() {
      if (TransMenu.isSupported()) {
        TransMenu.initialize();

        menu1.onactivate = function() { document.getElementById("menu1").className = "hover"; };
        menu1.ondeactivate = function() { document.getElementById("menu1").className = ""; };

        menu2.onactivate = function() { document.getElementById("menu2").className = "hover"; };
        menu2.ondeactivate = function() { document.getElementById("menu2").className = ""; };

        menu3.onactivate = function() { document.getElementById("menu3").className = "hover"; };
        menu3.ondeactivate = function() { document.getElementById("menu3").className = ""; };

        menu4.onactivate = function() { document.getElementById("menu4").className = "hover"; };
        menu4.ondeactivate = function() { document.getElementById("menu4").className = ""; };
      }
}

function resaltarImagen(cur,which){
   strength=(which==1)? 1 : 0.6
   if (cur.style.MozOpacity)
      cur.style.MozOpacity=strength
   else if (cur.filters)
      cur.filters.alpha.opacity=strength*100
}

function leerCookie(nombre) { 
   a = document.cookie.substring(document.cookie.indexOf(nombre + '=') + nombre.length + 1,document.cookie.length); 
   if(a.indexOf(';') != -1)a = a.substring(0,a.indexOf(';')) 
   return a;  
} 

function localizaObj(n, d) {
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
      d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=localizaObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function validarForm() {
      var i,p,q,nm,test,num,min,max,errors='',args=validarForm.arguments;
      if (leerCookie('luppa_ln')!='en') 
         var textorequerido='Campos requeridos:';
      else
         var textorequerido='Required fields:';
      
      for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=localizaObj(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' no válido.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' debe ser numérico.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' debe ser un nº entre '+min+' y '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+'\n'; }
      } 
      if (errors) {
         if (leerCookie('luppa_ln')=='en') {
            errors = errors.replace("nombre", "name");
            errors = errors.replace("telefono", "phone");
         }
         alert(textorequerido+'\n\n'+errors);
      }
      return (errors == '');
}

function solonumeros(evt) { 
      // Backspace = 8, Enter = 13, '0' = 48, '9' = 57 
      var key = nav4 ? evt.which : evt.keyCode; 
      return (key <= 13 || (key >= 48 && key <= 57));
}

var nav4 = window.Event ? true : false;
function sololetrasynumeros(evt) { 
      // Backspace = 8, Enter = 13, las eñes, las vocales acentuadas, minúsculas y mayúsculas y los números
      var key = nav4 ? evt.which : evt.keyCode; 
      return ((key<=13) || (key==32) || (key==209) || (key==241) || (key==225) || (key==233) || (key==237) || (key==243) || (key==250) || (key==193) || (key==201) || (key==205) || (key==211) || (key==218) || (key>=65 && key<=90) || (key>=97 && key<=122) || (key>= 48 && key<= 57));
}

function mostrar_tab(TabViewId, CurrentId)
{
  var TabView = document.getElementById(TabViewId);

  // ***** Tabs *****

  var Tabs = TabView.firstChild;
  while (Tabs.className != "Tabs") Tabs = Tabs.nextSibling;
  var Tab  = Tabs.firstChild;
  var textwidth = 0;
  var i    = 0;
  do
  {
    if (Tab.tagName == "A")
    {
      i++;
      Tab.href = "javascript:cambiarvista('"+TabViewId+"', "+i+");";
      textwidth = Tab.innerHTML.length;      
      Tab.className    = (i == CurrentId) ? "TabDefecto" : "";      
      Tab.blur();
    }
  }
  while (Tab = Tab.nextSibling);

  // ***** Pages *****

  var Pages = TabView.firstChild;
  while (Pages.className != 'Pages') Pages = Pages.nextSibling;
  var Page  = Pages  .firstChild;
  var i     = 0;
  var altura=0;

  do
  {
    if (Page.className == 'Page')
    {
      i++;
      Page.style.display  = (i == CurrentId) ? 'block' : 'none';
    	
      if (i == CurrentId) {
      	if (document.all)
      		Pages.style.height = Page.clientHeight +"px";  
      	else {
      	        if (Pages.offsetHeight) Page.style.height = (Page.scrollHeight)+"px";
      		Pages.style.height = Page.scrollHeight +"px";  
      		Page.style.overflow = "hidden"; 
      		//alert(Page.scrollHeight);
      	}
      }
    }
  }
  while (Page = Page.nextSibling);
}

function cambiarvista(TabViewId, id) { mostrar_tab(TabViewId, id); }
function inicializar_tabs(TabViewId) { mostrar_tab(TabViewId,  1); }

var min=8;
var max=20;
var original=12;
function aumentar() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
}

function reducir() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }   
}

function antesdeimprimir(){ 
   if (document.getElementById('filacabecera')) {	 
      document.getElementById('filacabecera').style.visibility = 'hidden';
      document.getElementById('filacabecera').style.position = 'absolute'; 
   }
   if (document.getElementById('filamenus')) {	 
      document.getElementById('filamenus').style.visibility = 'hidden';
      document.getElementById('filamenus').style.position = 'absolute'; 
   }      
   if (document.getElementById('filapie')) {
      document.getElementById('filapie').style.visibility = 'hidden';
      document.getElementById('filapie').style.position = 'absolute'; 
   }
} 

function despuesdeimprimir(){
   if (document.getElementById('filacabecera')) {	 
      document.getElementById('filacabecera').style.visibility = 'visible';
      document.getElementById('filacabecera').style.position = 'relative'; 
   }      
   if (document.getElementById('filamenus')) {	 
      document.getElementById('filamenus').style.visibility = 'visible';
      document.getElementById('filamenus').style.position = 'relative'; 
   }      
   if (document.getElementById('filapie')) {
      document.getElementById('filapie').style.visibility = 'visible';
      document.getElementById('filapie').style.position = 'relative'; 
   }
}

function pixelar(){
    if (ie5) {
    	document.images.imgcab1.filters[0].apply();
    	document.images.imgcab1.filters[0].play();
    	setTimeout("pixelar()",8000);
    }
}

function cargar_ejemplo(direccion) {
	loadwindow(direccion,800,600);
}

function PosicionX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1)
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

function PosicionY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}

function vercalendario(url,campo,width,height){
   if (!ie5&&!ns6)
      window.open(url,"","width=width,height=height,scrollbars=1")
   else {
      document.getElementById("dwindow").style.display=''
      document.getElementById("dwindow").style.width=initialwidth=width+"px"
      document.getElementById("dwindow").style.height=initialheight=height+"px"
      document.getElementById("dwindow").style.left=PosicionX(document.getElementById(campo)) + 'px';
      document.getElementById("dwindow").style.top=PosicionY(document.getElementById(campo)) + 'px';
      document.getElementById("cframe").src=url;
   }
}

function calendario(control) {
	vercalendario('./?opcion=calendario&campo='+control,control,230,215);
}

function navegar(opcion) {
    parent.window.location.href='./?salida='+opcion;
}

function setIframeHeight(iframeName) {
	  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
	  if (iframeEl) {
	  	var h = alertSize();
	  	iframeEl.style.height = h+'px';
	  }
}

function alertSize() {
		  var myHeight = 0;
		  if( typeof( window.innerWidth ) == 'number' ) {
		    //Non-IE
		    myHeight = window.outerHeight + 100;
		  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		    //IE 6+ in 'standards compliant mode'
		    myHeight = document.documentElement.clientHeight;
		  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		    //IE 4 compatible
		    myHeight = document.body.scrollHeight;
		  }
		  return myHeight;
}

