/*
rollover images
*/
function roll(img_name, img_src)
{
document[img_name].src = img_src;
}

/*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

/*
Make sure that textBox only contain number
*/
function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
	isInteger(textBox.value);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}

/*
	Check if a form element is empty.
	If it is display an alert box and focus
	on the element
*/
function isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}

/*
	Set one value in combo box as the selected value
*/
function setSelect(listElement, listValue)
{
	for (i=0; i < listElement.options.length; i++) {
		if (listElement.options[i].value == listValue)	{
			listElement.selectedIndex = i;
		}
	}	
}

/*
	Popup a new window in the center of screen
*/
function openWindow(url, window_name, width, height){       
var winW = width;      
var winH = height;      
var winX = (screen.availWidth - winW) / 2;      
var winY = (screen.availHeight - winH) / 2;       
var features = 'left=' + winX + ',top=' + winY + ',height=' + winH + ',' + 'width=' + winW + 'location=0,status=0,toolbar=0,scrollbars=1,scrollable=1,resizable=1';       
window.open(url, 'window_name', features);       
return false;
} 

/*
	Check is value s Integer
*/
function isInteger(s)
{
      var i;
	s = s.toString();
      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);
         if (isNaN(c)) 
	   {
		alert("Given value is not an integer number");
		return false;
	   }
      }
      return true;
}


