var oe = function (Fehler,Datei,Zeile)
{
	alert('Es ist der JS- Fehler: '+Fehler+', in der Datei: '+Datei+', in der Zeile: '+Zeile+'Aufgetreten.');
}

var o2 = function ()
{
	return true;	
}

window.onerror=o2;

if(navigator.appVersion.match(/MSIE/) && !(navigator.appVersion.match(/Macintosh/) || navigator.appVersion.match(/Konqueror/) || window.opera))document.IE=true; else document.IE=false;

document._root='/skischule';

var $ = function (Id,Parent)
{
	return (Parent || document).getElementById(Id);
}

var $T = function (Tag,Parent,Index){
	return (Parent || document).getElementsByTagName(Tag)[(Index || 0)];
}

var $TA = function (Tag,Parent)
{
	return (Parent || document).getElementsByTagName(Tag);
}

document.getElementsByClassName = function (ClassName,Parent)
{
	var ctr=0;
	var All=document.all?($(Parent) || document).all:($(Parent) || document).getElementsByTagName('*');
	var Objects=[];
	for(var i=0;i<All.length;i++){
		
		if(All[i].className==ClassName){
			Objects=Objects.concat([All[i]]);
		}
	}
	return Objects;
}

var $C = function (ClassName,Parent){
	return 	document.getElementsByClassName(ClassName,Parent);
}

var $S = function (a){
	return (a || $(a)).style;	
}

var init = function()
{
	var a=$TA('a');
	var an=$TA('a',$('navi'));
	var inp=$TA('input',$('iCont2'));
	$('admin').ondblclick = function()
	{
		window.location.href='http://' + window.location.hostname + '/admin.htm';
	}
	for(var i=0;i<a.length;i++){
		a[i].onmousedown=function()
		{
			this.onfocus=function()
			{
				this.blur();
			}
		}
		a[i].onmouseout=function()
		{
			this.onfocus=function(){}
		}
		a[i].onmouseup=function()
		{
			this.onfocus=function(){}
		}	
	}
	
	for(i=0;i<an.length;i++){
		if(an[i].firstChild.src.indexOf('_o.gif')==-1){
			an[i].onmouseover=function()
			{
				this.firstChild.src=this.firstChild.src.replace(/\.gif/,'_o.gif');
			}
			
			an[i].onmouseout=function()
			{
				this.firstChild.src=this.firstChild.src.replace(/\_o\.gif/,'.gif');
				this.onfocus=function(){}
			}
		}
	}
	if(document.IE==true){
		for(i=0;i<inp.length;i++){
			if(inp[i].className=='switcher'){
				inp[i].onclick=function(){
					var tds = this.form.getElementsByTagName('div');
					for(var x=0;x<tds.length;x++){
						if(tds[x].className=='conttextCont'){
							if(tds[x].firstChild.tagName.toLowerCase()=='textarea'){
								var Text=tds[x].firstChild.value;
								var Id=tds[x].firstChild.id;
								tds[x].removeChild(tds[x].firstChild);
								var dv=tds[x].appendChild(document.createElement('<DIV CONTENTEDITABLE CLASS=conttext ID='+Id+'>'));
								dv.innerHTML=Text;
							}
							else{
								Text=tds[x].firstChild.innerHTML;
								Id=tds[x].firstChild.id;
								tds[x].removeChild(tds[x].firstChild);
								dv=tds[x].appendChild(document.createElement('<TEXTAREA CLASS=conttext ID='+Id+' NAME='+Id+'>'));
								dv.value=Text.replace(/<BR>/g,'<br />').replace(/<EM>/g,'<em>').replace(/<U>/g,'<u>').replace(/<\/EM>/g,'</em>').replace(/<\/U>/g,'</u>');
							}
						}
						else if(tds[x].className=='conttextCont2'){
							if(tds[x].firstChild.tagName.toLowerCase()=='textarea'){
								var Text=tds[x].firstChild.value;
								var Id=tds[x].firstChild.id;
								tds[x].removeChild(tds[x].firstChild);
								var dv=tds[x].appendChild(document.createElement('<DIV CONTENTEDITABLE CLASS=conttext2 ID='+Id+'>'));
								dv.innerHTML=Text;
							}
							else{
								Text=tds[x].firstChild.innerHTML;
								Id=tds[x].firstChild.id;
								tds[x].removeChild(tds[x].firstChild);
								dv=tds[x].appendChild(document.createElement('<TEXTAREA CLASS=conttext2 ID='+Id+' NAME='+Id+'>'));
								dv.value=Text.replace(/<BR>/g,'<br />').replace(/<EM>/g,'<em>').replace(/<U>/g,'<u>').replace(/<\/EM>/g,'</em>').replace(/<\/U>/g,'</u>');
							}
						}
					}
				}
			}	
			else if(inp[i].className=='delete'){
				inp[i].onclick=function()
				{
					postValues('admin.htm','_self','frm','del',this.id.replace(/del\_/,''),'Id',this.form.Id.value);
				}
			}
		}
	}
}


var  postValues = function(Act,Targ,Id,Name,Value){
	var Names 	= 	[Name];
	var Values 	= 	[Value];
	if(arguments.length>6){
		for (var i=3;i<arguments.length;i++){
			if ((i%2)==1){
				Names=Names.concat([arguments[i]]);
			}
			else{
				Values=Values.concat([arguments[i]]);
			}
		}
	}
	var Form = makeForm('post',Act,Targ,Id);
	Form.encoding = "multipart/form-data";
	for(i=0;i<Names.length;i++){
		makeHiddenField(Form,Names[i],Values[i]);
	}
	Form.submit();
	return false;
}

var makeForm = function(Meth,Act,Targ,Id){
	var frmElem=document.createElement('form');
	var myForm=document.getElementsByTagName('body')[0].appendChild(frmElem);
	myForm.name=Id;
	myForm.id=Id;
	myForm.target=Targ;
	myForm.action=Act;
	myForm.method=Meth;
	return myForm;
}

var makeHiddenField = function(Form,Name,Value){
	var myHidd=Form.appendChild(document.IE==true?document.createElement('<INPUT TYPE=HIDDEN />'):document.createElement('input'));
	if(document.IE==false){
		myHidd.setAttribute('type','hidden');
	}
	myHidd.id=Name;
	myHidd.name=Name;
	myHidd.value=Value;
}


var subm=function(obj){
	var tds = obj.form.getElementsByTagName('div');
	for(var x=0;x<tds.length;x++){
		if(tds[x].className=='conttextCont'){
			if(tds[x].firstChild.tagName.toLowerCase()!='textarea'){
				var Text=tds[x].firstChild.innerHTML;
				var Id=tds[x].firstChild.id;
				tds[x].removeChild(tds[x].firstChild);
				var dv=tds[x].appendChild(document.createElement('<TEXTAREA CLASS=conttext ID='+Id+' NAME='+Id+'>'));
				dv.value=Text;
			}
		}
		if(tds[x].className=='conttextCont2'){
			if(tds[x].firstChild.tagName.toLowerCase()!='textarea'){
				var Text=tds[x].firstChild.innerHTML;
				var Id=tds[x].firstChild.id;
				tds[x].removeChild(tds[x].firstChild);
				var dv=tds[x].appendChild(document.createElement('<TEXTAREA CLASS=conttext2 ID='+Id+' NAME='+Id+'>'));
				dv.value=Text;
			}
		}
	}
	obj.form.submit();
	return false;
}
window.onload=init;
