| 2 |
lars |
1 |
$(document).ready(function(){
|
|
|
2 |
$.mockjax({
|
|
|
3 |
url: "emails.action",
|
|
|
4 |
response: function(settings) {
|
|
|
5 |
var email = settings.data.email,
|
|
|
6 |
emails = ["glen@marketo.com", "george@bush.gov", "me@god.com", "aboutface@cooper.com", "steam@valve.com", "bill@gates.com"];
|
|
|
7 |
this.responseText = "true";
|
|
|
8 |
if ( $.inArray( email, emails ) !== -1 ) {
|
|
|
9 |
this.responseText = "false";
|
|
|
10 |
}
|
|
|
11 |
},
|
|
|
12 |
responseTime: 500
|
|
|
13 |
});
|
|
|
14 |
|
|
|
15 |
jQuery.validator.addMethod("password", function( value, element ) {
|
|
|
16 |
var result = this.optional(element) || value.length >= 6 && /\d/.test(value) && /[a-z]/i.test(value);
|
|
|
17 |
if (!result) {
|
|
|
18 |
element.value = "";
|
|
|
19 |
var validator = this;
|
|
|
20 |
setTimeout(function() {
|
|
|
21 |
validator.blockFocusCleanup = true;
|
|
|
22 |
element.focus();
|
|
|
23 |
validator.blockFocusCleanup = false;
|
|
|
24 |
}, 1);
|
|
|
25 |
}
|
|
|
26 |
return result;
|
|
|
27 |
}, "Your password must be at least 6 characters long and contain at least one number and one character.");
|
|
|
28 |
|
|
|
29 |
// a custom method making the default value for companyurl ("http://") invalid, without displaying the "invalid url" message
|
|
|
30 |
jQuery.validator.addMethod("defaultInvalid", function(value, element) {
|
|
|
31 |
return value != element.defaultValue;
|
|
|
32 |
}, "");
|
|
|
33 |
|
|
|
34 |
jQuery.validator.addMethod("billingRequired", function(value, element) {
|
|
|
35 |
if ($("#bill_to_co").is(":checked"))
|
|
|
36 |
return $(element).parents(".subTable").length;
|
|
|
37 |
return !this.optional(element);
|
|
|
38 |
}, "");
|
|
|
39 |
|
|
|
40 |
jQuery.validator.messages.required = "";
|
|
|
41 |
$("form").validate({
|
|
|
42 |
invalidHandler: function(e, validator) {
|
|
|
43 |
var errors = validator.numberOfInvalids();
|
|
|
44 |
if (errors) {
|
|
|
45 |
var message = errors == 1
|
|
|
46 |
? 'You missed 1 field. It has been highlighted below'
|
|
|
47 |
: 'You missed ' + errors + ' fields. They have been highlighted below';
|
|
|
48 |
$("div.error span").html(message);
|
|
|
49 |
$("div.error").show();
|
|
|
50 |
} else {
|
|
|
51 |
$("div.error").hide();
|
|
|
52 |
}
|
|
|
53 |
},
|
|
|
54 |
onkeyup: false,
|
|
|
55 |
submitHandler: function() {
|
|
|
56 |
$("div.error").hide();
|
|
|
57 |
alert("submit! use link below to go to the other step");
|
|
|
58 |
},
|
|
|
59 |
messages: {
|
|
|
60 |
password2: {
|
|
|
61 |
required: " ",
|
|
|
62 |
equalTo: "Please enter the same password as above"
|
|
|
63 |
},
|
|
|
64 |
email: {
|
|
|
65 |
required: " ",
|
|
|
66 |
email: "Please enter a valid email address, example: you@yourdomain.com",
|
|
|
67 |
remote: jQuery.validator.format("{0} is already taken, please enter a different address.")
|
|
|
68 |
}
|
|
|
69 |
},
|
|
|
70 |
debug:true
|
|
|
71 |
});
|
|
|
72 |
|
|
|
73 |
$(".resize").vjustify();
|
|
|
74 |
$("div.buttonSubmit").hoverClass("buttonSubmitHover");
|
|
|
75 |
|
|
|
76 |
$("input.phone").mask("(999) 999-9999");
|
|
|
77 |
$("input.zipcode").mask("99999");
|
|
|
78 |
var creditcard = $("#creditcard").mask("9999 9999 9999 9999");
|
|
|
79 |
|
|
|
80 |
$("#cc_type").change(
|
|
|
81 |
function() {
|
|
|
82 |
switch ($(this).val()){
|
|
|
83 |
case 'amex':
|
|
|
84 |
creditcard.unmask().mask("9999 999999 99999");
|
|
|
85 |
break;
|
|
|
86 |
default:
|
|
|
87 |
creditcard.unmask().mask("9999 9999 9999 9999");
|
|
|
88 |
break;
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
);
|
|
|
92 |
|
|
|
93 |
// toggle optional billing address
|
|
|
94 |
var subTableDiv = $("div.subTableDiv");
|
|
|
95 |
var toggleCheck = $("input.toggleCheck");
|
|
|
96 |
toggleCheck.is(":checked")
|
|
|
97 |
? subTableDiv.hide()
|
|
|
98 |
: subTableDiv.show();
|
|
|
99 |
$("input.toggleCheck").click(function() {
|
|
|
100 |
if (this.checked == true) {
|
|
|
101 |
subTableDiv.slideUp("medium");
|
|
|
102 |
$("form").valid();
|
|
|
103 |
} else {
|
|
|
104 |
subTableDiv.slideDown("medium");
|
|
|
105 |
}
|
|
|
106 |
});
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
});
|
|
|
110 |
|
|
|
111 |
$.fn.vjustify = function() {
|
|
|
112 |
var maxHeight=0;
|
|
|
113 |
$(".resize").css("height","auto");
|
|
|
114 |
this.each(function(){
|
|
|
115 |
if (this.offsetHeight > maxHeight) {
|
|
|
116 |
maxHeight = this.offsetHeight;
|
|
|
117 |
}
|
|
|
118 |
});
|
|
|
119 |
this.each(function(){
|
|
|
120 |
$(this).height(maxHeight);
|
|
|
121 |
if (this.offsetHeight > maxHeight) {
|
|
|
122 |
$(this).height((maxHeight-(this.offsetHeight-maxHeight)));
|
|
|
123 |
}
|
|
|
124 |
});
|
|
|
125 |
};
|
|
|
126 |
|
|
|
127 |
$.fn.hoverClass = function(classname) {
|
|
|
128 |
return this.hover(function() {
|
|
|
129 |
$(this).addClass(classname);
|
|
|
130 |
}, function() {
|
|
|
131 |
$(this).removeClass(classname);
|
|
|
132 |
});
|
|
|
133 |
};
|