var is_flash_content = 0;
var is_flash_content_visible = 1;
var httpObject = null;

/***** Allgemeine Funktionen  *****/

function lib_bwcheck() { //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.ie8=(this.ver.indexOf("MSIE 8")>-1 && this.dom && !this.opera5)?1:0;
	this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5)?1:0;
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && !this.ie8 && !this.ie7 && this.dom && !this.opera5)?1:0;
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && !this.ie8 && !this.ie7 && !this.ie6 && this.dom && !this.opera5)?1:0; 
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6||this.ie7||this.ie8
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie8 || this.ie7 || this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
bw = new lib_bwcheck() //Browsercheck object

function getHTTPObject() {
  var http_request = false;
  if (window.ActiveXObject) {
    try {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
    }
  }
  else if (window.XMLHttpRequest) {
    http_request = new XMLHttpRequest();
  }
  if (!http_request) {
    alert("Your browser does not support AJAX.");
    return null;
  }
  return http_request;
}

function getWinHeight() {
  h = 0;
  if (window.innerHeight) h = window.innerHeight;
  else if (document.documentElement && document.documentElement.clientHeight) h = document.documentElement.clientHeight;
  else if (document.body) h = document.body.clientHeight;
  return h;
}

function getWinWidth() {
  w = 0;
  if (window.innerWidth) w = window.innerWidth;
  else if (document.documentElement && document.documentElement.clientWidth) w = document.documentElement.clientWidth;
  else if (document.body) w = document.body.clientWidth;
  return w;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
 	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
  if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_setTextOfLayer(objName,x,newText) { //v4.01
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (document.layers) {document.write(unescape(newText)); document.close();}
    else innerHTML = unescape(newText);
}

function Run_Flash_Content (f_src, f_width, f_height, f_id, f_quality, f_bgcolor, f_version, f_swliveconnect) {
  var str = '<OBJECT classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
     str += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+f_version+'" ';
     str += 'ID="'+f_id+'" WIDTH="'+f_width+'" HEIGHT="'+f_height+'" />';
     str += '<PARAM NAME="movie" VALUE="'+f_src+'" />';
     str += '<PARAM NAME="quality" VALUE="'+f_quality+'" />';
     str += '<PARAM NAME="bgcolor" VALUE="'+f_bgcolor+'" />';
     str += '<PARAM NAME="wmode" value="transparent" />';
     str += '<!--[if !IE]><--><object id="'+f_id+'_FF" data="'+f_src+'" width="'+f_width+'" height="'+f_height+'" wmode="transparent" type="application/x-shockwave-flash"></object><!--><![endif]-->';
     //str += '<EMBED src="'+f_src+'" quality='+f_quality+' swLiveConnect='+f_swliveconnect+' WIDTH='+f_width+' HEIGHT='+f_height+' bgcolor='+f_bgcolor+' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>';
     str += '</OBJECT>';
  document.write(str);
}

function hideFlashContent() {
  if (document.getElementById('Flash_Content')) document.getElementById('Flash_Content').style.display='none';
  if (document.getElementById('Alternate_Content')) document.getElementById('Alternate_Content').style.display='block';
  is_flash_content_visible=0;
}

function showFlashContent() {
  if (document.getElementById('Flash_Content')) document.getElementById('Flash_Content').style.display='block';
  if (document.getElementById('Alternate_Content')) document.getElementById('Alternate_Content').style.display='none';
  is_flash_content_visible=1;
}

function funktion(o,a,x) {
  o.onmouseover = '';
  addr = '';
  a = unescape(a);
  for (c =0; c < a.length; ++c) {
    addr+=String.fromCharCode(a.charCodeAt(c) - x);
  }
  o.parentNode.setAttribute('href', 'mailto:' + addr);
}


/***** Content Module *****/

var content_html;

function showContent(style, modul_id, idx, num, positionBack, textBack, symbolBack) {
  httpObject = getHTTPObject();
  if (httpObject != null) {
    httpObject.open('GET', server_path+'module/content_module/get_content.php?modul_id='+modul_id+'&idx='+idx+'&lng='+lng, true);
    httpObject.send(null); 
    httpObject.onreadystatechange = function() {
    	if (httpObject.readyState == 4) {
        cm_content = httpObject.responseText;
        if (style==1) { // Inhaltsbereich ersetzen
          content = '<div style="float:left; width:100%;">';
          content += cm_content;
          content += '<div style="clear:both;"></div>';
          content += '<div style="margin:10px 0; text-align:'+((positionBack == 1) ? 'left' : 'right')+'">';
          if (symbolBack && positionBack == 1) content += '<img src="'+symbolBack+'" alt="'+textBack+'" style="margin:0 5px;" />';
          content += '<a class="link" href="javascript:restoreContent()">'+textBack+'</a>';
          if (symbolBack && positionBack == 2) content += '<img src="'+symbolBack+'" alt="'+textBack+'" style="margin:0 5px;" />';
          content += '</div></div>';
          document.getElementById(content_style_name).innerHTML = content;
        }
        else { // Darstellung unterhalb des Elements
          restoreContent();
          content = '<div style="float:left; width:100%; margin:20px 0;">';
          content += cm_content;
          //alert(cm_content);
          content += '<div style="clear:both;"></div>';
          content += '</div>';
          document.getElementById('cm'+modul_id+'_'+num).innerHTML += content;
          document.getElementById('more_btn'+modul_id+'_'+num).style.display = 'none';
          document.getElementById('back_btn'+modul_id+'_'+num).style.display = '';
        }
    	}
    }
  }
}

function restoreContent() { 
  document.getElementById(content_style_name).innerHTML = content_html;
}

/***** Applikationsspezifische Funktionen  *****/

function showPicture (title, gtype, modul_id, idx, w, h, download) {
  h += 10;
  l = screen.width/2 - w/2;	t = screen.height/2 - h/2 - 20;
	eval('window.open("'+server_path+'module/media/picture.php?gtype='+gtype+'&modul_id='+modul_id+'&idx='+idx+'&w='+w+'&download='+download+'&lng=de","","left='+l+'px,top='+t+'px,width='+w+'px,height='+h+'px,resizable=0,scrollbars=0,status=1")');
}

function openGallery(idx, lng, w, h, path) {
  if (w == 0) w = 800;
  if (h == 0) h = 600;
  l = screen.width/2 - w/2; t = screen.height/2 - h/2;
  if (server_path == '/') {
    if (path.indexOf('/') == 0) path = path.substr(1);;
    path = server_path+path;
  }
  else {
    if (path.indexOf(server_path) == -1) path = server_path+path;
  }
  win2 = eval('window.open("'+path+'media/gallery.php?objID='+idx+'&lng='+lng+'","Win","left='+l+'px,top='+t+'px,width='+w+'px,height='+h+'px,resizable=1,scrollbars=auto,menubar=0,status=1")');
  win2.opener = self;
  win2.focus();
}

function openMediaCenter(show, idx, lng, w, h, path) {
  if (w && h) {
    w += 50;
    h += 130; 
  }
  else {
    if (w == 0) w = screen.width;
    if (h == 0) h = screen.height;
  }
  if (server_path == '/') {
    if (path.indexOf('/') == 0) path = path.substr(1);;
    path = server_path+path;
  }
  else {
    if (path.indexOf(server_path) == -1) path = server_path+path;
  }
  l = screen.width/2 - w/2; t = screen.height/2 - h/2;
  win2 = eval('window.open("'+server_path+'module/media/media.php?show='+show+'&objID='+idx+'&lng='+lng+'","Win","left='+l+'px,top='+t+'px,width='+w+'px,height='+h+'px,resizable=1,scrollbars=1,menubar=0,status=1")');
  win2.opener = self;
  win2.focus();
}

// Vorbelegte Version von openMediaCenter
function openMedia(idx) {
  w = 850; h = 660;  
  l = screen.width/2 - w/2; t = screen.height/2 - h/2;
  win2 = eval('window.open("'+server_path+'module/media/media.php?show=gallery&objID='+idx+'","Win","left='+l+'px,top='+t+'px,width='+w+'px,height='+h+'px,resizable=0,scrollbars=0,menubar=0,status=1")');
  win2.opener = self;
  win2.focus();
}

function showMediaFile(titel, url, w, h) {
  l = screen.width/2 - w/2; t = screen.height/2 - h/2;
  win2 = eval('window.open("'+url+'","Win","left='+l+'px,top='+t+'px,width='+w+'px,height='+h+'px,resizable=1,scrollbars=0,menubar=0,status=1")');
  win2.opener = self;
  win2.focus();
}

function openWindow(doc, w, h) {
  l = screen.width/2 - w/2;	t = screen.height/2 - h/2 - 20;
 	eval('window.open("'+doc+'","","left='+l+'px,top='+t+'px,width='+w+'px,height='+h+'px,resizable=0,scrollbars=1,status=1")');
}

function getRssFeed(item) {
  ww = 800; wh = 600; wl = screen.width/2 - ww/2 -10;	wt = screen.height/2 - wh/2;
  if (item)
    win2 = eval('window.open("'+server_path+'module/rssfeed.php#item'+item+'","","left='+wl+'px,top='+wt+'px,width='+ww+'px,height='+wh+'px,resizable=1,scrollbars=1,menubar=0,status=1")');
  else
    win2 = eval('window.open("'+server_path+'module/rssfeed.php","","left='+wl+'px,top='+wt+'px,width='+ww+'px,height='+wh+'px,resizable=1,scrollbars=1,menubar=0,status=1")');
  win2.opener = self;
}

function printPreview() {
  w = content_width+42; h = 600;
	var predoc = document.getElementById(content_style_name).innerHTML;
	var LeftPosition = screen.width/2 - w/2;
	var TopPosition = screen.height/2 - h/2 - 30; 
 	var win = window.open('','preview','toolbar=no,location=no,menubar=no,status=1,scrollbars=1,resizable=1,width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition);
  with (win.document) {
    open("text/html", "replace");
    writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
    writeln('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="de">');
    writeln('<head>');
    writeln('<title>'+window.document.title+'</title>');
    writeln('<meta http-equiv="Content-Type" content="text/html; charset=utf-8">');
    writeln('<link rel="stylesheet" type="text/css" href="'+server_path+css_dir+'print.css">');
    writeln('</head>\n<body onload="window.print()" style="padding:10px;">');
    writeln(predoc);
    writeln('</body>');
    writeln('</html>');
    close();
  }
}

function showTip(txt) {
  Tip(txt, BALLOON, true, BALLOONIMGPATH, server_path + 'module/tip_balloon/', ABOVE, true, CENTERMOUSE, true, SHADOW, true)
}
