/**
*
* @package Brylle
* @version 1.0
* @copyright (c) 2007 J. Seyfried, http://www.joerg-seyfried.de
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
*
* Demo at http://www.macmini-forum.de
*/

// brylle_common.js - common functions
// needs either brylle.js or brylle_nonajax.js 
// which have to be included AFTER this file.

var timeoutCloseCheck = 500;
var lastId = "0";
var curId = "0";
var load = -1;

var reloadInt = timeoutFocus;

var eText="";
var isLoading = false;
var xmlreqs = new Array();

function CXMLHTTP() {
	this.free = false;
	this.req = null;

	    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    		try {
				this.req = new XMLHttpRequest();
	        } catch(e) {
				this.req = null;
        	}
	    // IE/Windows ActiveX crap
    	} else if(window.ActiveXObject) {
       		try {
	        	this.req = new ActiveXObject("Msxml2.XMLHTTP");
    	  	} catch(e) {
        		try {
          			this.req = new ActiveXObject("Microsoft.XMLHTTP");
	        	} catch(e) {
    	      		this.req = null;
        		}
			}
    	} 
}

function getHTTPObject() {
    var pos = -1;
	for (var i=0; i<xmlreqs.length; i++) {
		if (xmlreqs[i].free) { pos = i; break; }
	}
	if (pos == -1) { 
		pos = xmlreqs.length; 		
    }
    xmlreqs[pos] = new CXMLHTTP();
	//document.getElementById('debug').innerHTML += "new "+pos;
	return pos;
}

function deleteHTTPObject(pos) {
	//document.getElementById('debug').innerHTML += "del "+pos;

	delete xmlreqs[pos].req;
	xmlreqs[pos].req = null;
	xmlreqs[pos].free = true;
}

function getId(pos) {
//document.getElementById('debug').innerHTML += httpReq.readyState;	
	if (xmlreqs[pos].req.readyState == 4) {
		if (xmlreqs[pos].req.status == 200) {
			lastId = xmlreqs[pos].req.responseText;
		} 
		setTimeout("deleteHTTPObject(pos)", 1000);
		if (curId<lastId) loadNext();
		//isLoading = false;
	}
}


var id=0;
var oldcolor;
var newcolor;
var retries = 0;

load = setTimeout('loadNext()', reloadInt);

window.onfocus=function(){
        loadNext();
        reloadInt = timeoutFocus;
}
        
window.onblur=function(){
	reloadInt = timeoutBlur;
} 


//
// editPost - open an edit-window
function editPost(msgid) {
	win = window.open(path+"post.php?mode=edit&id="+msgid, "Editieren", 
	"width=300,height=250,left=120,top=100,menubar=no,location=no,resizable=no,scrollbars=no,status=no");	
	oldcolor = document.getElementById('b'+msgid).style.backgroundColor;
	newcolor = "#d0ffd0";
	document.getElementById('b'+msgid).style.backgroundColor=newcolor;
}

//
// deletePost - open a confirmation window
function deletePost(msgid) {
	oldbcolor = document.getElementById('b'+msgid).style.backgroundColor;
	newcolor = "#ff0000";
	document.getElementById('b'+msgid).style.backgroundColor=newcolor;
	window.open(path+"post.php?mode=del&id="+msgid, "L&ouml;schen", 
	"width=200,height=80,left=120,top=100,menubar=no,location=no,resizable=no,scrollbars=no,status=no");	
}


