jQuery(document).ready(function($) {
   $("#message").keyup(function(){
   		$("#error").fadeOut("slow");
   });
});

function writeScrap(){
	
		$("#error").hide();
		$("#message").val('');
		$("#scrap").show();
}
    
function submitScrap(){
	
		var msg = $("#message").val();
		if(trim(msg) == ''){
			$("#error").fadeIn("slow");
			return false;
		}
		$("#scrap").hide();
		$("#loading").show();
		
		var newstr = msg.replace(/&/g,"@amp@");
		newstr = newstr.replace(/%/g,"@perc@");
		newstr = newstr.replace(/=/g,"@eq@");
		newstr = newstr.replace(/\+/g,"@pl@");
		newstr = newstr.replace(/#/g,"@hash@");
    	newstr = newstr.replace(/\n/g,"<br />");
    	  
		$.ajax({
   			type: "GET",
   			url : "/scrapsubmit",
		    data: "desc="+newstr,
	   		success: function(msg){
     			if(msg=="yes"){
     				$("#loading").hide();
     				$("#okmessage").show();
     				$("#okmessage").html("");
     				$("#okmessage").append('Success! Your Scrap was successfully sent.');
     				$("#okmessage").hide(4000);
     			}else if(msg="blocked"){
     				$("#loading").hide();
     				$("#okmessage").show();
     				$("#okmessage").html("");
     				$("#okmessage").append('You are blocked by this member. You cant send a scrap.');
     				$("#okmessage").hide(4000);     			
   				}else if(msg=="no"){
     				$("#loading").hide();
     				$("#okmessage").show();
     				$("#okmessage").html("");
     				$("#okmessage").append('Failure! Your Scrap has not been successfully sent.');
     				$("#okmessage").hide(4000);   				
   				}
   			}
 		});
}
   
function cancelScrap(){
   		$("#scrap").hide();
		$("#error").hide();
}
  
function trim(s){
  		return s.replace(/^\s+|\s+$/, '');
}
