function hideSubcategories() {
	var divSubcats = document.getElementById("subcats");
	
	divSubcats.style.visibility = "hidden";
}

function getY( el )
{
	var iReturnValue = 0;
	while( el != null ) {
	iReturnValue += el.offsetTop;
	el = el.offsetParent;
	}
	return iReturnValue;
}

function getX( el )
{
	var iReturnValue = 0;
	while( el != null ) {
	iReturnValue += el.offsetLeft;
	el = el.offsetParent;
	}
	return iReturnValue;
}

// Ajaxish functions
function ajaxPost(source) {
	var strURL = '/tools/getSubcategories.php';
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(source, self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getQuery(source));
}

function getQuery(source) {
    var catId = source.parentNode.id;
    qstr = 'catid=' + catId;  // NOTE: no '?' before querystring
    return qstr;
}

function updatepage(source, str){
	var x = getX(source);
	var y = getY(source);
	
	var divSubcats = document.getElementById("subcats");
	divSubcats.innerHTML = str;
	// it blows away without px suffix
	divSubcats.style.top = (y + 25) + "px";
	divSubcats.style.left = (x + 60) + "px";
	
	divSubcats.style.visibility = "visible";
}

