﻿$(function() {
		
		
		$("#dialog").dialog({
			bgiframe: true,
			autoOpen: false,
			width: 550,
			height: 420,
			modal: true,

			buttons: {
				'Send Request': function() {
						
						//alert('Form would be subitted now... but not implemented yet.');
						//do an ajax post
						//alert("Form.serialize: "+$("#recycleForm").serialize());
						var dataString = $("#recycleForm").serialize();
							//alert (dataString);return false;  
							$.ajax({  
									  type: "POST",  
									  url: "/includes/send.asp",  
									  data: dataString,  
									  success: function(data, textStatus) {
									  		if(data=="Request Sent")
									  			{
									    			//alert("Success!\ndata="+data+"\ntextStatus="+textStatus);
									    			alert("Thank you. Your request has been sent");
											    	$("#dialog").dialog('close');
											    }
											else
												{
													alert("Sorry, we could not send your request. Please try again.\n\nError: "+data);
												}
									    },
										error: function (XMLHttpRequest, textStatus, errorThrown) {
										  // typically only one of textStatus or errorThrown 
										  // will have info
										  //this; // the options for this ajax request
										  alert("ERROR\n\ntextStatus: "+textStatus+"\nerrorThrown: "+errorThrown);
										  //alert("XMLHttpRequest TEXT: "+XMLHttpRequest.text);
										}
									});
							//return false;  
						
						
				},
				Cancel: function() {
					//alert('Cancel function');
					$(this).dialog('close');
				}
			},
			close: function() {
				//alert('Close function');
				//allFields.val('').removeClass('ui-state-error');
			}
		});
		
		
		
		$('#load_recycle_form').click(function() {
			//alert('You clicked me!');
			$('#dialog').dialog('open');
		})
		

	});