		var	day_index = 0
		var	mth_index = 1
		var	yr_index  = 2
		var seperator = "/"


		//=============================================================
		//assumption made that the string is never null
		function currecnyToNumber(str_input)
		{	strfront = 0
			strback = str_input.length
			
			for ( pos=0; pos < str_input.length; pos++)
			{	if ( str_input.charAt(pos) != "$" )
				{	strfront = pos
					break
				}
			}
			tmpStr = str_input.substring(strfront,strback)
			tmpStr = tmpStr.replace(",","")
			return  tmpStr
		}
		
		//=============================================================
		//Calculates the difference between two dates
		//returns day_diff/month_diff/year_diff
		function date_diff(strdate1,strdate2)
		{
			calcday = 0
			calcmonth = 0
			calcyear = 0
			
			currdatearr = strdate1.split(seperator)
			datearr = strdate2.split(seperator)
			
			calcday = currdatearr[day_index] - datearr[day_index]
			calcmonth = currdatearr[mth_index] - datearr[mth_index]
			calcyear = currdatearr[yr_index] - datearr[yr_index]
			
			calcdate = calcday+seperator+calcmonth+seperator+calcyear

			return calcdate
		}
		
		//=============================================================
		//Compares two dates
		function datecomp(strdate1,strdate2)
		{
			dtcomp = date_diff(strdate1,strdate2).split(seperator)
			if (((dtcomp[yr_index]==0) && (dtcomp[mth_index]==0)) && (dtcomp[day_index]==0))
				return 0 	//dates are equal
			else 
			{
				if (dtcomp[yr_index] < 0)
				{	return 1	}	//date1 is less than date2
				else if (dtcomp[yr_index] == 0)
				{
					if (dtcomp[mth_index] < 0){return 1}
					else if (dtcomp[mth_index] == 0){if (dtcomp[day_index] < 0){return 1}}
				}
			}

			return -1 //date1 is greater than date2

		}

		//=============================================================
		function calcyears(strdate1,strdate2)
		{
			calcdiff = date_diff(strdate1,strdate2)
			datediffarr = calcdiff.split(seperator)
			daydiff = datediffarr[0]
			monthdiff = datediffarr[1]
			yeardiff = datediffarr[2]
		
			//if the difference is negative then the second date was later than the first
			if (daydiff < 0 )
			{	monthdiff = monthdiff - 1}
			
			if (monthdiff < 0)
			{	yeardiff = yeardiff - 1}
			
			return yeardiff
			
		}		

		//=============================================================
		function y2k(number) { return (number < 1000) ? number + 1900 : number; }
		
		//=============================================================
		//Validates the date
		function isDate (day,month,year) {
		    var today = new Date();
		    year = ((!year) ? y2k(today.getYear()):year);
		    month = ((!month) ? today.getMonth():month-1);
		    if (!day) return false
		    var test = new Date(year,month,day);
		    if ( (y2k(test.getYear()) == year) &&
		         (month == test.getMonth()) &&
		         (day == test.getDate()) )
		        return true;
		    else
		        return false
		}
		
		//=============================================================
		//gets current date
		function currentdate()
		{
			currdate=new Date();
			var wkyr = currdate.getFullYear();
			var wkmm = currdate.getMonth()+1;
			var wkdd = currdate.getDate();
			if(wkdd<10)wkdd = "0" + wkdd;
			return wkdd + seperator + wkmm + seperator + wkyr
		}
		
		
		//=============================================================
		//Validates Phone number format
		function isPhoneNumber(field)
		{
			var bLocaPhone = true
			if(isPhoneNumber.arguments.length>1)
			{
				if(isPhoneNumber.arguments[1] == "I")
					bLocaPhone = false
			}
			var numArray = field.value.split("-")
			if(bLocaPhone)
			{
				if(numArray.length == 1)
				{
					if( !isInteger(numArray))
					    return false
				}
				else if(numArray.length == 2)
				{
					if( numArray[0].length != 3)
						return false
					else if( numArray[1].length != 4)
						return false
					else if( !isInteger(numArray[0]))
						return false
					else if( !isInteger(numArray[1]))
						return false
				}
			}				
			else if(!bLocaPhone)
			{
				if(numArray.length != 2){
					if( !isInteger(numArray))
					    return false				
				}
				else if( !isInteger(numArray[0]))
					return false
				else if( !isInteger(numArray[1]))
					return false
			}				

			return true
		}
		
		//=============================================================
		//removes the spaces from the begin and end of a string		
		function trimSpaces(str_input)//assumption made that the string is never null
		{	strfront = 0
			strback = 0
			
			for ( pos=0; pos < str_input.length; pos++)
			{	if ( str_input.charAt(pos) != " " )
				{	strfront = pos
					break
				}
			}
		
			for ( pos=str_input.length-1 ; pos >= 0 ; pos--)
			{	if ( str_input.charAt(pos) != " " )
				{	strback = pos + 1
					break
				}
			}		
			return  str_input.substring(strfront,strback)
		}
		
		//=============================================================
		// This function returns true if character c is a digit // (0 .. 9).
		function isDigit (c)
		{   return ((c >= "0") && (c <= "9"))}
		
		//=============================================================
		//  This function returns true if s is a positive integer
		function isInteger (s)
		{   var i;
		    var s = new String(s)
		    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;
		}

		//=============================================================
		//  This function returns true if s is a positive decimal
		function isDecimal (s)
		{   var i;
			var numArray = s.split(".")
			
			if(numArray.length != 2){return false}			
			if( !isInteger(numArray[0]) || !isInteger(numArray[1]) ){return false}
		    return true;
		}

		//=============================================================
		//  This function returns true if s is a positive decimal
		function isCurrency (s)
		{   var i;
		    var num = currecnyToNumber(s)
			var numArray = s.split(".")
			
			if(numArray.length != 2){return false}			
			if( !isInteger(numArray[0]) || !isInteger(numArray[1]) ){return false}
			if( parseInt(numArray[0] < 0) ){return false}
			if( parseInt(numArray[1] < 0) ){return false}
			if( numArray[1].length != 2 ){return false}
		    return true;
		}

		//=============================================================
		//  This function returns true if s is a positive decimal
		function isNumber (s){return isInteger(s) || isDecimal(s)	}

		
		//=============================================================
		//  This function returns the rounded number to X decimal places, defaults to 2	
		function round_dec(number,X) 
		
		{	X = (!X ? 2 : X);
			return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
		}
		

		//=============================================================
		//  This function returns true if s is a positive decimal
		function isCurrency (s)
		{   var i;

			if(s.indexOf(".") == -1){return isInteger(s)}
				
			var numArray = s.split(".")			
			
			if(numArray.length != 2){return false}			
			if( !isInteger(numArray[0]) || !isInteger(numArray[1]) ){return false}
			if( numArray[1].length != 2 ){return false}
		    return true;
		}

		//=============================================================
		//  This function returns number formatted to currency
		function formatCurrency(num) 
		{	num = num.toString().replace(/\$|\,/g,'');
			if(isNaN(num))
			num = "0";
			sign = (num == (num = Math.abs(num)));
			num = Math.floor(num*100+0.50000000001);
			cents = num%100;
			num = Math.floor(num/100).toString();
			if(cents<10)
			cents = "0" + cents;
			for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			num = num.substring(0,num.length-(4*i+3))+','+
			num.substring(num.length-(4*i+3));
			return (((sign)?'':'-') + '$' + num + '.' + cents);
		}
			
		//=============================================================
		//  This function returns number formatted to currency
		//	without the $
		function formatCurrencyWithoutDollarSign(num) 
		{	num = num.toString().replace(/\$|\,/g,'');
			if(isNaN(num))
			num = "0";
			sign = (num == (num = Math.abs(num)));
			num = Math.floor(num*100+0.50000000001);
			cents = num%100;
			num = Math.floor(num/100).toString();
			if(cents<10)
			cents = "0" + cents;
			for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			num = num.substring(0,num.length-(4*i+3))+','+
			num.substring(num.length-(4*i+3));
			return (((sign)?'':'-') + num + '.' + cents);
		}
		
		
		//=============================================================
		//  This function validates a date
		function chkDate(dateValue) {
		
			var strDate;
			var strDateArray;
			var strDay;
			var strMonth;
			var strYear;
			var intday;
			var intMonth;
			var intYear;
			var booFound = false;
			var strSeparatorArray = new Array("-"," ","/",".");
			var intElementNr;
			var err = 0;
			var strMonthArray = new Array(12);
			strMonthArray[0] = "Jan";
			strMonthArray[1] = "Feb";
			strMonthArray[2] = "Mar";
			strMonthArray[3] = "Apr";
			strMonthArray[4] = "May";
			strMonthArray[5] = "Jun";
			strMonthArray[6] = "Jul";
			strMonthArray[7] = "Aug";
			strMonthArray[8] = "Sep";
			strMonthArray[9] = "Oct";
			strMonthArray[10] = "Nov";
			strMonthArray[11] = "Dec";
			
			strDate = trimSpaces(dateValue);
		
			if(strDate == "")
				return false
				
			strDateArray = strDate.split(seperator);
			if (strDateArray.length != 3) {
				err = 1;
				return false;
			}
			else {
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
		
			if (strYear.length == 2) {
				var strCC = (parseInt(strYear) > 50) ? '19' : '20';
				strYear = strCC + strYear;
			}
			
			intday = parseInt(strDay, 10);
			if (isNaN(intday)) {
				err = 2;
				return false;
			}
		
			intMonth = parseInt(strMonth, 10);
			if (isNaN(intMonth)) {
				for (i = 0;i<12;i++) {
					if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
						intMonth = i+1;
						strMonth = strMonthArray[i];
						i = 12;
					}
				}
			
				if (isNaN(intMonth)) {
					err = 3;
					return false;
				}
			}
			
			intYear = parseInt(strYear, 10);
			if (isNaN(intYear)) {
				err = 4;
				return false;
			}
			
			if (intMonth>12 || intMonth<1) {
				err = 5;
				return false;
			}
			
			if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
				err = 6;
				return false;
			}
			
			if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
				err = 7;
				return false;
			}
			
			if (intMonth == 2) {
				if (intday < 1) {
					err = 8;
					return false;
				}
				
				if (LeapYear(intYear) == true) {
					if (intday > 29) {
						err = 9;
						return false;
					}
				}
				else {
					if (intday > 28) {
						err = 10;
						return false;
					}
				}
			}
			
			return true;
		}
		
		//=============================================================
		//
		function LeapYear(intYear) {
		
			if (intYear % 100 == 0) {
				if (intYear % 400 == 0) { return true; }
			}
			else {
				if ((intYear % 4) == 0) { return true; }
			}
			return false;
		}
		
		//=============================================================
		//
		function validateEmail(email)
		{
			emlArray = email.split("@");if(emlArray.length != 2){return false};
			addrArray = emlArray[1].split(".");	if(addrArray.length < 2){return false}
			return true
		}
		
		
		//=============================================================
		//
		function isEmpty(str){return trimSpaces(str)==""}