var __webContextPath = 'http://imgroups.net';
var __forumContextPath = 'http://dis.imgroups.net';
var __photoContextPath = 'http://pho.imgroups.net';
var __shareContextPath = 'http://share.imgroups.net';
var Common = function () {
};
Common.prototype.exRemote = function (rUrl) {
	var scriptDom = document.createElement("script");
	scriptDom.src = rUrl;
	document.getElementsByTagName("HEAD")[0].appendChild(scriptDom);
	var p = scriptDom.parentNode;
	if (p) {
		if (navigator.appName != "Microsoft Internet Explorer") {//if not IE
        	//Firefox2、Firefox3、Safari3.1+、Opera9.6+ support js.onload
	        scriptDom.onload = function () {
	            p.removeChild(scriptDom);
	        }
	    } else {
	        //IE6、IE7 support js.onreadystatechange
	        scriptDom.onreadystatechange = function () {
	            if (scriptDom.readyState == 'loaded' || scriptDom.readyState == 'complete') {
	                p.removeChild(scriptDom);
	            }
	        }
	    }
	}
};
Common.prototype.strLength = function (str) {
	try {
		var valueLen = 0;
		for (i = 0; i < str.length; i++) {
			var code = escape(str.charAt(i));
			if ((code.length >= 4) && (code < "%uFF00" || code > "%uFFFF")) {
				valueLen += 2;
	                //这里表示是全角字符
			} else {
				valueLen++;
	                //这里是半角
			}
		}
		return valueLen;
	}
	catch (ex) {//alert(ex.description);
	}
};
Common.prototype.replaceMsg = function (rm) {
	if (rm == null) {
		rm = "";
	}
	while (rm.indexOf("'") > -1) {
		rm = rm.replace("'", "\u2018");
	}
	while (rm.indexOf("\"") > -1) {
		rm = rm.replace("\"", "\u201c");
	}
	while (rm.indexOf("<") > -1) {
		rm = rm.replace("<", "&lt;");
	}
	while (rm.indexOf(">") > -1) {
		rm = rm.replace(">", "&gt;");
	}
	return rm;
};
Common.prototype.subString = function (str, len) {
	try {
		str = this.unescapeHTML(str);
		var num_need = 40;
		if (len > 0) {
			num_need = len;
		}
		var num_str = this.strLength(str);
		var str_temp = "";
		if (num_need < 2) {
			num_need = 2;
		}
		if (num_need < num_str) {//大于,那么截取指定长度
			var nt = 0;
			for (var i = 0; i < str.length; i++) {
				if (nt >= num_need - 2) {
					break;
				} else {
					str_temp += str.charAt(i);
				}
				var code = escape(str.charAt(i));
				if ((code.length >= 4) && (code < "%uFF00" || code > "%uFFFF")) {
					nt += 2;
					//这里表示是全角字符
				} else {
					nt++;
					//这里是半角
				}
			}
			str_temp += "..";
		} else {
			str_temp = str;
		}
		return this.replaceMsg(str_temp);
	}
	catch (ex) {//alert(ex.description);
	}
};
Common.prototype.quickJoin = function (gid,mp) {
	var gUrl = __webContextPath + "/gid-" + gid + "&t=j";//空间群首页，t=j
	if (mp) {//已登录
		window.location.href = gUrl;
	} else {
		if ($j) {
			var encodeUrl = $j.base64Encode(gUrl);
			window.location.href = __webContextPath + "/u/login_show.do?jurl=" + encodeUrl;//登录，jurl=encodeUrl
		}
	}
};
Common.prototype.quickJoinR = function (gp, mp, mpType) {
	if (navigator.appName == "Microsoft Internet Explorer" && mp && mpType == 1) {//ie&&登录&&msn帐号
		window.open("msnim:add?contact=" + gp, "win");
	}
};
Common.prototype.quickLaunch = function (groupLiveId) {
	if (navigator.appName == "Microsoft Internet Explorer") {//ie
		window.open("msnim:chat?contact=" + groupLiveId, "win");
	} else {
		alert("\u5bf9\u4e0d\u8d77\uff0c\u672c\u529f\u80fd\u53ea\u6709IE\u6d4f\u89c8\u5668\u53ef\u4ee5\u4f7f\u7528");
	}
};
Common.prototype.back = function () {
	var navigatorName = "Microsoft Internet Explorer";
	var isIE = false;
	if (navigator.appName == navigatorName) {
		isIE = true;
	}
	if (isIE) { //IE代码
		history.go(-1);
	} else {
		window.history.back(-1);
	}
};
Common.prototype.showLayerDis = function (obj, msg) {
	$j("#head_loginTypeLayer_tip").html(msg);
	var div = $j(obj);
	$j("#head_loginTypeLayer").css({position:"absolute", top:(div.offset().top + div.height()) + "px", left:(div.offset().left + div.width() / 2) + "px"}).show();
};
Common.prototype.hideLayerDis = function () {
	$j("#head_loginTypeLayer").hide();
};
Common.prototype.skipToGroupOverView = function (gid) {
	window.location.href = __webContextPath + "/gid-" + gid;
};
Common.prototype.skipToGroupMember = function (gid) {
	window.location.href = __webContextPath + "/gr/viewMembers.do?gid=" + gid;
};
Common.prototype.skipToIndex = function () {
	window.location.href = __webContextPath + "/";
};
Common.prototype.skipToCreateGroup = function () {
	window.location.href = __webContextPath + "/u/cg_show.do";
};
Common.prototype.skipToGroupTool = function (gid) {
	window.location.href = __webContextPath + "/g/groupTool.do?gid=" + gid;
};
Common.prototype.skipToChatLog = function (gid) {
	window.location.href = __webContextPath + "/g/chatLog_show.do?gid=" + gid;
};
Common.prototype.skipToBrowseGroups = function () {
	window.location.href = __webContextPath + "/g/search_init.do";
};
Common.prototype.skipToGroupSet = function (gid) {
	window.location.href = __webContextPath + "/g/gu_index.do?gid=" + gid;
};
Common.prototype.skipToManagementPanel = function (gid) {
	window.location.href = __webContextPath + "/g/group_info.do?gid=" + gid;
};
Common.prototype.skipToFeatureTour = function () {
	window.location.href = __webContextPath + "/u/tour.do";
};
Common.prototype.skipToForum = function (gid) {
	window.location.href = __forumContextPath + "/Forum/forumtopic/getZoneForumtopicList.do?gid=" + gid + "&ad=0";
};
Common.prototype.skipToPhoto = function (gid) {
	window.location.href = __shareContextPath+"/share/pic/list/"+gid+"/all/1";
};
Common.prototype.skipToMyGroups = function () {
	window.location.href = __webContextPath + "/u/myGroups_show.do";
};
Common.prototype.skipToVideo = function (gid) {
	window.location.href = __shareContextPath + "/share/video/list/"+gid+"/all/1";
};
Common.prototype.skipToLink = function (gid) {
	window.location.href = __shareContextPath + "/share/link/list/"+gid+"/all/1";
};
Common.prototype.skipToFiles = function (gid) {
	window.location.href = __shareContextPath + "/files/groupFiles/index.do?gid="+gid;
};
Common.prototype.unescapeHTML = function (str) {
	str = String(str).replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, "\"").replace(/&amp;/g, "&");
	return str;
};
Common.prototype.escapeHTML = function (str) {
	str = String(str).replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;");
	return str;
};
Common.prototype.getStringReplaceByArgs = function (template) {
	var len = arguments.length;
	if (len <= 1) {
		return template;
	}
	var array = new Array();
	for (var i = 1; i < len; i++) {
		array[i - 1] = arguments[i];
	}
	return this.getStringReplaceByValues(template, array);
};
Common.prototype.getStringReplaceByValues = function (template, values) {
	for (var i = 0; i < values.length; i++) {
		var index = template.indexOf("{" + i + "}");
		if (index > -1) {
			if (values[i] != null) {
				template = template.replace("{" + i + "}", values[i].toString());
			} else {
				template = template.replace("{" + i + "}", "");
			}
		}
	}
	return template;
};

Common.prototype.createCookie = function(name,value,expires,path,domain,secure){
	document.cookie = name + "=" + encodeURI(value) + ((expires)? ('; expires='+expires) : '')+ ((path) ? ('; path='+path) : '') +((domain) ? ('; domain='+domain) : '') + ((secure) ? '; secure' : '');
}

Common.prototype.getCookie = function(name){
	var arg = name + "=";
	var alen= arg.length;
	var theCookie = '' + document.cookie;
	
	var inCookieSite = theCookie.indexOf(arg);
	if(inCookieSite == -1 || name == "")
	       return '';
	
	var begin = inCookieSite + alen ;
	var end = theCookie.indexOf(';',begin);
	if(end == -1){end=theCookie.length;}
	
	return decodeURI(theCookie.substring(begin,end));
}
