// ** depreciated 
// used by login.jsp
function initLoginForm(){
 document.loginForm.accountNumber.focus();
}

// used by forgottenAccountNumber.jsp
function initForgottenAccountNumberForm(){
 document.forgottenAccountNumberForm.EMAIL.focus();
}

// used by forgottenPassword.jsp
function initForgottenPasswordForm(){
 document.forgottenPasswordForm.USER_ID.focus();
}

// used by checkChallenge2.jsp
function initCheckChallengeTwoForm(){
 document.checkChallengeTwoForm.CHALLENGE_ANSWER2.focus();
}


// used by changeProfile.jsp
function initChangeProfilePage() {
  // Select the user's country in the list...
  var countryOptions = document.changeProfile.COUNTRY.options;
  for( var i = 0; i < countryOptions.length; i++ ) {
    if( countryOptions[i].value == country ) {
      countryOptions[i].selected = true;
    }
  }
}

// ** depreciated
/********** generic submit once function, used by forms in my account **/
var submission = 0;
function submitOnce() {
	submission++;
	if (submission==1) {
		return true;
	}
	else {
		return false;
	}
}

// ** depreciated
//********** used by /account/EFTDeposit.jsp **************/
function validateEFTAmount(that) {
		if (isNaN(that.AMOUNT.value)) {
			alert("Deposit amount is not valid...");
			that.AMOUNT.focus();
			return false;
		}
		if (that.AMOUNT.value < 50) {
			alert("The minimum credit card deposit is $50!\n Please change your deposit amount...");
			that.AMOUNT.focus();
			return false;
		}
		return submitOnce();
	}

// ** depreciated
/********** old scripts from BoDog 2 *************/
// used by welcomeNewAccount.jsp
function makeDeposit() {
	top.location = "/global/accounts/index.jsp?deposit";
}

// used by registerETFAccountPending.jsp
// used by registerETFAccountComplete.jsp
  var EFTWin = null; 
  function openVer(){
    openWindow('EFTWin','/accounts/EFTVerification.jsp','status=0,menubar=1,toolbar=1,scrollbars=1,resizable=1,width=600,height=600');
  }

  
// used by changePasswordStepTwo.jsp
function validate(that) {
	showNormalControl('PASSWORD1');
	showNormalControl('PASSWORD2');	
	removeError('error-message-password1-empty', 'error-description-password1-empty');
	removeError('error-message-password2-empty', 'error-description-password2-empty');	
	removeError('error-message-invalid-password', 'error-description-invalid-password' );
	removeError('error-message-both-empty', 'error-description-both-empty' );
	removeError('error-message-password-unmatched', 'error-description-password-unmatched' );

	if (that.PASSWORD1.value == "" && that.PASSWORD2.value  == ""){
		displayErrorTwoControls ( 'PASSWORD1', 'PASSWORD2', 'error-message-both-empty', 'error-description-both-empty' );
		return false;
	}
	
	if (that.PASSWORD1.value == "" ){	
		displayError ( 'PASSWORD1', 'error-message-password1-empty', 'error-description-password1-empty' );
		return false;	
	}
	
	if (that.PASSWORD2.value == "" ){	
		displayError ( 'PASSWORD2', 'error-message-password2-empty', 'error-description-password2-empty' );
		return false;		
	}
	
	if (that.PASSWORD1.value.length < 5) {
		displayError ( 'PASSWORD1', 'error-message-invalid-password', 'error-description-invalid-password' );
		return false;	
	}
	
	if (that.PASSWORD1.value != that.PASSWORD2.value) {
		displayErrorTwoControls ( 'PASSWORD1', 'PASSWORD2', 'error-message-password-unmatched', 'error-description-password-unmatched' );
		return false;
	}

	return true;
}


function showNormalControl(controlName){
	var objErrFormField = document.getElementById(controlName);
	if (objErrFormField) objErrFormField.className = 'form-field';
}


function removeError(errorMessage, errorDescription){
	var objErrMessage = document.getElementById(errorMessage);
	var objErrDescription = document.getElementById(errorDescription);

	if (objErrMessage) objErrMessage.style.display = 'none';
	if (objErrDescription) objErrDescription.style.display = 'none';
}

function displayError ( controlName, errorMessageName, errorDescriptionName ){
		var Control = document.getElementById(controlName);
		Control.className = 'form-field-error';		   

   		var messageError = document.getElementById(errorMessageName);
   		messageError.style.display = 'block';
   		var descriptionError = document.getElementById(errorDescriptionName);
   		descriptionError.style.display = 'block';
}

function displayErrorTwoControls ( controlName, controlName2, errorMessageName, errorDescriptionName ){
		var Control = document.getElementById(controlName);
		Control.className = 'form-field-error';		   
		var Control2 = document.getElementById(controlName2);
		Control2.className = 'form-field-error';		   

   		var messageError = document.getElementById(errorMessageName);
   		messageError.style.display = 'block';
   		var descriptionError = document.getElementById(errorDescriptionName);
   		descriptionError.style.display = 'block';
}

// used by changeProfile.jsp
function validateEmail(that) {
	if (isNotEmail(that.E_MAIL.value)) {
		alert("Invalid email address!");
		that.E_MAIL.focus();
		return false;
	}
	return true;
}


// ** depreciated
// used by creditCardDeposit.jsp
function validateCC(that) {
	if (isNaN(that.AMOUNT.value)) {
		alert("Deposit amount is not valid...");
		that.AMOUNT.focus();
		return false;
	}
	if (that.AMOUNT.value < 50) {
		alert("The minimum credit card deposit is $50!\n Please change your deposit amount...");
		that.AMOUNT.focus();
		return false;
	}
	if ( isNaN(that.CARD_CVV2.value)){
		alert("Your Credit Card Confirmation number is invalid.\nPlease refer to the 3 digit number located on the back of your credit card.");
		that.CARD_CVV2.focus();
		return false;
	}
	var cvv = that.CARD_CVV2.value;
	if (cvv.length !=3){
		alert("Your Credit Card Confirmation number is invalid.\nPlease refer to the 3 digit number located on the back of your credit card.");
		that.CARD_CVV2.focus();
		return false;
	}
	
	return true;
}
  
 /****** global form tools ***************/ 

 // ** depreciated
 // used by changePasswordStepTwo.jsp 
function isNumber(numvar) {		
		if (isNaN(numvar) || numvar.length == 0 || numvar == null) {
			return false
		}
		return true
}

 // ** depreciated
function isBlank(m){
	if (m == null) {return true}
	for (var i=0; i<m.length; i++) {
		var c = m.charAt(i)
		if ((c != ' ') && (c != '\n') && (c != '\t')) {return false}
	}
		return true
}

function inValid(v) {
	var Flag = false
	if (v.length == 0){return true}
	var pattern = /[^A-Za-z0-9]/
	var m = v.search(pattern)
	if (m != "-1") {Flag = true}
	return Flag
}

function isNotEmail(e) {
	if (e.length == 0) {return true}
	var pattern = /^[\w\._\-\#\&0-9]+\@[0-9a-zA-Z\.\-]+\.[a-zA-Z]{2,3}$/
	var result = e.search(pattern)
	if (result == "-1") {       
		return true
	}
}

// ** depreciated
/************** used by Account Statments ************/
function submitForm( thisOption, thisForm ){
    if( thisOption[0].selected ) {
	    return;
	} else {
	    for( i = 0; i < thisOption.length; i++) {
	        if( thisOption[i].selected && thisOption[i].value == selection ) {
	            return;
	        }
	    }
	    thisForm.submit();
	}
}

// ** depreciated
function checkAccountNumber() {
    var inputField;

    if( document.getElementById ){
        inputField = document.getElementById( 'instrumentNumber' );
    } else {
        inputField = document.forms['depositForm'].elements['instrumentNumber'];
    }

    var accountNumber = inputField.value;

    if( document.getElementById ){
        inputField = document.getElementById( 'BANK_ACCOUNT_NUMBER_COPY' );
    } else {
        inputField = document.forms['depositForm'].elements['BANK_ACCOUNT_NUMBER_COPY'];
    }

    var confirmNumber = inputField.value;

    if (accountNumber != confirmNumber){
       alert("The entered 'Confirm Account Number' must be the same as the entered 'Account Number'");
       return false;
    } else {
       return true;
    }
}

// ** depreciated
// validate value of deposit amount
function checkDepositValue( depositVal ) {

    if ( isNaN( depositVal ) ){
        alert('Deposit amount is not valid...');
        return false;
    } else if ( depositVal.indexOf( '.' ) > -1 ) {
        alert( 'Do not enter cents. Only enter the dollar amount.' );
        return false;
    } else if ( parseInt( depositVal ) < 20 || depositVal == '') {
        alert('The minimum deposit is $20! \n Please change your deposit amount...');
        return false;
    }
     return true;
}

// ** depreciated
function submitDepositForm(){
    var submitButton = document.getElementById( 'submitButton' );

    var inputFields = document.getElementsByTagName('input');
	var amount;
	for(var i=0;i<inputFields.length;i++){
		if (inputFields[i].id.indexOf("amount") == 0){
			amount = inputFields[i].value;
		} 
	}

    if ( checkDepositValue( amount ) ){
       if( confirmDepositAmount( amount ) ){
           submitButton.disabled=true;
           return submitOnce();
       }
    }
   
    return false;
}

function confirmDepositAmount( depositAmount , method ){

	var depositAmount2 = depositAmount.replace("$", "");
    var messageText = 'You are about to deposit $' + depositAmount2 + ' into your Bodog account.\n';
    messageText += 'If this amount is correct click OK.\n';
    messageText += 'If you would like to change this amount click Cancel.';
	
	if (method == 'DBT'){
    	messageText += '\n\nBy clicking OK you confirm this payment method is still active.';	
	}
	
    return confirm( messageText );
}


/*
 * CLASS: EFTRegistraionValidator
 *
 * Validates the EFT Registration information form
 * @author  Justin
 */

 // ** depreciated (EVERYTHING concerning EFTRegistration)
function EFTRegistration( elmForm ){
    this.routingNumInput = elmForm.ROUTING_TRANSIT;
    this.accountNumInput = elmForm.BANK_ACCOUNT_NUMBER;
    this.accountNumCopyInput = elmForm.BANK_ACCOUNT_NUMBER_COPY;

    this.routingError = null;
    this.accountError = null;
    this.confirmError = null;
}

EFTRegistration.prototype.MIN_ROUTING_NUM_LENGTH = 9;
EFTRegistration.prototype.MAX_ROUTING_NUM_LENGTH = 9;
EFTRegistration.prototype.MIN_ACCOUNT_NUM_LENGTH = 5;
EFTRegistration.prototype.MAX_ACCOUNT_NUM_LENGTH = 17;

EFTRegistration.prototype.ERROR_ROUTING_NUM_NUMERIC =   "The Routing Number must be contain only numbers.";
EFTRegistration.prototype.ERROR_ROUTING_NUM_LENGTH =    "The Routing Number must be exactly 9 digits long."
EFTRegistration.prototype.ERROR_ACCOUNT_NUM_NUMERIC =   "The Account Number must be contain only numbers.";
EFTRegistration.prototype.ERROR_ACCOUNT_NUM_LENGTH =    "The Account Number must be between 6 and 17 digits long."
EFTRegistration.prototype.ERROR_CONFIRM_MISMATCH =      "The Confirm Account Number must match the number entered in the Account Number box.";

// PUBLIC
EFTRegistration.prototype.isValid = function(){
    this.clearErrors()
    
    var routingIsValid = this.isValidRoutingNum();
    var accountIsValid = this.isValidAccountNum();
    var confirmIsValid = this.isValidConfirmNum();
    
    return ( routingIsValid && accountIsValid && confirmIsValid);
}

EFTRegistration.prototype.clearErrors = function(){
    this.routingError = null;
    this.accountError = null;
    this.confirmError = null;
}

EFTRegistration.prototype.getRoutingError = function(){
    return this.routingError;
}

EFTRegistration.prototype.getAccountError = function(){
    return this.accountError;
}

EFTRegistration.prototype.getConfirmError = function(){
    return this.confirmError;
}

// PRIVATE
EFTRegistration.prototype.isValidRoutingNum = function(){
    var routingNum = this.routingNumInput.value;
    
    // check if routing number contains non-numeric characters
    if( !this.isNumeric( routingNum ) ){
        this.routingError = this.ERROR_ROUTING_NUM_NUMERIC;
        return false;
    }
    
    // check if routing is in the correct length range
    if( routingNum.length < this.MIN_ROUTING_NUM_LENGTH || routingNum.length > this.MAX_ROUTING_NUM_LENGTH ){
        this.routingError = this.ERROR_ROUTING_NUM_LENGTH;
        return false;
        
        return false;
    }
        
    return true;
}

EFTRegistration.prototype.isValidAccountNum = function(){
    var accountNum = this.accountNumInput.value;
    
    // check if account number contains non-numeric characters
    if( !this.isNumeric( accountNum ) ){
        this.accountError = this.ERROR_ACCOUNT_NUM_NUMERIC;
        return false;
    }
    
    // check if account is in the correct length range
    if( accountNum.length < this.MIN_ACCOUNT_NUM_LENGTH || accountNum.length > this.MAX_ACCOUNT_NUM_LENGTH ){
        this.accountError = this.ERROR_ACCOUNT_NUM_LENGTH;
        return false;
    }
    
    return true;
}

EFTRegistration.prototype.isValidConfirmNum = function(){
    var accountNum = this.accountNumInput.value;
    var accountNumCopy = this.accountNumCopyInput.value;

    if( accountNum != accountNumCopy ){
        this.confirmError = this.ERROR_CONFIRM_MISMATCH;
        return false;
    }
    
    return true;
}

EFTRegistration.prototype.isNumeric = function( strNumericChars ){
    return (strNumericChars.match(/\D/) == null);
}

// END CLASS: EFTRegistraion

/*
 * CLASS: EFTDeposit
 *
 * Validates the EFT Deposit information form
 * @author  Justin
 */

function EFTDeposit( elmForm ){
    this.ammountInput = elmForm.AMOUNT;
    this.error = null;
}

EFTDeposit.prototype.MIN_DEPOSIT = 50;
EFTDeposit.prototype.MAX_DEPOSIT = 500;

EFTDeposit.prototype.ERROR_DEPOSIT_NUM_NUMERIC = "You must enter a valid dollar ammount";
EFTDeposit.prototype.ERROR_DEPOSIT_AMOUNT = "Your deposit must be at least $50 and no more than $500.";
//<br>If you would like to deposit more than $500 please call our Customer Service Center toll free at 1-888-263-0000.

// PUBLIC
EFTDeposit.prototype.isValid = function(){
    this.error = null;
    this.ammount = this.ammountInput.value;

    if( !this.isNumeric( this.ammount ) ){
        this.error = this.ERROR_DEPOSIT_NUM_NUMERIC;
        return false;
    }
    
    var fltAmmount = parseFloat( this.ammount )
    if( fltAmmount < this.MIN_DEPOSIT || fltAmmount > this.MAX_DEPOSIT ){
         this.error = this.ERROR_DEPOSIT_AMOUNT;
         return false;
    }
    
    return true;
}


// PRIVATE
EFTDeposit.prototype.getError = function(){
    return this.error;
}

EFTDeposit.prototype.isNumeric = function( strNumericChars ){
    //alert( isNaN( parseFloat( strNumericChars ) ) );
    return !isNaN( parseFloat( strNumericChars ) );
}

// END CLASS: EFTDeposit





function validatePayoutForm( payoutForm ){

   	var errorMessage = "";

   	//Using this way of accessing value because of two input fields having the 'amount' as an id
   	var inputFields = Forms.getElements(payoutForm);
	var amount;
	
	for(var i=0;i<inputFields.length;i++){
		if (inputFields[i].id.indexOf("amount") == 0){
			alert(i);
			amount = inputFields[i].value;
		} 
		
		if (inputFields[i].id.indexOf("METHOD") == 0){
			method = inputFields[i].value;
		}
	}
	   
	alert(method + ' ' + amount);
	
   //var amount = document.frmChoosePayout.AMOUNT.value;
   //var method = document.frmChoosePayout.METHOD.value;

   //Check for just whole dollars are used
   var dollars = "^[$]?([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)$";
   var dollarsExp = new RegExp(dollars);

   //Check for both dollars and cents
   var cents = "^[$]?([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)(.[0-9][0-9])?$";
   var centsExp = new RegExp(cents);


   if (amount == "" || ( !amount.match(dollarsExp) && !amount.match(centsExp)  ) ){
      errorMessage += 'Please enter a valid value for "Amount".\n';
   }

   if (!amount.match(dollarsExp) && method != "<%=InstrumentType.BANK_ACCOUNT.getCode().toString()%>"){
      errorMessage += 'Do not enter cents. Only enter the dollar amount.\n';
   }

   if (errorMessage != ""){
      alert("Please correct the following problems before continuing: \n\n" + errorMessage);
      return false;
   } else {
      return true;
   }

}

function clearInputControls() {
	//reset all the fields
 	var inputControls = document.getElementsByTagName('input')
	for(var i=0;i<inputControls.length;i++){
		if (inputControls[i].type == 'TEXT'){
    		inputControls[i].className  = 'form-field';
		}
	}
}

function clearErrorMessages() {
	//reset all the error fields
	var errorMessages = document.getElementsByTagName('div')
	for(var i=0;i<errorMessages.length;i++){

		if (errorMessages[i].id.indexOf("error-message-") == 0){
		    errorMessages[i].style.display = "none";
		} 
		
		if (errorMessages[i].id.indexOf("error-description-") == 0){
		    errorMessages[i].style.display = "none";
		} 

	}
}


function validateRegistrationForm(type, minAmountValue, maxAmountValue ) {
	clearInputControls();
	clearErrorMessages();
	
   	var routingNumber = document.getElementById('routingNumber-DBT-registration').value;
   	var accountNumber = document.getElementById('instrumentNumber-DBT-registration').value;
   	var confirmNumber = document.getElementById('BANK_ACCOUNT_NUMBER_COPY-DBT-registration').value;
  	var checkNumber = document.getElementById('CHECK_NUMBER-DBT-registration').value
   	var amount = document.getElementById('amount-DBT-registration').value;

   	var isValidated = true;

	// if deposit, need to check if greater than or equal to 20 dollars.
	var minAmount = 20;
	var maxAmount = 500;		

	if (minAmountValue != null && minAmountValue != ""){
		minAmount = minAmountValue;
	}
	
	if (maxAmountValue != null && maxAmountValue != ""){
		maxAmount = maxAmountValue;	
	}	
	
   //first check if terms have been checked
   var chkTerms = document.getElementById('agreeToTerms');
   if (!chkTerms.checked){
		var accountNumberErrorMessage = document.getElementById('error-message-DBT-registration-terms');
		accountNumberErrorMessage.style.display = 'block';
		var accountNumberErrorDescription = document.getElementById('error-description-DBT-registration-terms');
		accountNumberErrorDescription.style.display = 'block';	
		isValidated = false;		
   }


     if (checkNumber == "" || !IsNumeric(checkNumber) ){
                var checkNumberControl = document.getElementById('CHECK_NUMBER-DBT-registration');
                checkNumberControl.className = 'form-field-error';
                var checkNumberErrorMessage = document.getElementById('error-message-DBT-registration-checkNumberError');
                checkNumberErrorMessage.style.display = 'block';
                var checkNumberErrorDescription = document.getElementById('error-description-DBT-registration-checkNumberError');
                checkNumberErrorDescription.style.display = 'block';				
				isValidated = false;		
        }



   //Check for empty values or non numeric values
   if (routingNumber == "" || !IsNumeric(routingNumber) || routingNumber.length != 9){
		var routingNumberControl = document.getElementById('routingNumber-DBT-registration');
		routingNumberControl.className = 'form-field-error';		  
		var accountNumberErrorMessage = document.getElementById('error-message-DBT-registration-missing-routing-number');
		accountNumberErrorMessage.style.display = 'block';
		var accountNumberErrorDescription = document.getElementById('error-description-DBT-registration-missing-routing-number');
		accountNumberErrorDescription.style.display = 'block';	
		isValidated = false;				
   }

   if (accountNumber == "" || !IsNumeric(accountNumber) ){
		var accountControl = document.getElementById('instrumentNumber-DBT-registration');
		accountControl.className = 'form-field-error';		  
		var accountNumberErrorMessage = document.getElementById('error-message-DBT-registration-missing-account-number');
		accountNumberErrorMessage.style.display = 'block';
		var accountNumberErrorDescription = document.getElementById('error-description-DBT-registration-missing-account-number');
		accountNumberErrorDescription.style.display = 'block';	
		isValidated = false;				
   }

   	if (confirmNumber == "" || !IsNumeric(confirmNumber) || accountNumber != confirmNumber ){
		
		var accountControl = document.getElementById('BANK_ACCOUNT_NUMBER_COPY-DBT-registration');
		accountControl.className = 'form-field-error';		  
		var accountNumberErrorMessage = document.getElementById('error-message-DBT-registration-missing-account-confirm-number');
		accountNumberErrorMessage.style.display = 'block';
		var accountNumberErrorDescription = document.getElementById('error-description-DBT-registration-missing-account-confirm-number');
		accountNumberErrorDescription.style.display = 'block';		
		
		// BD-2791 Request to clear both fields in case of this issue.
		accountControl.value = "";
		accountControl = document.getElementById('instrumentNumber-DBT-registration');		
		accountControl.className = 'form-field-error';		  		
		accountControl.value = "";
				
		isValidated = false;																						   
   	}
   
  	//Check for just whole dollars are used
   	var dollars = "^[$]?([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)$";
   	var dollarsExp = new RegExp(dollars);  
   
   	if (amount == "" ||  !amount.match(dollarsExp)){
		var amountControl = document.getElementById('amount-DBT-registration');
		amountControl.className = 'form-field-error';		
		var amountErrorMessage = document.getElementById('error-message-DBT-registration-not-valid');
		amountErrorMessage.style.display = 'block';
		var amountErrorDescription = document.getElementById('error-description-DBT-registration-not-valid');
		amountErrorDescription.style.display = 'block';	  
		isValidated = false;				
   	}

   	if (type == 'DEPOSIT' && amount != "" && amount < minAmount){
		var amountControl = document.getElementById('amount-DBT-registration');
		amountControl.className = 'form-field-error';		   
		var amountErrorMessage = document.getElementById('error-message-DBT-registration-below-limit');
		amountErrorMessage.style.display = 'block';
		var amountErrorDescription = document.getElementById('error-description-DBT-registration-below-limit');
		amountErrorDescription.style.display = 'block';	
		isValidated = false;				
   	}

   	if (type == 'DEPOSIT' && amount != "" && amount > maxAmount){
	
		var amountControl = document.getElementById('amount-DBT-registration');
		amountControl.className = 'form-field-error';		   
		var amountErrorMessage = document.getElementById('error-message-DBT-registration-above-limit');
		amountErrorMessage.style.display = 'block';
		var amountErrorDescription = document.getElementById('error-description-DBT-registration-above-limit');
		amountErrorDescription.style.display = 'block';	
		isValidated = false;				
   	}
	
	//confirmation popup for deposits
	if (type == 'DEPOSIT' && isValidated == true){
		isValidated = confirmDepositAmount( amount , 'DBT' );	
	}
	
	// IE Snare integration
	if (type == 'DEPOSIT' && isValidated){

			var ioBlackBox_value = document.getElementById('ioBlackBox').value;	
			var ioBlackBox_form_value = document.getElementById('ioBlackBox-DBT-registration');	
			
			if (ioBlackBox_form_value){
				ioBlackBox_form_value.value = ioBlackBox_value;
			}
	}
					
	return isValidated;		

}

function IsNumeric(strString)
   //  check for valid numeric strings
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }


function validateTransactionForm( method, type, minAmountValue, maxAmountValue ) {

	clearInputControls();
	clearErrorMessages();

	var amountControl = document.getElementById('amount-' + method);
	var amount = ""; 			
	var isValidated = true;

	if (amountControl){
		amount = amountControl.value;		
	}
	
   	//Check for just whole dollars are used
   	var dollars = "^[$]?([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)$";
   	var dollarsExp = new RegExp(dollars);
	
   	//Check for both dollars and cents
   	//var cents = "^[$]?([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)(.[0-9][0-9])?$";
   	//var centsExp = new RegExp(cents);
	
	// 
	// Validate Amount Field (common to all panels)
	//
	// if deposit, need to check if greater than or equal to 20 dollars.
	var minAmount = 20;
	var maxAmount = 500;		
	
	if (minAmountValue != null && minAmountValue != ""){
		minAmount = minAmountValue;
	}
	
	if (maxAmountValue != null && maxAmountValue != ""){
		maxAmount = maxAmountValue;	
	}
	
	
	
	if (amount < minAmount || amount == ""){
		var amountControl = document.getElementById('amount-' + method);
		amountControl.className = 'form-field-error';		   
   		var messageError = document.getElementById('error-message-' + method + '-below-limit');
   		messageError.style.display = 'block';
   		var descriptionError = document.getElementById('error-description-' + method + '-below-limit');
   		descriptionError.style.display = 'block';
		isValidated = false;			
	}
	
	
   	if (!dollarsExp.test(amount) && isValidated ){
		var amountControl = document.getElementById('amount-' + method);
		amountControl.className = 'form-field-error';		   	
		var messageError = document.getElementById('error-message-' + method + '-not-valid');
		messageError.style.display = 'block';
		var descriptionError = document.getElementById('error-description-' + method + '-not-valid');
  		descriptionError.style.display = 'block';
		isValidated = false;
   	}
	
	
	if ((type == 'DEPOSIT' && isValidated) || (type == 'PAYOUT' && method == 'WU' && isValidated) ){
		
		var isOverLimit = false;

		if (amount > maxAmount){
			isOverLimit = true;
		}
			
		if (isOverLimit){
			var amountControl = document.getElementById('amount-' + method);
			amountControl.className = 'form-field-error';		   
	   		var messageError = document.getElementById('error-message-' + method + '-above-limit');
	   		messageError.style.display = 'block';
	   		var descriptionError = document.getElementById('error-description-' + method + '-above-limit');
	   		descriptionError.style.display = 'block';
			isValidated = false;			
		}
	}
	
	if (type == 'PAYOUT' ){
		var agreeToTermsAddress = document.getElementById('agreeToTermsAddress-' + method);
		if(!agreeToTermsAddress.checked){
			
	   		var messageError = document.getElementById('error-message-agreetoTermsAddress-' + method);
			messageError.style.display = 'block';

	   		var descriptionError = document.getElementById('error-description-agreetoTermsAddress-' + method);
	   		descriptionError.style.display = 'block';
			isValidated = false;
		
		}
		
		
	}
	



	// Validate EXTERNAL_ACCOUNT_NUMBER (all methods except Credit Card)
	
	// Validate EXTERNAL_ACCOUNT_PASSWORD (Neteller, Coincentral, Citadel)
	
	// Validate INSTRUMENT_NUMBER (Firepay)
	
	// Validate CARD_NUMBER (Credit Card)
	
	// Validate CARD_CVV2 (Credit Card)
	
	//confirmation popup for deposits


	if (type == 'DEPOSIT' && isValidated == true){
		isValidated = confirmDepositAmount( amount , method );	
	}
	
	// IE Snare integration
	if (type == 'DEPOSIT' && isValidated ){
			var ioBlackBox_value = document.getElementById('ioBlackBox').value;	
			var ioBlackBox_form_value = document.getElementById('ioBlackBox-' + method);	
			if (ioBlackBox_form_value){
				ioBlackBox_form_value.value = ioBlackBox_value;
			}
	}

	return isValidated;
}

 
function validateAmount (control) {

	//remove all error messages
	clearInputControls();
	clearErrorMessages();

	var amountControl = document.getElementById(control);
	var amount = ""; 			

	if (amountControl){
		amount = amountControl.value;		
	}
	
	if (amount == ""){
		var amountControl = document.getElementById(control);
		amountControl.className = 'form-field-error';		   
   		var messageError = document.getElementById('error-message-' + control + '-empty');
   		messageError.style.display = 'block';
   		var descriptionError = document.getElementById('error-description-' + control + '-empty');
   		descriptionError.style.display = 'block';
		return false;		
	
	}
	
   	//Check for just whole dollars are used
   	var dollars = "^[$]?([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)$";
   	var dollarsExp = new RegExp(dollars);
	
	if (amount < 1){
		var amountControl = document.getElementById(control);
		amountControl.className = 'form-field-error';		   
   		var messageError = document.getElementById('error-message-' + control + '-below-limit');
   		messageError.style.display = 'block';
   		var descriptionError = document.getElementById('error-description-' + control + '-below-limit');
   		descriptionError.style.display = 'block';
		return false;		
	
	}
	
   	if (!amount || !dollarsExp.test(amount) ){
		var amountControl = document.getElementById(control);
		amountControl.className = 'form-field-error';		   	
		var messageError = document.getElementById('error-message-' + control + '-not-valid');
		messageError.style.display = 'block';
		var descriptionError = document.getElementById('error-description-' + control + '-not-valid');
  		descriptionError.style.display = 'block';
		return false;
   	}	
	

	
	return true;

	
}




//  Start Scripts used by changeProfile.jsp

var FIELD_NAME = 0;
var FIELD_TYPE = 1;
var TEXT = 0;
var CHECKBOX = 1;
var DROPDOWN = 2;

var REQ_CHANGE_PROFILE_FIELDS = 9;

var requiredChangeProfileFields = new Array(REQ_CHANGE_PROFILE_FIELDS);

for (var i=0;i<REQ_CHANGE_PROFILE_FIELDS;i++) {
	requiredChangeProfileFields[i] = new Array(2);
}

requiredChangeProfileFields[0] =  new Array ( 'email', TEXT );
requiredChangeProfileFields[1] =  new Array ( 'address1', TEXT );
requiredChangeProfileFields[2] =  new Array ( 'city', TEXT );
requiredChangeProfileFields[3] =  new Array ( 'state', TEXT );
requiredChangeProfileFields[4] =  new Array ( 'zipcode', TEXT );
requiredChangeProfileFields[5] =  new Array ( 'phone1', TEXT );
requiredChangeProfileFields[6] =  new Array ( 'phone1usage', DROPDOWN );
requiredChangeProfileFields[7] =  new Array ( 'phone2usage', DROPDOWN );
requiredChangeProfileFields[8] =  new Array ( 'challenge1', TEXT );


function validateChangeProfile(revalidate) {

	var success = true;
	firstErrorField = -1

	// reset all fields
	for (var n=0;n<REQ_CHANGE_PROFILE_FIELDS;n++) {
		   showNormalChangeProfile(n);	
	}
	
	for (var n=0;n<REQ_CHANGE_PROFILE_FIELDS;n++) {
			if (!completeChangeProfile(n)) {
			   showErrorChangeProfile(n);
			   success = false;
			   
			   if (firstErrorField == -1){
			      firstErrorField = n;
			   }   
			} 
	}

	/* Canada check */
	var objCountry = document.getElementById('country');	
	if (objCountry.value == 'CA'){
		success = false;
	}

/*
	if (!success && !revalidate) {
		focusFirstError();
	}
*/
	return success;
}

function showNormalChangeProfile(elementIndex){
	var objErrArrow;
	var objErrStar;
	var objErrLabel;
	var objErrFormField;
	var objErrMessage;
	var objErrDescription;
	var tmpFieldName;

	objErrFormField = document.getElementById(requiredChangeProfileFields[elementIndex][FIELD_NAME]);
	objErrMessage = document.getElementById('error-message-' + requiredChangeProfileFields[elementIndex][FIELD_NAME]);
	objErrDescription = document.getElementById('error-description-' + requiredChangeProfileFields[elementIndex][FIELD_NAME]);

	tmpFieldName = requiredChangeProfileFields[elementIndex][FIELD_NAME];

	if(tmpFieldName == 'phone1usage'){
		tmpFieldName = 'phone1';
	}
	
	objErrStar = document.images['error-star-' + tmpFieldName];
	objErrArrow = document.getElementById('error-arrow-' + tmpFieldName);
	objErrLabel = document.getElementById('error-label-' + tmpFieldName);

	
	if (objErrArrow) objErrArrow.style.display = 'none';
	if (objErrFormField && requiredChangeProfileFields[elementIndex][FIELD_TYPE] == TEXT) objErrFormField.className = 'form-field';
	if (objErrFormField && requiredChangeProfileFields[elementIndex][FIELD_TYPE] == DROPDOWN) objErrFormField.className = 'form-field';
	if (objErrStar) objErrStar.src = '/images/join/required.gif';

	if (objErrLabel) objErrLabel.className = 'form-field-label';
	
	if (objErrMessage) {
		//objErrMessage.className = 'error-message';
		objErrMessage.style.display = 'none';
	}
	if (objErrDescription) {
		//objErrDescription.className = 'error-description';
		objErrDescription.style.display = 'none';
	}
	
}

function completeChangeProfile(elementIndex) {

	var objRequired;
	objRequired = document.getElementById(requiredChangeProfileFields[elementIndex][FIELD_NAME]);

	if (requiredChangeProfileFields[elementIndex][FIELD_NAME] == 'phone2usage'){
		var objPhone2 = document.getElementById('phone2');
		if (objPhone2.value == ''){
			return true;
		}
	}

	
	switch (requiredChangeProfileFields[elementIndex][FIELD_TYPE]) {
		case TEXT:
			if (objRequired.value == '') return false;
			break;
		case CHECKBOX:
			if (objRequired.checked == false) return false;			
			break;
		case DROPDOWN:
			if (objRequired.value == '') return false;
			break;
	}

	// Return true by default to remove chance of form being impossible to submit

	return true;
}

function showErrorChangeProfile(elementIndex) {

	var objErrArrow;
	var objErrStar;
	var objErrLabel;
	var objErrFormField;
	var objErrMessage;
	var objErrDescription;	
	var tmpFieldName;
	
	objErrFormField = document.getElementById(requiredChangeProfileFields[elementIndex][FIELD_NAME]);
	objErrMessage = document.getElementById('error-message-' + requiredChangeProfileFields[elementIndex][FIELD_NAME]);
	objErrDescription = document.getElementById('error-description-' + requiredChangeProfileFields[elementIndex][FIELD_NAME]);
	
	tmpFieldName = requiredChangeProfileFields[elementIndex][FIELD_NAME];
	
	if(tmpFieldName == 'phone1usage'){
		tmpFieldName = 'phone1';
	}

	objErrStar = document.images['error-star-' + tmpFieldName];
	objErrArrow = document.getElementById('error-arrow-' + tmpFieldName);
	objErrLabel = document.getElementById('error-label-' + tmpFieldName);
	
	if (objErrArrow) objErrArrow.style.display = 'block';
	if (objErrFormField && requiredChangeProfileFields[elementIndex][FIELD_TYPE] == TEXT) objErrFormField.className = 'form-field-error';
	if (objErrFormField && requiredChangeProfileFields[elementIndex][FIELD_TYPE] == DROPDOWN) objErrFormField.className = 'form-field-error';
	if (objErrStar) objErrStar.src = '/images/join/error-required.gif';

	if (objErrLabel) objErrLabel.className = 'form-field-label-error';
	
	if (objErrMessage) {
		objErrMessage.style.display = 'block';
	}

	if (objErrDescription) {
		objErrDescription.style.display = 'block';
	}

}

function countrySelect(value){       

	objErrFormField = document.getElementById('country');
	objErrLabel = document.getElementById('error-label-country');
	objErrMessage = document.getElementById('error-message-canada');
	objErrDescription = document.getElementById('error-description-canada');
	objErrStar = document.images['error-star-country'];

	if (value == 'CA'){		
		objErrMessage.style.display = 'block';
		objErrDescription.style.display = 'block';
		objErrStar.src = '/images/join/error-required.gif';	
		objErrFormField.className = 'form-field-error';
		objErrLabel.className = 'form-field-label-error'							
	} else {
		objErrMessage.style.display = 'none';
		objErrDescription.style.display = 'none';
		objErrStar.src = '/images/join/required.gif';	
		objErrFormField.className = 'form-field';
		objErrLabel.className = 'form-field-label'								
	}
}


<!--

var REQ_FIELDS = 15;

var DOB_DAY_INDEX = 3;
var DOB_DAY_ACTIVATED = false;
var DOB_YEAR_INDEX = 4;

var COMBINED_DATE = 'dobdate';

var requiredFields = new Array(REQ_FIELDS);
for (var i=0;i<REQ_FIELDS;i++) {
	requiredFields[i] = new Array(2);
}

requiredFields[0] =  new Array ( 'firstName', TEXT );
requiredFields[1] =  new Array ( 'lastName', TEXT );
requiredFields[2] =  new Array ( 'email', TEXT );
requiredFields[3] =  new Array ( 'dobday', TEXT );
requiredFields[4] =  new Array ( 'dobyear', TEXT );
requiredFields[5] =  new Array ( 'country', DROPDOWN );
requiredFields[6] =  new Array ( 'address1', TEXT );
requiredFields[7] =  new Array ( 'city', TEXT );
requiredFields[8] =  new Array ( 'zip', TEXT );
requiredFields[9] =  new Array ( 'phoneprimary', TEXT );
requiredFields[10] = new Array ( 'phoneprimaryusage', DROPDOWN );
requiredFields[11] = new Array ( 'phone2usage', DROPDOWN );
requiredFields[12] = new Array ( 'maiden', TEXT );
requiredFields[13] = new Array ( 'cityborn', TEXT );
requiredFields[14] = new Array ( 'agreeToTermsJoin', CHECKBOX );

var firstErrorField = -1;

function validateAccountCompleteForm(revalidate) {

	var success = true;
	firstErrorField = -1
	DOB_DAY_ACTIVATED = false;
	
	// reset all fields
	for (var n=0;n<REQ_FIELDS;n++) {
		   showNormal(n);	
	}
	
	showNormalOptional();

	// find errors	
	for (var n=0;n<REQ_FIELDS;n++) {
			if (!complete(n)) {
			   showError(n);
			   success = false;
			   
			   if (firstErrorField == -1){
			      firstErrorField = n;
			   }   
			} 
	}

	if (!success && !revalidate) {
		focusFirstError();
	} else {
		// horrible hack till it's fixed in esportz
		objRequired = document.getElementById('optinmail');	
		if (objRequired.checked){
			document.forms['join'].directMailOptin.value = 'true';
		} else {
			document.forms['join'].directMailOptin.value = 'false';
		}	
	}        

	return success;
}



function focusFirstError() {
	var objFormField;
	objFormField = document.forms['join'].elements[requiredFields[firstErrorField][FIELD_NAME]];	
	if (objFormField) {
		objFormField.focus();
	}

}


function complete(elementIndex) {

	var objRequired;
	
	if (requiredFields[elementIndex][FIELD_NAME] == 'phone2usage'){
		var objPhone2 = document.getElementById('phonesecond');
		if (objPhone2.value == ''){
			return true;
		}
	}

	objRequired = document.getElementById(requiredFields[elementIndex][FIELD_NAME]);

	//basic Date of Birth day check
	if (elementIndex == DOB_DAY_INDEX){
		if (objRequired.value > 31 || objRequired.value < 1){
			return false;
		}
	}
	
	switch (requiredFields[elementIndex][FIELD_TYPE]) {
		case TEXT:
			if (objRequired.value == '') return false;
			break;
		case CHECKBOX:
			if (objRequired.checked == false) return false;			
			break;
		case DROPDOWN:
			if (objRequired.value == '') return false;
			break;
	}
	
	
	// Return true by default to remove chance of form being impossible to submit

	return true;
}

function showNormal(elementIndex){
	var objErrArrow;
	var objErrStar;
	var objErrLabel;
	var objErrFormField;
	var objErrMessage;
	var objErrDescription;
	var tmpFieldName;

	objErrFormField = document.getElementById(requiredFields[elementIndex][FIELD_NAME]);
	objErrMessage = document.getElementById('error-message-' + requiredFields[elementIndex][FIELD_NAME]);
	objErrDescription = document.getElementById('error-description-' + requiredFields[elementIndex][FIELD_NAME]);

	if (requiredFields[elementIndex][FIELD_NAME].indexOf('dob') != -1) {
		tmpFieldName = 'dob';
	} else {
		tmpFieldName = requiredFields[elementIndex][FIELD_NAME];
	}

	objErrStar = document.images['error-star-' + tmpFieldName];
	objErrArrow = document.getElementById('error-arrow-' + tmpFieldName);
	objErrLabel = document.getElementById('error-label-' + tmpFieldName);
	
	if (objErrArrow) objErrArrow.style.display = 'none';
	if (objErrFormField && requiredFields[elementIndex][FIELD_TYPE] == TEXT) objErrFormField.className = 'form-field';
	if (objErrFormField && requiredFields[elementIndex][FIELD_TYPE] == DROPDOWN) objErrFormField.className = 'form-field';

	if (objErrStar) {
		if (objErrStar.src.indexOf('required2') != -1)
			objErrStar.src = '/images/join/required2.gif';
		else
			objErrStar.src = '/images/join/required.gif';
	}
	
	if (objErrLabel) objErrLabel.className = 'form-field-label';
	
	if (objErrMessage) {
		//objErrMessage.className = 'error-message';
		objErrMessage.style.display = 'none';
	}
	if (objErrDescription) {
		//objErrDescription.className = 'error-description';
		objErrDescription.style.display = 'none';
	}

}

function showNormalOptional(){

	var objErrMessage;
	var objErrDescription;

	objErrMessage = document.getElementById('error-message-dobdate');
	objErrDescription = document.getElementById('error-description-dobdate');
	
	if (objErrMessage) {
		objErrMessage.style.display = 'none';
	}
	if (objErrDescription) {
		objErrDescription.style.display = 'none';
	}
}


function showError(elementIndex) {

	var objErrArrow;
	var objErrStar;
	var objErrLabel;
	var objErrFormField;
	var objErrMessage;
	var objErrDescription;	
	var tmpFieldName;
	
	objErrFormField = document.getElementById(requiredFields[elementIndex][FIELD_NAME]);
	objErrMessage = document.getElementById('error-message-' + requiredFields[elementIndex][FIELD_NAME]);
	objErrDescription = document.getElementById('error-description-' + requiredFields[elementIndex][FIELD_NAME]);
	
	if (requiredFields[elementIndex][FIELD_NAME].indexOf('dob') != -1) {
		tmpFieldName = 'dob';
	} else {
		tmpFieldName = requiredFields[elementIndex][FIELD_NAME];
	}

	//objErrStar = document.images['error-star-' + tmpFieldName];
	//objErrArrow = document.getElementById('error-arrow-' + tmpFieldName);
	//objErrLabel = document.getElementById('error-label-' + tmpFieldName);


	if (objErrArrow) objErrArrow.style.display = 'block';
	if (objErrFormField && requiredFields[elementIndex][FIELD_TYPE] == TEXT) objErrFormField.className = 'form-field-error';
	if (objErrFormField && requiredFields[elementIndex][FIELD_TYPE] == DROPDOWN) objErrFormField.className = 'form-field-error';


	if (objErrStar) {
		if (objErrStar.src.indexOf('required2') != -1)
			objErrStar.src = '/images/join/error-required2.gif';
		else
			objErrStar.src = '/images/join/error-required.gif';
	}

	if (elementIndex == DOB_DAY_INDEX){
		DOB_DAY_ACTIVATED = true;	
	}
	

	// if day is already activated, need to turn off day error and activate combined day/year error
	// else just turn on year error
    if (DOB_DAY_ACTIVATED && DOB_YEAR_INDEX == elementIndex){
		objErrMessage = document.getElementById('error-message-' + requiredFields[DOB_DAY_INDEX][FIELD_NAME]);
		objErrDescription = document.getElementById('error-description-' + requiredFields[DOB_DAY_INDEX][FIELD_NAME]);
		objErrMessage.style.display = 'none';
		objErrDescription.style.display = 'none';		
		
		objErrMessage = document.getElementById('error-message-' + COMBINED_DATE);
		objErrDescription = document.getElementById('error-description-' + COMBINED_DATE);
    } 

	if (objErrLabel) objErrLabel.className = 'form-field-label-error';
	
	//alert(objErrMessage.id + ":" + objErrMessage.innerHTML);
	//alert(objErrDescription.id + ":" + objErrDescription.innerHTML);
	if (objErrMessage) {
		//objErrMessage.className = 'error-message';
		objErrMessage.style.display = 'block';
	}

	if (objErrDescription) {
		//objErrDescription.className = 'error-description';
		objErrDescription.style.display = 'block';
	}

}


function showServerError(value, message, countryPost){


         if (countryPost != null){
            if (countryPost == 'true'){
               return "";
            }
         }   

         //Uses the index of the required fields.
         var errorIndex = -1;
         var objErrMessage;

         switch(value){
            case(value = 'firstName'):
               errorIndex = 0; break;
            case(value = 'lastName'):
               errorIndex = 1; break;
            case(value = 'email'):
               errorIndex = 2; break;
            case(value = 'birthday'):
               errorIndex = 4; break;
            case(value = 'country'):
               errorIndex = 5; break;
            case(value = 'addressLine1'):
               errorIndex = 6; break;
            case(value = 'city'):
               errorIndex = 7; break;
            case(value = 'zipCode'):
               errorIndex = 8; break;
            case(value = 'phone1'):
               errorIndex = 9; break;
            case(value = 'phone2'):
               errorIndex = 9; break;
            case(value = 'challengeAnswer1'):
               errorIndex = 12; break;
            case(value = 'challengeAnswer2'):
               errorIndex = 13; break;
            case(value = 'referralInfo'):
               errorIndex = 14; break;
         }

         if (errorIndex > -1){
            showError(errorIndex);
            objErrMessage = document.getElementById('general-error');
            if (objErrMessage) objErrMessage.style.display = 'none';
           
	    if (firstErrorField == -1){
		firstErrorField = errorIndex;
	    }
		
			
         } else {
            objErrMessage = document.getElementById('general-error');
            if (objErrMessage) objErrMessage.style.display = 'block';
            return message;
         }
}


//  End Scripts used by changeProfile.jsp

function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function getDeliveryDateObj(startDate, businessDaysLeftForDelivery) {
  var now = new Date(startDate);
  var dayOfTheWeek = now.getDay(); 
  var calendarDays = businessDaysLeftForDelivery;

  var deliveryDay = dayOfTheWeek + businessDaysLeftForDelivery;
  if (deliveryDay >= 6) {
    businessDaysLeftForDelivery -= 6 - dayOfTheWeek;  //deduct this-week days
	calendarDays += 2;  //count this coming weekend
	deliveryWeeks = Math.floor(businessDaysLeftForDelivery / 5); //how many whole weeks?
	calendarDays += deliveryWeeks * 2;  //two days per weekend per week
  }
  
  now.setTime(now.getTime() + calendarDays * 24 * 60 * 60 * 1000);
  
  var pendingMonth = now.getMonth()+1;
  if (pendingMonth < 10){
    pendingMonth = "0" + pendingMonth;
  }
  
  var pendingDay = now.getDate();
  if (pendingDay < 10){
  	pendingDay = "0" + pendingDay;
  }
 
  document.write(pendingMonth + '/' + pendingDay + '/' + y2k(now.getYear()));
}


/* CASINO ACCOUNT */

var activehelp = "";
var activeicon = "";
function showHelp(img, id) {

	if (activehelp) {
		document.getElementById("help-"+activehelp).style.display = "none" ;
		activeicon.childNodes[0].style.display = "block" ;
	}
	document.getElementById('acct-line').style.backgroundImage = "url('/images/casino/acct-line-"+id+".gif')";
	//document['acct-line'].src = "/images/casino/acct-line-"+id+".gif";
	document.getElementById("help-"+id).style.display = "block" ;
	img.childNodes[0].style.display = "none" ;
	
	activehelp = id ;
	activeicon = img ;
}
