/*--------------------------------------------------------------------------------------------------
 <project>
 SunGardHE.AWC
 </project>
 <file>
 AWCGifts.js
 </file>
 <company>
 Advancement Solutions, SunGard Higher Education
 http://www.sungardhe.com
 </company>
 <copyright>
  
 Copyright (c) 2003-2007 
 All Rights Reserved.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 DEALINGS IN THE SOFTWARE.
</copyright>
<summary>
 This js file handles the gifts functions throughout AWC.
</summary>
--------------------------------------------------------------------------------------------------*/


/*----------------------------------------------------------------------------------------------------
  09/21/2004 Hamel - Select Other radio button when Other Amount is entered  
                     Selects the "Other" radio button
  11/09/2007 Sweatt - Change the Gift Amount Option to PaymentPlan
----------------------------------------------------------------------------------------------------*/
function SelectOther() {
    var form = document.getElementById("frmMain");
    if (form != null)
        form.GiftAmountopt[form.GiftAmountopt.length - 1].click();
    
    return true;
}
// Gets the GiftAmountother textbox
function GetGiftAmountOther() {
    if (document.getElementById != null)
        return document.getElementById("GiftAmountother");
    
    return null;
}
// Attaches the SelectOther() function as the onkeypress handler for the Other Amount text box 
function AttachOtherOnChange() {
    var otherBox = GetGiftAmountOther();
    if (otherBox != null)
        otherBox.onkeypress = SelectOther;
}
/*----------------------------------------------------------------------------------------------------
  09/21/2004 Hamel - End
----------------------------------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------------------------------
  11/09/2007 Sweatt - Do not allow gift with Pay In Full Today to have different gift/payment values  
                      flag that tells the SyncPayment whether or not to perform the sync
----------------------------------------------------------------------------------------------------*/
// Gets the GiftAmount text box
function GetGiftAmount() {
    if (document.getElementById != null)
        return document.getElementById("GiftAmount");
    
    return null;
}
// Gets the PledgeAmount text box
function GetPledgeAmount() {
    if (document.getElementById != null)
        return document.getElementById("PledgeAmount");
    
    return null;
}
// Gets the GiftAmountopt radio button array
function GetGiftAmountOpt() {
    if (document.getElementById != null) {
        var form = document.getElementById("frmMain");
        return form.GiftAmountopt;
    }
    return null;
}
// Gets the PaymentFrequencyopt radio button array
function GetPaymentFrequencyopt() {
    if (document.getElementById != null) {
        var form = document.getElementById("frmMain");
        return form.PaymentFrequencyopt;
    }
    return null;
}
// Gets the PaymentPlanopt radio button array
function GetPaymentPlanopt() {
    if (document.getElementById != null) {
        var form = document.getElementById("frmMain");
        return form.PaymentPlanopt;
    }
    return null;
}
// Gets the gifttypeopt radio button array
function GetGiftTypeopt() {
    if (document.getElementById != null) {
        var form = document.getElementById("frmMain");
        return form.gifttypeopt;
    }
    return null;
}
// Gets the value of the currently selected pledge Amount textbox
function GetSelectedPledgeAmount() {
    var giftAmountOpt = GetGiftAmountOpt();
    if (giftAmountOpt != null) {
        for (var index = 0; index < giftAmountOpt.length; index++) {
            if (giftAmountOpt[index].checked)
                return giftAmountOpt[index].value;
        }
    }
    return null;
}
function GetSelectedPaymentFrequency() { 
    var paymentFrequencyOpt = GetPaymentFrequencyopt();
    if (paymentFrequencyOpt != null) {
        for (var index = 0; index < paymentFrequencyOpt.length; index++) {
            if (paymentFrequencyOpt[index].checked)
                return paymentFrequencyOpt[index].value;
        }
    }
    return null;
}
function GetSelectedPaymentPlan() {
    var paymentPlanOpt = GetPaymentPlanopt();
    if (paymentPlanOpt != null) {
        for (var index = 0; index < paymentPlanOpt.length; index++) {
            if (paymentPlanOpt[index].checked)
                return paymentPlanOpt[index].value;
        }
    }
    return null;
}
function GetSelectedGiftTypeOption() {
    var giftTypeopt = GetGiftTypeopt();
    if (giftTypeopt != null) {
        for (var index = 0; index < giftTypeopt.length; index++)
            if (giftTypeopt[index].checked)
                return giftTypeopt[index].value;
    }
    return null;    
}
function SyncPledgeWithGiftPayment() {
    var pledgeAmount = document.getElementById('PledgeAmount');
    if (pledgeAmount != null) {
        var paymentAmountBox = document.getElementById('GiftAmount');
        if (paymentAmountBox != null)
            paymentAmountBox.value = pledgeAmount.value;
    }
    return true;
}
function ReCalculatePayment() {
    var option              = GetSelectedPaymentFrequency();
    var pledgeAmount        = GetPledgeAmount();
    if (pledgeAmount != null) {
        var pledgeAmountValue   = pledgeAmount.value;
        var giftAmount          = GetGiftAmount();
        var paymentPlanOpt      = GetPaymentPlanopt();
        var defaultValue        = "0";
        if (paymentPlanOpt != null) {
            // for loop used because order could be customized, or values removed
            for (var index = 0; index < paymentPlanOpt.length; index++) {
                if (paymentPlanOpt[index].checked)
                    defaultValue = paymentPlanOpt[index].value;
            }
        }
//        if (option != null) {
//            if (option == "B")      // One Payment
//                giftAmount.value = (pledgeAmountValue / 1);
//            else if (option == "A") // Quarterly  
//                giftAmount.value = (pledgeAmountValue / 4);
//            else if (option == "C") // Monthly
//                giftAmount.value = (pledgeAmountValue / 12); 
//        }
        giftAmount.value = pledgeAmountValue;
        
        var form862 = document.getElementById("xform862");
        // initialize
        
        switch (defaultValue) {
            case "1":
                EnableSync(false);
                if (form862 != null) {
                    if(form862.style.display == "none")   
                        form862.style.display = "";                     
                }                
                break;
            case "2":
                EnableSync(true);
                if (form862 != null) {
                    if(form862.style.display == "")
                        form862.style.display = "none";
                }                                
                break;
        }
    }
    return true;
}
// Sets AttachPaymanetFrequencySyncOnClick() as the onclick handler for the Payment Frequency radio buttons
function AttachPaymanetFrequencySyncOnClick() {
    var paymentFrequencyOpt = GetPaymentFrequencyopt();
    if (paymentFrequencyOpt != null) {
        for (var index = 0; index < paymentFrequencyOpt.length; index++)
            paymentFrequencyOpt[index].onclick = ReCalculatePayment;
    }
}
// Sets AttachPlanSyncOnClick() as the onclick handler for the Payment Plan radio buttons
function AttachPlanSyncOnClick() {
    var paymentPlanOpt  = GetPaymentPlanopt();
    if (paymentPlanOpt != null) {
        for (var index = 0; index < paymentPlanOpt.length; index++)
            paymentPlanOpt[index].onclick = ReCalculatePayment;
    }
}
function EnableSync(value) {
    var paymentAmount   = GetGiftAmount();
    var giftTypeOption  = GetSelectedGiftTypeOption();
    if (giftTypeOption == "2") {
        if (paymentAmount != null)
            paymentAmount.disabled = value;
   
    }
    
}
/*----------------------------------------------------------------------------------------------------
  11/09/2007 Sweatt - End
----------------------------------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------------------------------
  12/06/2004 Sweatt - Clearing out the Credit Card Number if a user click the previous  
                      button or the browser back button
----------------------------------------------------------------------------------------------------*/
function ClearCreditCardNumberOut(){
    var ccn = document.getElementById("CreditCardNumber");
    if (ccn != null) {
        if (ccn.value != "")
            ccn.value = "";
    }
}
/*----------------------------------------------------------------------------------------------------
  12/06/2004 Sweatt - End
----------------------------------------------------------------------------------------------------*/


/*----------------------------------------------------------------------------------------------------
  04/15/2005 Sweatt - Credit Card Number No AutoComplete for storing the CC Number in 
                      the brower's cache or cookie
----------------------------------------------------------------------------------------------------*/
function AutoOffCreditCardNumber(){
    var ccn = document.getElementById("CreditCardNumber");
    if (ccn != null)
        ccn.autocomplete = "off";
}
/*----------------------------------------------------------------------------------------------------
  04/15/2005 Sweatt - End
----------------------------------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------------------------------
  10/30/2007 Sweatt - Custom functions for the Multiple Allocation List, Add & Remove on Make A Gift
  12/06/2007 Sweatt - Added check for greater amount = 0 TT# 2500
  12/11/2007 Sweatt - added '|| amount.value == " "' ln:275
----------------------------------------------------------------------------------------------------*/
function AddAllocation() {
    try {
        if (ValidatorOnSubmit()) {
            var error       = document.getElementById('ErrorContainer');
            var amount      = document.getElementById('GiftAmount');     
            var allocCode   = document.getElementById('hidSelectedAllocationCode');
            var alloc       = document.getElementById('hidSelectedAllocationText');
            var errorHTML   = "<ul style='color:red;'>";
            var hasErrors     = false;    
            if (amount.value == "" || amount.value == " ") {
                errorHTML   += "<li>" + amountError;
                hasErrors     = true;
            } else {
                // 12/11/2007 Sweatt - Check for NaN property indicates that a value is "Not a Number".
                if (isNaN(parseInt(amount.value))  || parseInt(amount.value) <= 0) {
                    errorHTML   += "<li>" + amountError;
                    hasErrors     = true;
                }
            }
            if ((allocCode.value == "" && alloc.value == "") || 
                (allocCode.value == " " && alloc.value == " ")) {
                errorHTML   += "<li>" + allocError;
                hasErrors     = true;
            }
            if (hasErrors) {
                errorHTML       += "</ul>"
                error.innerHTML = errorHTML;
            } else {
                error.innerHTML = "&nbsp;";
                _ajax.callWebPage("AjaxServer.aspx?method=5", 
                                  SetAllocationList, 
                                  "POST", 
                                  "MultiAllocationForm=" + amount.value + "|" + allocCode.value + "|" + alloc.value + "|1", 
                                  null, 
                                  2); 
            }
        }
    } catch (ex) {
        displayError('Make A Gift Multiple Alloc','unsuccessful getting the allocation list', ex, 1);
        return;
    }
}

function SetAllocationList(content) {
    try {
    
        // 12/12/2007 Sweatt - added to remove Click Next Error Message from top of page
        if (document.getElementById('divValidationMessages') != null && content.split('|')[0] != '') {
            if (document.getElementById('divValidationMessages').style.display == "")
                document.getElementById('divValidationMessages').style.display = "none";
        }
        var allocList = document.getElementById('AllocationContainer');
        allocList.innerHTML = content.split('|')[0];       
        
        // Count the Allocation, when 5 then hidden form with controls 620
        // 12/03/2007 Sweatt - added new help text form to hidden
        if (content.split('|')[1] == 5) {
            ShowHideForm('xform620');
            ShowHideForm('xform624');
        }
        
        var catValue        = "";
        var paramsMethod    = 3;
        var method          = 3;
        var subCatValue     = "";
        var amount          = document.getElementById('GiftAmount');
        var category        = document.getElementById('Cat');
        var subCategory     = document.getElementById('SubCat');
        var allocation      = document.getElementById('Allocation');
        var allocCode       = document.getElementById('hidSelectedAllocationCode');
        var alloc           = document.getElementById('hidSelectedAllocationText');
        if (content.split('|')[1] >= 1) {            
            // Clear values on the form
            amount.value    = catValue;
            if (category != null)
                category.value = catValue;
            if (subCategory != null)
                subCategory.value = catValue;
                
            allocCode.value = catValue;
            alloc.value     = catValue;
                
            _ajax.callWebPage('AjaxServer.aspx?method=3', 
                              Populate, 
                              'POST', 
                              'ClearDropDowns=' + catValue + '|' + catValue, 
                              4);
        } else if (content.split('|')[1] == 0) {
            // set Gift Amount control  
            if (typeof amountFromMakeAGift == 'undefined')
                amount.value    = catValue;
            else {
                if (amountFromMakeAGift == 0)
                    amount.value    = catValue;
                else
                    amount.value    = amountFromMakeAGift;
            }
            // 12/10/2007 Sweatt - added to select the designation from Make A Gift Page TT# 2357 retains information
            if (typeof sysOption140 != 'undefined') {
                if (sysOption140 == 0) {
                    if (typeof allocFromGift != 'undefined') {
                        if (allocFromGift != null) {
                            // 12/18/2007 Sweatt - had to assign the hidden controls based on the allocation selected TT# 2357
                            var hasAllocDefaultSelected = false;
                            var options = allocation.options;
                    	    for(var index = 0; index < options.length; index++) {
		                        if(options[index].value == allocFromGift) {
			                        options[index].selected = "selected";
			                        hasAllocDefaultSelected = true
			                    }
                            }
                            if (hasAllocDefaultSelected)
                                SetAllocationHidden(allocation);
                        }
                    }
                } else {
                    // sysOption140 = 1 or 2
                    if (category != null) {
                        if (typeof categoryFromGift != 'undefined') {
                            if (categoryFromGift != null) {
                                var options = category.options;
                                catValue    = categoryFromGift;
                    	        for(var index = 0; index < options.length; index++) {
		                            if(options[index].value == catValue)
			                            options[index].selected = "selected";
                                }
                            }
                        }
                    }
                    if (subCategory != null) {
                        if (typeof subCategoryFromGift != 'undefined') {
                            if (subCategoryFromGift != null) {
                                var options = subCategory.options;
                                subCatValue = subCategoryFromGift;
                    	        for(var index = 0; index < options.length; index++) {
		                            if(options[index].value == subCatValue)
			                            options[index].selected = "selected";
                                }
                            }
                        }    
                        method          = 2;
                        paramsMethod    = 2;
                    }                                 
                    var params          = 'setdefaults=' + catValue + '|' + subCatValue;                    
                    _ajax.callWebPage('AjaxServer.aspx?method=' + method, 
                                      Populate, 
                                      'POST', 
                                      params, 
                                      paramsMethod);
                
                }
            }
            
            // code below is for future use (Passing parameters logic)
            // Set the category/subcategory/alloc 
            if (typeof cookieFromMakeAGift == 'undefined')
                cookieFromMakeAGift = new AWCCookie("defaultsFromMakeAGift", 5); // Create new Cookie
                        
            if (!cookieFromMakeAGift.cookieExists())
                return;
            else {
                var qCat        = '';
                var qSubCat     = '';
                var qAlloc      = '';
                var hasCat      = false;
                var hasSubCat   = false;
                var hasAlloc    = false;
//                // Get Value from the querystring
//                qCat        = queryString('catg');
//                qSubCat     = queryString('subg');
//                qAlloc      = queryString('alloc');
//                hasCat      = (qCat     == null || qCat     == 'false')? false:true;
//                hasSubCat   = (qSubCat  == null || qSubCat  == 'false')? false:true;
//                hasAlloc    = (qAlloc   == null || qAlloc   == 'false')? false:true;
                var hasCategory     = false;
                var hasSubCategory  = false;

//                if (!hasCat && !hasSubCat && !hasAlloc) {
                    if (category != null) {
                        if (cookieFromMakeAGift.getSubValue("defaultCategory") != null) {
                            var options = category.options;
                            catValue    = cookieFromMakeAGift.getSubValue("defaultCategory");
                    	    for(var index = 0; index < options.length; index++) {
		                        if(options[index].value == catValue)
			                        options[index].selected = "selected";
                            }
                        }
                    }
                    if (subCategory != null) {
                        if (cookieFromMakeAGift.getSubValue("defaultSubCategory") != null) {
                            var options = subCategory.options;
                            subCatValue = cookieFromMakeAGift.getSubValue("defaultSubCategory");
                    	    for(var index = 0; index < options.length; index++) {
		                        if(options[index].value == subCatValue)
			                        options[index].selected = "selected";
                            }
                        }
                        method          = 2;
                        paramsMethod    = 2;
                    }                                 
                    var params          = 'setdefaults=' + catValue + '|' + subCatValue;                    
                    _ajax.callWebPage('AjaxServer.aspx?method=' + method, 
                                      Populate, 
                                      'POST', 
                                      params, 
                                      paramsMethod);
//                }
            }
        }
        // 12/11/2007 Sweatt - set focus on the amount control after the click on Save icon
        if (content.split('|')[1] < 5)
            amount.focus();
        
    } catch (ex) {
        displayError('Make A Gift Multiple Alloc','unsuccessful rendering the allocation list table', ex, 1);
        return;
    }
}
var _indexRemove;
function RemoveAllocation(index) {
    var confirm = new Alert(_options);
    _indexRemove = index;
    //(title, text, button, buttonEvent, button2, button2Event)
    confirm.Confirm('Make A Gift Multiple Alloc',
                    'Are you sure you want to remove this Allocation?', 
                    'Yes', 
                    'RemoveAllocationYes()', 
                    'No', 
                    'RemoveAllocationNo()');
}

function RemoveAllocationYes() {
    //displayError('Make A Gift Multiple Alloc','Removed Allocation from list', ex, 2);
    try {
        _ajax.callWebPage("AjaxServer.aspx?method=5", 
                          SetAllocationList, 
                          "POST", 
                          "MultiAllocationForm=0|0|0|2" + "|" + _indexRemove, 
                          null, 
                          2); 
        // If the controls are hidden when 5 allocations are reached then on remove unhide controls                          
        if (document.getElementById('xform620').style.display == "none")
            document.getElementById('xform620').style.display = "";
            
        // 12/03/2007 Sweatt - Added help text form
        if (document.getElementById('xform624').style.display == "none")
            document.getElementById('xform624').style.display = "";
        
    } catch (ex) {
        displayError('Make A Gift Multiple Alloc','unsuccessful getting the allocation list', ex, 1);
        return;
    }
}

function RemoveAllocationNo() {
    return
}
// Called from the GiftMultipleAllocations only
// 12/11/2007 Sweatt - changed 1 to 3 to indicate when to display allocations list
function initAllocation() {
    try {
        _ajax.callWebPage("AjaxServer.aspx?method=5", 
                          SetAllocationList, 
                          "POST", 
                          "MultiAllocationForm=0|0|0|3", 
                          null, 
                          2); 
    } catch (ex) {
        displayError('Make A Gift Multiple Alloc','unsuccessful getting the allocation list onload event', ex, 1);
        return;
    }
}

function ShowHideForm(id) {
    if (document.getElementById(id).style.display == "none")
        document.getElementById(id).style.display = "";
    else
        document.getElementById(id).style.display = "none";
} 
/*----------------------------------------------------------------------------------------------------
  10/30/2007 Sweatt - End
----------------------------------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------------------------------
  11/05/2007 Sweatt - Handle the I wish to designate my gift for more than one purpose. 
                      (Gift must be paid in full today.) onchange hide/unhide controls
----------------------------------------------------------------------------------------------------*/
function DesignateOnChange() {
    var allocCheck  = document.getElementById("MultipleAllocation");
    var form        = document.getElementById("xform523");
    if (form != null) {
        if (allocCheck != null) {
            if (allocCheck.checked == true) {
                if (form.style.display == "");
                    form.style.display = "none"; 
            } else {                        
                if (form.style.display == "none");
                    form.style.display = "";   
            }
        }
    }

    // 26/11/2007 SN - Added for TT3 2236 Hide Gift Receipt Option     
    var form862 = document.getElementById("xform862");
    if (form862 != null) {
        if (allocCheck != null) {
            if (allocCheck.checked == true) {
                if (form862.style.display == "");
                    form862.style.display = "none"; 
            } else {                        
                if (form862.style.display == "none");
                    form862.style.display = "";   
            }
        }
    }       
    
}
/*----------------------------------------------------------------------------------------------------
  11/05/2007 Sweatt - End
----------------------------------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------------------------------
  11/08/2007 Sweatt - on make a pledge/gift forms, paymentfrequency control default radiolist checked
                      on pledge/gift selected type
----------------------------------------------------------------------------------------------------*/
function AssignPaymentFrequencyDefault() {
    var radioPF     = GetPaymentFrequencyopt();
    var radioChoice = false;
    if (typeof radioPF == "undefined")
        return;
        
    for (var index = 0; index < radioPF.length; index++) {
        if (radioPF[index].checked) 
            radioChoice = true;
    }
    if (!radioChoice)
        radioPF[0].checked = true;
}
/*----------------------------------------------------------------------------------------------------
  11/08/2007 Sweatt - End
----------------------------------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------------------------------
  11/16/2007 Sweatt - decided to create a category & subcategory onchange universal function
----------------------------------------------------------------------------------------------------*/
var cookieFromMakeAGift;
function OnChangeCategory(category, setDefaults, action) {
    var subCategory = document.getElementById('SubCat');
    
    if (setDefaults) {
        // Check cookie
        if(typeof cookieFromMakeAGift == 'undefined')
            cookieFromMakeAGift = new AWCCookie("defaultsFromMakeAGift", 5); // Create new Cookie
        
        // Set Cookie Category    
        cookieFromMakeAGift.setSubValue("defaultCategory", category.value);
    }
    // 12/13/2007 Sweatt - set hidden field TT# 2357
    var hidCat          = document.getElementById('hidSelectedCategoryCode');
    var catValue        = category.options[category.selectedIndex].value;
    if (hidCat != null)
        hidCat.value = catValue;
        
    if (action == 1) {
        // Get the filtered data for the SubCategory based on the Category value
        _ajax.callWebPage('AjaxServer.aspx?method=1', 
                          Populate, 
                          'POST', 
                          category.id + '=' + category.value + '|' + 
                          ((subCategory == null)?'':subCategory.value), 
                          ((subCategory == null)?3:1));
    } else if (action == 2) {    
        _ajax.callWebPage('AjaxServer.aspx?method=3', 
                          Populate, 
                          'POST', 
                          category.id + '=' + category.value + '|' + ((subCategory == null)?'':subCategory.value), 
                          ((subCategory == null)?3:1));
    }
                      
}
function OnChangeSubCategory(subCategory, setDefaults) {
    var category = document.getElementById('Cat');
    
    // 12/13/2007 Sweatt - set hidden field TT# 2357
    var hidSubCat          = document.getElementById('hidSelectedSubCategoryCode');
    var subCatValue        = subCategory.options[subCategory.selectedIndex].value;
    if (hidSubCat != null)
        hidSubCat.value = subCatValue;
    
    if (setDefaults) {
        // Check cookie
        if(typeof cookieFromMakeAGift == 'undefined')
            cookieFromMakeAGift = new AWCCookie("defaultsFromMakeAGift", 5); // Create new Cookie
        
        // Set Cookies Category & SubCategory
        cookieFromMakeAGift.setSubValue("defaultCategory", category.value);
        cookieFromMakeAGift.setSubValue("defaultSubCategory", subCategory.value); 
    }
    // Get the filtered data for the Allocations based on the Category & SubCategory values
    _ajax.callWebPage("AjaxServer.aspx?method=2", 
                      Populate, 
                      "POST", 
                      subCategory.id + "=" + category.value + "|" + subCategory.value, 
                      2); 
}
/*----------------------------------------------------------------------------------------------------
  11/16/2007 Sweatt - End
----------------------------------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------------------------------
  11/26/2007 SN[SOS] - Open New window to Print Gift Receipts
----------------------------------------------------------------------------------------------------*/
function PrintReceipt(trans_id)
{
    var pintloc = 'Action.aspx?Appid=862&i_transaction_id=' + trans_id;
    window.open(pintloc,'_blank','status=yes,toolbar=yes,resizable=yes,scrollbars=yes,menubar=yes,location=no');
}
/*----------------------------------------------------------------------------------------------------
  11/26/2007 SN[SOS] - End
----------------------------------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------------------------------
  12/01/2007 SN[SOS] - Enable/Disable Gift Receipt Options
----------------------------------------------------------------------------------------------------*/
function EnableDisableopt(trans_id)
{
    var pintloc = 'Action.aspx?Appid=862&i_transaction_id=' + trans_id;
    //var pintloc = 'PrintGiftReceipt.aspx?AppID=862&i_transaction_id=' + trans_id;
    window.open(pintloc,'_blank','status=yes,toolbar=no,resizable=yes,menubar=no,location=no');
    
    //iFrameDisplay("PrintReceipt",GetFullyQualifiedPath +  pintloc);
}
/*----------------------------------------------------------------------------------------------------
  11/26/2007 SN[SOS] - End
----------------------------------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------------------------------
  12/21/2007 SN[SOS] - Added to fix TT# 2687
----------------------------------------------------------------------------------------------------*/
function CheckPaymentPlanopt() {
    var form862 = document.getElementById("xform862");
    var form    = document.getElementById("frmMain");
    if(form.PaymentPlanopt != null) {
        if (form.PaymentPlanopt[1] != null) {
            if (form.PaymentPlanopt[1].checked) {
                if (form862 != null) 
                    form862.style.display = "none";
            }
            else
            {
                if (form862 != null) 
                    form862.style.display = "";
            }
        }
    }
}

/*----------------------------------------------------------------------------------------------------
  12/21/2007 SN[SOS] - END
----------------------------------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------------------------------
  09/21/2004 Hamel	- Select Other radio button when Other Amount is entered
  12/21/2007 Sweatt - added code below to support TT# 2498
----------------------------------------------------------------------------------------------------*/
// Hamel	09/29/2004	Do not allow gift with Pay In Full Today to have different gift/payment values --%>
// flag that tells the SyncPayment whether or not to perform the sync --%>
var _SyncGiftAndPayment;
//// Gets the PaymentAmount text box --%>
function GetPaymentAmount() {
    if (document.getElementById != null)
        return document.getElementById("PaymentAmount");

    return null;
}
// Gets the Gift Type Option radio button array
function GetGiftOptionopt() {
    if (document.getElementById != null) {
        var form = document.getElementById("frmMain");
        return form.gifttypeopt;
    }
    return null;
}
// Gets the value of the currently selected Gift Amount radio button --%>
function GetSelectedGiftAmount() {
    var giftAmountOpt = GetGiftAmountOpt();
    if (giftAmountOpt != null) {
        for (i = 0; i < giftAmountOpt.length; i++)
            if (giftAmountOpt[i].checked)
                return giftAmountOpt[i].value;
    }
    return null;
}
// If the Sync flag is set, sets the value in the Payment Amount box to the
//		currently selected Gift amount. If the Other radio button is selected, use
//		the value in the Other Amount text box --%>
function SyncPayment() {
    if (_SyncGiftAndPayment) {
        var giftAmount = GetSelectedGiftAmount();
        if (giftAmount != null) {
            if (giftAmount == "__other") {
                var otherAmountBox = GetGiftAmountOther();
                if (otherAmountBox != null)
                    giftAmount = otherAmountBox.value;
            }
            var paymentAmountBox = GetPaymentAmount();
            if (paymentAmountBox != null)
                paymentAmountBox.value = giftAmount;
        }
    }
    return true;
}
// Sets SyncPayment() as the onclick handler for the Gift Amount radio buttons --%>
function AttachGiftSyncOnChange() {
    var giftAmountOpt = GetGiftAmountOpt();
    if (giftAmountOpt != null) {
        for (i = 0; i < giftAmountOpt.length; i++) {
            giftAmountOpt[i].onclick = SyncPayment;
        }
    }
    
    var giftAmountOther = GetGiftAmountOther();
    if (giftAmountOther != null)
        giftAmountOther.onchange = SyncPayment;
}
// Sets the sync flag to true, disables the Payment Amount text box and syncs
//	12/10/2004 Sweatt    Added hidden field because enabling a control, has no value
//--%>
function EnableSync() {
    _SyncGiftAndPayment     = true;
    var giftType            = GetGiftOptionopt();
    if (giftType != null) {
        if (giftType == 2) {
            var paymentAmount   = GetPaymentAmount();
            if (paymentAmount != null)
                paymentAmount.disabled = true;        
        }
    }
    SyncPayment();
}
// Sets the sync flag to false, enables the Payment Amount text box --%>
function DisableSync() {
    _SyncGiftAndPayment     = false;
    var paymentAmount       = GetPaymentAmount();
    if (paymentAmount != null)
    {    paymentAmount.disabled = false;}
    
    //12/27/2007 - SN[SOS] Added To fix defect # 2687 
    CheckPaymentPlanopt();
            
}
// Sets the sync flag to false, disables the Payment Amount text box and sets it to blank --%>
function DisablePayments() {
    _SyncGiftAndPayment     = false;
    var paymentAmount       = GetPaymentAmount();
    if (paymentAmount != null) {
        paymentAmount.disabled  = true;
        paymentAmount.value     = "";
    }
    
    //12/27/2007 - SN[SOS] Added To fix defect # 2687 
    CheckPaymentPlanopt();
    
}
// Gets the PaymentPlanopt radio button array --%>
function GetPaymentPlanOpt() {
    if (document.getElementById != null) {
        var form = document.getElementById("frmMain");
        return form.PaymentPlanopt;
    }
    return null;
}
function AttachPlanSyncOnChange() {
    var paymentPlanOpt = GetPaymentPlanOpt();
    var defaultVal = "0";
    if (paymentPlanOpt != null) {
        // for loop used because order could be customized, or values removed --%>
        for (i = 0; i < paymentPlanOpt.length; i++) {
            switch(paymentPlanOpt[i].value) {
                case "0":
                    paymentPlanOpt[i].onclick = EnableSync;
                    break;
                case "1":
                    paymentPlanOpt[i].onclick = DisableSync;
                    break;
                case "2":
                    paymentPlanOpt[i].onclick = DisablePayments;
                    
                    break;
            }
            if (paymentPlanOpt[i].checked)
                defaultVal = paymentPlanOpt[i].value;
        }
    }
    // initialize
    switch (defaultVal) {
        case "0":
            EnableSync();
            break;
        case "1":
            DisableSync();
            break;
        case "2":
            DisablePayments();
            break;
    }
}

/*----------------------------------------------------------------------------------------------------
  12/21/2007 Sweatt - END
----------------------------------------------------------------------------------------------------*/