// libs/search.js

function tag(s){
   if (s == null) {
           return "";
   }
   else {
   var returnstring = "";
   for (var i=0; i<tag.arguments.length; i++)
       returnstring += "<"+tag.arguments[i]+">" ;
   }
       
  document.write(returnstring);
  return returnstring;
}
//****************************************************************
//*************************** MakeArray *****************************
//***************************************************************
//Funktionen des MakeArray-Objekts
function MakeArray(){
   for (var i=0; i<MakeArray.arguments.length; i++)
      this[i] = MakeArray.arguments[i]
   this.length = MakeArray.arguments.length
   this.toString = arraytoString  //Ret.: comma-sep-string
   this.push = arraypush      // Par.: value value ....
   this.sort = arraysort     // Par.: -
   this.del = arraydel      // Par.: position
   this.delall = arraydelall
   this.ins = arrayinsert  // Par:  position, value
   this.search = arraysearch //Par.: value Ret: position
}
//Methoden
function arraytoString(){
   var returnstring = ""
   for (var i=0; i<this.length-1; i++)
      returnstring += this[i] + ","
   returnstring += this[this.length-1]
   return returnstring
}
function arraypush(){
   for (var i=0; i<arraypush.arguments.length; i++)
      this[this.length+i] = arraypush.arguments[i]
   this.length += arraypush.arguments.length
}



function arraysort(){
   var sortiert = false  //Überprüfung, ob sortiert
   while (!sortiert){
      sortiert = true
      for (var i=0; i<this.length-1; i++)
          if (this[i] >this[i+1]) {
         // Eigene Suchfunktion: 
         //if (groesser(this[i], this[i+1], arraysort.arguments[0])){
            sortiert = false
            hilfsvariable = this[i]
            this[i]=this[i+1]
            this[i+1] = hilfsvariable
         }
   }
}

// groesser() vergleicht die Werte a und b. Wird die eine Funktion in 'arg'
// angegeben, so wird diese Funktion mit den Parametern 'a' und 'b' auf-
// gerufen  
function groesser(a, b, arg){
   if (!arg)
      return (a>b)
   else{
      var erg = eval(arg + "(\"" + a + "\", \"" + b + "\")")
      return (erg>0)
   }
}

function arraydel(_position) {	
	if ((_position > this.length-1) || (_position==null ) ) return; 
	this.length--;
	for (var i=_position+1; i<this.length+1; i++){
		this[i-1] = this[i]; 
	}	
}

function arraydelall(){
  this[0]=0;
  this.length=0;
}
function arraysearch(_value) {
	var pos = -1;
	for (var i=0; i< this.length; i++) {
		if (_value == this[i]) {
			pos = i;
			break;
		}					
	}	
	return pos;
}


function arrayinsert(_position, _value) {
        if (arrayinsert.arguments.length != 2) return;
	this.length++;
	for (var i=this.length-1; i>=_position; i--)
		this[i+1] = this[i];
	this[_position] = _value;
}	

// ****************************************************************
//************************** Cookies *****************************+
// ********************************************************************

function setCookie(name, wert, domain, expires, path, secure){
   var cook = name+"="+unescape(wert)
   cook += ((domain) ? "; domain="+ domain : "" )
   cook += ((expires) ? "; expires="+expires : "")
   cook += ((path) ? "; path="+path : "")
   cook += ((secure) ? "; secure" : "" )
   document.cookie = cook
}
function eraseCookie(name, domain, path){
   var cook= name+"=; expires=Thu, 01-Jan-70 00:00:01 GMT"
   cook += (domain) ? "domain="+domain : ""
   cook += (path) ? "path="+path : ""
   document.cookie = cook
}
function getCookie(name){
   var i=0  //Suchposition im Cookie
   var suche = name+"="
   while (i<document.cookie.length){
      if (document.cookie.substring(i, i+suche.length)==suche){
         var ende = document.cookie.indexOf(";", i+suche.length)
         ende = (ende>-1) ? ende : document.cookie.length
         var cook = document.cookie.substring(i+suche.length, ende)
         return unescape(cook)
      }
      i++
   }
   return null
}
function checkCookie(){
   setCookie("CookieTest", "OK")
   if (!getCookie("CookieTest"))
      return false
   else{
      eraseCookie("CookieTest")
      return true
   }
}


//*************** Hier sollen die markierten Datensätze geschrieben werden****
function readResArray2mail(){
    if (this.document.sendform) {
       var SResArray= parent.SCode.ResArray;
       var msendform = this.document.sendform;
       for(var i=0; i< SResArray.length; i++) {

          msendform.mimessage.value += "-->"+SResArray[i]+"\n ";

      }
    }

}




//Datensätze einfügen oder Löschen
function computeResArray(n) {
  if (n == undefined ) return;
  //var mresform = parent.mainframe.document.resform;
  var mresform = parent.mainframe.document.forms['resform'];
  var SResArray= parent.SCode.ResArray;
  // first search whether data exists in array
  var ex = SResArray.search(mresform.elements[n].value);

   if (ex > -1) {
     if (mresform.elements[n].checked == false) {
           SResArray.del(ex);
     }
  }
  
  if (ex == -1) {
  //else {
     if (mresform.elements[n].checked) {
           SResArray.push(mresform.elements[n].value);
     }

  }

  
  
}





