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


function loeschen(id) {
	var id_del = id;
	var antwort = confirm("Wollen Sie diesen Datensatz wirklich löschen!");
	if (antwort == true){
		window.open("index.php?action=delete&id="+id_del, "_parent");
	} else {
		window.open("index.php");
	}
}





function insert(aTag, eTag, txtfeld) {
  var input = document.forms['formular'].elements[txtfeld];
  input.focus();
  /* für Internet Explorer */
  if(typeof document.selection != 'undefined') {
    /* Einfügen des Formatierungscodes */
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = aTag + insText + eTag;
    /* Anpassen der Cursorposition */
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -eTag.length);
    } else {
      range.moveStart('character', aTag.length + insText.length + eTag.length);      
    }
    range.select();
  }
  /* für neuere auf Gecko basierende Browser */
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Einfügen des Formatierungscodes */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
    /* Anpassen der Cursorposition */
    var pos;
    if (insText.length == 0) {
      pos = start + aTag.length;
    } else {
      pos = start + aTag.length + insText.length + eTag.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
  /* für die übrigen Browser */
  else
  {
    /* Abfrage der Einfügeposition */
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Einfügen an Position (0.." + input.value.length + "):", "0");
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    /* Einfügen des Formatierungscodes */
    var insText = prompt("Bitte geben Sie den zu formatierenden Text ein:");
    input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);
  }
}

// JavaScript Document

function switch_layer(name) {
	
	if(document.getElementById(name).style.display=='block') {
		document.getElementById(name).style.display='none';
		return false;
	} else {
		document.getElementById(name).style.display='block';
		return false;
	}

}


function select_thumb2(sel, w, h) {
URL = sel.options[sel.selectedIndex].value;
//alert(URL);

x = screen.availWidth/2-w/2;
y = screen.availHeight/2-h/2;

var popupWindow = window.open(URL,'','menubar=no,status=no,scrollbars,toolbar=no,hotkeys,location=no,width='+w+',height='+h+',left='+x+',top='+y+',screenX='+x+',screenY='+y);

}

function preview_gallery(id, w, h) {

x = screen.availWidth/2-w/2;
y = screen.availHeight/2-h/2;

var popupWindow = window.open('gal_preview.php?galid='+id,'','menubar=no,status=no,scrollbars,toolbar=no,hotkeys,location=no,width='+w+',height='+h+',left='+x+',top='+y+',screenX='+x+',screenY='+y);

}

