/***************

Copyright (C) PEPPERZAK MULTIMEDIA GmbH 2001
Author: Christian Rienow
Purpose: BrowserDetect + Rollover

History:
	
*/

var app = new browser();

if (app.compat_d_layers)	{
	document.getElementById = ns4_getLayerById;
}


document.getImageById = app.compat_d_all ? ie_get_fromAll : (app.compat_d_layers ? ns_getImgById : dom_getImgById);

function inspect(inObj)	{
	var s = "";
	for (var p in inObj)	{
		s = s + p + ": " + inObj[p] + ";<br> ";
	}
	w = window.open("", "_blank");
	w.document.open();
	w.document.write(s);
	w.document.close();
}

function browser()	{
	this.compat_dom = (document.getElementById) ? 1 : 0;
	this.compat_d_all = (document.all) ? 1 : 0;
	this.compat_d_layers = (document.layers) ? 1 : 0;
	this.version_name = navigator.appVersion;
	this.ie5 = ((this.version_name.indexOf('MSIE') != -1) && this.compat_dom);
	this.ie4 = (this.compat_d_all && !this.compat_dom);
	this.ns4 = (this.compat_d_layers && !this.compat_dom);
	this.op5 = (this.compat_dom && (parseInt(this.version_name, 10) >= 5) && (navigator.appName.indexOf('Opera') != -1));
	this.ns6 = (this.compat_dom && (parseInt(this.version_name, 10) >= 5) && (navigator.userAgent.indexOf('Gecko') != -1));
	this.platform = (this.version_name.indexOf('Macintosh') != -1) ? 'mac' : ((this.version_name.indexOf('Win') != -1) ? 'win' : 'unix');
	this.scrollfactor = (this.platform == 'win') ? 10 : 1;
	this.scrollspeed = new Function ('inSpeed', 'return this.scrollfactor * inSpeed;');
	this.supported_browser = (this.ie5 || (this.ie4 && (this.platform == "win")) || this.ns4 || this.op5 || this.ns6);

	return this;
}

function ns4_getLayerById(inName)	{
	return ns4_searchTree(document, 'layers', inName);
}

function ns4_searchTree(inStart, inType, inName)	{
	var tree = inStart[inType];
	if (tree)	{
		for (var i = 0; i < tree.length; ++i)	{
			if (tree[i].name == inName)	{
				return tree[i];
			} else {
				var foundlayer = ns4_searchTree(tree[i], inType, inName);
				if (foundlayer) return foundlayer;
			}
		}
	}
	return null;
}
function ie_get_fromAll(inID, inDiv)	{
	return document.all[inID] || null;
}

function dom_getImgById(inID, inDiv)	{
	var elem = (document.getElementById(inID) || document.images[inID]);
	return elem;
}

function ns_getImgById(inID, inDiv)	{
	if (inDiv != "") {
		var lay = document.getElementById(inDiv);
		return lay.document.images[inID];
	} else {
		return document.images[inID];
	}	
}

var firstTime=true;
var pageNum=1;
var subNum=11;
var pageLayer;
var subLayer='submenu1';

var page=new MakeArray(1000);

function MakeArray(n)	
{
	this.length = n;
	for (var i = 0; i<=n; i++)	
	{
		this[i] = false;
	}
	return this;
}

function ppzPicOver(n,layer) {	
	if(page[n]==false) {
		var img = document.getImageById('pic'+n, layer);
		img.src = eval('on'+n).src;
	}
}

function ppzPicOut(n,layer) {
	if(page[n]==false) {
		var img = document.getImageById('pic'+n, layer);
		img.src = eval('off'+n).src;
	}
}


function ppzPicClick(n,layer) {
	//alert(firstNum);
	if (!firstTime)	{
		page[pageNum]=false;
		ppzPicOut(pageNum,pageLayer);
	}

	pageNum=n;
	pageLayer=layer;
	ppzPicOver(n,layer)	
	page[n]=true;
	firstTime=false;
}



/*

Copyright (C) PEPPERZAK MULTIMEDIA GmbH 2001
Author: Christian Rienow
Purpose: Open a Child-Window

History:
	
*/


function openChild(childUrl,childName,childWidth,childHeight,childLeft,childTop,childStatus,childScrollbars,childLocation,childTollbar,childMenubar) {
	var newChild = null;
	if (childLeft=='center') {	
		childPosLeft = Math.floor((screen.width - childWidth) / 2);
		if (childTop=='center'||childTop=='middle')
			childPosTop = Math.floor((screen.height - childHeight) / 2);
    	else if (childTop=='top')
			childPosTop = 0;
		else
			childPosTop = screen.height - childHeight-30;
	}
	else if (childLeft=='left') {	
		childPosLeft = 0;
		if (childTop=='center'||childTop=='middle')
			childPosTop = Math.floor((screen.height - childHeight) / 2);
    	else if (childTop=='top')
			childPosTop = 0;
		else
			childPosTop = screen.height - childHeight-30;
	}
	else {	
		childPosLeft = screen.width - childWidth-10;
		if (childTop=='center'||childTop=='middle')
			childPosTop = Math.floor((screen.height - childHeight) / 2);
    	else if (childTop=='top')
			childPosTop = 0;
		else
			childPosTop = screen.height - childHeight-30;
	}
	newChild = window.open(childUrl,childName,'width='+childWidth+',height='+childHeight+',innerwidth='+childWidth+',innerheight='+ childHeight+',top='+childPosTop+',left='+childPosLeft+',status='+childStatus+',scrollbars='+childScrollbars+',location='+childLocation+',toolbar='+childTollbar+',menubar='+childMenubar);
	if (newChild != null)
		newChild.window.focus();
}
function fuxxClick(id) {
	if (!(id == 0 || id == null)) {
		window.location.href = "/artikel/" + id;
	}
}

function resetForm(formName) {
	var myForm;
	eval('myForm = document.'+formName);
	for (var i=0; i<myForm.length; i++) {
		if (myForm.elements[i].type == "text" || myForm.elements[i].type == "textarea") {
			myForm.elements[i].value = '';
		}
	}
}

function isValidEmail(str) {
    var supported = 0;
    if (window.RegExp) {
        var tempStr = "a";
        var tempReg = new RegExp(tempStr);
        if (tempReg.test(tempStr)) {
            supported = 1;
        }
    }
    if (supported == 0) {
        return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
    }
    var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
    var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
    return (!r1.test(str) && r2.test(str));
}

function trim(value) {
	var endpos;
	var startpos = 0;
	while((value.charAt(startpos) == " ") && (startpos<value.length)) {
		startpos++;
	}
	if (startpos == value.length) {
		value = "";
	} else {
		value = value.substring(startpos,value.length);
		endpos = (value.length)-1;
		while(value.charAt(endpos) == " ") {
			endpos--;
		}
		value = value.substring(0,endpos+1);
	}
	return(value);
}

/*
Änderung free 29.09.2006
brauchen wir für die Transparenz der PNG's im IE

*/
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.
   {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
   }
window.attachEvent("onload", correctPNG);

function textCounter(field, countfield, maxlimit) {
    if (field.value.length > maxlimit) 
        field.value = field.value.substring(0, maxlimit);
    else 
        countfield.value = maxlimit - field.value.length;
}

