﻿
		var digits = "0123456789";
		var phoneNumberDelimiters = "()- ";
		var validWorldPhoneChars = phoneNumberDelimiters + "+";
		var minDigitsInIPhoneNumber = 10;
		var n;
		var p;
		var p1;
		var commonPasswords = new Array('password', 'pass', '1234', '1246'); 
 
		var numbers = "0123456789";
		var lowercase = "abcdefghijklmnopqrstuvwxyz";
		var uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		var punctuation = "!.@$£#*()%~<>{}[]";
		
		//****************************************************
		//
		// 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();
		}
    
		//****************************************************
		//
		// CreateXMLHttp
		//
		// Function creates the xmlHttp object
		//
		//****************************************************
		function CreateXMLHttp()
		{
			try
			{
				// Firefox, Opera 8.0+, Safari
				return new XMLHttpRequest();
			}
			catch (e)
			{
				// Internet Explorer
				try
				{
					return new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch (e)
				{
					try
					{
						return new ActiveXObject("Microsoft.XMLHTTP");
					}
					catch (e)
					{
						alert("Your browser does not support AJAX!");
						return null;
					}
				}
			}
		}
		
		//****************************************************
		//
		// 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(PhoneField)
		{
			var i;
			i = 0;
			while (i < 10)
			{
			
			p = document.getElementById(PhoneField).value;
			p1 = document.getElementById(PhoneField);
			if(p.length==3)
			{
				pp=p;
				d4=p.indexOf('(')
				d5=p.indexOf(')')
				if(d4==-1)
				{
					pp="("+pp;
				}
				if(d5==-1)
				{
					pp=pp+")";
				}
				document.getElementById(PhoneField).value="";
				document.getElementById(PhoneField).value=pp;
			}
			if(p.length>3)
			{
				d1=p.indexOf('(')
				d2=p.indexOf(')')
				if (d2==-1)
				{
					l30=p.length;
					p30=p.substring(0,4);
					p30=p30+")"
					p31=p.substring(4,l30);
					pp=p30+p31;
					document.getElementById(PhoneField).value="";
					document.getElementById(PhoneField).value=pp;
				}
			}
			if(p.length>5)
			{
				p11=p.substring(d1+1,d2);
				if(p11.length>3)
				{
					p12=p11;
					l12=p12.length;
					l15=p.length
					p13=p11.substring(0,3);
					p14=p11.substring(3,l12);
					p15=p.substring(d2+1,l15);
					document.getElementById(PhoneField).value="";
					pp="("+p13+")"+p14+p15;
					document.getElementById(PhoneField).value=pp;
				}
				l16=p.length;
				p16=p.substring(d2+1,l16);
				l17=p16.length;
				if(l17>3&&p16.indexOf('-')==-1)
				{
					p17=p.substring(d2+1,d2+4);
					p18=p.substring(d2+4,l16);
					p19=p.substring(0,d2+1);
					pp=p19+p17+"-"+p18;
					document.getElementById(PhoneField).value="";
					document.getElementById(PhoneField).value=pp;
				}
			}
			
			i = i + 1;
			}
			document.getElementById(PhoneField).value = document.getElementById(PhoneField).value.substring(0,14).replace(')-',') ');
		}

		//*************************************************
		//
		// 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(DomainPath, 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;
			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);
		}
		
		//****************************************************
		//
		// 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;
		}