if (typeof DeskPRO == 'undefined') var DeskPRO = {};
if (typeof DeskPRO.Live == 'undefined') DeskPRO.Live = {};
if (typeof DeskPRO.Live.Forms == 'undefined') DeskPRO.Live.Forms = {};

DeskPRO.Live.Forms.SignupLanding = function() {
	$('#signup_from_landing').validate({
		debug: DP_DEBUG,
		errorPlacement: function(error, element) {
			if ($(element).attr('name') == 'sub_domain') {
				$('#sub_domain_err').show().html(error);
			}
		},
		showErrors: function(errorMap, errorList) {
			$('#sub_domain_err').show();
			this.defaultShowErrors();
		},
		success: function(label) {
			$('#sub_domain_err').hide();
			label.html("&nbsp;");
		},
		submitHandler: function(form) {
			form.submit();
		}
	});

	$('#signup_from_landing input[name=sub_domain]').rules("add", {
		required: true,
		remote: BASEURL + '/signup/ajax-validate-subdomain'
	});
};


DeskPRO.Live.Forms.Signup = function() {
	this.validator = $('#signup_form').validate({
		debug: DP_DEBUG,
		errorPlacement: function(error, element) {
			if ($(element).attr('name') == 'sub_domain') {
				$('#sub_domain_err').show().html(error);
			} else {
				error.appendTo( element.parent("td").next("td") );
			}
		},
		showErrors: function(errorMap, errorList) {
			if (typeof errorMap.sub_domain != 'undefined') {
				$('#sub_domain_err').show();
			}
			
			this.defaultShowErrors();
		},
		success: function(label) {
			if (label.attr('for') == 'sub_domain') {
				$('#sub_domain_err').hide();
				label.html("&nbsp;");
			} else {
				label.html("&nbsp;").addClass("checked");
			}
		},
		submitHandler: function(form) {
			form.submit();
		},
		messages: {
			email2: 'Please enter a valid email address',
			password: 'Please enter a valid password with at least 4 characters'
		},
		rules: {
			'sub_domain': {
				required: true,
				remote: BASEURL + '/signup/ajax-validate-subdomain'
			},
			'email2': {
				required: true,
				email: true
			},
			'password': {
				required: true,
				minlength: 4
			}
		}
	});
};

DeskPRO.Live.Forms.Signup.prototype.getValidator = function() {
	return this.validator;
};