/* Copyright © 2005 memeticor ® */
/* Dipl.-Ing. Werner Riegler */
/* office@memeticor.com */
function dogoto(idx,href,target,open)
{
	// alert("dogoto:" + idx + " - " + href + " - " + target + " - " + open + " - " + lang + " - " + high_idx);
	if (! href) return;
	var _windowProperties=""
	var iidx = parseInt(idx.substring(1,idx.length));
	var b_c = ((iidx+1) % 8) -1; 
	var b_r = parseInt((iidx+1) / 8) + 2;
	if (b_c < 0) { b_c = 7; b_r --; }
	if (high_idx != "") {
		hidx_arr = high_idx.split(',');
		for (hi=0; hi<hidx_arr.length; hi++) {
			var hiidx = parseInt(hidx_arr[hi].substring(1,hidx_arr[hi].length));
			var hb_c = ((hiidx+1) % 8) -1;
			var hb_r = parseInt((hiidx+1) / 8) + 2;
			if (hb_c < 0) { hb_c = 7; hb_r --; }
			// alert(idx + " - " + iidx + ": " + b_c + " - " + b_r);
			var memtd = document.getElementById(hidx_arr[hi]);
			if(memtd && memtd.firstChild.id && memtd.firstChild.id.match("img_")) { 
				memtd.firstChild.className = "LowImg"; 
				memtd.firstChild.style.borderColor = "#990099";
			} 
			else { if(memtd) memtd.className = "Low"; }
			var td_l = document.getElementById("l_" + hb_r);
			var td_r = document.getElementById("r_" + hb_r);
			var td_o = document.getElementById("o_" + hb_c);
			var td_u = document.getElementById("u_" + hb_c);
			if (td_l) td_l.style.backgroundColor = "#990099";
			if (td_r) td_r.style.backgroundColor = "#990099";
			if (td_o) td_o.style.backgroundColor = "#990099";
			if (td_u) td_u.style.backgroundColor = "#990099";
		}
	}
	high_idx = idx;
	var memtd = document.getElementById(idx);
	if(memtd.firstChild.id && memtd.firstChild.id.match("img_")) { 
		memtd.firstChild.className = "HighImg"; 
		memtd.firstChild.style.borderColor = "#FF00FF";
	} 
	else { if(memtd) memtd.className = "High"; }
	var td_l = document.getElementById("l_" + b_r);
	var td_r = document.getElementById("r_" + b_r);
	var td_o = document.getElementById("o_" + b_c);
	var td_u = document.getElementById("u_" + b_c);
	if (td_l) td_l.style.backgroundColor = "#FF00FF";
	if (td_r) td_r.style.backgroundColor = "#FF00FF";
	if (td_o) td_o.style.backgroundColor = "#FF00FF";
	if (td_u) td_u.style.backgroundColor = "#FF00FF";
	if (open) {
		_windowProperties = open;
	}
	if(href) window.open(href, target, _windowProperties);
}
function is_history(href)
{
	for (var h=0; h<history.length; h++) {
		// alert (history[h]);
		if (history[h] == href) return true;
	}
	return false;
}
function bindMe (i,r,t,o){ 
	var ti = i; 
	var tr = r; 
	var tt = t; 
	var to = o;
	return function(){ 
		dogoto(ti,tr,tt,to); 
	}
}
function bindStyle (me, style){ 
	var ts = style; 
	var tme = me;
	return function(){ 
		tme.className = ts;
	}
}
function bindBorderColor (me, bcolor){ 
	var tbc = bcolor; 
	var tmec = me;
	return function(){ 
		tmec.firstChild.style.borderColor = tbc;
	}
}

function setMems()
{
	high = getParameter(window.top.location.href,"high");
	// alert (high);
	var memtable = document.getElementById("mems");
	while (memtable.rows.length > 0){
		memtable.deleteRow(0);
	}
	idx = 0;
	tr = memtable.insertRow(idx);
	tr.height="1%";
	td = document.createElement("td");
	td.className = "Border";
	td.width="1%";
	tr.appendChild(td);
	for (var i=0; i<8; i++) {
		td = document.createElement("td");
		td_text = document.createTextNode(String.fromCharCode(65+i));
		td.id = "o_" + i;
		td.className = "Border";
		td.appendChild(td_text);
		td.width="7%";
		td.align="center";
		td.vAlign="middle";
		tr.appendChild(td);
	}
	td = document.createElement("td");
	td.className = "Border";
	td.width="1%";
	tr.appendChild(td);
	var rcnt = 0;
	var lcnt = 0;
	idx = 1;
	midx = 0;
	for (var ii=0; ii < (64+8); ii++) {
		if (rcnt == 0) {
			tr = memtable.insertRow(idx++);
			tr.height="7%";
		}
		if (rcnt == 0 || rcnt == 8) {
			td = document.createElement("td");
			td_text = document.createTextNode(String.fromCharCode(49+lcnt));
			td.appendChild(td_text);
			td.id = (rcnt==0 ? "l_" : "r_") + idx;
			td.className = "Border";
			td.width="1%";
			td.align="center";
			td.vAlign="middle";
			tr.appendChild(td);
			if (rcnt == 8) {
				lcnt = lcnt + 1;
				rcnt = 0;
				continue;
			}
		}
		rcnt = rcnt + 1;
		td = document.createElement("td");
		td.className = "LightRow";
		if (ii % 2) td.className = "DarkRow";
		var iihref = "";
		var iitarget;
		if (midx < mems.length && mems[midx]) {
			iihref = "" + mems[midx]["href"][lang]; 
			iitarget = "" + mems[midx]["target"];
			iistyle = "" + mems[midx]["style"]
			iiopen = "" + mems[midx]["open"]
			iisize = "" + mems[midx]["size"]
			iimode = "" + mems[midx]["mode"]
			var iihtml; //  + mems[midx]["html"]
			img = "" + mems[midx]["image"][lang];

			var tiihref_idx = (iihref ? iihref.search("&high") : -1);
			if (tiihref_idx < 0) tiihref_idx = (iihref ? iihref.search("\\?high") : -1);
			var tiihref = iihref;
			if (iihref && tiihref_idx > 0) tiihref = iihref.substr(0,tiihref_idx);
			var thigh_idx = (high ? high.search("&high") : -1);
			if (thigh_idx < 0) thigh_idx = (high ? high.search("\\?high") : -1);
			var thigh = high;
			if (high && thigh_idx > 0) thigh = high.substr(0,thigh_idx);
			// alert(tiihref + "("+tiihref.length+") " + " == " + thigh + "("+thigh.length+") ");
			
			if (iihref && ((! img) || (iimode != ""))) {
				a = document.createElement("a");
				a.onclick = bindMe("_"+midx, iihref, iitarget, iiopen);
				if ((! img) || (iimode != "")) {
					if (iistyle.match("Small")) {
						a.onmouseover = function(){this.className="HighOverSmall"}
					}
					else {
						a.onmouseover = function(){this.className="HighOverBold"}
					}
					a.onmouseout = bindStyle(a, iistyle);
				}
				a.className = iistyle;
			}
			txt = "" + mems[midx][lang];
			if (txt.search("\<\w+\>")) iihtml = txt;
			if (img != "") {
				td_img = document.createElement("img");
				td_img.src = img;
				if (iihref) {
					itab = document.createElement("table");
					itr = itab.insertRow(0);
					a2 = document.createElement("td");
					itab.border="0";
					td_img.onclick = bindMe("_"+midx, iihref, iitarget, iiopen);
					td_img.border = "2";
					itab.id = "img_"+ii;
					td_img.className = (ii % 2) ? "DarkImg" : "LightImg";
					itab.className = (ii % 2) ? "DarkImg" : "LightImg";
					if (high && (tiihref == thigh)) itab.className = "HighImg"; 
					// td_img.onmouseover = function(){this.style.borderColor="#ff00ff"}
					a2.onmouseover = function(){this.firstChild.style.borderColor="#ff00ff"}
					ImgBS = (ii % 2) ? "DarkImg" : "LightImg";
					ImgBC = (ii % 2) ? "#999999" : "#ffffff";
					// td_img.onmouseout = bindStyle(td_img, ImgBS);
					a2.onmouseout = bindBorderColor(a2, ImgBC);
					a2.appendChild(td_img);
					itr.appendChild(a2);
					td.appendChild(itab);
				}
				else {
					td.appendChild(td_img);
				}
				if (iisize) {
					var _isz = iisize.search("x");
					if (_isz) 
					{
						_iszw = iisize.substr(0,_isz);
						_iszh = iisize.substr(_isz+1,iisize.length);
						td_img.width=_iszw;
						td_img.height=_iszh;
					}
					else
					{
						td_img.width=_iszw;
					}
				}
				var regexp = /<([A-Z][A-Z0-9]*)[^>]*>/gi;
				var regexp2 = /<(\/[A-Z][A-Z0-9]*)[^>]*>/gi;
				var otxt = txt.replace(regexp,"");
				var otxt = otxt.replace(regexp2,"");
				if (iihref) td_img.alt = otxt;
				if (iihref) td_img.title = otxt;
			}
			if (img == "" || iimode != "") {
				if (iihtml) {
					div = document.createElement("div");
					div.innerHTML=iihtml;
					if (iihref) { 
						a.appendChild(div); 
						td.appendChild(a);
					}
					else {
						div.className = iistyle;
						td.appendChild(div);
					}
				}
				else {
					td_text = document.createTextNode(txt);
					if (iihref) { 
						a.appendChild(td_text); 
						td.appendChild(a);
					}
					else {
						div = document.createElement("div");
						div.className = iistyle;
						div.appendChild(td_text);
						td.appendChild(div);
					}
				}
			}
			td.id = "_"+midx;
			if (high && (tiihref == thigh)) { 
				if (! img) td.className = "High"; 
				high_idx = "_"+midx+","+high_idx; 
				}
			midx++;
		}
		td.width="7%";
		td.align="center";
		td.vAlign="middle";
		tr.appendChild(td);
	}
	tr = memtable.insertRow(idx);
	tr.height="1%";
	td = document.createElement("td");
	td.className = "Border";
	td.width="1%";
	tr.appendChild(td);
	for (var i=0; i<8; i++) {
		td = document.createElement("td");
		td_text = document.createTextNode(String.fromCharCode(65+i));
		td.id = "u_" + i;
		td.className = "Border";
		td.appendChild(td_text);
		td.width="7%";
		td.align="center";
		td.vAlign="middle";
		tr.appendChild(td);
	}
	td = document.createElement("td");
	td.className = "Border";
	td.width="1%";
	tr.appendChild(td);		
}
