$(document).ready(function() { $('.fancybox').fancybox(); }); $.LoadingOverlaySetup({ color : "rgba(0, 0, 0, 0.4)", fade : true, image : "images/loading.gif", imagePosition : "center center", maxSize : 0, minSize : 0, resizeInterval : 0, size : 0, zIndex : 9999 }); function changeVerifyCode(){ var imgurl = "https://www.cncbinternational.com/Kaptcha.jpg?"+Math.random()*100; $('#kaptchaimg').attr("src", imgurl); } function getParameterByName(name) { name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search); return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); } function showNext(id,idd){ var targetB = "#" + idd; /*previous*/ var target = "#" + id; /*next*/ var source = getParameterByName('source'); var sur = $('#surname').val(); var giv = $('#givenname').val(); var username = sur + " " + giv; var cpgcode = $('#campaigncode').val(); var cpgname = $('#campaignname').val(); var lang = $('#lang').val(); var set1 = $('#cardset1').val(); var set2 = $('#cardset2').val(); var set3 = $('#cardset3').val(); var set4 = $('#cardset4').val(); var ccbin = $('#cardset1').val() + $('#cardset2').val() var tnc = $('#tnccheck:checked').val(); var cardnumb = $('#cardset1').val() + "-" + $('#cardset2').val() + "-" + $('#cardset3').val() + "-" + $('#cardset4').val(); var withdrawalamount = $('#withdrawalamount').val(); var repaymentperiod = $('#repaymentperiod').val(); var contactnumber = $('#contactnumber').val(); var veri = $('#verificationcode').val(); var errocount = false; errUp(); if ((sur == null) || (sur == "") || !validateName(sur)) { $("#err-surname").slideDown(); errocount = true; } if ((giv == null) || (giv == "") || !validateName(giv)) { $("#err-givenname").slideDown(); errocount = true; } if ((set1 == null) || (set1 == "") || (set1.length < 4) || isNaN(set1)) { $("#err-cardnum").slideDown(); errocount = true; }else if ((set2 == null) || (set2 == "") || (set2.length < 4) || isNaN(set2)) { $("#err-cardnum").slideDown(); errocount = true; }else if ((set3 == null) || (set3 == "") || (set3.length < 4) || isNaN(set3)) { $("#err-cardnum").slideDown(); errocount = true; }else if ((set4 == null) || (set4 == "") || (set4.length < 4) || isNaN(set4)) { $("#err-cardnum").slideDown(); errocount = true; }else if (!validateCC(ccbin)) { $("#err-cardnum3").slideDown(); errocount = true; } if ((withdrawalamount == null) || (withdrawalamount == "") || !validateNum(withdrawalamount)) { $("#err-withdrawalamount").slideDown(); errocount = true; } if ((repaymentperiod == "nan") || (repaymentperiod == null)) { $("#err-repaymentperiod").slideDown(); errocount = true; } if ((contactnumber == "") || (contactnumber == null) || !isPhoneNumber(contactnumber)) { $("#err-contactnum").slideDown(); errocount = true; } if ((tnc == false) || (tnc == null)) { $("#err-tnc").slideDown(); errocount = true; } //chcek verify code if($("#s2").is(":visible") && (id != "s1")){ if ((veri == null) || (veri == "")) { $("#err-veri").slideDown(); errocount = true; }else{ errocount = false; $("#err-veri").slideUp(); } } if ((errocount != true) && id == "s3") { //Generate reference number campaign code + Month + Day + Hour + Minutes + Seconds // var finitial = giv.charAt(0).toUpperCase(); // var linitial = sur.charAt(0).toUpperCase(); // var nnum = new Date().valueOf(); var subdate = new Date(); var month = ('0' + (subdate.getMonth() + 1)).slice(-2); var day = ('0' + subdate.getDate()).slice(-2); var hours = subdate.getHours(); if (hours < 10) { hours = "0" + hours; } var minutes = subdate.getMinutes(); if (minutes < 10) { minutes = "0" + minutes; } var seconds = subdate.getSeconds(); if (seconds < 10) { seconds = "0" + seconds; } // var refid = cpgcode + finitial + linitial + nnum; var refid = cpgcode + month + day + hours + minutes + seconds; //alert (refid); $("#refNum").text(refid); var msg = " Sent the following data to backend:-\n username: " + username + "\n usercard: " + cardnumb + "\n withdrawalamount: " + withdrawalamount + "\n repaymentperiod: " + repaymentperiod + "\n contactnumber: " + contactnumber + "\n campaigncode: " + cpgcode + "\n campaignname: " + cpgname + "\n submittime: " + subdate + "\n usertnc: " + tnc + "\n userrefno: " + refid + "\n usercaptchatext: " + veri; //Start overlay $.LoadingOverlay("show"); //Submit form to server via ajax // Send $.ajax({ url: '/cash-in-installment-program/ccEmailSend.jsp', type: 'post', dataType: 'json', data: { action: 'order', surname: sur, givenname: giv, usercard: cardnumb, withdrawalamount : withdrawalamount, repaymentperiod : repaymentperiod, contactnumber : contactnumber, campaigncode : cpgcode, campaignname : cpgname, language : lang, submittime : subdate, source : source, usertnc: tnc, userrefno: refid, usercaptchatext: veri }, success: function(data){ //log('order:', data); //alert(data.message); // Demo var msg = " Sent the following data to backend:-\n username: " + username + "\n usercard: " + cardnumb + "\n withdrawalamount: " + withdrawalamount + "\n repaymentperiod: " + repaymentperiod + "\n contactnumber: " + contactnumber + "\n campaigncode: " + cpgcode + "\n campaignname: " + cpgname + "\n submittime: " + subdate + "\n usertnc: " + tnc + "\n userrefno: " + refid + "\n usercaptchatext: " + veri; //alert(msg); // SUCCESS if(data.result == '0'){ // Clear & reset Form clearAll(); //Show result page $(targetB).slideUp(); $(target).slideDown(500); var shine = "#icon" + id; $(shine).css("opacity",1); var dark = "#icon" + idd; $(dark).css("opacity",0.3); $.LoadingOverlay("hide"); //alert("success"); } else { // ERROR if(data.result == '-1'){ errocount = true; $("#err-veri").slideUp(); $("#err-veri2").slideDown(); $("#err-veri3").slideUp(); //alert("result==-1"); } else if (data.result == '-2'){ errocount = true; $("#err-veri").slideUp(); $("#err-veri2").slideUp(); $("#err-veri3").slideDown(); //alert("result==-2"); } $.LoadingOverlay("hide"); } }, error: function() { errocount = true; $("#err-veri").slideUp(); $("#err-veri2").slideDown(); var errMsg = "Please try again later."; $.LoadingOverlay("hide"); //alert(errMsg); } }); } if ((errocount != true) && id != "s3") { //Show result page $(target).slideDown(500); var shine = "#icon" + id; $(shine).css("opacity",1); var dark = "#icon" + idd; $(dark).css("opacity",0.3); if($(targetB).is(":visible")){ $(targetB).slideUp(500); errUp(); /* display entered value*/ var numformat = "$" + numberWithCommas(withdrawalamount); $("#surnamedis").text(sur); $("#givenamedis").text(giv); $("#cardnumdis").text(cardnumb); $("#withdrawalamountdis").text(numformat); $("#repaymentperioddis").text(repaymentperiod); $("#contactnumberdis").text(contactnumber); /*$("#tncdis").slideUp();*/ } } } function NameValid(nfield) { errUp(); var fvalue = 0; if (nfield == 1) { fvalue = $("#surname").val(); fvalue = fvalue.replace(/[^a-zA-Z\s]/g,""); //English letters + Space $("#surname").val(fvalue); } if (nfield == 2) { fvalue = $("#givenname").val(); fvalue = fvalue.replace(/[^a-zA-Z\s]/g,""); //English letters + Space $("#givenname").val(fvalue); } } function CCValid(ccfield) { errUp(); var fvalue = 0; if (ccfield == 1) { fvalue = $("#cardset1").val(); fvalue = fvalue.replace(/[^0-9]/g,""); $("#cardset1").val(fvalue); if (fvalue.length == 4) { $("#cardset2").focus(); } } if (ccfield == 2) { var field1 = $("#cardset1").val(); fvalue = $("#cardset2").val(); var ccnum = field1 + fvalue; fvalue = fvalue.replace(/[^0-9]/g,""); $("#cardset2").val(fvalue); if (ccnum.length >= 6) { if (!validateCC(ccnum)){ errUp(); $("#err-cardnum3").slideDown(); } } if (fvalue.length == 4) { $("#cardset3").focus(); } } if (ccfield == 3) { fvalue = $("#cardset3").val(); fvalue = fvalue.replace(/[^0-9]/g,""); $("#cardset3").val(fvalue); if (fvalue.length == 4) { $("#cardset4").focus(); } } if (ccfield == 4) { fvalue = $("#cardset4").val(); fvalue = fvalue.replace(/[^0-9]/g,""); $("#cardset4").val(fvalue); if (fvalue.length == 4) { $("#emailaddress").focus(); } } } function clearAll() { $('#tnccheck').removeAttr("checked"); $('form').find(':input').each(function() { switch(this.type) { case 'password': case 'select-multiple': case 'select-one': case 'text': case 'textarea': $(this).val(''); break; case 'checkbox': this.removeAttr("checked"); case 'radio': this.checked = false; } }); errUp(); } function checkInp() { var d=document.getElementById("cardset1").value; var e=document.getElementById("cardset2").value; var f=document.getElementById("cardset3").value; var g=document.getElementById("cardset4").value; if (isNaN(d) || isNaN(e) || isNaN(f) || isNaN(g)) { $("#err-cardnum2").slideDown(); errocount = false; return false; } } function errUp(){ $("#err-surname").slideUp(); $("#err-givenname").slideUp(); $("#err-cardnum").slideUp(); $("#err-cardnum2").slideUp(); $("#err-cardnum3").slideUp(); $("#err-withdrawalamount").slideUp(); $("#err-repaymentperiod").slideUp(); $("#err-contactnum").slideUp(); $("#err-tnc").slideUp(); $("#err-veri").slideUp(); $("#err-veri2").slideUp(); } // VALIDATION function validateName(name) { var re = /^[A-Za-z\s]+$/; // space & eng //var re = /^[-'a-z\u4e00-\u9eff]{1,20}$/i; //var re = /^[\u3300-\u9fff\uf900-\ufaff]{2,}$/; // var re = /^[A-Za-z\u2E80-\u2FD5\u3400-\u4DBF\u4E00-\u9FCC\s]+$/; // space & eng & chinese return re.test(name); } // VALIDATION function validateEmail(email) { var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(email); } // VALIDATION function validateCC(identifier) { var CNCBCards = [ '434689', '434690', '434691', '491891', '491892', '542288', '540954', '539142','624303']; return checkCreditCardPrefix(identifier, CNCBCards, 6); } // VALIDATION function validateNum(numval) { //validate end 000 var numlast = numval.slice(-3); if ((numlast != "000") || !isInteger(numval) || (numval < 3000)) { return false; } else { return true; } } function checkCreditCardPrefix(identifier, cardPrefixs, cardPrefixLen) { var x = cardPrefixs.length; var y = 0; var cardprefix = identifier.substr(0,cardPrefixLen); while (y < x) { if (cardprefix == cardPrefixs[y]) { return true; } y++; } return false; } function numberWithCommas(x) { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); } function isInteger(s) { var i; for (i = 0; i < s.length; i++) { // Check that current character is number. var c = s.charAt(i); if (((c < "0") || (c > "9"))) return false; } // All characters are numbers. return true; } function trim(s) { var i; var returnString = ""; // Search through string's characters one by one. // If character is not a whitespace, append to returnString. for (i = 0; i < s.length; i++) { // Check that current character isn't whitespace. var c = s.charAt(i); if (c != " ") returnString += c; } return returnString; } function stripCharsInBag(s, bag) { var i; var returnString = ""; // Search through string's characters one by one. // If character is not in bag, append to returnString. for (i = 0; i < s.length; i++) { // Check that current character isn't whitespace. var c = s.charAt(i); if (bag.indexOf(c) == -1) returnString += c; } return returnString; } // Declaring required variables var digits = "0123456789"; // non-digit characters which are allowed in phone numbers var phoneNumberDelimiters = "()- "; // characters which are allowed in international phone numbers // (a leading + is OK) var validWorldPhoneChars = phoneNumberDelimiters + "+"; // Minimum no of digits in a phone no. var minDigitsInIPhoneNumber = 8; function isPhoneNumber(strPhone){ var bracket=3 strPhone=trim(strPhone) if(strPhone.indexOf("+")>1) return false if(strPhone.indexOf("-")!=-1)bracket=bracket+1 if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false var brchr=strPhone.indexOf("(") if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false s=stripCharsInBag(strPhone,validWorldPhoneChars); return (isInteger(s) && s.length >= minDigitsInIPhoneNumber); }