<script language="javascript" type="text/javascript">
// <![CDATA[

    //keep track of what customer's old value for paypal subscription
    //was so that we can show the proper warning when updating
    var old_subscriptionyes=false;
    var selectedplugin='{selectedpluginname}';
    var selectedpluginrealname='{selectedpluginrealname}';

    function DeleteCC(){
        //calls the ajax action that returns the fields
        //then call category with edit
        setStatus(lang("Deleting Credit Card"));

        var post;

        new Ajax.Request(   'index.php?fuse=clients&action=deleteCCNumber',
            {
                postBody    : post,
                onSuccess   : function(t)
                {

                   var data = eval('(' + t.responseText + ')');
                   unsetStatus('', 1);
                   if(data.message!=""){
                       alert(data.message);
                   }

                   window.location = "index.php?fuse=clients&view=ViewProfile_Billing";
                }
            }
        );

    }


    function SubscriptionConfirmation(new_subscriptionvalue,paymentmethodchanged){
        //scenario one

        var msg;
        if( (old_subscriptionyes) && (new_subscriptionvalue==0) && (!paymentmethodchanged) ){
            msg = lang("Click ok to confirm canceling your subscription through "+selectedpluginrealname+". Submit a support ticket if you wish to cancel your service with us.");
            a=confirm(msg);
            if(a) return true;
        }else if( (old_subscriptionyes) && (paymentmethodchanged) ){
            msg = lang("Changing payment method will cancel your subscription through "+selectedpluginrealname+". Click ok to confirm.");
            a=confirm(msg);
            if(a) return true;
        }else if( (!old_subscriptionyes) && (new_subscriptionvalue==1) ){
            msg = lang("Click ok to confirm. Your subscription with "+selectedpluginrealname+" will be initiated after paying your next invoice.");
            a=confirm(msg);
            if(a) return true;
        }
        return false;
    }

    function SaveBillingInformation(){
        //save billing information
        

        var post="dummy=dummy";
        var paymentmethodchanged=false;

                
        if($('paymenttype')!=null){
            post += "&paymenttype="+$('paymenttype').value;
            if($('paymenttype').value!=selectedplugin) paymentmethodchanged=true;
        }else{
            post += "&paymenttype="+selectedplugin;
        }


        if($('ccyear')!=null){
            post += "&ccyear="+$('ccyear').value;
        }
        if($('ccmonth')!=null){
            post += "&ccmonth="+$('ccmonth').value;
        }

        if($('newccnumber')!=null){
            if( ($('ccnumber')!=null) && ($('ccnumber').value!="") ){
                post += "&ccnumber="+$('ccnumber').value;
            }else{
                post += "&ccnumber="+$('newccnumber').value;
            }
        }

        if(old_subscriptionyes){
            post += "&old_subscription=1";
        }else{
            post += "&old_subscription=0";
        }

        post += "&old_selectedplugin="+selectedplugin;
        var new_subscriptionvalue = $RF("billingform","recurring_paypal");

        //only check if we are not showing cc information
        if( (new_subscriptionvalue!=null) && ($('creditcardinfo').style.display=="none") ){

            post += "&new_subscription="+new_subscriptionvalue;
            if(old_subscriptionyes!=new_subscriptionvalue){
                if(!SubscriptionConfirmation(new_subscriptionvalue,paymentmethodchanged)){
                    return false;
                };
            }
        }else{

            post += "&new_subscription=0";
            if( (old_subscriptionyes) && (paymentmethodchanged) ){
                if(!SubscriptionConfirmation(new_subscriptionvalue,paymentmethodchanged)){
                    return false;
                };
            }
        }

        setStatus(lang("Update billing information"));

        new Ajax.Request(   'index.php?fuse=clients&action=UpdateBilling',
            {
                postBody    : post,
                onSuccess   : function(t)
                {
                   var json = eval('(' + t.responseText + ')');
                   unsetStatus('', 1);
                   if(json.error!=""){
                       alert(json.error);
                       return false;
                   }
                   
                   window.location = "index.php?fuse=clients&view=ViewProfile_Billing";

                }
            }
        );
    }

     function GetCCInformation(selObj){


        setStatus(lang("Retrieving Credit Card Information"));

        var post="plugin="+selObj;
        new Ajax.Request(   'index.php?fuse=clients&action=GetPaymentPluginDetails',
            {
                postBody    : post,
                onSuccess   : function(t){
                    
                    var json = eval('(' + t.responseText + ')');

                    unsetStatus('', 1);

                    if(json.alertmessage!=""){
                        alert(json.alertmessage);
                        return;
                    }

                    
                    //show subscription options
                    if(json.showsubscriptionoptions){
                        $('use_recurring').style.display = 'block';
                        
                        if(json.subscriptionyes){
                            $('subscriptionyes').checked = true;
                            old_subscriptionyes = true;
                        }else{
                            old_subscriptionyes = false;
                        }
                    }else{
                        $('use_recurring').style.display = 'none';
                    }
                    
                    //show subscription options no edit
                    if(json.showsubscriptionoptionsnoedit){
                        $('use_recurring_no_edit').style.display = 'block';
                        
                        if(json.subscriptionyes){
                            $('subscriptionyes').checked = true;
                            old_subscriptionyes = true;
                            $('use_recurring_no_edit_yes').style.display = '';
                            $('use_recurring_no_edit_no').style.display = 'none';
                        }else{
                            old_subscriptionyes = false;
                            $('use_recurring_no_edit_yes').style.display = 'none';
                            $('use_recurring_no_edit_no').style.display = '';
                        }
                    }else{
                        $('use_recurring_no_edit').style.display = 'none';
                        $('use_recurring_no_edit_no').style.display = 'none';
                        $('use_recurring_no_edit_yes').style.display = 'none';
                    }
                    
                    //show update button
                    if(json.subscriptionyes && selectedplugin == 'paypal'){
                        $('update_button').style.display = 'none';
                    }else{
                        $('update_button').style.display = '';
                    }
                    
                    //show show edit vault payment information
                    if(json.showeditvaultpaymentinformation){
                        $('vaultpaymentinformation').style.display = 'block';
                        $('vaultpaymentiframe').src = "index.php?fuse=admin&view=ViewPluginUrl&plugintoshow=quantumvault";
                    }else{
                        $('vaultpaymentinformation').style.display = 'none';
                        $('vaultpaymentiframe').src = '';
                    }
                    
                    //show cc info
                    if(json.showccoptions){
                        $('creditcardinfo').style.display = 'block';
                    }else{
                        $('creditcardinfo').style.display = 'none';
                        return;
                        //return because the remaining options are only for cc
                    }


                    if(json.awaitingvalidation!=""){
                        $('awaitingvalidation').innerHTML = json.awaitingvalidation;
                        $('awaitingvalidationspan').style.display = '';
                        $('ccnumberspan').style.display = 'none';
                        $('deleteccspan').style.display = 'none';
                        $('newccspan').style.display = "none";
                    }else{
                        if(json.last4!=""){
                            $('newccspan').style.display = "";
                            $('ccnumberspan').style.display = 'none';
                            $('lastfourspan').style.display = '';
                            $('lastfour').innerHTML = "xxxxxxxxxxxx"+json.last4;
                            $('deleteccspan').style.display = '';  
                        }else{
                            $('newccspan').style.display = "none";
                            $('ccnumberspan').style.display = '';
                            $('lastfourspan').style.display = 'none';
                            $('lastfour').innerHTML = "";
                            $('deleteccspan').style.display = 'none';
                            
                        }
                        $('awaitingvalidationspan').style.display = 'none';
                    }
                    
                    //if cc then which cards do we show
                    $('visa_logo').style.display = json.visastyle;
                    $('mastercard_logo').style.display = json.mastercardstyle;
                    $('americanexpress_logo').style.display = json.americanexpressstyle;
                    $('discover_logo').style.display = json.discoverstyle;
                    //for card validation
                    $('validccbits').value= json.visabit+''+json.mcbit+''+json.amexbit+''+json.discbit;
                }
            }
        );
     }


// ]]>
</script>

<div id="kb" class="block">
<div class="block_title">
<h3><b><a href="index.php">[l]Support Center[/l]</a> &raquo; <a href="#">[l]Profile[/l]</a></b></h3>
</div>
<ul>
<li>
<h1>[l]Client Payment Options[/l]</h1>
<p class="kb st" style="background: url(templates/{TEMPLATE}/images/public/icon_submit_ticket.jpg) no-repeat 0 8px;">[l]Please keep your profile up to date.  You can use this section to update your billing preferences, alternatate contact information and update your password.[/l]</p>
</li>
<li>

    <div id="cip">
        <div class="nav_1">
            <ul>
                <li>
                    <a href="index.php?fuse=clients&amp;view=ShowCustomerData"><span>[l]Profile[/l]</span></a>
                </li>
                <li>
                    <a href="index.php?fuse=clients&amp;view=ViewProfile_AlternateEmails"><span>[l]Alternate Emails[/l]</span></a>
                </li>
                <li class="selected">
                    <a href="#"><span>[l]Billing[/l]</span></a>
                </li>
                <li>
                    <a href="index.php?fuse=clients&amp;view=ViewProfile_Password"><span>[l]Password[/l]</span></a>
                </li>
                <li>
                    <a href="index.php?fuse=clients&amp;view=ViewProfile_StaffNotes"><span>[l]Notes[/l]</span></a>
                </li>
            </ul>
        </div>
        <br /><br />
    </div>



<!-- BEGIN DYNAMIC BLOCK: billing -->
<div style="padding-left: 15px;">

    <!--  ADDED FOR: ACCOUNT_CREDIT - Credit Balance  -->
    <span class="label130">[l]Credit Balance[/l]:</span>
    {balance}
    <br>
    <!--  ADDED FOR: ACCOUNT_CREDIT - Credit Balance  -->

    <!-- BEGIN DYNAMIC BLOCK: caneditpaymenttype -->
    <span class="label130">[l]Payment Type[/l]:</span>
    <select name="paymenttype" id="paymenttype" onchange="GetCCInformation(this.options[this.selectedIndex].value); return false;">
        <!-- BEGIN DYNAMIC BLOCK: paymentTypeOption -->
        <option value="{paymentTypeOptionValue}" {paymentTypeOptionSelected} >{paymentTypeOptionLabel}</option>
        <!-- END DYNAMIC BLOCK: paymentTypeOption -->
    </select>
    <!-- END DYNAMIC BLOCK: caneditpaymenttype -->
    <!-- BEGIN DYNAMIC BLOCK: cannoteditpaymenttype -->
    <span class="label130">[l]Payment Type[/l]:</span>
    {paymentTypeOptionLabel}
    <!-- END DYNAMIC BLOCK: cannoteditpaymenttype -->
    

    <form method="post" id="billingform" name="billingform" action="index.php?fuse=clients&amp;action=UpdateBilling">

    <div id="use_recurring" style="display:none;">
        <span class="label130">[l]Use Subscription[/l]:</span>
        <span>
        <input type="radio" id="subscriptionno" name="recurring_paypal" value="0" checked="checked" />[l]No[/l]&nbsp;&nbsp;
        <input type="radio" id="subscriptionyes" name="recurring_paypal" value="1" />[l]Yes[/l]&nbsp;&nbsp;
        </span>
    </div>

    <div id="use_recurring_no_edit" style="display:none;">
        <span class="label130">[l]Use Subscription[/l]:</span>
        <span id="use_recurring_no_edit_no" style="display:none;">[l]No[/l]</span>
        <span id="use_recurring_no_edit_yes" style="display:none;">[l]Yes[/l]</span>
    </div>

    <div id="vaultpaymentinformation" style="display:none;">
        <p align=center>
            <font color=red>[l]We do not store credit card information<br>for your selected payment type[/l]</font><br><br>
        </p>
        <iframe
            id=vaultpaymentiframe
            src =""
            width="100%"
            height="300"
            scrolling="auto"
            frameborder="0"
        > 
            <p>
                Your browser does not support iframes.
            </p> 
        </iframe>
    </div>

    <div id="creditcardinfo" style="display:none;">
        <span class="label130">[l]Credit Card Number[/l]:</span>


        <span id="lastfourspan">
            <span id="lastfour"></span>
        </span>
	<!-- BEGIN DYNAMIC BLOCK: caneditcreditcard -->
        <span id="deleteccspan" style="padding-left:10px;">
            <input type="button" id="deleteccbutton" value="[l]Delete Credit Card[/l]" onclick="DeleteCC();return false;" />
            <br />
        </span>

        <span id="ccnumberspan">
            <input type="text" id="ccnumber" name="ccnumber" size="30" />
            <br />
        </span>

        <span id="awaitingvalidationspan">
            <span id="awaitingvalidation"></span>
            <br />
        </span>

        
        <span id="newccspan">
            <span class="label130">[l]New Card Number[/l]:</span>
            <input type="text" id="newccnumber" name="newccnumber" />&nbsp;&nbsp;{helpCCChange}
            <br/>
        </span>


        <span class="label130">[l]Expires[/l]:</span>
        <select id="ccmonth" name="ccmonth">
            <!-- BEGIN DYNAMIC BLOCK: monthOptions -->
            <option value="{monthOptionsValue}" {monthOptionsSelected} >{monthOptionsLabel}</option>
            <!-- END DYNAMIC BLOCK: monthOptions -->
        </select>

        <select id="ccyear" name="ccyear">
            <!-- BEGIN DYNAMIC BLOCK: yearOptions -->
            <option value="{yearOptionsValue}" {yearOptionsSelected} >{yearOptionsLabel}</option>
            <!-- END DYNAMIC BLOCK: yearOptions -->
        </select>
        <br />

        <span class="label130">[l]Accepting[/l]:</span>
        <span>
            <img src="images/creditcards/visa.gif" style="display:{visaStyle}" id="visa_logo" alt="" />
            <img src="images/creditcards/mc.gif" style="display:{mastercardStyle}" id="mastercard_logo" alt="" />
            <img src="images/creditcards/amex1.gif" style="display:{americanexpressStyle}" id="americanexpress_logo" alt="" />
            <img src="images/creditcards/discover.gif" style="display:{discoverStyle}" id="discover_logo" alt="" />
        </span>
        <input type="hidden" name="validcc" id="validccbits" value='{visabit}{mcbit}{amexbit}{discbit}' />
	<!-- END DYNAMIC BLOCK: caneditcreditcard -->
        <!-- BEGIN DYNAMIC BLOCK: cannoteditcreditcard -->
        <span id="ccnumberspan">
            <input type="text" id="ccnumber" name="ccnumber" size="30" />
            <br />
        </span>
        <span id="awaitingvalidationspan">
            <span id="awaitingvalidation"></span>
            <br />
        </span>
        <span id="newccspan">
        </span>
        <!-- END DYNAMIC BLOCK: cannoteditcreditcard -->
    </div>

    <br />
    <input id="update_button" type="submit" value='[l]update[/l]' onclick='SaveBillingInformation(); return false;' class="body" style="display:none;" />
    </form>
</div>

<script type="">
    GetCCInformation(selectedplugin);
</script>

<!-- END DYNAMIC BLOCK: billing -->

<br />
</li>
</ul>
</div>
