Function.prototype.partial = function(){
    var fn = this, args = Array.prototype.slice.call(arguments);
    return function(){
	   var k = 0;
	   for(var i = 0, l =  args.length; i < l && k < arguments.length; i++){
	       if(args[i] == undefined){
		        args[i] = arguments[k++];
		   }
	   }
	   return fn.apply(this, args);
	}
 }
 Function.prototype.curry = function(){
    var fn = this, args = Array.prototype.slice.call(arguments);
    return function(){
	   return fn.apply(this, args.concat(Array.prototype.slice.call(arguments)))
	 }
 }
 Function.prototype.delay = function(ms){
	 _this = this;
	 return function(){
		 var args = arguments;
		 window.setTimeout(function(){
			_this.apply(null, args);
		 }, ms||0);		 
	 }
 }
 Function.prototype.bind = function() 
 {
    var method = this, args = Array.prototype.slice.call(arguments), obj = args.shift();
    return function(){
    		return method.apply(obj, args.concat(arguments));
    }
 }  
 String.prototype.trim = function(){
	 return this.replace(/^\s+|\s+$/g, "");
 }
 String.prototype.escapeCharacters = function(chars)
 {
     var foundChar = false;
     for (var i = 0; i < chars.length; ++i) {
         if (this.indexOf(chars.charAt(i)) !== -1) {
             foundChar = true;
             break;
         }
     }

     if (!foundChar)
         return this;

     var result = "";
     for (var i = 0; i < this.length; ++i) {
         if (chars.indexOf(this.charAt(i)) !== -1)
             result += "\\";
         result += this.charAt(i);
     }

     return result;
 }

 String.prototype.escapeForRegExp = function()
 {
     return this.escapeCharacters("^[]{}()\\.$*+?|");
 }

 String.prototype.escapeHTML = function()
 {
     return this.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
 }

 String.prototype.collapseWhitespace = function()
 {
     return this.replace(/[\s\xA0]+/g, " ");
 }

 String.prototype.trimLeadingWhitespace = function()
 {
     return this.replace(/^[\s\xA0]+/g, "");
 }

 String.prototype.trimTrailingWhitespace = function()
 {
     return this.replace(/[\s\xA0]+$/g, "");
 }

 String.prototype.trimWhitespace = function()
 {
     return this.replace(/^[\s\xA0]+|[\s\xA0]+$/g, "");
 }

 String.prototype.trimURL = function(baseURLDomain)
 {
     var result = this.replace(new RegExp("^http[s]?:\/\/", "i"), "");
     if (baseURLDomain)
         result = result.replace(new RegExp("^" + baseURLDomain.escapeForRegExp(), "i"), "");
     return result;
 }
 /*通用分页*/
 function pagination(curPage, totalPage,reverse) {
 	var html = [];
 	var prev = reverse ? "下一页" : "上一页";
 	var next = reverse ? "上一页" : "下一页";
 	if (curPage > 0) html.push("<li><a href='javascript:void(0)' onclick='return gotoPage(" + (curPage - 1) + ");'><span>"+prev+"</span></a></li>");
 	var fstDot = false, sndDot = false;
 	for (var i = 1; i <= totalPage; i++) {
 		var displayPage;
 		if (!reverse){
 			displayPage=i;
 		}else {
 			displayPage=totalPage-i+1;
 		}
 		if (curPage == i - 1) {
 			html.push("<li class='activeNum'><strong>" + displayPage + "</strong></li>");
 			continue;
 		}
 		if (totalPage > 7) {
 			if (i == 1 || i == 2 || i == totalPage || i == totalPage - 1 || (i >= curPage && i <= curPage + 2)) {
 				html.push("<li><a href='javascript:void(0)' onclick='return gotoPage(" + (i - 1) + ")'><span>" + displayPage + "</span></a></li>");
 			} else {
 				if (curPage < 4 && i < 5) {
 					html.push("<li><a href='javascript:void(0)' onclick='return gotoPage(" + (i - 1) + ")'><span>" + displayPage + "</span></a></li>");
 					continue;
 				}
 				if (i < curPage + 1 && !fstDot) {
 					html.push("<li class='mid'>...</li>");
 					fstDot = true;
 				}
 				if (i > curPage + 1 && !sndDot) {
 					html.push("<li class='mid'>...</li>");
 					sndDot = true;
 				}
 			}
 		} else html.push("<li><a href='javascript:void(0)' onclick='return gotoPage(" + (i - 1) + ")'><span>" + displayPage + "</span></a></li>");
 	}
 	if (curPage < totalPage - 1) html.push("<li><a href='javascript:void(0)' onclick='return gotoPage(" + (curPage + 1) + ");'><span>"+next+"</span></a></li>");
 	return reverse?html.reverse().join(""):html.join("");
 }
 function gotoPage(page) {
     var href = window.location.href;
     page += 1;
     window.location.href = href.indexOf("page=") > -1 ? (href.replace(/page=\d+/,"page="+page)) : href.indexOf("?") > -1 ? (href+"&page="+page) : (href+"?page="+page);
     return false;
 }