﻿/** FORMS **/
var PROCESS_ERROR='Sorry, but there was an error processing your request. Please refresh the page and try again.';
var TIMEOUT_ERROR='Sorry, but your request timed out. Please refresh the page and try again.';
var ERROR_MSG_CLASS='.errorMessage';
var ERROR_CLASS='error';
var POST_PAGE='/ajax/';
var SUBMIT_MSG='SUBMIT';
var SENDING_MSG='SENDING...';

var FORM_ID="#joinForm";
var MESSAGE_ID="#message";
var SUBMIT_BTN="#joinButton";
var FORM_OBJ_ID=1;

function checkForm(id){
	$(id + ' .required-field').each(function(e){ $(this).blur(); });
	var errors=$('span.error:visible').length;
	return errors==0;
}
function submitForm(formId, action){
	if(!checkForm(formId)) return false;
	
	$(SUBMIT_BTN).unbind('click');
	$(SUBMIT_BTN).html(SENDING_MSG);
	
	var d="";
	$(formId+' :checkbox').each(function() {
         this.value = this.checked?'on':'off';
     });
	$(formId + ' input,select').each(function(){
	    d+=this.id+'='+$(this).val()+'&';
	});
	$.getJSON(POST_PAGE+action+"?"+d+'form_id='+FORM_OBJ_ID,
        function(json){
          onSubmitComplete(json,formId);
        });
}
function validateEmail(field) {
	if(field.id.indexOf('email') < 0) return true;
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($.trim(field.value))) return true;
	return false;
}
function validateField(e){
    if ($.trim(this.value) == '' || !validateEmail(this)) $(this).next('span').show();
    else $(this).next('span').hide();
}
/* EVENT HANDLERS */
function onSubmitComplete(e, formId){
	if (e.success == 1) $(formId).html(e.message);
	else $(formId).html(PROCESS_ERROR+"<br/>"+e.message);
}
function initForm(){
    $('.required-field').each(function(e){
        $(this).blur(validateField)
	});
	$('#sendprinted').click(function(){
	    $('#snailMailInfo').slideToggle('normal');
	});
	if($('#sendprinted').is(':checked'))$('#snailMailInfo').toggle(true);
	$('#selectall').click(function(){
	    $('#subchecks :checkbox').attr('checked', $('#selectall').is(':checked'));
	});
	$('#subchecks :checkbox').click(function(){
	    $('#selectall').attr('checked', $('#subchecks :checked').length == $('#subchecks :checkbox').length);
	});
	if($('#selectall').is(':checked'))$('#subchecks :checkbox').attr('checked', true);
	$('#zip').numeric('-');

	$('#optionToggle').click(function() {
	    $('#interestOptions').slideToggle('normal');
	});
	
	//$(SUBMIT_BTN).html(SUBMIT_MSG);
    $(SUBMIT_BTN).click(function(e){ submitForm(FORM_ID,'join'); });
}
/** WINDOW LOAD **/
$(document).ready(function (){
    initForm();
});
/* numeric */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('r.E.W=7(c,d){c=c||".";d=q d=="7"?d:7(){};6.K(7(e){g a=e.i?e.i:e.h?e.h:0;2(a==k&&6.N.J()=="G"){5 3}f 2(a==k){5 j}g b=j;2((e.4&&a==y)||(e.4&&a==v))5 3;2((e.4&&a==t)||(e.4&&a==u))5 3;2((e.4&&a==V)||(e.4&&a==S))5 3;2((e.4&&a==R)||(e.4&&a==Q))5 3;2((e.4&&a==P)||(e.4&&a==O)||(e.L&&a==p))5 3;2(a<I||a>H){2(a==p&&6.l.F==0)5 3;2(a==c.n(0)&&6.l.o(c)!=-1){b=j}2(a!=8&&a!=9&&a!=k&&a!=D&&a!=C&&a!=M&&a!=B&&a!=A){b=j}f{2(q e.i!="z"){2(e.h==e.m&&e.m!=0){b=3}f 2(e.h!=0&&e.i==0&&e.m==0){b=3}}}2(a==c.n(0)&&6.l.o(c)==-1){b=3}}f{b=3}5 b}).x(7(){g a=r(6).w();2(a!=""){g b=T U("^\\\\d+$|\\\\d*"+c+"\\\\d+");2(!b.s(a)){d.X(6)}}});5 6}',60,60,'||if|true|ctrlKey|return|this|function||||||||else|var|keyCode|charCode|false|13|value|which|charCodeAt|indexOf|45|typeof|jQuery|exec|120|88|65|val|blur|97|undefined|46|39|36|35|fn|length|input|57|48|toLowerCase|keypress|shiftKey|37|nodeName|86|118|90|122|67|new|RegExp|99|numeric|apply'.split('|'),0,{}))
/* end numeric */