/*
	$Id: global.js,v 1.1.1.1 2004/08/11 16:01:34 root Exp $
*/

//-- basics --
// "JavaScript-Error"-Unterdrueckung ggf. aktivieren:
// window.onerror = null; // errorcatcher script?

// so dick?
function BrowserDetection() {
	this.agent		= navigator.userAgent;
	this.browser 	= navigator.appName;
	this.ac 		= navigator.appCodeName;
	this.version 	= navigator.appVersion;
	this.DOM 		= document.getElementById ? true : false; // Netscape V6 + MSIE >= V5

	this.b = this.browser;
	if (this.browser == "Netscape") this.b = "ns";
	if (this.browser.indexOf("Explorer") != -1) this.b = "ie";
	
	this.pf = "n.A.";
	if (this.b == "ns" && this.DOM) {this.version = String(this.version + navigator.userAgent);}
	if (this.version.indexOf("Win98") > -1 || this.version.indexOf("Windows 98") > -1) this.pf = "Win98";
	if (this.version.indexOf("Win95") > -1 || this.version.indexOf("Windows 95") > -1) this.pf = "Win95";
	if (this.version.indexOf("NT 3") > -1 || this.version.indexOf("NT3") > -1) this.pf = "NT3";
	if (this.version.indexOf("NT 5") > -1 || this.version.indexOf("NT5") > -1) this.pf = "NT5"; // WIN 2000
	if (this.version.indexOf("2000") > -1 || this.version.indexOf("NT4") > -1) this.pf = "2000";
	if (this.version.indexOf("Macintosh") != -1 || this.version.indexOf("Mac") > -1) this.pf = "Mac";
	if (this.version.indexOf("Sun") > -1) this.pf = "Sun";

	
	this.v = parseInt(this.version);
	if (this.version.indexOf("MSIE") > -1) {
		this.v = parseInt(this.version.substring(this.version.indexOf("MSIE")+5,this.version.lastIndexOf(";")));
	}
	
	if (this.version.indexOf("Netscape6") > -1) {
		this.v = parseInt(this.version.substring(this.version.indexOf("Netscape6/")+10,this.version.length));
	}

	this.layers 	= (this.v >= 4) ? true : false;
	this.opera 		= (this.agent.indexOf("Opera") != -1) ? true : false;
	
	this.ns 		= (this.b=="ns" && this.v >= 4);
	this.ns3 		= (this.b=="ns" && this.v == 3);
	this.ns4 		= (this.b=="ns" && this.v == 4);
	this.ns5 		= (this.b=="ns" && this.v == 5);
	this.ns6 		= (this.b=="ns" && this.v == 6);
	
	this.ie 		= (this.b=="ie" && this.v >= 4);
	this.ie3 		= (this.version.indexOf("MSIE 3") != -1);
	this.ie4 		= (this.version.indexOf("MSIE 4") != -1);
	this.ie5 		= (this.version.indexOf("MSIE 5") != -1);
	this.ie55 		= (this.version.indexOf("MSIE 5.5") != -1);
	this.swapper 	= ((this.ie && this.v >=4) || this.ns && this.v >=3) ? true : false;
	
}

var is = new BrowserDetection();

// in <BODY> oder <FRAMESET> einzusetzen:
// onResize="resizer();"
// raushauen !!!!!!!!
if (is.ns) {
	b_width = top.window.innerWidth;
	b_height = top.window.innerHeight;
}

function resizer() {
    if (!is.ns4) {
		return;
	}
    if (b_width != top.window.innerWidth || b_height != top.window.innerHeight) {
		self.location.reload();
	}
}

function docAttrib (which, attr) {
	which = (which != null) ? "parent."+which+"." : "";
	
	var value = eval(which + (attr==0)
					? (is.ns) ? "\"window.innerWidth\"" : "\"document.body.clientWidth\""
					: (is.ns) ? "\"window.innerHeight\"" : "\"document.body.clientHeight\""
				);

	if (is.pf != "Mac") {
		value += (is.ie) ? 14 : -2;
	}

	return value; 
} 

var remoteWin = false;
function openWin(datei, breite, hoehe, x, y, scrolling) {
	if (!scrolling) {
		scrolling = 0;
	}
	var fenstereigenschaften = "resizable=yes,toolbar=0,scrollbars="+scrolling+",status=0,directories=0,menubar=0,location=0,width="+breite+",height="+hoehe;

	var win_width  = window.screen.width;
	var win_height = window.screen.height;
	
	if (top.is.v >= 4) {
	  	//wenn zwei Monitore am Mac angeschlossen sind... welches mac OS? a.d.R.
		var secondMon = 0;
		if (win_width >= 1600) {
			win_width = win_width/2;
			secondMon = win_width;
		}

		x = (x<0) ? secondMon+(win_width-breite)/2 : 0;
		y = (y<0) ? (win_height-hoehe)/2 : 0;
	
		fenstereigenschaften += ",screenX="+x+", left="+x;
		fenstereigenschaften += ",screenY="+y+", top="+y;
	}
	// ist Fenster bereits geoeffnet; wenn bei MSIE ja - schliesse.
	if (is.ie && (remoteWin.closed == false)) {
		remoteWin.close();
	}
	remoteWin = window.open(datei, "REMOTEWIN", fenstereigenschaften);
	if (top.is.v >= 4) {
		remoteWin.focus();
	}
}

//-- image handling --
pimg = new Array();

function imgpre(name, srcon, srcoff) {
	pimg[name] = new Array((new Image).src=srcoff, (new Image).src=srcon);
}

// anzugeben ist in imgswp:
//  name des bildes und des pimg-elementes
//  1 od. 0 fuer highlighted oder normal
//	layobj, wenn das bild in einem layer liegt, der bereits als layerobj initialisiert wurde, oder null
//  layname wenn das bild in einem layer liegt, der noch nicht als layerobj initialisiert wurde

// not referenced!
function imgswp(name, onoff, layobj, layname) {
	imgobj = false;
	if (layobj) {
		imgobj = 'layobj.img';
	} else {
		if (layname) {
			imgobj = 'document.images';
			if (is.ns4) {
				imgobj = 'document.layers["'+layname+'"].'+imgobj;
			}
		}
	}
	if (imgobj) {	
		imgobj = eval(imgobj);
		imgobj[name].src = pimg[name][onoff].src;
	}
}

function img_swap(frame, layer, nestlayer, which, onOff) {	
	if (layer) {
		var simage = new Layer(layer,nestlayer,frame);
		var bildpfad = simage.img[which].src;
	} else {
		if (frame) {
			var simage = parent[frame].document.images[which];
		} else {
			var simage = document.images[which];
		}
		var bildpfad = simage.src;
	}

	var bildname = bildpfad.substring(bildpfad.lastIndexOf("/")+1, bildpfad.length);
	var extension = bildname.substring(bildname.lastIndexOf("."), bildname.length);
	
	if (bildname.indexOf("_mo") > -1) {
		bildname = bildname.substring(0,bildname.lastIndexOf("_mo"));
	} else {
		bildname = bildname.substring(0,bildname.lastIndexOf("."));
	}
	bildpfad = bildpfad.substring(0,bildpfad.lastIndexOf("/")+1);
	
	if (layer) {
		if (onOff) {
			simage.img[which].src = bildpfad+bildname+"_mo"+extension;
		} else {
			simage.img[which].src = bildpfad+bildname+extension;
		}
	} else {
		if (onOff) {
			simage.src = bildpfad+bildname+"_mo"+extension;
		} else {
			simage.src = bildpfad+bildname+extension;
		}
	}
}

//-- layer handling --
function LayerExist(id,nested_in_id,frame) {

	var exist = false;
	
	if (is.DOM) {
		exist = (frame) ? parent.frames[frame].document.getElementById(id) : document.getElementById(id);
	} else {
		if (top.is.ns) {
			if (!frame) {
				exist = (nested_in_id) ? document.layers[nested_in_id].document.layers[id] :  document.layers[id];
			} else {
				exist = (nested_in_id) ? parent.frames[frame].document.layers[nested_in_id].document.layers[id] : parent.frames[frame].document.layers[id];
			}
		} else if (top.is.ie) {
			exist = (!frame) ? document.all[id] : parent.frames[frame].document.all[id];
		}
	}
	
	if (!exist) {
		exist = false;
	}
	
	return exist;
}

function Layer(id, nested_in_id, frame) {
	//if (!is.ns5 && !Layer.set && !frame) {LayerInit();}
	
	if (!LayerExist(id,nested_in_id,frame)) {this.exist = false; return false;}
    this.exist = true;
    
    this.frame = frame || self;
	
	if (is.DOM) {
		this.elm = this.event = (frame) ? parent.frames[frame].document.getElementById(id) : document.getElementById(id);
		this.css = this.elm.style;
		this.img = this.event = (frame) ? parent.frames[frame].document.images : document.images;
		this.doc = (frame) ? parent.frames[frame].document : document;
		this.real ='document.getElementById("'+id+'")';
		if  (frame) this.real = 'parent.frames["'+frame+'"].'+this.real;
		this.x = this.elm.offsetLeft;
		this.y = this.elm.offsetTop;
		this.w = this.elm.offsetWidth;
		this.h = this.elm.offsetHeight;
	} else {
		if (is.ns4) {
			// do we ever need frames??
			if (!frame) {
				this.css = (nested_in_id) ? document.layers[nested_in_id].document.layers[id] :  document.layers[id];
				this.img = (nested_in_id) ? document.layers[nested_in_id].document.layers[id].document.images : document.layers[id].document.images;
			} else {
				this.css = (nested_in_id) ? parent.frames[frame].document.layers[nested_in_id].document.layers[id] :  parent.frames[frame].document.layers[id];
				this.img = (nested_in_id) ? parent.frames[frame].document.layers[nested_in_id].document.layers[id].document.images : parent.frames[frame].document.layers[id].document.images;
			}
			
			this.elm  = this.event = this.css;
			this.doc  = this.css.document;
			this.real = 'document.layers["'+id+'"]';
			if (nested_in_id) {
				this.real = 'document.layers["'+id+'"].'+this.real;
			}
			if (frame) {
				this.real = 'parent.frames["'+frame+'"].'+this.real;
			}
			this.x = this.css.left;
			this.y = this.css.top;
			//this.w = this.css.clip.width;
			//this.h = this.css.clip.height;
			this.w = this.css.document.width;
			this.h = this.css.document.height;
			
		
		} else if (is.ie) {
			
			this.css  = (frame) ? parent.frames[frame].document.all[id].style : document.all[id].style;
			this.img  = this.event = (frame) ? parent.frames[frame].document.images : document.images;
			this.elm  = this.event = (frame) ? parent.frames[frame].document.all[id] : document.all[id];
			this.doc  = (frame) ? parent.frames[frame].document : document;
			this.real = 'document.all["'+id+'"]';
			if  (frame) {
				this.real = 'parent.frames["'+frame+'"].'+this.real;
			}
			
			this.x  = this.elm.offsetLeft;
			this.y = this.elm.offsetTop;
			//this.w = this.css.pixelWidth;
			this.w = this.elm.offsetWidth;
			//this.h = this.css.pixelHeight;
			this.h = this.elm.offsetHeight;
		}
	}
	
	this.id = id;
	this.nested_in_id = nested_in_id;
	this.slideActive = false;
	this.obj = id + "Layer";
	
	eval(this.obj + " = this");
	
	return true; // Netscape 4.05
}

function LayerShow() {
	this.css.visibility = (is.ns4)? "show" : "visible";
}
// anon-function ??
Layer.prototype.show = LayerShow;


function LayerHide() {
	this.css.visibility = (is.ns4)? "hide" : "hidden";
}
// anon-function ??
Layer.prototype.hide = LayerHide;

function LayerIsVisible() {
	if (is.ns4) {
		return (this.css.visibility=='hide')? false:true;
	} else {
		return (this.css.visibility=='hidden')? false:true;
	}
}
// not referenced?? anon-function ??
Layer.prototype.isvisible = LayerIsVisible

function LayerClipTo(t, r, b, l) {
	if (t==null) t = this.clipValues('t');
	if (r==null) r = this.clipValues('r');
	if (b==null) b = this.clipValues('b');
	if (l==null) l = this.clipValues('l');

	if (is.ns && !is.DOM) {
		this.css.clip.top = t;
		this.css.clip.right = r;
		this.css.clip.bottom = b;
		this.css.clip.left = l;
	}
	else if (is.ie || is.DOM) {
		this.css.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)";
	}
}
//anon-function ??
Layer.prototype.clipTo = LayerClipTo;

function LayerClipBy(t, r, b, l) {
	this.clipTo(this.clipValues('t')+t, this.clipValues('r')+r, this.clipValues('b')+b, this.clipValues('l')+l);
}
//anon-function ??
Layer.prototype.clipBy = LayerClipBy;

function LayerClipInit(clipTop, clipRight, clipBottom, clipLeft) {
	if (is.ie) {
		if (arguments.length==4) {
			this.clipTo(clipTop, clipRight, clipBottom, clipLeft);
		} else {
			if (is.ie && is.v >= 4) {
				this.clipTo(0, this.css.pixelWidth, this.css.pixelHeight, 0);
			}
		}
	}
}
//anon-function ??
Layer.prototype.clipInit = LayerClipInit;

function LayerClipValues(which) {
	if (is.ie || is.DOM) {
		if (!this.css.clip) {
			// MSIE Fehler abfangen, wenn kein clip-im css/style vorhanden.
			this.clipInit();
		}
		var clipval = this.css.clip.replace(/pt/,"px"); // Netscape 6 liefert pt, wenn werte == 0
		var clipv = clipval.split("rect(")[1].split(")")[0].split("px");
	}
	
	if (which=="t") { return (is.ns && !is.DOM)? this.css.clip.top : Number(clipv[0]); }
	if (which=="r") { return (is.ns && !is.DOM)? this.css.clip.right : Number(clipv[1]); }
	if (which=="b") { return (is.ns && !is.DOM)? this.css.clip.bottom : Number(clipv[2]); }
	if (which=="l") { return (is.ns && !is.DOM)? this.css.clip.left : Number(clipv[3]); }
}
//anon-function ??
Layer.prototype.clipValues = LayerClipValues;

function LayerMoveTo(x, y) {
	if (x!=null) {
		this.x = x;
		if (is.ns) {
			this.css.left = this.x;
		} else {
			this.css.pixelLeft = this.x;
		}
	}
	if (y!=null) {
		this.y = y;
		if (is.ns) {
			this.css.top = this.y;
		} else {
			this.css.pixelTop = this.y;
		}
	}
}
//anon-function ??
Layer.prototype.moveTo = LayerMoveTo;

function LayerMoveBy(x, y) {
	if (x != null) {
		x += this.x;
	}
	if (y!=null) {
		y += this.y;
	}
	
	this.moveTo(x, y)
}
//anon-function ??
Layer.prototype.moveBy = LayerMoveBy;

var slideActive = false;
var someActive = false;
var nextSlide = false;
var next_slideObj = false; 
var next_fn = false;

function LayerSlideTo(endx, endy, nc, speed, fn, sync) {
	if (!sync && (this.slideActive || someActive) ) {
		nextSlide = this.obj+".slideTo("+endx+","+endy+","+inc+","+speed+",\""+fn+"\")";
		return;
	}
	nextSlide = false;
	if (endx == null) { endx = this.x; }
	if (endy==null) { endy = this.y; }
	var distx = endx-this.x;
	var disty = endy-this.y;
	this.slideStart(endx, endy, distx, disty, inc, speed, fn);
}
//anon-function ??
Layer.prototype.slideTo = LayerSlideTo;

function LayerSlideBy(distx, disty, inc, speed, fn) {
	var endx = this.x + distx;
	var endy = this.y + disty;
	this.slideStart(endx, endy, distx, disty, inc, speed, fn)
}
//anon-function ??
Layer.prototype.slideBy = LayerSlideBy;

function LayerSlideStart(endx, endy, distx, disty, inc, speed, fn) {
	if (this.slideActive) { return; }
	if (!inc) { inc = 10; }
	if (!speed) { speed = 20; }
	var num = Math.sqrt(Math.pow(distx,2) + Math.pow(disty,2))/inc;
	if (num==0) { return; }
	var dx = distx/num;
	var dy = disty/num;
	if (!fn) { fn = null; }
	someActive = true;
	this.slideActive = true;
	this.slide(dx, dy, endx, endy, num, 1, speed, fn)
}
//anon-function ??
Layer.prototype.slideStart = LayerSlideStart;

function LayerSlide(dx,dy,endx,endy,num,i,speed,fn) {
	if (!this.slideActive) { return; }
	
	if (i++ < num) {
		this.moveBy(dx, dy);
		this.onSlide();
		if (this.slideActive) {
			this.slideActive = setTimeout(this.obj+".slide("+dx+","+dy+","+endx+","+endy+","+num+","+i+","+speed+",\""+fn+"\")",speed);
		} else {
			this.onSlideEnd();
		}
	} else {
		this.slideActive = false;
		clearTimeout(this.slideActive);
		this.moveTo(endx, endy);
		this.onSlide();
		this.onSlideEnd();
		someActive = false;
		
		if (next_fn) {
			eval(next_fn);
			next_fn = false;
		}
		
		if (nextSlide) {
			eval(nextSlide);
			next_fn = fn;
		} else {
			eval(fn);
		}
	}
}

Layer.prototype.slide = LayerSlide;
Layer.prototype.onSlide = LayerOnSlide;
Layer.prototype.onSlideEnd = LayerOnSlideEnd;

function LayerOnSlide() {
	return;
}

function LayerOnSlideEnd() {
	return;
}

function LayerWrite(html) {
	if (is.ns && !is.DOM) {
		this.doc.open();
		this.doc.write(html);
		this.doc.close();
	} else {
		this.elm.innerHTML = html;
	}
}
//anon-function ??
Layer.prototype.write = LayerWrite;

function writeCSS(str,showAlert) {
	str = css('START')+str+css('END');
	document.write(str);
	if (showAlert) {
		alert(str);
	}
}

// generate var str different
function css(id, left, top, width, height, color, vis, z, other) {
	if (id=="START") {
		return '<STYLE TYPE="text/css">\n';
	} else if (id=="END") {
		return '</STYLE>';
	}
	var str = (left!=null && top!=null) ? '#'+id+' {position:absolute; left:'+left+'px; top:'+top+'px;' : '#'+id+' {position:relative;';
	if (arguments.length>=4 && width!=null) {
		str += ' width:'+width+'px;';
	}
	if (arguments.length>=5 && height!=null) {
		str += ' height:'+height+'px;';
		if (arguments.length<9 || other.indexOf('clip')==-1) {
			str += ' clip:rect(0px '+width+'px '+height+'px 0px);';
		}
	}
	if (arguments.length>=6 && color!=null) {
		str += (is.ns) ? ' layer-background-color:'+color+';' : ' background-color:'+color+';';
	}
	if (arguments.length>=7 && vis!=null) {
		str += ' visibility:'+vis+';';
	}
	if (arguments.length>=8 && z!=null) {
		str += ' z-index:'+z+';';
	}
	if (arguments.length==9 && other!=null) {
		str += ' '+other;
	}
	str += '}\n'
	return str;
}

//-- shop spezials --
function submitPrintform (gId, aId) {
	var printForm = document.getElementById(gId);
	if(printForm)
	{
		printForm.articleId.value = aId;
		printForm.submit();
	}
}

function updatePrintID(intNewID)
{
	for(intF=0;intF < document.forms.length;intF++)
	{
		if(document.forms[intF].name.indexOf("printFormX") == -1)
			if(document.forms[intF].printId) document.forms[intF].printId.value=intNewID;
	}
}

var zit = 'undef';
function showzit(arg1) {
	if (zit=='undef') {
		zit = new Layer('zitLayer');
		
		if((is.DOM) && (is.ie))
			y = window.event.y - 20; // - zit.h - 30
		else
			y=0;

		zit.moveTo(280,y);
	}
	switch (arg1) {
		case 1: zit.show(); break;
		case 2: zit.hide(); break;
	}
}

function switchfunc(arg1) {
	clearTimeout(this.tmr);
	switch (arg1) {
		case 0: this.tmr = setTimeout(this.objname+'.switcher(2)',100); break;
		case 1: this.show(); break;
		case 2: this.hide(); break;
	}
}

var menus = new Array();

function initMenue() {
	z0 = 0;
	while (LayerExist('HeadDiv'+z0)) {

		menus[z0] = new Layer('MenueDiv'+z0);

		menus[z0].head = new Layer('HeadDiv'+z0);
		menus[z0].head.moveTo( (z0==0)? 190: menus[z0-1].head.x+menus[z0-1].head.w+10, 75 ); // defaultpositionierung !
		menus[z0].head.show();
		menus[z0].moveTo(menus[z0].head.x,menus[z0].head.y+menus[z0].head.h);
		menus[z0].tmr = 0;
		menus[z0].switcher = switchfunc;
		menus[z0].objname = 'menus['+z0+']';

		eval(menus[z0].head.real+'.onmouseover= new Function ("menus['+z0+'].switcher(1)")');
		eval(menus[z0].head.real+'.onmouseout= new Function ("menus['+z0+'].switcher(0)")');
		eval(menus[z0].real+'.onmouseover= new Function ("menus['+z0+'].switcher(1)")');
		eval(menus[z0].real+'.onmouseout= new Function ("menus['+z0+'].switcher(0)")');

		z0++;
	}
}

function submitItemsToBasket (form, value) {
	var ItemsForm = document.getElementById(form);
	if(ItemsForm)
	{
		ItemsForm.into_basket_event.value = value;
		ItemsForm.submit();
	}
}
function checkField(field) {
  if (field==0) {
   alert(unescape("Bitte geben Sie die gew%FCschte Menge an")); 
    return false;
  }

}
