﻿var acceptTermsValidatorControlID = '';//'valAcceptTerms';
var acceptTermsControlID = '';//'AcceptTerms';
var _cbCountryControlID='';
var _cbStateCotrolID='';
var _stateValidatorControlID='';


function CheckTermsAgreement()
{
    var isAgreeTermsChecked = getCheckboxChecked(document.forms[0].elements, acceptTermsControlID);
    
    if (isAgreeTermsChecked)
    {
        // hide the validation error
        //document.getElementById(acceptTermsValidatorControlID).firstChild.data = ' ';
        document.getElementById(acceptTermsValidatorControlID).innerHTML = ' ';
    }
    else
    {
        document.getElementById(acceptTermsValidatorControlID).innerHTML = '<br/> You must accept the Terms of Service before you can register.';
        //document.getElementById(acceptTermsValidatorControlID).firstChild.data = 'You must accept the Terms of Service.';
    }
}

function checkPasswordLength(source, arguments)
{
    var password = arguments.Value;
    if (password != null && password.length >= 5)
    {
        arguments.IsValid = true;
    }
    else
    {
        arguments.IsValid = false;
    }
}

function checkCountrySelection(source, arguments)
{     
    var _coutry=getSelectValue(document.forms[0].elements, _cbCountryControlID); 
    arguments.IsValid = (_coutry != 'AA');   
}

function checkStateSelection(source, arguments)
{   
    var _result=true;
    var _coutry=getSelectValue(document.forms[0].elements, _cbCountryControlID);
    var _state=getSelectValue(document.forms[0].elements, _cbStateCotrolID);    
    if(_coutry=='US')
    {
        if(_state=='AA'||_state=='A1')
        {
                _result=false;
        }
    }else
    {
        if(_state=='AA')
        {
            _result=false;
        }
    }
    arguments.IsValid =_result;
}

function ChangeCountry(_value)
{
    var _stateControl=document.getElementById(_cbStateCotrolID);
    
    callbackState.callback(_value);    
}


function checkConfirmPasswordAnswer(source, arguments)
{
    var confirmPasswordAnswerValue = getControlValue(document.forms[0].elements, 'ConfirmPasswordAnswer');
    var passwordAnswerValue = arguments.Value;
    arguments.IsValid = (passwordAnswerValue.length == 0) || (confirmPasswordAnswerValue.length > 0);
}

function checkAcceptTerms(source, arguments)
{
    var isAcceptTermsChecked = getCheckboxChecked(document.forms[0].elements, acceptTermsControlID);
    arguments.IsValid = isAcceptTermsChecked;
}

function handleStateError() { 
    // Just dummy handler to prevent error message popup
}
