var xDir = './js/cross-browser/x/'; 
var hiZ = 2;
var aMenus = new Array();

xInclude(xDir+'x_core.js',
		 xDir+'x_cook.js', 
		 xDir+'x_event.js', 
		 xDir+'x_slide.js', 
		 xDir+'x_drag.js',
		 xDir+'x_trave.js');
		 
window.onload = function () {
	return;
}

function xToggle(oID, valID, swapClass, asState) {
	if (!xGetElementById(oID)) return;
	objDisplay = xGetElementById(oID).style.display;
	
	if (asState == 'on' || asState == 'off') {
		xGetElementById(oID).style.display = (asState == 'on') ? 'block' : 'none';	
	} else {
		xGetElementById(oID).style.display = (!objDisplay || objDisplay == 'none') ? 'block' : 'none';
	}
	
	objDisplay = xGetElementById(oID).style.display;
	
	if (valID && valID != '') {
		xGetElementById(valID).value = (!objDisplay || objDisplay == 'block') ? 1 : 0;
	}
	if (swapClass && swapClass != '') {
		xGetElementById(oID+"_swap").className = (!objDisplay || objDisplay == 'block') ? swapClass + '_on' : swapClass + '_off';
	}

	xZIndex(oID, hiZ++);
}

function xSlideToCenter(e) {
	if (xGetElementById(e)) {
		xToggle(e,'','','on');
		halfX = (xClientWidth()/2)-(xWidth(e)/2);
		halfY = (xClientHeight()/2)-(xHeight(e));
		xMoveTo(e, halfX, 0-xHeight(e));
		xSlideTo(e, halfX, halfY, 500);
		//alert ('centered: ('+e+')');
	}
}

function xFocus(oID) {
	xGetElementById(oID).focus();	
}

function throwSuccess(msg) {
	xGetElementById('msgSuccess').innerHTML += '<div class="msg"><b>+</b> ' + msg + '</div>';
	xSlideToCenter('popSuccess');
}

function throwError(msg) {
	xGetElementById('msgError').innerHTML += '<div class="msg"><b>+</b> ' + msg + '</div>';	
	xSlideToCenter('popError');
}

function throwWarning(msg) {
	xGetElementById('msgWarning').innerHTML += '<div class="msg"><b>+</b> ' + msg + '</div>';
	xSlideToCenter('popWarning');
}

function clearSuccess() {
	xInnerHtml('msgSuccess', '');
}

function clearErrors() {
	xInnerHtml('msgError', '');
}

function clearWarnings() {
	xInnerHtml('msgWarning', '');
}

function closeGroup(aGroup) {
	for(i in aGroup) {
		xClose(aGroup[i]);
	}
}

function closeOpen(aGroup,oID,oID2) {	
	closeGroup(aGroup);
	xOpen(oID);
	if (oID2) xOpen(oID2);		
}

function openItem(aGroup, groupIndex) {
	xOpen(aGroup[groupIndex]);
}

function xOpen(oID) {
	xToggle(oID,'','','on');	
}

function xClose(oID) {
	xToggle(oID,'','','off');	
}

function openForums(category) {
	var c, f;

	if (category) {
		category = category.replace(/<[^>]*>/g, '');
	}

	switch(category) {
		/*case 'career'   : c = '2'; break;
		case 'technical': c = '3'; break;
		case 'education': c = '4'; break;

		case 'groupwise': f = '2'; break;
		case 'nds'	: f = '3'; break;
		case 'zenworks' : f = '4'; break;
		case 'bordermanager': f = '5'; break;
		case 'netware'	: f = '6'; break;
		case 'clustering': f = '7'; break;
		*/
		default: break;
	}

	var url = '/forums/index.php';

	if (c) {
		url += '?c=' + c;
	}

	if (f) {
		url = '/forums/viewforum.php?f=' + f;
	}

	OnaiForumsWin = window.open(url, 'OnaiForumsWin', "fullscreen=no,toolbar=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,directories=no,location=yes,width=800,height=500");
	OnaiForumsWin.focus();
}

// Simpler, old school toggle function
function toggle(oID, valID, imgClass) {
	objDisplay = document.getElementById(oID).style.display;
	document.getElementById(oID).style.display = (!objDisplay || objDisplay == 'block') ? 'none' : 'block';
	if (valID && valID != '') {
		document.getElementById(valID).value = (!objDisplay || objDisplay == 'block') ? 1 : 0;
	}
	if (imgClass && imgClass != '') {
		document.getElementById(oID+"_img").className = (!objDisplay || objDisplay == 'block') ? imgClass + '_off' : imgClass + '_on';	
	}
}

function myOnDragStart(ele, mx, my) {
	xZIndex(xParent(ele), hiZ++);
}

function myOnDrag(ele, mdx, mdy) {
	xMoveTo(xParent(ele), xLeft(xParent(ele)) + mdx, xTop(xParent(ele)) + mdy);
}

function myOnDragEnd(ele, mx, my) {

}

function winPopup(URL, width, height) {
	if (!width) width = 500;
	if (!height) height = 400;
	onaiPopup = parent.window.open(URL, "onaiPopup", "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=yes,directories=no,location=no,width="+width+",height="+height+",left=10,top=10");
	onaiPopup.focus();
}