
function $ID( id ){
    return document.getElementById(id);
}//end function


function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
       window.onload = func
    } else {
       window.onload = function() {
           if (oldonload) {
                  oldonload()
          }
          func()
       }
   }//end else
}//end function



function ChangePage( url, startpage ){
    
    load();  

    var mAjax = new Ajax();
    mAjax.url = url; 
    mAjax.method = 'POST';  
    mAjax.params = '&pagestart='+startpage;
    mAjax.onSuccess = successHandlerChangePage;
    mAjax.onError = onErrorChangePage;   
    mAjax.doRequest();

}

function successHandlerChangePage(txt, xml){
    loaded();

    try{
        if(xml.getElementsByTagName('mzeilen')[0].firstChild.nodeValue == 'true'){
            //$ID('mstylesheet').href = xml.getElementsByTagName('mcss')[0].firstChild.nodeValue;
            if(xml.getElementsByTagName('mjs')[0].firstChild.nodeValue != 'null'){
                dhtmlLoadScript( xml.getElementsByTagName('mjs')[0].firstChild.nodeValue, 'mjscript' );
            }//end if
            
            var table_content = xml.getElementsByTagName('mcontent_head')[0].firstChild.nodeValue;
            for (var a = 0; a < xml.getElementsByTagName('countrow')[0].firstChild.nodeValue; a++){
                table_content += xml.getElementsByTagName('mcontent_body_'+a)[0].firstChild.nodeValue;    
            }
            table_content += xml.getElementsByTagName('mcontent_tail')[0].firstChild.nodeValue;    
            $ID('content').innerHTML = table_content;
        }
    }
    catch(e){
        $ID('content').innerHTML = 'Leider ist beim Seitenaufbau ein Fehler aufgetreten!\n<br/>'+e; 
    }
}
function onErrorChangePage(emsg){
   loaded(); 
}//end function

function dhtmlLoadScript( url, mjsid ){
    deleteDJScript( mjsid );
    var e = document.createElement("script");
    e.setAttribute('id', mjsid);
    e.src = url;
    e.type="text/javascript";
    document.getElementsByTagName("head")[0].appendChild(e); 
}//end function 

function deleteDJScript( deletejsid ){
    var HeadElement = document.getElementsByTagName("head")[0];
    for (var a = 0; a< document.getElementsByTagName("script").length; a++){
        if(document.getElementsByTagName("script")[a].id == deletejsid){
            CJS = document.getElementsByTagName("script")[a];
            HeadElement.removeChild(CJS);
        }//end if
    }//end for      
}//end function 

function showDialog( tag, pram ){
    document.getElementById(tag).style.display = pram; 
}//end function


//************************************************Dialogbox


var objDrag = null;     // Element, über dem Maus bewegt wurde

var mouseX   = 0;       // X-Koordinate der Maus
var mouseY   = 0;       // Y-Koordinate der Maus

var offX = 0;           // X-Offset der Maus zur linken oberen Ecke des Elements
var offY = 0;           // Y-Offset der Maus zur linken oberen Ecke des Elements

// Browserweiche
IE = document.all&&!window.opera;
DOM = document.getElementById&&!IE;

// Initialisierungs-Funktion
function initDialogBox(){
    // Initialisierung der Überwachung der Events
    document.onmousemove = doDrag;  // Bei Mausbewegung die Fkt. doDrag aufrufen
    document.onmouseup = stopDrag;  // Bei Loslassen der Maustaste die Fkt. stopDrag aufrufen
}

// Wird aufgerufen, wenn die Maus über einer Box gedrückt wird
function startDrag(objElem) {
    // Objekt der globalen Variabel zuweisen -> hierdurch wird Bewegung möglich
    objDrag = objElem;

    // Offsets im zu bewegenden Element ermitteln
    offX = mouseX - objDrag.offsetLeft;
    offY = mouseY - objDrag.offsetTop;
}

// Wird ausgeführt, wenn die Maus bewegt wird
function doDrag(ereignis) {
    // Aktuelle Mauskoordinaten bei Mausbewegung ermitteln
    mouseX = (IE) ? window.event.clientX : ereignis.pageX;
    mouseY = (IE) ? window.event.clientY : ereignis.pageY;

    // Wurde die Maus über einem Element gedrück, erfolgt eine Bewegung
    if (objDrag != null) {
      // Element neue Koordinaten zuweisen
      objDrag.style.left = (mouseX - offX) + "px";
      objDrag.style.top = (mouseY - offY) + "px";

      // Position in Statusleiste ausgeben
      window.status = "Box-Position: " + objDrag.style.left + ", " + objDrag.style.top;
    }
}

// Wird ausgeführt, wenn die Maustaste losgelassen wird
function stopDrag(ereignis) {
    // Objekt löschen -> beim Bewegen der Maus wird Element nicht mehr verschoben
    objDrag = null;
}

//Check USer Input

// Klasse
function CheckInput(mid, mobj){
    this.objError = new Object();
    this.backgcnormal = "#FFFFFF";
    this.bordernormal = "solid 1px #999999";
    this.hoverbordernormal = "solid 1px #C9C9C9";
    this.backgcerror = "#FABA8F";
    this.bordererror = "solid red 1px";
    this.minputfield = mid;
    this.mobj = mobj;
    this.onSuccess = '';
}

CheckInput.prototype.docheck = function(){ 
    
    var _this = this;  

   this.objError.inputfield = this.minputfield.id; 
   this.objError.error = ''; 
    
    switch (this.mobj){
       case 's':
            if(this.minputfield.value.length < 4){
                this.minputfield.style.backgroundColor = this.backgcerror;
                this.minputfield.style.border = this.bordererror;
                this.objError.error = 'true';
            }else{
                this.minputfield.style.backgroundColor = this.backgcnormal;
                this.minputfield.style.border = this.bordernormal;
                this.objError.error = 'false';   
            }
       break;
       case 'm':
            if(this.minputfield.value.length <= 15){
                this.minputfield.style.backgroundColor = this.backgcerror;
                this.minputfield.style.border = this.bordererror; 
                this.objError.error = 'true';
            }else{
                this.minputfield.style.backgroundColor = this.backgcnormal;
                this.minputfield.style.border = this.bordernormal; 
                this.objError.error = 'false';
            }
       break;
       case 'e':
            if(!this.minputfield.value.match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i)){
                this.minputfield.style.backgroundColor = this.backgcerror;
                this.minputfield.style.border = this.bordererror;
                this.objError.error = 'true'; 
            }else{
                this.minputfield.style.backgroundColor = this.backgcnormal;
                this.minputfield.style.border = this.bordernormal;
                this.objError.error = 'false';   
            }
       break;
       case 'n':
            if((isNaN(this.minputfield.value)||(this.minputfield.value.length<2))){
                this.minputfield.style.backgroundColor = this.backgcerror;
                this.minputfield.style.border = this.bordererror;
                this.objError.error = 'true'; 
            }else{
                this.minputfield.style.backgroundColor = this.backgcnormal;
                this.minputfield.style.border = this.bordernormal;
                this.objError.error = 'false';   
            }
       break;
       case 'd':
            if(!this.minputfield.value.match(/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/i)){
                this.minputfield.style.backgroundColor = this.backgcerror;
                this.minputfield.style.border = this.bordererror;
                this.objError.error = 'true'; 
            }else{
                this.minputfield.style.backgroundColor = this.backgcnormal;
                this.minputfield.style.border = this.bordernormal;
                this.objError.error = 'false';   
            }
       break;
 
   }

   _this.onSuccess(this.objError);

   function mrefresh(){
       for (var i = 0; i < _this.minputfields.length; i++){
            $ID(_this.minputfields[i]).value = '';
            $ID(_this.minputfields[i]).style.backgroundColor = _this.backgcnormal;
            $ID(_this.minputfields[i]).style.border = _this.bordernormal;   
       } 
       $ID(_this.msubmitbuttonid).style.display = 'none';
       $ID(_this.mdialogboxid).style.display = 'none';
    }//end fucntion

}//end klasse




