
		

	/*************************************************************/
	/*** Trim strings functions **********************************/
		function ltrim(str)
		{ 
			for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
			return str.substring(k, str.length);
		}
		function rtrim(str)
		{
			for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
			return str.substring(0,j+1);
		}
		function trim(str)
		{
			return ltrim(rtrim(str));
		}
		function isWhitespace(charToCheck)
		{
			var whitespaceChars = " \t\n\r\f";
			return (whitespaceChars.indexOf(charToCheck) != -1);
		}
		
	/*************************************************************/
	/*** Validate string (search for charcters not listed) *******/
		function chk_Chars(val, charlist)
		{
			for (var i = 0; i < val.length; i++)
				if (charlist.indexOf(val.charAt(i)) < 0)
					return false;
		
			//String passed so it is valid							
			return true;
		}

	/*************************************************************/
	/*** Highlight input text if it is default text **************/
		function chk_Numeric(form,fld,row)
		{
			with (eval('document.forms[\'' + form + '\']'))
			{

				var str = eval(fld + '.value');
				if (!chk_Chars(str, "0123456789"))
				{
					alert("Field must only contain numbers");
					if (typeof(row) != 'undefined' && row.length > 0)
					{
						eval('document.getElementById(\'' + row + '\').className=\'Cell_Highlight\'');
					}
				}
			}
		}
		

	/*************************************************************/
	/*** Highlight input text if it is default text **************/
		function chk_Default(field,def)
		{
			if (field.value == def) field.select();
		}
		
	/*************************************************************/
	/*** Format phone numbers ************************************/
		function fmt_Phone(field)
		{
		/*
			alert("TEST");
		*/
			var newPhone = '';
			var phone = field.value;
			
			if (!chk_Chars(phone, "0123456789()-"))
			{
				alert("Phone number is not valid");
				field.focus();
				field.select();
			}
			
			if (field.value.length == 10)
			{
				newPhone = "(" + phone.substring(0,3) + ")" + phone.substring(3,6) + "-" + phone.substring(6,10);					
				field.value = newPhone;
			}
			
			if (field.value.indexOf("-") == 3 && field.value.indexOf("-",4) == 7 && field.value.length == 12)
			{
				newPhone = "(" + phone.substring(0,3) + ")" + phone.substring(4,7) + "-" + phone.substring(8,12);								
				field.value = newPhone;
			}
			
			if (field.value.indexOf("(") == 0 && field.value.indexOf(" ") == 5 && field.value.length == 14)
			{
				var newPhone = phone.substring(0,5) + phone.substring(6,14);								
				field.value = newPhone;
			}
		}
		
	/*************************************************************/
	/*** Format web address/URL **********************************/
	
		function fmt_URL(field)
		{
			if (field.value.indexOf("http://") == -1)
			{
				var newURL = '';
				var URL = field.value;
				var bla = "http://" + URL;
				newURL += bla;
								
				field.value = newURL;
			}
		}
		
	/*************************************************************/
	/*** Validate email address **********************************/
		function val_Email(field)
		{
			
			if (field.value.length != 0)
			{
				if (field.value.indexOf("@") == -1 || field.value.indexOf(".",field.value.indexOf("@")) == -1)
				{
					alert("Email address not valid");
					field.focus();
					field.select();
					return false;
				}
			}
			
			return true;
		}

	/*************************************************************/
	/*** Validate Password, must match password_confirm **************/
		function val_Pass()
		{
			pass1 = document.forms[0].Password.value;
			pass2 = document.forms[0].Password_confirm.value;
			
			if (pass1.length <= 5)
			{
				alert('Your password must be at least 6 characters in length');
				document.forms[0].Password.focus();
				return false;
			}
			
			if (pass1 != pass2)
			{
				alert('Your passwords do not match');
				document.forms[0].Password.focus();
				document.forms[0].Password.select();				
				return false;
			}
			else 
			{	
				return true;
			}
		}
	/*************************************************/
	/*** Validate dates, /'s, -'s, etc. **************/
		function val_date(form,fld,row)
		{
			with (eval('document.forms[\'' + form + '\']'))
			{

				var date = eval(fld + '.value');
				
				var re = /[A-z' ']/;
				
				if (!re.test(date))
				{
					if (date.indexOf('/') > 0)
					{
						slash1 = date.indexOf('/');
						slash2 = date.indexOf('/', slash1 + 1);
						mo = date.substr(0,slash1);
						yr = date.substr(slash2 + 1,date.length);
						dy = date.substr(slash1 + 1,date.length - mo.length - yr.length - 2);
					}
					else if (date.indexOf('-') > 0)
					{
						slash1 = date.indexOf('-');
						slash2 = date.indexOf('-', slash1 + 1);
						mo = date.substr(0,slash1);
						yr = date.substr(slash2 + 1,date.length);
						dy = date.substr(slash1 + 1,date.length - mo.length - yr.length - 2);
					}
					else if (date.indexOf('.') > 0)
					{
						slash1 = date.indexOf('.');
						slash2 = date.indexOf('.', slash1 + 1);
						mo = date.substr(0,slash1);
						yr = date.substr(slash2 + 1,date.length);
						dy = date.substr(slash1 + 1,date.length - mo.length - yr.length - 2);
					}
					else
					{
						if (date.length == 5)
						{
							mo = date.substr(0,1);
							yr = date.substr(3,2);
							dy = date.substr(1,2);
						}
						else if (date.length == 6)
						{
							mo = date.substr(0,2);
							yr = date.substr(4,2);
							dy = date.substr(2,2);
						}
						else if (date.length == 8)
						{
							mo = date.substr(0,2);
							yr = date.substr(4,4);
							dy = date.substr(2,2);
						}
					}
				}
				
				if (typeof(mo) != 'undefined' && mo.length > 0 && mo.value <= 12)
				{
					if (mo.length < 2) mo = '0' + mo;
					if (mo.value > 12) mo = '0' + mo.substr(mo.length - 1, 1);
					if (dy.length < 2) dy = '0' + dy;
					if (yr.length == 2)
						{
							if (yr <= 10) alert('Year is automatically being set to 19' + yr);
							yr = '19' + yr; // #Left(Year(Now()), 2)#
						}
					if (yr.length == 3) yr = '#Year(Now())#';
					
					var new_Date = mo + '/' + dy + '/' + yr;
					//alert(new_Date);
					eval(fld + '.value = \'' + new_Date + '\'');
				}
				else
				{
					alert('There is a formating error within one of your dates.  Please correct before proceeding');
					eval('document.getElementById(\'' + row + '\').className=\'Cell_Highlight\'');
				}
			}
		}
	/*************************************************/
	/*** Validate address (will return false if po box and it is not allowed) **************/	
		function val_address(form,fld,row,allow_po)
		{
			with (eval('document.forms[\'' + form + '\']'))
			{
			
				var address = eval(fld + '.value');
				
				address = trim(address);
				
				while(address.indexOf(".") != -1)
				{
					address = address.replace(".", "")
				}
				
				if (address.substring(0,6).toLowerCase() == 'po box')
				{
					if (allow_po.toLowerCase() == 'no')
					{
						alert('We can NOT ship ship to addresses with a PO Box.  Please enter in a physical address.');
						eval('document.getElementById(\'' + row + '\').className=\'Cell_Highlight\'');
						return false;
					}
					
					address = "PO Box " + address.substring(7,address.length);
					eval(fld + '.value = address');
					
				}
			}
		}
