var nPagina = 1;
var cPagina = "";
var Idioma;

Idioma = ( navigator.language ? navigator.language : navigator.userLanguage );
if( Idioma.indexOf( "es" ) == 0 )
   Idioma = "es";
if( Idioma.indexOf( "ca" ) == 0 )
   Idioma = "es";
if( Idioma.indexOf( "eu" ) == 0 )
   Idioma = "es";
Idioma = GetCookie( "Language", Idioma );
loading();


function init( nPage ) {
   if( cPagina.length == 0 )
      {
      cPagina = GetCookie( "Page", ( Idioma == "es" ? "noticias.htm" : "news.htm" ) );
      document.botones.SetVariable( "language", Idioma );
      }
   if( typeof( nPage ) != 'number' )
      nPage = nPagina;
   nPagina = nPage;
   document.botones.SetVariable( "cPagina", cPagina );
   document.botones.SetVariable( "cBoton", nPage );
   if( typeof( window.innerWidth ) != 'number' )
      document.botones.GotoFrame( 1 );
   resize();
}

function loading() {
   var cUrl = window.location.href;

   cUrl.toLowerCase();
   if( ( cUrl.indexOf( "index.html" ) == -1 ) && ( cUrl.indexOf( ".htm" ) > 0 ) )
      if( typeof( parent.Contenido ) != 'object' )
         {
         SetCookie( "Page", cUrl );
         window.location = "index.html";
         }
}

function loaded( nPage ) {
   var oLayer1;

   if( typeof( Contenido ) == 'object' )
      {
      oLayer1 = document.getElementById('Layer1');
      oLayer1.scrollTop = 0;
      oLayer1.innerHTML = Contenido.document.body.innerHTML;
      cPagina = Contenido.document.location;
      SetCookie( "Page", cPagina );
      if( typeof( nPage ) == 'number' )
         init( nPage );
      }
   else
      top.loaded( nPage );
}

function resize() {
   var nWidth = 0, nHeight = 0;
   if( typeof( window.innerWidth ) == 'number' ) {
     //Non-IE
     nWidth = window.innerWidth;
     nHeight = window.innerHeight;
   } else if( document.documentElement &&
       ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
     //IE 6+ in 'standards compliant mode'
     nWidth = document.documentElement.clientWidth;
     nHeight = document.documentElement.clientHeight;
   } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
     //IE 4 compatible
     nWidth = document.body.clientWidth;
     nHeight = document.body.clientHeight;
   }
   nWidth = ( nWidth > 760 ? ( nWidth - 760 ) / 2 : 0 );
   nHeight = ( nHeight > 450 ? ( nHeight - 450 ) / 2 : 0 );
   document.getElementById('Layer0').style.left = nWidth;
   document.getElementById('Layer0').style.top = nHeight;
}

function spanish() {
   Idioma = "es";
   SetCookie( "Language", "es", true );
   document.slogan.src = "images/fondo3es.png";
   document.title = "Xailer - El entorno de desarrollo definitivo en xbase";
}

function english() {
   Idioma = "en";
   SetCookie( "Language", "en", true );
   document.slogan.src = "images/fondo3en.png";
   document.title = "Xailer - The ultimate development environment for xbase";
}

function LoadVideo( cFile ) {
   window.open( "video/" + cFile, "", "top=0,left=0,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=800,height=600" );
}

function LoadScreen( cFile ) {
   window.open( "images/" + cFile, "", "top=0,left=0,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=770,height=620" );
}

function LoadForm( cFile ) {
   window.open( cFile, "", "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=620,height=300" );
}

function GetCookie( name, defvalue ) {
  var cname = name + "=";
  var dc = document.cookie;

  if (dc.length > 0) {
    begin = dc.indexOf(cname);
    if (begin != -1) {
      begin += cname.length;
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    }
  }
  return( defvalue );
}

function SetCookie(name, value, permanent) {
   var expires;

   if( permanent )
      {
      expires = new Date();
      expires.setFullYear( expires.getFullYear() + 1 );
      }
   document.cookie = name + "=" + escape(value) +
   (permanent ? "; expires=" + expires.toGMTString() : "" );
   if( permanent )
      if( GetCookie( name, null ) == null )
         if( Idioma == "es" )
            alert( "Los 'cookies' están desactivados en su navegador, y\n" +
                   "esto puede provocar algunos problemas al navegar entre\n" +
                   "las distintas páginas.\n\n" +
                   "Por favor, actívelos. El único propósito de los\n" +
                   "'cookies' que utiliza este sitio web es el de acceder\n" +
                   "correctamente a las páginas que solicite, así como\n" +
                   "el idioma seleccionado." );
         else
            alert( "'Cookies' are disabled in your browser, and could\n" +
                   "cause some problems on accessing the pages.\n\n" +
                   "Please, activate them. The only target of the 'cookies'\n" +
                   "used by this web site is to address the pages correctly,\n" +
                   "and to recall the selected language." );
}

