
//    
//    
//    

self.focus();


function DisplayWaitMsg(item, msg){
	//there's just no good, reliable, way to do this for netscape version 4.7,
	// so we're just not going to do it.
	
	if (document.getElementById)
	{
		//IE6 and NN6.2
		var Message;
		Message = document.getElementById(item);
		Message.innerHTML = msg;
	}
	else if (document.layers){
		 //NN4.7
	}
	else if (document.all) {

	  document.all[item].innerHTML = msg;
	  
	}
	
	window.status = msg;

}


//VI#15474 Deepakg 4 Jun 2002. Focusing the fields after server side validation failure.
var Message;
var FieldName;
var MessageType;		//1 is for confirmation 
var ConfirmationURL;	//where Confirmation will lead to
//used in all pages
function PopupMessage() 
{
	if (Message != null)
	{
		 
		if (MessageType == null)
		{
			alert(Message);
		}else if (MessageType == 1) 
		{	//0836
			if (confirm(Message)) 
			{
				self.location.href = (ConfirmationURL);
			} else {
				void(0);
			}
		}

		//VI#24648
		if (FieldName == "RedirectActivities")
		{
			location.replace("../Activities/Activities.asp");
			return true;
		}else if (FieldName == "RedirectStart")
		{
			location.replace("../Start/Start.asp");
			return true;
		}else if (FieldName == "RedirectFacilities")
		{
			location.replace("../Facilities/FacilitiesQuickRezSearchResult.asp?NewAccountInactive=Y");
			return true;
		}

		//SRS0815 JaiVardhan 25 Feb 04
		if ((document.frmQuickRezResultForm) && (document.frmQuickRezResultForm.SetFocusItemCount.value.length > 0))
		{
			var FieldType;
			FieldType = eval("document.frmQuickRezResultForm.inputtype" + document.frmQuickRezResultForm.SetFocusItemCount.value);
			if (FieldType.value == "C")
			{
				FieldName = eval("document.frmQuickRezResultForm.chkBook" + document.frmQuickRezResultForm.SetFocusItemCount.value);
				FieldName.focus();
			}
			else
			{
				FieldName = eval("document.frmQuickRezResultForm.SpotsToBook" + document.frmQuickRezResultForm.SetFocusItemCount.value);
				FieldName.focus();
				FieldName.select();	
			}
			return true;
		}

		//if the CardExpY field is hidden we are in kiosk mode so don't try to set focus!
		if ((document.RegistrationDetails) && (document.RegistrationDetails.CardExpY) && (document.RegistrationDetails.CardExpY.type != "hidden"))
		{
		      if (FieldName == "CardType") 
		      {
			      document.RegistrationDetails.CardType.focus();
		      }
		      else if (FieldName == "CardNum")
		      {
			      document.RegistrationDetails.CardNum.focus();
			      document.RegistrationDetails.CardNum.select();
		      }
		      else if (FieldName == "CardExpDate") 
		      {
			      document.RegistrationDetails.CardExpY.focus();
		      }
		}
		//Phone 
		if (document.CreateNewAccount || document.UpdateAccount || document.EditClientDetails || document.GuestIdentification)
		{
			if (FieldName == "HomeAreaCode")
			{
				if (document.CreateNewAccount)
				{
					document.CreateNewAccount.HomeAreaCode.focus();
				}else if (document.UpdateAccount)
				{
					document.UpdateAccount.HomeAreaCode.focus();
				}else if (document.EditClientDetails)
				{
					document.EditClientDetails.HomeAreaCode.focus();
				}
				
			}	
			if (FieldName == "HomePhoneNumber")
			{
				if (document.CreateNewAccount)
				{
					document.CreateNewAccount.HomePhoneNumber.focus();
				}else if (document.UpdateAccount)
				{
					document.UpdateAccount.HomePhoneNumber.focus();
				}else if (document.EditClientDetails)
				{
					document.EditClientDetails.HomePhoneNumber.focus();
				}
			}
			
			if (FieldName == "City")
			{
				if (document.CreateNewAccount)
				{
					document.CreateNewAccount.City.focus();
				}else if (document.UpdateAccount)
				{
					document.UpdateAccount.City.focus();
				}else if (document.EditClientDetails)
				{
					document.EditClientDetails.City.focus();
				}
			}
			
			if (FieldName == "WorkAreaCode")
			{
				 
				if (document.EditClientDetails)
				{
					document.EditClientDetails.WorkAreaCode.focus();
				}
			}		
			if (FieldName == "WorkPhoneNumber")
			{
				 
				if (document.EditClientDetails)
				{
					document.EditClientDetails.WorkPhoneNumber.focus();
				}
			}
			if (FieldName == "FaxAreaCode")
			{
				 
				if (document.EditClientDetails)
				{
					document.EditClientDetails.FaxAreaCode.focus();
				}
			}	
			if (FieldName == "FaxPhoneNumber")
			{
				 
				if (document.EditClientDetails)
				{
					document.EditClientDetails.FaxPhoneNumber.focus();
				}
			}	
			if (FieldName == "CellAreaCode")
			{
				 
				if (document.EditClientDetails)
				{
					document.EditClientDetails.CellAreaCode.focus();
				}
			}	
			if (FieldName == "CellPhoneNumber")
			{
				 
				if (document.EditClientDetails)
				{
					document.EditClientDetails.CellPhoneNumber.focus();
				}
			}	
		 	if (FieldName == "PagerAreaCode")
			{
				 
				if (document.EditClientDetails)
				{
					document.EditClientDetails.PagerAreaCode.focus();
				}
			}	
			if (FieldName == "PagerPhoneNumber")
			{
				 
				if (document.EditClientDetails)
				{
					document.EditClientDetails.PagerPhoneNumber.focus();
				}
			}	
			
			if (FieldName == "PostalCodeZip")
			{
				if (document.CreateNewAccount)
				{
					document.CreateNewAccount.PostalCodeZip.select();
					document.CreateNewAccount.PostalCodeZip.focus();
				}else if (document.UpdateAccount)
				{
					document.UpdateAccount.PostalCodeZip.select();
					document.UpdateAccount.PostalCodeZip.focus();
				}else if (document.EditClientDetails)
				{
					document.EditClientDetails.PostalCodeZip.select();
					document.EditClientDetails.PostalCodeZip.focus();
				}
				
			}
			if (FieldName == "AreaCode")
			{
				 
				if (document.GuestIdentification)
				{
					document.GuestIdentification.AreaCode.focus();
				}
			}	
			if (FieldName == "Phone")
			{
				 
				if (document.GuestIdentification)
				{
					document.GuestIdentification.Phone.focus();
				}
			}				
						
		}
	}
	if (document.EditClientDetails)
	{	//onLoad of EditClientDetails disable address field is we are using account address
		if (document.EditClientDetails.UseAccountAddress)
		{ 
			if (document.EditClientDetails.UseAccountAddress.checked || document.EditClientDetails.UseAccountAddress.value == "1")
			{	
				if (document.EditClientDetails.AddressLine1)
				{
					document.EditClientDetails.AddressLine1.disabled = true;
				}
				if (document.EditClientDetails.AddressLine2)
				{
					document.EditClientDetails.AddressLine2.disabled = true;
				}
				if (document.EditClientDetails.RR)
				{
					document.EditClientDetails.RR.disabled = true;
				}
				if (document.EditClientDetails.POBox)
				{
					document.EditClientDetails.POBox.disabled = true;
				}
				if (document.EditClientDetails.STN)
				{
					document.EditClientDetails.STN.disabled = true;
				}
				if (document.EditClientDetails.StreetNo)
				{
					document.EditClientDetails.StreetNo.disabled = true;
				}
				if (document.EditClientDetails.Suffix)
				{
					document.EditClientDetails.Suffix.disabled = true;
				}
				if (document.EditClientDetails.Suite)
				{
					document.EditClientDetails.Suite.disabled = true;
				}
				if (document.EditClientDetails.StreetName)
				{
					document.EditClientDetails.StreetName.disabled = true;
				}
				if (document.EditClientDetails.StreetTypeCbx)
				{
					document.EditClientDetails.StreetTypeCbx.disabled = true;
				}
				if (document.EditClientDetails.PreDirCbx)
				{
					document.EditClientDetails.PreDirCbx.disabled = true;
				}
				if (document.EditClientDetails.PostDirCbx)
				{
					document.EditClientDetails.PostDirCbx.disabled = true;
				}
				if (document.EditClientDetails.ProvinceStateCbx)
				{
					document.EditClientDetails.ProvinceStateCbx.disabled = true;
				}
				if (document.EditClientDetails.CityCbx)
				{
					document.EditClientDetails.CityCbx.disabled = true;
				}
				if (document.EditClientDetails.City)
				{
					document.EditClientDetails.City.disabled = true;
				}
				if (document.EditClientDetails.CountryCbx)
				{
					document.EditClientDetails.CountryCbx.disabled = true;
				}
				if (document.EditClientDetails.AreaCbx)
				{
					document.EditClientDetails.AreaCbx.disabled = true;
				}
				if (document.EditClientDetails.PostalCodeZip)
				{
					document.EditClientDetails.PostalCodeZip.disabled = true;
				}
			}
		}
	}
		return true;
}

//used in MyBasketCheckout.asp and MyAccountBalancePay.asp
//VI#20641 MohitA 28May02. Credit Card Expiry Month/Year Text boxes are changed to Month/Year Combo Boxes.
function CheckCC(form,sInvalidCardNumberMessage, sInvalidCardExpiryDateMessage, sInvalidPaymentAmountMessage)
{

	if (form.CardNum) 
	{
		var sTmp;
		var test;
				      
		var selIndexCardExpM = form.CardExpM.selectedIndex;
		var selIndexCardExpY = form.CardExpY.selectedIndex;
		var cardExpM = form.CardExpM.options[selIndexCardExpM].value;
		var cardExpY = form.CardExpY.options[selIndexCardExpY].value;

		//VI#28369 - Bansi Jun 4, 03. Invalid card expiry date should be checked on client side. 
		//The card expiry month and year should not be earlier than current month and year.
		var dDate = new Date();
		var currentMonth = (dDate.getMonth() + 1);
		var currentYear = dDate.getYear();

		sTmp = form.CardNum.value;

		form.CardNum.value = sTmp.replace(/ /g,"");

		test = ( (isInteger(form.CardNum.value)) && (form.CardNum.value.length > 12) );
		if (test == false) 
		{
			var msg = sInvalidCardNumberMessage;
			alert(msg);
			form.CardNum.focus();
			form.CardNum.select();
			return false;
		}

		if (cardExpM == '')
		{
			var msg = sInvalidCardExpiryDateMessage;  
			alert(msg);
			form.CardExpM.focus();
			return false;
		}

		if (cardExpY == '') 
		{
			var msg = sInvalidCardExpiryDateMessage;
			alert(msg);
			form.CardExpY.focus();
			return false;
		}

		//VI#28369 - Bansi Jun 4, 03. Invalid card expiry date should be checked on client side. 
		//The card expiry month and year should not be earlier than current month and year.
		if ((cardExpM < currentMonth) && (cardExpY <= currentYear))
		{
			var msg = sInvalidCardExpiryDateMessage;
			alert(msg);
			form.CardExpM.focus();
			return false;
		}

		//VI#14473
		if (form.CurrCharges)
		{
			var lIndexOfComma;
			var lIndexOfDecimal;
			var Charges;
			var DecimalAmount;
			
			Charges = form.CurrCharges.value;
			lIndexComma = Charges.indexOf(',');
			Charges = Charges.substring(0,lIndexComma) + Charges.substring(lIndexComma + 1, Charges.length)
			lIndexOfDecimal = Charges.indexOf('.');
		    
		    if (lIndexOfDecimal == -1){
				DecimalAmount = "0"
			}else
			{ 
				DecimalAmount = Charges.substring(lIndexOfDecimal + 1, Charges.length);
			}
					
			test = ( (isFloat(Charges)) && (DecimalAmount.length <= 2) && (Charges <= 50000) && (Math.round(Charges*100) > 0));
			 
			if (test == false) 
			{
				var msg = sInvalidPaymentAmountMessage; 
				alert(msg);
				form.CurrCharges.focus()
				form.CurrCharges.select()
				return false;
			}
		}
		
		//VI#23950
		if (form.TransactionStarted)
		{
			form.TransactionStarted.value = "1";	
		}

	}      
}




//-------------------The following functions are from form.js. 
//-------------------They can be used in multiple places.

//used by isWhitespace method
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

//used in Activities.js and isEmail in Account.js
function isWhitespace (s)
{   var i;
	var whitespace = " \t\n\r";
    // Is s empty?
    if (isEmpty(s)) return true;
 
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

//used in Facilities.js
function stripWhitespace (s)
{    
	var i;
    var returnString = "";
	var whitespace = " \t\n\r";
	 
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) returnString += c;
    }

    return returnString;

}
 
//used in isSignedInteger method, CheckCC method, Facilities.js, and Activities.js
function isInteger (s)
{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return false;
       else return (isInteger.arguments[1] == true);
 
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!((c >= "0") && (c <= "9"))) 
	return false;
    }

    // All characters are numbers.
    return true;
}


//used in MyAccount.js
function isPositiveInteger (s)
{   
    var secondArg = false;

    if (isPositiveInteger.arguments.length > 1)
        secondArg = isPositiveInteger.arguments[1];
	 
    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (s > 0) ) );
}


//used in isPositiveInteger method
function isSignedInteger (s)
{   
    if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return false;
       else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = false;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}

//used in CheckCC method
function isFloat (s)
{   var i;
    var seenDecimalPoint = false;
	var decimalPointDelimiter = ".";
	
    if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return false;
       else return (isFloat.arguments[1] == true);

    if (s == decimalPointDelimiter) return false;

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!((c >= "0") && (c <= "9"))) return false;
    }

    // All characters are numbers.
    return true;
}

//----------------------End of form.js functions



//used for Kiosk Print in BasketPrint.asp and MyAccountPrint.asp
function KioskPrintReceipt(){

	WB.ExecWB(6,-1);
	window.close();

}

/********************************************************************
OnDayChkClick
	Deselects the all checkbox if another day of week is selected.
	Deselects all other days of week if all is selected.
	
	Expectation is that checkboxes are name chkWeekDay1-7 with an optional
	chkWeekDay8 for which is All.
	
	use in Activities Adv Search page; Activities Details Search page; Facilities page
Param:
	roForm			Reference to the search form
	roChk			Reference to the checkbox that was clicked
*********************************************************************/
function OnDayChkClick(roForm, roChk) {
	//Selected all, deselect 1-7
	if(roChk.name == 'chkWeekDay8') {
		roForm.chkWeekDay1.checked = false;
		roForm.chkWeekDay2.checked = false;
		roForm.chkWeekDay3.checked = false;
		roForm.chkWeekDay4.checked = false;
		roForm.chkWeekDay5.checked = false;
		roForm.chkWeekDay6.checked = false;
		roForm.chkWeekDay7.checked = false;
	}
	else
		if( roForm.chkWeekDay8 )
			roForm.chkWeekDay8.checked = false;
}