// JavaScript Document
// mootools AJAX function. Requires mootools
function useAjax	(	server_script,
						query_string,
						callback,
						return_var,
						method
					)
{
	return	new Ajax(	server_script, 
						{
							method:			method,
							data:			query_string,
							update:			$(return_var),
							evalScripts:	true,
							onComplete: 	eval(callback)
						}
					);
		alert("script: " + server_script);
}



/////  Getting Values and Text from select boxes ////
function getCurrentValueFromSelectBox	(	select_id	)
{
	return document.getElementById(select_id).options[document.getElementById(select_id).options.selectedIndex].value;
}
function getCurrentTextFromSelectBox	(	select_id	)
{
	return document.getElementById(select_id).options[document.getElementById(select_id).options.selectedIndex].text;
}



// checks to see whether the input is a numeric string or not
function IsWholeNumber(strString)
{
	var strValidChars = "0123456789"; // valid characters for a numeric string
	var strChar;
	var result = true;
	var i = 0
	if (strString.length == 0) return false;
	// check to see if strString consists of valid characters listed in strValidChars
	while (i < strString.length && result == true)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1) return false;
		i++;
	}
	return result;
}


//
function javascript_sleep(milliseconds)
{
	var date = new Date();
	var curDate = null;
	do
	{ 
		curDate = new Date(); 
	}while(curDate - date < milliseconds);
}


// Pass the string as argument (value) to the function below.
function RightTrim( value ) 
{ 
	var re = /((\s*\S+)*)\s*/; 
	return value.replace(re, "$1");
}

// Pass the string as argument (value) to the function below.
function LeftTrim( value ) 
{	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes leading and ending whitespaces 
// The string to be processed as an argument (value) to the function below.
function trim( value ) 
{ 
	return LeftTrim(RightTrim(value));
}



