function showDialog( tag, pram ){
    document.getElementById(tag).style.display = pram; 
}//end function

function cancel( url_back ){
   mChangeContent( url_back );   
}

function $ID( id ){
    return document.getElementById(id);
}//end function

function mround(x, n) {
  //if (n < 1 || n > 14) return false;
  var e = Math.pow(10, n);
  var k = (Math.round(x * e) / e).toString();
  if (k.indexOf('.') == -1) k += '.';
  k += e.toString().substring(1);
  var to = parseInt( k.indexOf('.')+1 );
  n = parseInt(n);
  n+= to;

  return k.substring(0, n); 

}//end funcrtion

function mError( mInputfield ){
   $ID(mInputfield).style.backgroundColor="#FABA8F";
   $ID(mInputfield).style.border="solid red 1px"; 
   $ID(mInputfield).focus();   
}
function mNoError( mInputfield ){
    $ID(mInputfield).style.backgroundColor="#F0F2F4";
    $ID(mInputfield).style.border="solid #606060 1px";
}

function closeErrorMessage(){
    $ID('right').innerHTML = '';  
}

function getKeyCode(event) {
   event = event || window.event;
   return event.keyCode;
}


//**********************************************************

mTimeout = '';

function LoadPage(){
    document.getElementsByTagName("title")[0].text ='Anmelden';
    mGenerateLeftNavi();
    mGenerateMiddleNavi(); 
    mGenerateRightNavi();   
    mChangeContent( 'login' ); 
}//end function 

//Left Navi
function mGenerateLeftNavi(){
    var mAjax = new Ajax();
    mAjax.url = 'basic_scripte/head_navi_links.php';
    mAjax.method = 'POST';
    mAjax.params = '';
    mAjax.onSuccess = successmGenerateLeftNavi;
    mAjax.onError = onErrormGenerateLeftNavi;
    mAjax.doRequest();  
}//end function 

function successmGenerateLeftNavi(txt, xml){
    if(xml.getElementsByTagName('merror')[0].firstChild.nodeValue != 'true'){     
        if(xml.getElementsByTagName('mlockoffjs')[0].firstChild.nodeValue != 'null'){
            dhtmlLoadScript( xml.getElementsByTagName('mlockoffjs')[0].firstChild.nodeValue, 'lockoffjscript' );
        }
        $ID('headerNavi_left').innerHTML = xml.getElementsByTagName('mnavitopleft')[0].firstChild.nodeValue;
    }else{
        $ID('right').innerHTML = xml.getElementsByTagName('merror_content')[0].firstChild.nodeValue; 
    }//end else    
}//end function 

function onErrormGenerateLeftNavi(emsg){}//end function 


//Middle Navi
function mGenerateMiddleNavi(){
    var mAjax = new Ajax();
    mAjax.url = 'basic_scripte/head_navi_middle.php';
    mAjax.method = 'POST';
    mAjax.params = '';
    mAjax.onSuccess = successmGenerateMiddleNavi;
    mAjax.onError = onErrormGenerateMiddleNavi;
    mAjax.doRequest();  
}//end function 

function successmGenerateMiddleNavi(txt, xml){
    if(xml.getElementsByTagName('merror')[0].firstChild.nodeValue != 'true'){     
        $ID('headerNavi_middle').innerHTML = xml.getElementsByTagName('mnavitopmiddle')[0].firstChild.nodeValue;
    }else{
        $ID('right').innerHTML = xml.getElementsByTagName('merror_content')[0].firstChild.nodeValue; 
    }//end else    
}//end function 

function onErrormGenerateMiddleNavi(emsg){}//end function 

//Right Navi
function mGenerateRightNavi(){
    var mAjax = new Ajax();
    mAjax.url = 'basic_scripte/head_navi_right.php';
    mAjax.method = 'POST';
    mAjax.params = '';
    mAjax.onSuccess = successmGenerateRightNavi;
    mAjax.onError = onErrormGenerateRightNavi;
    mAjax.doRequest();  
}//end function 

function successmGenerateRightNavi(txt, xml){
    if(xml.getElementsByTagName('merror')[0].firstChild.nodeValue != 'true'){     
        $ID('headerNavi_right').innerHTML = xml.getElementsByTagName('mnavitopright')[0].firstChild.nodeValue;
    }else{
        $ID('right').innerHTML = xml.getElementsByTagName('merror_content')[0].firstChild.nodeValue; 
    }//end else    
}//end function 

function onErrormGenerateRightNavi(emsg){}//end function 

//Content
function mChangeContent( url ){       
    
    var mAjax = new Ajax();
    mAjax.url = 'basic_scripte/main.php';
    mAjax.method = 'POST';
    if(mTimeout == 'true'){
        url = 'login';  
    }
    mAjax.params = CMenueVar+'='+url;  
    mAjax.onSuccess = successmChangeContent;
    mAjax.onError = onErrormChangeContent;
    //mAjax.contentID = contentID; 
    mAjax.doRequest();

}//end function

function successmChangeContent(txt, xml){

    try{
        if(xml.getElementsByTagName('merror')[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
            if(xml.getElementsByTagName('mzeilen')[0].firstChild.nodeValue == 'true'){
                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;
            }else{
                $ID('content').innerHTML = xml.getElementsByTagName('mcontent')[0].firstChild.nodeValue;    
            }//end else
        }else{
            $ID('right').innerHTML = xml.getElementsByTagName('merror_content')[0].firstChild.nodeValue; 
            mChangeContent( xml.getElementsByTagName('merror_url')[0].firstChild.nodeValue );  
        }//end else
        
        updatePosition();  
        
    }catch(e){
        if(mTimeout != 'true'){
            mShowExceptionMessage(e);
        }
        checkLoginStatus();    
    }  
}//end function 

function onErrormChangeContent(emsg){}//end function

//Change Content Klasse
function ChangeContentSubmenue(){
   this.contentID = '';
   this.xmlreply = '';  
}

ChangeContentSubmenue.prototype.Change = function(){   
    var _this = this;
    _this.contentID = this.contentID; 
    _this.xmlreply =  this.xmlreply;  
    
    try{
        if(_this.xmlreply.getElementsByTagName('merror')[0].firstChild.nodeValue == 'false'){
            if(_this.xmlreply.getElementsByTagName('mzeilen')[0].firstChild.nodeValue == 'true'){
                var table_content = _this.xmlreply.getElementsByTagName('mcontent_head')[0].firstChild.nodeValue;
                for (var a = 0; a < _this.xmlreply.getElementsByTagName('countrow')[0].firstChild.nodeValue; a++){
                    table_content += _this.xmlreply.getElementsByTagName('mcontent_body_'+a)[0].firstChild.nodeValue;    
                }
                table_content += _this.xmlreply.getElementsByTagName('mcontent_tail')[0].firstChild.nodeValue;    
                $ID( _this.contentID ).innerHTML = table_content;
            }else{
                $ID( _this.contentID ).innerHTML = _this.xmlreply.getElementsByTagName('mcontent')[0].firstChild.nodeValue;    
            }//end else
        }else{
            $ID('right').innerHTML = _this.xmlreply.getElementsByTagName('merror_content')[0].firstChild.nodeValue; 
        }//end else
    }catch(e){
        if(mTimeout != 'true'){
            mShowExceptionMessage(e);
        }
        checkLoginStatus();    
    }
}

//Zeige die Exception Fehler
function mShowExceptionMessage( error ){
    var mAjax = new Ajax();
    mAjax.url = 'basic_scripte/showerror.php';
    mAjax.method = 'POST';
    mAjax.params = '&errorMessage='+error;
    mAjax.onSuccess = successmShowExceptionMessage;
    mAjax.onError = onErrormShowExceptionMessage;
    mAjax.doRequest();  
}
function successmShowExceptionMessage(txt, xml){
    $ID('right').innerHTML = xml.getElementsByTagName('merror_content')[0].firstChild.nodeValue;
}//end function 

function onErrormShowExceptionMessage(emsg){}//end function

//Position
function updatePosition(){ 
    
    checkLoginStatus(); 
    
    var mAjax = new Ajax();
    mAjax.url = 'basic_scripte/position.php';
    mAjax.method = 'POST';
    mAjax.params = '';
    mAjax.onSuccess = successUpdatePosition;
    mAjax.onError = onErrorUpdatePosition;
    mAjax.doRequest();  
}

function successUpdatePosition(txt, xml){
    $ID('position').innerHTML = xml.getElementsByTagName('mposition')[0].firstChild.nodeValue;   
}//end function 

function onErrorUpdatePosition(emsg){}//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 checkLoginStatus(){
    var mAjax = new Ajax();
    mAjax.url = 'basic_scripte/checkLoginStatus.php';
    mAjax.method = 'POST';
    mAjax.params = '';
    mAjax.onSuccess = successcheckLoginStatus;
    mAjax.onError = onErrorcheckLoginStatus;
    mAjax.doRequest();   
}

function successcheckLoginStatus(txt, xml){
    
    if( xml.getElementsByTagName('sessiontimeout')[0].firstChild.nodeValue == 'true'){
        $ID('right').innerHTML = xml.getElementsByTagName('merror_content')[0].firstChild.nodeValue; 
        mTimeout = 'true';
        LoadPage();
    }else{
        mTimeout = 'false';
    }
   
}  

function onErrorcheckLoginStatus(emsg){}//end function 
