addEvent(window, 'load', init, false);

function init() {
    if (!Sarissa || !document.getElementsByTagName) return;
    
    var formElements = document.getElementsByTagName('form');
    for (var i = 0; i < formElements.length; i++) {
        if (formElements[i].className.match(/\bajaxify\b/)) {
            addEvent(formElements[i], 'submit', submitRating, false);
        }
    }
}
function submitRating(e) {
    /* Cancel the submit event, and find out which form was submitted */
    knackerEvent(e);
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    /* Set up the request */
    var xmlhttp =  new XMLHttpRequest();
    xmlhttp.open('POST', 'write.php', true);
    
    /* The callback function */
    xmlhttp.onreadystatechange = function() {
	document.getElementById('commentbox').value = '';
	if (xmlhttp.readyState == 1) { 
	showLayer("loading");
	//document.chatform.comment.value = "";
	//document.getElementById('commentbox').value = '';
}
        if (xmlhttp.readyState == 4) {
			if (window.opera || navigator.appName=="Konqueror") {
			hideLayer("loading"); }
            if (xmlhttp.status == 200) 
            {
					cpg = 1;
					ajaxpage('display.php?page=1', 'chat');
					ajaxpage('pages.php', 'pages');
					hideLayer("loading");
					var xres = xmlhttp.responseXML.getElementsByTagName('msg')[0].childNodes;
					if (xres.length>0 && xres[0].nodeValue!= "") {
							alert(xres[0].nodeValue);
						}
				}
            else
                target.submit();
        }
    }
    
    /* Send the POST request */
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send('name=' + target.elements['name'].value + '&comment=' + target.elements['comment'].value);
   
}