//--------------------------------------------------------
//Class Node
function Node (parent,userObject)
	{
	this.parent=parent;
	this.index=null;
	this.userObject=userObject;
	this.collapsed = true;
	this.expanded = false;
	
	this.childNodes=new Array();
	}

Node.prototype.addNode = function (node){
	this.childNodes[this.childNodes.length] = node;
}

Node.prototype.getNode = function (criteria,optParam) {
	if (this.userObject && this.userObject.equals(criteria,optParam))
		return this;
	if (this.childNodes.length == 0)
		return false;
	else {
		for (var i=0;i<this.childNodes.length;i++) {
			var node = this.childNodes[i].getNode(criteria,optParam);
			if (node != false)
				return node;
		}
		return false;
	}	
}

Node.prototype.collapse = function(children) {
	this.expanded = false;
	if (children) {
		for (var i=0;i<this.childNodes.lenght;i++)
			this.childNodes[i].collapse(children);
	}
}

Node.prototype.expand = function(children) {
	this.expanded = true;
	if (children) {
		for (var i=0;i<this.childNodes.length;i++)
			this.childNodes[i].expand(children);
	}
}

Node.prototype.callOnUserObject = function (funcID,param) {
	this.userObject.exec(funcID,param);
	if (param["callOnChildren"]) {
		param["childCall"] = true;
		for (var i=0;i<this.childNodes.length;i++)
			this.childNodes[i].callOnUserObject(funcID,param);
	}
}

	
//--------------------------------------------------------
//Class Tree
function Tree (root) {
	this.root = root;
}

Tree.prototype.getNode = function(criteria,optParam) {
	if (this.root == null)
		return false;
	else
		return this.root.getNode(criteria,optParam);
}


//------------------------------------------------------
//Class Category
function Category(name,ukatnr,posnr,script,ordernr,type,allowed,password)
	{
	this.name=name;
	this.ukatnr=ukatnr;
	this.posnr = posnr;
	this.script=script;
	this.ordernr=new String(ordernr);
	this.type=type;
	this.allowed=allowed;
	this.password=password;
	this.oldOrdernr=null;
	this.modified = false;
	this.changes = 0;
	}

Category.prototype.equals = function (compare,optParam) {
	if (optParam)
		return this[optParam] == compare;
	else
		return (this.ordernr==compare);
}

Category.prototype.changeOrdernr = function (param)
	{
	var newOrdernr = new String(param.ordernr);
	if (!this.modified)
		this.oldOrdernr=this.ordernr;
	if (newOrdernr.length < this.ordernr.length)
		this.ordernr=newOrdernr+this.ordernr.substring(newOrdernr.length,this.ordernr.length);
	else
		this.ordernr=newOrdernr;
	this.modified = true;
	}

Category.prototype.rename = function (param) {
	var newName = param.name;
	this.name = newName;
}

Category.prototype.changePwd = function (param) {
	this.password = param.password;
	this.modified = true;
}

Category.prototype.exec = function (id,param) {
	eval("this."+id+"(param);");
}
/**
* Standard JavaScript library Contwise 2
* Copyright General Solutions Steiner GmbH & F.Falkner
*
/******************************************************************
Original Code from
© 2001 Struppi
Mail: struebig@gmx.net
URL: http://home.arcor.de/struebig/computer/javascript
Modified 2004 by Florian Falkner
*/
var default_bgColor = '#EAEAEA';
var default_width = 400;
var default_height = 200;
var rahmen_w = 20;
var rahmen_h = 100;

//New Version start
function showBild(link, title, descr)
{
    // Das Fenster öffnen
    isLoad = false;

    if(!showFenster || showFenster.closed) showFenster = popUp("", "NEW_WIN", default_width, default_height);
    
  
    showFenster.document.open();
    showFenster.document.write(getHTML(link,title,descr));
    showFenster.document.close();
    showFenster.focus();
    return false;
}

function fitWin(i, win)
{
    if(isLoad == true) return;
    isLoad = true;

    var w = i.width;
    var h = i.height;

    if(w < 100) w = 150;
    if(h < 100) h = 100;

    var size = getWinSize(win);

    win.resizeBy((w - size.w + rahmen_w), (h - size.h + rahmen_h) );
    
    win.focus();
}

function popUp(url, fname, w, h)
{
    var tmp = new Array();
    tmp[tmp.length] = 'resizable=yes';
    tmp[tmp.length] = 'scrollbars=yes';
    if(w) tmp[tmp.length] = 'width=' + w;
    if(h) tmp[tmp.length] = 'height=' + h;
    var string = tmp.join(",");
    return window.open(url, fname, string);
}

function getHTML(src, title, descr) {
    var body = (window.opera || document.layers) ? false : true;
    if(!title) title = 'Bild / Picture';
    var bgcolor = default_bgColor;
    descr = descr || "";
    var text ="";
    text+= '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">\n'
    + '<HTML>\n<HEAD>\n'
    + '<TITLE>' + title + '</TITLE>\n'
    + '<STYLE type="text/css">\n'
     + 'body{margin:0;padding:0;overflow:hidden;\n' + 'background-color:' + bgcolor + ';}\n'
    + '#img{\nposition:absolute;top:0;left:0;margin:0;padding:0;overflow:hidden;\n}\n'
    + '</STYLE>\n'
    + '</HEAD>\n'
    + '<body onload="var img = new Image();'
    + 'img.onload = function(){opener.fitWin(this, window);};'
    + 'img.src = \'' + src +'\';img.vspace=6;">'
    + '<center><div align="center"><br><a href="javascript:self.close()" title="Zum Schließen ins Bild klicken."><img border=0 src="' + src + '" alt="' + title + '"' + '></a></div>'
    + '<div align=center><font face="Verdana,Arial,Helvetica,sans-serif" size=1>' + descr + '</font></div>'
    + '\n</body>\n</html>\n'
    ;
    return text;
}

function getWinSize(win)
{
    if(!win) win = window;
    var pos = {w:0,h:0};
    if(typeof win.innerWidth != 'undefined')
    {
        pos = { w: win.innerWidth, h: win.innerHeight};
    }
    else
    {
         var obj = checkIE(win);

         pos.w = parseInt(obj.clientWidth);
         pos.h = parseInt(obj.clientHeight);
    }
    return pos;
}

function checkIE(win)
{
    if(!win) win = window;
    return (win.document.compatMode && win.document.compatMode == "CSS1Compat") ?
    win.document.documentElement : win.document.body;
}
var showFenster = null;
//end

/**
------------------------------------------------------------------------------------------------
Start of Standardlibrary copyrighted by G & S GmbH & F.Falkner
------------------------------------------------------------------------------------------------
**/
function oWin(path,name,height,width,posX,posY) {
   var winName = name || "CONTWISE_OUT_WIN";
   var winHeight = height || 487;
   var winWidth = width || 480;
   var left,top;
   if (!posX && !posY) {
    left = (screen.width) ? (screen.width-winHeight)/2 : 20;
    top = (screen.height) ? (screen.height-winWidth)/2 : 20;
   }
   else {
     left = posX;
     top = posY;
   }
   var settings ='height='+winHeight+',width='+winWidth+',top='+top+',left='+left+',scrollbars=yes,resizable=yes'
   win = window.open(path,name,settings)
   win.focus();
   return win;
}

var WARN_CATEGORY_NOT_FOUND = true;
var DEFAULT_PARENT_NAME = "diverses";

function writeParents(val,tree,link,style,sep) {
   if (!tree) tree = catTree;
   var curNode;
   curNode = catTree.getNode(val,"ukatnr");
   if (!curNode) {
      if (WARN_CATEGORY_NOT_FOUND) {
         alert("Node "+val+" not found!");
         return;
      }
      else {
         window.document.write(DEFAULT_PARENT_NAME);
      }
   }

// alert(curNode.userObject.name);
   var catString = "";
   if (!style) style = "cat-link";  
   if (!sep) sep = " / ";
   while (curNode.parent) {
      if (!curNode.userObject) continue;
      var tmp = catString;
      if (link)
         catString="<a href='"+curNode.userObject.script+"?ukatnr="+curNode.userObject.ukatnr+"' class='"+style+"'>"+curNode.userObject.name+"</a>";
      else
         catString=curNode.userObject.name;
      if (tmp) catString = catString+sep+tmp;
         curNode = curNode.parent;
   }
   window.document.write(catString);
}

function replaceForUrl (text) {
	text = text.toLowerCase();
	text=text.replace(/ /g, "_");
	text=text.replace(/,/g, "");
	text=text.replace(/\u00fc/g, "ue");
	text=text.replace(/\u00f6/g, "oe");
	text=text.replace(/\u00e4/g, "ae");
	text=text.replace(/\u00df/g, "ss");
	text=text.replace(/[^a-zA-Z 0-9_]+/g,'');
	return text;
}

function searchFriendlyUrl (name, ukatnr, artnr) {
	return replaceForUrl(name) + "," + ukatnr + (artnr ? "," + artnr : "") + ".html";
}



// JS function for uncrypting spam-protected emails:
// To Crypt, undo the right shift for each character by unicode character
function linkTo_UnCryptMailto(s) {
	var n=0;
	var r="";
	
	for(var i=0; i < s.length; i++) {
		n=s.charCodeAt(i);
		
		if(s.charAt(i) == '^')
			r+= '&';
		else
			r += String.fromCharCode(n-(1));
	}
	
	location.href='mailto:' + r;
}
