// JavaScript Document
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function showHideDiv(id,openIt) {
	obj = MM_findObj(id);
	if (obj.style) {
		obj=obj.style;
		if(openIt) { v = 'visible' }
		else { v = 'hidden'; }
	}
	else {
		if(openIt) { v = 'show' }
		else { v = 'hide'; }
	}
	obj.visibility=v;
}

function showHideElem(elemID,showIt) {
	obj = MM_findObj(elemID);
	if (obj.style) {
		obj=obj.style;
	}
	if(showIt==undefined) {
		if(obj.visibility=="hidden" || obj.visibility=="") { v = 'visible' }
		else { v = 'hidden'; }
	}
	else {
		if(showIt) { v = 'visible'; }
		else { v = 'hidden'; }
	}
	obj.visibility=v;
}

function openCloseDiv() {
	var args = openCloseDiv.arguments;
	var id = args[0];
	
	obj = MM_findObj(id);
	if (obj.style) {
		obj=obj.style;
	}
	if(obj.display=="none" || obj.display=="") { v = 'block' }
	else { v = 'none'; }
	obj.display=v;
	
	var btnName = "B"+id.substr(1);
	if(document.images[btnName]) {
		if(v=="block") {
			document.images[btnName].src = "images_standard/btn_close.png";
		}
		else {
			document.images[btnName].src = "images_standard/btn_open.png";
		}
   }
}

function showHideObject(obj,show) {
	var actualState;
	if(document.getElementById(obj)) {
		if(show==undefined) {
			if(document.getElementById(obj).style.display) {
				actualState = document.getElementById(obj).style.display;
				if(actualState=="block") { show = false; }
				else { show = true; }
			}
			else { show = true; }
		}
		if(show) { document.getElementById(obj).style.display = "block"; }
		else { document.getElementById(obj).style.display = "none"; }
	}
}

function hideShowObject(obj,show) {
	var actualState;
	if(document.getElementById(obj)) {
		if(show==undefined) {
			if(document.getElementById(obj).style.display) {
				actualState = document.getElementById(obj).style.display;
				if(actualState=="block") { show = false; }
				else { show = true; }
			}
			else { show = false; }
		}
		if(show) { document.getElementById(obj).style.display = "block"; }
		else { document.getElementById(obj).style.display = "none"; }
	}
}

function htmlencode(strIn) {
	var returner = encodeURIComponent(strIn);
	return returner;
}

function htmlentities(str,typ) {
	alert("strIn="+str);
	if(typeof str=="undefined") str="";
	if(typeof typ!="number") typ=2;
	typ=Math.max(0,Math.min(3,parseInt(typ)));
	var html=new Array();
	html[38]="&amp;"; html[60]="&lt;"; html[62]="&gt;";
	if(typ==1 || typ==3) html[39]="&#039;";
	if(typ==2 || typ==3) html[34]="&quot;";
	for(var i in html) eval("str=str.replace(/"+String.fromCharCode(i)+"/g,\""+html[i]+"\");");
	var entity=new Array(
		"&nbsp;","&iexcl;","&cent;","&pound;","&curren;","&yen;","&brvbar;","&sect;",
		"&uml;","&copy;","&ordf;","&laquo;","&not;","&shy;","&reg;","&macr;",
		"&deg;","&plusmn;","&sup2;","&sup3;","&acute;","&micro;","&para;","&middot;",
		"&cedil;","&sup1;","&ordm;","&raquo;","&frac14;","&frac12;","&frac34;","&iquest;",
		"&Agrave;","&Aacute;","&Acirc;","&Atilde;","&Auml;","&Aring;","&AElig;","&Ccedil;",
		"&Egrave;","&Eacute;","&Ecirc;","&Euml;","&Igrave;","&Iacute;","&Icirc;","&Iuml;",
		"&ETH;","&Ntilde;","&Ograve;","&Oacute;","&Ocirc;","&Otilde;","&Ouml;","&times;",
		"&Oslash;","&Ugrave;","&Uacute;","&Ucirc;","&Uuml;","&Yacute;","&THORN;","&szlig;",
		"&agrave;","&aacute;","&acirc;","&atilde;","&auml;","&aring;","&aelig;","&ccedil;",
		"&egrave;","&eacute;","&ecirc;","&euml;","&igrave;","&iacute;","&icirc;","&iuml;",
		"&eth;","&ntilde;","&ograve;","&oacute;","&ocirc;","&otilde;","&ouml;","&divide;",
		"&oslash;","&ugrave;","&uacute;","&ucirc;","&uuml;","&yacute;","&thorn;","&yuml;"
	);
	for(var i in entity) eval("str=str.replace(/"+String.fromCharCode(i*1+160)+"/g,\""+entity[i]+"\");");
	str = str.replace(/'/g,"&prime;");
	//document.forms["form1"].elements["out"].value = str;
	alert("strOut="+str);
	return str;
}

function testmodeecho(msg) {
	document.getElementById("msg").innerHTML+= '<div class="msg entry">JS: '+msg+'</div>';
}

function createElem() {
	var args = createElem.arguments;
	var elem = document.createElement(args[0]);
	var tn;
	if(args[1].length>0) {
		tn = document.createTextNode(args[1]);
		elem.appendChild(tn);
	}

	var an;
	for(var i=2; i<args.length; i+=2) {
		an = document.createAttribute(args[i]);
		an.nodeValue = args[i+1];
		elem.setAttributeNode(an);
	}
	//alert("ok elem");
	return elem;
}

function confirm2(text) {
	/*
	var container = "LStatus2";
	var statuscontainer = "LStatus";
	var url = airroot+"includes/messages.ajax.php";
	var xml = new Ajax.Updater(
		container,
		url,
		{
			method:"post",
			parameters: {
				f: "AJAX_confirm",
				ue: "Bitte bestätigen:",
				text: text,
				container: container,
				caller: confirm2.caller
			},
			onCreate: function() {
			},
			onSuccess: function(resp) {
				document.getElementById(container).style.display = "block";
			}
		}
	)
	Dialog.confirm("text",
		{
			top: 10,
			width:250,
			className: "alphacube",
			ok:function(win) {
				return true;
			}
 		}
	);
	*/


	return confirm(text)
}

/*
function alert2(text) {
	//Dialog.alert({url: "templates/messages/alert.tpl.html", options: {method: 'post'}}, {className: "alphacube", width:540, top:50, left:50, okLabel: "Close"});

	var container = "LStatus2";
	var statuscontainer = "LStatus";
	var url = airroot+"includes/messages.ajax.php";
	
	var xml = new Ajax.Updater(
		container,
		url,
		{
			method:"post",
			parameters: {
				f: "AJAX_alert",
				ue: "Achtung!",
				text: text,
				container: container
			},
			onCreate: function() {
			},
			onSuccess: function(resp) {
				document.getElementById(container).style.display = "block";
			},
			onError: function(e) {
				//alert("ERROR: e="+e);
			}
		}
	)
	//return alert(text);
}
*/


function prompt2(text,initval) {
	return prompt(text,initval);
}

function isTrue(itm) {
	if((itm==1 || itm=="true" || parseInt(itm)==1 || itm==true || parseInt(itm)>1) && (itm!=0 || itm!=false || itm!="false" || itm!="0")) { return true; }
	else { return false; }
}

function is_array(variable) {
    return typeof(variable) == "object" && (variable instanceof Array);
}

function in_array(itm,arr) {
	for(p=0; p<arr.length; p++) { if(itm == arr[p]) { return true; } }
	return false;
}

function extractFromArray(itm,arr) {
	var arrNew = new Array();
	var j = 0;
	for(var i=0; i<arr.length; i++) {
		if(arr[i]!=itm) { arrNew[j] = arr[i]; j++; }
	}
	return arrNew;
}

function explode(sep,str) {
	return str.split(sep);
}
function implode(glue, pieces) {
    var i = '', retVal='', tGlue='';
    if (arguments.length === 1) {
		pieces = glue;
		glue = '';
    }
    if (typeof(pieces) === 'object') {
        if (pieces instanceof Array) { return pieces.join(glue); }
        else {
            for (i in pieces) {
                retVal += tGlue + pieces[i];
				tGlue = glue;
            }
            return retVal;
        }
    }
	else { return pieces; }
}
