/*
function keepMark(objLiId,aState) {}
*/

var TXTCONTENT = "Seiteninhalt";
var TXTRIGHTS = "Zugriffsrechte";

function objApi()
{
	this.agent = window.navigator.userAgent.toLowerCase();
	this.isDOM = typeof(document.getElementById) != "undefined";
	this.isIE = (this.agent.indexOf("msie") >= 0 && typeof(document.all) != "undefined");
	this.isIE4 = (document.all && !this.isDOM);
	this.isNC = this.agent.indexOf("netscape") > -1;
	this.isNC4 = this.isNC && !isDOM;
	this.isMac = this.agent.indexOf("mac") >= 0;
	this.isOpera = (this.agent.indexOf("opera") != -1);
	this.isIE6 = this.agent.indexOf("msie 6.0") > -1;
	this.isM4 = this.agent.indexOf("mozilla/4.0") > -1;
	this.isFF = this.agent.indexOf("firefox") > -1;
}
var objApi = new objApi();

function position(el)	{
	var parent = el;
	var p = Array();
	p.x = parent.offsetLeft;
	p.y = parent.offsetTop;
	while (parent.offsetParent)	{
		parent = parent.offsetParent;
		p.x += parent.offsetLeft;
		p.y += parent.offsetTop;
	}
	return p;
}

function keepMark(objLiId,aState) {
	var objLi = document.getElementById(objLiId);
	if (aState==true) {
		objLi.style.color="#878787";
	} else {
		objLi.style.color="#ffffff";
	}
}
//--------------------------------------

function clearSVGBForm() {
	var aGBF=document.getElementById("SVGBForm");
	for (var i=0; i<aGBF.length; i++) {
		if ((aGBF.elements[i].type != "hidden")&&(aGBF.elements[i].type != "button"))
			aGBF.elements[i].value = "";
	}
}
//--------------------------------------

function swapBW2C(thisImg,aSBI,aCI) {
 if (thisImg.src != aCI) {
  thisImg.src = aCI;
 }
}
//--------------------------------------

function swapC2BW(thisImg,aSBI,aCI) {
 if (thisImg.src != aSBI) { 
  thisImg.src = aSBI;
 }
}
//--------------------------------------

function doSearch(e)
{
	if (!e) e = window.event;
	if (e.keyCode == 13)
	{ 
		document.onkeydown = null;
	    Search();
	}
}
//--------------------------------------

function Search()
{
	var link = document.getElementById("svRefSearch");
	document.svSearchForm.action = link.href;
	//link.href = "";
	document.svSearchForm.submit();
}
//--------------------------------------

function buildNaviTreeItem2(myArray) {
	document.write("<ul class='myMargin' style='padding-left:15px;'>");
	for (var i=0; i<myArray.length; i++){
		document.write("<li><table><tr>");
                document.write("<td><img src='img/klein.gif' alt=''/></td>");
                document.write("<td><a href='index.php?id=" + myArray[i][1] + "' class='svNavi myMargin'>");
		document.write(myArray[i][0]);
		document.write("</a></td>");
		document.write("</tr></table>");
		if (myArray[i][2] != null) {
			buildNaviTreeItem2(myArray[i][2])
		}
		document.write("</li>");
	}
	document.write("</ul>");
}
//--------------------------------------

function buildNaviTreeItem2A(myArray) {
	document.write("<ul class='myMargin' style='padding-left:15px;'>");
	for (var i=0; i<myArray.length; i++){
		document.write("<li><table><tr>");
		document.write("<td><img src='img/klein.gif' alt=''/></td>");
                document.write("<td><a href='index.php?id=" + myArray[i][1] + "' class='svNavi myMargin'>");
		document.write("<b>" + myArray[i][0] + "</b>");
		document.write("</a></td>");
		document.write("</tr></table>");
		if (myArray[i][2] != null) {
			buildNaviTreeItem2(myArray[i][2])
		}
		document.write("</li>");
	}
	document.write("</ul>");
}
//--------------------------------------

function buildNaviTreeItem1(myArray) {
	if (myArray != null){
		document.write("<li><table><tr>");
		document.write("<td><img src='img/gros.gif' alt=''/></td>");
                document.write("<td><a href='index.php?id=" + myArray[1] + "' class='svNavi myMargin'><b>" + myArray[0] + "</b></a></td>");
		document.write("</tr></table>");

		if (myArray[2] != null){
			buildNaviTreeItem2(myArray[2]);
		}
		document.write("</li>");
	}
}
//--------------------------------------

function buildNaviTree(myArray){
	document.write("<div><ul class='tree' style='padding-left:15px;'>")
	for (var i=0; i<myArray.length; i++){
		buildNaviTreeItem1(myArray[i]);
	}
	document.write("</ul></div>");
}
//--------------------------------------

function buildNaviDivTree(myArray){
	document.write("<div><ul class='tree' style='padding-left:15px;'>")
	for (var i=0; i<myArray.length; i++){
		buildNaviTreeItem2A(myArray[i]);
	}
	document.write("</ul></div>");
}
//--------------------------------------


//========== ADMIN =======

function haveRights2see3(elmId,level,myRights,isAdmin){
	if (isAdmin == true) {
		return true;
	}
	for (var i=0; i<myRights.length; i++) {
		thePage = "" + myRights[i][0];
		if (-1 != thePage.indexOf(".")) {
			thePage = thePage.split(".")[level];
		}
		if ((elmId == thePage)&&(1 == myRights[i][2])) {
			//return elmId+"-"+thePage+"+++";//true;
			return "";
		}
	}
	return elmId+"-"+thePage+"___";//false;
}
//--------------------------------------



function haveRights2do(elmId,level,myRights,isAdmin){
	if (isAdmin == true) {
		return true;
	}
	for (var i=0; i<myRights.length; i++) {
		thePage = "" + myRights[i][0];
		if ((elmId == thePage)&&(1 == myRights[i][1])) {
			return true;
		}
	}
	return false;
}
//--------------------------------------

function haveRights2see(elmId,level,myRights,isAdmin){
	if (isAdmin == true) {
		return true;
	}
	for (var i=0; i<myRights.length; i++) {
		thePage = "" + myRights[i][0];
		if (-1 != thePage.indexOf(".")) {
			//thePage = thePage.split(".")[level];
		}
		if ((elmId == thePage)&&(1 == myRights[i][2])) {
			return true;
		}
	}
	return false;
}
//--------------------------------------

function build4AdminNaviTreeItem2(myArray,myRights,level,isAdmin) {
	document.write("<ul class='myMargin' style='padding-left:15px;'>");
	for (var i=0; i<myArray.length; i++){

		//document.write(haveRights2see3(myArray[i][1],level,myRights,isAdmin));

		if (haveRights2see(myArray[i][1],level,myRights,isAdmin) == false) {
			continue;
		}

		document.write("<li><table><tr>");
		document.write("<td><img src='img/klein.gif' alt=''/></td>");
                document.write("<td><a href='index.php?id=" + myArray[i][1] + "' target='_blank' class='svNavi myMargin'>");
		document.write(myArray[i][0]);
		document.write("</a></td>");

		if (haveRights2do(myArray[i][1],level,myRights,isAdmin) == true) {
                        document.write("<td><a href='admin.php?action=login&id=" + myArray[i][1] +
			"'><img src='img/edit2.gif' alt='' border='0' title='"+ TXTCONTENT +"'></a></td>");
		}

		if (isAdmin == true) {
                        document.write("<td><a href='admin.php?action=login&chmod=1&id=" + myArray[i][1] + "'><img src='img/edit3.gif' alt='Zugrifrechte' border='0' title='"+ TXTRIGHTS +"'></a></td>");
		}

		document.write("</tr></table>");
		if (myArray[i][2] != null) {
			build4AdminNaviTreeItem2(myArray[i][2],myRights,1,isAdmin)
		}
		document.write("</li>");
	}
	document.write("</ul>");
}
//--------------------------------------

function build4AdminNaviTreeItem0(myArray,myRights,level,isAdmin) {
	if (myArray != null){
		if (haveRights2see(myArray[1],level,myRights,isAdmin) == false) {
			return;
		}

		document.write("<li><table><tr>");
		document.write("<td><img src='img/gros.gif' alt=''/></td>");
                document.write("<td><a href='index.php?id=" + myArray[1] + "' target='_blank' class='svNavi myMargin'><b>" + myArray[0] + "</b></a></td>");

		if (haveRights2do(myArray[1],level,myRights,isAdmin) == true) {
                        document.write("<td><a href='admin.php?action=login&id=" + myArray[1] + "'><img src='img/edit2.gif' alt='' border='0' title='"+ TXTCONTENT +"'></a></td>");
		}

		if (isAdmin == true) {
                        document.write("<td><a href='admin.php?action=login&chmod=1&id=" + myArray[1] + "'><img src='img/edit3.gif' alt='' border='0' title='"+ TXTRIGHTS +"'></a></td>");
		}

		document.write("</tr></table>");

		if (myArray[2] != null){
			build4AdminNaviTreeItem2(myArray[2],myRights,0,isAdmin);
		}
		document.write("</li>");
	}
}
//--------------------------------------

function build4AdminNaviTree(myArray,myRights,isAdmin){
	document.write("<div><ul class='tree' style='padding-left:15px;'>")
	for (var i=0; i<myArray.length; i++){
		build4AdminNaviTreeItem0(myArray[i],myRights,0,isAdmin);
	}
	document.write("</ul></div>");
}
//--------------------------------------

function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if ((email==null)||(email=='')) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}
//--------------------------------------

function checkShopItems(aFormId, elmTotalPcsPrefix) {
	var theF = document.getElementById(aFormId);
	for (var i=0;i<theF.length;i++) {
		var anE = theF.elements[i];
		var aRE =new RegExp( "("+elmTotalPcsPrefix+"[0-9]{1,})" );
		if (anE.name.match(aRE) != null) {
			if ((anE.value != '')&&(anE.value != 0)) {
				return true;
			}
		}
	}
	return false;
}
//--------------------------------------

function doCheckKey4Time(event) {
	if (event == 'undefined') {	event = window.event; }
	var theE;
	if (objApi.isFF==false) {
		theE = document.getElementById(event.srcElement.id);
	} else {
		theE = document.getElementById(event.target.id);
	}
    theE.value = new String(theE.value.replace(/[^0-9:]/g,''));
	var the1=theE.value.indexOf(':');
	var the2=theE.value.lastIndexOf(':');
	if (the1 != the2) {
		var a1= theE.value.substr(0,the2);
		var a2= theE.value.substr(the2+1,theE.value.length-1);
		theE.value=a1+a2;
	}
	if (theE.value.length==2){
		theE.value= theE.value+':';
	}
}
//--------------------------------------

function doCheckKey4Money(event) {
	if (event == 'undefined') {	event = window.event; }
	var theE;
	if (objApi.isFF==false) {
		theE = document.getElementById(event.srcElement.id);
	} else {
		theE = document.getElementById(event.target.id);
	}
    theE.value = new String(theE.value.replace(/[^0-9,.]/g,''));
    theE.value = new String(theE.value.replace(/[,]/,'.'));
	var the1=theE.value.indexOf('.');
	var the2=theE.value.lastIndexOf('.');
	if (the1 != the2) {
		var a1= theE.value.substr(0,the2);
		var a2= theE.value.substr(the2+1,theE.value.length-1);
		theE.value=a1+a2;
	}
}
//--------------------------------------

function doCheckFinal4Money(aThis) {
	aThis.value = aThis.value*1;
	var theP=aThis.value.indexOf('.');
	var theL=aThis.value.length;
	//alert(theL);
	switch (theP) {
		case -1:
			aThis.value = aThis.value + ".00";
			break;
		case theL:
			break;
			aThis.value = aThis.value + "00";
		case theL-2:
			aThis.value = aThis.value + "0";
			break;
	}
	theL=aThis.value.length;
	if (theL==0) { aThis.value="0.00"; }
}
//--------------------------------------

function chqKey4NaN(event) {	
	if (event == 'undefined') {	event = window.event; }
	var theE;
	//alert(objApi.isFF);
	if (objApi.isFF==false) {
		theE = document.getElementById(event.srcElement.id);  
	} else {
		theE = document.getElementById(event.target.id);    
	}		
   	theE.value = theE.value.replace(/[^0-9.]/g,'');
   	if(theE.value.match(/[.]{2,10}/,'')) {
   		theE.value = theE.value.replace(/[.]/,'');
   	}
}
//--------------------------------------


//========================
