//
// JavaScript: Miscellanous Functions
// 
// Internet Explorer, Konqueror, Mozilla, Netscape, Opera (Linux, OS/2, Windows)
//

var COL_LINK_ACTIVE="#0000ff", COL_LINK_PASSIVE="#404080";
var STY_LINK_ACTIVE="underline", STY_LINK_PASSIVE="underline";
var img_x=0, img_y=0, tag=0, __canvas=0;
 
if (typeof(__sesam__) == "undefined" && self == top) {		// reload frameset 
  with (self.location) {
    var dom = "scambaiter.info/";
    var loc = hostname + pathname;
    var cut = loc.lastIndexOf(dom) + dom.length;
    replace("http://" + loc.substring(0, cut) + "?link=" + loc.substring(cut, loc.lastIndexOf(".phtml")));
  }
}

if (document.layers)      	// Netscape 4.x is special
{
  function ehandler(e)
  {
    if (e.type == "mouseout") {
      tag.visibility = "hide";
      window.status = "";
    }
    else {
      tag.visibility = "show";
      window.status = tag.status;
    }
  }
}

window.onload = function() { initiate(); } 

function initiate()
{
  if (document.getElementById) {
    if (document.search && document.search.q) {
      var v = 'Suche';

      with (document.search) {
        q.value = v;
        q.onblur = function() { if (this.value == '') this.value = v; }; 
        q.onfocus = function() { if (this.value == v) this.value = ''; }; 
        q.title = 'Sie können dieses Feld leer lassen, wenn Sie den Suchbegriff mit der Maus markieren';
        s.onmousedown = function() { google(); };
        s.title = 'Sie können den Suchbegriff auch mit der Maus markieren und hier klicken';
      }
    }
  }
}

function google()
{
  var q = '', r;

  if (self.getSelection) {
    q = self.getSelection();
  }
  else if (self.document.getSelection) {
    q = self.document.getSelection();
  }
  else if (self.document.selection) {
    if (self.document.selection.type.toLowerCase() == 'text')
      q = self.document.selection.createRange().text;
  }

  if (q != '')
    document.search.q.value = q;
}

function hilite(obj, mode)
{
  if (obj.style) with (obj.style) {
    if (mode) {
      color = COL_LINK_ACTIVE;
      textDecoration = STY_LINK_ACTIVE;
    }
    else {
      color = COL_LINK_PASSIVE;
      textDecoration = STY_LINK_PASSIVE;
    }
  }

  else if (document.layers) { // Netscape 4.x: hover
    if (!tag) {
      tag = new Layer(1);
      tag.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
      tag.onmouseover = ehandler;
      tag.onmouseout  = ehandler;
    }

    if (mode) {
      tag.left = obj.x;
      tag.top  = obj.y;
      tag.status = obj.text;
      tag.document.open();
      tag.document.write("<nobr><a href='" + obj.href + "' target='" + obj.target + "' class='hover'>"+ obj.text + "<\/a><\/nobr>");
      tag.document.close();
      tag.visibility = "show";
      window.status = obj.text;
    }
    else {
      tag.visibility = "hide";
      window.status = "";
    }
  }
}

function openurl(url)
{
  var w = window.open(url, "sbwindow", "width=800,height=600,menubar=yes,scrollbars=yes,status=yes,left=1,top=1");

  w.focus();    
}

function openimg(obj)
{
  var src;

  if (obj.storage)
    src = obj.storage;
  else
    obj.storage = src = obj.pathname;	// use absolute path

  if (obj.storage && (document.getElementById || document.all)) { 

    obj.href = "javascript:resizeimg()";
    obj.target = "";

    if (!__canvas || __canvas.closed)
      __canvas = window.open("", "canvas", "width=660,height=500,resizable=yes,scrollbars=yes,menubar=no,location=no,status=yes,left=1,top=1"); //,dependent=yes");

    __canvas.document.open("text/html");
    __canvas.document.write('<html><head><title><\/title><\/head><body style="margin:0;padding:0" oncontextmenu="return false;"><div style="position:absolute;left:0px;top:0px"><img src="'+src+'" alt="" border="0"><\/div><\/body><\/html>');
    __canvas.document.close();

    __canvas.focus();

    window.setTimeout("resizeimg()", 500);
  }
}

function resizeimg()
{
  var x, y;

  if (!__canvas.document.images[0].complete) {
    window.setTimeout("resizeimg()", 500);
    return;
  }

  x = img_x ? img_x : __canvas.document.images[0].width;
  y = img_y ? img_y : __canvas.document.images[0].height;  

  x = x ? x : 640;
  y = y ? y : 480;

  if (screen) {
    x = (x < screen.availWidth) ? x : screen.availWidth;
    y = (y < screen.availHeight) ? y : screen.availHeight;
  }

  if (__canvas.resizeTo) {

    if (__canvas.innerHeight) {
      if (__canvas.outerWidth < __canvas.innerWidth)
        __canvas.resizeBy(x - __canvas.outerWidth, y - __canvas.innerHeight);
      else
        __canvas.resizeBy(x - __canvas.innerWidth, y - __canvas.innerHeight);
    }
    else if (__canvas.document.body.clientHeight) {
      __canvas.resizeBy(x - __canvas.document.body.clientWidth, y - __canvas.document.body.clientHeight);
    }
    else
      __canvas.resizeTo(x, y);
  }

  __canvas.focus();
}

function popup(id, style, head, text)
{
  var p;

  if (document.getElementById) {
    if ((p = document.getElementById('popup'))) {

      if (p.parentNode.id == id) {
        p.parentNode.innerHTML = '';
        return;
      } 
      p.parentNode.innerHTML = '';
    }

    document.getElementById(id).innerHTML = '<div id="popup" class="popup" style="'+style+'" title="'+head+'"><table width="100%" border="0" cellspacing="0" cellpadding="2"><tr valign="top"><td class="pophead">'+head+'<\/td><td align="right"><img src="/gfx/close.gif" alt="X" border="1" title="Schlie&szlig;en" onclick="popoff();" style="cursor:pointer"><\/td><\/tr><\/table><div class="poptext">'+text+'<\/div><\/div>';
  }
  else
    alert("Ihr Browser ist völlig veraltet und kann den Inhalt nicht darstellen.");
}

function popoff()
{
  if (document.getElementById)
    document.getElementById('popup').parentNode.innerHTML = '';
}

function have_swf()
{
  var a = 0;

  if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) {
    if (navigator.mimeTypes['application/x-shockwave-flash'] && navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin)
      a = 1;
  }
  else if (document.getElementById) {	// beware of old browsers
    eval ('try{a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}if(a!=null)a=2;');
  }
  
  return a;
}

function inline_player(url, txt, cfg)
{
  var p;

  if ((cfg & 0x0F00) == 0x0200 && have_swf()) {
    p = '<embed src="sounds/mplayer.swf" type="application/x-shockwave-flash" width="200" height="20" quality="high" flashvars="file='+url+'&repeat=false&showeq=false&showdigits=true&showdownload=true&link='+url+'"><\/embed>';

    if ((cfg & 0x00F0) == 0x0020)	// with ActiveX
      p = '<obj'+'ect classid="CLSID:D27CDB6E-AE6D-11CF-96B8-444553540000" width="240" height="20"><param name="movie" value="sounds/mplayer.swf"><param name="quality" value="high"><param name="flashvars" value="file='+url+'&repeat=false&showeq=false&showdigits=true&showdownload=true&link='+url+'">'+p+'<\/object>';

    document.write('<span class="menu">'+p+' '+txt+'<\/span>');
  }
  else
    document.write("<a href='"+url+"' type='audio/mpeg'>"+(txt.length? txt:"<img src='gfx/hear.jpg' alt='Anh&ouml;ren' border='0'>")+"<\/a>");
}

function get_cookie(name)
{
  var a, c = window.document.cookie.split(';'), i;

  for (i = 0; i < c.length; i++) {
    a = c[i].split('=');
    if (a[0].indexOf(name) >= 0)
      return unescape(a[1]);
  } 
  return false;
}

function cfg_cookie(date)
{
  var c=0;

  with (window.document.config) {
    if (css[0].checked) c += 0x0003;
    if (css[1].checked) c += 0x0002;
    if (css[2].checked) c += 0x0001;
    if (mmi[0].checked) c += 0x0020;
    if (mmi[1].checked) c += 0x0010;
    if (mp3[0].checked) c += 0x0200;
    if (mp3[1].checked) c += 0x0100;
 }
  window.document.cookie = "CONFIG="+escape(c)+"; expires="+date.toGMTString()+"; path=/";

  window.location.reload();
}

function configurate()
{
  var c = get_cookie('CONFIG'), html;

  if (!c) c = 530;

  html = '<form class="menu" name="config" action=""><fieldset><legend>Einstellungen<\/legend><table width="98%" border="0" cellpadding="2" cellspacing="4"><tr valign="top"><td align="right" class="tech" width="100">Schriftgr&ouml;&szlig;e:<\/td><td class="tech"><input type="radio" name="css" value="3"'+(((c & 0x0F)==3)? ' checked="checked"': "")+'>Gro&szlig;e Schrift<br><input type="radio" name="css" value="2"'+(((c & 0x0F)==2)? ' checked="checked"': "")+'>Mittlere Schrift<br><input type="radio" name="css" value="1"'+(((c & 0x0F)==1)? ' checked="checked"': "")+'>Kleine Schrift<\/td><\/tr><tr valign="top"><td align="right" class="tech" width="100">Multimedia:<\/td><td class="tech"><input type="radio" name="mmi" value="2"'+((((c >> 4) & 0x0F)==2)? ' checked="checked"': "")+'>ActiveX verwenden (Internet Explorer...)<br><input type="radio" name="mmi" value="1"'+((((c >> 4) & 0x0F)==1)? ' checked="checked"': "")+'>Standard verwenden (alle Browser)<br><input type="radio" name="mmi" value="0"'+((((c >> 4) & 0x0F)==0)? ' checked="checked"': "")+'>Multimedia abstellen<\/td><\/tr><tr valign="top"><td align="right" class="tech" width="100">MP3-Spieler:<\/td><td class="tech"><input type="radio" name="mp3" value="2"'+((((c >> 8) & 0x0F)==2)? ' checked="checked"': "")+'><a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&promoid=BIOW" target="_blank">Adobe Flash Player<\/a> (verwendet den serverseitigen Player)<br><input type="radio" name="mp3" value="1"'+((((c >> 8) & 0x0F)==1)? ' checked="checked"': "")+'>Browser-Standard (verwendet die Einstellung des Browsers)<\/td><\/tr><tr valign="top"><td align="right" class="tech" width="100"><\/td><td class="tech"><input class="knopf" type="button" name="clear" value="Konfiguration entfernen" title="Die Konfiguration entfernen" onclick="cfg_cookie(new Date(1970,0,1))">&nbsp;&nbsp;&nbsp;&nbsp;<input class="knopf" type="button" name="store" value="Konfiguration speichern" title="Die Einstellungen im Browser speichern" onclick="cfg_cookie(new Date(2020,0,1))"><\/td><\/tr><\/table><\/fieldset><\/form>';

  if (!navigator.cookieEnabled && !window.document.cookie)
    alert('In Ihrem Browser sind die Cookies abgeschaltet.\nEine dauerhafte Konfiguration ist nicht möglich.')

  if (document.getElementById)
    popup('config','width:640px;top:50px;right:0;left:0;margin:auto;position:fixed;background:#E0E0E0;border:4px ridge white;','&nbsp;Konfiguration der Webseiten', html);
  else
    self.location.href = "config.phtml";
}