// JavaScript Document ALC - 2009İFITWD
$(document).ready(function() {
	
	jQuery.preloadImages = function()
	{
	  for(var i = 0; i<arguments.length; i++)
	  {
		jQuery("<img>").attr("src", arguments[i]);
	  }
	}

	
	
	$.preloadImages("../images/files/files_over_01.png", "../images/files/files_over_02.png", "../images/files/files_over_03.png");

	$("#content").corners("4px");
	
	$("a[id='mcsc']").colorbox({width:"80%", height:"80%", iframe:true});
	$("a[id='credit_counseling']").colorbox({width:"80%", height:"80%", iframe:true});
 	$("a[id='dialog']").colorbox({width:"80%", height:"80%", iframe:true});
	
	// CONTACT - SUBMIT CONTACT INFO
	$("input#contact_us").colorbox({width:320, height:260, inline:true, href:"#submit_form_box", title:"Submit Form"});
	
	$("input#contact_us").click(function(e) { 
		e.preventDefault();
		
		$("#c_fname").css("border", "2px solid #C7A91F");
		$("#c_lname").css("border", "2px solid #C7A91F");
		$("#c_phone").css("border", "2px solid #C7A91F");
		$("#c_email").css("border", "2px solid #C7A91F");
		
		$.post('../include/ajax_email.php', {
			task: 'submit_contact',   
			fname: $("#c_fname").val(),
			lname: $("#c_lname").val(),
			phone: $("#c_phone").val(),
			email: $("#c_email").val(),
			interested: $("#c_interested").val(),
			comments: $("#c_comments").val(),
		}, function(data) {
			
			if (data != "sent") {
				
				var all_error_messages = '<h3><img src="images/exclamation.png" align="left" style="margin: 3px 5px 5px;">There Was a Problem Submitting Your Form</h3><p>Please check the following and submit again:</p><ul>';
				
				var values = data.split("|-|");
				
				var error_messages = values[0].split("++");
				var error_fields = values[1].split("++");
				
				for (x in error_messages) {
					all_error_messages += "<li>" + error_messages[x] + "</li>";
				}
				
				all_error_messages += "</ul>";
			    
				$("error_messages").html(all_error_messages);
				
				for (x in error_fields) {
					$("input[id='" + error_fields[x] + "']").css("border", "2px solid red");
				}
			
			} else {
			
				$("error_messages").html("<h3>Thank You " + $("#c_fname").val() + ". <br>Your Form Has Been Sent.</h3> <p style='padding:4px 0px 0px 0px;'>We will respond to your query promptly. If you are using email filtering remember to add affordablelawcenter.com to your list of acceptable recipients.</p>");
				
				$("#c_fname").val("");
				$("#c_lname").val("");
				$("#c_phone").val("");
				$("#c_email").val("");
				$("#c_comments").val("");
			}
			
		});
	});	
	
});
