// Perl-Script-URL
var scriptURL = '../cgi-bin/shoutbox/shoutbox.cgi' ;

// Refreshrate in Sekunden
var scriptREFRESH = 5 ;

// XMLHttpRequest-Instanz
var xmlHttp = false;

try {

    xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
    
} catch(e) {
    
    try {
        xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {
        xmlHttp  = false;
    }
}

if (!xmlHttp  && typeof XMLHttpRequest != 'undefined') {
	
    xmlHttp = new XMLHttpRequest();
}


// aktuelle Daten laden
loadShoutbox();


// Box-Refresh
setInterval( "loadShoutbox()" , scriptREFRESH*1000 );


// Shoutbox laden
function loadShoutbox() {
	
 	if (xmlHttp) {
 	
 		var timestamp = new Date().getTime() ;
     	xmlHttp.open('GET' , scriptURL + '?func=shoutout&nocache=' + timestamp , true) ;
     	xmlHttp.onreadystatechange = function () {
        
    	    if (xmlHttp.readyState == 4) {
        		document.getElementById("shoutbox_outputtext").innerHTML = xmlHttp.responseText ;
			}
    	}
    
        xmlHttp.send(null) ;
 	}
}


// Shoutbox speichern
function saveShoutbox() {

	if (xmlHttp) {

		// Timestamp für Nocache    
    	var timestamp = new Date().getTime() ;
    	
    	// Post absetzen
    	xmlHttp.open('POST', scriptURL) ;
    	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded') ;

		// Textfeld leeren und Focus setzen
		xmlHttp.onreadystatechange = function () {
        
    	    if (xmlHttp.readyState == 4) {
        		
        		document.ShoutboxForm.shouttext.value = '' ;
        		
        		if (!document.ShoutboxForm.shoutname.value) {
        			document.ShoutboxForm.shoutname.focus() ;
        		} else {
					document.ShoutboxForm.shouttext.focus() ;
				}
	
				// Box direkt neu laden			
				loadShoutbox() ;
			}
    	}
    	
    	// Parameter schicken
    	xmlHttp.send('sbname='+document.ShoutboxForm.shoutname.value+'&sbtext='+document.ShoutboxForm.shouttext.value+'&nocache='+timestamp) ;
	}
}


//END - AJAX -PERL - SHOUTBOX