	$(function(){ 

		var _parts = "";
		$(".submitquote_btn").click(function(){
			$("tbody#tbodycart tr td:even").each(function() {
					_parts = _parts + $(this).text() + "\n";
			});


			
		
			$("#submit_form").css("display","");
			$("#message").css("display","none");
			$("#text_id").val(_parts);
			
			var rand_no = Math.random();
		
			$("#dialog").modal({
						opacity: 70, 
						onOpen: function (dialog) {
						  dialog.overlay.fadeIn('slow', function () {
						    dialog.container.fadeIn('fast', function () {
						      dialog.data.slideDown('slow');
							  $("#code_img").attr("src", "captcha.php?a=image&"+rand_no);  
						    });
						  });
						},

						onClose: function (dialog) {
						  dialog.data.slideUp('slow', function () {
						    dialog.container.fadeOut('slow', function () {
						      dialog.overlay.fadeOut('slow', function () {
						        $.modal.close(); // must call this!
						      });
						    });

						  });
						}
				});	

			return false;
		});
		

		$("#submit_form").submit(function(){
			if($("#name_id").val() === ''){
				$("#error_message").html("ERROR: Please enter your name.");
				return false;
			}
			if($("#company_id").val() === ''){
				$("#error_message").html("ERROR: Please enter your company.");
				return false;
			}
			if($("#email_id").val() === ''){
				$("#error_message").html("ERROR: Please enter your phone or email address.");
				return false;
			}
			if($("#text_id").val() === ''){
				$("#error_message").html("ERROR: Please add quote request information.");
				return false;
			}
			if($("#captcha_v").val() === ''){
				$("#error_message").html("ERROR: Please enter the security access code.");
				return false;
			}
			
			
			$.post("./send_mail.php",
				{	
					code: $("#captcha_v").val(),
					name: $("#name_id").val(),
					company: $("#company_id").val(),
					email: $("#email_id").val(),
					quote: $("#text_id").val()
				},
				
			function (data){
			
				if(data === 'error_code'){
					alert("Wrong security access code");
				}else{
					$("#message").css("display","inline");
					$("#submit_form").css("display","none");
					erasecookie('deccart');
				}
			});
			
			return false;
			
		});
	
	});
