var cur_pos=0;

var news_lenght = 1;

var from;
var to;
var step_lenght = 344;

function set_lenght( tmp )
{
 news_lenght=tmp;
}

function news_schieben()
{
 setTimeout("document.getElementById('newsbox').className='nbc1';", 200);
 setTimeout("document.getElementById('newsbox').className='nbc2';", 400);
 setTimeout("document.getElementById('newsbox').className='nbc3';", 500);
 setTimeout("document.getElementById('newsbox').className='nbc4';", 600);
 setTimeout("document.getElementById('newsbox').className='nbc5';", 700);
 setTimeout("document.getElementById('newsbox').className='nbc6';", 800);
 setTimeout("document.getElementById('newsbox').className='nbc7';", 1000);

 setTimeout("document.getElementById('newsbox').style.left=-to + 'px';", 1300);

 setTimeout("document.getElementById('newsbox').className='nbc7';", 1600);
 setTimeout("document.getElementById('newsbox').className='nbc6';", 1800);
 setTimeout("document.getElementById('newsbox').className='nbc5';", 2000);						 
 setTimeout("document.getElementById('newsbox').className='nbc4';", 2200);
 setTimeout("document.getElementById('newsbox').className='nbc3';", 2400);			 
 setTimeout("document.getElementById('newsbox').className='nbc2';", 2600);
 setTimeout("document.getElementById('newsbox').className='nbc1';", 2800);
 setTimeout("document.getElementById('newsbox').className='nbc0';", 3000);
}

function news_go_new( mode )
{
 from = cur_pos*step_lenght; 
	
 if (mode=='up')	
 {
  cur_pos=cur_pos+1;	
 } else {
  cur_pos=cur_pos-1;
 }
	
 if (cur_pos>=news_lenght)
  cur_pos=0;
  
 if (cur_pos<0)
  cur_pos=(news_lenght-1);
  
 to = cur_pos*step_lenght;
  
 news_schieben(); 
 
 return false;
}

function news_schieber()
{ 
 from = cur_pos*step_lenght; 
 to   = (cur_pos+1)*step_lenght
 
 if (cur_pos>=(news_lenght-1))
 {
  cur_pos=0;
  to = 0;
  
 } else {
  cur_pos=cur_pos+1; 
 }

 news_schieben();
}


// :::::::: welcher Browser ? ::::::::
if (document.layers) {navigator.family = "nn4"}
if (document.all) {navigator.family = "ie4"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {navigator.family = "gecko"}

overdiv="0";

//  :::::::: kreiert Tabelle für die PopUp-Box ::::::::
function popLayer(a){
if(!descarray[a]){descarray[a]="<font color=red>Dieses PopUp (#"+a+") ist nicht korrekt definiert - Beschreibung fehlt</font>";}
if (navigator.family == "gecko") {pad="0"; bord="1 bordercolor=black";}
else {pad="1"; bord="0";}
desc = "<table cellspacing=0 cellpadding="+pad+" border="+bord+" bgcolor=black><tr><td>\n"
        +"<table cellspacing=0 cellpadding=4 border=0 width=100%><tr><td class=\"help_div_table\">\n"
        +descarray[a]
        +"\n</td></tr></table>\n"
        +"</td></tr></table>";
if(navigator.family =="nn4") {
        document.help_msg.document.write(desc);
        document.help_msg.document.close();
        document.help_msg.left=x+15;
        document.help_msg.top=y-5;
        }
else if(navigator.family =="ie4"){
        help_msg.innerHTML=desc;
        help_msg.style.pixelLeft=x+15;
        help_msg.style.pixelTop=y-5;
        }
else if(navigator.family =="gecko"){
        document.getElementById("help_msg").innerHTML=desc;
        document.getElementById("help_msg").style.left=x+15;
        document.getElementById("help_msg").style.top=y-5;
        }
}

var isNav = (navigator.appName.indexOf("Netscape") !=-1);

function handlerMM(e)
{
        x = (isNav) ? e.pageX : event.clientX + document.body.scrollLeft;
        y = (isNav) ? e.pageY : event.clientY + document.body.scrollTop;
}

if (isNav){document.captureEvents(Event.MOUSEMOVE);} document.onmousemove = handlerMM;


//  :::::::: versteckt die PopUp-Box ::::::::
function hideLayer(){
if (overdiv == "0") {
        if(navigator.family =="nn4") {eval(document.help_msg.top="-500");}
        else if(navigator.family =="ie4"){help_msg.innerHTML="";}
        else if(navigator.family =="gecko") {document.getElementById("help_msg").style.top="-500";}
        }
}

function rechnungs_popup( id, type )
{
      if (type=="") { var type="RE"; }		 
      var breite=635;
      var hoehe=screen.availHeight;
      var positionX=((screen.availWidth / 2) - breite / 2);
      var positionY=((screen.availHeight / 2) - hoehe / 2);
      var url='/rechnung.php?rechn_nr=' + id + '&type=' + type;
      pop=window.open('','','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,fullscreen=0,width='+breite+',height='+hoehe+',top=0,left=0');
      pop.resizeTo(breite,hoehe);
      pop.moveTo(positionX,positionY);
      pop.location=url;
	  
	  return false;
}
	  
function doamin_loesch_popup( id )
{
      var breite=635;
      var hoehe=screen.availHeight;
      var positionX=((screen.availWidth / 2) - breite / 2);
      var positionY=((screen.availHeight / 2) - hoehe / 2);
      var url='/domain_kuendigung.php?domain_nr=' + id;
      pop=window.open('','','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,fullscreen=0,width='+breite+',height='+hoehe+',top=0,left=0');
      pop.resizeTo(breite,hoehe);
      pop.moveTo(positionX,positionY);
      pop.location=url;
}


// global xmlhttprequest object
var xmlHttp = false;



/** AJAX functions **/

// constants
var REQUEST_GET        = 0;
var REQEST_POST        = 2;
var REQUEST_HEAD       = 1;
var REQUEST_XML        = 3;



/**
 * instantiates a new xmlhttprequest object
 *
 * @return xmlhttprequest object or false
 */
function getXMLRequester( )
{
    var xmlHttp = false;
            
    // try to create a new instance of the xmlhttprequest object        
    try
    {
        // Internet Explorer
        if( window.ActiveXObject )
        {
            for( var i = 5; i; i-- )
            {
                try
                {
                    // loading of a newer version of msxml dll (msxml3 - msxml5) failed
                    // use fallback solution
                    // old style msxml version independent, deprecated
                    if( i == 2 )
                    {
                        xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" );    
                    }
                    // try to use the latest msxml dll
                    else
                    {
                        
                        xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP." + i + ".0" );
                    }
                    break;
                }
                catch( excNotLoadable )
                {                        
                    xmlHttp = false;
                }
            }
        }
        // Mozilla, Opera und Safari
        else if( window.XMLHttpRequest )
        {
            xmlHttp = new XMLHttpRequest();
        }
    }
    // loading of xmlhttp object failed
    catch( excNotLoadable )
    {
        xmlHttp = false;
    }
    return xmlHttp ;
}


/**
 * sends a http request to server
 * @param strSource, String, datasource on server, e.g. data.php
 * @param strData, String, data to send to server, optionally
 * @param intType, Integer,request type, possible values: REQUEST_GET, REQUEST_POST, REQUEST_XML, REQUEST_HEAD default REQUEST_GET
 * @param strData, Integer, ID of this request, will be given to registered event handler onreadystatechange', optionally
 * @return String, request data or data source
 */
function sendRequest( strSource, strData, intType, intID )
{
    if( !strData )
        strData = '';

    // default type (0 = GET, 1 = xml, 2 = POST )
    if( isNaN( intType ) )
        intType = 0; // GET

    // previous request not finished yet, abort it before sending a new request
    if( xmlHttp && xmlHttp.readyState )
    {
        xmlHttp.abort( );
        xmlHttp = false;
    }
        
    // create a new instance of xmlhttprequest object
    // if it fails, return
    if( !xmlHttp )
    {
        xmlHttp = getXMLRequester( );
        if( !xmlHttp )
            return;
    }
    
    // parse query string
    if( intType != 1 && ( strData && strData.substr( 0, 1 ) == '&' || strData.substr( 0, 1 ) == '?' ) )
        strData = strData.substring( 1, strData.length );

    // data to send using POST
    var dataReturn = strData ? strData : strSource;
    
    switch( intType )
    {
        case 1:    // xml
            strData = "xml=" + strData;
        case 2: // POST
            // open the connection 
            xmlHttp.open( "POST", strSource, true );
            xmlHttp.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
            xmlHttp.setRequestHeader( 'Content-length', strData.length );
            break;
        case 3: // HEAD
            // open the connection 
            xmlHttp.open( "HEAD", strSource, true );
            strData = null;
            break;
        default: // GET
            // open the connection 
            var strDataFile = strSource + (strData ? '?' + strData : '' );
            xmlHttp.open( "GET", strDataFile, true );
            strData = null;
    }
    
    // set onload data event-handler
    xmlHttp.onreadystatechange = new Function( "", "processResponse(" + intID + ")" ); ;

    // send request to server
    xmlHttp.send( strData );    // param = POST data
    
    return dataReturn;
}
    

function processResponse( intID )
{
    // status 0 UNINITIALIZED open() has not been called yet.
    // status 1 LOADING send() has not been called yet.
    // status 2 LOADED send() has been called, headers and status are available.
    // status 3 INTERACTIVE Downloading, responseText holds the partial data.
    // status 4 COMPLETED Finished with all operations.
    switch( xmlHttp.readyState )
    {
        // uninitialized
        case 0:
        // loading
        case 1:
        // loaded
        case 2:
        // interactive
        case 3:
            break;
        // complete
        case 4:    
            // check http status
            if( xmlHttp.status == 200 )    // success
            {
                processData( xmlHttp, intID );
            }
            // loading not successfull, e.g. page not available
            else
            {
                if( window.handleAJAXError )
                    handleAJAXError( xmlHttp, intID );
                else
                    alert( "ERROR\n HTTP status = " + xmlHttp.status + "\n" + xmlHttp.statusText ) ;
            }
    }
}
