$(document).ready(function($){
	$("input#contact_phone_number").mask("(999) 999-9999",{placeholder:" "});
});

$(document).ready(function() {
  $("form#quote_request").submit(function(){
	var hasError = false;
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	var process_type = $("input#process_type").val();
	var contact_name = $("input#contact_name").val();
	if(contact_name == '') {
		$("#contact_name_error").html('Please enter your name.');
		hasError = true;
	} else {
		$("#contact_name_error").html('');
	}
	var contact_company = $("input#contact_company").val();
	if(contact_company == '') {
		$("#contact_company_error").html('Please enter your company name.');
		hasError = true;
	} else {
		$("#contact_company_error").html('');
	}
	var contact_addr = $("input#contact_addr").val();
	var contact_city = $("input#contact_city").val();
	var contact_state = $("input#contact_state").val();
	var contact_zip = $("input#contact_zip").val();
	var contact_phone_number = $("input#contact_phone_number").val();
	if(contact_phone_number == '') {
		$("#contact_phone_number_error").html('Please enter a valid phone number.');
		hasError = true;
	} else {
		$("#contact_phone_number_error").html('');
	}
	var contact_email_address = $("input#contact_email_address").val();
	if(contact_email_address == '') {
		$("#contact_email_address_error").html('Please enter a valid e-mail address.');
		hasError = true;
	} else if(!emailReg.test(contact_email_address)) {	
		$("#contact_email_address_error").html('Please enter a valid e-mail address.');
		hasError = true;
	} else {
		$("#contact_email_address_error").html('');
	}
	var contact_web = $("input#contact_web").val();
	var project_type = $("select#project_1").val();
	if(project_type == '') {
		$("#project_type_error").html('Please select at least 1 project type.');
		hasError = true;
	} else {
		$("#project_type_error").html('');
	}
	for(var j=0;j<project_type.length;j++) {
		if(j>0) {
			project_type_break = project_type_break + "," + project_type[j];
		} else {
			var project_type_break = project_type[j];
		}
	}
	var project_budget = $("select#project_budget").val();
	if(project_budget == 'none') {
		$("#project_budget_error").html('Please select a budget for these project(s).');
		hasError = true;
	} else {
		$("#project_budget_error").html('');
	}
	var project_description = $("textarea#project_description").val();
	if(project_description == '') {
		$("#project_description_error").html('Please enter a description for these project(s).');
		hasError = true;
	} else {
		$("#project_description_error").html('');
	}
	var contact_referral = $("input#contact_referral").val();
	if(contact_referral == '') {
		$("#contact_referral_error").html('Please tell us how you heard about xclntDesign.');
		hasError = true;
	} else {
		$("#contact_referral_error").html('');
	}
	if(hasError == false) {
		$("#form_message").html('Submitting form...');
		$.post("../../../includes/process.php",{ process_type: process_type, contact_name: contact_name, contact_company: contact_company, contact_addr: contact_addr, contact_city: contact_city, contact_state: contact_state, contact_zip: contact_zip, contact_phone_number: contact_phone_number, contact_email_address: contact_email_address, contact_web: contact_web, project_type: project_type_break, project_budget: project_budget, project_description: project_description, contact_referral: contact_referral }, function() { $("#quote_request").slideUp("normal", function() { $("#quote_request").before('<h2>Thank You! <span class="red">&raquo;</span></h2><p>We have received your request for a quote.</p><p>We will review your request, and find the best solutions for your project(s).  You should have a quote from xclntDesign within 48 hours.</p></div>' )} )} );
	}
    return false;
  });
});

function project_count_check() {
	var selectedArray = new Array();
	var selObj = document.getElementById('project_1');
	var i;
	var count = 0;
	for (i=0; i<selObj.options.length; i++) {
		if (selObj.options[i].selected) {
			selectedArray[count] = selObj.options[i].value;
			count++;
		}
  	}
	if(count > 5) {
		alert("Cannot select more than 5 project types.");
		return false;
	} else {
		return true;
	}

}
