// JavaScript Document
var fileSite = "http://ftp.zjtcn.com";// 文件系统域名
var passportSite = "http://ca.zjtcn.com"; // 统一登录验证的域名

var domains = ["www.gdzjt.com", "www.zjtcn.com", "www.gxzjt.com",
		"www.szzjt.com.cn", "www.sczjt.com", "www.ccwcw.com"];

/*-------------------基本工具类----------------------*/
String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
};
String.prototype.ltrim = function() {
	return this.replace(/(^\s*)/g, "");
};
String.prototype.rtrim = function() {
	return this.replace(/(\s*$)/g, "");
};
var dealStr = function(v) {
	v = v.replace(/(')/g, "");
	return v.trim();
};
var replacebranch = function(v) {
	return v.replace(/(;)/g, "/");
};
String.prototype.isNumber = function() {
	var patrn = /^([0-9])+(.)?([0-9])*$/;
	if (!patrn.exec(this))
		return false;
	return true;
};
String.prototype.delwave = function() {
	return this.replace(/(~|～)/g, "-");
}
var delwave = function(v) {
	if (v == null || v == undefined||v=="")
		return "^!^";//特殊转换为""
	else {
		v = v.replace(/(;)/g, "；");
		v = v.replace(/(~)/g, "～");
		v = v.replace(/(')/g, "‘");
		v = v.replace(/(")/g, "“");
		v = v.replace(/(<)/g, "&lt;");
		v = v.replace(/(>)/g, "&gt;");
		v = v.replace(/(&nbsp;)/g, "");
		v = v.replace(/(&nbsp)/g, "");
		v = v.replace(/(<p>|<\/p>)/g, "");
		return v;
	}
}
var delwave2 = function(v) {
	v = v.replace(/(')/g, "‘");
	return v;
}
var del_space = function(v) {
	if ((v || "") != "") {
		var temp = encodeURI(v);
		v = temp.replace(/(%C2%A0)/g, "");
		return decodeURI(v);
	} else
		return " ";

};
var trim = function(txt) {
	if (txt)
		return txt.replace(/(^\s*)|(\s*$)/g, "");
};
var replacedot = function(v) {
	if ((v || "") != "") {
		v = v.replace(/(')/g, "")
		return v.replace(/(")/g, "")
	}
}
var getE = function(id) {
	return document.getElementById(id);
};
var getN = function(ename) {
	return document.getElementsByName(ename);
};
var getV = function(id) {
	var obj = getE(id);
	if (obj)
		return obj.value;
	else
		return "";
}
var getT = function(obj, tagname) {
	return obj.getElementsByTagName(tagname);
};
var encode = function(txt) {
	return encodeURI(txt);
}
var decode = function(txt) {
	return decodeURI(txt);
}
var getArgs = function(sHref, sArgName) {
	var args = sHref.split("?");
	var retval = "";
	if (args[0] == sHref) {
		return retval;
	}
	var str = args[1];
	var spec = str.indexOf("#");
	if (spec != -1)
		str = str.substring(0, spec)
	args = str.split("&");
	var len = args.length;
	for (var i = 0; i < len; i++) {
		str = args[i];
		var arg = str.split("=");
		if (len < 1)
			continue;
		if (arg[0] == sArgName)
			retval = arg[1];
	}
	return retval;
}
function getCurArgs(argName) {
	var args = new Object();
	var query = location.search.substring(1); // Get query string
	var pairs = query.split("&"); // Break at ampersand
	for (var i = 0; i < pairs.length; i++) {
		var pos = pairs[i].indexOf('='); // Look for "name=value"
		if (pos == -1)
			continue; // If not found, skip
		var argname = pairs[i].substring(0, pos); // Extract the name
		var value = pairs[i].substring(pos + 1); // Extract the value
		value = decodeURIComponent(value); // Decode it, if needed
		args[argname] = value; // Store as a property
	}
	if ((argName || "") == "")
		return args; // Return the object,you can use it by this method:
						// "getCurArgs()["xx"]" or "getCurArgs().xx"
	else
		return args[argName]; // return the element,you can use it by this
								// method: getCurArgs("xx")
}
var setMenu = function(index) {
	var obj = getE("navmenus");
	var menus = obj.getElementsByTagName("a");
	var len = menus.length;
	for (var j = 0; j < len; j++) {
		menus[j].className = "indexnav";
	}
	menus[index - 1].className = "currnav";
}

var addAttribute = function(obj, styleClass) {
	if (obj) {
		if (document.all)
			obj.setAttribute("className", obj.getAttribute("className") + " "
							+ styleClass);
		else
			obj.setAttribute("class", obj.getAttribute("class") + " "
							+ styleClass);

	}
}

var removeAttribute = function(obj, styleClass) {
	if (obj) {
		if (document.all)
			obj.setAttribute("className", obj.getAttribute("className")
							.replace(styleClass, ""));
		else
			obj.setAttribute("class", obj.getAttribute("class").replace(
							styleClass, ""));

	}

}
var selectAllCheck = function(checkName) {
	var obj = document.getElementsByName(checkName);
	if (obj) {
		var len = obj.length;
		for (var i = 0; i < len; i++) {
			if (!obj[i].checked)
				obj[i].checked = true;
			else
				obj[i].checked = false;
		}
	}
};
var unSelectAllCheck = function(checkName) {
	var obj = document.getElementsByName(checkName);
	if (obj) {
		var len = obj.length;
		for (var i = 0; i < len; i++) {
			obj[i].checked = false;
		}
	}
};
var getRadioValue = function(radioName) {
	var txt = "";
	var obj = getN(radioName);
	if (obj) {
		var objlen = obj.length;
		for (var i = 0; i < objlen; i++) {
			if (obj[i].checked) {
				txt = obj[i].value;
				break;
			}
		}
	}
	return txt;
};

var resetSelectByValue = function(selectId, optionValue,fn) {
	var obj = getE(selectId);
	var option = "";
	if (obj) {
		setTimeout(function() {
					var len = obj.options.length;
					for (var i = 0; i < len; i++) {
						option = obj.options[i];
						if (option.value == optionValue)
							option.selected = true;
					}
				}, 200);
		if (fn != undefined) {
					fn();

		}
	}
};
var resetSelectByText = function(selectId, optionText,fn) {
	var obj = getE(selectId);
	var option = "";
	if (obj) {
		setTimeout(function() {
					var len = obj.options.length;
					for (var i = 0; i < len; i++) {
						option = obj.options[i];
						if (option.text == optionText)
							option.selected = true;
					}
				}, 200);
		if (fn != undefined) {
			fn();
		}
	}
};
var getSelectText = function(selectId) {
	var obj = getE(selectId);
	if (obj) {
		var len = obj.options.length;
		for (var i = 0; i < len; i++) {
			if (obj.options[i].selected == true)
				return obj.options[i].text;
		}
	}
};
function Cookie() {
}
Cookie.prototype.setCookie = function(name, value, option) {
	var str = name + "=" + encodeURIComponent(value);
	if (option) {
		if (option.expireDays) {
			var date = new Date();
			var ms = option.expireDays * 24 * 3600 * 1000;
			date.setTime(date.getTime() + ms);
			str += "; expires=" + date.toGMTString();
		}
		if (option.path)
			str += "; path=" + option.path;
		if (option.domain)
			str += "; domain" + option.domain;
		if (option.secure)
			str += "; true";
	}
	document.cookie = str;
};
Cookie.prototype.getCookie = function(name) {
	var cookieArray = document.cookie.split("; ");
	var cookie = new Object();
	for (var i = 0; i < cookieArray.length; i++) {
		var arr = cookieArray[i].split("=");
		if (arr[0] == name)
			return decodeURIComponent(arr[1]);
	}
	return "";
}

Cookie.prototype.deleteCookie = function(name) {
	this.setCookie(name, "", {
				expireDays : -1
			});
};
Array.prototype.inArray = function(value) {
	var i;
	for (i = 0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};

String.prototype.gblen = function() {
	var len = 0;
	var txt = this.replace(/(^\s*)|(\s*$)/g, "");
	txt = txt.replace(/(^\s*)/g, "");
	txt = txt.replace(/(\s*$)/g, "");
	var templen = "";
	var temptype = 1;
	for (var i = 0; i < txt.length; i++) {
		if (txt.charCodeAt(i) > 127 || txt.charCodeAt(i) == 94) {
			len += 2;

		} else {
			len++;
		}
	}
	return len;

};
String.prototype.gbtrim = function(len, s) {
	var txt = this.replace(/(^\s*)|(\s*$)/g, "");
	txt = txt.replace(/(^\s*)/g, "");
	txt = txt.replace(/(\s*$)/g, "");
	var str = '';
	var sp = s || '';
	var len2 = 0;
	for (var i = 0; i < txt.length; i++) {
		if (txt.charCodeAt(i) > 127 || txt.charCodeAt(i) == 94) {
			len2 += 2;
		} else {
			len2++;
		}
	}
	if (len2 <= len) {
		return txt;
	}
	len2 = 0;
	len = (len > sp.length) ? len - sp.length : len;
	for (var i = 0; i < txt.length; i++) {
		if (txt.charCodeAt(i) > 127 || txt.charCodeAt(i) == 94) {
			len2 += 2;
		} else {
			len2++;
		}
		if (len2 > len) {
			str += sp;
			break;
		}
		str += txt.charAt(i);
	}
	return str;
};

//判断非空
function isEmpty(v){
	if((v||"")!="")
		return true;
	else
		return false;
};

/* 设为首页 */
var setHomepage = function(url) {
	var thisUrl;
	if (url == "" || url == undefined) {
		thisUrl = window.location.protocol + "//" + window.location.host;
	} else {
		thisUrl = url;
	}
	if (document.all) {
		document.body.style.behavior = 'url(#default#homepage)';
		document.body.setHomePage(thisUrl);
	} else if (window.sidebar) {
		if (window.netscape) {
			try {
				netscape.security.PrivilegeManager
						.enablePrivilege("UniversalXPConnect");
			} catch (e) {
				alert("你的浏览器不允许这个操作!");
			}
		}
		var prefs = Components.classes['@mozilla.org/preferences-service;1']
				.getService(Components.interfaces.nsIPrefBranch);
		prefs.setCharPref('browser.startup.homepage', thisUrl);
	}
};
/* 加入收藏 */
var setFavorite = function(url) {
	var thisUrl;
	if (url == "" || url == undefined) {
		thisUrl = window.location.href;
	} else {
		thisUrl = url;
	}
	var title = document.title;
	if (document.all) {
		window.external.addFavorite(thisUrl, title);
	} else if (window.sidebar) {
		window.sidebar.addPanel(title, thisUrl, "");
	}
};

// 自身跳转
var goback = function(url) {
	if (!isNull(url))
		window.location.href = url;
	else
		alert("未传入url");
};
// 新开窗口跳转
var gojump = function(url) {
	if (!isNull(url))
		window.open(url);
	else
		alert("未传入url");
};

// 继承
var apply = function(o, c, defaults) {
	// no "this" reference for friendly out of scope calls
	if (defaults) {
		this.apply(o, defaults);
	}
	if (o && c && typeof c == 'object') {
		for (var p in c) {
			o[p] = c[p];
		}
	}
	return o;
};
