/***
 *   Copyright (C) 2005 by Juergen Heinemann
 *   heinemann DOT juergen AT hjcms DOT de
 *
 * $Id: Ettringen.js,v 1.17 2007/11/09 22:09:24 heinemann Exp $
 *
 * THIS SOFTWARE IS PROVIDED BY DEVELOPER Heinemann All rights reserved.
 ***/

var ettrdomain = null;
var querystring = null;
var popset = null;
var lang = null;
var system = null;
var xPos = 0;
var yPos = 0;
var watcher = {val:null};

try {
  var uAgent = navigator.userAgent.toLowerCase();
} catch(e) {
  var uAgent = 'netscape';
}
var is_opera  = (uAgent.indexOf('opera') != -1);
var is_saf    = ((uAgent.indexOf('applewebkit') != -1  && uAgent.indexOf('spoofer') == -1) || (navigator.vendor == 'Apple Computer, Inc.'));
var is_ie     = ((uAgent.indexOf('msie') != -1) && (!is_opera));
var is_khtml  = (navigator.vendor == 'KDE' || (document.childNodes && !document.all && !navigator.taintEnabled));
var is_moz    = ((navigator.product == 'Gecko') && (!is_saf) && (!is_khtml));
var is_kon    = (uAgent.indexOf('konqueror') != -1);
var is_netsc  = (uAgent.indexOf('netscape') != -1);
var glW = is_ie ? screen.width : window.innerWidth;
var glH = is_ie ? screen.height : window.innerHeight;

function NoscriptUtil() { return 0; }

function ldf(o)
{
   window.defaultStatus = lng['STATUSLINE'];
   ettrdomain = window.location.hostname;
   querystring = window.location.search;
   lang = (navigator.language) ? navigator.language.toLowerCase() : 'de';
   system = (navigator.platform) ?  navigator.platform.toLowerCase() : 'windows';
   // FIX Netscape >= 8.*
   if (is_netsc && !getCookieParam('netscape')) {
      if (confirm(lng['BROWSERMISSMATCH']))
         setCookieParam('netscape',true);
   }
}

function SetClientCursorPos(o)
{
   xPos = (is_ie) ? window.event.clientX : o.offsetLeft;
   yPos = (is_ie) ? window.event.clientY : o.offsetTop;
   // alert(xPos+':'+yPos);
}

function SwapDisplay(i)
{
   if (document.getElementById(i).style.display == 'none') {
      document.getElementById(i).style.display = '';
   } else {
      document.getElementById(i).style.display = 'none';
   }
}

function DestroyObject(o)
{
   if (o) {
      o.innerHTML = '';
      o.style.display = 'none';
      delete o;
   }
}

function InvalidCaracters(o)
{
   var p = /[\'|\*|`|\^]+/ig;
   var val = o.value;
   var reg = new RegExp(p);
   if (reg.test(val) == false) {
      alert(lng['NOVALIDINPUT']);
      return false;
   } else
      return true;
}

function UrlImagePopUp(u, w, h)
{
   var wH = (glH < h) ? ((h + 60) / 2) : (h + 60);
   var wW = (glW < w) ? ((w + 40) / 2) : (w + 40);
   var _x = (glW - w) / 2;
   var _y = (glH - h) / 2 - 30;
   var opts = 'menubar=yes,toolbar=no,status=no,dependent=yes,resizable=yes';
   var st = 'width='+wW+',height='+wH+',top='+_y+',left='+_x+','+opts;
   popset = escape(u);
   var pp = window.open('./UrlImagePopUp.html?img='+u,'Bild',st);
   pp.focus();
}

function UrlPopUp(u, n, wW, wH, t)
{
   var _x = (screen.width - wW) / 2;
   var _y = (screen.height - wH) / 2 - 30;
   var opts = 'menubar=yes,toolbar=no,status=no,dependent=yes,resizable=yes,scrollbaes=yes';
   t = t+',width='+wW+',height='+wH+',top='+_y+',left='+_x+','+opts;
   window.open(u, n, t);
}

function ScrollToAnker(id)
{
   window.document.location.href = '#'+id;
}

function ScrollToTagID(id)
{
   var el = document.getElementById(id);
   if (el) {
      var _x = el.x ? el.x : el.offsetLeft;
      var _y = el.y ? el.y : el.offsetTop;
      window.scrollTo(_x, _y);
   }
}

function KalenderReceiver(i,t)
{
   document.getElementById('NewsRuntime').value = i;
   document.getElementById('DisplayNewsRuntime').innerHTML = lng['EXPIRESAT'] + t;
}

function setCookieParam(p, v)
{
   if (! navigator.cookieEnabled)
      return false;

   if(!p)
      return false;

   var t = (new Date((new Date()).getTime() + (1110000 * 45000))).toGMTString();
   document.cookie = escape(p) + "=" + escape(v) + ";expires=" + t + ";path=/;domain=" + ettrdomain;
   return true;
}

function getCookieParam(p)
{
   var co = document.cookie.split("; ");
   for(var i = 0; i < co.length; i++) {
      var C = co[i].split("=");
      if(C[0] == escape(p)) {
         return unescape(C[1]);
      }
   }
   return false;
}

function iezoom(o)
{
   if (! is_ie) {
      o.removeAttribute('onmouseover');
      o.setAttribute('title', o.alt);
      return true;
   }

   o.setAttribute('style');
   o.style.zoom = '1.05';

   var out = function() {
      o.style.zoom = '0.80';
   }

   o.onmouseout = out;

   return true;
}

function SetHiddenAnker(sel, val, set)
{
   for (var i = 0; i < sel.childNodes.length; i++)
   {
      if (sel[i].nodeName.toLowerCase() == 'option' && sel[i].value == val) {
         try {
            var opt = sel[i].getAttribute('id').split("_");
            document.getElementById(set).value = parseInt(opt[1]);
            break;
         } catch(err) {
            alert(err);
         }
      }
   }
   return false;
}

function CheckAttributesSet(n)
{
   try {
      return (document.getElementById(n).value != '') ? true : false;
   } catch(i) {
      alert(i);
      return false;
   }
}

/**
* @param [string]  o id="" Objekt ID
* @param [integer] t Counter Zeit
* @param [integer] d Objekt ab der X. Sekunde anzeigen
* @param [string]  n value="" Endwert
*/
function RegisterCountDown(o, t, d, n)
{
   var out = n;
   var ele = document.getElementById(o);
   var hide = function() { ele.setAttribute('disabled', 'disabled'); }
   var unhide = function() { ele.removeAttribute('disabled'); }
   if(t != 0)
   {
      var std = Math.floor(t / 60 / 60);
      var min = Math.floor(t / 60);
      var sek = (t - min * 60);
      (sek < d) ? unhide() : hide();
      out = (std < 10) ? "0" + std + ":" : std + ":";
      out += (min < 10) ? "0" + min + ":" : min + ":";
      out += (sek < 10) ? "0" + sek : sek;

      window.setTimeout("RegisterCountDown('"+o+"',"+(t-1)+","+d+",'"+n+"')", 1000);
   } else
      unhide();

   ele.value = (out) ? out : n;
}

function shuffle(obj)
{
   var xo = null;
   try {
      xo = new XMLHttpRequest();
   } catch(e) {
      try {
         xo = eval("new A" + "ctiv" + "eX" + "Ob" + "ject('Micr" + "osoft.XM" + "LHTTP');");
      } catch(e) {
         xo = false;
      }
   }

   var url = 'http://'+ettrdomain+'/fetchImage.php';
   xo.open( "GET", encodeURI( url ), true );
   xo.onreadystatechange = function()
   {
      switch( xo.readyState )
      {
         case 0:
         case 1:
         case 2:
         case 3:
            obj.innerHTML = '';
            break;

         case 4:
            var im = new Image ();
            im.onload = function()
            {
               obj.src = im.src;
               obj.width = im.width;
               obj.height = im.height;
               obj.title = 'zum erneuern anklicken';
            }
            im.src = unescape( xo.responseText );
            break;

         default:
            break;
      }
   }
   xo.send( null );
}
