// ==UserScript==
// @name          SoftPedia Avertisment
// @author        Ciuly  
// @namespace     http://www.ciuly.com
// @description   Sends a warning message to a user and posts the message in the dedicated area 
// @include       http://forum.softpedia.com/index.php?showtopic=*
// @require       http://www.ciuly.com/greasemonkey/aa_all_common.user.js
// @require       http://www.ciuly.com/greasemonkey/aa_sp_common.user.js
// @require       http://www.ciuly.com/greasemonkey/aa_sp_mod_common.user.js
// ==/UserScript==


(function(wnd){

  wnd.ciuly_Avertisment = function(username){
    var reason = prompt("Reason ("+username+")", "");
    if (reason =="" || !reason) {
      alert("No reason given. No action taken.");
      return false;
    }

    // change all crlf (no matter the case) into \n
    reason = reason.replace(/crlf/gi,"\n");

    wnd.ciuly_progress_show();
    wnd.ciuly_progress_log("sending PM...");
    // send PM
    if (!wnd.ciuly_send_pm(username, "Avertisment", "Avertisment: "+reason)){
	alert("Did not send PM. Aborting.");
        wnd.ciuly_progress_hide();
	return false;
    }

    wnd.ciuly_progress_log("done. posting to dedicated area..");
    // post in dedicated area
    if (!wnd.ciuly_sp_post_bless(username, "265", reason)){
	alert("Did not post to dedicated thread. Aborting");
	wnd.ciuly_progress_hide();
	return false;
    };

    wnd.ciuly_progress_log("done");
    wnd.ciuly_progress_hide();
  }

  function addButton(postid, uname, uid){
    return "&nbsp;<button class=\"button\" name=\"avertisment\" title=\"Avertizeaza\" onclick=\"return ciuly_Avertisment('"+uname+"')\">Avertisment</button>&nbsp;";
  } 

  if (wnd.ipb_md5_check){
    wnd.ciuly_on_every_post(addButton);
  }

})(window.wrappedJSObject || window);