// JavaScript Document
// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

function isvalidemail(value) {
	var emailexpr=/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	return emailexpr.test(value);
}
function isvalidimgfile(value) {
	var fileexpr=/^.*(\.(gif|jpg|bmp|jpeg|GIF|JPG|BMP|JPEG))$/;
	return fileexpr.test(value);
}
function isvalidvideofile(value) {
	var fileexpr=/^.*(\.(avi|dat|mgp|mpeg|flv|wmv|AVI|DAT|MPG|MPEG|FLV|WMV))$/;
	return fileexpr.test(value);
}

//USE: onKeyPress="return keyRestrict(event,'0123456789')
function keyRestrict(e, validchars) { 
	var key='', keychar='';
	key = getKeyCode(e);
	if (key == null) return true;
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	validchars = validchars.toLowerCase();
	if (validchars.indexOf(keychar) != -1)
	  return true;
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
	  return true;
	return false;
}
function getKeyCode(e) {
	if (window.event)
	return window.event.keyCode;
	else if (e)
	return e.which;
	else
	return null;
}

function selchk(id,hid)
{
	var val=document.getElementById(hid).value;
	if(document.getElementById(id).checked)
		val+=document.getElementById(id).value+",";
	else
		val=val.replace(document.getElementById(id).value+",","");
	document.getElementById(hid).value=val;
}
function selchksign(id,hid,sign)
{
	var val=document.getElementById(hid).value;
	if(document.getElementById(id).checked)
		val+=document.getElementById(id).value+sign;
	else
		val=val.replace(document.getElementById(id).value+sign,"");
	document.getElementById(hid).value=val;
}
function url_check(url)
{
	var urlRegxp = /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([\w]+)(.[\w]+){1,2}$/;
	return urlRegxp.test(url);
}
function isProper(string)
{
	if (!string)
		return false;
	var iChars = "*|,\":<>[]{}`\';()@&$#% ";
	for (var i = 0; i < string.length; i++)
	{
		if (iChars.indexOf(string.charAt(i)) != -1)
			return false;
	}
	return true;
}
function $I(id)
{
	return document.getElementById(id);
}
function $V(id)
{
	return $I(id).value;
}
function AddToOptionList(OptionList, OptionValue, OptionText)
{
	// Add option to the bottom of the list
	OptionList[OptionList.length] = new Option(OptionText, OptionValue);
}
function ClearOptions(OptionList)
{
	// Always clear an option list from the last entry to the first
	for (x=OptionList.length; x >= 0; x--)
	{
		OptionList[x] = null;
	}
}