var ScrollTextheight
var crossobj
var speed=1
var iens6
var ns4
var url = "http://vorsicht-glas.de/"

iens6=document.all||document.getElementById
ns4=document.layers

function movedown() {
  if (window.moveupvar)
    clearTimeout(moveupvar)

  crossobj.style.top = (crossobj.style.top) ? crossobj.style.top : crossobj.offsetTop
  if (iens6&&parseInt(crossobj.style.top)>=(ScrollTextheight*(-1)+150))
    crossobj.style.top=parseInt(crossobj.style.top)-speed+"px"
  else if (ns4&&crossobj.top>=(ScrollTextheight*(-1)+100))
    crossobj.top-=speed
  movedownvar = setTimeout("movedown()",20)
}

function moveup() {
  if (window.movedownvar)
    clearTimeout(movedownvar)

  if (iens6&&parseInt(crossobj.style.top)<=-1)
    crossobj.style.top=parseInt(crossobj.style.top)+speed+"px"
  else if (ns4&&crossobj.top<=0)
    crossobj.top+=speed
  moveupvar=setTimeout("moveup()",20)
}

function stopscroll() {
  if (window.moveupvar)
    clearTimeout(moveupvar)
  if (window.movedownvar)
    clearTimeout(movedownvar)
}

function getcontent_height() {
  if (iens6)
    ScrollTextheight=crossobj.offsetHeight
  else if (ns4)
    document.nscontainer.document.nscontent.visibility="show"
}


function textClick(id, name, scroll, reset) {
  if(!id) {
    alert("no id, dude")
    return
  }
  if(!name) {
    alert("no name, dude")
    return
  }
  var data = new Array()
  data = getTextData()

  if(data[name]) {
    document.getElementById(id).innerHTML= data[name]
    if (reset == 1)
      resetScroll()

    if (scroll)
      setScroll(1)
    else
      setScroll(0)
  }
  return
}

function resetScroll() {
  document.getElementById('ScrollText').style.top = "0px"
  // crossobj = 0
  // ScrollTextheight = 0
  return
}

function setScroll(onoff) {
  if (onoff == 1)
    document.getElementById('ScrollPfeile').innerHTML = '<a href="#" onMouseOver="moveup();" onMouseOut="stopscroll();"><img name="pfeilup" src="'+url+'img/pfeil-up3.gif" border="0" alt=""></a><a href="#" onMouseOver="movedown();" onMouseOut="stopscroll();"><img name="pfeildown" src="'+url+'img/pfeil-down3-blink.gif" border="0" alt=""></a>'
  else
    document.getElementById('ScrollPfeile').innerHTML = ''
  if (iens6){
    crossobj = document.getElementById ? document.getElementById("ScrollText")
                                         : document.all.ScrollText
    ScrollTextheight = crossobj.offsetHeight}
  else if (ns4){
    crossobj = document.ScrollContainer.document.ScrollText
    contentheight = crossobj.clip.height
  }
  window.onload = getcontent_height
  return

}


function setPage(page, last) {
  if (page == 0)
    document.getElementById('PagePfeile').innerHTML = '<img name="pfeillinks" src="'+url+'img/pfeil-leer3.gif" border="0" alt=""><a href="?page='+page+'&dir=1"><img name="pfeilrechts" src="'+url+'img/pfeil-rechts3.gif" border="0" alt=""></a>'
  else if (last == 1)
    document.getElementById('PagePfeile').innerHTML = '<a href="?page='+page+'&dir=-1"><img name="pfeillinks" src="'+url+'img/pfeil-links3.gif" border="0" alt=""></a><img name="pfeillinks" src="'+url+'img/pfeil-leer3.gif" border="0" alt="">'
  else
    document.getElementById('PagePfeile').innerHTML = '<a href="?page='+page+'&dir=-1"><img name="pfeillinks" src="'+url+'img/pfeil-links3.gif" border="0" alt=""></a><a href="?page='+page+'&dir=1"><img name="pfeilrechts" src="'+url+'img/pfeil-rechts3.gif" border="0" alt=""></a>'
}

// AXAJ was here
/**
 * 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 ;
}

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

/**
 * 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 intID, 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;
}

/**
 * process the response data from server
 *
 * @param intID, Integer, ID of this response
 */
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 ) ;
            }
    }
}


// process data from server
function processData( xmlHttp, intID )
{
    // process text data
    alert( xmlHttp.responseText );
}


// handle response errors
function handleAJAXError( xmlHttp, intID )
{
    alert("handleAJAXError")
}
