function isValidEmail(email) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if (reg.test(email) == false) {
		return false;
	}
	return true;
}

function _getErrorDiv(idx) {
	var errorDiv = jQuery('#dvStep' + idx + 'Error');
	errorDiv.html('');
	errorDiv.css('display', 'none');
	return errorDiv;
}
function validateStep1(o) {
	var errorDiv = _getErrorDiv(1);
	if (jQuery('#lead_genre_id').val() == '') errorDiv.html(errorDiv.html() + '<div>Please select a genre</div>');
	if (jQuery('#lead_ready').val() == '') errorDiv.html(errorDiv.html() + '<div>Please select on where are you ready to publish</div>');
	if (jQuery('#lead_reason').val() == '') errorDiv.html(errorDiv.html() + '<div>Please select what is your reason to publish</div>');

	if (errorDiv.html() != '') {
		errorDiv.css('display', 'block');
	} else {
		showHide(2,1);
	}
}

function validateStep2(o) {
	var errorDiv = _getErrorDiv(2);
	if (jQuery('#lead_budget').val() == '') errorDiv.html(errorDiv.html() + '<div>Please select your budget</div>');
	if (jQuery('#lead_need').val() == '') errorDiv.html(errorDiv.html() + '<div>Please select the help you needed to publish</div>');

	if (errorDiv.html() != '') {
		errorDiv.css('display', 'block');
	} else {
		showHide(3,2);
	}
}

function validateStep3(o) {
	var errorDiv = _getErrorDiv(3);
	if (jQuery('#lead_salutation').val() == '') errorDiv.html(errorDiv.html() + '<div>Salutation is required</div>');
	if (jQuery('#lead_firstname').val() == '') errorDiv.html(errorDiv.html() + '<div>First name is required</div>');
	if (jQuery('#lead_lastname').val() == '') errorDiv.html(errorDiv.html() + '<div>Last name is required</div>');
	if (jQuery('#lead_email').val() == '') {
		errorDiv.html(errorDiv.html() + '<div>Email address is required</div>');
	} else {
		if (!isValidEmail(jQuery('#lead_email').val())) {
			errorDiv.html(errorDiv.html() + '<div>Email address is invalid</div>');
		} else {
			if (jQuery('#lead_email').val() != jQuery('#lead_email_confirmation').val()) {
				errorDiv.html(errorDiv.html() + '<div>Email address does not match</div>');
			}
		}
	}
	if (jQuery('#lead_phone').val() == '') errorDiv.html(errorDiv.html() + '<div>Phone number is required</div>');
	if (jQuery('#lead_occupation_id').val() == '') errorDiv.html(errorDiv.html() + '<div>Please select your occupation</div>');
	if (jQuery('#lead_country_id').val() == '') errorDiv.html(errorDiv.html() + '<div>Please select your country</div>');
	var state = $('#lead_state');
	if (!state.attr('disabled')) {
		if (state.val() == '') errorDiv.html(errorDiv.html() + '<div>State is required</div>');
	}
	if (jQuery('#lead_city').val() == '') errorDiv.html(errorDiv.html() + '<div>City is required</div>');
	if (jQuery('#lead_birthdate_2i').val() == '' || jQuery('#lead_birthdate_3i').val() == '' || jQuery('#lead_birthdate_1i').val() == '') errorDiv.html(errorDiv.html() + '<div>Birth date is required</div>');
	if (errorDiv.html() != '') {
		errorDiv.css('display', 'block');
	} else {
		jQuery('#new_lead').submit();
	}
}

function showHide(newIdx, oldIdx) {
	jQuery('#dvStep' + oldIdx).css('display', 'none');
	jQuery('#dvHeader' + oldIdx).css('display', 'none');
	jQuery('#dvHeader' + newIdx).css('display', 'block');
	jQuery('#dvStep' + newIdx).css('display', 'block');
}