﻿function PaymentType(RadioGroup){
    var RadioGroupName = replaceAll(RadioGroup, "_", "$")
    var RadioButtonList = document.forms[0][RadioGroupName];
    var PaymentType = getSelectedRadioValue(RadioButtonList);
    var divCardDetails = document.getElementById("divCardDetails") ;
    
    if (PaymentType == "credit"){
        divCardDetails.style.display = "";
    }else{
        divCardDetails.style.display = "none";
    }
}

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i;
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
}

function replaceAll(strSource,lookFor,replaceWith) {
    strLowerCase = strSource.toLowerCase();
    lookForLower = lookFor.toLowerCase();
    while(strLowerCase.indexOf(lookForLower) != -1) {
        posStart = strLowerCase.indexOf(lookForLower)
        posEnd = posStart + lookFor.length
        strLowerCase = strLowerCase.substring(0,posStart) + replaceWith + strLowerCase.substring(posEnd,strLowerCase.length)
        strSource = strSource.substring(0,posStart) + replaceWith + strSource.substring(posEnd,strSource.length)
    }
    return strSource;
}

function printpage() {
  window.print();
  return false;
}