// JavaScript Document
		jQuery.blockUI.defaults = {
		//var sendToAFriendBlockUIOptions = {
			// the message displayed when blocking the entire page 
			pageMessage:    '<h1>Please wait...<\/h1>', 
			// the message displayed when blocking an element 
			elementMessage: '', // none 
			// styles for the overlay iframe 
			overlayCSS:  { backgroundColor: '#242424', opacity: '.89' }, 
			// styles for the message when blocking the entire page 
			pageMessageCSS:    { width:'60%', margin:'0 auto 0 auto', top:'25%', left:'20%', textAlign:'left', color:'#fff', backgroundColor:'#777', border:'2px solid #bbb' }, 
			// styles for the message when blocking an element 
			elementMessageCSS: { width:'60%', padding:'10px', textAlign:'center', backgroundColor:'#fff'}, 
			// styles for the displayBox 
			displayBoxCSS: { width: '60%', top:'25%', padding: '15px 0 15px 0'}, 
			// allow body element to be stetched in ie6 
			ie6Stretch: 0, 
			// supress tab nav from leaving blocking content? 
			allowTabToLeave: 0, 
			// Title attribute for overlay when using displayBox 
			closeMessage: 'Click to close', 
			// use fadeIn effect 
			fadeIn:  1, 
			// fadeIn transition time in millis 
			fadeInTime: 450, 
			// use fadeOut effect when unblocking (can be overridden on unblock call) 
			fadeOut:  1, 
			// fadeOut transition time in millis 
			fadeOutTime: 450,
			width: '60%',
			padding: '0'
			
		};       
		
		var sendtoafriend;		
		var handler;		
		jQuery().ready(function(){
			sendtoafriend = jQuery("#sendtoafriend")[0];  
			
			handler = new FormHandler(jQuery("div#sendtoafriend"));
			
			jQuery("a.emailafriend").bind("click", function(){
				//jQuery.blockUI(sendtoafriend, { width: '60%', padding: '0', cursor: 'default' });
				//jQuery.blockUI({ css: { backgroundColor: '#f00', color: '#fff' } }); 
				jQuery("body").block({message:sendtoafriend, css:{ width: '60%', padding: '0', cursor: 'default', backgroundColor:'#242424'},centerY: true,centerX:true,baseZ: 5000} );
				return false;
			});
		});
		
		function FormHandler(c){			
				this.container = c;
				this.form = jQuery("form", this.container);	
				var $this = this;
				
				this.request = {};
				
				this.sender = this.form[0].sender;
				this.receipient = this.form[0].receipient;
				this.message = this.form[0].message;
				this.uri = this.form[0].page;

				this.success = jQuery("div#success");
				this.errors = jQuery("div#errors");
				
				this.send = jQuery("input[type=button][value=Send]", this.form);
				this.send.bind("click", function(){
					$this.processForm();
				});
				this.cancel = jQuery("input[type=button][value=Cancel]", this.form);
				this.cancel.bind("click", function(){
					$this.cancelSend();
				});
				
				this.close = jQuery("div#cancelTab a", this.container);
				this.close.bind("click", function(){
					$this.cancelSend();
				});
				
				
				
			}
			
		FormHandler.prototype.cancelSend = function()
		{
			jQuery("body").unblock();
			//jQuery.unblockUI();
			this.sender.value = "";
			this.receipient.value = "";
			this.message.value = "";
			this.success.hide();
			this.errors.hide();			
			
		}	
		FormHandler.prototype.handle = function(data, x, y){
			if(data.success)
			{
				this.receipient.value = "";
				this.success.html("Your message has been successfully sent.");
				this.success.fadeIn("slow");
				this.errors.hide();
			}
			else if(typeof(data.errors) != 'undefined' && data.errors.length > 0)
			{
				var m = "<ul>";
				for(i=0; i<data.errors.length; i++)
				{
					m += "<li>" + data.errors[i] + "</li>";
				}				
				m += "</ul>";
				this.errors.html(m);
				this.success.hide();
				this.errors.fadeIn("slow");
			}
			else
			{
				alert("Unable to precess request : an error has occured");
			}
		}
		
		FormHandler.prototype.processForm = function()
			{				
				var $this = this;
				
				var params = {
					"URI":this.uri.value,
					"sender":this.sender.value, 
					"receipient":this.receipient.value, 
					"message":this.message.value
					};
				this.request = jQuery.ajax({
				   type: "POST",
				   url: "/elements/classes/email/Email.cfc?method=sendToAFriend",
				   dataType: "json",
				   data: params,
				   //success: this.onStartSuccess,
				   //error: this.onStartError
				   success:function(data){
				   		$this.handle(data);
				   },
				   error:function(data){
				   		$this.handle(data);
				   }
				});	
				return false;
			}		
			
		