// 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;
}