function SendToFriend( divId , url , propertyId )
{
	this.divId 		= divId;
	this.url 		= url;
	this.propertyId = propertyId ? propertyId : null ;
	
	
	$(this.divId).jqm();
	
	this.reset();
	
	var self = this;
	
	$(this.divId+" input:button").bind( "click" , function()
	{
		var data = {};
		
		// $( self.divId 
		
		$( self.divId +" div.error-message").hide();
		
		$( self.divId +" input, "+ self.divId +" textarea").each( function()
		{ 
			data[ $(this).attr("name") ] = $(this).val();
		} );
		

		
		
		if( this.propertyId )
		{
			$( self.divId + " input.property-id").val( this.propertyId );
		}
		
		$.post( url +"?"+ Math.round( Math.random()*100000 ) , data , function ( xml )
		{
			
			if( $( "errors" , xml ).length == 0 )
			{
			
				$( self.divId +" form").hide();
				$( self.divId +" h2").show();
			}
			else 
			{
				$( self.divId +" div.error-message").hide();
				
				var errors = $( "error" , xml ); 
				
				if( errors.length > 0 )
				{
					errors.each( function()
					{ 
						$( self.divId +" div.error-" + $(this).attr("name") ).show();
						
						
						
						// $( "#sendEmail div.error-" . $(this).tagName )  
					} );
				}
				else
				{
					$(self.divId +" div.error-overal" ).show();
				}
			}
		} , "xml" ); 
		
		return false;
		
	} );	
	
}


SendToFriend.prototype.response =	function ( xml )
{
	alert(123);
	if( $( "error" , xml ).length == 0 )
	{
		$( this.divId +" form").hide();
		$( this.divId +" h2").show();
	}
	else 
	{
		$( this.divId +" div.error-message").hide();
		
		$( "error" , xml ).each( function()
		{ 
			$(this.divId +" div.error-" + $(this).attr("name") ).show();
			// $( "#sendEmail div.error-" . $(this).tagName )  
		} );
	}
}
	
SendToFriend.prototype.reset = function ( xml )
{
	$( this.divId + " div.error-message").hide();	
	$( this.divId + " h2").hide();
	$( this.divId + " form").show();
	$( this.divId + " textarea").html( $( this.divId + " input.message_default" ).val() );
	$( this.divId + " input:text:visible").val("");
	
}

SendToFriend.prototype.bind = function ( selector , propertyId  )
{
	var self = this;
	
	$( selector ).click( function()
	{ 
	
		self.reset();
		if( propertyId )
		{
			$(self.divId +" input.property-id" ).val( propertyId );
		}
		$( self.divId ).jqmShow(); 
		return false; 
	} );
}
