/**
 * @author Jeremy Manoto
 * @copyright 2009
 * @version 1.0
 */

 
 	$(document).ready(function() {
		
		ContactUs_Init();

	});

	
	function ContactUs_Init() {
		var form = $("#frmContactUs");
		
		form.validate({
			errorLabelContainer: "#frmContactUsErrors",
			wrapper: "li",
			errorClass: "invalid",
			rules: {
				txtName: {
					required: true
				},
				txtEmail: {
					required: true
				}
			},
			messages: {
				txtName: {
					required: "Please enter your name"
				},
				txtEmail: {
					required: "Please enter a valid email address"
				}
			}
		});
		
		//Handle Form submission event
		form.find(".send").click(function() {
			
			if (form.valid()) {
				var name = form.find("#txtName").val();
				var email = form.find("#txtEmail").val();
				var phone = form.find("#txtPhone").val();
				var comment = form.find("#txtComment").val();
				
				var interests = "";
				
				form.find("input:checked").each(function(){
					var input = $(this);
					interests += input.val() + "; ";
				});
				
				//alert(name + email + phone + comment + interests);
				
				var postUrl = "services/WSContactUs.php";
				var postParams = {
					name: name,
					email: email,
					phone: phone,
					comment: comment,
					interests: interests
				}
				//Make the post
				$.post(postUrl, postParams, function(data){
					if (data == "OK") {
						$("#frmContactUsSuccess").dialog({
							bgiframe: true,
							modal: true,
							buttons: {
								Ok: function() {
									$(this).dialog('close');
								}
							}
						});

					}
				});
			} else {
				//alert("Errors exist");
			}
		});
	}
