var ACCESSKEYS= new Array(101,65);

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 galerie_action(dowhattodo){
	window.document.oe2edit_form.oeModul_action.value = dowhattodo;
	window.document.oe2edit_form.submit();
	return true;
}
function delete_galerie_images(){
	var Check = confirm("Wollen Sie wirklich alle gewählten Dateien entgültig vom Server löschen?");
	if (Check == true){
		window.document.oe2edit_form.oeModul_action.value = "galerie_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_aufrufen(){
	window.document.oe2edit_form.submit();
}
function wassollgeladenwerden(){
	if(window.document.oe2edit_form.oe_editable.value == "off"){
		return false;
	}
	if(window.document.oe2edit_form.action.value == "false"){
		// oe bewirkt nichts
		// Fenster Zittert
		shake();
		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();
		alert("Diese Seite kann leider nicht editiert werden.");
	}else if (window.document.oe2edit_form.action.value == "galerie_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"){ 
		// eo ruft Editor auf
		cms_aufrufen();
	}else{ 
		// hier darf nichts passieren, sonst wird bei jedem eingetippten Buchstaben ein "" gespeichert :-(
	}
}


// 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;
	}
}

// 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();
		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();
		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();
			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();
		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();
		alert("Die Datei "+file+" ist leider nicht erlaubt. Bitte wählen Sie eine Datei folgenden Typs "+extensionchain);
		return false;
	}
}

function shake() { 
	var i, n = 3; // Bebenstärke
	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);
}

