// JavaScript Document
// functions ähnlich zur php functions

/*****************************************************************************/
/*                                                                           */
/* Funktion: toFilename()                                                    */
/* Parameter: str   Headline des Post                       STRING    IN     */
/*            ret   konvertierter Returnstring              STRING    RET    */
/*                                                                           */
/* Anmerkung: Gibt keine Dateiendung zurück !                                */
/*                                                                           */
/* Autor:    Sebastian Lüke                                     Februar 2009 */
/*                                                                           */
/*****************************************************************************/

	function toFilename(str) {

		findA = new Array();
		replaceA = new Array();

		findA.push(" ");
		replaceA.push("_");
		
		findA.push(".");
		replaceA.push("_");
		
		findA.push("-");
		replaceA.push("_");
		
		findA.push("&Auml;");
		replaceA.push("Ae");
		
		findA.push("&Ouml;");
		replaceA.push("Oe");
		
		findA.push("&Uuml;");
		replaceA.push("Ue");
		
		findA.push("&auml;");
		replaceA.push("ae");
		
		findA.push("&ouml;");
		replaceA.push("oe");
		
		findA.push("&uuml;");
		replaceA.push("ue");
		
		findA.push("&szlig;");
		replaceA.push("ss");
		
		findA.push("/");
		replaceA.push("_");
		
		var ret = str_replace(findA, replaceA, str);

		// Doppelte Unterstriche eliminieren

		ret = ret.replace(/__/g, "_");

		// Alle Zeichen ausser Ziffern, A-Z,Punkt und Unterstrich raus

		ret = ret.replace(/\W/g, "");

		// Trailing Unterstriche eliminieren

		ret = ret.replace(/_*$/g, "");

		return ret;
	}
	
	function is_array(value) 
	{ 
	   var s = typeof value; 
	   if (s === 'object') 
	   { 
		  if (value) 
		  { 
			 if (value instanceof Array) 
			 { 
				s = 'array'; 
			 } 
		  } 
		  else 
		  { 
			 s = 'null'; 
		  } 
	   } 
	   return s; 
	} 
	
	function str_replace(search, replace, subject) 
	{ 
	   if ( is_array(search) == 'array' ) 
	   { 
		  //alert('Array'); 
		  for(var i=0; i<search.length; i++) 
		  { 
			 subject = subject.split(search[i]).join(replace[i]); 
		  } 
	   } 
	   else 
	   { 
		  //alert('String'); 
		  subject = subject.split(search).join(replace); 
	   } 
	   return subject; 
	} 

/*****************************************************************************/
/*                                                                           */
/* Funktion: format_date                                                     */
/* Parameter:                                               INT       IN     */
/*                                                                           */
/* Anmerkung: formatiert Datenbankdatum auf deutsches Format                 */
/*                                                                           */
/* Autor:    Sebastian Lüke											Feb 2009 */
/*                                                                           */
/*****************************************************************************/

	function format_date(timestamp) {

		ret=timestamp.substr(8,2)+"."+timestamp.substr(5,2)+"."+timestamp.substr(0,4);   // Datum

		return ret;
	}
	
	
	function new_window(kajLink){
	  string = 'width=400,height=200,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes';
	  window.open(kajLink,'mywindow',string);
	}
	  
/*****************************************************************************/
/*                                                                           */
/* Funktion: decodeEntities                                                  */
/* Parameter:                                               INT       IN     */
/*                                                                           */
/* Anmerkung: deformatiert htmlentities                */
/*                                                                           */
/* Autor:    Sebastian Lüke											Jan 2010 */
/*    http://www.highdots.com/forums/javascript-german/umlaute-bei-alert-50395.html                                                                  */
/*****************************************************************************/

	function decodeEntities(sHTML) {
		var sText = null;
		if (typeof document.createElement != "undefined") {
			var oElem = document.createElement("span");
			if (typeof oElem.innerHTML != "undefined") {
				oElem.innerHTML = sHTML;
				if (typeof oElem.firstChild != "undefined"
					&& typeof oElem.firstChild.nodeValue != "undefined")
				sText = oElem.firstChild.nodeValue;
			}
		}
		return sText;
	}
/*****************************************************************************/
/*                                                                           */
/* Funktion: submitForm                                                  */
/* Parameter:                                               INT       IN     */
/*                                                                           */
/* Anmerkung: sendet ein submit mittels IS ab          */
/*                                                                           */
/* Autor:    Sebastian Lüke											Apr 2010 */
/*****************************************************************************/
	function submitForm(action){
		document.update.submit();
	}
	function submitFormById(mid){
		document.getElementById(mid).submit();
	}
	
	
	Array.prototype.contains = function (elem) {
	  var i;
	  for (i = 0; i < this.length; i++) {
		if (this[i] == elem) {
		  return true;
		}
	  }
	
	  return false;
	};

	Array.prototype.smaller_as = function (elem) {
	  var i;
	  for (i = 0; i < this.length; i++) {
		if (this[i] <= elem) {
		  return false;
		}
	  }
	
	  return true;
	};
