var meta= -1;
NN4 = false;
checkBrowser('none');
if (myAppName == "Netscape" && parseInt(myAppVers<5)) { NN4 == true; }

function changeTd(name,color) {
	name = name+"";
	if (name.indexOf('td') == -1 && name.indexOf('str') == -1) name = "td"+name;
	if (document.getElementById) {
		document.getElementById(name).style.backgroundColor=color;
	}
}

function changeNavPic(name,mysrc) {
	document.images[name].src = mysrc;
}

function changePortalTd(what,color,picsrc,flag) {
	if (document.getElementById) {
		document.getElementById("tr"+what).style.backgroundColor=color;
		if (flag == 1) {
			document.getElementById("tr"+what).style.border="solid #FFFFFF 1px";
		}
		else {
			document.getElementById("tr"+what).style.border="solid #9D0027 1px";
		}
		document.images['pic'+what].src = picsrc;
	}
}

function changeSnTd(what,color,pic1,pic2) {
	if (document.getElementById) {
		if (color.indexOf('#') != -1) {
			document.getElementById("thisone"+what).style.backgroundColor=color;
		}
		else {
			document.getElementById("thisone"+what).style.backgroundImage="url("+color+")";
		}
	}
	document.images["cnavileft"+what].src=pic1;
	document.images["cnaviright"+what].src=pic2;
}

function jumpTo(nameform,namelem) {
	var FormObj = document.forms[nameform].elements[namelem];
	var nr = FormObj.selectedIndex;
	var hyperref = FormObj.options[nr].value;
	if (hyperref.indexOf("-1") == -1 && hyperref.substring(0,1) == "/") {
		document.location.href=hyperref;
	}
}

function checkBrowser(prefix) {
	redirect = false;
	myWidth = screen.width;
	myHeight = screen.height;
	myAppName = navigator.appName;
	myAppVers = navigator.appVersion;
	myUserAgent = navigator.userAgent;
	if (myAppName == "Netscape") {
		if (parseInt(myAppVers) < 5) {
			redirect = true;
		}
	}
	else {
		if (parseInt(myUserAgent.substring(myUserAgent.indexOf('MSIE')+5,myUserAgent.length))<5) {
			redirect=true;
		}
	}
	if (myWidth < 1024 || myHeight < 768)  redirect = true;
	if (prefix != "none") {
		if (redirect == true) {
			makePop(prefix+"/ctcommon/browsercheck/browsercheck.jsp",myWidth,myHeight,myAppName,myAppVers,myUserAgent);
		}
	}
}

function makePop(url,w,h,an,av,ua) {
	var sat = window.open(url,"satellit","width=660,height=530,scrollbars=yes");
	sat.focus();
}

function goForm(what,where) {
	var formObj = document.forms[what];
	formObj.action = where;
	formObj.submit();
}

function openWindow() {
	var stdWidth = 640;
	var stdHeight = 480;
	var stdTop = 0;
	var stdLeft = 0;
	var extraAttrib = "";
	var args = new Array();
	for (i = 0; i < openWindow.arguments.length; i++) args[i] = openWindow.arguments[i];
		if (args[2]) stdWidth = args[2];
		if (args[3]) stdHeight = args[3];
		if (args[4]) {
		if (args[4] != "center") stdTop = args[4];
		else stdTop = (screen.height/2) - (stdHeight/2);
	}
	if (args[5]) {
		if (args[5] != "center") stdLeft = args[5];
		else stdLeft = (screen.width/2) - (stdWidth/2);
	}
	if (args[6]) extraAttrib = args[6];
	attribs  = "width=" + stdWidth;
	attribs += ",height=" + stdHeight;
	attribs += ",top=" + stdTop + ",left=" + stdLeft + "," + extraAttrib;
	var newWin = window.open(args[0], args[1], attribs);
	newWin.focus();
}

function counterPic(siteNr,prefix) {
	if (prefix!="/ctauthor") {
		var countPic = new Image();
		var countDate = new Date();
		var picName = "/userstats/"+siteNr+"/"+Math.round(countDate.getTime()/1000)+"_"+Math.round(Math.random()*255)+".gif";
		countPic.src = picName;
		//alert(picName);
	}
}

function correctOverflow() {
	if (!NN4) {
		document.body.style.overflowX='hidden';
	}
}

function changePic(what,pic) {
	document.images['haupt'+what].src = pic;
}

function deleteOldEntries(what) {
	formObj = document.forms[what];
	formObj.submit();
	for (i=0;i<formObj.elements.length;i++) {
		if (formObj.elements[i].name!="action" && (formObj.elements[i].type=="text" || formObj.elements[i].type=="password")) {
			formObj.elements[i].value="";
		}
	}
}

function checkTI(object) {
	formObj = document.forms['superquiz'];
	if (object.value != "") {
		actTab = object.tabIndex;
		for (i = 0; i< formObj.elements.length; i++) {
			actElement = formObj.elements[i];
			if (actElement.tabIndex == actTab+1) actElement.focus();
		}
	}
}

/**
	Create a tool bar within the templates (used for author mode only)
**/
	function makeBar(what,nr) {
		kriterium = document.getElementById('cticons'+nr).style.clip;
		if (kriterium == "rect(0px 525px 40px 0px)") {
			slideBar(525,nr,"left");
		}
		else {
			slideBar(44,nr,"right");
		}
	}

	function slideBar(what,nr,dir) {
		document.getElementById("opener"+nr).style.visibility="hidden";
		if (dir == "left") { what = what-37; }
		if (dir == "right") { what = what+37; }
		if (what >= 44 && what <= 525) {
			document.getElementById('cticons'+nr).style.clip="rect(0px "+what+"px 40px 0px)";
			self.setTimeout("slideBar("+what+",'"+nr+"','"+dir+"')",1);
		}
		else {
			if (what == 7) {
				document.getElementById("opener"+nr).style.visibility="visible";
			}
		}
	}

	function openOpener(page,ctobid,what,ctsite,prefix,anc) {
		if (checkOpener()) {
			self.opener.document.location.href=prefix+"/ctadmin/"+page+"?ctobid="+ctobid+"&"+what+"="+ctsite;
			self.opener.top.frames['leftFrame'].document.location.href=prefix+"/ctadmin/tree.jsp?ctobid="+anc+"&ctsite="+ctsite+"#"+anc;
			self.opener.focus();
		}
	}

	function checkOpener() {
		try {
			if (self.opener.document.location.href.indexOf("ctadmin")==-1) {
				alert("This action cannot be performed!\nReason: Try to access admin from popup!");
				return false;
			}
			else if (self.opener.closed == false) { return true; }
			else {
				alert("This action cannot be performed!\nReason: Opening window has been closed!");
				return false;
			}
		}
		catch (e) {
			alert("This action cannot be performed!\nReason: Opening window has been moved or reloaded!");
		}
	}

	function moveMe(what,ob1,ob2,prefix) {
		if (checkOpener()) {
			self.opener.document.location.href=prefix+"/ctadmin/list.jsp?"+what+"="+ob1+"&ctobid="+ob2;
			self.document.location.reload();
			self.focus();
		}
	}

	function setCookie(what,val) {
		document.forms[what].elements['myCookie'].value=val;
		document.forms[what].submit();
	}

	function askMe(what2,what,prefix) {
		if (checkOpener()) {
			var elem =(what==what2)?"page":"page element";
			var asking =window.confirm("Do you really wish to delete this "+elem+"?");
			if (asking == true) self.opener.document.location.href=prefix+"/ctadmin/list.jsp?ctobid="+what+"&ctdelete="+what2;
			self.location.reload();
			self.focus();
		}
	}
	
	/**
	Function to create a pop up window
**/
	function ctpopup(datei) {
		var newWind = window.open(datei, "ctolpopup", "width=660,height=530,resizable=no,menubar=no,scrollbars=yes,status=yes");
		newWind.focus();
	}
	
	function showPersons() {
		formObj = document.forms['conform'];
		selecter = formObj.elements['persons'];
		active = selecter.options[selecter.selectedIndex].value;
		personHead = document.getElementById('personhead');
		
		person1active = formObj.elements['acc_act1'];
		person2active = formObj.elements['acc_act2'];
		person3active = formObj.elements['acc_act3'];

		personHead.style.display="none";
		person1.style.display="none";
		person2.style.display="none";
		person3.style.display="none";
		person1active.value = 0;
		person2active.value = 0;
		person3active.value = 0;

		if (active != 0) {
			personHead.style.display="inline";
			person1.style.display="inline";
			person1active.value = 1;
		}
		if (active > 1) {
			person2.style.display="inline";
			person2active.value = 0;
		}
		if (active > 2) {
			person3.style.display="inline";
			person3active.value = 1;
		}
		self.focus();
	}