function fraction2float(frac)
{
var r = -1;
	if(frac.indexOf('/') > 0)
	{
		var fa = frac.split('/');
		if(!isNaN(parseFloat(fa[0])) && !isNaN(parseFloat(fa[1])))
			r = parseFloat(fa[0])/parseFloat(fa[1])
	}
	return r;
}
function writeBirthYear(by)
{
	if(isNaN(by) || by < 1700 || by > 2100)
		return;
//	document.write("&lt;");
	document.write(by);
//	document.write("&gt;");
//	document.write('-');
//	by=by+1;
//	if(by > 1900) by=by-1900;
//	else if(by == 1900) by=by;
//	else if(by > 1800) by=by-1800;
//	else if(by == 1800) by=by;
//	else if(by > 1700) by=by-1700;
//	else if(by == 1700) by=by;
//	if(by < 10) document.write('0');
//	document.write(by);
}
function isGarbage(s)
{
	if(0 == s.length || 0 == s.replace(' ','').length)
		return true;
	for(var i = 0; i < s.length;i++)
	{
		var c = s.charAt(i);
		if(c >= '0' && c <= '9')
			continue;
		if(c == ' ' || c == '/')
			continue;
		return true;
	}
	return false;
}
function BirthYear(iCensusYear, age)
{
	if(isGarbage(age))
		return;
	var by = iCensusYear - age-1;
	if(!isNaN(by))
		writeBirthYear(by);
	else
	{
		var i;
		var fage = '';

		if(age.indexOf(' ') > 0)
		{
			var a = age.split(' ');
			if(2 == a.length)
			{
				if(2 != a.length)
					return;
				if(isNaN(parseFloat(a[0])))
					return;
				fage = parseFloat(a[0]);
				if(-1 == fraction2float(a[1]))
					return;
				fage = fage + fraction2float(a[1]);
			}
		}
		else
		{
			fage = fraction2float(age);
			if(-1 == fage)
				return;
		}
		if(!isNaN(fage))
		{
			by = iCensusYear - fage;
			if(Math.round(by-.33) != Math.round(by-.25))
				writeBirthYear(Math.round(by-1));
			else
			{
//				document.write("&lt;");
				document.write(Math.round(by-.33));
//				document.write("&gt;");
			}
		}
	}
}
function fraction2Months(frac)
{
var r = -1;
	if(frac.indexOf('/') > 0)
	{
		var fa = frac.split('/');
		if(!isNaN(parseFloat(fa[0])) && !isNaN(parseFloat(fa[1])))
			r = parseFloat(fa[0])
	}
	return r;
}

function AgeWith12ths(age, bAll)
{
	if(isGarbage(age))
		return;
	if(!isNaN(age))
	{
		document.write(age);
		if(bAll && 0 != age)
		{
			document.write("&nbsp;year");
			if(1 != age)
				document.write("s");
			document.write("&nbsp;");
		}
	}
	else
	{
		var i;
		var fage = '';

		if(age.indexOf(' ') > 0)
		{
			var a = age.split(' ');
			if(2 == a.length)
			{
				if(2 != a.length)
					return;
				if(isNaN(parseFloat(a[0])))
					return;
				fage = parseFloat(a[0]);

				document.write(fage);
				if(bAll)
				{
					document.write("&nbsp;year");
					if(1 != fage)
						document.write("s");
					document.write("&nbsp;");
				
					fage = fraction2Months(a[1])
					if(-1 == fage)
						return;

					document.write(fage)
					document.write("&nbsp;month");
					if(1 != fage)
						document.write("s");
				}
			}
		}
		else 
		{
			if (bAll)
			{
				fage = fraction2Months(age);
				if(-1 == fage)
					return;
			
				document.write(fage);
				document.write("&nbsp;month");
					if(1 != fage)
						document.write("s");
			}
			else
			{
				document.write("0");
			}
		}
	}
}

function formatPhone(phone)
{
	if(10 == phone.length)
	{
		document.write("(");
		document.write(phone.substr(0,3));
		document.write(") ");
		document.write(phone.substr(3,3));
		document.write("-");
		document.write(phone.substr(6,4));
	}
	else if (12 == phone.length)
	{
		document.write("(");
		document.write(phone.substr(0,3));
		document.write(") ");
		document.write(phone.substr(4,3));
		document.write("-");
		document.write(phone.substr(8,4));
	}
	else
		document.write(phone);
	
}