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

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 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 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 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('filacontroles')) {	 
      document.getElementById('filacontroles').style.visibility = 'hidden';
      document.getElementById('filacontroles').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('filacontroles')) {	 
      document.getElementById('filacontroles').style.visibility = 'visible';
      document.getElementById('filacontroles').style.position = 'relative'; 
   }      
   if (document.getElementById('filapie')) {
      document.getElementById('filapie').style.visibility = 'visible';
      document.getElementById('filapie').style.position = 'relative'; 
   }
}

// Luz
var r=100;
var s=5;
var p=0;
function luces() {
    if (ie5) {
    	if (r>95) s=-5;
    	if ((r==10) && (s<0)) s=5;
    	document.images.imgcab1.style.filter='alpha(style=1,opacity='+r+',finishOpacity=100,startX=0,finishX=125,startY=0,finishY=425)';
    	r=r+s;
	setTimeout("luces()",100);
    }
}


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

