	/*
	** Returns true if a string is blank. 
	*/
	function isBlank(str){
		var i
		for (i=0; i<=str.length-1; i++){
			if (str.substring(i, i+1) != " ")
				return (false)
			}
			return (true)
	}

	/*
	** Returns number of days between two date objects.
	** Make sure you pass a 'date object'. ie new Date(someDate).
	** It will NOT work if you just pass a string in mm/dd/yyyy format.
	*/
	function daysBetween(earlyDate,laterDate){
	   var earlySecs=earlyDate.getTime()
	   var laterSecs=laterDate.getTime()
	   return Math.floor ((((((laterSecs-earlySecs)/1000)/60)/60)/24))
	}


	/*
	** Returns true if a date is greater than the current date. 
	*/
	function isFutureDate(a){
		if (isBlank(a)) err = 1
		var err=0
		var psj=0;
		var d = 0
		var b = 0
		var f = 0
		
		strDate = a
		posDay = strDate.indexOf("/")
		b = strDate.substring(0, posDay) // day
		posMonth = strDate.indexOf("/", posDay+1)
		if (posMonth == -1) err = 1
		d = strDate.substring(posDay+1, posMonth) // month
		f = strDate.substring(posMonth+1, (strDate.length)) //year
		c = '/'
		e = '/'
		
		if (f < 1000 || f == 0 || f > 9999)
				err = 1;
		//checking for current date
		currDate = new Date()
		day = currDate.getDate()
		month = currDate.getMonth()
		year = currDate.getFullYear()
		
		//basic error checking
		if (b<1 || b>12) err = 1
		if (c != '/') err = 1
		if (d<1 || d>31) err = 1
		if (e != '/') err = 1
		if (f<0) err = 1
		
		//advanced error checking
		// uncomment if you want the date to be greater than current date
		newDate = new Date(b + "/" + d + "/" + f)
		if(daysBetween(currDate, newDate) < 0){
			err = 1
		}
		
		// months with 30 days
		if (b==4 || b==6 || b==9 || b==11){
			if (d==31) err=1
		}

		// february, leap year
		if (b==2){
			// feb
			var g=parseInt(f/4)
			if (isNaN(g)) {
				err=1
			}

			if (d>29) err=1
			if (d==29 && ((f/4)!=parseInt(f/4))) err=1
		}

		if (err==1){
			return (false);
		}
		else{
			return (true);
		}
	}

	/*
	** Returns false if a date is greater than the current date. 
	*/
	function isPastDate(a){
		if (isBlank(a)) err = 1
		var err=0
		var psj=0;
		var d = 0
		var b = 0
		var f = 0
		
		strDate = a
		posDay = strDate.indexOf("/")
		b = strDate.substring(0, posDay) // day
		posMonth = strDate.indexOf("/", posDay+1)
		if (posMonth == -1) err = 1
		d = strDate.substring(posDay+1, posMonth) // month
		f = strDate.substring(posMonth+1, (strDate.length)) //year
		c = '/'
		e = '/'
		
		if (f < 1000 || f == 0 || f > 9999)
				err = 1;
		//checking for current date
		currDate = new Date()
		day = currDate.getDate()
		month = currDate.getMonth()
		year = currDate.getFullYear()
		
		//basic error checking
		if (b<1 || b>12) err = 1
		if (c != '/') err = 1
		if (d<1 || d>31) err = 1
		if (e != '/') err = 1
		if (f<0) err = 1
		
		//advanced error checking
		// uncomment if you want the date to be greater than current date
		newDate = new Date(b + "/" + d + "/" + f)
		if(daysBetween(currDate, newDate) > 0){
			err = 1
		}
		
		// months with 30 days
		if (b==4 || b==6 || b==9 || b==11){
			if (d==31) err=1
		}

		// february, leap year
		if (b==2){
			// feb
			var g=parseInt(f/4)
			if (isNaN(g)) {
				err=1
			}

			if (d>29) err=1
			if (d==29 && ((f/4)!=parseInt(f/4))) err=1
		}

		if (err==1){
			return (false);
		}
		else{
			return (true);
		}
	}

	/* Function to trim a string.......*/
	function trim(str){
		newStr = ""
		for(x=0; x < str.length; x++){
			if (str.substr(x,1) != " "){
				newStr = str.substr(x)
				break;
			}
		}
						
		for(x=newStr.length-1; x >= 0; x--){
			if (newStr.substr(x,1) != " "){
				newStr = newStr.substr(0, x+1)
				break;
			}
		}
			
		return (newStr)
	}

