﻿var SIGN_UP_SUMMARY;
String.prototype.replaceAll = function(stringToReplace, replaceString) {
    var val = this;
    while(val.indexOf(stringToReplace,0) > 0){
         val = val.replace(stringToReplace, replaceString);
    }
    return val;
}
function clearTable(tableName){
    var table = $get(tableName);
    if(table)
    {
		while(table.rows.length > 0)
		{		    
		    clearTableRow(table.rows[0])
			table.deleteRow(0);
		}
    }
}
function clearTableRow(el){
    if(el.childNodes.length > 0){
        while(el.childNodes.length > 0){
            clearTableRow(el.childNodes[0]);
        }
    }else{
        el.parentNode.removeChild(el);
    }
    return;
}
function toggleDiv(divId) {
    var el = $get(divId);
    if (el.style.display == 'none') {
        el.style.display = 'block';
    } else {
        el.style.display = 'none';
    }
}
function updateAddPhoneList(){
    var tbl = $get("tblAdditionalPhoneNumbers");
    if(tbl.rows.length > 0){
        var el = $get(contentId + '_addPhoneNumbers');
        var cell;
        var ary1 = new Array();
        var ary2 = new Array();
        var ary3 = new Array();
        var count = tbl.rows.length;        
        for(i = 0; i < count; ++i){
            cell = tbl.rows[i].cells[1];
            for(x = 0; x < cell.childNodes.length; x++){
                if(cell.childNodes[x].nodeType == 1){
                    if(cell.childNodes[x].id.substr(0, 9) == "addPhone1")
                        ary1[i] = cell.childNodes[x].value;
                    if(cell.childNodes[x].id.substr(0, 9) == "addPhone2")
                        ary2[i] = cell.childNodes[x].value;
                    if(cell.childNodes[x].id.substr(0, 9) == "addPhone3")
                        ary3[i] = cell.childNodes[x].value;
                }
            }            
        }
        for(i = 0; i < count; ++i){
            el.value += ary1[i] + '-' + ary2[i] + '-' + ary3[i] + '~';
        }
    }
}
function removePhone(index){
    var tbl = $get("tblAdditionalPhoneNumbers");
    var row = tbl.rows[index];
    var cell;
    var ary1 = new Array();
    var ary2 = new Array();
    var ary3 = new Array();
    row.deleteCell(1);
    row.deleteCell(0);
    tbl.deleteRow(index);
    if(tbl.rows.length > 0){
        for(i = 0; i < tbl.rows.length; ++i){
            cell = tbl.rows[i].cells[1];
            for(x = 0; x < cell.childNodes.length; x++){
                if(cell.childNodes[x].nodeType == 1){
                    if(cell.childNodes[x].id.substr(0, 9) == "addPhone1")
                        ary1[i] = cell.childNodes[x].value;
                    if(cell.childNodes[x].id.substr(0, 9) == "addPhone2")
                        ary2[i] = cell.childNodes[x].value;
                    if(cell.childNodes[x].id.substr(0, 9) == "addPhone3")
                        ary3[i] = cell.childNodes[x].value;
                }
            }
        }
        clearTable('tblAdditionalPhoneNumbers');
        for(i = 0; i < ary1.length; ++i){
            addPhone(ary1[i], ary2[i], ary3[i]);
        }
    }
}
function addPhone(phone1, phone2, phone3){
    var tbl = $get("tblAdditionalPhoneNumbers");
    var rowIndex = tbl.rows.length;
    var row = tbl.insertRow(rowIndex);
    var cell = row.insertCell(0);
    cell.innerHTML = '<span id="valPhone" style="color:Red;display:none;">*</span>';
    cell = row.insertCell(1);
    var htm = '( <input id="addPhone1' + rowIndex + '" type="text" maxlength="3" style="width:40px" value="' + phone1 + '" /> ) <input id="addPhone2' + rowIndex + '" type="text" maxlength="3" style="width:40px" value="' + phone2 + '" />&nbsp;- <input id="addPhone3' + rowIndex + '" type="text" maxlength="4" style="width:40px" value="' + phone3 + '" />';
    htm += ' <span class="hoverLink" onclick="removePhone(' + rowIndex + ');"><img src="images/delete.gif" border="0" /></span>';
    cell.innerHTML = htm;    
    $get("addPhone1" + rowIndex).focus();
}
function updateAddEmailList() {
    var tbl = $get("tblAdditionalEmailAddresses");
    if (tbl.rows.length > 0) {
        var el = $get(contentId + '_addEmailAddress');
        var cell;
        var ary = new Array();
        var count = tbl.rows.length;
        for (i = 0; i < count; ++i) {
            cell = tbl.rows[i].cells[1];
            for (x = 0; x < cell.childNodes.length; x++) {
                if (cell.childNodes[x].nodeType == 1) {
                    ary[i] = cell.childNodes[x].value;
                }
            }
        }
        for (i = 0; i < count; ++i) {
            el.value += ary[i] + '~';
        }
    }
}
function removeEmail(index) {
    var tbl = $get("tblAdditionalEmailAddresses");
    var row = tbl.rows[index];
    var cell;
    var ary = new Array();
    row.deleteCell(1);
    row.deleteCell(0);
    tbl.deleteRow(index);
    if (tbl.rows.length > 0) {
        for (i = 0; i < tbl.rows.length; ++i) {
            cell = tbl.rows[i].cells[1];
            for (x = 0; x < cell.childNodes.length; x++) {
                if (cell.childNodes[x].nodeType == 1) {
                    ary[i] = cell.childNodes[x].value;
                }
            }
        }
        clearTable('tblAdditionalEmailAddresses');
        for (i = 0; i < ary.length; ++i) {
            addEmail(ary[i]);
        }
    }
}
function addEmail(email) {
    var tbl = $get("tblAdditionalEmailAddresses");
    var rowIndex = tbl.rows.length;
    var row = tbl.insertRow(rowIndex);
    var cell = row.insertCell(0);
    cell.innerHTML = '<span id="valEmail"' + rowIndex + ' style="color:Red;display:none;">*</span>';
    cell = row.insertCell(1);
    var htm = '<input id="addEmail' + rowIndex + '" type="text" maxlength="255" style="width:150px" value="' + email + '" />';
    htm += ' <span class="hoverLink" onclick="removeEmail(' + rowIndex + ');"><img src="images/delete.gif" border="0" /></span>';
    cell.innerHTML = htm;
    $get("addEmail" + rowIndex).focus();
}
function validateAccount(){
    var valid = true;
    var elSel = false;
    clearAccountValidators();
    var el = $get(contentId + '_txtPassword');
    if(el.value == null || el.value == ''){
        SIGN_UP_SUMMARY.style.display = 'block';
        SIGN_UP_SUMMARY.innerHTML += '- Password is Required.<br />';
        $get('valPassword').style.display = 'block';
        if(!elSel){
            el.focus();
            elSel = true;
        }        
        valid = false;
    }else{
        var el2 = $get(contentId + '_txtPasswordConfirm');
        if(el.value != el2.value){
            SIGN_UP_SUMMARY.style.display = 'block';
            SIGN_UP_SUMMARY.innerHTML += '- Password Does Not Match.<br />';
            $get('valPasswordConfirm').style.display = 'block';
            if(!elSel){
                el.focus();
                elSel = true;
            }             
            valid = false;
        }
    }    
    var el = $get(contentId + '_txtTotalIncome');
    if(el.value == null || el.value == ''){
        SIGN_UP_SUMMARY.style.display = 'block';
        SIGN_UP_SUMMARY.innerHTML += '- Monthly Income is Required.<br />';
        $get('valTotalIncome').style.display = 'block';
        if(!elSel){
            el.focus();
            elSel = true;
        }        
        valid = false;
    }else{
        var num = el.value.replaceAll(',','');
        num = num.replaceAll('$','');
        if(isNaN(num)){
            SIGN_UP_SUMMARY.style.display = 'block';
            SIGN_UP_SUMMARY.innerHTML += '- A Valid Monthly Income is Required.<br />';
            $get('valTotalIncome').style.display = 'block';
            if(!elSel){
                el.focus();
                elSel = true;
            }        
            valid = false;        
        }
    }
    return valid;    
}
function validateBilling() {    
    var valid = true;
    var elSel = false;
    if ($get(contentId + '_divBillingInfo').style.display == 'block') {
        clearBillingValidators();
        var el = $get(contentId + '_txtFirstName');
        if (el.value == null || el.value == '') {
            SIGN_UP_SUMMARY.style.display = 'block';
            SIGN_UP_SUMMARY.innerHTML += '- First Name is Required.<br />';
            $get('valFirstName').style.display = 'block';
            el.focus();
            elSel = true;
            valid = false;
        }
        el = $get(contentId + '_txtLastName');
        if (el.value == null || el.value == '') {
            SIGN_UP_SUMMARY.style.display = 'block';
            SIGN_UP_SUMMARY.innerHTML += '- Last Name is Required.<br />';
            $get('valLastName').style.display = 'block';
            if (!elSel) {
                el.focus();
                elSel = true;
            }
            valid = false;
        }
        if ($get(contentId + '_divBillingAddress').style.display == 'block') {
            el = $get(contentId + '_txtStreet');
            if (el.value == null || el.value == '') {
                SIGN_UP_SUMMARY.style.display = 'block';
                SIGN_UP_SUMMARY.innerHTML += '- Street Address is Required.<br />';
                $get('valStreet').style.display = 'block';
                if (!elSel) {
                    el.focus();
                    elSel = true;
                }
                valid = false;
            }
            el = $get(contentId + '_txtCity');
            if (el.value == null || el.value == '') {
                SIGN_UP_SUMMARY.style.display = 'block';
                SIGN_UP_SUMMARY.innerHTML += '- City is Required.<br />';
                $get('valCity').style.display = 'block';
                if (!elSel) {
                    el.focus();
                    elSel = true;
                }
                valid = false;
            }
            el = $get(contentId + '_lstStates');
            if (el.options[el.selectedIndex].value == null || el.options[el.selectedIndex].value == '') {
                SIGN_UP_SUMMARY.style.display = 'block';
                SIGN_UP_SUMMARY.innerHTML += '- State is Required.<br />';
                $get('valState').style.display = 'block';
                if (!elSel) {
                    el.focus();
                    elSel = true;
                }
                valid = false;
            }
            el = $get(contentId + '_txtZip');
            if (el.value == null || el.value == '') {
                SIGN_UP_SUMMARY.style.display = 'block';
                SIGN_UP_SUMMARY.innerHTML += '- A Valid Zip Code is Required.<br />';
                $get('valZip').style.display = 'block';
                if (!elSel) {
                    el.focus();
                    elSel = true;
                }
                valid = false;
            }
        }
        el = $get(contentId + '_txtCardNumber');
        if (isNaN(el.value) || el.value == '') {
            SIGN_UP_SUMMARY.style.display = 'block';
            SIGN_UP_SUMMARY.innerHTML += '- A Valid Credit Card is Required.<br />';
            $get('valCardNumber').style.display = 'block';
            if (!elSel) {
                el.focus();
                elSel = true;
            }
            valid = false;
        }
        el = $get(contentId + '_txtCVVCode');
        if (isNaN(el.value) || el.value == '') {
            SIGN_UP_SUMMARY.style.display = 'block';
            SIGN_UP_SUMMARY.innerHTML += '- A Valid Credit Card Security Code is Required.<br />';
            $get('valSecurityCode').style.display = 'block';
            if (!elSel) {
                el.focus();
                elSel = true;
            }
            valid = false;
        }
        el = $get(contentId + '_txtCardHoldersEmail');
        if (el.value == null || el.value == '') {
            SIGN_UP_SUMMARY.style.display = 'block';
            SIGN_UP_SUMMARY.innerHTML += '- Card Holders Email Address is Required.<br />';
            $get('valEmail').style.display = 'block';
            if (!elSel) {
                el.focus();
                elSel = true;
            }
            valid = false;
        }
    }
    if ($get('divDebitCard').style.display == 'block') {
        el = $get(contentId + '_txtSocial1');
        var bSSDisplayed = false;
        if (isNaN(el.value) || el.value == '') {
            SIGN_UP_SUMMARY.style.display = 'block';
            SIGN_UP_SUMMARY.innerHTML += '- Valid social security number is required.<br />';
            bSSDisplayed = true;
            $get('valSocial').style.display = 'block';
            if (!elSel) {
                el.focus();
                elSel = true;
            }
            valid = false;
        }
        el = $get(contentId + '_txtSocial2');
        if (isNaN(el.value) || el.value == '') {
            SIGN_UP_SUMMARY.style.display = 'block';
            if (!bSSDisplayed) {
                SIGN_UP_SUMMARY.innerHTML += '- Valid social security number is required.<br />';
                bSSDisplayed = true;
            }
            $get('valSocial').style.display = 'block';
            if (!elSel) {
                el.focus();
                elSel = true;
            }
            valid = false;
        }
        el = $get(contentId + '_txtSocial3');
        if (isNaN(el.value) || el.value == '') {
            SIGN_UP_SUMMARY.style.display = 'block';
            if (!bSSDisplayed) {
                SIGN_UP_SUMMARY.innerHTML += '- Valid social security number is required.<br />';
                bSSDisplayed = true;
            }
            $get('valSocial').style.display = 'block';
            if (!elSel) {
                el.focus();
                elSel = true;
            }
            valid = false;
        }
        el = $get('chkAgree');
        if (! el.checked) {
            $get('valTerms').style.display = 'block';
            if (!elSel) {
                el.focus();
                elSel = true;
            }
            valid = false;
        }                
    }
    return valid;
}
function validateSignup() {    
    var valid = true;
    var elSel = false;
    clearSignupValidaters();
    var el = $get(contentId + '_txtFirstName');
    if(el.value == null || el.value == ''){
        SIGN_UP_SUMMARY.style.display = 'block';
        SIGN_UP_SUMMARY.innerHTML += '- First Name is Required.<br />';
        $get('valFirstName').style.display = 'block';
        el.focus();
        elSel = true;
        valid = false;
    }
    el = $get(contentId + '_txtLastName');
    if(el.value == null || el.value == ''){
        SIGN_UP_SUMMARY.style.display = 'block';
        SIGN_UP_SUMMARY.innerHTML += '- Last Name is Required.<br />';
        $get('valLastName').style.display = 'block';
        if(!elSel){
            el.focus();
            elSel = true;
        }        
        valid = false;
    }
    el = $get(contentId + '_txtStreet');
    if(el.value == null || el.value == ''){
        SIGN_UP_SUMMARY.style.display = 'block';
        SIGN_UP_SUMMARY.innerHTML += '- Street Address is Required.<br />';
        $get('valStreet').style.display = 'block';
        if(!elSel){
            el.focus();
            elSel = true;
        }        
        valid = false;
    }        
    el = $get(contentId + '_txtCity');
    if(el.value == null || el.value == ''){
        SIGN_UP_SUMMARY.style.display = 'block';
        SIGN_UP_SUMMARY.innerHTML += '- City is Required.<br />';
        $get('valCity').style.display = 'block';
        if(!elSel){
            el.focus();
            elSel = true;
        }        
        valid = false;
    }
    el = $get(contentId + '_lstStates');
    if(el.options[el.selectedIndex].value == null || el.options[el.selectedIndex].value == ''){
        SIGN_UP_SUMMARY.style.display = 'block';
        SIGN_UP_SUMMARY.innerHTML += '- State is Required.<br />';
        $get('valState').style.display = 'block';
        if(!elSel){
            el.focus();
            elSel = true;
        }        
        valid = false;
    }
    el = $get(contentId + '_txtZip');
    if(el.value == null || el.value == ''){
        SIGN_UP_SUMMARY.style.display = 'block';
        SIGN_UP_SUMMARY.innerHTML += '- A Valid Zip Code is Required.<br />';
        $get('valZip').style.display = 'block';
        if(!elSel){
            el.focus();
            elSel = true;
        }        
        valid = false;
    }    
    el = $get(contentId + '_txtPhone1');
    var el2 = $get(contentId + '_txtPhone2');
    var el3 = $get(contentId + '_txtPhone3');
    var el4;
    var phoneValid = true;
    if(isNaN(el.value) || el.value ==''){
        phoneValid = false;
        el4 = el;
    }
    if(isNaN(el2.value)||el2.value ==''){
        if(phoneValid)
            el4 = el2;    
        phoneValid = false;
    }    
    if(isNaN(el3.value) || el3.value==''){
        if(phoneValid)
            el4 = el3;    
        phoneValid = false;
    }
    var addPhoneValid = validateSignUpAddPhone(elSel);
    if(!phoneValid || !addPhoneValid){
        SIGN_UP_SUMMARY.style.display = 'block';
        SIGN_UP_SUMMARY.innerHTML += '- A Valid Phone Number is Required.<br />';
        if(!phoneValid){
            $get('valPhone').style.display = 'block';
            if(!elSel){
                el4.focus();
                elSel = true;
            }
        }        
        valid = false;        
    }        
    el = $get(contentId + '_txtEmail');
    if(el.value == null || el.value == ''){
        SIGN_UP_SUMMARY.style.display = 'block';
        SIGN_UP_SUMMARY.innerHTML += '- Email Address is Required.<br />';
        $get('valEmail').style.display = 'block';
        if(!elSel){
            el.focus();
            elSel = true;
        }        
        valid = false;
    }else{
        el2 = $get(contentId + '_txtEmailConfirm');
        if(el.value != el2.value){
            SIGN_UP_SUMMARY.style.display = 'block';
            SIGN_UP_SUMMARY.innerHTML += '- Email Address Does Not Match.<br />';
            $get('valEmail').style.display = 'block';
            if(!elSel){
                el.focus();
                elSel = true;
            }             
            valid = false;
        }
    }
    el = $get('chkAgree');
    if(!el.checked){
        $get('valTerms').style.display = 'block';
        if(!elSel){
            el.focus();
            elSel = true;
        }        
        valid = false;
    }
    if (valid) {        
        var elPlanList;
        if ($get('spnPlanCodeList').style.display == 'block') {
            elPlanList = document.getElementsByName('rdoPlanList');
        } else {
            elPlanList = document.getElementsByName('ctl00$ContentPlaceHolder1$rdoPlanList');
        }
        var selIndex = 0;
        for (var index = 0; index < elPlanList.length; ++index) {
            if (elPlanList[index].checked) {
                selIndex = index;
                break;
            }
        }
        $get(contentId + '_hidPlanIndex').value = selIndex;
    }
    return valid;
}
function validateSignUpAddPhone(elSelected){
    var valid = true;
    var tbl = $get("tblAdditionalPhoneNumbers");
    var count = tbl.rows.length;
    var cell;
    var el;
    var elVal;
    if(count > 0)
    {
        for(var i = 0; i < count; ++i){
            cell = tbl.rows[i].cells[1];
            elVal = tbl.rows[i].cells[0].childNodes[0];
            for(var x = 0; x < cell.childNodes.length; x++){
                if(cell.childNodes[x].nodeType == 1){
                    if(cell.childNodes[x].id.substr(0, 9) == "addPhone1"){                        
                        el = cell.childNodes[x];                        
                        if(isNaN(el.value) || el.value==''){
                            valid = false;                            
                            break;
                        }
                    }
                    if(cell.childNodes[x].id.substr(0, 9) == "addPhone2"){
                        el = cell.childNodes[x];                        
                        if(isNaN(el.value) || el.value==''){
                            valid = false;
                            break;
                        }                        
                    }
                    if(cell.childNodes[x].id.substr(0, 9) == "addPhone3"){
                        el = cell.childNodes[x];                        
                        if(isNaN(el.value) || el.value==''){
                            valid = false;
                            break;
                        }                        
                    }
                }
            }
            if(!valid)
                break;            
        }        
    }   
    if(!valid){
        if(!elSelected)
            el.focus();        
        elVal.style.display = 'block';
    }
    return valid;     
}
function clearSignupValidaters(){
    clearAddressValidators();
    clearAddPhoneValidators();
    $get('valPhone').style.display = "none";
    $get('valEmail').style.display = "none";
    $get('valTerms').style.display = "none";
}
function clearAddPhoneValidators(){
    var tbl = $get("tblAdditionalPhoneNumbers");
    var count = tbl.rows.length;
    if(count > 0)
    {
        for(var i = 0; i < count; ++i){            
            tbl.rows[i].cells[0].childNodes[0].style.display = "none";
        }
    }
}
function clearAddressValidators(){
    SIGN_UP_SUMMARY = $get('valSummary');
    $get('valFirstName').style.display = "none";
    $get('valLastName').style.display = "none";
    $get('valStreet').style.display = "none";
    $get('valCity').style.display = "none";
    $get('valState').style.display = "none";
    $get('valZip').style.display = "none";
    SIGN_UP_SUMMARY.innerHTML = "";
    SIGN_UP_SUMMARY.style.display = "none";    
}
function clearAccountValidators(){
    SIGN_UP_SUMMARY = $get('valSummary');
    $get('valPassword').style.display = "none";
    $get('valTotalIncome').style.display = "none";
    SIGN_UP_SUMMARY.innerHTML = "";
    SIGN_UP_SUMMARY.style.display = "none";        
}
function clearBillingValidators(){
    clearAddressValidators();
    $get('valCardNumber').style.display = "none";
    $get('valEmail').style.display = "none";
    $get('valSocial').style.display = "none";
    $get('valTerms').style.display = 'none';
    $get('valSecurityCode').style.display = 'none';
}
var time;
function waitDisplay(){
   time = setTimeout("signUp()", 4000);
}
function signUp(){
    clearTimeout(time);
    var payload = $get(contentId + '_hidPayload').value;
    SignupService.AddAccount(payload, signUpSuccess, signUpFailure);
}
function signUpSuccess(result) {    
    if (result[0] == "1") {
        $get(contentId + '_hidPayload').value = result[1];
        $get(contentId + '_hidTransactionComplete').value = "1";
        theForm.submit();
    }else{
        signUpDisplayError(result[1]);
    }
}
function signUpFailure(result){
    signUpDisplayError('There was an unexpected error, please hit your browsers back button and try again.');
}
function signUpDisplayError(val){
    $get('pnlProcess').style.display = 'none';
    $get('pnlProcessError').style.display = 'block';
    $get('lblProcessErrorMessage').innerHTML = val;
}
function ValidateUserID(){
    var val = $get(contentId + '_txtUserID').value;
    if(isNaN(val) || val == ''){
        ValidateUserIDMessage('User ID Not Found.');
    }else{
        SignupService.GetCallersEmailAddress(val, ValidateUserIDSuccess, ValidateUserIDFailure);
    }
}
function ValidateUserIDSuccess(result){
    if(result != '')
    {
        SignupService.SendCallerPassword(result, SendCallerPasswordSuccess, SendCallerPasswordFailure);
    }else{
        $get('valUserID').style.display = 'block';
    }
}
function SendCallerPasswordSuccess(result){
    if(result != ''){
        ValidateUserIDMessage('There was an unexpected error.  Please try again.');
    }else{
        $get('divPassReset').style.display = 'none';
        $get('divPassSuccess').style.display = 'block';
    }
}
function SendCallerPasswordFailure(result){
    ValidateUserIDMessage('There was an unexpected error.  Please try again.');
}
function ValidateUserIDFailure(result){
    ValidateUserIDMessage('There was an unexpected error.  Please try again.');
}
function ValidateUserIDMessage(txt){
    var el = $get('valUserID');
    el.innerHTML = txt;
    el.style.display = 'block';    
}
function updatePassword(){
    if(validatePassUpdate()){
        $get(contentId + '_hidSubmit').value = '1';
        theForm.submit();
    }
}
function validatePassUpdate(){
    if($get(contentId + '_txtPassword').value != $get(contentId + '_txtPassConfirm').value){
        $get('valUserID').style.display = 'block';
        return false;
    }else{
        return true;
    }
}
function validateGroupEligibility() {
    var planCode = $get(contentId + '_txtPromoCode').value;
    var groupId = $get('txtGroupId').value;
    var memberId = $get('txtMemberId').value;
    $get('valGroupMembershipIndicator').style.display = 'block';
    SignupService.CheckGroupEligibility(planCode, groupId, memberId, validateGroupEligibility_Return, validateGroupEligibility_Error);
}
function validateGroupEligibility_Return(result) {    
    $get('valGroupMembershipIndicator').style.display = 'none';
    var ary = result.split('&');
    var cid = ary[0].split('=');
    if (cid[1] != '') {
        $get(contentId + '_hidCID').value = cid;
        groupRequest = false;
        next();
    } else {
        $get('spnValidateMember').style.display = 'block';
    }
}
function validateGroupEligibility_Error(result) {
    $get('valGroupMembershipIndicator').style.display = 'none';    
}
function ValidateDiscountCode() {
    resetDiscountCodeValidators();        
    var dc = $get(contentId + '_txtPromoCode').value;
    var refid = 0;
    $get('spnPlanSelectLoading').style.display = 'block';
    SignupService.ValidateDiscountCode(dc, refid, ValidateDiscountCode_Return, ValidateDiscountCode_Failure);    
}
var groupRequest = false;
function ValidateDiscountCode_Return(result) {    
    $get('spnPlanSelectLoading').style.display = 'none';
    $get(contentId + '_valPromoCode').style.display = 'none';
    if (result.length > 0) {
        // Check valid state
        if (result[0].ValidState != 0) {
            $get(contentId + '_valPromoCode').style.display = 'block';
        } else {
            var plan;
            var li = '';
            $get(contentId + '_spnPlanList').style.display = 'none';
            var rdo = $get('spnPlanCodeList');
            var rdoItems = '';
            groupRequest = false;
            for (var i = 0; i < result.length; ++i) {
                plan = result[i];                
                li += plan.PlanId + '|' + plan.MonthlyCost + '|' + plan.SetupCost;
                li += '|' + plan.TrialDays + '|' + plan.EmailTemplate + '|' + plan.PathToLogo + '|' + plan.AccountCode;
                li += '|' + plan.DeptNo + '|' + plan.Discription + '|' + $get(contentId + '_txtPromoCode').value + '|0|';
                li += plan.VerificationRequired + '|' + plan.ResponsibleForPayment + '|' + plan.RequestGroupNumber + '|';
                li += plan.DisablePhoneAccess + '|' + plan.PlanDialInNumber + '~';
                rdoItems += "<input type='radio' name='rdoPlanList' id='rdoPlanList" + i + "' value='" + li + "'";
                if (i == 0)
                    rdoItems += " checked='checked'";
                rdoItems += " />" + plan.Discription + " <br />";
                if (plan.RequestGroupNumber == 1) {
                    groupRequest = true;
                    break;
                }
            }
            rdo.style.display = 'block';
            rdo.innerHTML = rdoItems;
            $get(contentId + '_hidPlanCodes').value = li;
            if (groupRequest) {
                $get(contentId + '_divGroupMember').style.display = 'block';
            }
        }
    }
}
function ValidateDiscountCode_Failure(result) {
    $get('spnPlanSelectLoading').style.display = 'none';
    alert('There was an error trying to verify the plan/referral id.  Please try again.');
}
function resetDiscountCodeValidators() {
    $get(contentId + '_valPromoCode').style.display = 'none';
    $get(contentId + '_spnPlanList').style.display = 'block';
    $get('spnPlanCodeList').style.display = 'none';
    $get('spnValidateMember').style.display = 'none';
    $get(contentId + '_divGroupMember').style.display = 'none';
    
}
function resetPlanList() {
    $get('txtGroupId').value = '';
    $get('txtMemberId').value = '';
    $get(contentId + '_txtPromoCode').value = defaultPlan;
    groupRequest = false;
    resetDiscountCodeValidators();
    ValidateDiscountCode();
}
function signupDebitCard() {
    var el = $get(contentId + '_hidWantDebitCard');
    if (el.value == "0")
        el.value = "1";
    else
        el.value = "0";
    toggleDiv('divDebitCard')
}
if(typeof(Sys)!= 'undefined') Sys.Application.notifyScriptLoaded();