/*
Allgemeine JS Scripte
*/

// select all checkboxes by name
function change_checkbox(cb_name,cbx_value) {
  	for (var i = 0; i < document.form.elements.length; i++) {
		if (document.form.elements[i].name == cb_name) {
    		document.form.elements[i].checked = cbx_value;
    	}
  	}
}

// zum oeffnen eines neuen fensters ohne menubar und locationbar
function openWindow(URL,windowname,width_px,height_px) { //v2.0
	if(width_px < 10) { 
		var width_px = screen.width;
		if(width_px < 100) { width_px = 450; }
	}
	if(height_px < 10) { 
		var height_px = screen.height;
		if(height_px < 100) { height_px = 400; }
	}
	if(windowname == 'Media' || windowname == 'Bildergalerie') var toolbar_sett = 'no';  else var toolbar_sett = 'yes';
 Fenster = window.open(URL,windowname,"locationbar=no,menubar=no,status=no,toolbar="+toolbar_sett+",resizable=yes,width="+width_px+",height="+height_px+",scrollbars=yes,top=0");
	Fenster.focus();
}

// checkt VOR upload, ob richtiger datei-extension gewaehlt
function uploadcheck(file_id,info_id,ext_allowed) 
{
	if (document.getElementById(file_id).value != "") {
    var ext1 = document.getElementById(file_id).value;
	ext1 = ext1.substring(ext1.length-3,ext1.length);
    ext1 = ext1.toLowerCase();
	var Ergebnis = ext_allowed.search(new RegExp(ext1));
	if (Ergebnis == -1) { // hier wird definiert, welcher Dateityp hochgeladen werden darf
		document.getElementById(info_id).innerHTML = 'Sie haben einen falschen Dateityp gew&auml;hlt.<br>Bitte w&auml;hlen Sie die m&ouml;glichen Datei-Typen (siehe Link)!<br>';
		document.getElementById(file_id).value = "";
		document.getElementById(file_id).focus();
		return false; 
    }
	else document.getElementById(info_id).innerHTML = '';
  }
}

function changeInputType(
  oldElm, // a reference to the input element
  iType // value of the type property: "text" or "password"
  ) {  
  var newElm = document.createElement("input");
  newElm.type = iType;
  if(oldElm.name) newElm.name = oldElm.name;
  if(oldElm.id) newElm.id = oldElm.id;
  if(oldElm.className) newElm.className = oldElm.className;
  if(oldElm.size) newElm.size = oldElm.size;
  if(oldElm.tabIndex) newElm.tabIndex = oldElm.tabIndex;
  if(oldElm.accessKey) newElm.accessKey = oldElm.accessKey;

 // hasFocus is to prevent a loop where onfocus is triggered over and over again
  oldElm.parentNode.replaceChild(newElm,oldElm);
  return newElm;
}

