	function CheckEmail(sValue, sField)
	{
	// checks field for a @ and .
	// fails if both are not found
	
	var sChar;
	var bFindAt = false;
	var bFindPeriod = false;
	
	for(i=0;i < sValue.length && (bFindPeriod == false || bFindAt == false);i++)
	{
		if(sValue.charAt(i)=='@')
		{
			bFindAt = true
		}
		
		if(sValue.charAt(i)=='.')
		{
			bFindPeriod = true;
		}
		
	}

	if(bFindAt!=true || bFindPeriod != true)
	{
		alert('The ' + sField + ' field must contain a valid email address.');
		return false;	
	}
	else
	{
		return true;
	}

}
	
	function SocialSinCheck(sSocial)
	{
		
		/*** check for numbers or - only!**/
		var sTest = "-1234567890";
		var bMatch = false;
		var bFail = false;
		if (sSocial.length != 11 )
		{
			return false;
		
		}
		
		for (i = 0;i <= (sSocial.length - 1) && bFail == false; i++)
		{
			bMatch = false;
			
			for (z = 0; z <= (sTest.length - 1) && bMatch == false; z++)
			{
/**alert(sSocial.charAt(i) + '  ' + sTest.charAt(z) + (sSocial.charAt(i) == sTest.charAt(z)));
**/				if (sSocial.charAt(i) == sTest.charAt(z))
				{
					
					bMatch = true;
				}
							
			}							
		
			if (bMatch == false)
			{
			
				bFail = true;
			}
			else
			{
				bFail = false;
			}
			
		}

		if (bFail == true)
		{
			return false;
		}
		
		/*** check for format nnn-nn-nnnn***/
		
		if (sSocial.charAt(3) != '-' || sSocial.charAt(6) != '-' )
		{
			bFail = true;
		}
		
		/** check for Canadian Format nnn-nnn-nnn**/
		if (bFail == true)
		{
			if (sSocial.charAt(3) == '-' && sSocial.charAt(7) == '-' )
			{
				bFail = false;
			}
		
		}
		
		if (bFail == true)
		{
			return false;
		}
		
		return true;		
				
	}
	
	function VerifyIncluded(sTest,sMatches)
	{
		var bMatch;
		
		for (var i = 0; i < sTest.length ; i++)
		{
			bMatch = false;
		
			for (var z = 0; (z < sMatches.length ) && (bMatch == false); z++)
			{
				
				if(sTest.charAt(i) == sMatches.charAt(z))
				{
					bMatch = true;
				}				
							
			}
			
			if (bMatch == false)
			{
				return false;
			}	
							
		}
	
		return true;
			
	}

function ValidateDate(sDate)
{
	var iMonth, iDay, iYear
	var iDayBegin, iYearBegin
	var iTmp, iFreq, iSlash, iSlash2
	
	if(VerifyIncluded(sDate,'0123456789/') != true)
	{
		return false;
	}
	
	iFreq = Frequency(sDate,'/');
	if(iFreq != 2)
	{
		return false;
	}
		
	if(sDate.length > 10 || sDate.length < 6)
	{
		return false;
	}
	
	if(sDate.charAt(0) == '/' || sDate.charAt(sDate.length-1) == '/' || sDate.charAt(sDate.length-2) == '/')
	{
		return false;	
	}
	
	iSlash = sDate.indexOf('/');
	
	iMonth = new Number(sDate.slice(0,iSlash));

	if(iMonth > 12)
	{
		return false;	
	}		
	
	iSlash2 = sDate.lastIndexOf('/');
	
	if((iSlash2 - iSlash) <= 1)
	{
		return false;
	}
	
	iDay = new Number(sDate.slice(iSlash+1,iSlash2));


	if(iDay > 31)
	{
		return false;
	}
	
	iYear = new Number(sDate.slice(iSlash2+1));
	
	return true;
}

function Frequency(sText,sMatches)
{
	var i, z, iFreq
	iFreq = 0;
	
	for (var i = 0; i < sText.length; i++)
		{
			bMatch = false;
		
			for (var z = 0; z < sMatches.length && bMatch == false; z++)
			{
				
				if(sText.charAt(i) == sMatches.charAt(z))
				{
					bMatch = true;
					iFreq++;
				}				
							
			}
										
		}
	
	return iFreq;
}


function Trim(myform,field)
{
   value = document.forms[myform].elements[field].value;

  while (value.charAt(value.length-1) == " "){value = value.substring(0,value.length-1);} 
  while(value.substring(0,1) ==" "){value = value.substring(1,value.length);}

  document.forms[myform].elements[field].value = value;
  //Leave the next line only when you want to select the textbox after you have clicked the button.
}