//w/ all cboxes - home page
function master_search() {
	var $obj = $('input[type="checkbox"][value="1"]');
	var len = $obj.length;
	if (len>=1) {
		if (confirm("Proceed?")) {
			$('#process').hide();
			$('#message').html("Loading...");
			$('#message').show();

			var arr_ids = [];
			for(var lv=0; lv<len; lv++) {
				arr_tmp = $obj[lv].id.split('_');
				arr_ids.push(arr_tmp[3]);
			}

			$('#occ_ids').val(arr_ids.join('|'));
			$('#frm_srch').submit();
		}
	}
	else {
		alert("Please select one or more services.");
	}
}


//after step1
function process_estimate_request() {
	$('#process').hide();
	$('#message').show();
	$('#message').html('Validating...');

	var err = "";

	//run checks
	if (jQuery.trim($('#fe_fname').attr("value")) == "") {
		err += "\n\t- First Name";
	}

	if (jQuery.trim($('#fe_lname').attr("value")) == "") {
		err += "\n\t- Last Name";
	}

	if (!valid_email($('#fe_email').attr("value"))) {
		err += "\n\t- Email";
	}

	if (jQuery.trim($('#fe_email').attr("value")) != jQuery.trim($('#fe_c_email').attr("value"))) {
		err += "\n\t- Email fields should match";
	}

	if (jQuery.trim($('#fe_addr_line_1').attr("value")) == "") {
		err += "\n\t- Address line 1";
	}

	if (jQuery.trim($('#fe_addr_city').attr("value")) == "") {
		err += "\n\t- City";
	}

	if (jQuery.trim($('#fe_addr_state').attr("value")) == "") {
		err += "\n\t- State";
	}

	if (!/^[0-9]{5}$/.test($('#fe_addr_zip').attr("value"))) {
		err += "\n\t- Zip code";
	}

	if (!/^[0-9]{3}\-[0-9]{3}\-[0-9]{4}$/.test($('#fe_phone_p').attr("value"))) {
		err += "\n\t- Primary Phone in 123-456-7890 format";
	}

	if (!/^[0-9]{3}\-[0-9]{3}\-[0-9]{4}$/.test($('#fe_phone_a').attr("value"))) {
		err += "\n\t- Alternate Phone in 123-456-7890 format";
	}

	if (jQuery.trim($('#fe_btc').attr("value")) == "") {
		err += "\n\t- Best Time to Call";
	}

	if (jQuery.trim($('#fe_hau').attr("value")) == "") {
		err += "\n\t- Hear About Us";
	}

	if (jQuery.trim($('#fe_task').attr("value")) == "") {
		err += "\n\t- Task Description";
	}

	//alert($('#fe').attr("action"));

	if (err != "") {
		$('#message').hide();
		$('#message').html('');
		$('#process').show();

		err = "Please make sure the following fields are complete and valid:\n" + err;
		alert(err);
	}
	else {
		$.ajax(
			{
				type: "POST",
				url: $('#fe').attr("action"),
			 	cache: false,
				data: $('#fe').serialize(),
				complete: function(resp) {
					if (resp.responseText == 1) {
						//reset form
						$('#fe').each(function(){
				        	this.reset();
						});

						var txt = "Your Free Estimate request has been successfully submitted. Our contractors shall be in touch with you ASAP! Please check your email account for a confirmation message containing the tracking number of your request.";
						$('#message').html(txt);
						alert(txt);
					}
					else {
						$('#message').hide();
						$('#message').html('');
						$('#process').show();

						alert(resp.responseText);
					}
				}
			}
		);
	}
}


function v3_load_first_cat(cat_id) {
	$('#div_cat_'+cat_id).show();
}


function v3_show_services(cat_id) {
	if ($('#div_cat_'+cat_id).is(":hidden")) {
		$('#div_cat_'+cat_id).show();
	}
	else {
		$('#div_cat_'+cat_id).hide();
	}
}