function updateJobType(){

	var label = $("#scope_label_type");
	var jobType = $('#job_type');
	var jobScope = $('#job_scope');
	var jobTimeframe = $('#job_timeframe');
	var jobBudget = $('#job_budget');
	
	jobTypeValue = jobType.children(":selected").text();
	jobScope = jobScope.children(":selected").text();
	jobTimeframe = jobTimeframe.children(":selected").text();
	jobBudget = jobBudget.children(":selected").text();

	switch (jobTypeValue){
		
		case 1:
			label.text("Page(s)");
		break;
	
		case 2:
			label.text("Page(s)");
		break;
		
		case 3:	
			label.text("View(s)");	
		break;
	}
}

function checkName(strng){

	var error = "";
	
	if(strng == "" || strng == "first and last please"){
		error = "You didn't enter a name.";
	}
	
	return error;

}

function checkprojName(strng){
	
	var error = "";
	
	if(strng == "" || strng == "(or company name)"){
		error = "You didn't enter a project name.";
	}
	
	return error;
}

function checkEmail (strng) {

	var error="";
	
	if (strng == "" || strng == "yourname@example.com") {
	   error = "You didn't enter an email address.";
	}

    var emailFilter=/^.+@.+\..{2,3}$/;
    
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.";
	}
    else {
	
	//test email for illegal characters
	
		var illegalChars=/[\(\)\<\>\,\;\:\\\"\[\]]/;
		
		if (strng.match(illegalChars)) {
			 error = "The email address contains illegal characters.";
		}
	}
	
	return error;    
}


function checkJobType(choice) {

	var error = "";
	
	if (choice == "0") {
		error = "You didn't choose a job type.";
	}
	
	return error;
}

function checkJobBudget(choice) {
    
    var error = "";
    
    if (choice == "0") {
		error = "You didn't choose a budget.";
	}
	
	return error;
} 

function checkJobScope(choice) {
	
    var error = "";
    
    if (choice == "0") {
		error = "You didn't choose a quantity.";
	}
	
	return error;
	
}    

function checkJobTimeframe(choice) {

    var error = "";
    
    if (choice == "0") {
		error = "You didn't choose a timeframe.";
	}
	
	return error;
}

function checkMessage(){

	var error = "";
	
	if($("#message").val() == "" || $("#message").val() == "tell me all about your project here" || $("#message").val() == "what's on your mind?"){
		error = "You didn't enter a message.";
	}
	
	return error;
}

function checkWholeForm(theForm) {
    var why = "";
    
    var name = checkName($(theForm).find("#name").val());
    if(name != ""){$("#name_label").addClass("error"); why += name;}
	
	var email = checkEmail($(theForm).find("#email").val());
    if(email != ""){$("#email_label").addClass("error"); why += email;}
    
    if($("#formtype").val() == "request"){
    
		var jobName = checkprojName($("#project_name").val());
		if(jobName != ""){$("#project_name_label").addClass("error"); why += jobName;}

		var jobType = checkJobType($("#job_type option:selected").val());
		if(jobType != ""){$("#type_label").addClass("error"); why += jobType;}
		
		var jobBudget = checkJobBudget($("#job_budget option:selected").val());
		if(jobBudget != ""){$("#budget_label").addClass("error"); why += jobBudget;}
		
		var jobScope = checkJobScope($("#job_scope option:selected").val());
		if(jobScope != ""){$("#scope_label").addClass("error"); why += jobScope;}
		
		var jobTimeframe = checkJobTimeframe($("#job_timeframe option:selected").val());
		if(jobTimeframe != ""){$("#timeframe_label").addClass("error"); why += jobTimeframe;}
	}
	
	var message = checkMessage();
	
	if(message != ""){$("#message_label").addClass("error"); why += message;}
	
    if(why != ""){
		
		$("#estimate_form #errors").html("").append("<h4>Please correct the following errors:</h4>");
		
		$("#estimate_form #errors").append("<ul></ul>");
		
		var errors = why.split(".");
		
		$.each(errors, function(){
			if(this !=""){$("#errors ul").append("<li>"+this+"</li>");}
		});
		
		$("#estimate_form #errors").show();
		
		return false;
    }
	
	return true;
}