// Steffen 09.01.07
oe2edit_preloadImages('../oe/images/login/login_20_button_over.gif', '../oe/images/login/login_19_button_over.gif');



function getKeyCode(ev)
{
    if(ev.which != undefined)//Firefox
    {
        if(ev.which>0)
        {
            return ev.which;
        }
        else if(ev.keyCode != undefined)
        {
            return ev.keyCode;
        }
        else if (ev.modifiers != undefined)
        {
            return ev.modifiers;
        }
        else
        {
            return false;
        }
    }
    else //1337 M$ I3xPl0r3r0r, die erste Wahl fuer den anspruchsvollen Surfer
    {
        return ev.keyCode;
    }
}

function KeyEvents(ev)
{    for(var i=0;i<=ACCESSKEYS.length;i++)
    {
        if(ACCESSKEYS[i] == getKeyCode(ev))
        {
 
 		//alert("Array Element: " + String(i));
			wassollgeladenwerden();
        }
    }
}
//------------------------------------------------------------------------

function gallery_action(dowhattodo){
	window.document.oe2edit_form.module_action.value = dowhattodo;
	window.document.oe2edit_form.submit();
	return true;
}
function delete_gallery_images(){
	var Check = confirm("Wollen Sie wirklich alle gewählten Dateien entgültig vom Server löschen?");
	if (Check == true){
		window.document.oe2edit_form.module_action.value = "gallery_delete_files";
		window.document.oe2edit_form.submit();
	}else{
		return false;
	}
	return true;
}
function rueckfrage_link(frage,linkurl){
	var Check = confirm(frage);
	if (Check == true){
		document.location.href = linkurl;
	}else{
		return false;
	}
	
	return true;
}

function delete_selector(dateiname){
	dateiname.toString();
	trashbox_full = new Image ();
	trashbox_empty = new Image ();
	trashbox_full.src = "../oe/images/icons/trashbox-20_full.gif";
	trashbox_empty.src = "../oe/images/icons/trashbox-20.gif";
	//alert(dateiname+": "+document.forms[0]["deletefile_"+dateiname].value);
	if(document.forms[0]["deletefile_"+dateiname].value == 1){
		// Wenn schon selected wieder deselecten
		document["datei_"+dateiname].border = 0;
		document["datei_"+dateiname].style.border = "0px solid red";
		document.forms[0]["deletefile_"+dateiname].value = 0;
		document["datei_"+dateiname].alt = document.images["datei_"+dateiname].title = "Dieses Bild doch nicht vom Server löschen";
		document["datei_"+dateiname].style.filter = false;
		document['deleteicon_'+dateiname].src = trashbox_empty.src;
	}else{
		// Fürs löschen merken
		document["datei_"+dateiname].alt="Dieses Bild wird vom Server gelöscht";
		document["datei_"+dateiname].title="Dieses Bild wird vom Server gelöscht";
		document["datei_"+dateiname].style.border = "thin solid red";
		document["datei_"+dateiname].border = 1;
		document["datei_"+dateiname].style.border = "1px solid red";
		document.forms[0]["deletefile_"+dateiname].value = 1;
		document["datei_"+dateiname].style.filter = "Gray()";
		document['deleteicon_'+dateiname].src = trashbox_full.src;
	}
}


function popup(url,name,xsize,ysize)
{
	var navName = navigator.appName;
	var brVer = navigator.userAgent; var brNum; var reg = new RegExp('/');

	var breite = screen.width;
	var hoehe = screen.height;
	var agt=navigator.userAgent.toLowerCase();

	if (breite < 1024){
		top.location.href = url;
	}else{
		fenster = window.open(url, name, "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width="+xsize+",height="+ysize);
		var xpos=(breite-920)/2;
		var ypos=20;
		fenster.moveTo(xpos,ypos);
                setTimeout('fenster.focus();',200);
	}
}


function cms_save(){
	window.document.oe2edit_form.action.value = "speichern";
	window.document.oe2edit_form.submit();
}

function cms_aufrufen(){
	window.document.oe2edit_form.action.value = "edit";
	window.document.oe2edit_form.submit();
}
function wassollgeladenwerden(){

	if (document.getElementsByName('oe_search_active')[0]) {
		if (document.getElementsByName('oe_search_active')[0].value != "") {
			return false;
		}
	}
	
	if(window.document.oe2edit_form.oe_editable.value == "off"){
		// oe bewirkt nichts
		return false;
	}else if( (window.document.oe2edit_form.oe_editable.value != "") && (window.document.oe2edit_form.oe_editable.value != "true") ){
		
		shake(3);// Fenster zittert
		playSound("../oe/sounds/failure.mp3");
		alert(window.document.oe2edit_form.oe_editable.value);
		return false;
	}
	
	if(window.document.oe2edit_form.action.value == "false"){
		// oe bewirkt nichts
		// Fenster Zittert
		shake(3);
		playSound("../oe/sounds/failure.mp3");
	}else if (window.document.oe2edit_form.action.value == "alert"){ 
		// oe erzeugt Fehlermeldung in Fenster
		playSound("../oe/sounds/failure.mp3");
		shake(3);
		alert("Diese Seite kann leider nicht editiert werden.");
	}else if (window.document.oe2edit_form.action.value == "gallery_edit"){ 
		window.document.oe2edit_form.submit();		
	}else if (window.document.oe2edit_form.action.value == "guestbook_edit"){ 
		window.document.oe2edit_form.submit();		
	}else if (window.document.oe2edit_form.action.value == "vote_edit"){ 
		window.document.oe2edit_form.submit();		
	}else if ( (window.document.oe2edit_form.action.value == "edit") || (window.document.oe2edit_form.action.value == "") ){ 
		if(document.getElementById('oe_login_window').style.visibility != "hidden"){
			// Wenn Login Window gezeigt wird nicht auf oe reagieren!
			return false;
		}else if(window.document.oe2edit_form.writeright.value == "yes"){
			// ist eingeloggt und hat scheinbar schreibrechte
			// eo ruft Editor auf
			cms_aufrufen();
		}else if(window.document.oe2edit_form.writeright.value == "no"){
			window.document.oe2edit_form.action.value = "edit";
			showLogin('visible',window.document.oe2edit_form.loginWindowX.value,window.document.oe2edit_form.loginWindowY.value,'');
			//alert("Sorry, you have no right to change this text.");
		}else{
			// Der Benutzer ist nicht angemeldet, bzw kein Editor
			window.document.oe2edit_form.action.value = "edit";
			showLogin('visible',window.document.oe2edit_form.loginWindowX.value,window.document.oe2edit_form.loginWindowY.value,'Bitte melden Sie sich an.');
		}
	}else{
		shake();
	}
}

/*
function oe2editInit() {
	aler("hier!");
	return 1;
    /*var formObj = document.getElementByName("oe2edit_form");
    for (var i = 0; i<formObj.childNodes.length; i++) {
        if( (formObj.childNodes[i].nodeType == 1) && (formObj.childNodes[i].type == "text") ){
            XBrowserAddHandler(formObj.childNodes[i], "focus", HandlerFoc);
            XBrowserAddHandler(formObj.childNodes[i], "blur", HandlerBlu);
            XBrowserAddHandler(formObj.childNodes[i], "mouseover", HandlerOver);
            XBrowserAddHandler(formObj.childNodes[i], "mouseout", HandlerOut);
		document.getElementById("debugText").innerHTML += "T: ";
        }else{
		document.getElementById("debugText").innerHTML += "- ";
        }
    	document.getElementById("debugText").innerHTML += formObj.childNodes[i].name + "/" + formObj.childNodes[i].id + ": "+ formObj.childNodes[i].type + "<br>";
    }
    window.status += i+" Objekte durchlaufen";
    alert("Init beendet");
    *//*
}
function HandlerFoc() {
	window.status = "oe2edit off";
	document.textFieldInFocus = true;
}
function HandlerBlu() {
	window.status = "oe2edit on";
	document.textFieldInFocus = false;
}
function HandlerOver() {
    this.style.backgroundColor = "#FF0000";
}
function HandlerOut() {
    this.style.backgroundColor = "#FFFFFF";
}

//---------------------------------------------------------------------------
function XBrowserAddHandler(target, eventName, fnHandler) {
    var originalHandler = target["on"+eventName];
    if (originalHandler) {
        target["on"+eventName] = function (e) {
            XBrowserApplyHandler(this, originalHandler, e);
            XBrowserApplyHandler(this, fnHandler, e);
        };
    } else {
        target["on"+eventName] = function (e) {
            XBrowserApplyHandler(this, fnHandler, e);
        };
    }
}
function XBrowserApplyHandler(target, fn, e) {
    if (!e) {
        e = window.event;
    }
    if (!e) {
        alert("Problem mit XBrowserApplyHandler: Objekt nicht gefunden!");
    }
    if (Function.prototype.call) {
        fn.call(target, e);
    } else {
        target.__XBrowserElementApply = fn;
        target.__XBrowserElementApply(e);
    }
}
*/

// Fürs Voting
function vote(zeile,nummer){
	var voteimage = "voteimage"+zeile+""+nummer;
	var votevalue = "votevalue"+zeile+""+nummer;
	if(window.document.oe2edit_form[votevalue].value == 0){
		window.document.oe2edit_form[votevalue].value = 1;
		window.document.images[voteimage].src = voteimage_aktiv.src;
	}else{
		window.document.oe2edit_form[votevalue].value = 0;
		window.document.images[voteimage].src = voteimage_deaktiv.src;
	}
}


// Für das Formularsenden
function formularsenden() {
	window.document.oe2edit_form.module_action.value = "formular_senden";
	window.document.oe2edit_form.submit();

}


function SetWindowPosition (x, y) {

	// Aus den x und y Werten die "px" Angaben rausholen
	var new_x = x.replace(/px/, "");
	var new_y = y.replace(/px/, "");
	
	// Schauen, dass die Werte nicht zu klein werden
	if (new_x < 0) {
		new_x = 0;
	}
	
	if (new_y < 0) {
		new_y = 0;
	}
	
	// Werte in die Hiddenfields übernehmen
	window.document.oe2edit_form.loginWindowX.value = new_x;
	window.document.oe2edit_form.loginWindowY.value = new_y;

}



// JPG Check ####################################################################################
function jpgcheck()
{
	var filename, flag, extensionA=".jpg", extensionB=".JPG";
	filename=window.document.oe2edit_form.file.value;
	flag=window.document.oe2edit_form.flag.value;
	if (flag==1){
		playSound("../oe/sounds/failure.mp3");
		shake(3);
		alert("Der Uploadvorgang läuft.\nJe nach Leitungskapazität kann dieser Vorgang sehr lange dauern!");
		window.document.oe2edit_form.flag.value='1';
		return false;
	}
	if ( (filename.indexOf(extensionA)==-1) && (filename.indexOf(extensionB)==-1)) {
		playSound("../oe/sounds/failure.mp3");
		window.document.oe2edit_form.file.focus();
		window.document.oe2edit_form.flag.value='0';
		window.document.oe2edit_form.upload_button.disabled=false;
		//Fenster soll sich bei einem Fehler Schütteln!
		shake(3);
		alert("Bitte vergewissern Sie sich, dass Sie nur ein JPG-Datei oder ein ZIP-Archive mit JPG-Dateien ausgewählt haben.");
		return false;
	}else{
		window.document.oe2edit_form.flag.value='1';
		window.document.oe2edit_form.upload_button.disabled=true;
		window.document.oe2edit_form.submit();
		return true;
	}
}

function upload_button_click(extensionchain)
{
	extensions = new Array();
	extensions = extensionchain.split(',');
	var check = false;
	var file=window.document.oe2edit_form.file.value.toLowerCase();
	
	// Wenn kein gültiger File übergeben wurde:
	if(file.length < 5){
			playSound("../oe/sounds/failure.mp3");
			shake(3);
			alert("Die Datei "+file+" ist leider nicht erlaubt. Bitte wählen Sie eine Datei folgenden Typs "+extensionchain);
			window.document.oe2edit_form.flag.value='0';
			window.document.oe2edit_form.file.focus();
			return false;		
	}
	
	for(i=0;i<extensions.length;i++){
		if(file.indexOf( extensions[i].toLowerCase() ) > -1){
			check = true;
		}
	}
	// Wenn gar keine extension übergeben wurden alle Files akzeptieren
	if(extensions.length == 0){
		check = true;
	}
	
	flag=window.document.oe2edit_form.flag.value;
	if (flag==1){
		playSound("../oe/sounds/failure.mp3");
		shake(3);
		alert("Der Uploadvorgang läuft.\nJe nach Leitungskapazität kann dieser Vorgang sehr lange dauern!");
		window.document.oe2edit_form.flag.value='1';
		return false;
	}
	if (check == true) {
		window.document.oe2edit_form.flag.value='1';
		window.document.oe2edit_form.upload_button.disabled=true;
		window.document.oe2edit_form.submit();
		return true;
	}else{
		playSound("../oe/sounds/failure.mp3");
		window.document.oe2edit_form.file.focus();
		window.document.oe2edit_form.flag.value='0';
		window.document.oe2edit_form.upload_button.disabled=false;
		//Fenster soll sich bei einem Fehler Schütteln!
		shake(3);
		alert("Die Datei "+file+" ist leider nicht erlaubt. Bitte wählen Sie eine Datei folgenden Typs "+extensionchain);
		return false;
	}
}

function shake(n) { 
	var i;
	// n ist Bebenstärke je größer die Zahl um so stärker das Beben
	if (self.moveBy){ 
		for (i = 10; i > 0; i--) { 
			for (j = n; j > 0; j--) { 
				self.moveBy(0,i); 
				self.moveBy(i,0); 
				self.moveBy(0,-i); 
				self.moveBy(-i,0); 
			} 
		} 
	} 
}

function playSound(soundfile) {
  document.all.oe2edit_sounds.src = soundfile;
}

function oe_winresize (xspace,yspace){
	// Ließt höhe und Breite des Images aus und passt die Fenstergröße dem Bild an.
	var scrW = window.document.images[0].width+30+xspace;
	var scrH = window.document.images[0].height+30+yspace;
	var breite = screen.width;
	var hoehe = screen.height;
	if(breite < scrW){
		// Wenn die Bildschimauflösung kleiner ist als die Breite des Bildes,
		// dann soll die Popupbriete etwas kleiner als die Bildschirmauflösung sein.
		scrW = breite - breite/10;
	}
	if(hoehe < scrH){
		// das gleiche für die Höhe
		scrH = hoehe - hoehe/10;
	}
	resizeTo(scrW, scrH);
	//alert("resizeTo "+scrW+"x"+scrH);
}

//-----------------------------------------------------------------------------
var ACCESSKEYS= new Array(101,65);
//var textFieldInFocus = false;
//oe2editInit;// Dient zum inistialiesieren von Textfeldern
//-----------------------------------------------------------------------------



// Beginn Scripts fuer Login-Fenster
//var load_action = document.getElementsByName('action')[0].value;
var load_action = "";

function Tastendruck () {
    if (window.event.keyCode == 13) {								
		if (!(window.document.getElementById("user").value == "" && window.document.getElementById("password").value == "")) 
		{
			window.document.getElementsByName("ok")[0].focus();
			oe2edit_swapImage('ok','','../oe/images/login/login_19_button_over.gif',1); 
			cms_aufrufen();
		}
	}
    if (window.event.keyCode == 27) {
			window.document.getElementsByName("abbrechen")[0].focus();
			oe2edit_swapImage('abbrechen','','../oe/images/login/login_20_button_over.gif',1); 
			showLogin('hidden');
		}
}
function showLogin(eigenschaft,x_pos,y_pos,message){

	load_action = window.document.getElementsByName('action')[0].value;

	if(eigenschaft == 'hidden'){
		document.getElementById('oe_login_window').style.left = '-500px';
		document.getElementById('oe_login_window').style.top = '-500px';
		document.getElementById('password').className = "oe_login_textboxes";
		document.getElementById('password').disabled = false;
		document.getElementById('pwf_chk').checked = false;
		document.getElementById('pw_text').className = "oe_login_beschreibung";
		document.getElementsByName('action')[0].value = "" ;
		oe2edit_swapImage('abbrechen','','../oe/images/login/login_20_button.gif',1); 
	}else{
		document.getElementById('oe_login_window').style.left = x_pos+"px";
		document.getElementById('oe_login_window').style.top = y_pos+"px";
		if(message){
			document.getElementById('login_message').innerHTML = message;
		}
	}

	document.getElementById('oe_login_window').style.visibility = eigenschaft;

	// Objekt erst anzeigen, dann weiter machen 
	if(!(eigenschaft == 'hidden')){
		window.document.getElementById('user').focus();
		window.document.getElementById('password').value = '' ;
		window.setTimeout("window.document.getElementById('user').value=''",10);
		//window.document.getElementsByName('action')[0].value = "show_editor" ;

	}
}




function pwf(){
	if(window.document.getElementById('pwf_chk').checked == true){
		window.document.getElementById('pwf_chk').checked = false;
	}else{
		window.document.getElementById('pwf_chk').checked = true;
	}
	return pwf_field();
	if(window.document.getElementById('user').value.length > 3){
		window.document.forms['oe2edit_form'].submit();
	}
	return true;
}
function pwf_field(){
	if(window.document.getElementById('pwf_chk').checked == true){
		window.document.getElementById('password').className = "oe_login_textboxes_disabled";
		window.document.getElementById('pw_text').className = "oe_login_text_disabled";
		window.document.getElementById('password').disabled = true;
		window.document.getElementById('password').value = "";
		window.document.forms['oe2edit_form'].action.value = "sendpw";
	}else{
		window.document.getElementById('password').className = "oe_login_textboxes";
		window.document.getElementById('password').disabled = false;
		window.document.getElementById('pw_text').className = "oe_login_beschreibung";
		window.document.forms['oe2edit_form'].action.value = load_action;
	}
	return true;
}

// Ende Scripts Login - Fenster

function oe2edit_generate_new_file_property() {
	window.document.getElementsByName('act')[0].value = "content_prop_generatefileproperty";
	window.document.oe2edit_form.submit();
}

function oe2edit_properties_for () {
	window.document.getElementsByName('act')[0].value = "content_prop_mask";
	window.document.oe2edit_form.submit();
}

function oe2edit_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


function initiate_security_logout() {
	window.document.getElementsByName('action')[0].value = "security_logout";
	window.document.oe2edit_form.submit();
}



function oe2edit_swapImgRestore() { //v3.0
  var i,x,a=document.oe2edit_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function oe2edit_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.oe2edit_p) d.oe2edit_p=new Array();
    var i,j=d.oe2edit_p.length,a=oe2edit_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.oe2edit_p[j]=new Image; d.oe2edit_p[j++].src=a[i];}}
}

function oe2edit_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=oe2edit_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function oe2edit_swapImage() { //v3.0
  var i,j=0,x,a=oe2edit_swapImage.arguments; document.oe2edit_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=oe2edit_findObj(a[i]))!=null){document.oe2edit_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}