       function purchaseCertificate() {

          var rEmail = trimLeftRightSpace(document.getElementById('recipient_email').value);
          var rEmail2 = trimLeftRightSpace(document.getElementById('recipient_email2').value);
          var name = trimLeftRightSpace(document.getElementById('recipient_name').value);
          var sender = trimLeftRightSpace(document.getElementById('sender_name').value);
          var isValid = true;

          wipeErrorMessagesClean();
          
          if (!checkValidField(name)) {
             replaceInnerHTML('name_error',errorNoName);
             isValid = false;
          }
          
          if (!checkValidField(rEmail)) {
             replaceInnerHTML('email_error', errorNoEmail);
             isValid = false;
          } else if(!checkFieldMatch(rEmail2,rEmail)) {
             replaceInnerHTML('match_error',errorRetypeEmail);
             isValid = false;
          }
          
          if (!checkRange()) {
             rangeError();
             isValid = false;
          }

          if (!checkValidField(sender)) {
	      replaceInnerHTML('sender_error',errorNoSenderName);
	      isValid = false;
          }
          
         
	  if (isValid) {document.GC_order.submit();}
          return false;
       }

       function testAndShowCustom(e) {
	   if (e.value == "custom" && e.checked) {
		document.getElementById('other_choice_b').style.display = "inline";
		document.getElementById('other_choice_a').style.display = "none";
		saveOnForm(e);
		document.getElementById('custom_amount').focus();
           } else {
		document.getElementById('other_choice_a').style.display = "inline";
		document.getElementById('other_choice_b').style.display = "none";
             	saveOnForm(e);
           }
       }
       
       function checkValidField(txt) {
       	  return (txt !='' && txt != null);
       }

       function checkFieldMatch(first,second) {
          return (first.toLowerCase()==second.toLowerCase());
       }

       function replaceInnerHTML(id,txt){
           
           if (txt == "") {
             document.getElementById(id).style.display = "none";
           } else {
             document.getElementById(id).innerHTML  = txt;
             document.getElementById(id).style.display = "block";
           }
       }
       
       
       function stripDecimals(e) {
	var dectext = e.value; // what is parsed into whole numbers

	  if (!isNaN(dectext) || dectext != "") {
		if (dectext.indexOf('.') != -1) {		
			dectext = dectext.substring(0,dectext.indexOf('.'));
		}	
          }
        e.value = dectext;
        return e;
       }
       

      function wipeErrorMessagesClean() {
        var fieldList = new Array('name_error','email_error','match_error','gift_error','sender_error');
        
        for (i=0;i<fieldList.length;i++) {
           var tempItem = document.getElementById(fieldList[i]);
           replaceInnerHTML(tempItem.id, "");
           }
      }
      
      function gcTermsPopUp() {
	      var url = "GiftCertificateTerms.jsp?";
	      var termsWin = window.open(url,"GC_terms","scrollbars,resizable,width=400,height=700");
	      termsWin.focus();
	      return false;
      }
      
       function gcSamplePopUp() {
	      var url = "GiftCertificateSample.jsp?";
	      var sampleWin = window.open(url,"GC_sample","scrollbars,resizable,width=700,height=600");
	      sampleWin.focus();
	      return false;
      }

       function trimLeftRightSpace(userString){
                   return(userString.replace(/^\s*/,"").replace(/\s*$/,""));
       }
