function Trim(STRING){
STRING = LTrim(STRING);
return RTrim(STRING);
}

function RTrim(STRING){
while(STRING.charAt((STRING.length -1))==" "){
STRING = STRING.substring(0,STRING.length-1);
}
return STRING;
}


function LTrim(STRING){
while(STRING.charAt(0)==" "){
STRING = STRING.replace(STRING.charAt(0),"");
}
return STRING;
}

function test(src) 
{
     //var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
	 var emailReg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
     var regex = new RegExp(emailReg);
     return regex.test(src);
}
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 get_age(yr, mon, day, unit, decimal, round){
	var one_day=1000*60*60*24
	var one_month=1000*60*60*24*30
	var one_year=1000*60*60*24*30*12
	today=new Date()
	var pastdate=new Date(yr, mon-1, day)

	var countunit=unit
	var decimals=decimal
	var rounding=round

	finalunit=(countunit=="days")? one_day : (countunit=="months")? one_month : one_year
	decimals=(decimals<=0)? 1 : decimals*10

	if (unit!="years"){
	if (rounding=="rounddown")
	return Math.floor((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals+" "+countunit;
	else
	return Math.ceil((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals+" "+countunit;
	}
	else{
	yearspast=today.getFullYear()-yr-1
	tail=(today.getMonth()>mon-1 || today.getMonth()==mon-1 && today.getDate()>=day)? 1 : 0
	pastdate.setFullYear(today.getFullYear())
	pastdate2=new Date(today.getFullYear()-1, mon-1, day)
	tail=(tail==1)? tail+Math.floor((today.getTime()-pastdate.getTime())/(finalunit)*decimals)/decimals : Math.floor((today.getTime()-pastdate2.getTime())/(finalunit)*decimals)/decimals
	return yearspast+tail+" "+countunit;

	}
}
// File: copy-code.js
// Requires: prototype.js, scriptaculous.js?load=effects

	function copyToClipboard(elt) {
		var urlSwf = "/include/swf/_clipboard.swf";
		var strMssgBoxId = "notifyTextCopied";
		var eltNotify = null;

		// Display Notifications
		if((eltNotify = $(strMssgBoxId)) == null){
			// Attach the notification to the DOM
			var eltBody = document.getElementsByTagName('body').item(0);

			eltNotify = document.createElement('div');
			eltNotify.setAttribute('id', strMssgBoxId);
			eltNotify.style.display = 'none';

			eltNotify.innerHTML = 'Copied';

			eltBody.appendChild(eltNotify);
		}
		elt.onblur =
			function(e){
				Element.hide(eltNotify);
				return true;
			}

		var z = Position.cumulativeOffset(elt);
		var x = z[0];
		var y = z[1];

		Element.show(eltNotify);

		if(navigator.appName == 'Microsoft Internet Explorer'){
			if(x < 100){
				eltNotify.style.left = (x + (elt.offsetWidth - 23)) + 'px';
			}
			else{
				eltNotify.style.left = (x - (eltNotify.offsetWidth + 2)) + 'px';
			}
		}
		else{
			if(x < 100){
				eltNotify.style.left = (x + (elt.offsetWidth + 3)) + 'px';
			}
			else{
				eltNotify.style.left = (x - (eltNotify.offsetWidth + 2)) + 'px';
			}
		}

		eltNotify.style.top = y + 'px';

		var xEffect = Effect.Fade(eltNotify, { fps: 75, from: 1.9, to: 0.0, duration: 1.0, queue: 'front' } );
		window.status = 'Copied text to clipboard';

		// Copy the text inside the text box to the user's clipboard
		var flashcopier = 'flashcopier';
		if(!$(flashcopier)){
			var divholder = document.createElement('div');
			divholder.id = flashcopier;
			document.body.appendChild(divholder);
		}

		$(flashcopier).innerHTML = '';
		var divinfo = '<embed src="' + urlSwf + '" FlashVars="clipboard='+escape(elt.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
		$(flashcopier).innerHTML = divinfo;

		elt.select();

		return true;
	}

function validate_text_field_as_int(event)
{
  var KeyCode=document.all?event.keyCode:event.which;
   if((KeyCode<=105 && KeyCode>=96)||KeyCode==8 || KeyCode==46 || KeyCode==37 || KeyCode==39 || (KeyCode<=57 && KeyCode>=48))
	{
	return true;      
	}
   else  
	{
	 return false;
	}
}
function popup(file, width, height)
{
	window.open(file, 'popup', "width="+width+", height="+height+", menubar=no, scrollbars=yes")
}
function checkall(objForm){
	len = objForm.elements.length;
	var i=0;
	for( i=0 ; i<len ; i++) {
		if (objForm.elements[i].type=='checkbox') {
			objForm.elements[i].checked=objForm.check_all.checked;
		}
	}
}