// JavaScript Document var valid = new Object(); // REGEX Elements // matches zip codes valid.zipCode = /\d{5}(-\d{4})?/; // matches $17.23 or $14,281,545.45 or ... valid.Currency = /\$\d{1,3}(,\d{3})*\.\d{2}/; // matches 5:04 or 12:34 but not 75:83 valid.Time = /^([1-9]|1[0-2]):[0-5]\d$/; //matches email valid.emailAddress = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // matches phone ###-###-#### valid.phoneNumber = /^\(?\d{3}\)?\s|-\d{3}-\d{4}$/; // International Phone Number valid.phoneNumberInternational = /^\d(\d|-){7,20}/; // IP Address valid.ipAddress = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/; // Date xx/xx/xxxx valid.Date = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/; // state Abbreviation valid.state = /^(AK|AL|AR|AZ|CA|CO|CT|DC|DE|FL|GA|HI|IA|ID|IL|IN|KS|KY|LA|MA|MD|ME|MI|MN|MO|MS|MT|NB|NC|ND|NH|NJ|NM|NV|NY|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VA|VT|WA|WI|WV|WY)$/i; function deleteItem(dUrl,dName) { if (dName = "") { dName = "item"; } var x = confirm("Are you sure you want to delete this "+dName+"?"); if (x) { window.location=dUrl; } } // Social Security Number valid.SSN = /^\d{3}\-\d{2}\-\d{4}$/; /*$(document).ready(function(){ $("#wrapper").css("width",$(window).width()-50); $("#panel_left").css("width",$("#wrapper").width()-$("#panel_right").width()-30); $("#feed_area").css("width",$("#panel_left").width()-$(".left_menu").width()-25); $(".feedItemProject").tooltip(); });*/ function submitForm(form_id) { var elm = "#" + form_id; $("input").each(function(){ $(this).removeClass("error_field"); }); $(elm+" .form").hide(); $(elm+" .formLoading").show(); $(elm+" .submitButton").hide(); if (validateForm(elm)) { $.post($(elm).attr("action"),$(elm).serialize(),function(data){ var returnObject = $.parseJSON(data); if (returnObject.result == "success") { window.location=str_replace('[returnMessage]',returnObject.message,$(elm).attr("forwardUrl")); } else { $(elm+" .formError").show(); $(elm+" .submitButton").show(); $(elm+" .form").show(); $(elm+" .formLoading").hide(); $(elm+" .errorText").html(returnObject.message); if (returnObject.field != "") { $("input[name='"+returnObject.field+"']").addClass("error_field"); } } }); } else { $(elm+" .form").show(); $(elm+" .submitButton").show(); $(elm+" .formLoading").hide(); } } function validateForm(elm) { // make sure all fields marked required are filled out. var error = 0; $(elm).find("input").each(function(){ if (!error) { if ($(this).hasClass("required") && strlen($(this).val()) == 0) { $(this).addClass("error_field"); $(this).focus(); $(elm+" .formError").show(); $(elm+" .errorText").html("You are missing a required field (Outlined in red)."); error = 1; return false; } if ($(this).hasClass("password")) { // they must have a confirm password var confirmPassElm = "input[name="+$(this).attr("name")+"_confirm]"; if ($(this).val() != $(confirmPassElm).val()) { $(this).addClass("error_field"); $(confirmPassElm).addClass("error_field"); $(elm+" .formError").show(); $(elm+" .errorText").html("The passwords you entered don't match."); error = 1; } } if ($(this).hasClass("email") && strlen($(this).val()) > 0) { var emailValid = validateEmail($(this).val()); if (!emailValid) { $(this).addClass("error_field"); $(elm+" .formError").show(); $(elm+" .errorText").html("You've entered an invalid e-mail address."); error = 1; } } if ($(this).hasClass("creditCard") && strlen($(this).val()) > 0) { var cardValid = Mod10($(this).val()); //alert(cardValid); if (!cardValid) { $(this).addClass("error_field"); $(this).focus(); $(elm+" .formError").show(); $(elm+" .errorText").html("You've entered an invalid card number."); error = 1; } } if ($(this).hasClass("number") && strlen($(this).val()) > 0) { if (!isNumeric($(this).val())) { $(this).addClass("error_field"); $(this).focus(); $(elm+" .formError").show(); $(elm+" .errorText").html("Field outlined in red must be a valid number."); error = 1; } } if ($(this).hasClass("year") && strlen($(this).val()) > 0) { if (strlen($(this).val()) != 2 && strlen($(this).val()) != 4) { $(this).addClass("error_field"); $(elm+" .formError").show(); $(elm+" .errorText").html("You've entered an invalid Year. Must be YY or YYYY format."); error = 1; } } if ($(this).hasClass("month") && strlen($(this).val()) > 0) { if (strlen($(this).val()) != 2) { $(this).addClass("error_field"); $(elm+" .formError").show(); $(elm+" .errorText").html("You've entered an invalid Month. Must be MM format."); error = 1; } } /*if ($(this).hasClass("state") && strlen($(this).val()) > 0) { if (!$(this).val().match(valid.state)) { $(this).addClass("error_field"); $(elm+" .formError").show(); $(elm+" .errorText").html("You've entered an invalid State"); error = 1; } }*/ } }); if (error) { return false; } return true; } function Mod10(ccNumb) { // v2.0 var valid = "0123456789" // Valid digits in a credit card number var len = ccNumb.length; // The length of the submitted cc number var iCCN = parseInt(ccNumb); // integer of ccNumb var sCCN = ccNumb.toString(); // string of ccNumb sCCN = sCCN.replace (/^s+|s+$/g,''); // strip spaces var iTotal = 0; // integer total set at zero var bNum = true; // by default assume it is a number var bResult = false; // by default assume it is NOT a valid cc var temp; // temp variable for parsing string var calc; // used for calculation of each digit // Determine if the ccNumb is in fact all numbers for (var j=0; j= 15){ // 15 or 16 for Amex or V/MC for(var i=len;i>0;i--){ // LOOP throught the digits of the card calc = parseInt(iCCN) % 10; // right most digit calc = parseInt(calc); // assure it is an integer iTotal += calc; // running total of the card number as we loop - Do Nothing to first digit i--; // decrement the count - move to the next digit in the card iCCN = iCCN / 10; // subtracts right most digit from ccNumb calc = parseInt(iCCN) % 10 ; // NEXT right most digit calc = calc *2; // multiply the digit by two // Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7, // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple. switch(calc){ case 10: calc = 1; break; //5*2=10 & 1+0 = 1 case 12: calc = 3; break; //6*2=12 & 1+2 = 3 case 14: calc = 5; break; //7*2=14 & 1+4 = 5 case 16: calc = 7; break; //8*2=16 & 1+6 = 7 case 18: calc = 9; break; //9*2=18 & 1+8 = 9 default: calc = calc; //4*2= 8 & 8 = 8 -same for all lower numbers } iCCN = iCCN / 10; // subtracts right most digit from ccNum iTotal += calc; // running total of the card number as we loop } // END OF LOOP if ((iTotal%10)==0){ // check to see if the sum Mod 10 is zero bResult = true; // This IS (or could be) a valid credit card number. } else { bResult = false; // This could NOT be a valid credit card number } } } return bResult; // Return the results } function isNumeric(sText) { var ValidChars = "0123456789"; var IsNumber=true; var Char; for (i = 0; i < sText.length && IsNumber == true; i++) { Char = sText.charAt(i); if (ValidChars.indexOf(Char) == -1) { IsNumber = false; } } return IsNumber; } function isCash(sText) { var ValidChars = "0123456789."; var IsNumber=true; var Char; for (i = 0; i < sText.length && IsNumber == true; i++) { Char = sText.charAt(i); if (ValidChars.indexOf(Char) == -1) { IsNumber = false; } } return IsNumber; } function validateReg(sText,regexp) { return sText.match(regexp); } function validateEmail(email) { var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; var address = email; return reg.test(address); } function loadContent(path) { window.location="http://www.lovedango.com/"+path; } function checkEnter(e) { //e is event object passed from function invocation var characterCode; if(e && e.which) { //if which property of event object is supported (NN4) e = e; characterCode = e.which; //character code is contained in NN4's which property } else { e = event characterCode = e.keyCode; //character code is contained in IE's keyCode property } if(characterCode == 13) { //if generated character code is equal to ascii 13 (if enter key) login(); return false; } else { return true; } }