var ControlIDSeparator = "__";

String.prototype.trim = function() 
	{
	a = this.replace (/^\s+/, '');
	return a.replace (/\s+$/, '');
	};
	
function IsControlType (controlID, controlIDPrefix, ControlIDSuffix)
	{
	var returnControlIDSuffix = 0;
	var returnValue = false;

	if (controlID.indexOf (controlIDPrefix + ControlIDSeparator) == 0)
		{
		if ((returnControlIDSuffix = GetControlIDSuffix (controlID, controlIDPrefix)) != 0)
			{
			controlIDSuffix = returnControlIDSuffix;
			returnValue = true;
			}
		}

	return (returnValue);
	}
	
function GetControlIDSuffix (controlID, controlIDPrefix)
	{
	var tempControlID;
	var tempControlIDPrefix;
	var tempControlIDSuffix;
	var controlIDSuffix = 0;

	tempControlID = controlID;
	tempControlIDPrefix = controlIDPrefix + ControlIDSeparator;
	if (tempControlID.indexOf (tempControlIDPrefix) == 0)
		{
		tempControlIDSuffix = tempControlID.substring (tempControlIDPrefix.Length, tempControlID.Length - tempControlIDPrefix.Length);
		if (IsInteger (tempControlIDSuffix))
			{
			controlIDSuffix = parseInt (tempControlIDSuffix);
			}
		}

	return (controlIDSuffix);
	}

function IsInteger (testString)
	{
	//char [] testArray;
	var index;
	var returnValue = false;
			
	try
		{
		if (testString != null)
			{
			//testArray = testString.ToCharArray ();

			//if (testArray.GetLength (0) > 0)
			if (testString.length > 0)
				{
				//for (index = 0; index < testArray.GetLength (0); index++)
				for (index = 0; index < testString.length; index++)
					{
					if (index == 0 && testString.charAt (index) == '-')
						continue;
					//if (!Char.IsDigit (testArray [index]))
					if (!testString.charAt (index).isDigit ())
						break;
					}
	
				if (index == testString.length)
					returnValue = true;
				}
			}
		}	
	finally
		{
		}

	return (returnValue);	
	}
	
function getElementPosition (object) 
	{
    var position = {x:0, y:0};
    
    if (object.offsetParent)
		{
		do 
			{
    		position.x += object.offsetLeft;
    		position.y += object.offsetTop;
			}
		while (object = object.offsetParent);
		}
			
    return (position);
    }
	
function getMousePosition (e)
	{
	var position = {x:0, y:0};
	
	if (!e)
		var e = window.event;
	
	if (e)
		{	
		if (e.pageX || e.pageY)
		 	{
			position.x = e.pageX;
			position.y = e.pageY;
			}
		else if (e.clientX || e.clientY)
		 	{
			position.x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			position.y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
			}
		}
		
	return (position);
	}

function getStyleAttribute (object, styleAttribute) 
	{
	if (~styleAttribute.indexOf ("-"))
		{ 
		var ___styleAttribute = styleAttribute, ___styleAttribute = styleAttribute.replace (/-([a-z]) /, function (__styleAttribute) {return (__styleAttribute [1] || __styleAttribute.substring (1)).toUpperCase();});
		}
	else
		{ 
		var ___styleAttribute = styleAttribute.replace (/([A-Z])/, "-$1").toLowerCase(), ___styleAttribute = styleAttribute;
		}
		
	return (object.currentStyle ? object.currentStyle [___styleAttribute] : window.getComputedStyle (object, null). getPropertyValue (___styleAttribute));
	}
		
function UploadButton_Clicked (uploadButtonControl, uploadFileControl, statusControl)
	{
	if (uploadFileControl.value !== '')
		{
		uploadButtonControl.enabled = false;
		statusControl.innerText = 'Your photo is uploading. Thank you for your patience.';
		
		return (true);
		}
	}
	
function SubmitButton_Clicked (submitButtonControl, statusControl)
	{
	Page_ClientValidate ();
	
	if (Page_IsValid)
		{
		submitButtonControl.enabled = false;
		statusControl.style.height = 12;
		statusControl.innerHTML = 'Your profile is being saved, please be patient...<br>';
	
		return (true);
		}
	}
	
function UpdateFieldLengthNotificationControl (textFieldControl, lengthNotificationControl, maxDisplayLength)
	{ 
	if (textFieldControl.value.length <= parseInt (maxDisplayLength))
		{
		lengthNotificationControl.style.color = 'gray';
		lengthNotificationControl.innerText = (textFieldControl.value.length - parseInt (maxDisplayLength)) + '';
		}
	else
		{
		lengthNotificationControl.style.color = 'red';
		lengthNotificationControl.innerText = "+" + (textFieldControl.value.length - parseInt (maxDisplayLength));
		}
	}
	
function DatePicker_OnBlur (sender)
	{
	var datePickerControl;
	var selectedDateFromString;
	var selectedDate;
	
	datePickerControl = eo_GetObject ("BirthdateCalendar");
	
	if (datePickerControl !== null)
		{
		selectedDate = datePickerControl.getSelectedDate ();						 
		
		if (selectedDate !== null)
			{
			if (selectedDate.getYear () < 10)
				selectedDate.setYear (selectedDate.getYear () + 2000);
			
			datePickerControl.setSelectedDate (selectedDate);
		
			delete (selectedDate);
			}
		}
		
	return;
	}

function NextButton_Clicked (approveCheckBoxControl)
	{
	var returnValue = false;
	
	if (approveCheckBoxControl.checked == false)
		alert ('You must approve the content of your Trading Card before proceeding.');
	else
		returnValue = true;
	
	return (returnValue);		
	}

function MakePurchase_Clicked (makePurchaseTopControl, makePurchaseBottomControl, statusMessageControl)
	{
	var hasInnerText = (document.getElementsByTagName("body")[0].innerText != undefined) ? true : false;
	var index;
	var childNode;
	
	
	makePurchaseTopControl.enabled = false;
	/*	
	for (index = 0; makePurchaseTopControl.childNodes.length; index++)
		{
		childNode = makePurchaseTopControl.childNodes [index];
		if (childNode.nodeName.toLowerCase () == "img") 
			{
			childNode.src = '../images/btn-makepurchase-disabled.jpg';
			break;
			}
		}
	*/
	
	makePurchaseBottomControl.enabled = false;
	/*
	for (index = 0; makePurchaseBottomControl.childNodes.length; index++)
		{
		childNode = makePurchaseBottomControl.childNodes [index];
		if (childNode.nodeName.toLowerCase () == "img") 
			{
			childNode.src = '../images/btn-makepurchase-disabled.jpg';
			break;
			}
		}
	*/
	statusMessageControl.className = 'errorMessage';
	if (hasInnerText)
		statusMessageControl.innerText = 'Your order is being processed. Please be patient.'
	else
		statusMessageControl.textContent = 'Your order is being processed. Please be patient.'
	
	return (true);		
	}
	
function ServerValidateProductOption (source, args)
	{
	var productID = -1;
	var productQuantityTextBox = null;
			
	try 
		{
		if (Globals.IsControlType (source.ID, productOptionPrefix, productID))
			{
			if ((productQuantityTextBox = document.getElementById (Globals.BuildControlID (productQuantityPrefix, productID))) != null)
				{
				if (productQuantityTextBox.value == "0")
					args.IsValid = true;
				else if (source.selectedValue == "")
					args.IsValid = false;
					}
				}
			}
		catch (Exception)
			{
			args.IsValid = false;
			}

		}
	
function ShowPopup (positioningControl, popupControl, horizontalOffset, verticalOffset)
	{
	var mousePosition;
	var popupControlWidth = 0;
	
	popupControlWidth = getStyleAttribute (popupControl, "width");
	popupControlWidth = popupControlWidth.replace ('px', '');
	popupControlWidth = popupControlWidth.replace ('pt', '');
	
	//mousePosition = getMousePosition (event);
	mousePosition = getElementPosition (positioningControl);
	
	popupControl.style.left = mousePosition.x - popupControlWidth + horizontalOffset;
	popupControl.style.top = mousePosition.y + verticalOffset;
	popupControl.style.visibility='visible';
	
	//return (false);	
	} 
	
function ClosePopup (popupControl)
	{
	popupControl.style.visibility = 'hidden';
	
	return (false);
	}
