function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
		return "";
	}
	else{
		return TRIM_VALUE;
	}
} //End Function

function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;
	
	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	} //End While
	return strTemp;

} //End Function

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function
function checkForBlank(ctr, msg)
{
	if(Trim(ctr.value)=='')
	{
		alert("Please insert the "+msg);
		ctr.focus();
		return true;
	}
	else return false;
}

function isEmailAddr(ctr)
{
  var result = true;
  var theStr = new String(ctr.value)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = false;
  }
  if(result==true){
	  alert("Please enter a complete email address in the form: yourname@yourdomain.com");
	  ctr.focus();
  }
  return result;
}

function checkNAN(ctr, msg){  // Number field validation
 	var result = true;
	var txt_num = new String(ctr.value)

	var x=txt_num
	if(ctr.value!=''){
		var anum=/(^\d+$)|(^\d+\.\d+$)/
		if (anum.test(x))
			result=false
		else{
			alert('Please input a valid number for '+ msg +'!');
			ctr.focus();		
			result=true
		}
	}
	else{
		result=false
	}
	return (result)
}

function checkForSelection(ctr, msg){  // List field validation
	result=false;
	if(ctr.selectedIndex==0){
		alert('Please select a '+ msg +'!');
		ctr.focus();
		result=true;
	}
	return result;
}	
function checkForMultiSelection(ctr, msg){  // List field validation
	result=false;
	for (var i = 0; i < ctr.length; i++) {
		if (ctr.options[i].selected) {
			return result;
		}
	}
	alert('Please select a '+ msg +'!');
	ctr.focus();
	result=true;
	return result;
}	

function isDate(ctr, msg){	
	var dtStr = new String(ctr.value)
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strYear=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert('The '+ msg +' format should be : yyyy-mm-dd')
		return true
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert('Please enter a valid 4 digit year between '+minYear+' and '+maxYear + ' for '+ msg)
		return true
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert('Please enter a valid month for '+ msg)
		return true
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert('Please enter a valid day for '+ msg)
		return true
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert('Please enter a valid date for '+ msg)
		return true
	}
return false
}

function image_preview(scr_ctr,disp_ctr,img_dir) //image display
  {
  	if(!img_dir){
		img_dir='';
	}
	var filename = scr_ctr.value;
	var Img = new Image();
	if (navigator.appName == "Netscape")
	{
	  alert("Previews do not work in Netscape.");
	}
	else
	{
	  Img.src = img_dir+filename;
	  disp_ctr.src = Img.src;
	}
  }