
	
	Event.observe('add-to-description', 'submit', AddToDescription);
	
	function AddToDescription(e)
	{
		
		var add = new Ajax.Request(
		
			'http://www.abovephotography.com.au/misc/add-to-description.php', 
			{ 
				method: 'post', 
				
				onSuccess: function(transport)
				{

					if ( transport.responseText == '1' )
					{
						var form = $('add-to-description');
						var	description = $F(form['description']).gsub("\n", '<br>');
						
						try {
							
							new Insertion.Bottom(
								'added-description', 
								'<p>' + description + '</p>' 
							);
						}
					
						catch(e)
						{
							//alert(dumpObj(e));
						}
						
						$('notice').update('Thanks!  We will review your submission soon!').setStyle({background: 'transparent', color: '#000'});
					}
					else
					{
						$('notice').update('Please enter a description.').setStyle({background: 'transparent', color: '#f00'});
					}
					
				}, 
				
				onFailure: function(transport) { $('notice').update('Oops, something went wrong.').setStyle({color: '#f00'}); }, 
				
				parameters: $('add-to-description').serialize(true) 
			}
		);
		
		Event.stop(e);
	}
	
	
var MAX_DUMP_DEPTH = 10;

      

       function dumpObj(obj, name, indent, depth) {

              if (depth > MAX_DUMP_DEPTH) {

                     return indent + name + ": <Maximum Depth Reached>\n";

              }

              if (typeof obj == "object") {

                     var child = null;

                     var output = indent + name + "\n";

                     indent += "\t";

                     for (var item in obj)

                     {

                           try {

                                  child = obj[item];

                           } catch (e) {

                                  child = "<Unable to Evaluate>";

                           }

                           if (typeof child == "object") {

                                  output += dumpObj(child, item, indent, depth + 1);

                           } else {

                                  output += indent + item + ": " + child + "\n";

                           }

                     }

                     return output;

              } else {

                     return obj;

              }

       }
	