var Common = Common || {};
Common = {
	HtmlEncode: function(t) {
        // Source: http://stackoverflow.com/questions/1219860/javascript-jquery-html-encoding
        return $('<div/>').text(t).html();
    },
	getScrollTop: function() {
		if (document.documentElement.scrollTop) {
			return document.documentElement.scrollTop;
		}
		return document.body.scrollTop;
    },
	scrollHandler: function() {
		$('#rc_notify').css("top", Common.getScrollTop());     
    },
	showNotify: function(str) {
		$("#rc_notify").css("display", "block");
		$("#rc_notify").css("visibility", "visible");

		if ($("#rc_notify").css("position") == 'absolute') {
			$("#rc_notify").css("top", Common.getScrollTop());
			window.onscroll = Common.scrollHandler;
		}

		$("#rc_notify").html(str);     
    },
	hideNotify: function() {
		$("#rc_notify").css("display", "none");
		$("#rc_notify").css("visibility", "hidden");
		window.onscroll = null;    
    }
};

// Extension Methods
String.format = function(text) {
    // Source: http://frogsbrain.wordpress.com/2007/04/28/javascript-stringformat-method/
    if (arguments.length <= 1) {
        return text;
    }
    //decrement to move to the second argument in the array
    var tokenCount = arguments.length - 2;
    for (var token = 0; token <= tokenCount; token++) {
        //iterate through the tokens and replace their placeholders from the original text in order
        text = text.replace(new RegExp("\\{" + token + "\\}", "gi"), arguments[token + 1]);
    }
    return text;
};

String.prototype.replaceAll = function(s1, s2) {
    return this.split(s1).join(s2)
}
