﻿
var phoneNumberDelimiters = "()- ";
var validWorldPhoneChars = phoneNumberDelimiters + "+";
var minDigitsInIPhoneNumber = 10;
var n;
var p;
var p1;
var commonPasswords = new Array('password', 'pass', '1234', '2468');
var lowercase = "abcdefghijklmnopqrstuvwxyz";
var uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var numbers = "0123456789";
var digits = numbers;
var punctuation = "!.@$£#*()%~<>{}[]";
var acceptableNormalText = "0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ ~`!@#$%^&*()_+-=?,.:;'/\"\\";

//****************************************************
//
// CreateXMLHttp
//
// Function creates the xmlHttp object
//
//****************************************************
function CreateXMLHttp()
{
    try
    {
        // Firefox, Opera 8.0+, Safari
        return new XMLHttpRequest();
    }
    catch (e1)
    {
        // Internet Explorer
        try
        {
            return new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e2)
        {
            try
            {
                return new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e3)
            {
                alert("Your browser does not support AJAX!");
                return null;
            }
        }
    }
}

//****************************************************
//
// ValidatePasswordOnKeyUp
//
// Checks the strength of a password
//
//****************************************************
function ValidatePasswordOnKeyUp(password, PasswordStrengthDiv)
{
	var combinations = 0;
	if (contains(password, numbers) > 0)
	{ combinations += 10; }

	if (contains(password, lowercase) > 0)
	{ combinations += 26; }

	if (contains(password, uppercase) > 0)
	{ combinations += 26; }

	if (contains(password, punctuation) > 0)
	{ combinations += punctuation.length; }

	// work out the total combinations 
	var totalCombinations = Math.pow(combinations, password.length);

	// if the password is a common password, then everthing changes... 
	if (isCommonPassword(password))
	{ totalCombinations = 75000 }

	// work out how long it would take to crack this (@ 200 attempts per second) 
	var timeInSeconds = (totalCombinations / 200) / 2;

	// this is how many days? (there are 86,400 seconds in a day. 
	var timeInDays = timeInSeconds / 86400

	// how long we want it to last 
	var lifetime = 365;

	// how close is the time to the projected time? 
	var percentage = timeInDays / lifetime;

	var friendlyPercentage = cap(Math.round(percentage * 100), 100);
	if (totalCombinations != 75000 && friendlyPercentage < (password.length * 5))
	{ friendlyPercentage += password.length * 5; }

	var progressBar = document.getElementById(PasswordStrengthDiv);
	progressBar.style.width = friendlyPercentage + "%";

	if (percentage > 1)
	{
		// strong password 
		progressBar.style.backgroundColor = "#3bce08";
		return;
	}

	if (percentage > 0.5)
	{
		// reasonable password 
		progressBar.style.backgroundColor = "#ffd801";
		return;
	}

	if (percentage > 0.10)
	{
		// weak password 
		progressBar.style.backgroundColor = "orange";
		return;
	}

	// useless password! 
	if (percentage <= 0.10)
	{
		// weak password 
		progressBar.style.backgroundColor = "red";
		return;
	}
}

//****************************************************
//
// cap
//
// Caps a number at it's max
//
//****************************************************
function cap(number, max)
{
	var retVal = number;
	if (number == null || max == null)
	{
		retVal = null;
	}
	else if (!isInteger(number) || !isInteger(max))
	{
		retVal = null;
	}
	else if (number > max)
	{
		retVal = max;
	}
	else
	{
		retVal = number;
	}
	return retVal;
}

//****************************************************
//
// isCommonPassword
//
// Checks if a password is common
//
//****************************************************
function isCommonPassword(password)
{
	var retVal = false;
	if (password == null)
	{
		retVal = true;
	}
	else if (password.length < 2)
	{
		retVal = true;
	}
	else
	{
		for (i = 0; i < commonPasswords.length; i++)
		{
			var commonPassword = commonPasswords[i];
			if (password == commonPassword)
			{
				retVal = true;
			}
		}
	}
	return retVal;
}

//****************************************************
//
// contains
//
// verifies a password has valid characters
//
//****************************************************
function contains(password, validChars)
{
	count = 0;
	if (password != null && validChars != null)
	{
		for (i = 0; i < password.length; i++)
		{
			var char = password.charAt(i);
			if (validChars.indexOf(char) > -1)
			{ count++; }
		}
	}
	return count;
}

//****************************************************
//
// SearchWebsite
//
// Function to pull up search results via AJAX
// It pulls one variable, DirectoryPath, which will
// change depending on the environment. Some sample
// values might be:
//
// www.youthville.org
// test.youthville.org
// development:88
// localhost/Youthville
//
//****************************************************
function SearchWebsite(DirectoryPath)
{
	var txtSearch = document.getElementById('txtSearch').value;
	window.location = 'http://' + DirectoryPath + '/SearchWebsite.aspx?search=' + txtSearch;
}

//****************************************************
//
// SetFocus
//
// Function to set the focus on a given control
//
//****************************************************
function SetFocus(ControlID)
{
	document.getElementById(ControlID).focus();
}

//****************************************************
//
// DisplayHiddenControl
//
// Function to display a hidden control
//
//****************************************************
function DisplayHiddenControl(ControlID)
{
	document.getElementById(ControlID).style.display = 'block'
}

//****************************************************
//
// HideVisibleControl
//
// Function to hide a visible control
//
//****************************************************
function HideVisibleControl(ControlID)
{
	document.getElementById(ControlID).style.display = 'none'
}

//*************************************************
//
// ValidatePhoneOnBlur
//
// Makes phone number correct format
//
//*************************************************
function ValidatePhoneOnBlur(phoneFieldID)
{
    var phoneField = document.getElementById(phoneFieldID);
    if (phoneField != null)
    {
        var phoneNumber = phoneField.value;
        phoneNumber = ConvertToNumeric(phoneNumber);

        if (phoneNumber.length == 10)
        {
            // 3165551212
            phoneNumber = '(' + phoneNumber.substring(0, 3) + ') ' + phoneNumber.substring(3, 6) + '-' + phoneNumber.substring(6, 10);
        }
        else if (phoneNumber.length == 11 && phoneNumber.indexOf('1') == 0)
        {
            // 13165551212
            phoneNumber = '(' + phoneNumber.substring(1, 4) + ') ' + phoneNumber.substring(4, 7) + '-' + phoneNumber.substring(7, 11);
        }
        else if (phoneNumber.length == 7)
        {
            // 5551212
            phoneNumber = phoneNumber.substring(0, 3) + '-' + phoneNumber.substring(3, 7);
        }
    }

    phoneField.value = phoneNumber;
}

//*************************************************
//
// isInteger
//
// Identifies whether or not string is all integers
//
//*************************************************
function isInteger(s)
{
	var retVal = true;
	var i;
	if (s == null)
	{
		retVal = false;
	}
	else
	{
		for (i = 0; i < s.length; i++)
		{
			// Check that current character is number.
			var c = s.charAt(i);
			if (((c < "0") || (c > "9"))) retVal = false;
		}
	}
	// All characters are numbers.
	return retVal;
}

//*************************************************
//
// stripCharsInBag
//
// Gets rid of permitted but unneccessary
// junk in phone string like "( ) -" chars
//
//*************************************************
function stripCharsInBag(s, bag)
{
	var i;
	var returnString = "";
	if (s != null && bag != null)
	{
		// Search through string's characters one by one.
		// If character is not in bag, append to returnString.
		for (i = 0; i < s.length; i++)
		{
			// Check that current character isn't whitespace.
			var c = s.charAt(i);
			if (bag.indexOf(c) == -1) returnString += c;
		}
	}
	else if (bag == null && s != null)
	{
		returnString = s;
	}
	return returnString;
}

//*************************************************
//
// stripCharsNotInBag
//
// Takes out every character in s
// that is not also in bag
//
//*************************************************
function stripCharsNotInBag(s, bag)
{
	var i;
	var returnString = "";
	if (s != null && bag != null)
	{
		// Search through string's characters one by one.
		// If character is not in bag, append to returnString.
		for (i = 0; i < s.length; i++)
		{
			// Check that current character isn't whitespace.
			var c = s.charAt(i);
			if (bag.indexOf(c) > -1) returnString += c;
		}
	}
	return returnString;
}

//*************************************************
//
// checkInternationalPhone
//
// Checks if the specified number is an
// international phone number
//
//*************************************************
function checkInternationalPhone(strPhone)
{
	s = stripCharsInBag(strPhone, validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

//*************************************************
//
// ValidatePhoneNumber
//
// Checks any specified Phone field to make sure
// it is really a phone number
//
//*************************************************
function ValidatePhoneNumber(PhoneField)
{
	var Phone = document.getElementById(PhoneField);
	if (checkInternationalPhone(Phone.value) == false)
	{
		alert("Please Enter a Valid Phone Number with Area Code\r\nin the following format: (555) 555-5555");
		Phone.value = "";
		Phone.focus();
		return false;
	}
	return true;
}

//*************************************************
//
// ValidateCurrencyOnBlur
//
// Makes currency correct format
//
//*************************************************
function ValidateCurrencyOnBlur(CurrencyField)
{
	var DollarAmount = document.getElementById(CurrencyField).value.replace('$', '');
	var i = parseFloat(DollarAmount);
	if (isNaN(i)) { i = 0.00; }
	var minus = '';
	if (i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if (s.indexOf('.') < 0) { s += '.00'; }
	if (s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	document.getElementById(CurrencyField).value = s;
}

//*************************************************
//
// ValidateEmail
//
// Checks any specified Email field to make sure
// it is really an Email Address
//
//*************************************************
function ValidateEmail(EmailField)
{
	var EmailField = document.getElementById(EmailField)
	var str = EmailField.value;
	if (str.length > 0)
	{
		var at = "@"
		var dot = "."
		var lat = str.indexOf(at)
		var lstr = str.length
		var ldot = str.indexOf(dot)
		if (str.indexOf(at) == -1)
		{
			alert("Please enter a valid Email Address");
			EmailField.value = "";
			EmailField.focus();
			return false;
		}
		if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr)
		{
			alert("Please enter a valid Email Address");
			EmailField.value = "";
			EmailField.focus();
			return false;
		}
		if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr)
		{
			alert("Please enter a valid Email Address");
			EmailField.value = "";
			EmailField.focus();
			return false;
		}
		if (str.indexOf(at, (lat + 1)) != -1)
		{
			alert("Please enter a valid Email Address");
			EmailField.value = "";
			EmailField.focus();
			return false;
		}
		if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot)
		{
			alert("Please enter a valid Email Address");
			EmailField.value = "";
			EmailField.focus();
			return false;
		}
		if (str.indexOf(dot, (lat + 2)) == -1)
		{
			alert("Please enter a valid Email Address");
			EmailField.value = "";
			EmailField.focus();
			return false;
		}
		if (str.indexOf(" ") != -1)
		{
			alert("Please enter a valid Email Address");
			EmailField.value = "";
			EmailField.focus();
			return false;
		}
		return true;
	}
	else
	{
		return true;
	}
}

//****************************************************
//
// showHelp
//
// Function to show help info
//
//****************************************************
function showHelp(tooltipId)
{
	it = document.getElementById(tooltipId);
	if (self.innerWidth)
	{
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}

	it.style.width = '350px'
	if (frameWidth < (tempX + 400))
	{
		//Not enough space to the right
		it.style.left = (frameWidth - 400) + 'px';
		it.style.top = tempY + 5 + 'px';
	}
	else
	{
		//plenty of space to the right
		it.style.left = tempX + 5 + 'px';
		it.style.top = tempY + 5 + 'px';
	}

	it.style.visibility = 'visible';
}

//****************************************************
//
// hideHelp
//
// Function to hide help info
//
//****************************************************
function hideHelp(tooltipId)
{
	it = document.getElementById(tooltipId);
	it.style.visibility = 'hidden';
}

//*************************************************
//
// ValidateEmailOnBlur
//
// Confirms Email Address is a valid Email
//
//*************************************************
function ValidateEmailOnBlur(EmailField)
{
	if (document.getElementById(EmailField).value != "")
	{
		if (!isEmail(document.getElementById(EmailField).value))
		{
			document.getElementById(EmailField).value = "";
			alert("Please enter a valid Email Address.");
		}
	}
}

//*************************************************
//
// isEmail
//
// Confirms Email Address is a valid Email
//
//*************************************************
function isEmail(str)
{
	if (str == null)
	{
		return false;
	}
	else
	{
		var at = "@"
		var dot = "."
		var lat = str.indexOf(at)
		var lstr = str.length
		var ldot = str.indexOf(dot)
		if (str.indexOf(at) == -1)
		{ return false; }

		if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr)
		{ return false; }

		if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr)
		{ return false; }

		if (str.indexOf(at, (lat + 1)) != -1)
		{ return false; }

		if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot)
		{ return false; }

		if (str.indexOf(dot, (lat + 2)) == -1)
		{ return false; }

		if (str.indexOf(" ") != -1)
		{ return false; }

		return true
	}
}

//*************************************************
//
// Validate4SSNOnBlur
//
// Confirms that last 4 of SSN are numeric
//
//*************************************************
function Validate4SSNOnBlur(SSNField)
{
	if (!isInteger(document.getElementById(SSNField).value))
	{
		document.getElementById(SSNField).value = "";
		alert("Please enter the last 4 digits of your SSN correctly.");
	}
}

//*************************************************
//
// ValidatePasswordsOnBlur
//
// Confirms that Password and ConfirmPassword
// are the same
//
//*************************************************
function ValidatePasswordsOnBlur(Password, ConfirmPassword)
{
	if (document.getElementById(Password).value != document.getElementById(ConfirmPassword).value)
	{
		document.getElementById(ConfirmPassword).value = "";
		alert("Make sure your Password and your Confirm Password are identical.");
	}
}

//*************************************************
//
// CompareUsernameScreennameOnBlur
//
// Confirms that Username and Screenname
// are not the same
//
//*************************************************
function CompareUsernameScreennameOnBlur(Username, Screenname)
{
	if (document.getElementById(Username).value != "" && document.getElementById(Screenname).value != "")
	{
		if (document.getElementById(Username).value == document.getElementById(Screenname).value)
		{
			document.getElementById(Screenname).value = "";
			alert("Your Screenname must be different than your Username.");
		}
	}
}

//****************************************************
//
// CheckDateFormatAgainstSQL
//
// Double check that the date is in a format that
// SQL Server will accept
//
//****************************************************
function CheckDateFormatAgainstSQL(theDate)
{
	var xmlHttp = CreateXMLHttp();
	var strReturn = '';
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4)
		{
			strReturn = xmlHttp.responseText;
			return strReturn;
		}
	}

	var day = new Date();
	var RandomID = day.getTime();
	var PagePath = "YouthvilleDateChecker.aspx?rand=" + RandomID + "&date=" + theDate;

	xmlHttp.open("GET", PagePath, true);
	xmlHttp.send(null);
}

//*************************************************
//
// ValidateDOBOnBlur
//
// Confirms that DOB field is correctly formatted
//
//*************************************************
function ValidateDOBOnBlur(DOBField)
{
	re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
	if (document.getElementById(DOBField).value != '')
	{
		if (!document.getElementById(DOBField).value.match(re))
		{
			document.getElementById(DOBField).value = "";
			alert("Your Date of Birth must be in the following format: MM/DD/YYYY");
		}
	}
}

//*************************************************
//
// ValidateDateField
//
// Confirms that DateField is correctly formatted
//
//*************************************************
function ValidateDateField(DateField)
{
	re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
	if (document.getElementById(DateField).value != '')
	{
		if (!document.getElementById(DateField).value.match(re))
		{
			document.getElementById(DateField).value = "";
			alert("The date must be in the following format: MM/DD/YYYY");
			return false;
		}
		else
		{
			var xmlHttp = CreateXMLHttp();
			var strReturn = '';
			xmlHttp.onreadystatechange = function()
			{
				if (xmlHttp.readyState == 4)
				{
					strReturn = xmlHttp.responseText;
					if (strReturn == '')
					{
						return true;
					}
					else
					{
						document.getElementById(DateField).value = "";
						alert(strReturn);
						return false;
					}
				}
			}

			var day = new Date();
			var RandomID = day.getTime();
			var PagePath = "/YouthvilleDateChecker.aspx?rand=" + RandomID + "&date=" + document.getElementById(DateField).value;

			xmlHttp.open("GET", PagePath, true);
			xmlHttp.send(null);

		}
	}
}

//*************************************************
//
// AdjustDateFieldFormat
//
// Correctly formats the DateField
//
//*************************************************
function AdjustDateFieldFormat(DateField)
{
	var DateValue;
	DateValue = "";
	DateValue = stripCharsNotInBag(document.getElementById(DateField).value, "0123456789");
	re = /^\d{1,2}\/\d{1,2}\/\d{2,4}$/;
	if (document.getElementById(DateField).value != '')
	{
		if (!document.getElementById(DateField).value.match(re))
		{
			if (DateValue.length == 8)
			{
				try
				{
					var NewDateValue;
					NewDateValue = DateValue.substring(0, 2) + "/" + DateValue.substring(2, 4) + "/" + DateValue.substring(4, DateValue.length);
					DateValue = NewDateValue;
					document.getElementById(DateField).value = DateValue;
				}
				catch (e)
				{
					document.getElementById(DateField).value = "";
					SetFocus(DateField);
				}
			}
			else if (DateValue.length == 7)
			{
				try
				{
					var NewDateValue;
					if (DateValue.charAt(0) > 1)
					{
						NewDateValue = DateValue.charAt(0) + "/" + DateValue.substring(1, 3) + "/" + DateValue.substring(3, DateValue.length);
					}
					else
					{
						NewDateValue = DateValue.substring(0, 2) + "/" + DateValue.charAt(2) + "/" + DateValue.substring(3, DateValue.length);
					}
					DateValue = NewDateValue;
					document.getElementById(DateField).value = DateValue;
				}
				catch (e)
				{
					document.getElementById(DateField).value = "";
					SetFocus(DateField);
				}
			}
			else if (DateValue.length == 6)
			{
				try
				{
					var NewDateValue;
					NewDateValue = DateValue.charAt(0) + "/" + DateValue.charAt(1) + "/" + DateValue.substring(2, DateValue.length);
					DateValue = NewDateValue;
					document.getElementById(DateField).value = DateValue;
				}
				catch (e)
				{
					document.getElementById(DateField).value = "";
					SetFocus(DateField);
				}
			}
			else
			{
				document.getElementById(DateField).value = "";
				SetFocus(DateField);
			}
		}

		var CheckDate = document.getElementById(DateField).value;
		var xmlHttp = CreateXMLHttp();
		var strReturn = '';
		xmlHttp.onreadystatechange = function()
		{
			if (xmlHttp.readyState == 4)
			{
				strReturn = xmlHttp.responseText;
				if (strReturn == '')
				{
					//alert('1. ' + CheckDate);
					return true;
				}
				else
				{
					//alert('2. ' + CheckDate);
					document.getElementById(DateField).value = "";
					alert(strReturn);
					SetFocus(DateField);
				}
			}
		}
		var day = new Date();
		var RandomID = day.getTime();
		var PagePath = "/YouthvilleDateChecker.aspx?rand=" + RandomID + "&date=" + CheckDate;
		xmlHttp.open("GET", PagePath, true);
		xmlHttp.send(null);
	}
}

//*************************************************
//
// OpenHelpWindow
//
// Opens a pop-up window for assistance
//
//*************************************************
function OpenHelpWindow(PageURL)
{
	var isIE3 = false;
	var aV = navigator.appVersion.charAt(0);
	if (aV > 3 && navigator.appCodeName == 'Mozilla')
	{
	}
	else if (aV == 2)
	{
		isIE3 = (-1 < navigator.userAgent.toLowerCase().indexOf('msie'));
	}
	if (isIE3)
	{
		alert('IE3 is not compatible with this Pop-Up');
		return;
	}
	//var where = "http://" + DomainPath + "/Help/" + PageURL;
	var where = "/Help/" + PageURL;
	open(where, "SBWIN", "toolbar=no,directories=no,location=no,status=no,resizable=no,screenx=10,screeny=10,width=400,height=300,top=10,left=10,scrollbars=1");
}

//*************************************************
//
// OpenCustomWindow
//
// Opens a custom pop-up window
//
//*************************************************
function OpenCustomWindow(PageURL, toolbar, directories, location, status, resize, top, left, width, height, scroll)
{
	var isIE3 = false;
	var aV = navigator.appVersion.charAt(0);
	if (aV > 3 && navigator.appCodeName == 'Mozilla')
	{
	}
	else if (aV == 2)
	{
		isIE3 = (-1 < navigator.userAgent.toLowerCase().indexOf('msie'));
	}
	if (isIE3)
	{
		alert('IE3 is not compatible with this Pop-Up');
		return;
	}
	open(PageURL, "CustomWindow", "toolbar=" + toolbar + ",directories=" + directories + ",location=" + location + ",status=" + status + ",resizable=" + resize + ",screenx=" + left + ",screeny=" + top + ",width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + ",scrollbars=" + scroll);
}

//*************************************************
//
// OpenGalleryImage
//
// Opens a Gallery Image
//
//*************************************************
function OpenGalleryImage(imageURL, width, height)
{
	var isIE3 = false;
	var aV = navigator.appVersion.charAt(0);
	if (aV > 3 && navigator.appCodeName == 'Mozilla')
	{
	}
	else if (aV == 2)
	{
		isIE3 = (-1 < navigator.userAgent.toLowerCase().indexOf('msie'));
	}
	if (isIE3)
	{
		alert('IE3 is not compatible with this Pop-Up');
		return;
	}
	var where = imageURL;
	open(where, "SBWIN", "toolbar=no,directories=no,location=no,status=no,resizable=no,screenx=10,screeny=10,width=" + width + ",height=" + height + ",top=10,left=10,scrollbars=1");
}

//****************************************************
//
// moveXbySlicePos
//
// adds x to the left coordinate of the img control
//
//****************************************************
function moveXbySlicePos(x, img)
{
	if (!document.layers)
	{
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
		var par = img;
		var lastOffset = 0;
		while (par)
		{
			if (par.leftMargin && !onWindows) x += parseInt(par.leftMargin);
			if ((par.offsetLeft != lastOffset) && par.offsetLeft) x += parseInt(par.offsetLeft);
			if (par.offsetLeft != 0) lastOffset = par.offsetLeft;
			par = macIE45 ? par.parentElement : par.offsetParent;
		}
	}
	else if (img.x) x += img.x;
	return x;
}

//****************************************************
//
// moveYbySlicePos
//
// adds y to the top coordinate of the img control
//
//****************************************************
function moveYbySlicePos(y, img)
{
	if (!document.layers)
	{
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
		var par = img;
		var lastOffset = 0;
		while (par)
		{
			if (par.topMargin && !onWindows) y += parseInt(par.topMargin);
			if ((par.offsetTop != lastOffset) && par.offsetTop) y += parseInt(par.offsetTop);
			if (par.offsetTop != 0) lastOffset = par.offsetTop;
			par = macIE45 ? par.parentElement : par.offsetParent;
		}
	}
	else if (img.y >= 0) y += img.y;
	return y;
}

//*************************************************
//
// trimString
//
// Removes whitespace on the ends of a string
//
//*************************************************
function trimString(stringToTrim)
{
	return stringToTrim.replace(/^\s+|\s+$/g, "");
}

//*************************************************
//
// nl2br
//
// Converts New Lines to <br />
//
//*************************************************
function nl2br(text)
{
	text = escape(text);
	if (text.indexOf('%0D%0A') > -1)
	{
		re_nlchar = /%0D%0A/g;
	} else if (text.indexOf('%0A') > -1)
	{
		re_nlchar = /%0A/g;
	} else if (text.indexOf('%0D') > -1)
	{
		re_nlchar = /%0D/g;
	}
	return unescape(text.replace(re_nlchar, '<br />'));
}


//****************************************************
//
// isAlphaNumeric
//
//****************************************************
function isAlphaNumeric(alphane)
{
	var answer = true;
	var numaric = alphane;
	for(var j=0; j<(numaric + '').length; j++)
	{
		var alphaa = (numaric + '').charAt(j);
		var hh = alphaa.charCodeAt(0);
		if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		{
			answer = true;
		}
		else
		{
			answer = false;
		}
	}
	return answer;
}


//****************************************************
//
// isNumeric
//
//****************************************************
function isNumeric(alphane)
{
	var answer = true;
	var numaric = alphane;
	for(var j=0; j<(numaric + '').length; j++)
	{
		var alphaa = (numaric + '').charAt(j);
		var hh = alphaa.charCodeAt(0);
		if((hh > 47 && hh < 58))
		{
			answer = true;
		}
		else
		{
			answer = false;
		}
	}
	return answer;
}


//****************************************************
//
// ConvertToAlphaNumeric
//
//****************************************************
function ConvertToAlphaNumeric(theValue)
{
	var theOutput = '';
	for(var j = 0; j < (theValue + '').length; j++)
	{
		var alphaa = (theValue + '').charAt(j);
		if(isAlphaNumeric(alphaa))
		{
			theOutput = theOutput + alphaa;
		}
	}
	return theOutput;
}


//****************************************************
//
// ConvertToNumeric
//
//****************************************************
function ConvertToNumeric(theValue)
{
	var theOutput = '';
	for (var j = 0; j < (theValue + '').length; j++)
	{
		var alphaa = (theValue + '').charAt(j);
		if (isNumeric(alphaa))
		{
			theOutput = theOutput + alphaa;
		}
	}
	if (theOutput == '')
	{
		theOutput = '0';
	}
	return theOutput;
}


//****************************************************
//
// ConvertToStandardizedText
//
//****************************************************
function ConvertToStandardizedText(id)
{
	var theField = document.getElementById(id);
	if (theField != null)
	{
		theField.value = stripCharsNotInBag(theField.value, acceptableNormalText);
	}
}


//****************************************************
//
// CheckCharacterCount
//
//****************************************************
function CheckCharacterCount(textControl, maxLength)
{
	var textBox = document.getElementById(textControl);
	if (textBox != null)
	{
		var theText = textBox.value;
		var charCount = theText.length;
		var warning = '';

		if (maxLength < charCount)
		{
			warning = 'You have exceeded the maximum number of characters.\nYou may only use ' + maxLength + ' characters.';
			while (maxLength < charCount)
			{
				theText = theText.substring(0, (theText.length - 1));
				charCount = theText.length;
			}
			textBox.value = theText;
		}

		if (warning != '')
		{
			alert(warning);
		}
	}
}


//****************************************************
//
// DetermineIfAnyRadioButtonInParentControlIsSelected
//
//****************************************************
function DetermineIfAnyRadioButtonInParentControlIsSelected(parentControl)
{
	var isSelected = false;

	var i = 0;
	for (i = 0; i < parentControl.childNodes.length; i++)
	{
		if (isSelected == false)
		{
			try
			{
				if (parentControl.childNodes[i].tagName == 'INPUT')
				{
					var radioButton = parentControl.childNodes[i];
					if (radioButton.checked)
					{
						isSelected = true;
					}
				}
				else if (parentControl.childNodes[i].nodeName != '#text')
				{
					isSelected = DetermineIfAnyRadioButtonInParentControlIsSelected(parentControl.childNodes[i]);
				}
			}
			catch (e)
			{
			}
		}
	}

	return isSelected;
}


//****************************************************
//
// MakeTableRowVisible
//
//****************************************************
function MakeTableRowVisible(tableRow)
{
	if (navigator.appName == 'Microsoft Internet Explorer')
	{
		tableRow.style.display = 'block';
	}
	else
	{
		tableRow.style.display = 'table-row';
	}
}
