/**
 * Replaces the format item in a specified String with the text equivalent  
 *
 * @example alert($.format("hello, {0} name is {1}", "my", "unicorn"));
 *
 */
$.format = function(){
	var num = arguments.length;   
	var oStr = arguments[0];   
	for (var i = 1; i < num; i++) {   
		var pattern = "\\{" + (i-1) + "\\}";   
		var re = new RegExp(pattern, "g");   
		oStr = oStr.replace(re, arguments[i]);   
	}   
	return oStr;   
};
	
/**
 * Replaces all occurrences string, all match findStr will replace as replaceStr
 *
 * @example alert($.replaceAll('hello hell word.','hell','****'));
 */
$.replaceAll = function(str, findStr, replaceStr){
	return str.replace(new RegExp(findStr,"gm"),replaceStr);
};
/**
 * check a string is numeric (include 0)
 *
 * @example $.isNumeric('01');
 */	
$.isNumeric = function(str) {
	var nums = "0123456789";
	if (str.length==0)return(false);
	for (var n=0; n < str.length; n++){
		if(nums.indexOf(str.charAt(n))==-1)return(false);
	}
	return(true);
}	
/**
 * check browser support flash , and get flash version
 *
 * @example alert($.browser.flash.version); // result: 9
 *
 */	
if (jQuery.browser.flash == null) {
	var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
	if (plugin) {
		var words = navigator.plugins["Shockwave Flash"].description.split(' ');
		for (var i = 0; i < words.length; ++i) {
			if (isNaN(parseInt(words[i])))
				continue;
			var ver = words[i]; 
		}
	} else if (jQuery.browser.msie) {
		try {
			var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			var ver = flash.GetVariable("$version").split(' ')[1].split(',')[0];		
		} catch(e) {}
	}
	ver = parseFloat(ver);
	jQuery.browser.flash = {
		version: ver | 0,
		enabled: ver>=6
	};
}
/**
* check the page in the iframe?
*
* @example alert($.isInIframe());
*/	
$.isInIframe = function() {
    var res = false;
    $('iframe', window.parent.document).contents().each(function() {
        if (window.location.href == this.location.href) {
            res = true;
            return;
        }
    });
    return res;
};

$.isNullOrEmpty = function(s) {
	return s == null || s == undefined || s == '';
}