Array.prototype.contains = function(value) {
	for(var i=0;i<this.length;i++)  {
		if(this[i] == value) return true;
	}
	return false;
}
Array.prototype.item = function(index) {
	return this[index];
}
Array.prototype.unique = function( b ) {
 var a = [], i, l = this.length;
 for( i=0; i<l; i++ ) {
  if( a.indexOf( this[i], 0, b ) < 0 ) { a.push( this[i] ); }
 }
 return a;
};

function LIBgetSelectedIDPubG3(items) {
	var r = Array();
	for(var i=0;i<items.length;i++)  {
		var item = items[i];
		if(item.className == "selected") {
			var spans = item.getElementsByTagName("SPAN");
			if(spans.length > 0) {
				var firstSpan = spans.item(0);
				var values = firstSpan.innerHTML.split("|");
				for(var j=0;j<values.length;j++)  {
					var item = values[j];
					if(item != "") r.push(item);
				}
			}
		}
	}
	return r;
}

function Anwendungsgebiet(DOMElement) {
	this.node = DOMElement;
	this.items = this.node.getElementsByTagName("LI");
	this.selectedValues = Array();
	this.toogleItem = function(item) {
		if(item.className == "selected") item.className = "";
		else {
			item.className = "selected";
		}
	}
	this.getSelectedIDPubG3 = function() {
		var r = LIBgetSelectedIDPubG3(this.items);
		return r.unique();
	}
	this.filter = function(query) {
		for(var i=0;i<this.items.length;i++) {
			var item = this.items[i];
			AAJS.removeClassName(item,"selected");
		}
		if(typeof(query) != "undefined" && query != "") {
			for(var i=0;i<this.items.length;i++) {
				var item = this.items[i];
				if(item.innerHTML.toLowerCase().indexOf(query.toLowerCase()) ==-1) {
					AAJS.setClassName(item,"hidden");
				} else {
					AAJS.removeClassName(item,"hidden");
				}
			}
		} else {
			for(var i=0;i<this.items.length;i++) {
				var item = this.items[i];
				AAJS.removeClassName(item,"hidden");
			}
		}
	}
	this.selectAll = function() {
		for(var i=0;i<this.items.length;i++) {
			var item = this.items[i];
			if(item.className.indexOf("hidden")==-1) {
				AAJS.setClassName(item,"selected");
			}
		}
	}
	this.deSelectAll = function() {
		for(var i=0;i<this.items.length;i++) {
			var item = this.items[i];
			if(item.className == "selected") item.className = "";
		}
	}
}
function Checklist(DOMElement) {
	this.node = DOMElement;
	this.items = this.node.getElementsByTagName("LI");
	this.state = "INIT";
	this.toogleItem = function(element) {
		var liElement = null;
		var inputElement = null;
		switch(element.nodeName) {
			case "LABEL":
			case "IMG":
				inputElement = element.parentNode.getElementsByTagName("INPUT")[0];
				if(inputElement.checked) inputElement.checked = false;
				else inputElement.checked = true;
				liElement = element.parentNode;
				break;
			case "LI":
				inputElement = element.getElementsByTagName("INPUT")[0];
				if(inputElement.checked) inputElement.checked = false;
				else inputElement.checked = true;
				liElement = element;
				break;
			case "INPUT":
				inputElement = element;
				liElement = element.parentNode;
				break;
		}
		if(inputElement.checked) liElement.className = "selected";
		else {
			liElement.className = "";
		}
	}
	this.selectAll = function() {
		for(var i=0;i<this.items.length;i++)  {
			var item = this.items[i];
			item.className = "selected";
			item.getElementsByTagName("INPUT").item(0).checked = true;
		}
	}
	this.deSelectAll = function() {
		for(var i=0;i<this.items.length;i++)  {
			var item = this.items[i];
			item.className = "";
			item.getElementsByTagName("INPUT").item(0).checked = false;
		}
	}
	this.getSelectedIDPubG3 = function() {
		var r = LIBgetSelectedIDPubG3(this.items);
		return r.unique();
	}
	this.getSelectedLKID = function() {
		var r = Array();
		for(var i=0;i<this.items.length;i++)  {
			var item = this.items[i];
			if(item.className == "selected") {
				r.push(item.value);
			}
		}
		return r;
	}
}
function FaktorCollection() {
	this.anw = null;
	this.klass = null;
	this.nenn = null;
	this.getSelectedIDPubG3 = function() {
		var r = null;
		if(this.anw) {
			r = this.anw.getSelectedIDPubG3();
		}
		if(this.klass) {
			if(r) r = r.intersect(this.klass.getSelectedIDPubG3());
			else r = this.klass.getSelectedIDPubG3();
		}
		if(this.nenn) {
			if(r) r = r.intersect(this.nenn.getSelectedIDPubG3());
			else r = this.nenn.getSelectedIDPubG3();
		}
		return r;
	}
	this.selectAllByNode = function(node) {
		this.getFaktorByNodeId(node.parentNode.id).selectAll();
	}
	this.deSelectAllByNode = function(node) {
		this.getFaktorByNodeId(node.parentNode.id).deSelectAll();
	}
	this.getFaktorByNodeId = function(nodeId) {
		switch(nodeId) {
			case "anwendungsCheck1":
				return this.klass;
				break;
			case "anwendungsCheck2":
				return this.nenn;
				break;
		}
	}
}
var AAJS = {
	mode : "",
	standardAnchor : null,
	idl2 : "",
	preselect : "",
	highliteColor:'#ffff99',
	helpDivIds : new Array(),
	onload : function() {
		initLightbox();
		AAJS.standardAnchor = $('contentAnwendung');
		switch(AAJS.standardAnchor.className) {
			case "AATIEFbau": AAJS.highliteColor = "#BFDDE8"; break;
			case "AAGALAbau": AAJS.highliteColor = "#E2F1CF"; break;
			case "AASPORTbau": AAJS.highliteColor = "#FCDEC7"; break;
			case "AAAQUAbau": AAJS.highliteColor = "#BFE0E0"; break;
		}
		Event.observe($("aa_help_switch"),"click", AAJS.aaswitch_click);
		switch(AAJS.mode) {
			case "Init":
				AAJS.helpDivIds.push("aa_help_1_1");
				new Ajax.Updater($("aa_left"), "/lib/php/services/getAWarenkorb.php?sign=AA", {insertion: Insertion.Bottom});
				break;
			case "SystemSelect":
				AAJS.helpDivIds = "aa_help_2_1 aa_help_2_2 aa_help_2_3 aa_help_2_4".split(" ");
				new Ajax.Updater($("aa_left"), "/lib/php/services/getAWarenkorb.php?sign=AA", {insertion: Insertion.Bottom});
				AAJS.SystemSelect.onload();
				break;
			case "SystemConfiguration":
				AAJS.helpDivIds = "aa_help_3_1 aa_help_3_2".split(" ");
				new Ajax.Updater($("aa_left"), "/lib/php/services/getAWarenkorb.php?sign=AA");
				AAJS.SystemConfiguration.onload();
				break;
		}
	},
	aaswitch_click : function(event) {
		var e = Event.element(event);
		if(e.className.match("open")) {
			e.innerHTML =  Translator.transByIndex(333);
			for(var i=0;i<AAJS.helpDivIds.length;i++) {
				try {
					Effect.Fade($(AAJS.helpDivIds.item(i)),{duration: 0.5});
				} catch(e) {}
			}
			AAJS.removeClassName(e,"open");
		} else {
			e.innerHTML = Translator.transByIndex(335);
			for(var i=0;i<AAJS.helpDivIds.length;i++) {
				try {
					Effect.Appear($(AAJS.helpDivIds.item(i)),{to:0.9,duration: 0.5});
				} catch(e) {}
			}
			AAJS.setClassName(e,"open");
		}
	},
	setClassName : function (element, clName) {
		if(element.className.indexOf(clName)>-1) return;
		else {
			if(element.className == "") element.className = clName;
			else element.className = element.className+" "+clName;
		}
	},
	removeClassName : function (element, clName) {
		element.className = element.className.replace(" "+clName, "");
//		element.className = element.className.replace(clName, "");
	},
	texts : {
		selectAllAnwendung : "Alle auswählen",
		itemDelete : "Wollen Sie wirklich den Artikel entfernen?",
		itemTitle  : "Artikel aus der Auswahl entfernen",
		itemTitleTitle : "Passende Artikel anzeigen",
		artNoTitle : "Artikel zur Auswahl hinzufügen"
	},
	navScrollTo: function(element) {
		var x = element.x ? element.x : element.offsetLeft,
			y = element.y ? element.y : element.offsetTop;
		window.scrollTo(x, (y+50));
	}
}
AAJS.SystemSelect = {
	selectDiv : null,
	anwendungsCheck1 : null,
	anwendungsCheck2 : null,
	systemDivs : new Array(),
	faktorCollection : new FaktorCollection(),
	showAllCB : null,
	onload : function() {
		$('left').style.height = "2000px";
		AAJS.SystemSelect.selectDiv = $('selectDiv');
		AAJS.SystemSelect.showAllCB = $("showAll");
		Event.observe("showAll", "click", AAJS.SystemSelect.showAll_click);
		if($("f2SelectAll")) {
			Event.observe("f2SelectAll", "click", AAJS.SystemSelect.faktor_selectAll);
			$("f2SelectAll").style.display = "none";
		}
		if($("f3SelectAll")) {
			Event.observe("f3SelectAll", "click", AAJS.SystemSelect.faktor_selectAll);
			$("f3SelectAll").style.display = "none";
		}
		if($("f2DeSelectAll")) Event.observe("f2DeSelectAll", "click", AAJS.SystemSelect.faktor_deSelectAll);
		if($("f3DeSelectAll")) Event.observe("f3DeSelectAll", "click", AAJS.SystemSelect.faktor_deSelectAll);
		if(AAJS.SystemSelect.selectDiv) {
			Event.observe("selectPullDownMenu", "focus", AAJS.SystemSelect.anwendungsearch_focus);
			Event.observe("selectPullDownMenu", "keyup", AAJS.SystemSelect.anwendungsearch_keyup);
			Event.observe("selectPullDownMenu", "blur", AAJS.SystemSelect.anwendungsearch_blur);
			Event.observe("selectPullDownMenuIcon", "click", AAJS.SystemSelect.anwendungsearchbutton_click);
			$('selectPullDownMenuIcon').title = AAJS.texts.selectAllAnwendung;
			var items = AAJS.SystemSelect.selectDiv.getElementsByTagName("LI");
			for(var i=0;i<items.length;i++)  {
				var item = items[i];
				Event.observe(item,"click",AAJS.SystemSelect.anwendungs_click);
			}
			AAJS.SystemSelect.faktorCollection.anw = new Anwendungsgebiet(AAJS.SystemSelect.selectDiv);
		}
		AAJS.SystemSelect.faktorCollection.anw.selectAll();
		AAJS.SystemSelect.anwendungsCheck1 = $('anwendungsCheck1');
		if(AAJS.SystemSelect.anwendungsCheck1) {
			AAJS.SystemSelect.faktorCollection.klass = new Checklist(AAJS.SystemSelect.anwendungsCheck1);
			for(var i=0;i<AAJS.SystemSelect.faktorCollection.klass.items.length;i++) {
				var item = AAJS.SystemSelect.faktorCollection.klass.items[i];
				Event.observe(item,"click",AAJS.SystemSelect.belastungsklasse_click);
			}
			AAJS.SystemSelect.faktorCollection.klass.selectAll();
		}
		AAJS.SystemSelect.anwendungsCheck2 = $('anwendungsCheck2');
		if(AAJS.SystemSelect.anwendungsCheck2) {
			AAJS.SystemSelect.faktorCollection.nenn = new Checklist(AAJS.SystemSelect.anwendungsCheck2);
			for(var i=0;i<AAJS.SystemSelect.faktorCollection.nenn.items.length;i++) {
				var item = AAJS.SystemSelect.faktorCollection.nenn.items[i];
				Event.observe(item,"click",AAJS.SystemSelect.nennweite_click);
			}
			AAJS.SystemSelect.faktorCollection.nenn.selectAll();
		}

		var items = $('anwendungsSystem').getElementsByTagName("DIV");
		for(var i=0;i<items.length;i++)  {
			var item = items[i];
			if(item.className.indexOf("picText")>-1) {
				AAJS.SystemSelect.systemDivs.push(item);
			}
		}
		$('loadingDiv').style.display = "none";
		AAJS.SystemSelect.setScreen();
	},
	setScreen : function() {
		var ids = AAJS.SystemSelect.faktorCollection.getSelectedIDPubG3();
		for(var i=0;i<AAJS.SystemSelect.systemDivs.length;i++) {
			var item = AAJS.SystemSelect.systemDivs[i];
			AAJS.removeClassName(item, "fadet");
			AAJS.removeClassName(item, "hidden");
			if(!ids.contains(item.id)) {
				if(AAJS.SystemSelect.showAllCB.checked) {
					AAJS.setClassName(item, "hidden");
				} else {
					AAJS.setClassName(item, "fadet");
				}
			}
		}
	},
	anwendungsearch_focus : function(event) {
		var e = Event.element(event);
		e.value = "";
		AAJS.SystemSelect.faktorCollection.anw.filter();
	},
	anwendungs_click : function(event) {
		var e = Event.element(event);
		AAJS.SystemSelect.faktorCollection.anw.deSelectAll();
		AAJS.SystemSelect.faktorCollection.anw.toogleItem(e);
		AAJS.SystemSelect.setScreen();
	},
	anwendungsearch_keyup : function(event) {
		var e = Event.element(event);
		AAJS.SystemSelect.faktorCollection.anw.filter(e.value);
		AAJS.SystemSelect.setScreen();
	},
	anwendungsearchbutton_click : function(event) {
		var e = Event.element(event);
		AAJS.SystemSelect.faktorCollection.anw.selectAll();
		AAJS.SystemSelect.setScreen();
	},
	anwendungsearch_blur : function(event) {
		var e = Event.element(event);
		AAJS.SystemSelect.faktorCollection.anw.filter(e.value);
		AAJS.SystemSelect.setScreen();
	},
	belastungsklasse_click : function(event) {
		var e = Event.element(event);
		if(AAJS.SystemSelect.faktorCollection.klass.state == "INIT") {
			AAJS.SystemSelect.faktorCollection.klass.state = "CLICKED";
			AAJS.SystemSelect.faktorCollection.klass.deSelectAll();
			$("f2SelectAll").style.display = "block";
		}
		AAJS.SystemSelect.faktorCollection.klass.toogleItem(e);
		AAJS.SystemSelect.setScreen();
	},
	nennweite_click : function(event) {
		var e = Event.element(event);
		if(AAJS.SystemSelect.faktorCollection.nenn.state == "INIT") {
			AAJS.SystemSelect.faktorCollection.nenn.state = "CLICKED";
			AAJS.SystemSelect.faktorCollection.nenn.deSelectAll();
			$("f3SelectAll").style.display = "block";
		}
		AAJS.SystemSelect.faktorCollection.nenn.toogleItem(e);
		AAJS.SystemSelect.setScreen();
	},
	showAll_click : function(event) {
		AAJS.SystemSelect.setScreen();
	},
	faktor_selectAll : function(event) {
		var e = Event.element(event);
		AAJS.SystemSelect.faktorCollection.selectAllByNode(e);
		AAJS.SystemSelect.setScreen();
	},
	faktor_deSelectAll : function(event) {
		var e = Event.element(event);
		AAJS.SystemSelect.faktorCollection.deSelectAllByNode(e);
		AAJS.SystemSelect.setScreen();
	},
	produktuntergruppen_click : function(href) {
		if(AAJS.SystemSelect.faktorCollection.klass) {
			href += "&LKID=,"+AAJS.SystemSelect.faktorCollection.klass.getSelectedLKID().join(",")+",";
		}
		location.href=href;
	}
}
function Koordinate(node) {
	this.node = node;
	this.isOK = false;
	this.pointsOnArticles = false;
	var test = /^all_([0-9]+)$/;
	if(test.test(this.node.lang)) {
		this.artikel = AAJS.SystemConfiguration.tabellenCollection.getAllArtikelnummernByIdArtArts(RegExp.$1);
	} else {
		this.artikel = this.node.lang.split(",");
		this.pointsOnArticles = true;
	}
	this.text = this.node.title;
	this.setScreen = function(artikelSelected) {
		var schnitt = artikelSelected.intersect(this.artikel);
		this.isOK = schnitt.length > 0;
		if(this.isOK) {
			if(this.node.className != "signalTrue") {
				Effect.Pulsate(this.node, { pulses: 2, duration: 1.5 });
			}
			this.node.className = "signalTrue";
		} else {
			if(this.node.className != "signalFalse") {
				Effect.Pulsate(this.node, { pulses: 2, duration: 1.5 });
			}
			this.node.className = "signalFalse";
		}
	}
}
function Ausschreibungsitem(node, artikelnummer) {
	this.node = node;
	this.artikelnummer = artikelnummer;
}
function AusschreibungsitemCollection(node) {
	this.node = node;
	this.title = this.node.getElementsByTagName("h2").item(0).innerHTML;
	Event.observe(this.node.getElementsByTagName("h2").item(0),"click",AAJS.SystemConfiguration.ausschreibungsitemcollection_click);
	this.ul = this.node.getElementsByTagName("ul").item(0);
	this.noSelectLi = this.node.getElementsByTagName("li").item(0);
	this.isOK = false;
	this.idArtArts = this.node.lang.split(" ");
	this.artikel = new Array();
	this.pointsOnArticles = false;
	var test = /^all_([0-9]+)$/;
	if(test.test(this.node.lang)) {
		this.myArtikel = AAJS.SystemConfiguration.tabellenCollection.getAllArtikelnummernByIdArtArts(RegExp.$1);
	} else {
		this.myArtikel = this.node.lang.split(",");
		this.pointsOnArticles = true;
	}



	/**
	 * @return Ausschreibungsitem
	 */
	this.addArtikel = function(artikelnummer) {
		if(!this._artikelExits(artikelnummer)) {
			var node = document.createElement("LI");
			node.style.display = "none";
			Effect.Appear(node);
			var strong = document.createElement("STRONG");
			strong.innerHTML = artikelnummer.HAN;
			node.appendChild(strong);

			var text = document.createElement("SPAN");
			text.innerHTML = artikelnummer.articleName;
			node.appendChild(text);

			Event.observe(node, "click", AAJS.SystemConfiguration.ausschreibungsitem_click);

			var r = new Ausschreibungsitem(node, artikelnummer);
			this.artikel.push(r);
			return r;
		}
	}
	this.removeArtikel = function(node) {
		var r = "";
		var newArtikel = new Array();
		for(var i=0;i<this.artikel.length;i++) {
			var item = this.artikel[i];
			if(item.node!=node) newArtikel.push(item);
			else r = item.artikelnummer.HAN;
		}
		this.artikel = newArtikel;
		return r;
	}
	this.setScreen = function() {
		//Clear
		var items = this.node.getElementsByTagName("LI");
		var len = items.length;
		for(var i=1;i<len;i++)  {
			this.ul.removeChild(this.ul.getElementsByTagName("LI").item(1));
		}

		//Check
		this.isOK = this.artikel.length>0;
		if(this.isOK) {
			for(var i=0;i<this.artikel.length;i++) {
				var item = this.artikel[i];
				this.ul.appendChild(item.node);
			}
			AAJS.setClassName(this.node, "checkTrue");
			AAJS.removeClassName(this.node, "checkFalse");
			this.noSelectLi.style.display = "none";
		} else {
			AAJS.removeClassName(this.node, "checkTrue");
			AAJS.setClassName(this.node, "checkFalse");
			this.noSelectLi.style.display = "block";
		}
	}
	this._artikelExits = function(artikelnummer) {
		for(var i=0;i<this.artikel.length;i++) {
			var item = this.artikel[i];
			if(item.artikelnummer == artikelnummer) return true;
		}
		return false;
	}
}
function AusschreibungsLink(format, text, lang) {
	this.node = null;
	this.format = format;
	this.text = text;
	this.node = document.createElement("A");
	this.node.innerHTML = text;
	this.linkTemplate = "/ATexte-Modul/atexte?fmt="+this.format+"&tblst=ART&lang=_"+lang+"&zip=ja;";
	this.node.href = "#";
	this.node.className = this.format;
	this.setLink = function(artikel) {
		this.node.href = this.linkTemplate.replace("ART", artikel.join(','));
	}
}
function AusschreibungsLinkContainer(node) {
	this.node = node;
	this.links = new Array();
	this.links.push(new AusschreibungsLink("html","HTML",this.node.lang));
	this.links.push(new AusschreibungsLink("pdf","PDF",this.node.lang));
	this.links.push(new AusschreibungsLink("text","Text",this.node.lang));
	this.links.push(new AusschreibungsLink("rtf","RTF",this.node.lang));
	this.links.push(new AusschreibungsLink("xml","XML",this.node.lang));
	if(this.node.lang == "D") {
		this.links.push(new AusschreibungsLink("gaeb81_90","GAEB 81-90","D"));
		this.links.push(new AusschreibungsLink("gaeb83","GAEB 83","D"));
		this.links.push(new AusschreibungsLink("gaeb81_2000","GAEB 81-2000","D"));
		this.links.push(new AusschreibungsLink("onrm2062","ÖNORM 2062","D"));
		this.links.push(new AusschreibungsLink("onrm2063","ÖNORM 2063","D"));
	}
	for(var i=0;i<this.links.length;i++) {
		var item = this.links[i];
		this.node.appendChild(item.node);
	}
	this.setScreen = function(artikel) {
		if(artikel.length == 0) {
			this.node.parentNode.style.display = "none";
		} else {
			if(this.node.parentNode.style.display == "none") {
				Effect.Appear(this.node.parentNode);
			}
//			this.node.parentNode.style.display = "block";
			for(var i=0;i<this.links.length;i++) {
				var item = this.links[i];
				item.setLink(artikel);
			}
		}
	}
}
function ArtikelNummer(node, idArtArt) {
	this.node = node;
	Event.observe(this.node,"click", AAJS.SystemConfiguration.artikelnummer_click);
	this.HAN = node.innerHTML;
	var items = this.node.parentNode.getElementsByTagName("TD").item(0).getElementsByTagName("DIV");
	for(var i=0;i<items.length;i++)  {
		var item = items[i];
		if(item.className == "artText") {
			this.articleName = item.innerHTML.stripTags();
		}
	}
	this.idArtArt = idArtArt;
}
function Zeile(node, idArtArt) {
	this.node = node;
	this.idArtArt = idArtArt;
	this.artikelNummern = new Array();
	var items = node.getElementsByTagName("TD");
	for(var i=0;i<items.length;i++)  {
		var item = items[i];
		if(item.className.indexOf("isArt")>-1) {
			if(item.innerHTML != "-") this.artikelNummern.push(new ArtikelNummer(item, this.idArtArt));
		}
	}
	this.containsArtikel = function(no) {
		var items = this.artikelNummern;
		for(var i=0;i<items.length;i++)  {
			var item = items[i];
			if(item.HAN == no) return true;
		}
		return false;
	}
}

function Tabelle(node) {
	this.node = node;
	this.button = this.node.getElementsByTagName("DIV").item(0);
	this.buttonLink = this.button.getElementsByTagName("A").item(0);
	this.table = this.node.getElementsByTagName("DIV").item(1);
	this.idArtArts = this.node.lang.split(" ");
	this.isOpen = false;
	this.isVisible = true;

	this.zeilen = new Array();
	var items = this.table.getElementsByTagName("TR");
	for(var i=1;i<items.length;i++)  {
		var item = items[i];
		this.zeilen.push(new Zeile(item, this.idArtArts.item(0)));
	}

	this.openMe = function() {
		this.table.style.display = "block";
		this.isVisible = true;
		this.buttonLink.className = "open";
	}
	this.closeMe = function() {
		this.table.style.display = "none";
		this.isVisible = false;
		this.buttonLink.className = "close";
	}
	this.show = function() {
		this.node.style.display = "block";
		this.openMe();
	}
	this.hide = function() {
		this.node.style.display = "none";
		this.closeMe();
	}
	this.containsArtikel = function(no) {}
	this.getAllArtikelnummern = function() {
		var r = new Array();
		var items = this.zeilen;
		for(var i=0;i<items.length;i++)  {
			var item = items[i];
			for(var j=0;j<item.artikelNummern.length;j++)  {
				r.push(item.artikelNummern.item(j).HAN);
			}
		}
		return r;
	}
	this.toogleOpenClose = function() {
		if(this.isVisible) this.closeMe();
		else this.openMe();
	}
	this.highliteArtikel = function(artikel) {
		var items = this.zeilen;
		for(var h=0;h<artikel.length;h++)  {
			for(var i=0;i<items.length;i++)  {
				var item = items[i];
				if(item.containsArtikel(artikel[h])) {
					new Effect.Highlight(item.node, { startcolor: AAJS.highliteColor, endcolor: '#ffffff', duration: 2, to:0.9, restorecolor:"#FFFFFF" });
				}
			}
		}
	}
}
function TabelleCollection(node) {
	this.node = node;
	this.tabellen = new Array();
	var items = this.node.getElementsByTagName("DIV");
	for(var i=0;i<items.length;i++)  {
		var item = items[i];
		if(item.className == "produktTechnischeDaten") {
			this.tabellen.push(new Tabelle(item));
		}
	}
	this.showAll = function() {
		for(var i=0;i<this.tabellen.length;i++)  {
			var item = this.tabellen[i];
			item.show();
		}
	}
	this.hideAll = function() {
		for(var i=0;i<this.tabellen.length;i++)  {
			var item = this.tabellen[i];
			item.hide();
		}
	}
	this.showHideByArtikelList = function(artikel, highlite) {
		this.hideAll();
		var r = AAJS.standardAnchor;
		var isFirst = true;
		for(var i=0;i<this.tabellen.length;i++)  {
			var item = this.tabellen[i];
			if(item.getAllArtikelnummern().intersect(artikel).length > 0) {
				if(isFirst) {
					r = item;
					isFirst = false;
				}
				item.show();
				if(highlite) item.highliteArtikel(artikel);
			}
		}
		return r;
	}
	this.showHideByIDArtArts = function(IDArtArts) {
		this.hideAll();
		var r = AAJS.standardAnchor;
		var isFirst = true;
		for(var i=0;i<this.tabellen.length;i++) {
			var item = this.tabellen[i];
			if(item.idArtArts.intersect(IDArtArts).length > 0) {
				item.show();
				if(isFirst) {
					r = item;
					isFirst = false;
				}
			}
		}
		return r;
	}
	this.getArtikelNummerByNode = function(node) {
		for(var i=0;i<this.tabellen.length;i++)  {
			for(var j=0;j<this.tabellen[i].zeilen.length;j++)  {
				for(var k=0;k<this.tabellen[i].zeilen[j].artikelNummern.length;k++)  {
					if(this.tabellen[i].zeilen[j].artikelNummern[k].node == node) return this.tabellen[i].zeilen[j].artikelNummern[k];
				}
			}
		}
		return null;
	}
	this.getZeileByArtikelNo = function(no) {
		for(var i=0;i<this.tabellen.length;i++)  {
			for(var j=0;j<this.tabellen[i].zeilen.length;j++)  {
				if(this.tabellen[i].zeilen[j].containsArtikel(no)) return this.tabellen[i].zeilen[j].node;
			}
		}
		return null;
	}
	this.getAllArtikelnummernByIdArtArts = function(idArtArts) {
		var r = new Array();
		for(var i=0;i<this.tabellen.length;i++)  {
			var item = this.tabellen[i];
			if(item.idArtArts.contains(idArtArts)) {
				var nos = item.getAllArtikelnummern();
				for(var j=0;j<nos.length;j++)  {
					r.push(nos[j]);
				}
			}
		}
		return r;
	}
	this.toogleOpenCloseByNode = function(node) {
		for(var i=0;i<this.tabellen.length;i++)  {
			var item = this.tabellen[i];
			if(item.button == node) {
				item.toogleOpenClose();
				break;
			}
		}
	}
}
function artikelTable_click(some) {}

AAJS.SystemConfiguration = {
	tabellenCollection : null,
	koordinaten : new Array(),
	itemCollection :  new Array(),
	linkContainer : null,
	onload : function() {


		//Ausschreibungs-Links
//		AAJS.SystemConfiguration.linkContainer = new AusschreibungsLinkContainer($('whiteBox'));
		AAJS.SystemConfiguration.linkContainer = $("export");
		Event.observe(AAJS.SystemConfiguration.linkContainer, "click", AAJS.SystemConfiguration.linkContainer_click)

		//Tabellen
		//
		AAJS.SystemConfiguration.tabellenCollection = new TabelleCollection($('technischeDatenTables'));
		var items = AAJS.SystemConfiguration.tabellenCollection.tabellen;
		for(var i=0;i<items.length;i++)  {
			var item = items[i];
			Event.observe(item.button, "click", AAJS.SystemConfiguration.tabellebutton_click);
			AAJS.SystemConfiguration.addTableRowFunctionality(item);
		}
		//Behälter rechts
		var items = $('contentAnwendungRechts').getElementsByTagName("DIV");
		j=0;
		for(var i=0;i<items.length;i++)  {
			var item = items[i];
			if(item.className.indexOf("AusschreibungsLinkContainer")>-1) {
				var add = new AusschreibungsitemCollection(item);
				AAJS.SystemConfiguration.itemCollection.push(add);
				add.node.getElementsByTagName("H2").item(0).title = AAJS.texts.itemTitleTitle;
				j++;
			}
		}

		//Koordinaten
		var items = $('contentAnwendungLinks').getElementsByTagName("A");
		for(var i=0;i<items.length;i++)  {
			var item = items[i];
			AAJS.SystemConfiguration.koordinaten.push(new Koordinate(item));
			Event.observe(item,"click", AAJS.SystemConfiguration.koordinate_click);
		}
		ToolTip.itemContainerId = "contentAnwendungLinks";
		ToolTip.itemTagName = "A";
		ToolTip.stdToolTipNodeId = "imgAnchorText";
		ToolTip.xDiv = 245;
		ToolTip.yDiv = 175;
		ToolTip.onload();
		if(typeof(AAJS.preselect == "object")) {
			var items = AAJS.preselect;
			for(var i=0;i<items.length;i++)  {
				var item = items[i];
				var con = AAJS.SystemConfiguration.getACollectionByArtNo(item.HAN);
				var res = con.addArtikel(item);
				if(res) res.node.title = AAJS.texts.itemTitle;
			}
			AAJS.SystemConfiguration.setScreen(false);
		}
	},
	addTableRowFunctionality : function(table) {
		var items = table.zeilen;
		for(var i=0;i<items.length;i++)  {
			var item = items[i];
			Event.observe(item.node, "mouseover", AAJS.SystemConfiguration.tablerow_over);
			Event.observe(item.node, "mouseout", AAJS.SystemConfiguration.tablerow_out);
			var firstCell = item.node.getElementsByTagName("TD").item(0);
			//AAJS.SystemConfiguration.showImgIconsOfACell(firstCell);
			var items2 = item.artikelNummern;
			for(var j=0;j<items2.length;j++)  {
				var item2 = items2[j];
				item2.node.title = Translator.transByIndex(338);
				item2.node.alt = Translator.transByIndex(338);
			}
		}
	},
	showImgIconsOfACell : function(cell) {
		var items = cell.getElementsByTagName("A");
		for(var i=0;i<items.length;i++)  {
			var item = items[i];
			if(item.href.match(/jpg$/)) {
				var img = document.createElement("img");
				img.src = "/lib/php/exe/imgResize.php?width=32&src="+item.href.replace(/http:.*hauraton\.[a-z]+/, "");
				img.alt = item.innerHTML;
				img.title = item.innerHTML;
				cell.appendChild(img);
			}
		}
	},

	setScreen : function(appereanceOfLink) {
		if(typeof(appereanceOfLink)=="undefined") appereanceOfLink = true;
		var selectedArtikel = AAJS.SystemConfiguration.getSelectedHAN();
		var items = AAJS.SystemConfiguration.koordinaten;
		for(var i=0;i<items.length;i++)  {
			var item = items[i];
			item.setScreen(selectedArtikel);
		}
		var items = AAJS.SystemConfiguration.itemCollection;
		for(var i=0;i<items.length;i++)  {
			var item = items[i];
			item.setScreen();
		}
//		AAJS.SystemConfiguration.linkContainer.setScreen(selectedArtikel);
		if(appereanceOfLink) Effect.Appear($(AAJS.SystemConfiguration.linkContainer));
	},
	getACollectionByIdArtArts : function(idArtArts) {
		var items = AAJS.SystemConfiguration.itemCollection;
		for(var i=0;i<items.length;i++)  {
			var item = items[i];
			if(item.idArtArts.contains(idArtArts)) return item;
		}
		return AAJS.SystemConfiguration.itemCollection.last();
	},
	getACollectionByArtNo : function (artNo) {
		var items = AAJS.SystemConfiguration.itemCollection;
		for(var i=0;i<items.length;i++)  {
			var item = items[i];
			if(item.myArtikel.contains(artNo)) return item;
		}
		return AAJS.SystemConfiguration.itemCollection.last();
	},
	getSelectedHAN : function () {
		var selectedArtikel = new Array();
		var items = AAJS.SystemConfiguration.itemCollection;
		for(var i=0;i<items.length;i++)  {
			var item = items[i];
			for(var j=0;j<item.artikel.length;j++)  {
				selectedArtikel.push(item.artikel.item(j).artikelnummer.HAN);
				if (navigator.appVersion.match(/\bMSIE\b/) && j==0) {
					item.artikel.item(j).node.style.marginBottom = "1px";
				}
			}
		}
		return selectedArtikel;
	},
	koordinate_click : function(event) {
		var e = Event.element(event);
		var items = AAJS.SystemConfiguration.koordinaten;
		for(var i=0;i<items.length;i++)  {
			var item = items[i];
			if(e == item.node) {
				var firstTable = AAJS.SystemConfiguration.tabellenCollection.showHideByArtikelList(item.artikel, item.pointsOnArticles);
			}
		}
		AAJS.navScrollTo(firstTable.node);
	},
	ausschreibungsitem_click : function(event) {
		if(window.confirm(AAJS.texts.itemDelete)) {
			var e = Event.findElement(event, "LI");
			var items = AAJS.SystemConfiguration.itemCollection;
			for(var i=0;i<items.length;i++)  {
				var item = items[i];
				var artikel = item.removeArtikel(e);
				if(artikel != "") {
					var zeile = AAJS.SystemConfiguration.tabellenCollection.getZeileByArtikelNo(artikel);
					new Effect.Morph(zeile, {
						style: 'background:#fff; color:#000;',
						duration: 0.8
					});
				}
			}
			AAJS.SystemConfiguration.setScreen();
		}
	},
	ausschreibungsitemcollection_click : function(event) {
		var e = Event.element(event);
		var i = 0;
		while(e.className.indexOf("AusschreibungsLinkContainer") == -1 && i < 10) {
			i++;
			e = e.parentNode;
		}
		var items = AAJS.SystemConfiguration.itemCollection;
		anch = AAJS.standardAnchor;
		for(var i=0;i<items.length;i++)  {
			var item = items[i];
			if(item.node == e) {
				var firstTable = AAJS.SystemConfiguration.tabellenCollection.showHideByArtikelList(item.myArtikel, item.pointsOnArticles);
//				anch = AAJS.SystemConfiguration.tabellenCollection.showHideByIDArtArts(item.idArtArts).node;
				break;
			}
		}
		AAJS.navScrollTo(firstTable.node);
	},
	artikelnummer_click : function(event) {
		AAJS.SystemConfiguration._setMainButtonImg("/styles/img/AA/auswahl_speichern.jpg");
		var e = Event.element(event);
//		if (navigator.appVersion.match(/\bMSIE\b/)) {
//			e.parentNode.style.backgroundColor = AAJS.highliteColor;
//			e.parentNode.style.color = "#bbb";
//		} else {
//			new Effect.Morph(e.parentNode, {
//				style: 'background:'+AAJS.highliteColor+'; color:#bbb;',
//				duration: 0.8
//			});
//		}
		var artNo = AAJS.SystemConfiguration.tabellenCollection.getArtikelNummerByNode(e);
//		var con = AAJS.SystemConfiguration.getACollectionByIdArtArts(artNo.idArtArt);
		var con = AAJS.SystemConfiguration.getACollectionByArtNo(artNo.HAN);
		var res = con.addArtikel(artNo);
		if(res) res.node.title = AAJS.texts.itemTitle;
		AAJS.standardAnchor.scrollTo();
		AAJS.SystemConfiguration.setScreen();
	},
	addPlainArtikel : function(HAN, articleName) {
		var con = AAJS.SystemConfiguration.getACollectionByArtNo(HAN);
		var res = con.addArtikel({HAN:HAN,articleName:articleName});
		if(res) res.node.title = AAJS.texts.itemTitle;
	},
	tabellebutton_click : function(event) {
		var e = Event.findElement(event,"DIV");
		AAJS.SystemConfiguration.tabellenCollection.toogleOpenCloseByNode(e);
	},
	tablerow_over : function(event) {
		var ruler = new Ruler(Event.findElement(event,"TR"));
		ruler.show();
	},
	tablerow_out : function(event) {
		var ruler = new Ruler(Event.findElement(event,"TR"));
		ruler.hide();
	},
	linkContainer_click : function(event) {
//		var e = Event.findElement(event,"DIV");
		var mainButton = $("export");
		mainButton.hide();
		var div = mainButton.getElementsByTagName("DIV")[0];
		if(div.innerHTML == Translator.transByIndex(337)) {
			location.href = "?";
		} else {
			div.innerHTML = Translator.transByIndex(337);
			var moveMe = $("export2");
			moveMe.show();
			new Effect.Move(moveMe, { x: -603, y: -10, mode: "absolute", duration: 0.8});
			new Effect.Morph(moveMe, {
				style:"width:188px;height:100px;",
				duration: 0.8,
				afterFinish : function() {
				}
			});
			var url = "/lib/php/services/getAWarenkorb.php?sign=AA&action=addItems&hans="+AAJS.SystemConfiguration.getSelectedHAN().join(",")+"&group="+AAJS.idl2;
			new Ajax.Updater($("aa_left"), url, {
				method:"get",
				onSuccess: function(transport) {
					Effect.Appear($("export"));
					Effect.Fade($("export2"), {
						afterFinish : function() {
							var el = $("export2");
							el.setAttribute("style","display:none;");
						}
					});
				}
			});
		}
	},
	_setMainButtonImg : function(src) {
		var mainButton = $("export");
		var div = mainButton.getElementsByTagName("DIV")[0];
// 		div.style.backgroundImage = "url("+src+");";
	}
}
function Ruler(node) {
	this.node = node;
	var items = this.node.getElementsByTagName("TD");
	this.layout = "";
	this.pointerswidth = 0;
	this.pointimgWidth = 8;
	for(var i=0;i<items.length;i++) {
		var item = items[i];
		if(i==0) {
			this.rulerdiv = item.getElementsByTagName("DIV")[0];
			this.pointers = item.getElementsByTagName("SPAN");
		}
		if(item.className.indexOf("isArt")>-1) {
			this.pointerswidth += item.offsetWidth;
			this.layout += "X";
		}
		if(item.className.indexOf("isEmptyArt")>-1) {
			this.pointerswidth += item.offsetWidth;
			this.layout += "_";
		}
	}
	switch(this.layout) {
		case "X_":
			this.pointers.item(2).style.display = "none";
			this.pointers.item(3).style.display = "none";
			var pad = (this.pointerswidth - this.pointimgWidth - 10) / 4;
			this.pointers.item(1).style.paddingLeft = pad+"px";
			this.pointers.item(1).style.paddingRight = pad*3+"px";
			break;
		case "X":
			this.pointers.item(2).style.display = "none";
			this.pointers.item(3).style.display = "none";
			var pad = (this.pointerswidth - this.pointimgWidth) / 2;
			this.pointers.item(1).style.paddingLeft = pad+"px";
			this.pointers.item(1).style.paddingRight = pad+"px";
			break;
		case "_X":
			this.pointers.item(1).style.display = "none";
			this.pointers.item(2).style.display = "none";
			var pad = (this.pointerswidth - this.pointimgWidth - 10) / 4;
			this.pointers.item(3).style.paddingLeft = pad*3+"px";
			this.pointers.item(3).style.paddingRight = pad+"px";
			break;
		case "XX":
			var pad = (this.pointerswidth - 50 - 2 * this.pointimgWidth) / 4;
			this.pointers.item(1).style.paddingLeft = pad+"px";
			this.pointers.item(1).style.paddingRight = pad+"px";
			this.pointers.item(3).style.paddingLeft = pad+"px";
			this.pointers.item(3).style.paddingRight = pad+"px";
			break;
	}
	this.show = function() {
		this.rulerdiv.style.display = "block";
		this.node.style.backgroundColor = "#ffff99";
	}
	this.hide = function() {
		this.rulerdiv.style.display = "none";
		this.node.style.backgroundColor = "#fff";
	}
}
function artikelTableButton_click() {}
Event.observe(window,"load",AAJS.onload);