function calcTotal(inO) {
var oBase = document.getElementById("basePrice1");
var oShipping = document.getElementById("shipping");

var oE = document.getElementById("expedited");
var oR = document.getElementById("rush");

var oEP = document.getElementById("expeditedPrice1");
var oRP = document.getElementById("rushPrice1");

var oEP2 = document.getElementById("expeditedPrice2");
var oRP2 = document.getElementById("rushPrice2");

var oT = document.getElementById("total");


var isE = oE.checked;
var isR = oR.checked;

var base = parseInt(oBase.innerHTML.substring(1,oBase.innerHTML.length+1));
//var taxid_base = base;
//document.write(taxid_base);
if(oShipping) {
  var shipping = parseInt(oShipping.innerHTML.substring(1,oShipping.innerHTML.length+1));
  base = base + shipping;
}

var expedited = parseInt(oEP.innerHTML.substring(1,oEP.innerHTML.length+1));
var rush = parseInt(oRP.innerHTML.substring(1,oRP.innerHTML.length+1));
if (inO == oE) {
  if(isE) {
    oR.checked = false;
    addClass(oEP2, 'selected');
    removeClass(oEP, 'selected');
    addClass(oRP, 'selected');
    removeClass(oRP2, 'selected');
  } else {
    removeClass(oEP2, 'selected');
    addClass(oEP, 'selected');
  }
}

if (inO == oR) {
  if(isR) {
    oE.checked = false;
    addClass(oRP2, 'selected');
    removeClass(oEP2, 'selected');
    addClass(oEP, 'selected');
    removeClass(oRP, 'selected');
  } else {
    removeClass(oRP2, 'selected');
    addClass(oRP, 'selected');
  }
}

if (oE.checked) {
  base = base + expedited;
}

if (oR.checked) {
  base = base + rush;
}

//document.write(base);
oT.innerHTML = "$"+base;

}

function determineCCType() {
  var oN = document.getElementById("cc_number");
  var oC = document.getElementById("ccselection");
  var oType = document.getElementById("cc_type");

  num = oN.value;

  if (num.charAt(0) == '4') {
    oC.src = "https://www.simplefilings.com/images/graphics/cc_visa.jpg";
    oType.value = "Visa";
  } else {
    if (num.charAt(0) == '5' ) {
      oC.src = "https://www.simplefilings.com/images/graphics/cc_mastercard.jpg";
      oType.value = "MasterCard";
    } else {    
      if (num.charAt(0) == '3' && (num.charAt(1) == '4' || num.charAt(1) == '7')) {
        oC.src = "https://www.simplefilings.com/images/graphics/cc_amex.jpg";
        oType.value = "Amex";
      } else {
        if (num.charAt(0) == '6' && num.charAt(1) == '0' && num.charAt(2) == '1' && num.charAt(3) == '1') {
          oC.src = "https://www.simplefilings.com/images/graphics/cc_discover.jpg";
          oType.value = "Discover";
        } else {
           oC.src = "https://www.simplefilings.com/images/graphics/cc_noselection.jpg";
           oType.value = "";
        }
      }
    }
  }
}

var defaultSelection = 'https://www.simplefilings.com/images/graphics/cc_noselection.jpg';

function changeCCSelection( sSelection ) {
  var oC = document.getElementById("ccselection");
  var oType = document.getElementById("cc_type");

  if( sSelection == 'default') {
    oC.src = defaultSelection;
    oType.value = "";
  }
  if( sSelection == 'visa' ) {
    oC.src = "https://www.simplefilings.com/images/graphics/cc_visa.jpg";
    oType.value = "Visa";
  }

  if( sSelection == 'mastercard' ) {
    oC.src = "https://www.simplefilings.com/images/graphics/cc_mastercard.jpg";
    oType.value = "MasterCard";
  }

  if( sSelection == 'amex' ) {
    oC.src = "https://www.simplefilings.com/images/graphics/cc_amex.jpg";
    oType.value = "Amex";
  }

  if( sSelection == 'discover' ) {
    oC.src = "https://www.simplefilings.com/images/graphics/cc_discover.jpg";
    oType.value = "Discover";
  }

}

function selectCC(sSelection) {
  var oType = document.getElementById("cc_type");

  if( sSelection == 'visa' ) {
    oType.value = "visa";
    defaultSelection = "https://www.simplefilings.com/images/graphics/cc_visa.jpg";
  }

  if( sSelection == 'mastercard' ) {
    oType.value = "MasterCard";
    defaultSelection = "https://www.simplefilings.com/images/graphics/cc_mastercard.jpg";
  }

  if( sSelection == 'amex' ) {
    oType.value = "Amex";
    defaultSelection = "https://www.simplefilings.com/images/graphics/cc_amex.jpg";
  }

  if( sSelection == 'discover' ) {
    oType.value = "Discover";
    defaultSelection = "https://www.simplefilings.com/images/graphics/cc_discover.jpg";
  }
}

function toggleFax(faxsel) 
{
var oFW = document.getElementById("fax_wrapper");
var oFN = document.getElementById("fax_number");

oFN.value="";

if (faxsel.checked) 
{
  oFW.className = "show";
} else {
  oFW.className = "hide";
}
}

function toggleDBA(dbasel) {
var oDS = document.getElementById("dba_section");

if (dbasel.checked) {
  oDS.className = "show";
} else {
  oDS.className = "hide";
}
}

function toggleTrademark(tmsel) {
var oTMS = document.getElementById("trademark_section");

if (tmsel.checked) {
  oTMS.className = "show";
} else {
  oTMS.className = "hide";
}
}

function toggleTollfree(tfsel) {
var oTS = document.getElementById("tollfree_section");

if (tfsel.checked) {
  oTS.className = "show";
} else {
  oTS.className = "hide";
}
}

function showRegister(regsel) {
var oRS = document.getElementById("register_section");

  if (regsel.checked) {
    oRS.className = "show";
  } else {
    oRS.className = "hide";
  }
}

function showTrademarkUse(tmusesel) {
var oTMS = document.getElementById("trademark_use_section");

  if (tmusesel.checked) {
    oTMS.className = "show";
  } else {
    oTMS.className = "hide";
  }
}

function validatePaypal(form) {
  var firstname = document.getElementById("first_name");
  var lastname = document.getElementById("last_name");
  var ccnumber = document.getElementById("cc_number");
  var expmonth = document.getElementById("exp_month");
  var expyear = document.getElementById("exp_year");
  
  removeClass(firstname, "required");
  removeClass(lastname, "required");
  removeClass(ccnumber, "required");
  removeClass(expmonth, "required");
  removeClass(expyear, "required");
  
  var bRet = validateForm(form, false);

  addClass(firstname, "required");
  addClass(lastname, "required");
  addClass(ccnumber, "required");
  addClass(expmonth, "required");
  addClass(expyear, "required");
  return bRet;
}

function doGoogleCheckoutSubmit(action) {
  var form = document.getElementById("taxid_checkout");
  var google = document.getElementById("google");

  if(validatePaypal(form)) {
    google.value = 'Google';
    form.action = action;
    form.submit();
  }
}

function doPayPalSubmit(field) {
  var form = document.getElementById("taxid_checkout");
  var paypal = document.getElementById("paypal");
  var sb = document.getElementById("submit_button");  
  var pb = document.getElementById("paypal_submit");  
  var pt = document.getElementById('paypal_text');  
  var hsb = document.getElementById('processing_button');
  var hpb = document.getElementById('paypal_disabled');
    sb.style.display='none';
    hsb.style.display='';
    pb.style.display='none';
    hpb.style.display='';
    sb.disabled = true;
    pb.disabled = true;
    pt.innerHTML = '<br>';

  if(validatePaypal(form)) {
    paypal.value = 'PayPal';
    form.submit();
  }
  else {
    sb.style.display='';
    hsb.style.display='none';
    pb.style.display='';
    hpb.style.display='none';
//    pb.src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckoutsm.gif";
    sb.disabled = false;
    pb.disabled = false;
    pt.innerHTML = 'Or, click <a href="#" onclick="doPayPalSubmit(); event.returnValue = false; return false;">here</a> to check out with PayPal.';
  }
}

function doSubmit(field) {
  var form = document.getElementById("taxid_checkout");
  var paypal = document.getElementById("paypal");
  var radioCC_credit = document.getElementById("radioCC_credit");
  var sb = document.getElementById("submit_button");
  var pb = document.getElementById("paypal_submit");
  var pt = document.getElementById('paypal_text');
  var hsb = document.getElementById('processing_button');
  var hpb = document.getElementById('paypal_disabled');
//    sb.className="button_processing";
//    sb.src="https://www.simplefilings.com/images/button_processing.png";
    sb.style.display='none';
    hsb.style.display='';
    pb.style.display='none';
    hpb.style.display='';
//    pb.src="https://www.simplefilings.com/images/paypal_disabled.gif";
    sb.disabled = true;
    pb.disabled = true;
    pt.innerHTML = '<br>';

  if(validateForm(form, true)) {
    paypal.value = '';
    form.submit();
  }
  else {
//    sb.className="button_submit";
//    sb.src="https://www.simplefilings.com/images/button_checkout.png";       
    sb.style.display='';
    hsb.style.display='none';
    pb.style.display='';
    hpb.style.display='none';  
//    pb.src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckoutsm.gif";
    sb.disabled = false;
    pb.disabled = false;
    pt.innerHTML = 'Or, click <a href="#" onclick="doPayPalSubmit(); event.returnValue = false; return false;">here</a> to check out with PayPal.';
  }
}

function selectccradio(sel) {
  var ccsection = document.getElementById("cc_section");
  var checksection = document.getElementById("check_section");
  var checknotesection = document.getElementById("check_note_section");

  if(sel == 'cc') {
    ccsection.className = "show";
    checksection.className = "hide";
    checknotesection.className = "hide";
  }
  if(sel == 'check') {
    ccsection.className = "hide";
    checksection.className = "show";
    checknotesection.className = "show";
  }
}

