function CVV2(){window.open("/includes/cvv2.html", "mywindow","toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,width=400,height=560,left=0,top=0");} function TERMS(){window.open("/includes/terms.html", "mywindow","height=400,width=400,toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,left=0,top=0,resizable=no");} function Verisign(){window.open("https://trustsealinfo.verisign.com/splash?form_file=fdf/splash.fdf&dn=www.jamplay.com&lang=en", "mywindow","height=405,width=520,toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,left=0,top=0,resizable=no");} String.prototype.trim = function () { return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"); }; var Signup = { DOM: {}, REG: {// From aMember, most of this isn't used.. EMAIL: /^[0-9a-zA-Z_\.-]+@([0-9a-zA-Z\.\-_]+\.)+[a-zA-Z]{2,7}$$/, TEL: /^1?[\- ]?\(?\d{3}\)?[\- ]?\d{3}[\- ]?\d{4}$/, PC: /^[a-z]\d[a-z] ?\d[a-z]\d$/i, ZIP: /^\d{5}$/, MONEY: /^\d+([\.]\d\d)?$/, CC: null, ZIPsixORseven: /^[a-zA-Z]\d[a-zA-Z] ?\d[a-zA-Z]\d$/, ZIPfiveORten: /^\d{5}(\-\d{4})?$/ }, Text: { Errors: { FirstName: "First Name is required.", LastName: "Last Name is required.", CC: "Credit Card Number must be at least 13 digits.", CCFormat: "Numbers only please, no spaces, dashes, or non-digits.", CCNumbers: "Numbers only please.", Terms: "You must agree in order to become a member.", Coupon: { InvalidProduct: 'Sorry, this code is invalid for this product', Invalid: 'Sorry, this code is invalid!', Expired: 'Sorry, this code has expired!', Success: 'DISCOUNT ACCEPTED.This code applies the following discounts:' }, Email: { Duplicate: "Sorry, this email is being used under a different account.", Format: "Sorry, this email address is not valid.", Empty: "Sorry, but your email address is required." }, Login: { Duplicate: "Sorry, this name already in use.", Empty: "Sorry, but your login name is required." }, Password: { NoMatch: "Sorry, passwords do not match.", Spaces: "Sorry, no spaces allowed.", Length: "Sorry, password needs to be at least 4 characters." } } }, Variables: { Paysys: null, Coupon: null, PriceGroup: null, Products: null, Selected: null, SelectedPayment: null }, collect: function() { this.DOM.productOptions = $('productOptions'); this.DOM.paymentCheck = this.DOM.productOptions.down('img#checkmarkLarge'); this.DOM.productOptionsDivs = this.DOM.productOptions.select('div'); this.DOM.productOptionsInputs = this.DOM.productOptions.select('input'); this.DOM.textFields = $$('#signupForm input[type="text"]', '#signupForm input[type="password"]'); this.DOM.SelectCountry = $('countrySelect'); this.DOM.SelectState = $('stateSelect'); this.DOM.StateText = $('stateText'); this.DOM.SelectExp = $$('select.expiration'); this.DOM.PassOne = $('passwordFirst'); this.DOM.PassTwo = $('passwordSecond'); this.DOM.Terms = $('agreeTerms'); this.DOM.paymentTypes = $('payment-options'); this.DOM.paymentTitle = this.DOM.paymentTypes.previous('b.complete'); this.DOM.paymentTypes.Divs = this.DOM.paymentTypes.select('div'); this.DOM.paymentTypes.Radios = this.DOM.paymentTypes.select('input[type="radio"]'); this.DOM.paymentDivs = $$('#paymentDivs div'); this.DOM.couponInput = $('couponInput'); this.setupPage(); }, brickPage: function() { $('Signup').setOpacity(0.2); $('signupForm').disable(); alert('Invalid parameters for signup process'); window.location = "https://www.jamplay.com/pro/signup.php"; return true; }, setupPage: function() { //console.info('Products Available: ' + this.Variables.Products); //console.log('Paysys: ' + this.Variables.Paysys); //console.log('Coupon: ' + this.Variables.Coupon); //console.log('PriceGroup: ' + this.Variables.PriceGroup); if (this.Variables.Products == 1 && this.Variables.Paysys) {this.brickPage();} if (!this.Variables.Paysys && !this.Variables.PriceGroup) {this.brickPage();} if (this.Variables.Coupon) { Signup.DOM.couponInput.setAttribute('readOnly','readOnly'); Signup.error(Signup.DOM.couponInput, true); } this.setupEvents(); if (this.Variables.Paysys) {//console.info('SHOW PAY SYSTEMS'); this.selectPayment(); // Search for Product Option Divs, assign // click events for easy product selection. this.DOM.paymentTypes.Divs.each(function(div, i) { div.observe('mousedown', function() { if (!Signup.DOM.paymentTypes.Radios[i].checked) { Signup.DOM.paymentTypes.Radios[i].checked = true; Signup.selectPayment(); } }); }); this.DOM.productOptionsDivs.each(function(option, i) { if (!Signup.DOM.productOptionsInputs[i].checked) { Signup.DOM.productOptionsDivs[i].className = 'dead'; } else { Signup.DOM.productOptionsDivs[i].className = 'alive'; Signup.Variables.Selected = Signup.DOM.productOptionsDivs[i]; } option.observe('mouseover', function() {if (this.hasClassName('dead')) {this.addClassName('hover');}}); option.observe('mouseout', function() {this.removeClassName('hover');}); option.observe('mousedown', function() {Signup.selectProduct(option, i);}); }); this.DOM.SelectCountry.observe('change', Signup.swapStates); this.DOM.SelectState.observe('change', function() { if (this.selectedIndex != 0) { Signup.error(this, true); } else { Signup.error(this, false, "State is required."); } }); this.DOM.SelectExp.each(function(sel,i) {sel.observe('change', Signup.checkYear)}); this.DOM.SelectExp[1].selectedIndex = this.DOM.SelectExp[1].selectedIndex+1; } else { $('Payment').hide(); //console.info('HIDE PAY SYSTEMS'); } }, setupEvents: function() { this.DOM.Terms.observe('change', function() { if (this.checked) {Signup.error(this, true);} else {Signup.error(Signup.DOM.Terms, false, Signup.Text.Errors.Terms);} }); this.DOM.textFields.each(function(textfield, i) { if (textfield.name == 'coupon') { new Form.Element.DelayedObserver(textfield, 0.5, function(){Signup.Validate.realTime(textfield);});//textfield.observe('keyup', function() {Signup.Validate.realTime(this);}); } else { textfield.observe('change', function() {Signup.Validate.realTime(this);}); //new Form.Element.DelayedObserver($('firstName'), 0.5, function(){}); } }); this.DOM.PassTwo.readOnly = true; this.DOM.PassOne.observe('keyup', function() { Signup.DOM.PassTwo.readOnly = false; Signup.DOM.PassOne.stopObserving('keyup'); return; }); }, checkYear: function() {//console.log('index: ' +this.selectedIndex+' | month: '+month); var d = new Date(); var month = d.getMonth(); var y = d.getYear(); var year = (y < 1000) ? y + 1900 : y; var selectedYear = $F(Signup.DOM.SelectExp[1]); var selectedMonth = $F(Signup.DOM.SelectExp[0]); if (Signup.DOM.SelectExp[0].selectedIndex < month && year == selectedYear) { Signup.error(this, false, "Looks like your card may be expired."); } else { Signup.error(this, true); } }, selectPayment: function() { // Not great code here, but functional. Show and hide payment options.. // Only caveat, divs need to be in order in DOM collection, as they are on the page.. Signup.DOM.paymentDivs.each(function(div,i) { if (Signup.DOM.paymentTypes.Radios[i].checked && Signup.DOM.paymentTypes.Radios[i].readAttribute('rel') == div.readAttribute('id')) { Signup.DOM.paymentTitle.className = 'complete'; // if it had an error div.show(); Signup.DOM.paymentTypes.Divs[i].className = 'active'; Signup.Variables.SelectedPayment = Signup.DOM.paymentTypes.Radios[i].value; } else { div.hide(); Signup.DOM.paymentTypes.Divs[i].className = ''; } }); }, selectProduct: function(option, i) { if (!Signup.DOM.productOptionsInputs[i].checked) { var pixelResult = 220 + (i * 300); Signup.Variables.Selected.down('input').checked = false; Signup.DOM.productOptionsInputs[i].checked = true; new Effect.Morph(Signup.DOM.paymentCheck, {style:'left:'+pixelResult+'px', duration:0.5}); Signup.Variables.Selected.className = 'dead'; option.className = 'alive'; Signup.Variables.Selected = option; this.ajaxTest(Signup.DOM.couponInput); } }, swapStates: function() { var selectedCountry = $F(Signup.DOM.SelectCountry); var waiting = $('waiting'); Signup.error(Signup.DOM.SelectCountry, true); Signup.restart(Signup.DOM.SelectState); if (selectedCountry == '') { Signup.restart(Signup.DOM.SelectCountry); Signup.DOM.SelectState.selectedIndex = 0; Signup.DOM.SelectState.disabled = true; Signup.DOM.StateText.disabled = true; Signup.DOM.SelectState.hide(); Signup.DOM.StateText.hide(); waiting.show(); } else { waiting.hide(); new Ajax.Request('/pro/ajax/get_states.php', {asynchronous: false, method:'post', parameters: {country:selectedCountry}, onSuccess: function(evt) { var data = evt.responseText.evalJSON(); //Check to see if there are states available for this country // if not, disable and hide the select box, and show the empty text field. if (evt.responseText == 'null') { Signup.DOM.StateText.disabled = false; Signup.DOM.StateText.show(); Signup.DOM.SelectState.selectedIndex = 0; Signup.DOM.SelectState.disabled = true; Signup.DOM.SelectState.hide(); } // Enable the drop down, hide the text box, and start working on // clearing the old select and ajax to re-populate it. else { Signup.DOM.StateText.value = ''; Signup.DOM.StateText.disabled = true; Signup.DOM.StateText.hide(); Signup.DOM.SelectState.show(); Signup.DOM.SelectState.disabled = false; // Dump the current options in the state select box. Signup.DOM.SelectState.select('option').each(function(opt,i) {opt.remove();}); // Loop through the JSON Object for new states. $H(data).each(function(obj, i) { var newOption = new Element('option', {'value':obj[0], 'label':obj[1]}).update(obj[1]); Signup.DOM.SelectState.insert({'bottom':newOption}); }); } } }); } }, ajaxTest: function(textfield) { if (textfield.name == 'coupon' && textfield.value == '') { Signup.Coupon.remove(); return; } var params = {}; var text = null; if (textfield.name == 'email') { params.coupon = -1; params.login = -1 params.email = textfield.value; text = Signup.Text.Errors.Email.Duplicate; } if (textfield.name == 'login') { params.coupon = -1; params.login = textfield.value; params.email = -1; text = Signup.Text.Errors.Login.Duplicate; } if (textfield.name == 'coupon') { params.coupon = textfield.value; params.login = -1; params.email = -1; text = 'Coupon code is not valid, sorry!'; } new Ajax.Request('/index.php/services/check-code-unique/', {asynchronous: false, method:'post', parameters: params, onSuccess: function(evt) {// 1 means good, non duplicate, 0 means duplicate if (textfield.name == 'coupon') { if (evt.responseJSON.c == -1) { Signup.Coupon.remove(); Signup.error(textfield, false, Signup.Text.Errors.Coupon.Invalid); } if (evt.responseJSON.c == 0) { Signup.Coupon.remove(); Signup.error(textfield, false, Signup.Text.Errors.Coupon.Expired); } if (evt.responseJSON.c == 1) { Signup.Coupon.apply(textfield, evt.responseJSON.discount_type, evt.responseJSON.discount, evt.responseJSON.pd, evt.responseJSON.pg); } } else { if (evt.responseJSON.e == 0 || evt.responseJSON.l == 0) {Signup.error(textfield, false, text);} else {Signup.error(textfield, true);} } } }); }, Coupon: { remove: function() { Signup.restart(Signup.DOM.couponInput); if (Signup.Variables.Paysys) { $$('li[title="couponLI"]').each(function(li,i) {li.remove()}); } }, compute: function(productPrice, discountType, discount) { var final = (discountType == 'flat') ? productPrice - discount : productPrice - (productPrice * (discount/100)); final = Math.round(final*100+((final*1000)%10>4?1:0))/100; return final; }, apply: function(textfield, discountType, discount, codeProductIDs, priceGroup) { var IDs = []; var pageIDs = []; var newPrices = []; // Formatting: taking the available product_ids from AJAX that this code will work on var tempArr = codeProductIDs.split(","); tempArr.each(function(f,i) {IDs.push(Number(f));}); // Take the inputs on the page, grab their value (product_id), and format/push to new array Signup.DOM.productOptionsInputs.each(function(input, i) {pageIDs.push(Number(input.value));}); // run an intersection to see if they share any values console.log('IDs:'+IDs+' | pageIDs:'+pageIDs+' ... ' +intersection); var intersection = pageIDs.intersect(IDs); // If the code's available products didn't match any of our product_ids if (intersection.length == 0) { Signup.error(textfield, false, Signup.Text.Errors.Coupon.InvalidProduct); } else { Signup.DOM.productOptionsInputs.each(function(input,i) { var productID = input.value; IDs.each(function(id,a) { if (productID == id && Signup.Variables.Paysys) { var product = input.up('div').readAttribute('id'); var final = Signup.Coupon.compute(parseFloat(product.split("|")[1]), discountType, discount); var finalText = product.split("|")[0] +': $'+final; newPrices.push(finalText); } }); }); var text; var li = Signup.restart(textfield); li.className = 'goodMessage'; if (Signup.Variables.Paysys) { var display = (discountType == 'flat') ? '$'+discount : discount+'% '; text = ''+display + Signup.Text.Errors.Coupon.Success + ''+newPrices.join('')+''; } else { text = 'Successful code submission!'; } li.insert(""+text+""); } } }, restart: function(textfield) { var li = textfield.up('li'); var span = li.down('span') || null; //console.log('span = ' + span); if (span) {span.remove();} li.className = ''; return li; }, error: function(textfield, success, text) { var li = this.restart(textfield); var message = text || null; if (success) {li.className = 'good';} else { if (message) { li.className = 'badMessage'; li.insert(""+text+""); if (textfield.name != 'coupon') { Form.Element.activate.delay(0.1, textfield); } } else { li.className = 'bad'; } } }, Validate: { mandatory: function(textfield) { if (textfield.value.length > 0) {Signup.error(textfield, true);} else {Signup.error(textfield, false);} }, testMatch: function(textfield) { if (Signup.DOM.PassOne.value != Signup.DOM.PassTwo.value) { Signup.error(textfield, false, Signup.Text.Errors.Password.NoMatch); } else { Signup.error(Signup.DOM.PassOne, true); Signup.error(Signup.DOM.PassTwo, true); } }, realTime: function(textfield) { var fieldName = textfield.name; var fieldID = textfield.id; var result = textfield.value; var errorText = null; // Pretty dirty syntax structure here, lots of conditionals so no // real elegant way around a shit load of if else.. // Could clean up at some point, but it's functional. var test = { //coupon: function() {Signup.Validate.mandatory(textfield);}, name_f: function() {Signup.Validate.mandatory(textfield);}, name_l: function() {Signup.Validate.mandatory(textfield);}, cc_street: function() {Signup.Validate.mandatory(textfield);}, cc_city: function() {Signup.Validate.mandatory(textfield);}, cc_zip: function() {Signup.Validate.mandatory(textfield);}, cc_state: function() {if (textfield.style.display != 'none') {Signup.Validate.mandatory(textfield);}}, cc_number: function() { //var trim = textfield.value.replace(/^\s+|\s+$/g,""); //textfield.value = trim; if (!result.match(/^\d+$/)) { Signup.error(textfield, false, Signup.Text.Errors.CCFormat); } else { if (result.length < 13) {Signup.error(textfield, false, Signup.Text.Errors.CC);} else {Signup.error(textfield, true);} } }, cc_code: function() { if (result != '' && !result.match(/^\d+$/)) { Signup.error(textfield, false, Signup.Text.Errors.CCNumbers); } else if (result == '') { Signup.restart(textfield); } else { Signup.error(textfield, true); } }, email: function() { if (result.length == 0) {Signup.error(textfield, false);} if (result.match(Signup.REG.EMAIL)) {Signup.ajaxTest(textfield);} else {Signup.error(textfield, false, Signup.Text.Errors.Email.Format);} }, login: function(textfield) { if (result.length == 0) {Signup.error(textfield, false);} else {Signup.ajaxTest(textfield); } }, coupon: function(textfield) { //console.log('from real time'); Signup.ajaxTest(Signup.DOM.couponInput); }, pass0: function(textfield) { if (result.match(/^\s*(\S*(\s+\S+)*)\s/)) { Signup.error(textfield, false, Signup.Text.Errors.Password.Spaces); return; } if (result.length < 4) { Signup.error(textfield, false, Signup.Text.Errors.Password.Length); return; } else { result.trim(); if (Signup.DOM.PassTwo.value.length > 3) { Signup.Validate.testMatch(textfield); return; } else { if (result.length > 3) { Signup.error(textfield, true); } else { } } } }, pass1: function(textfield) { result.trim(); if (Signup.DOM.PassOne.value.length == 0) { Signup.Validate.testMatch(textfield); return; } if (Signup.DOM.PassOne.value == result) { Signup.Validate.testMatch(textfield); return; } else { Signup.error(textfield, false, Signup.Text.Errors.Password.NoMatch); } } }; test[fieldName](textfield); }, onSubmit: function(theForm) { // Enable the button on a delay, this is mostly // to avoid double-clicks creating double entries var btn = $('submitBtn'); btn.disabled=true; // create an empty array for errorFields var errorFields = new Array(); // check all required fields in the Account area, and coupon code (non payment) // we will check the credit card variables seperately. Signup.DOM.textFields.each(function(textfield, i) { // If the field has the required class with an error listed, or is required // and has an empty value, push it into our errorArray if (textfield.hasClassName('required')) { var errorMessages = Signup.DOM.textFields[i].up('li.bad, li.badMessage') || null; // check if there are already dicked fields on the page if (errorMessages) { errorFields.push(textfield); } else if (textfield.value.length == 0) { Signup.error(textfield, false); errorFields.push(textfield); } } // If it's not required (like coupon code), and it bricks out, let's // restart the form element and empty it's value else { //console.log(textfield.name); //return; //textfield.value = ''; //Signup.restart(textfield); } }); // Only check CC fields is it's selected as the current payment // option. Skip and ignore if PayPal / Google Checkout are selected. // Manually check that a payment type available and selected if (Signup.Variables.Paysys && !Signup.Variables.SelectedPayment) { errorFields.push($('paysys_idpaypal_r')); } else if (Signup.Variables.SelectedPayment == 'authorize_aim') { var requiredCC = $('cc').select('input, select'); requiredCC.each(function(field, a) { // If the field has a mandatory class name, is empty, or hasn't moved // off of initial selectedIndex, validation is needed. if (field.hasClassName('mandatory')) { if (field.value.length == 0 || field.selectedIndex == 0) { if (field.style.display != 'none') {//console.log('if ' + field.id); errorFields.push(field); Signup.error(field, false); } } } else { // Clean up CC field, strip anything that isn't a digit if (field.name == 'cc_number') {//console.log('else ' + field.id); field.value = field.value.replace(/\D/g,''); } if (field.name != 'cc_code') { Signup.error(field, true); } } }); } else { // nada, probably PayPal. } // Manually check the terms agreement since we aren't going to loop through // this type of input. if (!$('agreeTerms').checked) { Signup.error($('agreeTerms'), false, Signup.Text.Errors.Terms); errorFields.push($('agreeTerms')); } //errorFields.each(function(e) {console.log('Error fields = ' +e.name);}); // Check error array for fields if (errorFields[0]) { Form.Element.focus.delay(0.1, errorFields[0]); errorFields.each(function(error, i) { if (error.name == 'paysys_id') { Signup.DOM.paymentTitle.addClassName('error'); if (i == 0) { // if this is the only error Effect.Pulsate(Signup.DOM.paymentTitle, {pulses:4, duration: 1}); } } }); Effect.Pulsate(errorFields[0], {pulses:4, duration: 1}); Form.Element.enable.delay(1, btn); errorFields.clear(); return false; } // No errors, proceed else { btn.value="Processing..."; var couponError = $('couponForm').down('li').hasClassName('badMessage'); if (couponError) { Signup.DOM.couponInput.value = ''; } $('signupForm').submit(); } } } }; document.observe("dom:loaded", function() { Signup.collect(); }); /* var containerTag = 'DIV'; var compatible = ( document.getElementById && document.getElementsByTagName && document.createElement && !(navigator.userAgent.indexOf('MSIE 5') != -1 && navigator.userAgent.indexOf('Mac') != -1) ); if (compatible) { document.write(''); var waitingRoom = document.createElement('div'); } var hiddenFormFieldsPointers = new Object(); function prepareForm() { if (!compatible) return; var marker = document.createElement(containerTag); marker.style.display = 'none'; var x = document.getElementsByTagName('balls'); for (var i=0;i