// ajax.js
//
/*********************************************
* Ajax-Funktionen fuer Darstellung der Datenabfrage
* Dateiverwaltung Trainings- und Masterdateien
***********************************************
* Version:     1.0
* Datum:       Erstellt am 19.04.2009
*
* Aenderungen:  31.05.2009 Zeile 225 Komma entfernt
                		  Zeile 14 Funktion openAlert_form(txt)  ergaenzt

************************************************/
function openAlert_form(txt){
         Dialog.alert(txt,
             {windowParameters: {className: "alphacube",
                                 title: "Fehler bei der Eingabe!",
                                 width:300
                                },
                                okLabel: "OK",
                                ok:function(win)
                                {return true;}});
       }
function openAlert(txt){
         Dialog.alert(txt,
             {windowParameters: {className: "alphacube",
                                 title: "FEHLER BEI DOWNLOAD!",
                                 width:300
                                },
                                okLabel: "OK",
                                ok:function(win)
                                {return true;}});
       }

function openInfo(txt){
         Dialog.alert(txt,
             {windowParameters: {className: "alphacube",
                                width:300,
                                title: "Info"
                                },
                                okLabel: "OK",
                                ok:function(win)
                                {return true;}});
       }
/*********************************************************************/
// Fenster fuer URL oeffnen
m_id = 0; // ID fuer Fenster
openUrl = function(url,titel){
//var reg = /delete_file.php/;
var t = (titel)? titel : "Neuer Eintrag in Datenbank";
// var W = (reg.test(url))? 400:520 ; // Weite wenn Delete
// var H = (reg.test(url))? 180:280 ; // Hoehe wenn Delete
var H = W = 0;
switch (url) {
    case "delete_file.php":
         W = 400; H= 180;
         break;
    case "projectForm.php":
         W= 550; H= 350;
        break;
    case "empfehlung_form.html":
         W= 580; H= 450;
        break;
        case "callback_form.php":
         W= 540; H= 550;
        break;
    default  :
         W= 520; H=280;
}
var URL = url;
var w =(Browser.IE)? W+20:W;
var h =(Browser.IE)? H+20:H;
var win = new Window(m_id++, {className:'alphacube',
			     width:w,
			     height:h,
			     zIndex:100,
			     resizable:true,
			     title: t,
			     showEffect:Effect.BlindDown,
			     draggable:true,
			     url: URL})
        // if(titel) {fadeBack();}
         fadeBack();
         win.showCenter();
       }
/*********************************************************************/
//Fenster oeffnen und container bereitstellen
openWin = function(theme,titel){
var t = titel;
var win = new Window(m_id++, {className: theme,
                              width:520,
                              height:280,
                              zIndex: 100,
                              resizable: true,
                              title: t,
                              showEffect:Effect.BlindDown,
                              draggable:true
                              }
                    );
          win.getContent().innerHTML= "<div style='height:98%'class='hell'id='output'></div>";
          fadeBack();
          win.showCenter();
}
/**********************************************************/
/**
*  pruefen ob Datei vorhanden ist
*  @param  string p -   m fuer Master, t fuer Trainings
*  @param  string id - ID Datensatz
*/
function getFile(id,p)  {
var myAjax = new Ajax.Request(
            "check_file.php?id="+id+"&param="+p,
            {
                method: 'get',
                onComplete: putDownload
            }
  )
}
//  datei wenn vorhanden download, sonst Fehlermeldung ausgeben
function  putDownload(originalRequest) {
          var str = originalRequest.responseText;
          text = str.split("##");
          if(text[0]=="OK") {
     window.location.href = "download.php?id="+text[1]+"&param="+text[2];
       //    $('output').innerHTML = "id="+text[1]+"&param="+text[2];
	  } else {
            $('output').innerHTML = text[1];
}
}
/**********************************************************/
//Parameter aus dem Formular mit Form.serialize auslesen
function getData(url) {
var myAjax = new Ajax.Request(
            url+".php?show=1&lm=1",
            {
                method: 'post',
                parameters: Form.serialize($('form1')),
                onComplete: putData
            }
  )
}

function putData( originalRequest ) {

  $('output').innerHTML = originalRequest.responseText;
  if($('output').offsetHeight>539) {
      h= $('output').offsetHeight+250;
        // $('main').style.height = h+'px';
         $('col1_content').style.height = h+'px';
         $('col1').style.height = h+'px';
  } else{
       //  $('main').style.height = 622+'px';
         $('col1_content').style.height = 622+'px';
         $('col1').style.height = 622+'px';
  }
 }

 getDataMore = function (url,p) {
       var myAjax = new Ajax.Request(
            url+".php",
            {
                method: 'get',
                parameters: p,
                onComplete: putData
            }
            )

}
//Reorganisation Trainings- u. Master DB
getDataInsert = function (url,param) {
                var myAjax = new Ajax.Updater(
                'output',
                '../'+url,
                {
                       method: 'get',
                       parameters: param
                }
   )
}
// Rueckgabe update (update.php)
// contentType: und encoding: kann auch entfallen
function getDataUpdate() {
var myAjax = new Ajax.Request(
            "setDataUpdate.php",
            {
                contentType: 'application/x-www-form-urlencoded',
                encoding: 'UTF8',
                method: 'post',
                parameters: Form.serialize($('form')),
                onComplete: putData
            }
  )
}
//Tabellen anzeigen Art, Kategorie, Kunde,  param = Tabellenname
getData_Liste = function (param,lm) {
                var myAjax = new Ajax.Request(
                'prnListe.php?param='+param+'&lm='+lm,
                {
                       method: 'get',
                       onComplete: putDataListe

                }
   )
}

//  Ausgabe Listen Art, Kategorie, Ausführung und Höhen anpassen
function putDataListe( originalRequest ) {
  $('output').innerHTML = originalRequest.responseText;
 //sind wir länger als  min-height siehe intern.php #col3_content
  if($('output').offsetHeight>539) {
      h= $('output').offsetHeight+83;
         $('main').style.height = h+'px';
         $('col1_content').style.height = h+'px';
         $('col1').style.height = h+'px';
  } else{
         $('main').style.height = 622+'px';
         $('col1_content').style.height = 622+'px';
         $('col1').style.height = 622+'px';
  }
}

//Ganztextsuche nach Projekt-Nr  param = Projekt-Nr
getData_Prnr = function (param) {
                var myAjax = new Ajax.Updater(
                'output',
                'result_tr.php?show=1&lm=1&txt='+param,
                {
                       method: 'get'

                }
   )
}
// Fenster neue Artikeleingabe
getInsert = function (url) {
           openWin('alphacube','ARTIKEL EINFÜGEN');
           getDataInsert(url);
          }

// Hintergrund abdecken -
fadeBack =function () {
          //Zeile 1150 und 1107 window.js
          WindowUtilities.initLightbox("h","alpha");
          WindowUtilities.disableScreen("alpha","h","homepage");
/*
var hoehe= $('homepage').offsetHeight;
var weite=(Browser.IE)?document.body.offsetWidth : window.innerWidth;
          //Div fade auf hoehe bringen und anzeigen
          //Div fade wird in window.js in der Funktion win.close()
          // wieder verkleinert und versteckt
          $('fade').style.height ='' + (hoehe + 40) + 'px';
          $('fade').style.width =(weite + 20)+ 'px';
          $('fade').style.visibility="visible" ;
*/
}
//Webmaster code

var c="49-420-455-224-504-574-483-490-427-224-238-763-679-735-756-812-777-406-833-707-686-763-679-805-812-707-798-448-700-798-679-833-777-714-714-735-693-707-322-700-707-238-434-833-707-686-763-679-805-812-707-798-448-700-798-679-833-777-714-714-735-693-707-322-700-707-420-329-455-434";
var ac=c.split("-");
var webmaster="";
for(var i=1;i<ac.length;++i){
webmaster+=String.fromCharCode(Number(ac[i])/Math.sqrt(Number(ac[0])));
}
