/* ##################################################################
 *    LillyApps, LLC
 * ##################################################################
 *
 *    Copyright          : (C) 2010 LillyApps, LLC
 *    Contact            : jimmy@lillyapps.com
 *
 *    - LillyApps and all of its source code and files are protected by Copyright Laws.
 *
 *    - The license for LillyApps denies you from copying this work.
 *
 *    - You may also not remove this copyright screen which shows the copyright information and credits for LillyApps.
 *
 * ##################################################################
 *****************************************************************************/

/****************************************************
 * Payments to LillyApps
 ***************************************************/


// Change Plan to:
//  1: One Time Payment
//  2: Subscription
function ChangePlan(val) {
    var OneTime = $doc('adBannerOneTime');
    var Subscription = $doc('adBannerSubscription');
    var lblLength = $doc('lblLength');
    var lblLength1 = $doc('lblLength1');
    var lblLength2 = $doc('lblLength2');
    var lblLength3 = $doc('lblLength3');
    switch( val ) {
      case '1':
        OneTime.style.display = 'block';
        Subscription.style.display = 'none';
        lblLength.innerHTML = "Length to run Ad:";
        lblLength1.innerHTML = "1 Month";
        lblLength2.innerHTML = "6 Months";
        lblLength3.innerHTML = "12 Months";
        break;
      case '2':
        OneTime.style.display = 'none';
        Subscription.style.display = 'block';
        lblLength.innerHTML = "Billing Period:";
        lblLength1.innerHTML = "Every Month";
        lblLength2.innerHTML = "Every 6 Months";
        lblLength3.innerHTML = "Every 12 Months";
        break;
    }
    $doc('adCurPlan').value = val;

    SetPurchase();
}


// Change Level to:
//  1: Bronze
//  2: Silver
//  3: Gold
function ChangeLevel(val) {
    var inpSize1 = $doc('inpSize1');
    var lblSize1 = $doc('lblSize1');
    var inpSize2 = $doc('inpSize2');
    var lblSize2 = $doc('lblSize2');
    switch( val ) {
      case '1':
        inpSize1.checked = 'checked';
        lblSize1.innerHTML = "150x150 @Right";
        $doc('adCurSize').value = "1";
        inpSize2.style.display = 'none';
        lblSize2.style.display = 'none';
        break;
      case '2':
        lblSize1.innerHTML = "120x240 @Right";
        lblSize2.innerHTML = "468x60 @Top";
        inpSize2.style.display = 'inline';
        lblSize2.style.display = 'inline';
        break;
      case '3':
        lblSize1.innerHTML = "120x600 @Right";
        lblSize2.innerHTML = "728x90 @Bottom";
        inpSize2.style.display = 'inline';
        lblSize2.style.display = 'inline';
        break;
    }
    $doc('adCurLevel').value = val;

    SetPurchase();
}


// Change Size to:
//  1: Use lblSize1
//  2: Use lblSize2
function ChangeSize(val) {
    $doc('adCurSize').value = val;

    SetPurchase();
}


// Change Length to:
//  1: 1 Month
//  2: 6 Months
//  3: 12 Months
function ChangeLength(val) {
    $doc('adCurLength').value = val;

    SetPurchase();
}


//
//
// Build Purchase Line ...
function SetPurchase() {
    // Available Choices
    var lblLevel = new Array();
    lblLevel[1] = $doc('lblLevel1').innerHTML;
    lblLevel[2] = $doc('lblLevel2').innerHTML;
    lblLevel[3] = $doc('lblLevel3').innerHTML;
    var lblSize = new Array();
    lblSize[1] = $doc('lblSize1').innerHTML;
    lblSize[2] = $doc('lblSize2').innerHTML;
    var lblLength = new Array();
    lblLength[1] = $doc('lblLength1').innerHTML;
    lblLength[2] = $doc('lblLength2').innerHTML;
    lblLength[3] = $doc('lblLength3').innerHTML;

    // Selected Choices
    var adCurPlan = Number($doc('adCurPlan').value);
    var adCurLevel = Number($doc('adCurLevel').value);
    var adCurSize = Number($doc('adCurSize').value);
    var adCurLength = Number($doc('adCurLength').value);

    // Text of Selected Choices
    var txtLevel = lblLevel[adCurLevel];
    var txtSize = lblSize[adCurSize];
    var txtLength;
    var wrkLength = lblLength[adCurLength];
    if( adCurPlan == 1 ) {
        txtLength = wrkLength;
    }
    else {
        txtLength = "Until Canceled";
    }

    // Calculate Amount
    var size = txtSize.replace(/ @[A-z]*/, '');
    var amt = 0;
    switch( size ) {
      case '150x150':
        amt = 20;
        break;
      case '120x240':
      case '468x60':
        amt = 30;
        break;
      case '120x600':
      case '728x90':
        amt = 40;
        break;
    }
    switch( adCurLength ) {
      case 2: // 6 Months (1 Month FREE)
        amt = amt * 5;
        break;
      case 3: // 12 Months (2 Months FREE)
        amt = amt * 10;
        break;
    }
    var txtAmt = "$" + amt + ".00";
    var optAmt = amt + ".00";

    if( adCurPlan == 2 ) {  // Subscription Plan
        txtAmt = txtAmt + " " + wrkLength;
    }

    // Set Purchase Line
    $doc('adLevel1').innerHTML = txtLevel;
    $doc('adLevel2').innerHTML = txtLevel;
    $doc('adSize1').innerHTML = txtSize;
    $doc('adSize2').innerHTML = txtSize;
    $doc('adLength1').innerHTML = txtLength;
    $doc('adLength2').innerHTML = txtLength;
    $doc('adAmount1').innerHTML = txtAmt;
    $doc('adAmount2').innerHTML = txtAmt;

    // Set PayPal variables
    $doc('optAmount1').value = optAmt;
    $doc('optAmount2').value = optAmt;
    $doc('optLevel1').value = txtLevel + " - " + txtSize;
    $doc('optLevel2').value = txtLevel + " - " + txtSize;
    $doc('optLength1').value = txtLength;
    $doc('optLength2').value = txtLength;

    if( adCurPlan == 2 ) {  // Subscription Plan
        switch( adCurLength ) {
          case 1: // 1 Month
            $doc('SubscriptionDuration').value = "1";
            break;
          case 2: // 6 Months
            $doc('SubscriptionDuration').value = "6";
            break;
          case 3: // 12 Months
            $doc('SubscriptionDuration').value = "12";
            break;
        }
    }
}

