// JavaScript Document //field validation ----------------------------------------- function fieldCheck(field,alerttxt) { with (field) { if (value==null||value=="") { alert(alerttxt);return false; } else { return true; } } } //----------------------------------------------------------- //email validation ------------------------------------------- function emailCheck(email, alerttxt) { if (email == '' || email == null) { alert(alerttxt); return false; } else { //alert(email); var at=email.indexOf('@'); var dot=email.lastIndexOf('.'); var atpos=email.lastIndexOf('@'); var emlen=email.length; if (at<1||dot-at<2||atpos+1==emlen||dot+1==emlen||emlen-dot<3) { alert(alerttxt); return false } } return true; } //----------------------------------------------------------------- //for phone number check ------------------------------------------ function phoneCheck(pnum, alerttxt) { if (pnum == '' || pnum == null) { alert(alerttxt); return false; } else { var phchar="1234567890 -_+.()"; for (i=0;i<=pnum.length;i++) { if(phchar.indexOf(pnum.charAt(i))==-1) { alert(alerttxt); return false ; } } } return true ; } //---------------------------------------------------------------- //for number check------------------------------------------------ function numCheck(pnum, alerttxt) { if (pnum == '' || pnum == null) { alert(alerttxt); return false; } else { var phchar="1234567890."; for (i=0; i<=pnum.length; i++) { if(phchar.indexOf(pnum.charAt(i))==-1) { alert(alerttxt); return false ; } } } return true ; } //----------------------------------------------------------------- //Radio butoon check boxes --------------------------------------- function checkBox(chkname, alerttxt) { alert(chkname); var inputs = document.getElementsByTagName("input"); a=0; for(var t = 0;t < inputs.length;t++){ if(inputs[t].type == "checkbox" && inputs[t].checked == true && inputs[t].name===chkname) { a=1; } } //alert(a) ; if(a==0) { alert(alerttxt); return false ; }else { return true ; } } //---------------------------------------------------------------- //For radio boxes function radio(radname,alerttxt) { //alert(chkname); var inputs = document.getElementsByTagName("input"); a=0; for(var t = 0;t < inputs.length;t++){ if(inputs[t].type == "radio" && inputs[t].checked == true && inputs[t].name===radname) { a=1; } } //alert(a) ; if(a==0) { alert(alerttxt); return false ; }else { return true ; } } //----------------------------------------------------------------- //form validation ------------------------------------------------- function validate_form(thisform) { //alert(thisform) ; with (thisform) { //alert(tamount.value); if (fieldCheck(tamount,"Check the servicess or custom quote to continue...")==false) {tamount.focus();return false;} if (fieldCheck(name,"Name must be filled out!")==false) {name.focus();return false;} if (emailCheck(email.value,"Valid email must be filled out!")==false) {email.value=''; email.focus();return false;} if (fieldCheck(ccname,"Credit card holder name must be filled out!")==false) {ccname.focus();return false;} if (fieldCheck(cctype,"Select the type of credit card!")==false) {cctype.focus();return false;} if (isValidCreditCard(ccnum.value, cctype.value, "Credit card number must be valid!")==false) {ccnum.value=''; ccnum.focus();return false;} if (fieldCheck(ccmonth,"Expiry month must be selecte!")==false) {ccmonth.focus();return false;} if (fieldCheck(ccyear,"Expiry year must be selecte!")==false) {ccyear.focus();return false;} if (isExpiryDate(ccmonth.value, ccyear.value, "Card was expired. Sorry!")==false) {ccyear.focus();return false;} } } //---------------------------------------------------------------- function createElements(cntry) { //alert(cntry) ; document.getElementById('austate').style.visibility='hidden'; if(cntry == 'AU'){ //document.getElementById('austate').innerHTML = '' ; //document.getElementById('austate').innerHTML = 'jfsadfsadjfsl' ; document.getElementById('austate').style.visibility='visible'; } } //Credit card validation------------------------------------------- function isValidCreditCard(ccnum, type, alerttxt) { // alert(ccnum); //alert(type); if (type == "Visa") { // Visa: length 16, prefix 4, dashes optional. var re = /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/; } else if (type == "MasterCard") { // Mastercard: length 16, prefix 51-55, dashes optional. var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/; } else if (type == "Amex") { // American Express: length 15, prefix 34 or 37. var re = /^3[4,7]\d{13}$/; } else if (type == "Diners") { // Diners: length 14, prefix 30, 36, or 38. var re = /^3[0,6,8]\d{12}$/; }else if (type == "Disc") { // Discover: length 16, prefix 6011, dashes optional. var re = /^6011-?\d{4}-?\d{4}-?\d{4}$/; } if (!re.test(ccnum)) { alert(alerttxt); return false; } // Remove all dashes for the checksum checks to eliminate negative numbers ccnum = ccnum.split("-").join(""); // Checksum ("Mod 10") // Add even digits in even length strings or odd digits in odd length strings. var checksum = 0; for (var i=(2-(ccnum.length % 2)); i<=ccnum.length; i+=2) { checksum += parseInt(ccnum.charAt(i-1)); } // Analyze odd digits in even length strings or even digits in odd length strings. for (var i=(ccnum.length % 2) + 1; i expiry.getTime()) { alert(alerttxt) return false; } else { //alert("success") return true; } } //--------------------------------------------------------- //*********************************for adding total************************************ function checkTotal() { //alert('price'); var consult_amount= 0; var checkbox_amount=0; var custom_amount=0; var total_amount; // discount list array; var discount = new Array(); discount["0NIEUDISC1"]= 0.01; discount["0NIEUDISC2"]= 0.02; discount["0NIEUDISC3"]= 0.03; discount["0NIEUDISC4"]= 0.04; discount["0NIEUDISC5"]= 0.05; discount["0NIEUDISC6"]= 0.06; discount["0NIEUDISC7"]= 0.07; discount["0NIEUDISC8"]= 0.08; discount["0NIEUDISC9"]= 0.09; discount["1NIEUDISC0"]= 0.1; // discount percent var dpercent = document.fproducts.discount_code.value; dpercent = discount[dpercent] ; //alert(dpercent) ; consult_amount = consultTotal(); /*document.fproducts.custom_amount.value = custom_amount ; document.fproducts.custom_amount.readOnly = true ;*/ checkbox_amount = gTotal(); if(document.fproducts.custom_amount.value!='') { custom_amount = parseFloat(document.fproducts.custom_amount.value); } else { custom_amount = 0; } // alert(custom_amount) ; total_amount = parseFloat(custom_amount)+parseFloat(checkbox_amount)+parseFloat(consult_amount) ; if (dpercent!= '' && !isNaN(dpercent)) { total_amount = total_amount - (total_amount*dpercent) ; } //alert(total_amount) ; if(total_amount==0) { document.fproducts.amount.value= total_amount; document.f_service.tamount.value= total_amount; document.fproducts.amount.readOnly= true ; alert("Please check your service to continue.!"); document.getElementById('prod1').focus; return false ; } document.fproducts.amount.value= total_amount; document.f_service.tamount.value= total_amount; document.fproducts.amount.readOnly= true ; } //********************************************************************** //*********************************for adding total************************************ function gTotal() { //alert(price); var inputs = document.getElementsByTagName("input"); var amount = 0; for(var t = 0;t < inputs.length;t++){ // alert(t); if(inputs[t].type == "checkbox" && inputs[t].checked == true && inputs[t].name=== 'service[]') { //alert('fasdf') amount = amount+parseFloat(inputs[t].value); } } //alert(amount) ; return amount ; } //********************************************************************** //*********************************for adding Custom total************************************ function consultTotal() { //alert(price); var amount; var a=0; var b=0; if(document.fproducts.tax_consult.value!='') { a= parseFloat(document.fproducts.tax_consult.value); } if(document.fproducts.finance_consult.value!='') { b= parseFloat(document.fproducts.finance_consult.value); } amount = parseFloat(a) + parseFloat(b) ; // alert(amount) ; return amount ; } //**********************************************************************