/*
Arie Nugraha 2007
this file need prototype. js
library to works

UI related functions
*/

/* change the style of submenu link */
function setSubmenuClass(strMenuID, strClassName)
{
	var defaultClass = 'subMenuItem';
    var elementObj = $(strMenuID);
    // get current element class name
    previousClass = elementObj.className;

	// get other element that already have name 'strClassName'
	var prevElemnts = document.getElementsByClassName(strClassName);
	// iterate
	prevElemnts.each(function(elmnt) {
		elmnt.className = defaultClass;
		});

    // change the class name specified in function argument
    elementObj.className = strClassName;
}

/* color of highlighted row */
var strRowColor = '#64ff64';
/* color of highlighted row based on checkbox */
var strRowSelColor = '#ffb865';

/* highlight the selected row */
function highlightRow(strRowID)
{
	// get the descendants TD of row
	var descElmnt = $(strRowID).immediateDescendants();
	// iterate TD and set style for each of it
	descElmnt.each(function(elmnt) {
		if (elmnt.hasClassName('cbChecked')) {
			return;
		}

		elmnt.setStyle({
			backgroundColor: strRowColor
		});
	});
}

/* unhighlight the selected row */
function unHighlightRow(strRowID)
{
	// get the descendants TD of row
	var descElmnt = $(strRowID).immediateDescendants();
	// iterate TD and set style for each of it
	descElmnt.each(function(elmnt) {
		if (elmnt.hasClassName('cbChecked')) {
			return;
		}
		// reset the background color property
		elmnt.setStyle({
			backgroundColor: ''
		});
	});
}

/* highlight the selected row based on checkbox */
function cbHighlightRow(cbObj, strRowID)
{
	// color buffer
	var clr = '';
	// check is the checkbox is in checked state
	isChecked = cbObj.checked;
	// get the descendants TD of row
	var descElmnt = $(strRowID).immediateDescendants();

	if (isChecked) {
		clr = strRowSelColor;
		// iterate TD and set style for each of it
		descElmnt.each(function(elmnt) {
			elmnt.addClassName('cbChecked');
			elmnt.setStyle({
				backgroundColor: clr
			});
		});
	} else {
		descElmnt.each(function(elmnt) {
			elmnt.removeClassName('cbChecked');
			elmnt.setStyle({
				backgroundColor: ''
			});
		});
	}
}

/* hide browser status message */
function noStatus()
{
	window.status = null;
	return true
}

/* Javasript function to open new window  */
function openWin(strURL, strWinName, intWidth, intHeight, boolScroll)
{
	// variables to determine the center position of window
	var xPos = (screen.width - intWidth)/2;
	var yPos = (screen.height - intHeight)/2;

    var withScrollbar = 'no';

    // if scrollbar allowed
    if (boolScroll) {
        withScrollbar = 'yes';
    }

	window.open(strURL, strWinName, "height=" + intHeight + ",width=" + intWidth +
	",menubar=no, scrollbars=" + withScrollbar + ", location=no, toolbar=no," +
	"directories=no,resizable=no,screenY=" + yPos + ",screenX=" + xPos + ",top=" + yPos + ",left=" + xPos);
}

/* set iframe content */
function setIframeContent(strIframeID, strUrl)
{
	var iframeObj = $(strIframeID);
	if (iframeObj != undefined) {
		iframeObj.src = strUrl;
	}
}
