/*

version			: 0.2 + TW

functions.js	: contains general functions, which are needed project indepentent (for all dhtml projets). 
				: @since	06/2001
				: @author	alexanderhoth.com
				: @lastedit	
				
*/

// BrowserCheck Object
// provides most commonly needed browser checking variables
// 19990326

// Copyright (C) 1999 Dan Steinman
// Distributed under the terms of the GNU Library General Public License
// Available at http://www.dansteinman.com/dynapi/

function BrowserCheck() {
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
		this.v = parseInt(navigator.appVersion)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0)
	this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0)
	this.ie6 = (navigator.userAgent.indexOf('MSIE 6')>0)
	this.dom = (document.getElementByID != -1);
	this.min = (this.ns||this.ie)
}

// automatically create the "is" object
is = new BrowserCheck()

// output the css include line
stylesheet();

// LOCAL FUNCTIONS
function stylesheet () {
	if (is.dom) {
		document.write ("<link rel=\"stylesheet\" type=\"text/css\" href=\"/includes/css/ie5.css\"");
	} else if (is.ns4) {
		document.write ("<link rel=\"stylesheet\" type=\"text/css\" href=\"/includes/css/ns4.css\"");
	}
}

// GLOBAL FUNCTIONS
// Image Preloading
function preload(imgObj,imgSrc) {
	if (document.images){
	 	eval(imgObj + ' = new Image()');
	  	eval(imgObj + '.src = "' + imgSrc + '"');
	}
}

// Image Swapping
function changeImage(imgName, imgObj) {
		document.images[imgName].src = eval(imgObj+".src");
}



function showLayer (strLayer) {
	
	// if (!strLayer) return false;
	
	if (is.ie4) {
		document.all[strLayer].style.visibility = "visible";
	} else if (is.ns4){
		document.layers[strLayer].visibility = "show";
	} else if (is.dom){
		lyr = eval(document.getElementById(strLayer));
		lyr.style.visibility = "visible";
 	} 
}


function hideLayerAll (strKeyword) {
	
	// Versteckt alle Content Layer, die strKeyword im Namen tragen.
	// Beispiel:  hideLayerAll("content");
	
	if (is.ie4) {
		for (i = 0; i < document.all.length; i++) {
			
		 	if (document.all[i].tagName == "DIV") {
				if (document.all[i].id.indexOf(strKeyword) != -1) {
					hideLayer (document.all[i].id);
				}
			}
		}
	} else if (is.ns4) {
		for (i = 0; i < document.layers.length; i++) {
				if (document.layers[i].name.indexOf(strKeyword) != -1) {
					hideLayer (document.layers[i].name);
				}
		}
	} else if (is.dom) {
		for (i = 0; i < document.getElementsByTagName("div").length; i++) {
				
				if (document.getElementsByTagName("div")[i].id.indexOf(strKeyword) != -1) {
					hideLayer (document.getElementsByTagName("div")[i].id);
				}
				
		}
	}
}

function hideLayer (strLayer) {
	
	if (!strLayer) return false;
	

	if (is.ie4) {
		document.all[strLayer].style.visibility = "hidden";
	} else if (is.ns4){
		document.layers[strLayer].visibility = "hide";
	} else if (is.dom){
		lyr = eval(document.getElementById(strLayer));
		lyr.style.visibility = "hidden";
 	}

}

function toggleLayer (strLayer) {
	if (!strLayer) return false;

	if (is.ie4) {
		var mode = document.all[strLayer].style.visibility
		if (mode == "visible") hideLayer(strLayer);
		else showLayer(strLayer);		
	}
	else if (is.ns4) {
		var mode = document.layers[strLayer].visibility
		if (mode == "show") hideLayer(strLayer);
		else showLayer(strLayer);		
	}
	else if (is.dom) {
		var mode = document.getElementById(strLayer).style.visibility;
		if (mode == "visible") hideLayer(strLayer);
		else showLayer(strLayer);
	}
	
}

function ScreenCenter(){
	var ScreenWidth = 0;
	switch (is.b) {
		case "ie" : 
				ScreenWidth = document.body.clientWidth;
  				break;
		case "ns" : 
				ScreenWidth = window.innerWidth;
				break;
		default : 
				ScreenWidth = "Falscher Browser";
				break;
	}
	return ScreenWidth / 2;
}

function openpopup (url,name,w,h,switches,x,y) {
	
		widthdefault = "300";
		heightdefault = "300";
	
		var r  = "";
		var s  = "";
		var m  = "";
		var t  = "";
		var d  = "";
		var params  = "";
	
		if (!url) { url = "" } // oeffnet leeres fenster
		if (!name) { name = "popup" }
		if (!w) { w = "width=" + widthdefault } else { w = "width=" + w }
		if (!h) { h = ",height=" + heightdefault } else { h = ",height=" + h; }
	
		if (switches.indexOf("r") > -1 ) { r = ",resizable" }
		if (switches.indexOf("s") > -1 ) { s = ",scrollbars" }
		if (switches.indexOf("m") > -1 ) { m = ",menubar" }
		if (switches.indexOf("t") > -1 ) { t = ",toolbar" }
		if (switches.indexOf("d") > -1 ) { d = ",directories" }
	
		params = w + h + r + s + m + t + d;
	
		// funktion zum plazieren des Fensters an einer bestimmten Stelle
		// x und y geben x/y-Koordinaten von linker oberer Fensterecke an
		if (x && y && window.moveTo && screen) { 
			params += ",screenX=" + x + ",screenY=" + y;
		}
	
		// Popup oeffnen
		newwin = open (url, name, params) 
	
		// wenn es unterstuetzt wird: Popup nach vorne bringen
		if (window.focus) { newwin.focus() }
	
	}

function TW_swapImgRestore() { //v3.0
  var i,x,a=document.TW_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function TW_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.TW_p) d.TW_p=new Array();
    var i,j=d.TW_p.length,a=TW_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.TW_p[j]=new Image; d.TW_p[j++].src=a[i];}}
}

function TW_findObj(n, d) { //v4.0
  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=TW_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function TW_swapImage() { //v3.0
  var i,j=0,x,a=TW_swapImage.arguments; document.TW_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=TW_findObj(a[i]))!=null){document.TW_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
//-->
}	

function TW_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.TW_pgW=innerWidth; document.TW_pgH=innerHeight; onresize=TW_reloadPage; }}
  else if (innerWidth!=document.TW_pgW || innerHeight!=document.TW_pgH) location.reload();
}
TW_reloadPage(true);

// Bildwechsel
function bildwechsel(bildname,tauschbild)
{
document.images[bildname].src=tauschbild;
}

function encode(theform){
	theform.name.value = encodeURIComponent(theform.name.value);
	theform.anschrift.value = encodeURIComponent(theform.anschrift.value);
	theform.telfax.value = encodeURIComponent(theform.telfax.value);
	theform.email.value = encodeURIComponent(theform.email.value);
	theform.termin.value = encodeURIComponent(theform.termin.value);
	theform.file.value = encodeURIComponent(theform.file.value);
}



