function trim_string() {
	var ichar, icount;
	var strValue = this;
	ichar = strValue.length - 1;
	icount = -1;
	while (strValue.charAt(ichar) == ' ' && ichar > icount)
		--ichar;
	if (ichar != (strValue.length - 1))
		strValue = strValue.slice(0, ichar + 1);
	ichar = 0;
	icount = strValue.length - 1;
	while (strValue.charAt(ichar) == ' ' && ichar < icount)
		++ichar;
	if (ichar != 0)
		strValue = strValue.slice(ichar, strValue.length);
	return strValue;
}

String.prototype.Trim = trim_string;

function checkFilled(field){
   if (field.value.length==0) return false;
   if (field.value.Trim()=="") return false;
   return true;
}

function y2k(number) {
	return (number < 1000) ? number + 1900 : number;
}

function isInteger (s) {
	var i;

    if (isEmpty(s)) return false;

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++) {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isEmpty(s) {
	return ((s == null) || (s.length == 0))
}

function isDigit (c) {   
	return ((c >= "0") && (c <= "9"))
}

function checkDate(field) {
	var strDate = field.value
	if (strDate.length == 10) {
		if ((strDate.substring(2,3) == "/") && (strDate.substring(5,6) == "/")) {
			var date = strDate.substring(0,2);
			var month = strDate.substring(3,5);
			var year = strDate.substring(6,10);
			var indate = new Date(year, month-1, date);
			if ((year == y2k(indate.getYear())) && (month - 1 == indate.getMonth()) && (date == indate.getDate()))
				return true;
			else
				return false;
			}
		else
			return false;
	}
	else
		return false;
}

function compareDate(field1, field2, compareString) {
	var strDate1 = field1.value;
	var strDate2 = field2.value;

	var date1 = strDate1.substring(0,2);
	var month1 = strDate1.substring(3,5);
	var year1 = strDate1.substring(6,10);
	var indate1 = new Date(year1, month1-1, date1);

	var date2 = strDate2.substring(0,2);
	var month2 = strDate2.substring(3,5);
	var year2 = strDate2.substring(6,10);
	var indate2 = new Date(year2, month2-1, date2);
	
	switch ( compareString ) {
		case "<" :
			if (indate1 < indate2)
				return true;
			else
				return false;
			break;  
		case "<=" :
			if (indate1 <= indate2)
				return true;
			else
				return false;
			break;  
		 case "==" :
			if (indate1 == indate2)
				return true;
			else
				return false;
			break;
		case ">" :
			if (indate1 > indate2)
				return true;
			else
				return false;
			break;
		case ">=" :
			if (indate1 >= indate2)
				return true;
			else
				return false;	
			break;
		default:
			return false;
			break;

	}		
	return true;
}


function comparingDate(field1, field2, compareString) {
	var strDate1 = field1;
	var strDate2 = field2;

	var date1 = strDate1.substring(0,2);
	var month1 = strDate1.substring(3,5);
	var year1 = strDate1.substring(6,10);
	var indate1 = new Date(year1, month1-1, date1);

	var date2 = strDate2.substring(0,2);
	var month2 = strDate2.substring(3,5);
	var year2 = strDate2.substring(6,10);
	var indate2 = new Date(year2, month2-1, date2);
	
	switch ( compareString ) {
		case "<" :
			if (indate1 < indate2)
				return true;
			else
				return false;
			break;  
		case "<=" :
			if (indate1 <= indate2)
				return true;
			else
				return false;
			break;  
		 case "==" :
			if (indate1 == indate2)
				return true;
			else
				return false;
			break;
		case ">" :
			if (indate1 > indate2)
				return true;
			else
				return false;
			break;
		case ">=" :
			if (indate1 >= indate2)
				return true;
			else
				return false;	
			break;
		default:
			return false;
			break;

	}		
}
		
function messageErr(field, errString){
    alert(errString);
	field.focus();
	field.select();
}

// function definition to perform the item validation
function vs_is_digits(item) 
{
	// define the error message using the items display name
	var i;
	var ch;
        var j;
	var k;
	for (i = 0; i < item.value.length; i++)
	     {
		ch = item.value.charAt(i);
		if ((ch < "0" || ch > "9") && ch!=".") 
		   {
			item.focus();
			return false;
  		   }
		if (ch==".") 
		   {j=i;}
	}

	for (i = 0; i < item.value.length; i++) 
		{
		ch = item.value.charAt(i);
		if ((ch==".") && (i!=j))
 		  {
		  item.focus();
                  return false;
		  }
		}

	return true;
}