var require_tandc_acceptance = "N";
var stripePublishableKey = "pk_live_xZXTORmiqHcAC3CQneMGdfB4";
Stripe.setPublishableKey(stripePublishableKey);
jQuery(document).ready(function () {
// binds form submission and fields to the validation engine
jQuery("#formPayment").validationEngine();
});
/**
*
* @param {jqObject} the field where the validation applies
* @param {Array[String]} validation rules for this field
* @param {int} rule index
* @param {Map} form options
* @return an error string if validation failed
*/
function checkHELLO(field, rules, i, options) {
if (field.val() != "HELLO") {
// this allows to use i18 for the error msgs
return options.allrules.validate2fields.alertText;
}
}
function passwordCheck(form) {
var pcmmsg = "Password and the re-typed Password fields must match.";
var pmsg = "Password is a required field. Please enter password.";
var alphamsg = "Only alphanumberic characters allowed in Password.";
if (document.getElementById("cpassword")) {
//alert("here");
var cpassword = document.getElementById("cpassword").value;
var cpasswordconfirm = "";
if (document.getElementById("cpasswordconfirm")) {
cpasswordconfirm = document.getElementById("cpasswordconfirm").value;
}
else {
if (pmsg != null)
alert("Password and the re-typed Password fields must match.");
else
alert("Password is a required field. Please enter Password.");
document.getElementById("cpassword").focus();
return false;
}
if (cpassword == "") {
document.getElementById('btnPleaseWait').style.display = 'none';
document.getElementById('btnSubmit').style.display = 'initial';
if (pmsg != null)
alert("Password is a required field. Please enter password.");
else
alert("Password is a required field. Please enter Password.");
document.getElementById("cpassword").focus();
return false;
}
if ((cpassword != cpasswordconfirm) || (cpassword == "")) {
document.getElementById('btnPleaseWait').style.display = 'none';
document.getElementById('btnSubmit').style.display = 'initial';
if (pcmmsg != null)
alert("Password and the re-typed Password fields must match.");
else
alert("Password and the re-typed Password fields must match.");
document.getElementById("cpassword").focus();
return false;
}
if (/[^a-zA-Z0-9]/.test(cpassword)) {
document.getElementById('btnPleaseWait').style.display = 'none';
document.getElementById('btnSubmit').style.display = 'initial';
if (alphamsg)
alert('Only alphanumberic characters allowed in Password.');
else
alert('Only alphanumber characters allowed in Password');
document.getElementById("cpassword").focus();
return false;
}
}
return true;
}
function validateBillInfo(form, createValidationList, customFields)
{
var first_name = document.getElementById("first_name").value;
var last_name = document.getElementById("last_name").value;
var billing_first_name = document.getElementById("billing_first_name").value;
var billing_last_name = document.getElementById("billing_last_name").value;
var address = document.getElementById("address").value;
var country = document.getElementById("country").value;
var state = document.getElementById("state").value;
var city = document.getElementById("city").value;
var zip = document.getElementById("zip").value;
var phone = document.getElementById("phone").value;
var email = document.getElementById("email").value;
var cpassword = "";
if (document.getElementById("cpassword")) {
cpassword = document.getElementById("cpassword").value;
}
var customfieldval = "";
if ((customFields) && (customFields != "")) {
var n = customFields.split(",");
//validate custom fields
for (i = 0; i < n.length; i++) { if (document.getElementById("custom_" + n[i])) { var cval = document.getElementById("custom_" + n[i]).value; if (cval != "") { if (customfieldval == "") customfieldval = customfieldval + "custom_" + n[i] + ":" + cval; else customfieldval = customfieldval + ",custom_" + n[i] + ":" + cval; } } } //alert("final custom val = " + customfieldval); } var howdidyouhearaboutus = ""; var comments = ""; if (document.getElementById("howdidyouhearaboutus")) { howdidyouhearaboutus = document.getElementById("howdidyouhearaboutus").value; } if (document.getElementById("comments")) { comments = document.getElementById("comments").value; } var lldocroot = "/home/bootstrappingstr/public_html"; //alert("cpassword="+cpassword); var submiturl = '/dap/storeBillInfo.php'; jQuery.ajax({ url: submiturl, type: "POST", async: false, cache: false, data: {"first_name": first_name, "last_name": last_name, "billing_first_name": billing_first_name, "billing_last_name": billing_last_name, "address": address, "country": country, "state": state, "city": city, "zip": zip, "phone": phone, "email": email, "cpassword": cpassword, "customfieldval": customfieldval, "comments": comments, "howdidyouhearaboutus": howdidyouhearaboutus, "lldocroot": lldocroot}, success: function (returnval) { //alert("Updated in session"); } }); //ajax if (validateCustomerInfo(form) == false) { return false; } if (document.getElementById("cpassword")) { if (!passwordCheck()) return false; cpassword = document.getElementById("cpassword").value; } var billinginforequired = "Y"; if (billinginforequired == "Y") { var ret = validateBillingInfo(form); if (ret == false) { return false; } } var str = createValidationList; var cfrmsg = "cannot be empty. It's a required field."; var customfieldval = ""; if ((str) && (str != "")) { var n = str.split(","); //validate custom fields for (i = 0; i < n.length; i++) { var ln = n[i].split(":"); if (ln[0]) { var cval = document.getElementById(ln[0]).value; //alert("custom field name = "+ln[0]+", val = "+cval); if (cval == "") { document.getElementById('btnPleaseWait').style.display = 'none'; document.getElementById('btnSubmit').style.display = 'initial'; if (cfrmsg) alert(ln[1] + " " + cfrmsg); else alert(ln[1] + " cannot be empty. It's a required field."); document.getElementById(ln[0]).focus(); return false; } } } } if (require_tandc_acceptance == "Y") { if (!document.getElementById('tandc').checked) { var tandcmsg = "Please accept Terms & Conditions to proceed!"; if (tandcmsg != "") alert(tandcmsg); else alert("Please accept Terms & Conditions to Proceed!"); return false; } } return true; //return validateBillingInfo(form); } function askvalidation(form, createValidationList, require_tandc_acceptance) { /* if(typeof dapcartwidgetargs.submitimgurl=="undefined"){ dapcartwidgetargs.submitimgurl = '< plugin_dir_url(__FILE__) ?>includes/images/pleasewaitanim.gif';
}
*/
var submitimg="";
if(submitimg=="") {
submitimg= 'http://bootstrappingstrategies.com/wp-content/plugins/dapshoppingcart/includes/images/pleasewaitanim.gif';
}
jQuery("#imgbox").html("");
var cfrmsg = "cannot be empty. It's a required field.";
var first_name = document.getElementById("first_name").value;
var last_name = document.getElementById("last_name").value;
var billing_first_name = document.getElementById("billing_first_name").value;
var billing_last_name = document.getElementById("billing_last_name").value;
var address = document.getElementById("address").value;
var country = document.getElementById("country").value;
var state = document.getElementById("state").value;
var city = document.getElementById("city").value;
var zip = document.getElementById("zip").value;
var phone = document.getElementById("phone").value;
var email = document.getElementById("email").value;
var cpassword = "";
if (document.getElementById("cpassword")) {
cpassword = document.getElementById("cpassword").value;
}
var howdidyouhearaboutus = "";
var comments = "";
if (billing_first_name)
first_name = billing_first_name;
if (billing_last_name)
last_name = billing_last_name;
if (document.getElementById("howdidyouhearaboutus")) {
howdidyouhearaboutus = document.getElementById("howdidyouhearaboutus").value;
}
if (document.getElementById("comments")) {
comments = document.getElementById("comments").value;
}
var lldocroot = "/home/bootstrappingstr/public_html";
var submiturl = '/dap/storeBillInfo.php';
jQuery.ajax({
url: submiturl,
type: "POST",
async: false,
cache: false,
data: {"first_name": first_name, "last_name": last_name, "address": address, "country": country, "state": state, "city": city, "zip": zip, "phone": phone, "email": email, "cpassword": cpassword, "comments": comments, "howdidyouhearaboutus": howdidyouhearaboutus, "lldocroot": lldocroot},
success: function (returnval) {
//alert("Updated in session");
}
}); //ajax
var pagetemplate = 'template2';
if (validateCustomerInfo(form) == false) {
if(pagetemplate=='template1'){
document.getElementById('btnPleaseWait').style.display = 'none';
document.getElementById('btnSubmit').style.display = 'initial';
}
return false;
}
if (document.getElementById("cpassword")) {
if (!passwordCheck())
return false;
cpassword = document.getElementById("cpassword").value;
}
var billinginforequired = "Y";
billinginforequired="Y";
if (billinginforequired == "Y") {
var ret = validateBillingInfo(form);
if (ret == false) {
if(pagetemplate=='template1'){
document.getElementById('btnPleaseWait').style.display = 'none';
document.getElementById('btnSubmit').style.display = 'initial';
}
return false;
}
}
var vstatemsg = "";
if(state=="Other") {
if(vstatemsg!="")
alert(vstatemsg);
else
alert("Please Enter a Valid Value for State");
return false;
}
// validate custom field
var str = createValidationList;
if ((str) && (str != "")) {
var n = str.split(",");
//validate custom fields
for (i = 0; i < n.length; i++) { var ln = n[i].split(":"); if (ln[0]) { var cval = document.getElementById(ln[0]).value; if (cval == "") { // document.getElementById('btnPleaseWait').style.display = 'none'; // document.getElementById('btnSubmit').style.display = 'initial'; if (cfrmsg) alert(ln[1] + " " + cfrmsg); else alert(ln[1] + " cannot be empty. It's a required field."); document.getElementById(ln[0]).focus(); return false; } } } } if (validateCCInfo(form) == false) { return false; } if (require_tandc_acceptance == "Y") { if (!document.getElementById('tandc').checked) { var tandcmsg = "Please accept Terms & Conditions to proceed!"; if (tandcmsg != "") alert(tandcmsg); else alert("Please accept Terms & Conditions to Proceed!"); return false; } } var payment_gateway = "stripe"; var month = document.getElementById("exp_date"); var monthval = month.options[month.selectedIndex].text; var year = document.getElementById("exp_date_year"); var yearval = year.options[year.selectedIndex].text; var submitmsg=""; //alert("payment gateway="+payment_gateway); if ((payment_gateway) && (payment_gateway == "stripe")) { jQuery("#dap-popup-wrapper,#dap-popup").show(); // if(typeof dapcartwidgetargs.submitmessage!='undefined'){ if(submitmsg!="") jQuery("#popup-message").html(submitmsg); //} Stripe.createToken({ number: form.card_num.value, cvc: form.card_code.value, exp_month: monthval, exp_year: yearval, address_country: country, address_state: state, address_city: city, address_zip: zip, address_line1: address, name: first_name + " " + last_name }, stripeResponseHandler); return false; } if(pagetemplate=='template1'){ document.getElementById('btnPleaseWait').style.display = 'initial'; document.getElementById('btnSubmit').style.display = 'none'; } jQuery("#dap-popup-wrapper,#dap-popup").show(); //if(typeof dapcartwidgetargs.submitmessage!='undefined'){ //jQuery("#popup-message").html(dapcartwidgetargs.submitmessage); //} if(submitmsg!="") jQuery("#popup-message").html(submitmsg); document.getElementById("formPayment").submit(); } function stripeResponseHandler(status, response) { console.log('d'); if (response.error) { // re-enable the submit button // jQuery('.btnSubmit').removeAttr("disabled"); //setErrortext var lldocroot = "/home/bootstrappingstr/public_html"; var submiturl = '/dap/setCartError.php'; jQuery.ajax({ url: submiturl, type: "POST", async: false, cache: false, data: {"err_text": escape(response.error.message), "lldocroot": lldocroot}, success: function (returnval) { //alert("Updated in session"); document.getElementById('btnSubmit').style.display = 'initial'; document.getElementById('btnPleaseWait').style.display = 'none'; window.location.href = window.location.href; } }); //ajax } else { var form$ = jQuery("#formPayment"); // token contains id, last4, and card type var token = response['id']; // insert the token into the form so it gets submitted to the server form$.append("");
document.getElementById('btnSubmit').style.display = 'none';
document.getElementById('btnPleaseWait').style.display = 'initial';
// and submit
form$.get(0).submit();
return;
}
document.getElementById('btnSubmit').style.display = 'initial';
document.getElementById('btnPleaseWait').style.display = 'none';
}
function initCardType() {
var cardtype = document.getElementById('card_type');
if (cardtype != null) {
var val =
"";
if (val != null && val != '') {
//cardtype.options[cardtype.selectedIndex].text = val;
for (i = 0; i < cardtype.options.length; i++) { if (cardtype.options[i].value == val) { cardtype.selectedIndex = i; } } } } } function applyCoupon(form) { if (form.coupon_code.value == null || form.coupon_code.value == "") { alert("Please enter coupon code"); form.coupon_code.focus(); return; } // use coupon code to get discount amount form.action = "/dap/inc/validateCoupon.php"; form.submit(); } function paypalformsubmit() { document.formPayment.action = "/dap/paypalCoupon.php"; //document.getElementById("formPayment").submit(); } function loginsubmit(email, password, url) { var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/; //if (document.getElementById('dapemail').value == '' || !filter.test(document.getElementById('dapemail').value)) if (document.getElementById('dapemail').value == '') { alert('Please provide a valid email address'); email.focus; return false; } // alert(email+password+url); //alert("password="+password); if (document.getElementById('dappassword').value == '' || document.getElementById('dappassword').value == 'password') { alert("Please enter a valid password"); return false; } document.getElementById('btnLoginSign').style.display = 'none'; document.getElementById('btnLoginPleaseWait').style.display = 'initial'; var submiturl = '/dap/authenticate.php?email=' + email + '&password=' + password + '&submitted=Y&dapcart=Y'; jQuery.ajax({ url: submiturl, type: "POST", async: false, cache: false, success: function (returnval) { if (returnval == 0) { window.location.href = window.location.href; } else if (returnval == -1) { //alert("Invalid Password"); window.location.href = window.location.href; } } }); //ajax return; } function updateProductInfo() { //alert("change option"); var item_name_l = document.getElementById("item_name_l"); // alert(sourceProductId.options[sourceProductId.selectedIndex].text); // if(item_name_l.options[item_name_l.selectedIndex].text == " var item_selected = item_name_l.options[item_name_l.selectedIndex].value; var item_number = ""; var submiturl = '/dap/updateProdInfo.php'; //alert("submit url="+submiturl); jQuery.ajax({ url: submiturl, type: "POST", async: false, cache: false, data: {"item_selected": item_selected, "item_number": item_number}, success: function (returnval) { window.location.reload(); } }); //ajax return; }
var templatetype = 'rwd';
var showpaypal = "";
var showcc = "";
var templatename= "template2";
//this code will make sure shipping and billing info is same
jQuery("#Billing input,#Billing select").change(function () {
shipID = "#ship_to_" + this.id.substring(this.id.indexOf("_") + 1);
jQuery(shipID).val(jQuery(this).val()).change();
});
//end of code
jQuery("#cpasswordconfirm").keyup(function(){
if(jQuery(this).val()!==jQuery("#cpassword").val()){
jQuery("#confirmpasserror").show();
}else{
jQuery("#confirmpasserror").hide();
}
})
if(templatename=="template1" || templatename=="") {
if(typeof templatetype=='undefined'){
jQuery("#state option[value='Other'],#ship_to_state option[value='Other']").remove();
}
if(showpaypal=="N") {
jQuery("#payWithCC").css("width", "100%");
jQuery("#payWithCC .formLabel").css("width","200px");
jQuery(".checkoutForms .formLabel").css("float","left");
jQuery("#payWithCC .ccImages").css("float","left");
jQuery("#payWithCC input[type='text']").css("max-width","208px");
}
else if (showcc=="N") {
jQuery("#payPal").css("width", "100%");
jQuery("#payPal").css("height", "20px");
jQuery("#paymentInformation").css("width", "100%");
}
else {
jQuery("#payWithCC input[type='text']").css("max-width","168px");
}
}
else { //template2
jQuery(window).bind('resize',function(){
var windowsize = jQuery('body').innerWidth();;
var containerw=Number(jQuery("#checkoutWrapper").css("width").split("px")[0]);
if(containerw>windowsize){
jQuery("#checkoutWrapper").css("width",windowsize+"px");
}
})
window.onload=function(){
var windowsize = jQuery('body').innerWidth();;
var containerw=Number(jQuery("#checkoutWrapper").css("width").split("px")[0]);
if(containerw>windowsize){
jQuery("#checkoutWrapper").css("width",windowsize+"px");
}
}
if (showpaypal=="N") {
jQuery("#payWithCC").css("width", "100%");
jQuery("#payWithCC .formLabel").css("width", "200px");
jQuery(".checkoutForms .formLabel").css("float", "left");
jQuery("#payWithCC .ccImages").css("float", "left");
jQuery("#payWithCC input[type='text']").css("max-width", "208px");
jQuery("#payPal").hide();
}
else if (showcc == "N") {
jQuery("#payPal").css("width", "100%");
jQuery("#payPal").css("height", "20px");
jQuery(".actions").css('display','none');
jQuery("#paymentInformation").css("width", "100%");
jQuery("#payWithCC").hide();
}
else {
var ht=jQuery("#payWithCC").height();
jQuery("#payPal").css("height",ht+"px");
//jQuery("#payWithCC").show();
}
jQuery("#payWithCC").resize(function(){
var ht=jQuery("#payWithCC").height();
jQuery("#payPal").css("height",ht+"px");
})
jQuery("#card_num").bind('keyup blur',function(){
jQuery("#payWithCC").resize();
})
jQuery("#country option[value='USA']").attr('selected', true).change();
jQuery("#state option[value='Other']").attr('id', 'dynamic-state');
jQuery("#ship_to_state option[value='Other']").attr('id', 'shipping-dynamic-state');
jQuery("#state-other,#shipping-state-other").hide();
jQuery("#state-other").keyup(function () {
jQuery("#dynamic-state").val(this.value);
})
jQuery("#shipping-state-other").keyup(function () {
jQuery("#shipping-dynamic-state").val(this.value);
})
jQuery(document).ready(function(){
jQuery("#ship_to_state").change(function(){
if(this.value=='Other'){
jQuery("#shipping-state-other").show().addClass("validate[required]");
}else{
jQuery("#shipping-state-other").hide().removeClass("validate[required]");
}
})
jQuery("#state").change(function(){
if(this.value=='Other'){
jQuery("#state-other").show().addClass("validate[required]");
}else{
jQuery("#state-other").hide().removeClass("validate[required]");
}
})
jQuery("#checkoutWrapper").css('width',"");
if(typeof templatetype != 'undefined'){
jQuery("#first_name,#last_name").keyup(function(){
jQuery("#billing_"+this.id).val(jQuery(this).val());
});
}
})
}
[/custom_html]