jQuery(document).ready(function(){
	initPromoForm();
});

/* ipad promo registration page form */
function initPromoForm() {
	$j = jQuery;	
	
	
	$j.validator.addMethod("phone", function(pnumber) {
		var stripped = pnumber.replace(/[\(\)\.\-\ ]/g, '');
		if (isNaN(parseInt(stripped)) || !(stripped.length == 10)) {
			return false;
		}else{
			return true;
		}
	}, "Please specify a valid phone number");	
	
	$j.validator.addMethod("firstName", function(theVal) {
		if ( theVal == "" ) {
			return false;
		}else{
			return true;
		}
	}, "First Name is required");	
	
	$j.validator.addMethod("lastName", function(theVal) {
		if ( theVal == "" ) {
			return false;
		}else{
			return true;
		}
	}, "Last Name is required");		
	
	$j.validator.addMethod("companyName", function(theVal) {
		if ( theVal == "" ) {
			return false;
		}else{
			return true;
		}
	}, "Company Name is required");	
	
	$j.validator.addMethod("address", function(theVal) {
		if ( theVal == "" ) {
			return false;
		}else{
			return true;
		}
	}, "Address is required");	
	
	$j.validator.addMethod("city", function(theVal) {
		if ( theVal == "" ) {
			return false;
		}else{
			return true;
		}
	}, "City is required");	
	
	$j.validator.addMethod("zipcode", function(theVal) {
		if ( theVal == "" ) {
			return false;
		}else{
			return true;
		}
	}, "Zipcode is required");	
	
	$j.validator.addMethod("state", function(theVal) {
		if ( theVal == "" ) {
			return false;
		}else{
			return true;
		}
	}, "State is required");	

	
    $j("#promo_form").validate({
        rules: {
	    	FirstName: { // compound rule
    			firstName: true
    		},
	    	LastName: { // compound rule
    			lastName: true
    		},
	    	CompanyName: { // compound rule
    			companyName: true
    		},
	    	Address: { // compound rule
    			address: true
    		},
	    	City: { // compound rule
    			required: true,
    			city: true
    		},
	    	Zipcode: { // compound rule
    			zipcode: true
    		},
	    	Phone: {// compound rule
    			phone: true
    		},
	    	EmailAddress: {// compound rule
	          required: true,
	          email: true
	        },
	    	State: {// compound rule
		          state: true
		    }
    	}
    });
}
