
/** events for every page **/
function initialize() {
    checkHeight();
    init();
}

/** override for page specific onload events **/
function init() {

}

/**  opens a new window **/
function openWindow(url,height,width,title,scrollbars,statusbar,resizable,top,left) {

    if (url == null) return;
    if (title == null) title = "popup";
    if (height == null) height = "400";
	if (width == null) width = "400";
    if (left == null) left = parseInt((window.screen.width - width)/2);
	if (top == null) top = parseInt((window.screen.height - height)/2);

    var params = "height=" + height + "," +
                 "width=" + width + "," +
                 "top=" + top + "," +
                 "left=" + left;

    if (scrollbars != null) params += ",scrollbars=yes";
    if (statusbar != null) params += ",statusbar=yes";
    if (resizable != null) params += ",resizable=yes";

	var win = window.open(url, title, params);
	win.focus();
	return win;
}

function openPopup(page,height,width,title,scrollbars) {
    openWindow("popups/" + page + ".htm",height,width,title,scrollbars);
}

/**  closes a window and returns focus to the opener **/
function closeWindow(refresh) {
	if (window.opener) {
	    if (refresh)
	        window.opener.location.reload();
		window.opener.focus();
    }
	window.close();
}

/**  Returns an object from an id. **/
function getObj(objId) {
    if (typeof(objId) == "string")
        return document.getElementById(objId);
    return objId;
}

/**  Sets the display of an object to inline **/
function showLayer(obj) {
	if (typeof(obj) == "string")
		obj = getObj(obj);
	obj.style.display = "inline";
}

/**  Sets the display of an object to none **/
function hideLayer(obj) {
	if (typeof(obj) == "string")
		obj = getObj(obj);
	obj.style.display = "none";
}

/** returns an object with the x & y coordinate of an object **/
function returnPosition(obj) {
	var retVal = new Object();
	retVal.x = 0;
	retVal.y = 0;
	while (obj) {
		retVal.x += obj.offsetLeft;
		retVal.y += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return retVal;
}

/** trims the whitespace from a string, returns the trimmed string **/
function trim(str,trimFrontOnly) {
	while (str.substr(0,1) == " ")
		str = str.substring(1,str.length)
	if (!trimFrontOnly) {
		while (str.substr(str.length-1,1) == " ")
			str = str.substring(0,str.length-1)
	}
	return str;
}

/** returns false if a string is empty or is undefined **/
function isEmpty(str,checkWhitespace) {
	if (!str || str.length == 0)
		return true;
	if (checkWhitespace)
		return (trim(str) == "")
	return false;
}

function checkHeight() {
    setHeights();
    if (getObj("pagecontent") != null && getObj("pagecontent_inner") != null &&
        getObj("pagecontent_inner").offsetHeight > getObj("pagecontent").offsetHeight) {
            var cls = getObj("pagecontent").className;
            cls = cls.substr(0,cls.lastIndexOf(" "));
            getObj("pagecontent").className = cls;
    }
}



function setHeights() {
	var divs = document.getElementsByTagName("DIV");

	var conts = new Array();
	for (var i=0;i<divs.length;i++) {
		if (divs[i].className != null && divs[i].className.indexOf("auto") != -1)
			conts[conts.length] = divs[i];
	}

	if (conts.length == 0)
		return;

	var contheight = 501;
	for (var i=0;i<conts.length;i++) {
		conts[i].style.height = "";
		contheight = (conts[i].offsetHeight > contheight)? conts[i].offsetHeight : contheight;
	}
	for (var i=0;i<conts.length;i++)
		conts[i].style.height = contheight + "px";

}


function nextScreen(dir) {
    if (getObj("screenshots") == null)
        return;
    var screenImgs = getObj("screenshots").getElementsByTagName("IMG");
    var idx = 0;
    for (var i=0;i<screenImgs.length;i++) {
        if (screenImgs[i].style.display == "inline") {
            idx = i;
            break;
        }
    }

    var newidx = idx + dir;
    if (newidx < 0)
        newidx = screenImgs.length - 1;
    if (newidx >= screenImgs.length)
        newidx = 0;

    screenImgs[idx].style.display = "none";
    screenImgs[newidx].style.display = "inline";
}
