/* Paginate User Control */
function LoadPage(thisForm, intPage)
{
	thisForm.idCurrentPage.value=intPage;
	thisForm.submit();
}

/* EventSelector User Control */

/* Login box homepage. */
function LoginboxValid(thisForm, logincodeName, passwordName,  defaultValue )
{	
	var objLogincode = objField(thisForm, logincodeName, "");
	var objPasswordcode = objField(thisForm, passwordName, "");
	
	var objStringUtils = new CSoftixUtils();

	//FireFox2 has implemented window.external but does not have this method
	if (window.external)
	{
		try{
		window.external.AutoCompleteSaveForm(myform);
		}catch(e){}
	}

	if (objStringUtils.strTrim(objLogincode.value) == defaultValue)
	{
		objLogincode.focus();
		alert(_messages['loginboxMissingCode']);
		return false;
	}		
	
	// Add the charset validation		
	if (!ValidateCharSet(objLogincode)) return false;
	if (!ValidateCharSet(objPasswordcode)) return false;
	
	return true;	
}


/*

Call by an instance of ValidateButton when performing client-side validation
after the user has clicked the button.

If this function returns TRUE then the form is submitted.

*/
function ValidateButton_IsValid(thisForm, validationArray)
{
	var success = true;
	for (var i=0; i< validationArray.length; i++)
	{
		eval("success = " + validationArray[i]);
		if (!success) break;
	}
		
	return success;
}

/*

Each validation control that participates in a validation via the ValidateButton
(i.e. implements IValidationParticipant) must implement a javascript function that
validates its own data and registers itself with the corresponding ValidateButton.

The ValidateButton will then iterate thru its validation array and evaluate each
participating function. If any return false then execution terminates and the form
is not submitted.

*/
function ValidateDataControl(thisForm, idToValidate)
{
	var firstname = objField(thisForm, idToValidate, ":firstname");
	var emailaddress = objField(thisForm, idToValidate, ":email");
	
	if (firstname.value == "")
	{
		firstname.focus();
		alert("Firstname may not be blank.");
		return false;
	}
	
	if (emailaddress.value == "")
	{
		emailaddress.focus();
		alert("Email address may not be blank.");
		return false;
	}
	
	return true;
	
}

/*

Validate the Account Controls

*/
function ValidateAccountBasicDetails(thisForm, idToValidate, 
	emailReq, 
	loginReq, 
	passwordReq,
	passwordLength,
	salutationReq,
	firstNameReq, 
	middleNameReq, 
	lastNameReq,
	dobReq,
	homeCCodeReq, 
	homeACodeReq, 
	homeReq, 
	otherCCodeReq, 
	otherACodeReq, 
	otherReq, 
	mobCCodeReq, 
	mobReq )

{
	
	// Get form fields back
	var email			= objField(thisForm, idToValidate, ":email");
	var login			= objField(thisForm, idToValidate, ":login");
	var password1		= objField(thisForm, idToValidate, ":password1");
	var password2		= objField(thisForm, idToValidate, ":password2");	
	var salutation		= objField(thisForm, idToValidate, ":salutation");
	var firstName		= objField(thisForm, idToValidate, ":firstName");
	var middleName		= objField(thisForm, idToValidate, ":middleName");
	var lastName		= objField(thisForm, idToValidate, ":lastName");
	var dobDay			= objField(thisForm, idToValidate, ":dateOfBirthDay");
	var dobMonth		= objField(thisForm, idToValidate, ":dateOfBirthMonth");
	var dobYear			= objField(thisForm, idToValidate, ":dateOfBirthYear");
	
	var homePhoneCC     = objField(thisForm, idToValidate, ":txtHomeCC");
	var homePhoneAC     = objField(thisForm, idToValidate, ":txtHomeAC");
	var homePhoneNo     = objField(thisForm, idToValidate, ":txtHome");

	var mobilePhoneCC	= objField(thisForm, idToValidate, ":txtMobileCC");
	var mobilePhoneNo	= objField(thisForm, idToValidate, ":txtMobile");

	var otherPhoneCC	= objField(thisForm, idToValidate, ":txtOtherCC");
	var otherPhoneAC	= objField(thisForm, idToValidate, ":txtOtherAC");
	var otherPhoneNo    = objField(thisForm, idToValidate, ":txtOther");	
	
	var objStringUtils = new CSoftixUtils;
	
	//Validate UniCode for all input field for AccountBasicDetails
	if (!ValidateCharSet(email)) return false;
	if (!ValidateCharSet(login)) return false;
	if (!ValidateCharSet(password1)) return false;
	if (!ValidateCharSet(password2)) return false;
	if (!ValidateCharSet(salutation)) return false;
	if (!ValidateCharSet(firstName)) return false;	
	if (!ValidateCharSet(middleName)) return false;
	if (!ValidateCharSet(lastName)) return false;
	if (!ValidateCharSet(dobDay)) return false;
	if (!ValidateCharSet(dobMonth)) return false;
	if (!ValidateCharSet(dobYear)) return false;
	if (!ValidateCharSet(homePhoneCC)) return false;
	if (!ValidateCharSet(homePhoneAC)) return false;
	if (!ValidateCharSet(homePhoneNo)) return false;
	if (!ValidateCharSet(mobilePhoneCC)) return false;
	if (!ValidateCharSet(mobilePhoneNo)) return false;	
	if (!ValidateCharSet(otherPhoneCC)) return false;
	if (!ValidateCharSet(otherPhoneAC)) return false;
	if (!ValidateCharSet(otherPhoneNo)) return false;

	// Email Not Blank
	if ((typeof(email) != 'undefined') && (emailReq) && (objStringUtils.strTrim(email.value) == ""))
	{
		email.focus();
		alert(_messages["EmailBlank"]);
		return false;
	}
	
	// Email Invalid
	if ((typeof(email) != 'undefined') && (emailReq) && (!ValidateEmail(email.value)))
	{
		email.focus();
		alert(_messages["EmailInvalid"]);
		return false;
	}

	// Login Code Not Blank
	if ((typeof(login) != 'undefined') && (loginReq) && (objStringUtils.strTrim(login.value) == ""))
	{
		login.focus();
		alert(_messages["LoginBlank"]);
		return false;
	}

	// Password1 Blank
	if ((typeof(password1) != 'undefined') && (passwordReq) && (objStringUtils.strTrim(password1.value) == ""))
	{
		password1.focus();
		alert(_messages["PasswordBlank"]);
		return false;
	}

	// Password1 Min length
	if ( (typeof(password1) != 'undefined') && (passwordReq || password1.value != "") && ( parseInt(passwordLength) > (objStringUtils.strTrim(password1.value)).length ) ) 
	{	
		password1.focus();		
		alert(_messages["PasswordLength"].replace(/\{0\}/g, passwordLength));
		return false;
	}


	// Password Confirmation
	if ((typeof(password2) != 'undefined') && (passwordReq) && (objStringUtils.strTrim(password1.value) != objStringUtils.strTrim(password2.value)))
	{
		password2.focus();
		alert(_messages["PasswordUnConfirmed"]);
		return false;
	}

	// Salutation Selected
	if ((typeof(salutation) != 'undefined') && (salutationReq) && (salutation.options.selectedIndex == 0))
	{
		salutation.focus();
		alert(_messages["SalutationUnSelected"]);
    	return false;
	}

	// First Name Blank
	if ((typeof(firstName) != 'undefined') && (firstNameReq) && (objStringUtils.strTrim(firstName.value) == ""))
	{
		firstName.focus();
		alert(_messages["FirstNameBlank"]);
		return false;
	}

	// Middle Name Blank
	if ((typeof(middleName) != 'undefined') && (middleNameReq) && (objStringUtils.strTrim(middleName.value) == ""))
	{
			middleName.focus();
			alert(_messages["MiddleNameBlank"]);
			return false;
	}

	// Last Name Blank
	if ((typeof(lastName) != 'undefined') && (lastNameReq) && (objStringUtils.strTrim(lastName.value) == ""))
	{
			lastName.focus();
			alert(_messages["LastNameBlank"]);
			return false;
	}
	// Date of birth day blank
	if  ((typeof(dobDay) != 'undefined') && (dobReq) && (objStringUtils.strTrim(dobDay.value) == ""))
	{
			dobDay.focus();
			alert(_messages["DateOfBirthBlank"]);
			return false;
	}
	
	// Date of birth month blank
	if  ((typeof(dobMonth) != 'undefined') && (dobReq) && (objStringUtils.strTrim(dobMonth.value) == ""))
	{
			dobMonth.focus();
			alert(_messages["DateOfBirthBlank"]);
			return false;
	}
	
	// Date of birth year blank
	if  ((typeof(dobYear) != 'undefined') && (dobReq) && (objStringUtils.strTrim(dobYear.value) == ""))
	{
			dobYear.focus();
			alert(_messages["DateOfBirthBlank"]);
			return false;
	}
	
	// Date of birth valid
	if  ((typeof(dobYear) != 'undefined') && (typeof(dobMonth) != 'undefined') && 
	  (typeof(dobYear) != 'undefined'))
	{
		dobYear.value = objStringUtils.strTrim(dobYear.value);
		dobMonth.value = objStringUtils.strTrim(dobMonth.value);
		dobDay.value = objStringUtils.strTrim(dobDay.value);
		
		if (dobYear.value.length > 0 || dobMonth.value.length > 0 || dobDay.value.length > 0)
		{	
			var invalid = false;
			
			if (IsNumeric(dobYear) && IsNumeric(dobMonth) && IsNumeric(dobDay))
			{
				var day = dobDay.value[0] == '0' ? dobDay.value.substring(1) : dobDay.value;
				var month = dobMonth.value[0] == '0' ? dobMonth.value.substring(1) : dobMonth.value;
				var year = dobYear.value;
				
				if (objStringUtils.blnIsDate(year, month, day)) 
				{//months: 0 - 11
					var dobDate = new Date(year, month - 1, day);
					//not future birth?
					if (objStringUtils.CompareDates(dobDate, new Date()) < 0)
					{
						// >= 1900
						if (objStringUtils.CompareDates(dobDate, new Date(1900, 0, 1)) >= 0)
						{
							//OK
						}
						else
						{
							invalid = true;
						}
					}
					else
					{
						invalid = true;
					}
				}
				else
				{
					invalid = true;
				}
			}
			else
			{
				invalid = true;
			}
			if (invalid)
			{
				dobDay.focus();
				alert(_messages["DateOfBirthInvalid"]);
				return false;
			}
		}
	}


	// Validate home phone.
	if ( !IsValidNumber(homePhoneCC, homeCCodeReq, "PhoneCountryCodeBlank", "HomePhoneNonNumeric" ))
			return false;

	if ( !IsValidNumber(homePhoneAC, homeACodeReq, "PhoneAreaCodeBlank", "HomePhoneNonNumeric" ))
			return false;

	if ( !IsValidNumber(homePhoneNo, homeReq, "HomePhoneBlank", "HomePhoneNonNumeric" ))
			return false;


	// Validate mobile phone	
	if ( !IsValidNumber(mobilePhoneCC, mobCCodeReq, "PhoneCountryCodeBlank", "MobilePhoneNonNumeric" ))
			return false;		

	if ( !IsValidNumber(mobilePhoneNo, mobReq, "MobilePhoneBlank", "MobilePhoneNonNumeric" ))
			return false;			


	// Validate Phone Other.	
	if ( !IsValidNumber(otherPhoneCC, otherCCodeReq, "PhoneCountryCodeBlank", "OtherPhoneNonNumeric" ))
			return false;
	
	if ( !IsValidNumber(otherPhoneAC, otherACodeReq, "PhoneAreaCodeBlank", "OtherPhoneNonNumeric" ))
			return false;
	
	if ( !IsValidNumber(otherPhoneNo, otherReq, "OtherPhoneBlank", "OtherPhoneNonNumeric" ))
			return false;
			
	return true;
}	
	
function ValidateAccountCheckBox(thisForm, idToValidate)
{
	return true;
}

function ValidateAccountRadioButtons(thisForm, idToValidate)
{
	return true;
}

function ValidateAccountUserPrefs(thisForm, idToValidate)
{
	return true;
}

function ValidateEmail(emailAddress)
{
	var regex = new RegExp(RegExp.EmailPattern);
	return regex.test(emailAddress);
}

function ValidateCharSet(obj)
{
	var regex = new RegExp(RegExp.ValidCharSetPattern);		
	
	if (obj != null && obj != '')
	{		
		if (!regex.test(obj.value))
		{
			obj.focus();
			alert(_messages['InvalidCharSet']);
			return false;
		}
		
	}
	
	if ( !ForbiddenCharsCheck(obj) )
		return false;

	return true;
}

function ForbiddenCharsCheck(obj)
{
	var regex = new RegExp(RegExp.ForbiddenCharsPattern);		

	if (obj != null && obj != '')
	{		
		if (regex.test(obj.value))
		{
			obj.focus();
			alert(_messages['ForbiddenChars']);	

			return false;
		}		
	}
	return true;
}


function ValidatePhone(CC, AC, N, phoneCCVisible, phoneACVisible)
{	
	var number = "";
	var objStringUtils = new CSoftixUtils;	

	if ((typeof(CC) != 'undefined') && (typeof(CC.value) != 'undefined') && (phoneCCVisible))
	{	
		CC.value = objStringUtils.CCStripSpaces(CC.value);
		number += CC.value;
	}

	if ((typeof(AC) != 'undefined') && (typeof(AC.value) != 'undefined') && (phoneACVisible))
	{
		AC.value = objStringUtils.CCStripSpaces(AC.value);
		number += AC.value;
	}

	if (typeof(N.value) != 'undefined')
	{
		N.value = objStringUtils.CCStripSpaces(N.value);
		number += N.value;
	}
	
    var numberReg = "^[0-9]*$";
    var regex = new RegExp(numberReg);

    return regex.test(number);
}

/*
ShowTickets.aspx Page 
*/

function ChangePriceCategory(thisForm, uniqueId, iNewIndex, dtypeControlId) 
{
	var objPulldown
	for (var i=1; i<=_ptypeCount; i++) {
		eval("objPulldown = " + thisForm + "['" + uniqueId + ":uiPType" + i + "'];")
		if (objPulldown != null) 
			objPulldown.options.selectedIndex = iNewIndex
	}

	RestrictDeliveryTypes(thisForm, uniqueId, dtypeControlId);
}


// Validates that a ticket selection has been made and that it is within the defined
// limites - up to 4 ptypes and less than pcat's max tickets.
function TicketSelectorValid(thisForm, uniqueId)
{
	var isValid = true;
	// Determine the current price category and pass to Tickets object.
	for (var i=1; i<=_ptypeCount; i++) 
	{
		eval("var objPtype = " + thisForm + "['" + uniqueId + ":uiPType" + i + "'];");
		if (typeof(objPtype) != 'undefined')
			break;
	}
		
	
	var maxTickets;
	var area;	
	var type;

	if (_areas.length == 1)
	{
		type = _areas[0][1];
		area = _areas[0][0];	// Not a pulldown as only 1 pcat
		maxTickets = _areasMaxTickets[0];
	}
	else
	{
		var index = objPtype.options.selectedIndex ;
		
		if (index > 0)
		{
			type = _areas[index-1][1];
			area = _areas[index-1][0]; //Is a pulldown
			maxTickets = _areasMaxTickets[index-1];
		}
		else
		{	
			type = 'Category';
			area = 0;	//Best available option
			maxTickets = _areasMaxTickets[0]; //For best avail use the first pcat max
		}
	}
		
	var tickets = new Tickets(type, area, maxTickets);

	
	
	// Scan through each ptype pulldown and add ticket selections.
	for (var i=1; i<=_ptypeCount; i++) 
	{
		eval("var objTickets = " + thisForm + "['" + uniqueId + ":notickets" + i + "'];");
		
		if ((typeof(objTickets) != 'undefined'))
		{
			var number = parseInt(objTickets.options[objTickets.options.selectedIndex].value);
			if (number > 0)
			{
				eval("var objPtype = " + thisForm + "['" + uniqueId + ":uiPType" + i + "'];")
				
				var ptype;
				if (_areas.length > 1)
					ptype = objPtype.options[objPtype.options.selectedIndex].value;
				else
					ptype = objPtype.value;

				// Chck that ptype can be selected.
				if (ptype != "")
				{
					if (ptype == "na")
					{
						isValid = false;
						alert(_messages["PcatNotAvail"]);				
					}
					if (!tickets.Add(ptype, number))
					{
						isValid = false;
						break;
					}
				}
				else
				{
					alert(_messages["PcatNotAvail"]);
					isValid = false;
					break;
					objPtype.focus();
				}
			}
		}
	}
	if (isValid)
	{
		var selection = tickets.ToString();
		if (selection == "") 
		{
			alert(_messages["NoTickets"]);
			isValid = false;
		}
		else
			{
				eval("var objType = " + thisForm + "['" + uniqueId + ":type']");
				eval("var objArea = " + thisForm + "['" + uniqueId + ":area']");
				eval("var objSelection = " + thisForm + "['" + uniqueId + ":selection']"); 
				objType.value = tickets.Type;
				objSelection.value = selection;
				objArea .value = tickets.Area;
			}

	}
	
	return isValid;
	
}


function DeliveryMethodValid(thisForm, uniqueId)
{
	var isValid = true;
	
	// Check delivery optios selected.
	var objDelivery = objField(thisForm, uniqueId, ":deliverymethod");
	if (!IsRadioSelected(objDelivery))
	{
		alert(_messages["NoDelivery"]);
		isValid = false;
	}
	return isValid;
}

// Check if a group of radio buttons has a choice selected.
function IsRadioSelected(objRadios)
{
	if (typeof(objRadios.length) != 'undefined')
	{
		for (var i=0; i<objRadios.length; i++)
		{
			if (objRadios[i].checked)
				return true;
		}
		return false;
	}
	else
		return objRadios.checked;
}

// This object captures users ticket selection. checks it is within limits (Add()) and 
// formats valid selection into single string (ToString()).
function Tickets(type, area, maxTickets)
{
	this.Type = type;
	this.Area = area;
	this.MaxTickets = maxTickets;
	this.Selection = new Array();
	this.Count = 0;					// Current ticket count.
	
	this.Add = TicketsAdd;
	this.ToString = TicketsToString;
}

	function TicketsAdd(ptype, number)
	{
		if (this.MaxTickets >= this.Count + number)
		{
			this.Count += number;
			var length = this.Selection.length;
			if (length < 4)	// Max number of price types allowable.
			{
				this.Selection[length] = ptype + number;
				//alert('add ' + ptype + number)
				return true
			}
			else
			{
				// Alert max ptypes.
				alert(_messages["MaxPTypes"]);
			}
		}
		else
		{
			// Alert max tickets for price category. (replaces {0} with max tickets)
			alert(_messages["MaxTickets"].replace(/\{0\}/g, this.MaxTickets));
		}

		return false;
	}

	function TicketsToString()
	{
		var length = this.Selection.length;
		var buffer = "";
		for (var i=0; i<length; i++)
		{
			buffer = (i==0) ? this.Selection[i] : buffer + "," + this.Selection[i];
		}
		return buffer;
	}

/*
	This functions ensures that all the restricted delivery types for a 
	particular price type updated 
*/
						
function RestrictDeliveryTypes(thisForm, uniqueId, dtypeControlId)
{
	// validate that the delivery type restrions exists
	if (typeof(_dtypeRestrictions) != 'undefined' && _dtypeRestrictions.length != 0)
	{
		EnableDeliveryTypes(thisForm, dtypeControlId);
		
		// Determine the current price category and pass to Tickets object.
		for (var i = 1; i <= _ptypeCount; i++) 
		{
			eval("var objPtype = " + thisForm + "['" + uniqueId + ":uiPType" + i + "'];");
			
			if (typeof(objPtype) != 'undefined')
			{
				eval("var objTickets = " + thisForm + "['" + uniqueId + ":notickets" + i + "'];");
				
				if (typeof(objTickets) != 'undefined')
				{
					var ticketsNum = objTickets.options[objTickets.options.selectedIndex].value;
					
					var ptype = null;
					
					// disable restricted delivery types only if the number of tickets selected is > 0
					if (ticketsNum > 0)
					{
						if (objPtype.length > 1)
							ptype = objPtype.options[objPtype.options.selectedIndex].value;
						else
							ptype = objPtype.value;
							
						DisableDeliveryTypes(thisForm, dtypeControlId, ptype);
					}
				} 
			}
		}
	}
}

/* 
	This functions will iterate through all available delivery methods in the current form
	and re-enable them all.
*/
function EnableDeliveryTypes(thisForm, uniqueId)
{
	// retrieve delivery method radio collection object
	var objDelivery = objField(thisForm, uniqueId, ":deliverymethod");

	// validate that the object is defined in the form
	if (typeof(objDelivery) != 'undefined')
	{
		if (objDelivery.length > 1)
		{
			// loop through available selections and enable them 
			for (var i = 0; i < objDelivery.length; i++)
			{
				objDelivery[i].disabled = false;
			}	
		}
		else
		{
			objDelivery.disabled = false;
		}
	}
}

/* 
	This functions will iterate through all available delivery methods in the current form
	and re-enable them all.
*/
function DisableDeliveryTypes(thisForm, uniqueId, ptype)
{
	// Check delivery optios selected.
	eval("var objDelivery = " + thisForm + "['" + uniqueId + ":deliverymethod']");

	// validate that the delivery object is defined
	if (typeof(objDelivery) != 'undefined')
	{
		// loop through restricted prices and disable only for the requested price type
		for (var i = 0; i < _dtypeRestrictions.length; i++)
		{
			if (_dtypeRestrictions[i][0] == ptype)
			{
				for (var k = 0; k < _dtypeRestrictions[i][1].length; k++)
				{
					if (objDelivery.length > 1)
					{
						for (var j = 0; j < objDelivery.length; j++)
						{
							if (objDelivery[j].value == _dtypeRestrictions[i][1].charAt(k))
							{
								objDelivery[j].checked = false;
								objDelivery[j].disabled = true;
								break;
							}
						}
					}
					else
					{
						if (objDelivery.value == _dtypeRestrictions[i][1].charAt(k))
						{
							objDelivery.checked = false;
							objDelivery.disabled = true;
						}
					}					
				}
				
				break;				
			}
		}
	}
}

/* 
	This functions will validate that the delivery method is not disabled prior to selecting it.
	Primarily used for the onclick on the delivery method name.
	
*/
function SelectDeliveryMethod(thisForm, uniqueId, dtypePos)
{
	// Check delivery optios disabled or not before allowing the selection of it
	var objDelivery = objField(thisForm, uniqueId, dtypePos);

	if (typeof(objDelivery) != 'undefined' && !objDelivery.disabled)
		objDelivery.checked = true;
}

/*
This function (called only when hold control is displayed) asks user
to agree to losing hold information when clicking back button - if they
have entered any
*/
function showTicketsBackButtonClick(thisForm, holdQtyID, backUrl)
{
 var objHoldQtyControl = objField(thisForm, holdQtyID, "");
 if (typeof(objHoldQtyControl) != 'undefined') 
 {
     if (objHoldQtyControl.selectedIndex > 0)
     {
         if (window.confirm(_messages["ShowTicketsConfirmLoseHoldInfo"]))
         {
             document.location.href = backUrl;
         }
     }
     else
     {
         document.location.href = backUrl;
     }
 }
 else
 {
     document.location.href = backUrl;
 }
 return false;
}

/* Performance Selector Control */

function CanChangeVenue(thisForm, venuename)
{
	var uiDropdown = objField(thisForm, venuename, "");

	if (uiDropdown.options[uiDropdown.options.selectedIndex].value == '') 
	{
		alert(_messages["VenueSoldout"]);
		for (var i=0; i < uiDropdown.options.length; i++)
		{
			if (uiDropdown.options[i].value == _currentVenue)
					uiDropdown.options.selectedIndex = i;
		}
		return false;
	}

	return true;
}

function CanChangePerformance(thisForm, name)
{
	var uiDropdown = objField(thisForm, name, "");
	if (uiDropdown.options[uiDropdown.options.selectedIndex].value == '') {
		alert(_messages["PerformanceSoldout"]);
		for (var i=0; i < uiDropdown.options.length; i++)
			if (uiDropdown.options[i].value == _currentPerf)
					uiDropdown.options.selectedIndex = i;
		return false;
	}
	return true;
		
}				

function BuyNow(thisForm, ticketSelectUrl) 
{
	location.href = ticketSelectUrl;
}	

/*
*	BASKET RELATED FUNCTIONS
*/
var gblnProcessing = false;
var gobjBasketPurchasingWindow;

// VerifyPurchase.ascx - form validation.
function blnBasketOffersValidate(thisForm, idToValidate)
{
	var objRef;	

	if (gblnProcessing) 
	{
		alert(_messages["PurchaseAlreadyClicked"]);
		return false;
	}

	objStringUtils = new CSoftixUtils;
	objRef = objField(thisForm, idToValidate, ":chkObstr");

	if (objRef != null && !objRef.checked) {
		objRef.focus();
		alert(_messages["BasketObstructedView"]);
		return false;
	}

	return true;
}

function blnRemoveOffer(dibsid, thisForm, fieldName)
{
	if (confirm(_messages["PurchaseRemoveOffer"]))
	{
		var removeOffer = objField(thisForm, fieldName, "");
		removeOffer.value = dibsid;
		return true;
	}

	return false;
}

function AutoReducedAlert(dibsid, thisForm, fieldName, performance, venue, perfDate, tickets)
{
	var message = _messages["AutoReducedTicketsConfirm"];
	var detail = "\n\n";
	if (tickets.length != 'undefined')
	{
		for(i=0; i<tickets.length; i++)
		{
			detail += "\t" + tickets[i] + "\n";
		}
	}
	detail += "\n\t" + performance + "\n\t" + perfDate + "\n\t" + venue + "\n\n";
	if (window.confirm(message.replace(/\{0\}/g, detail)))
	{
		return false;
	} else {
		var removeOffer = objField(thisForm, fieldName, "");
		removeOffer.value = dibsid;
		return true;
	}
}

// CreditCardDetails.ascx - form validation.
function blnCreditCardDetailsValidate(thisForm, idToValidate)
{
	if (gblnProcessing) 
	{
		alert(_messages["PurchaseAlreadyClicked"]);
		return false;
	}

	objStringUtils = new CSoftixUtils;

	objradCCTypeRef = eval(thisForm + "['" + idToValidate + ":radCCType']");
	objtxtCCNumberRef = eval(thisForm + "['" + idToValidate + ":txtCCNumber']");
	objtxtCCCvcRef = eval(thisForm + "['" + idToValidate + ":txtCCCvc']");
	objtxtCCNameRef = eval(thisForm + "['" + idToValidate + ":txtCCName']");
	objselCCExpiryMonthRef = eval(thisForm + "['" + idToValidate + ":selCCExpiryMonth']");
	objselCCExpiryYearRef = eval(thisForm + "['" + idToValidate + ":selCCExpiryYear']");
	objhdnMonthRef = eval(thisForm + "['" + idToValidate + ":hdnMonth']");
	objhdnYearRef = eval(thisForm + "['" + idToValidate + ":hdnYear']");
	
	//Unicode Validation
	if (!ValidateCharSet(objtxtCCNumberRef)) return false;
	if (!ValidateCharSet(objtxtCCCvcRef)) return false;
	if (!ValidateCharSet(objtxtCCNameRef)) return false;
	if (!ValidateCharSet(objselCCExpiryMonthRef)) return false;
	if (!ValidateCharSet(objselCCExpiryYearRef)) return false;

	// Validate that the CC Type is selected
	// Validate the credit card type was selected
	if (!IsRadioSelected(objradCCTypeRef))
	{
		objradCCTypeRef[0].focus();
		alert(_messages["CreditCardType"]);
		return false;
	}

	
	// Validate CC Details if not a 0 value trans
	// Validate the credit card type
	if (!IsValidCreditCardType(objradCCTypeRef, objtxtCCNumberRef.value))
		return false;

	if (objtxtCCNumberRef.value == '')
	{					
		objtxtCCNumberRef.focus();
		alert(_messages["CreditCardNumber"]);
		return false;
	}
		
	objtxtCCNumberRef.value = objStringUtils.CCStripSpaces(objtxtCCNumberRef.value)
															
	if (!objStringUtils.CCMod10Check(objtxtCCNumberRef.value))
	{
		objtxtCCNumberRef.focus();
		alert(_messages["CreditCardNumberInvalid"]);

		return false;
	}

	if (objtxtCCCvcRef != null)
		{
			if (objtxtCCCvcRef.value == '')
			{					
				objtxtCCCvcRef.focus();
				alert(_messages["CreditCardCvc"]);
				return false;
			}
						
			objtxtCCCvcRef.value = objStringUtils.CCStripSpaces(objtxtCCCvcRef.value);
		
			var regex = new RegExp("^[0-9]{3,4}$");    									
			if (!regex.test(objtxtCCCvcRef.value))
			{
				objtxtCCCvcRef.focus();
				alert(_messages["CreditCardCvcInvalid"]);
	
				return false;
			}
		}

												
	if (objtxtCCNameRef.value == '')
	{
		objtxtCCNameRef.focus();
		alert(_messages["CreditCardName"]);
		return false;
	}

	strSelectedMonth = objselCCExpiryMonthRef.options[objselCCExpiryMonthRef.options.selectedIndex].value;
	strSelectedYear = objselCCExpiryYearRef.options[objselCCExpiryYearRef.options.selectedIndex].value;
		
							
	if (strSelectedMonth == '')
	{
		objselCCExpiryMonthRef.focus();
		alert(_messages["CreditCardMonth"]);
		return false;
	}
		
	if (strSelectedYear == '')
	{
		objselCCExpiryYearRef.focus();
		alert(_messages["CreditCardYear"]);

		return false;
	}
						
	strPassedMonth = objhdnMonthRef.value;
	strPassedYear = objhdnYearRef.value;

	if ((parseInt(strSelectedYear, 10) <= parseInt(strPassedYear, 10) - 2000) && parseInt(strSelectedMonth, 10) < parseInt(strPassedMonth, 10))
	{
		alert(_messages["CreditCardExpiryDate"]);
		return false;
	}		
	
	return true;
}

// VerifyShowAttributes.ascx - form validation.
function blnVerifyShowAttributesValidate(thisForm, idsToValidate)
{	
	if (gblnProcessing) 
	{
		alert(_messages["PurchaseAlreadyClicked"]);
		return false;
	}

	// Iterate through all the show attribute checkboxes on the page,
	// subtracting 1 from the pass array length to take into account irrelevant last item.
	for (var i = 0; i < idsToValidate.length - 1; i++)
	{
		var objRef;
		objStringUtils = new CSoftixUtils;

		objRef = objField(thisForm, idsToValidate[i], "");

		if (!objRef.checked) {
			objRef.focus();
			alert(_messages["ShowConditionAgreed"]);
			return false;
		}
	}

	return true;	
}

// VerifyPurchase.ascx - form validation.
function blnAgreeToPurchaseValidate(thisForm, idToValidate)
{
	var objRef;

	if (gblnProcessing) 
	{
		alert(_messages["PurchaseAlreadyClicked"]);
		return false;
	}

	objStringUtils = new CSoftixUtils;
	objRef = eval(thisForm + "['" + idToValidate + ":agreed']");

	if (!objRef.checked) {
		objRef.focus();
		alert(_messages["PurchaseAgreed"]);
		return false;
	}

	gblnProcessing = true;
	gobjBasketPurchasingWindow = OpenWindow("PurchasePopup.aspx", 600, 200);

	return true;
}

function PopUpWindow(strURL, intWidth, intHeight, strName)
{
	OpenWindow(strURL, intWidth, intHeight, 'windowPopup');
}	

function OpenWindow(strURL, intWidth, intHeight, strName)
{
	var newWindows = null;
	strName =  strName || 'popWindow';	//Trick to replace deault to popwindow if strName is not supplied

	if (screen == null)
	{
		if (document.all || document.getElementById)
		{
		newWindows = window.open(strURL, strName,
			            "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=" + intWidth + ",height=" + intHeight);		
		}
		else
		{
		// NN4	
		newWindows = window.open(strURL, strName,
			            "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=" + intWidth + ",height=" + intHeight);
		}
	}
	else	//Position in centre of screen if possible
	{
		if (document.all || document.getElementById)
		{
		newWindows = window.open(strURL, strName,
			            "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=" + intWidth + ",height=" + intHeight + ',left=' + (screen.width-intWidth)/2 + ',top=' + (screen.height-intHeight)/2);
		}
		else
		{
		// NN4
		newWindows = window.open(strURL, strName,
			            "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=" + intWidth + ",height=" + intHeight + ',left=' + (screen.width-intWidth)/2 + ',top=' + (screen.height-intHeight)/2);
		}
	}

	newWindows.focus();
	
	return newWindows;
}

function CloseWindow()
{
	if (gobjBasketPurchasingWindow)
	gobjBasketPurchasingWindow.close();
}

/*

Centralised user alert messages. This needs to be externalised and made multilingual.

*/
var _messages = new Messages();


/*

AccountAddressDetails User Control

*/

function AddressAsAbove(thisForm, uniqueId)
{
	var objCheckbox = objField(thisForm, uniqueId, ":asabove");

	var objLine1 = objField(thisForm, uniqueId, ":line1");
	var objLine2 = objField(thisForm, uniqueId, ":line2");
	var objHouse = objField(thisForm, uniqueId, ":house");  //only for nl control
	var objApmt = objField(thisForm, uniqueId, ":apmt");	//only for nl control
	var objCity = objField(thisForm, uniqueId, ":city");
	var objState = objField(thisForm, uniqueId, ":state");
	var objCountry = objField(thisForm, uniqueId, ":country");
	var objPostCode = objField(thisForm, uniqueId, ":postcode");
	// IsNaN to check that the disabled property is supported	
	if (typeof(objCheckbox.disabled) != 'undefined')
	{
		var disableField = false;
		if (objCheckbox.checked) disableField = true;

		if (typeof(objLine1) != 'undefined') objLine1.disabled = disableField;
		if (typeof(objLine2) != 'undefined') objLine2.disabled = disableField;
		if (typeof(objHouse) != 'undefined') objHouse.disabled = disableField;
		if (typeof(objApmt) != 'undefined') objApmt.disabled = disableField;
		if (typeof(objCity) != 'undefined') objCity.disabled = disableField;
		if (typeof(objState) != 'undefined') objState.disabled = disableField;
		if (typeof(objCountry) != 'undefined') objCountry.disabled = disableField;
		if (typeof(objPostCode) != 'undefined') objPostCode.disabled = disableField;
	}
}

function ErrorMessageWithPrefix(contentIdPrefix, contentId)
{	
	if (contentIdPrefix.length != 0 && _messages[contentIdPrefix + contentId] != null)
		return _messages[contentIdPrefix + contentId];
	else
		return _messages[contentId];
}

function ErrorMessageWithPrefix(contentIdPrefix, contentId)
{	
	if (contentIdPrefix.length != 0 && _messages[contentIdPrefix + contentId] != null)
		return _messages[contentIdPrefix + contentId];
	else
		return _messages[contentId];
}


// Address user control field validation function.
function ValidateAddress(thisForm, uniqueId, line1Req, line2Req, cityReq, stateReq, countryReq, postCodeReq, contentIdPrefix)
{	
	var isValid = true;
	var objCheckbox = objField(thisForm, uniqueId, ":asabove");
	if ((typeof(objCheckbox) != 'undefined' && !objCheckbox.checked) || typeof(objCheckbox) == 'undefined')
	{
		var objLine1 = objField(thisForm, uniqueId, ":line1");
		var objLine2 = objField(thisForm, uniqueId, ":line2");
		var objCity = objField(thisForm, uniqueId, ":city");
		var objState = objField(thisForm, uniqueId, ":state");
		var objStateSelect = objField(thisForm, uniqueId, ":stateSelect");
		var objCountry = objField(thisForm, uniqueId, ":country");
		var objCountryOther = objField(thisForm, uniqueId, ":countryother");
		var objPostCode = objField(thisForm, uniqueId, ":postcode");
		
		// Unicode validation
		if (!ValidateCharSet(objLine1)) return false;
		if (!ValidateCharSet(objLine2)) return false;
		if (!ValidateCharSet(objCity)) return false;
		if (!ValidateCharSet(objState)) return false;
		if (!ValidateCharSet(objCountry)) return false;
		if (!ValidateCharSet(objCountryOther)) return false;
		if (!ValidateCharSet(objPostCode)) return false;
				
		if (typeof(objLine1) != 'undefined' && line1Req && objLine1.value == "")
		{
			alert(ErrorMessageWithPrefix(contentIdPrefix, "AddressLine1Error"));
			objLine1.focus();
			return false;
		}

		if (typeof(objLine2) != 'undefined' && line2Req && objLine2.value == "")
		{
			alert(ErrorMessageWithPrefix(contentIdPrefix, "AddressLine2Error"));
			objLine2.focus();
			return false;
		}

		if (typeof(objCity) != 'undefined' && cityReq && objCity.value == "")
		{
			alert(ErrorMessageWithPrefix(contentIdPrefix, "AddressCityError"));
			objCity.focus();
			return false;
		}

		if (typeof(objState) != 'undefined' && objState.style.display != 'none' && stateReq && objState.value == "")
		{
			alert(ErrorMessageWithPrefix(contentIdPrefix, "AddressStateError"));
			objState.focus();	
			return false;
		}
	
		if (typeof(objStateSelect) != 'undefined' && objStateSelect.style.display != 'none' && stateReq && objStateSelect.value == "")
		{
			alert(ErrorMessageWithPrefix(contentIdPrefix, "AddressStateError"));
			objStateSelect.focus();
			return false;
		}


		if (typeof(objCountry) != 'undefined')
		{
			var countryValue = objCountry.options[objCountry.selectedIndex].value;

			if (countryReq && countryValue == 'other' && objCountryOther.value == "")
			{
				alert(ErrorMessageWithPrefix(contentIdPrefix, "AddressCountryError"));
				objCountryOther.focus();
				return false;
			}
		}
		
		if (typeof(objPostCode) != 'undefined' && postCodeReq && objPostCode.value == "")
		{
			alert(ErrorMessageWithPrefix(contentIdPrefix, "AddressPostCodeError"));
			objPostCode.focus();
			return false;
		}
	}
	return true;
}

// Address user control field validation function.
function ValidateAddress_nl(thisForm, uniqueId, line1Req, apmtReq, houseReq, cityReq, stateReq, countryReq, postCodeReq)
{
	var isValid = true;
	
	var objCheckbox = objField(thisForm, uniqueId, ":asabove");
	if ((typeof(objCheckbox) != 'undefined' && !objCheckbox.checked) || typeof(objCheckbox) == 'undefined')
	{
		var objLine1 = objField(thisForm, uniqueId, ":line1");
		var objHouse = objField(thisForm, uniqueId, ":house");
		var objApmt = objField(thisForm, uniqueId, ":apmt");
		var objCity = objField(thisForm, uniqueId, ":city");
		var objState = objField(thisForm, uniqueId, ":state");
		var objCountry = objField(thisForm, uniqueId, ":country");
		var objCountryOther = objField(thisForm, uniqueId, ":countryother");
		var objPostCode = objField(thisForm, uniqueId, ":postcode");

		// Unicode validation
		if (!ValidateCharSet(objLine1)) return false;
		if (!ValidateCharSet(objHouse)) return false;
		if (!ValidateCharSet(objApmt)) return false;
		if (!ValidateCharSet(objCity)) return false;
		if (!ValidateCharSet(objState)) return false;
		if (!ValidateCharSet(objCountry)) return false;
		if (!ValidateCharSet(objCountryOther)) return false;
		if (!ValidateCharSet(objPostCode)) return false;

		if (typeof(objLine1) != 'undefined' && line1Req && objLine1.value == "")
		{
			alert(_messages["AddressLine1Error"]);
			objLine1.focus();
			return false;
		}

		if (typeof(objHouse) != 'undefined' && houseReq && objHouse.value == "")
		{
			alert(_messages["AddressHouseError"]);
			objHouse.focus();
			return false;
		}

		if (typeof(objApmt) != 'undefined' && apmtReq && objApmt.value == "")
		{
			alert(_messages["AddressApartmentError"]);
			objApmt.focus();
			return false;
		}

		if (typeof(objCity) != 'undefined' && cityReq && objCity.value == "")
		{
			alert(_messages["AddressCityError"]);
			objCity.focus();
			return false;
		}

		if (typeof(objState) != 'undefined' && stateReq && objState.value == "")
		{
			alert(_messages["AddressStateError"]);
			objState.focus();
			return false;
		}

		if (typeof(objCountry) != 'undefined')
		{
			var countryValue = objCountry.options[objCountry.selectedIndex].value;
			
			if (countryReq && countryValue == 'other' && objCountryOther.value == "")
			{
				alert(_messages["AddressCountryError"]);
				objCountryOther.focus();
				return false;
			}
		}
		
		if (typeof(objPostCode) != 'undefined' && postCodeReq && objPostCode.value == "")
		{
			alert(_messages["AddressPostCodeError"]);
			objPostCode.focus();
			return false;
		}
	}
	return true;
}

/*

Utility Class

*/

	function CSoftixUtils() {
	
		//Methods
		this.IsMSBrowser = IsMSBrowser;				//Check if the browser is Internet Explorer
		this.strFormatNumber = strFormatNumber;		//Format a number to specified number of places
		this.strFormatDate = strFormatDate;			//Format a date: dd mmm yyyy 
		this.strTrim = strTrim;						//Trim leading and trailing spaces
		this.blnDateIsFuture = blnDateIsFuture;		//Check that a date is not in the past
		this.strStripBlanks = strStripBlanks;		//Strips ALL blanks from a string passed as a parameter
		this.CCStripSpaces = CCStripSpaces;			// Strips spaces and dashes from credit card number.
		this.CCMod10Check = CCMod10Check;			// Perfroms the mod10 check on a credit card number.
		this.CompareDates = CompareDates;			//Compares two dates, returns + if 1 > 2, 0 if 1 = 2, else -
		this.blnIsDate = blnIsDate;					//Checks if three params constitute a date, with optional year offset for use with 2 digit years
	}

		function IsMSBrowser()
		{
			var objAgent = navigator.userAgent.toLowerCase();
			if (objAgent.indexOf("msie") != -1)
				return true;
			else
				return false;
		}
		//Formats a number to the specified decimal places
		function strFormatNumber(strNumber, intPlace) {
			var sngNumber = parseFloat(strNumber)
			var i
			var strBuffer
			
			if (!isNaN(sngNumber)) {
				if (0 != sngNumber) {
					strBuffer = "" + Math.round(sngNumber * (Math.pow(10, intPlace)) );
					if (0 != intPlace) {
						while (strBuffer.length < intPlace) strBuffer = "0" + strBuffer;
						strBuffer = strBuffer.substr(0, strBuffer.length - intPlace) + "." + strBuffer.substr(strBuffer.length - intPlace, intPlace);
					}
					if ("." == strBuffer.substr(0,1)) strBuffer = "0" + strBuffer
				} else {
					strBuffer = "0"
					if (0 != intPlace) {
						strBuffer += "."
						for(i=0; i<intPlace; i++) strBuffer+="0";
					}
				}
			} else {
				strBuffer = "0"
				if (0 != intPlace) {
					strBuffer += "."
					for(i=0; i<intPlace; i++) strBuffer+="0";
				}
			}
			return(strBuffer);
		}

		//Input validation functions
		function strFormatDate(strNewDate) {
			var datDate
			var strMonthsArray = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec".split(",");
			var str2kCorrection;
			
			if (strNewDate.indexOf("/") > 0) 
				strNewDate = strOzDate(strNewDate, "/")
			else if (strNewDate.indexOf("-") > 0) 
				strNewDate = strOzDate(strNewDate, "-")
			else if (strNewDate.indexOf(" ") > 0) 
				strNewDate = strOzDate(strNewDate, " ")
			
			var strDate = Date.parse(strNewDate)

			//If cannot be interpretted as a date then exit with keyword "N.A."
			if (isNaN(strDate)) return "N.A.";
			
			//Convert to internal date format
			datDate = new Date(strDate);
			
			str2kCorrection = datDate.getFullYear();
			//alert (str2kCorrection);
			//if ("1900" == str2kCorrection) str2kCorrection = "2000";
			if (1950 >= str2kCorrection) str2kCorrection = str2kCorrection + 100;
			
			return (datDate.getDate() + " " + strMonthsArray[datDate.getMonth()] + " " + str2kCorrection);
			
		}
		
			function strOzDate(strDate,strSeparator) {
				var strDateArray;
				var intDay;
				var intMonth;
				var intYear;
				
				strDateArray = strDate.split(strSeparator);
				if (strSeparator == " ") strSeparator = "/";
				
				//using / format in date so parse and check
				if (strDateArray.length > 2) {			
					intDay = parseInt(strDateArray[0]);
					intMonth = parseInt(strDateArray[1]);
					intYear = parseInt(strDateArray[2]);
					
					if (!isNaN(intMonth)) {
						if (!(intMonth > 0 && intMonth <= 12)) {
							return;
						} else if (!(intDay > 0 && intDay <= 31)) {
							return;
						}
						return (strDateArray[1] + strSeparator + strDateArray[0] + strSeparator + strDateArray[2]);
					}
				}
				return strDate;	//Return unchanged
			}
			
		function strTrim(strText) {
				
			for (i=0; i<strText.length; ++i) {
				if (strText.charAt(i) != ' ') break;
			}

			//All spaces so exit
			if (i >= strText.length) return ('');
			
			//Left trim spaces
			if (i > 0) strText = strText.substring(i, strText.length);
			
			for (j=strText.length-1; j > i; --j) {
				if (strText.charAt(j) != ' ') break;
			}
			
			if (j < strText.length -1)
				strText = strText.substring(0, j+1);
				
			return strText;
		}
		
		function blnDateIsFuture(datDateToCheck) {
			return (CompareDates(new Date(), new Date(datDateToCheck)) <= 0);			
		}

		function CompareDates(date1, date2) {
			if (date1.getFullYear() < date2.getFullYear())
				return -1;
			if (date1.getFullYear() > date2.getFullYear())
				return 1;
			if (date1.getMonth() < date2.getMonth())
				return -1;
			if (date1.getMonth() > date2.getMonth())
				return 1;
			if (date1.getDate() < date2.getDate())
				return -1;
			if (date1.getDate() > date2.getDate())
				return 1;
			return 0;
		}
		
		function blnIsDate(year, month, day, year2kOffset){
			if (!IsNaturalNumber(year) || !IsNaturalNumber(month) || !IsNaturalNumber(day)) return false;
			if ((''+year).length != 4 && (''+year).length != 2) return false;
			day = (day[0] == '0' ? day.substring(1, day.length) : day);
			month = (month[0] == '0' ? month.substring(1, month.length) : month);
			year = (year.length == 4 ? year : (year < (year2kOffset ? year2kOffset : 50) ? '20' : '19') + year);
			if (day <= 0 || day > 31) return false;
			if (month <= 0 || month > 12) return false;
			//apr,jun,sep,nov have 30 days
			if (day > 30 && (month == 4 || month == 6 || month == 9 || month == 11)) return false;
			//feb has 28, unless leap year - year div by 4 and (not 100 or is by 400) - then 29
			if (month == 2 && day > 28 && !((year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) && day == 29)) return false;
			return true;
		}
		
		function strStripBlanks(strString) {
			var strNewString = "";
			var iIter = 0;
			var jIter = 0;
			var intPosition = 0;
			var strTempString = "";
		
			if (strString.indexOf(" ") > 0) {
				for (iIter=0; iIter<strString.length; iIter++) {
					if (strString.charAt(iIter) == " ") {
						strTempString = strTempString + strString.substring(intPosition,iIter);
					} else {
						strTempString = strTempString + strString.charAt(iIter);
					}
					intPosition = iIter+1;
				}
				strNewString = strTempString;
			} else {
				strNewString = strString;
			}
		
			return strNewString;
		}

		// Strips spaces and dashes
		function CCStripSpaces(strPassedCCNumber)
		{		
			var strBuffer = '';
					
			for(var i = 0; i < strPassedCCNumber.length; i++)
			{
				if (strPassedCCNumber.charAt(i) != ' ' && strPassedCCNumber.charAt(i) != '-')
				{
					strBuffer = strBuffer + strPassedCCNumber.charAt(i);
				}
			} 
									
			return strBuffer;
		}

		// Perfroms the mod10 check on a credit card number.
		function CCMod10Check(strPassedCCNumber)
		{
			var intEvenSum = 0;
			var intOddSum = 0;
			var intTemp = 0;
					
			for(var i = strPassedCCNumber.length - 2; i >= 0; i = i - 2)
			{
				intTemp = parseInt(strPassedCCNumber.charAt(i));
				intTemp = intTemp * 2;
						
				if (intTemp > 9)
				{
					intTemp = intTemp - 9;
				}
				intEvenSum = intEvenSum + intTemp;
			} 
					
			for(var j = strPassedCCNumber.length - 1; j >= 0; j = j - 2)
			{
				intTemp = parseInt(strPassedCCNumber.charAt(j));
				intOddSum = intOddSum + intTemp;
			} 

			if (((intOddSum + intEvenSum) % 10) != 0)
			{
				return false
			}
			else 
			{
				return true
			}
			
		}	
		

/*
    Obtain a reference to the form object
*/
function GetForm(formID)
{
    var objForm = document.forms[formID];
    if (!objForm) eval("objForm = document." + formID);
    return objForm;
}
// Gains scope on a field in a manner that works for all browsers.
function objField(thisForm, uniqueId, fieldSuffix)
{
 eval("var objField=GetForm('" + thisForm + "')['" + uniqueId + fieldSuffix + "'];");
 return objField;
}
		
function ToggleChildCheckBoxes(checkBoxIds)
{
	alert(checkBoxIds);
}

function ValidateContactUs(thisForm, idToValidate, 
	typeReq,
	messageReq,
	emailReq,
	nameReq,
	phoneReq,
	phoneCCVisible,
	phoneACVisible	
	)
{
	var type           = objField(thisForm, idToValidate, ":type");
	var message        = objField(thisForm, idToValidate, ":message");
	var email          = objField(thisForm, idToValidate, ":email");
	var nameSalutation = objField(thisForm, idToValidate, ":nameSalutation");
	var nameFirst      = objField(thisForm, idToValidate, ":nameFirst");
	var nameLast       = objField(thisForm, idToValidate, ":nameLast");
	var phoneCC        = objField(thisForm, idToValidate, ":phoneCC");
	var phoneAC        = objField(thisForm, idToValidate, ":phoneAC");
	var phoneN         = objField(thisForm, idToValidate, ":phoneN");

	//Validate UniCode
	if (!ValidateCharSet(message)) return false;
	if (!ValidateCharSet(email)) return false;
	if (!ValidateCharSet(nameSalutation)) return false;
	if (!ValidateCharSet(nameFirst)) return false;
	if (!ValidateCharSet(nameLast)) return false;
	if (!ValidateCharSet(phoneCC)) return false;
	if (!ValidateCharSet(phoneAC)) return false;
	if (!ValidateCharSet(phoneN)) return false;

	// Type is Blank
	if ((typeof(type) != 'undefined') && (typeReq) && (!IsRadioSelected(type)))
	{
		type[0].focus();
		alert(_messages["TypeBlank"]);
		return false;
	}
	
	
	// Message Blank
	if ((message != 'undefined') && (messageReq) && (message.value == ""))
	{
			message.focus();
			alert(_messages["MessageBlank"]);
			return false;
	}
	
	// Email Not Blank
	if ((typeof(email) != 'undefined') && (emailReq) && (email.value == ""))
	{
		email.focus();
		alert(_messages["EmailBlank"]);
		return false;
	}
	
	// Email Invalid
	if ((typeof(email) != 'undefined') && (emailReq) && (!ValidateEmail(email.value)))
	{
		email.focus();
		alert(_messages["EmailInvalid"]);
		return false;
	}

	// Salutation Selected
	if ((typeof(nameSalutation) != 'undefined') && (nameReq) && (nameSalutation.options.selectedIndex == 0))
	{
		nameSalutation.focus();
		alert(_messages["SalutationUnSelected"]);
    	return false;
	}

	// First Name Blank
	if ((typeof(nameFirst) != 'undefined') && (nameReq) && (nameFirst.value == ""))
	{
		nameFirst.focus();
		alert(_messages["FirstNameBlank"]);
		return false;
	}

	// Last Name Blank
	if ((typeof(nameLast) != 'undefined') && (nameReq) && (nameLast.value == ""))
	{
			nameLast.focus();
			alert(_messages["LastNameBlank"]);
			return false;
	}

	// Phone CC Blank
	if ((typeof(phoneCC) != 'undefined') && (phoneReq) && (phoneCC.value == "") && (phoneCCVisible))
	{
			phoneCC.focus();
			alert(_messages["PhoneCCBlank"]);
			return false;
	}	

	// Phone AC Blank
	if ((typeof(phoneAC) != 'undefined') && (phoneReq) && (phoneAC.value == "") && (phoneACVisible))
	{
			phoneAC.focus();
			alert(_messages["PhoneACBlank"]);
			return false;
	}	

	// Phone N Blank
	if ((typeof(phoneN) != 'undefined') && (phoneReq) && (phoneN.value == ""))
	{
			phoneN.focus();
			alert(_messages["PhoneNBlank"]);
			return false;
	}	
	
	// Phone Not Numeric
	if (((((typeof(phoneCC) != 'undefined') && (phoneCCVisible)) || ((typeof(phoneAC) != 'undefined') && (phoneACVisible)) || (typeof(phoneN) != 'undefined'))) && (phoneReq) && !ValidatePhone(phoneCC, phoneAC, phoneN, phoneCCVisible, phoneACVisible))
	{		
		alert(_messages["PhoneNonNumeric"]);
		return false;
	}

	eval(thisForm + '.submit();');
}

/* Contact Us Details User Control */
// Validates ContactUs detailed form
function ValidateContactUsDetailed(thisForm, 
	idToValidate, 
	performanceReq,
	performanceLocationReq,
	performanceDateReq,
	queryCategoryReq,
	querySubCategoryReq,
	messageReq,
	softixAccountNumReq,
	softixTransactionNumReq,
	nameFirstReq,
	nameLastReq,
	phoneDayReq,
	phoneEveningReq,
	emailReq
	)
{
	// Get form fields back
	var performance				= objField(thisForm, idToValidate, ":performance");
	var performanceLocation		= objField(thisForm, idToValidate, ":performanceLocation");
	var performanceDay			= objField(thisForm, idToValidate, ":performanceDateDD");
	var performanceMonth		= objField(thisForm, idToValidate, ":performanceDateMM");
	var performanceYear			= objField(thisForm, idToValidate, ":performanceDateYY");
	var queryCategory			= objField(thisForm, idToValidate, ":queryCategory");
	var querySubCategory		= objField(thisForm, idToValidate, ":querySubCategory");
	var message					= objField(thisForm, idToValidate, ":message");
	var softixAccountNum		= objField(thisForm, idToValidate, ":softixAccountNum");
	var softixTransactionNum	= objField(thisForm, idToValidate, ":softixTransactionNum");
	var nameFirst				= objField(thisForm, idToValidate, ":nameFirst");
	var nameLast				= objField(thisForm, idToValidate, ":nameLast");
	var phoneDay				= objField(thisForm, idToValidate, ":phoneDay");
	var phoneEvening			= objField(thisForm, idToValidate, ":phoneEvening");
	var email					= objField(thisForm, idToValidate, ":email");
		
	//Validate UniCode
	if (!ValidateCharSet(performance)) return false;
	if (!ValidateCharSet(performanceLocation)) return false;
	if (!ValidateCharSet(performanceDay)) return false;
	if (!ValidateCharSet(performanceMonth)) return false;
	if (!ValidateCharSet(performanceYear)) return false;
	if (!ValidateCharSet(queryCategory)) return false;
	if (!ValidateCharSet(querySubCategory)) return false;
	if (!ValidateCharSet(message)) return false;
	if (!ValidateCharSet(softixAccountNum)) return false;
	if (!ValidateCharSet(softixTransactionNum)) return false;
	if (!ValidateCharSet(nameFirst)) return false;
	if (!ValidateCharSet(nameLast)) return false;
	if (!ValidateCharSet(phoneDay)) return false;
	if (!ValidateCharSet(phoneEvening)) return false;
	if (!ValidateCharSet(email)) return false;

	// Performance Blank
	if ((typeof(performance) != 'undefined') && (performanceReq) && (performance.value == ""))
	{
		performance.focus();
		alert(_messages["ContactUsPerformanceBlank"]);
		return false;
	}
	
	// Performance Location Blank
	if ((typeof(performanceLocation) != 'undefined') && (performanceLocationReq) && (performanceLocation.options.selectedIndex == 0))
	{
		performanceLocation.focus();
		alert(_messages["ContactUsPerformanceLocationBlank"]);
		return false;
	}
	
	// Performance Month Blank
	if ((typeof(performanceMonth) != 'undefined') && (performanceDateReq) && (performanceMonth.options.selectedIndex == 0))
	{
		performanceMonth.focus();
		alert(_messages["ContactUsPerformanceMonthBlank"]);
		return false;
	}

	// Performance Day Blank
	if ((typeof(performanceDay) != 'undefined') && (performanceDateReq) && (performanceDay.options.selectedIndex == 0))
	{
		performanceDay.focus();
		alert(_messages["ContactUsPerformanceDayBlank"]);
		return false;
	}	
	
	// Performance Year Blank
	if ((typeof(performanceYear) != 'undefined') && (performanceDateReq) && (performanceYear.options.selectedIndex == 0))
	{
		performanceYear.focus();
		alert(_messages["ContactUsPerformanceYearBlank"]);
		return false;
	}

	// Performance Date not required but not filled appropriately
	if (((typeof(performanceMonth) != 'undefined') && (typeof(performanceDay) != 'undefined') && (typeof(performanceYear) != 'undefined')) && ((performanceMonth.value != '') || (performanceDay.value != '') || (performanceYear.value != '')))
	{
		if ((performanceMonth.value == '') || (performanceDay.value == '') || (performanceYear.value == ''))
		{
			performanceMonth.focus();
			alert(_messages["ContactUsPerformanceDateBlank"]);
			return false;
		}
	}
	
	// Category Blank
	if ((typeof(queryCategory) != 'undefined') && (queryCategoryReq) && (queryCategory.options.selectedIndex == 0))
	{
		queryCategory.focus();
		alert(_messages["ContactUsQueryCategoryBlank"]);
		return false;
	}	
		
	// Sub-Category Blank
	if ((typeof(querySubCategory) != 'undefined') && (querySubCategoryReq) && (querySubCategory.options.selectedIndex == 0))
	{
		querySubCategory.focus();
		alert(_messages["ContactUsQuerySubCategoryBlank"]);
		return false;
	}		
	
	// Message Blank
	if ((typeof(message) != 'undefined') && (messageReq) && (message.value == ""))
	{
		message.focus();
		alert(_messages["ContactUsMessageBlank"]);
		return false;
	}
	
	// Softix Account Number Blank
	if ((typeof(softixAccountNum) != 'undefined') && (softixAccountNumReq) && (softixAccountNum.value == ""))
	{
		softixAccountNum.focus();
		alert(_messages["ContactUsSoftixAccountNumBlank"]);
		return false;
	}
	
	// Softix Account Number Non Numeric
	if ((typeof(softixAccountNum) != 'undefined') && (softixAccountNum.value != "") && (!IsNumeric(softixAccountNum)))
	{
		softixAccountNum.focus();
		alert(_messages["ContactUsSoftixAccountNumNonNumeric"]);
		return false;
	}
	
	// Softix Transaction Number Blank
	if ((typeof(softixTransactionNum) != 'undefined') && (softixTransactionNumReq) && (softixTransactionNum.value == ""))
	{
		softixTransactionNum.focus();
		alert(_messages["ContactUsSoftixTransactionNumBlank"]);
		return false;
	}
	
	// First Name Blank
	if ((typeof(nameFirst) != 'undefined') && (nameFirstReq) && (nameFirst.value == ""))
	{
		nameFirst.focus();
		alert(_messages["ContactUsFirstNameBlank"]);
		return false;
	}
	
	// Last Name Blank
	if ((typeof(nameLast) != 'undefined') && (nameLastReq) && (nameLast.value == ""))
	{
		nameLast.focus();
		alert(_messages["ContactUsLastNameBlank"]);
		return false;
	}
		
	// Day Phone Blank
	if ((typeof(phoneDay) != 'undefined') && (phoneDayReq) && (phoneDay.value == ""))
	{
		phoneDay.focus();
		alert(_messages["ContactUsPhoneDayBlank"]);
		return false;
	}
	
	// Evening Phone Blank
	if ((typeof(phoneEvening) != 'undefined') && (phoneEveningReq) && (phoneEvening.value == ""))
	{
		phoneEvening.focus();
		alert(_messages["ContactUsPhoneEveningBlank"]);
		return false;
	}
	
	// Email Not Blank
	if ((typeof(email) != 'undefined') && (emailReq) && (email.value == ""))
	{
		email.focus();
		alert(_messages["ContactUsEmailBlank"]);
		return false;
	}
	
	// Email Invalid
	if ((typeof(email) != 'undefined') && (email.value != '') && (!ValidateEmail(email.value)))
	{
		email.focus();
		alert(_messages["ContactUsEmailInvalid"]);
		return false;
	}
	
	eval(thisForm + '.submit();');
}

/* 
IsNumeric function will validate true if the value is numeric (i.e in [0-9]), 
otherwiser it will validate to false as the value contains non numeric characters 
*/
function IsNumeric(formNumber)
{	
	var objStringUtils = new CSoftixUtils;	

	if (typeof(formNumber.value) != 'undefined')
		formNumber.value = objStringUtils.CCStripSpaces(formNumber.value);
    
	return IsNaturalNumber(formNumber.value);
}

function IsNaturalNumber(val)
{					
    var regex = new RegExp("^[0-9]*$");    
    return regex.test(val);
}


// Updates sub category drop down list, based on the category selected
function UpdateSubCategory(thisForm, idToRetrieve, 
	queryCategoryReq,
	querySubCategoryReq,
	queryCategoryValueList,
	querySubCategoryNameList, 
	querySubCategoryValueList	
	)
{	
	// retrieve objects for the drop downs
	var queryCategory		= objField(thisForm, idToRetrieve, ":queryCategory");
	var querySubCategory	= objField(thisForm, idToRetrieve, ":querySubCategory");
	
	if (  (typeof(querySubCategory) != 'undefined') && (typeof(queryCategory) != 'undefined')  ) // && (queryCategoryArrayLength == querySubCategoryArraylength))
	{
		querySubCategory.length = 1;

		// split category value list to retrieve available values for the category drop down	
		var queryCategoryValueArray	= queryCategoryValueList.split("~");
	
		// get the length of the category values array
		var queryCategoryValueArrayLength = queryCategoryValueArray.length;
	
		// split sub category name list to retrieve available sub catgories for each category
		var querySubCategoryNameArray = querySubCategoryNameList.split("^");

		// split sub category valie list to retrieve available sub catgories for each category
		var querySubCategoryValueArray = querySubCategoryValueList.split("^");
		
		// get the lebgth of the category values array
		var querySubCategoryArraylength = querySubCategoryNameArray.length;
		
		if (queryCategory.value != '')
		{	
			var subCategoryNameArray = querySubCategoryNameArray[queryCategory.selectedIndex].split('~');
			var subCategoryValueArray = querySubCategoryValueArray[queryCategory.selectedIndex].split('~');
			for	(var j = 0; j < subCategoryNameArray.length; j++)
			{
				querySubCategory.options[j] = new Option(subCategoryNameArray[j], subCategoryValueArray[j]  );
			}
		}
	}
}


/*
confirm whether a user has agreed to delete his/her account
*/
function ConfirmAccountCancellation(thisForm, 
	idToValidate,
	selectionReq)
{
	if(confirm(_messages["AccountCancelConfirm"]))
	{
		return true;
	}
	
	return false;
}

/*
validates unsubscribe form to ensure that form is filled out
*/
function ValidateAccountUnsubscribe(thisForm, 
	idToValidate,
	loginCodeReq
	)
{
	// Get form fields back
	var loginCode				= objField(thisForm, idToValidate, ":loginCode");
	
	//UniCode Validation
	if (!ValidateCharSet(loginCode)) return false;
			
	// Email Not Blank
	if ((typeof(loginCode) != 'undefined') && (loginCodeReq) && (loginCode.value == ""))
	{
		loginCode.focus();
		alert(_messages["AccountUnsubscribeLoginCodeBlank"]);
		return false;
	}
	
	return true;
}

/*
this function will loop through an array of checkboxes and will validate whether at least one value is selected
*/
function IsCheckBoxSelected(objCheckBoxs)
{
	// check if the array is defined
	if (typeof(objCheckBoxs.length) != 'undefined')
	{
		// loop through the array of check boxes
		for (var i=0; i<objCheckBoxs.length; i++)
		{
			if (objCheckBoxs[i].checked)
				return true;
		}
		return false;
	}
	else
		return objCheckBoxs.checked;
}

/*
Unsubscribe.aspx - user control
this function will validate if user has selected at least one of the account unsubscribe check box options
*/
function ValidateAccountUnsubscribeCheckBox(thisForm, idToValidate)
{
	var isValid = true;
	var checkBoxIndex = 0;
	
	// define the check box values to check
	var checkBoxName = 'uiEmailAccountAttribute';
	
	// checkboxes array	
	var objAccountAttrbuteCheckBox = new Array;
	
	// get all elements on the form
	var objForm = GetForm(thisForm);
	eval("var formElements = objForm.elements");
	
	// loop through all elements on the list and build the check box array
	for (var i = 0; i < formElements.length; i++)
	{
		var formElementId = formElements[i].id;
		
		// check if the form element is a checkbox
		if (formElementId.indexOf(checkBoxName) != -1)
		{
			eval("objAccountAttrbuteCheckBox[" + checkBoxIndex + "] = objForm['" + 
			checkBoxName + checkBoxIndex + ":checkBox']");

			checkBoxIndex += 1;
		}
	}	

	if (!IsCheckBoxSelected(objAccountAttrbuteCheckBox))
	{
		alert(_messages["AccountUnsubscribeCheckBoxBlank"]);
		isValid = false;
	}
	
	return isValid;
}


/*
Unsubscribe.aspx - user control
this function will validate if user has selected at least one of the account unsubscribe radio options
*/
	
function ValidateAccountUnsubscribeRadioButton(thisForm, idToValidate)
{
	var isValid = true;

	// Check account attributes selected
	var objAccountAttrbuteRadioButton = objField(thisForm, idToValidate, ":radioButton");
	
	if (!IsRadioSelected(objAccountAttrbuteRadioButton))
	{
		alert(_messages["AccountUnsubscribeRadioButtonBlank"]);
		isValid = false;
	}
		
	return isValid;
}
	
// Validates phone number fields for PersonalDetails user control
function IsValidNumber( formField, fieldRequired, errMsgBlankField, errMsgNonNumeric  )
{	
	var objStringUtils = new CSoftixUtils;
	var errMsg = "";		

	if (typeof(formField) != 'undefined')
	{
		if (fieldRequired && objStringUtils.strTrim(formField.value) == "")	
			errMsg = errMsgBlankField;
		else if (!IsNumeric(formField))
			errMsg = errMsgNonNumeric;
	}

	if (errMsg != "")
	{
		alert(_messages[errMsg]);
		formField.focus();
		return false;
	}

	return true;	
}

/*
 * ValidateAccountChangePassword for AccountChangePasswordControl
 */
 
 // Unicode validation for ChangePassword
 function ValidateAccountChangePassword(thisForm, idToValidate)
 {
 	// Original Password
 	var orgPassword	= objField(thisForm, idToValidate, ":password0");
	// New Password
	var newPassword	= objField(thisForm, idToValidate, ":password1");	
	// Confirm Password
	var conPassword	= objField(thisForm, idToValidate, ":password2");	

	//Validate UniCode
	if (!ValidateCharSet(orgPassword)) return false;
	if (!ValidateCharSet(newPassword)) return false;
	if (!ValidateCharSet(conPassword)) return false;
	
	//Validate new Password and Confirm Password
	if (newPassword.value != conPassword.value)
	{
		alert(_messages["PasswordUnConfirmed"]);
		return false;
	}
		
	return true;
 }
 
 
/*
	This function update the states form field based on the following rules:
	
	a. If there are states available for the country selected, then a select combo box is visible with 
	the approptiate state options;
	b. If there are no states available for the country selected, the hide the select combo box and make input text field
	visible.
*/
function ChangeState(thisForm, uniqueId, stateComboBoxAllowed)
{
	// identifies the country form field 
	var objCountry = objField(thisForm, uniqueId, ":country");
	// identifies the state input form field
	var objState = objField(thisForm, uniqueId, ":state");
	// identifies the state select form field
	var objStateSelect = objField(thisForm, uniqueId, ":stateSelect");
	// identifies if the select drop down is visible
	var stateSelectVisible = false;
	
	// validate the country state array exist
	if (_countryStateValues != 'undefined')
	{	
		// loop through available country state options
		for (var i = 0; i < _countryStateValues.length; i++)
		{
			// retrieve the country values
			var countryStateValue = _countryStateValues[i];
				
			// find the selected country
			if (countryStateValue[0] == objCountry.value)
			{
				// retrieves the current states available 
				var stateValues = countryStateValue[1];
				
				// there are states available to render
				if (stateValues.length != 0 && objStateSelect != 'undefined')
				{
					objStateSelect.options.length = stateValues.length;
					// iterate and render the states as a new option
					for (var j = 0; j < stateValues.length; j++)
					{		
						objStateSelect.options[j] = new Option(stateValues[j][1], stateValues[j][0]);
						
						if (objState.value == stateValues[j][0])
							objStateSelect.options[j].selected = true;
					}	
					stateSelectVisible = true;	
				}
				
				break;
			}
		}
		
		// validate if the state select combo box is visible
		if (stateSelectVisible && stateComboBoxAllowed)
		{
			// set the style for the select combo box to be visible
			objStateSelect.style.display = 'inline';			
			// set the style for the input text field to be invisible
			objState.style.display = 'none';
		}
		else
		{
			// set the style for the select combo box to be invisible
			objStateSelect.style.display = 'none';
			// set the style for the input text field to be visible
			objState.style.display = 'inline';
		}
	}	
}

function UpdateStateValue(thisForm, uniqueId, stateComboBoxAllowed)
{
	// identifies the state input form field
	var objState = objField(thisForm, uniqueId, ":state");
	// identifies the state select form field
	var objStateSelect = objField(thisForm, uniqueId, ":stateSelect");
	
	objState.value = objStateSelect.options[objStateSelect.options.selectedIndex].value;
}

/* Email A Friend control */
function ValidateEmailAFriend(thisForm, idToValidate, fromNameReq, fromEmailReq, toNameReq, messageReg)
{
	// Get form fields back
	var fromName	= objField(thisForm, idToValidate, ":fromName");
	var fromEmail	= objField(thisForm, idToValidate, ":fromEmail");
	var toName		= objField(thisForm, idToValidate, ":toName");
	var toEmail		= objField(thisForm, idToValidate, ":toEmail");
	var message		= objField(thisForm, idToValidate, ":message");
			
	// FromName
	if ((typeof(fromName) != 'undefined') && (fromNameReq) && (fromName.value == ""))
	{
		fromName.focus();		
		alert(_messages["FromNameBlank"]);
		return false;
	}
	
	// FromEmail
	if ((typeof(fromEmail) != 'undefined') && (fromEmailReq) && (fromEmail.value == ""))
	{
		fromEmail.focus();		
		alert(_messages["FromEmailBlank"]);
		return false;
	}
	
	// FromEmail Invalid
	if ((typeof(fromEmail) != 'undefined') && (fromEmail.value != '') && (!ValidateEmail(fromEmail.value)))
	{
		fromEmail.focus();		
		alert(_messages["FromEmailInvalid"]);
		return false;		
	}
	
	// ToName
	if ((typeof(toName) != 'undefined') && (toNameReq) && (toName.value == ""))
	{
		toName.focus();
		alert(_messages["ToNameBlank"]);
		return false;
	}

	// ToEmail
	if ((typeof(toEmail) != 'undefined') && (toEmail.value == ""))
	{
		toEmail.focus();
		alert(_messages["ToEmailBlank"]);
		return false;
	}	
	
	// ToEmail invalid
	if ((typeof(toEmail) != 'undefined') && (toEmail.value != '') && (!ValidateEmail(toEmail.value)))
	{
		toEmail.focus();
		alert(_messages["ToEmailInvalid"]);
		return false;
	}

	// Message
	if ((typeof(message) != 'undefined') && (messageReg) && (message.value == ""))
	{
		message.focus();
		alert(_messages["MessageBlank"]);
		return false;
	}	
		
	eval(thisForm + '.submit();');
}

function ValidateSpecialOffer(thisForm, idToValidate)
{
	eval("var objUserPreferences = " + thisForm + "['uiUserPreferences:userPref']");
	eval("var objEmailSpecialOffers = " + thisForm + "['uiAttribute1:checkBox']");
	
	if(objEmailSpecialOffers && objEmailSpecialOffers.checked)
	{
		if(objUserPreferences && objUserPreferences[0])
		{
			var anyChecked = false;
			for(var i = 0; i < objUserPreferences.length; i++)
			{
				if(objUserPreferences[i] && objUserPreferences[i].checked)
				{
					anyChecked = true;
					break;
				}
			}
			if(!anyChecked)
			{
				alert(_messages["AccountSpecialOffers"]);
				return false;
			}
		}
		else if(objUserPreferences)
		{
			if(!objUserPreferences.checked)
			{
				alert(_messages["AccountSpecialOffers"]);
				return false;
			}																			
		}
	}
	return true;
}

/*
Validate the credit card type selected
*/
function IsValidCreditCardType(objCCType, objCCNumber)
{
	var objStringUtils = new CSoftixUtils();
	
	// trim the credit card type value before testing	
	switch (objStringUtils.strTrim(GetRadioSelected(objCCType)))
	{
		case "Visa": 
			var regex = new RegExp("^4");
			if (!regex.test(objCCNumber))
			{
				alert(_messages["VisaCardInvalid"]);
				return false;
			}
			break;
		case "Mastercard":
			var regex = new RegExp("^5[1-5]{1}");
			if (!regex.test(objCCNumber))
			{
				alert(_messages["MasterCardInvalid"]);
				return false;
			}
			break;
		case "Diners":
			var regex = new RegExp("^(30{1}[0-5]{1}|36|38)");
			if (!regex.test(objCCNumber))
			{
				alert(_messages["DinnersCardInvalid"]);
				return false;
			}
			break;
		case "American Express":
			var regex = new RegExp("^(34|37)");
			if (!regex.test(objCCNumber))
			{
				alert(_messages["AmexCardInvalid"]);
				return false;
			}
			break;	
	}
	
	return true;
}

function GetRadioSelected(objRadios)
{
	if (typeof(objRadios.length) != 'undefined')
	{
		for (var i=0; i<objRadios.length; i++)
		{
			if (objRadios[i].checked)
				return objRadios[i].value;
		}
		return false;
	}
	else
		return objRadios.value;
}

/*
 * AO Concession Card control custom validation
 */
function ValidateConcessionNumber(thisForm, idToValidate, isRequired)
{
	var concessionid = objField(thisForm, idToValidate, ":Text");

	// Add the charset validation
	if (!ValidateCharSet(concessionid)) return false;

	// Check for required
	if (isRequired && concessionid != null)
	{

							if (concessionid.value == '')
							{
													concessionid.focus();
													alert(_messages['concessionIdMissingCode']);
													return false;
							}
	}

	return true;        
}

/* 20070727 CMD - START invite a friend */

/* Invite a Friend control */
function inviteAFriendAddRow(tableID, maxRows, isInvite)
{
 var objTable = document.getElementById(tableID);
 if (typeof(objTable) != 'undefined')
 {
     if (objTable.rows.length < maxRows + 3)
     {
         // copy the friend first row
         var objRow = objTable.rows[1];
         var objNewRow = objTable.insertRow(1);
         var objFirstNewElement = null;     
         
         for (var i = 0; i < objRow.cells.length; i++)
         {
             var objNewCell = objNewRow.insertCell(i);
             for (var j = 0; j < objRow.cells[i].childNodes.length; j++)
             {
                 objNewElement = objRow.cells[i].childNodes[j].cloneNode(true);
                 objNewCell.appendChild(objNewElement);
                 if (objNewElement.tagName == 'INPUT')
                 {
                     objNewElement.value = '';
                     if (objFirstNewElement == null)
                     {
                         objFirstNewElement = objNewElement;
                     }
                 }
             }
         }    
         
         // hide the add button from the copied row and make sure the delete button is shown
         inviteAFriendShowHideButtons(objRow.cells[objRow.cells.length - 1], false);
         
 
         //if max rows reached remove the add button 
         if (objTable.rows.length == maxRows + 3)
         {
             inviteAFriendShowHideButtons(
                 objTable.rows[1].cells[objTable.rows[1].cells.length - 1], false);
         }
         //Make sure the tabbing is correct 
         if (isInvite) inviteAFriendSetKeyHandlers();
         
         //first cell needs to span all rows
         objTable.rows[0].cells[0].rowSpan = objTable.rows.length - 2;
         
         if (objFirstNewElement != null) objFirstNewElement.focus();
     }
 }
 return;    
}

function inviteAFriendShowHideButtons(objParent, showAdd)
{
 // NB first span is add second span is delete
    var spanCount = 0;
    for (var i = 0; i < objParent.childNodes.length; i++)
    {
        if (objParent.childNodes[i].tagName == 'SPAN')
        {
            if ((!showAdd && spanCount == 0) || (showAdd && spanCount > 0))
            {
                objParent.childNodes[i].style.display = 'none';
                objParent.childNodes[i].style.visibility = 'hidden';
            }
            else
            {
                objParent.childNodes[i].style.display = 'inline';
                objParent.childNodes[i].style.visibility = 'visible';
            }
            spanCount++;
        }
    }
}

function inviteAFriendDeleteRow(tableID, objSource, isInvite)
{
 var objTable = document.getElementById(tableID);
 if (typeof(objTable) != 'undefined')
 {
     if (objTable.rows.length > 4)
     {
         // Our source should be an img or link in the last column of 
         // one of the rows in the table - we need to know which row
         for (var i = 1; i < objTable.rows.length - 2; i++)
         {
             var objCell = objTable.rows[i].cells[objTable.rows[i].cells.length - 1];
             if (isDescendantOf(objSource, objCell))
                {
                    //Remove this row
                    objTable.deleteRow(i);
                    //first cell needs to span all rows
                    objTable.rows[0].cells[0].rowSpan = objTable.rows.length - 2;
                    //Make sure add button is visible
                    inviteAFriendShowHideButtons(
                        objTable.rows[1].cells[objTable.rows[1].cells.length - 1], true);
                    if (isInvite) inviteAFriendSetKeyHandlers();
                    // Set the focus to the first name field in the first friend row
                    for (var k = 0; k < objTable.rows[1].cells.length; k++)
                    {
                        for (var m = 0; m < objTable.rows[1].cells[k].childNodes.length; m++)
                        {
                         if (objTable.rows[1].cells[k].childNodes[m] != null
                             && objTable.rows[1].cells[k].childNodes[m].tagName == 'INPUT')
                            {
                                objTable.rows[1].cells[k].childNodes[m].focus();
                                return;
                            }
                        }   
                    }
                    return;
                }
 
         }
     }
     else
     {
         alert(_messages["InviteAFriendCannotRemoveLastRow"]);
     }
 }
}

function isDescendantOf(objNode, objParentNode)
{
    if (objNode == null || objNode.parentNode == null || 
        objNode.parentNode == document || objParentNode == null)
    {
        return false;
    }
    else
    {
        if (objNode.parentNode == objParentNode) return true;
        else return isDescendantOf(objNode.parentNode, objParentNode);
    }
}

function inviteAFriendCountBlurbLength(formID, controlID, spanID, maxLength)
{
 var objBlurb = document.forms[formID][controlID];
 var objSpan = document.getElementById(spanID);
 for (var i = objSpan.childNodes.length - 1; i >= 0; i--)
 {
     objSpan.removeChild(objSpan.childNodes[i]);
 } 
 objSpan.appendChild(document.createTextNode(maxLength - objBlurb.value.length));
}

function HoldAdjacentSeatsValid(formID, controlID, blurbMaxLength, blurbReq)
{
    var objHoldNumber = objField(formID, controlID, ':uiHoldNumber');
    if (typeof(objHoldNumber) != 'undefined')
    {
        if (parseInt(objHoldNumber.options[objHoldNumber.selectedIndex].value, 10) > 0)
        {
            return InviteAFriendCommonValid(formID, controlID, blurbMaxLength, blurbReq);
        }
    }
    return true;
}

function InviteAFriendValid(formID, controlID, blurbMaxLength, blurbReq)
{
    return InviteAFriendCommonValid(formID, controlID, blurbMaxLength, blurbReq);
}

function InviteAFriendCommonValid(formID, controlID, blurbMaxLength, blurbReq)
{
 var objStringUtils = new CSoftixUtils;
 var objForm = GetForm(formID);
 var objFriendNames = objForm['uiInviteAFriendName'];
 var objFriendEmails = objForm['uiInviteAFriendEmail'];

 // Validate the friends names and email addresses
 var anyFriends = false;
 var objFirstFriendNameControl = null;
 if (typeof(objFriendNames.length) != 'undefined')
 {     
     objFirstFriendNameControl = objFriendNames[0];
     for (var i = 0; i < objFriendNames.length; i++)
     {
         var result = InviteAFriendFriendValid(objFriendNames[i], objFriendEmails[i]);
         if (result == 0) return false;
         else if (result > 0) anyFriends = true;
     }      
 }
 else
 {
     objFirstFriendNameControl = objFriendNames;
        var result = InviteAFriendFriendValid(objFriendNames, objFriendEmails);
        if (result == 0) return false;
        else if (result > 0) anyFriends = true;
 }
 if (!anyFriends)
 {
     alert(_messages["InviteAFriendNoFriendsSpecified"]);
     objFirstFriendNameControl.focus();
     return false;
 }

 // Validate the email message
 objEmailMessage = objField(formID, controlID, ":uiEmailBlurb");
 if (!ValidateCharSet(objEmailMessage)) return false;
 //must be less than 255 characters
 var emailMessage = objStringUtils.strTrim(objEmailMessage.value);
 if((typeof(emailMessage) == 'undefined' || emailMessage.length == 0) && blurbReq)
 {
     alert(_messages["InviteAFriendEmailMessageRequired"]);
     objEmailMessage.focus();
     return false;     
 }
 if (typeof(emailMessage) != 'undefined' && emailMessage.length > blurbMaxLength)
 {
     alert(_messages["InviteAFriendEmailMessageTooLong"]);
     objEmailMessage.focus();
     return false;     
 }

 // Check a template has been chosen
 var objTemplateRadioButtons = objForm['uiEmailTemplate'];
 if (typeof(objTemplateRadioButtons) != 'undefined')
 {
     var templateSelected = false;
     if (typeof(objTemplateRadioButtons.length) != 'undefined')
     {   
         for (var i = 0; i < objTemplateRadioButtons.length; i++)
         {
             if (objTemplateRadioButtons[i].checked)
             {
                 templateSelected = true;
                 break;
             }
         }
     }
     else
     {
         templateSelected = objTemplateRadioButtons.checked;
     }
     if (!templateSelected)
     {
         alert(_messages["InviteAFriendNoEmailTemplateSelected"]);
         return false;   
     }
 }
 return true;
}

function InviteAFriendFriendValid(objName, objEmail)
{
 var objStringUtils = new CSoftixUtils;
    var strName = objStringUtils.strTrim(objName.value);
    var strEmail = objStringUtils.strTrim(objEmail.value);
    if ((strName.length == 0 || typeof(strName) == 'undefined') && 
        (strEmail.length == 0 || typeof(strEmail) == 'undefined'))
    {
        return -1;
    }
    else if (strName.length == 0 || typeof(strName) == 'undefined')
    {
        alert(_messages["InviteAFriendNameEmpty"]);
        objName.focus();
        return 0;
    }
    else if (strEmail.length == 0 || typeof(strEmail) == 'undefined')
    {
        alert(_messages["InviteAFriendEmailEmpty"]);
        objEmail.focus();
        return 0;
    }
    else if (!ValidateCharSet(objName) || !ValidateCharSet(objEmail))
    {
        return 0;
    }
    else if (!ValidateEmail(strEmail))
    {
        alert(_messages["InviteAFriendEmailInvalid"]);
        objEmail.focus();
        return 0;
    }
    else
    {
        return 1;
    }
}

function resizeParentModalPopupWindow()
{
    // We want the actual height of the content not of the frame
    window.parent.resizeModalPopWindow(document.forms[0].offsetHeight);
    return;
}

function resizeAndCentreParentModalPopupWindow()
{
    //make sure we are at the top/left
    window.parent.document.body.scrollLeft=0;
    window.parent.document.body.scrollTop=0;
    //Set the size
    resizeParentModalPopupWindow();
    //Place into the centre
    window.parent.centerPopWin(null, null, true);
}
/*
Invite a friend page methods
*/
function inviteAFriendSetKeyHandlers()
{
    if (!document.all)
    {
        var objFirstElement = getFirstTabbableNode();
        var objLastElement = getLastTabbableNode();
        if (objFirstElement != null && objLastElement != null)
        {
            if (objFirstElement == objLastElement)
            {
                // if they are the same we need to disable tab key
                objFirstElement.onkeydown = disableTabbingEventHandler;
            }
            else
            {
                objFirstElement.onkeydown = inviteAFriendHandleFirstElementTabbing;
                objLastElement.onkeydown = inviteAFriendHandleLastElementTabbing;
            }
        }
    }
}

function inviteAFriendHandleFirstElementTabbing(e)
{
    if (e.keyCode == 9 && e.shiftKey) 
    { 
        var objLastElement = getLastTabbableNode();
        if (objLastElement != null) objLastElement.focus(); 
        if (typeof(e.preventDefault) != 'undefined') e.preventDefault();
        return false; 
    }
}

function inviteAFriendHandleLastElementTabbing(e)
{
    if (e.keyCode == 9 && !e.shiftKey) 
    { 
        var objFirstElement = getFirstTabbableNode();
        if (objFirstElement != null) objFirstElement.focus(); 
        if (typeof(e.preventDefault) != 'undefined') e.preventDefault();
        return false; 
    }
}
/*
Some generic methods to do with focus/tabbing/elements
*/
function getFirstTabbableNode()
{
    var objFirstLink = null;
    for (var i = 0; i < document.links.length; i++)
    {
        if (isNodeVisible(document.links[i]))
        {
            objFirstLink = document.links[i];
            break;    
        }   
    }
    var objFirstElement = getFirstVisibleElement();
    if (objFirstLink == null) return objFirstElement;
    else if (objFirstElement == null) return objFirstLink;
    //check which is first!      
    return whichNodeIsFirst(objFirstLink, objFirstElement);
}

function getLastTabbableNode()
{
    var objLastLink = null;
    for (var i = document.links.length - 1; i >= 0; i--)
    {
        if (isNodeVisible(document.links[i]))
        {
            objLastLink = document.links[i];
            break;    
        }   
    }
    var objLastElement = getLastVisibleElement();
    if (objLastLink == null) return objLastElement;
    else if (objLastElement == null) return objLastLink;
    //check which is first and then use the other one!      
    var objFirst = whichNodeIsFirst(objLastLink, objLastElement);
    if (objFirst == null) return null;
    else if (objFirst = objLastLink) return objLastElement;
    else objLastLink; 
}

function whichNodeIsFirst(objNodeOne, objNodeTwo)
{
    var objNodeOneParents = getParentsArray(objNodeOne);
    var objNodeTwoParents = getParentsArray(objNodeTwo);
    for (var i = 0; i < objNodeOneParents.length; i++)
    {
        if (i >= objNodeTwoParents.length) break; 
        if (objNodeOneParents[i] != objNodeTwoParents[i])
        {
            if (i == 0) break; 
            for (var j = 0; j < objNodeOneParents[i - 1].childNodes.length; j++)
            {
                if (objNodeOneParents[i - 1].childNodes[j] == objNodeOneParents[i])
                {
                    return objNodeOne;
                }
                if (objNodeOneParents[i - 1].childNodes[j] == objNodeTwoParents[i])
                {
                    return objNodeTwo;
                }
            }
            break;
        }
    }
    return null;
}

function getParentsArray(objNode)
{
    var i = 1;
    var objParentNode = objNode;
    while (objParentNode != document)
    {
        i++;
        objParentNode = objParentNode.parentNode
    }
    var objParents = new Array(i);
    objParentNode = objNode;
    for (var j = i - 1; j >= 0; j--)
    {
        objParents[j] = objParentNode;
        objParentNode = objParentNode.parentNode;
    }
    return objParents;
}

function disableTabbingEventHandler(e)
{
    if (e.keyCode == 9) 
    {
        if (typeof(e.preventDefault) != 'undefined') e.preventDefault();
        return false;
    }
}

function setFocusToFirstElement()
{
    var objElement = getFirstVisibleElement();
    if (objElement != null) objElement.focus();
}

function getFirstVisibleElement()
{
    for (var i = 0; i < document.forms.length; i++)
    {
        for (var j = 0; j < document.forms[i].elements.length; j++)
        {
            var objElement = document.forms[i].elements[j];
            if (isNodeVisible(objElement)) return objElement;
        }
    }
    return null;
}

function isNodeVisible(objNode)
{
    if (objNode.tagName.toUpperCase() != 'INPUT' || objNode.type.toLowerCase() != 'hidden')
    {
        var objCheckNode = objNode
        while (objCheckNode != null)
        {
            if (objCheckNode == document) break;
            if (typeof(objCheckNode.style) != 'undefined' && 
                    (objCheckNode.style.display == 'none' || objCheckNode.style.visibility == 'hidden'))
            {
                return false;

            }
            objCheckNode = objCheckNode.parentNode;
        }
        return true;
    }
    else
    {
        return false;
    }
}

function getLastVisibleElement()
{
    for (var i = document.forms.length - 1; i >= 0; i--)
    {
        for (var j = document.forms[i].elements.length - 1; j >= 0; j--)
        {
            var objElement = document.forms[i].elements[j];
            if (objElement.tagName.toUpperCase() != 'INPUT' || 
                objElement.type.toLowerCase() != 'hidden')
            {
                if (objElement.style.display != 'none' && objElement.style.visibility != 'hidden')
                {
                    return objElement;
                }
            }
        }
    }
    return null;
}

function inviteAFriendHoldNumberChanged(objDropDown, controlContainerID)
{
    if (typeof(objDropDown) != 'undefined')
    {
        var objContainer = document.getElementById(controlContainerID);
        if (typeof(objContainer) != 'undefined')
        {
            if (objDropDown.selectedIndex >= 0 && 
                parseInt(objDropDown.options[objDropDown.selectedIndex].value, 10) > 0)
            {
                objContainer.style.display = 'block';
            }
            else
            {
                objContainer.style.display = 'none';
            }
        }
    }
}
/* 20070727 CMD - END invite a friend */

/* 20070727 CMD - START AO Concession Card control custom validation */
function ValidateConcessionNumber(thisForm, idToValidate, isRequired) {
	var concessionid = objField(thisForm, idToValidate, ":Text");

	// Add the charset validation
	if (!ValidateCharSet(concessionid)) return false;
	
	// Check for required
	if (isRequired && concessionid != null) {
	
		if (concessionid.value == '') {
			concessionid.focus();
			alert(_messages['concessionIdMissingCode']);
			return false;
		}
	}
	
	return true;        
}
/* 20070727 CMD - END AO Concession Card control custom validation */

