
// function --------------------------------------------------------------------
function post(url, data, option) {
	option = option || {};
	if (getType(option) == "String")
		option = {
			question : option
		};
	var _option = {
		question : false,
		target : "_self"
	};
	for (var name in _option) {
		if (!(name in option))
			option[name] = _option[name];
	}

	if (option.question) {
		if (!confirm(option.question))
			return;
	}
	var d = data || {};
	var html = "";
	for (name in d) {
		html += "<input type='hidden' name='" + name + "' value='" + d[name]
				+ "'/>";
	}
	var f = document.createElement("form");
	f.method = "post";
	f.action = url;
	f.target = option.target;
	f.innerHTML = html;
	document.body.appendChild(f);
	f.submit();
} 

/**
 * @param {String}
 *            url
 * @param {String}
 *            params 要附加的子符串, 如 param1=value&param2=value
 * @param {Array}
 *            excludes 要排除的请求参数名
 */
function rebuildUrl(url, params, excludes) {
	url = url || window.location.href;
	params = params || "";
	excludes = excludes || [];
	var query = "";
	var pos = url.indexOf("?");
	if (pos != -1) {
		query = url.substring(pos);
		url = url.substring(0, pos);
	}

	var temp = "";
	var inExcludes = function(str) {
		for (var i = 0; i < excludes.length; i++) {
			if (str == excludes[i])
				return true;
		}
		return false;
	};
	if (query.length > 0) {
		query = query.substring(1);
		var array = query.split("&");
		for (var i = 0; i < array.length; i++) {
			var name = array[i].split("=")[0];
			if (!inExcludes(name))
				temp += "&" + array[i];
		}
	}
	if (temp.length > 0 || params.length > 0)
		url += "?"; // 有请求参数
	if (temp.length > 0) {
		url += temp.substring(1);
		if (params.length > 0)
			url += "&";
	}
	if (params.length > 0) {
		if (params.indexOf('&') == 0)
			params = params.substring(1);
		url += params;
	}
	return url;
}

/**
 * 弹出窗口
 * 
 * @param {String}
 *            url
 * @param {String}
 *            width
 * @param {String}
 *            height
 */
function openWindow(url, width, height) {
	var win = window.open(url, "popupwin",
			"menubar=no,scrollbars=yes,toolbar=no,location=no,status=no,width="
					+ width + ",height=" + height + ",left="
					+ (screen.availWidth - width) / 2 + ",top="
					+ (screen.availHeight - height) / 2);
	win.window.focus();
}

function getOSName() {
	// This script sets OSName variable as follows:
	// "Windows" for all versions of Windows
	// "MacOS" for all versions of Macintosh OS
	// "Linux" for all versions of Linux
	// "UNIX" for all other UNIX flavors
	// "Unknown OS" indicates failure to detect the OS
	var OSName = "Unknown OS";
	if (navigator.appVersion.indexOf("Win") != -1)
		OSName = "Windows";
	if (navigator.appVersion.indexOf("Mac") != -1)
		OSName = "MacOS";
	if (navigator.appVersion.indexOf("X11") != -1)
		OSName = "UNIX";
	if (navigator.appVersion.indexOf("Linux") != -1)
		OSName = "Linux";
	return OSName;
}

function isIE() {
	return document.all && !window.opera;
}

/**
 * 增强的类型测试. 对于基本数据类型, 返回它们对应的包装类型
 * 
 * @param {Object}
 *            x 要测试的对象
 * @return {String} 返回表示 x 所属类型的字符串
 */
function getType(x) {
	if (x == undefined)
		return "undefined";
	if (x == null)
		return "null";

	// Next try the typeof operator
	var t = typeof x;
	// If the result is not vague, return it
	if (t != "object")
		return t.charAt(0).toUpperCase() + t.substring(1);

	// Otherwise, x is an object. Use the default toString( ) method to
	// get the class value of the object.
	var c = Object.prototype.toString.apply(x); // Returns "[object class]"
	c = c.substring(8, c.length - 1); // Strip off "[object" and "]"

	// If the class is not a vague one, return it.
	if (c != "Object")
		return c;

	// If we get here, c is "Object". Check to see if
	// the value x is really just a generic object.
	if (x.constructor == Object)
		return c; // Okay the type really is "Object"
	// For user-defined classes, look for a string-valued property named
	// classname, that is inherited from the object's prototype
	if ("classname" in x.constructor.prototype && // inherits classname
			typeof x.constructor.prototype.classname == "string") // its a
		// string
		return x.constructor.prototype.classname;

	// If we really can't figure it out, say so.
	return "<unknown type>";
}

/**
 * This function parses ampersand-separated name=value argument pairs from the
 * query string of the URL. It stores the name=value pairs in properties of an
 * object and returns that object. Use it like this:
 * 
 * var params = getParams(); // Parse params from URL var q = params.q || ""; //
 * Use argument, if defined, or a default value var n = params.n ?
 * parseInt(params.n) : 10;
 */
function getParams() {
	var regexp = /\u002B/g; // 匹配一个加号
	var params = 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 name = pairs[i].substring(0, pos); // Extract the name
		var value = pairs[i].substring(pos + 1); // Extract the value
		name = decodeURIComponent(name.replace(regexp, " ")); // Decode it, if
		// needed
		value = decodeURIComponent(value.replace(regexp, " "));
		params[name] = value; // Store as a property
	}
	return params; // Return the object
}

/**
 * 提取表单数据
 * 
 * @param {Form}
 *            f 表单对象
 * @return {Object} 存放表单数据的对象
 */
function form2object(f) {
	var data = {};
	var elements = f.elements;
	for (var i = 0; i < elements.length; i++) {
		var elem = elements[i];
		var name = elem.name;
		if (getType(name) == "undefined")
			continue;
		if (elem.disabled == true)
			continue;
		if (elem.type == "radio") {
			if (elem.checked)
				data[name] = elem.value;
		} else if (elem.type == "checkbox") {
			if (!(name in data))
				data[name] = [];
			if (elem.checked)
				data[name].append(elem.value);
		} else if (elem.type == "select-one") {
			for (var j = 0; j < elem.options.length; j++) {
				if (elem.options[j].selected) {
					data[name] = elem.options[j].value;
					break;
				}
			}
		} else if (elem.type == "select-multiple") {
			data[name] = [];
			for (var j = 0; j < elem.options.length; j++) {
				if (elem.options[j].selected)
					data[name].append(elem.options[j].value);
			}
		} else {
			// text password textarea 及其他
			data[name] = elem.value;
		}
	}
	return data;
}

var StrutsResult = {
	json2array : function(data) {
		var array = [];
		var exception = data.exception;
		var actionErrors = data.actionErrors;
		var actionMessages = data.actionMessages;
		var fieldErrors = data.fieldErrors;
		if (exception != null) {
			if ("message" in exception)
				array.append(exception.message);
			else
				array.append("系统异常：" + exception.className);
		}
		for (var i = 0; i < actionErrors.length; i++)
			array.append(actionErrors[i]);
		for (var i = 0; i < actionMessages.length; i++)
			array.append(actionMessages[i]);
		for (var i = 0; i < fieldErrors.length; i++) {
			var fieldName = fieldErrors[i]["fieldName"];
			var errors = fieldErrors[i]["errors"];
			for (var j = 0; j < errors.length; j++)
				array.append(errors[j]);
		}
		return array;
	}
};

// 验证 -------------------------------------------------------------------------
/**
 * 测试一个字符串是否只包含空白字符.
 * 
 * @param {String}
 *            str
 * @return 只包含空白字符则返回 true, 否则返回 false.
 */
function isBlank(str) {
	var pattern = /^\s+$/;
	return pattern.test(str);
}

/**
 * 测试一个字符串是否为空串, 或只包含空格的字符串.
 * 
 * @param {String}
 *            str
 * @return 是空字符串则返回 true, 否则返回 false.
 */
function isEmpty(str) {
	if (str === null || str.length === 0 || isBlank(str)) {
		return true;
	} else {
		return false;
	}
}

/**
 * 测试一个字符串是否能转换为整数, 即只包括0-9.
 * 
 * @param {String}
 *            str
 * @return 能转换为整数则返回 true, 否则返回 false.
 */
function isInteger(str) {
	var pattern = /^[0-9]+$/; // 只能包括0-9, 不能包括空格或小数点.
	return pattern.test(str);
}

/**
 * 测试一个字符串是否能转换成钱数.
 * 
 * @param {String}
 *            str
 * @return 能转换为钱数则返回 true, 否则返回 false.
 */
function isMoney(str) {
	var pattern = /^\d+(\.\d{1,2})?$/;
	return pattern.test(str);
}

/**
 * 测试一个字符串是否为有效的 email 地址.
 * 
 * @param {String}
 *            str
 */
function isEmail(str) {
	var pattern = /^[_a-zA-Z0-9.]+@([_a-zA-Z0-9]+\.)+[a-zA-Z0-9]{2,3}$/;
	return pattern.test(str);
}

/**
 * 测试一个字符串是否为有效的 url
 * 
 * @param {String}
 *            str
 */
function isUrl(str) {
	var pattern = /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i;
	return pattern.test(str);
}

/**
 * 测试字符串是否仅包含汉字,数字0-9,字母a-zA-Z和下划线_
 * 
 * @param {String}
 *            str
 * @return {Boolean}
 */
function chkstr(str) {
	if (getType(str) != 'String') {
		str = str.value;
	}
	for (var i = 0; i < str.length; i++) {
		if (str.charCodeAt(i) < 127 && !str.substr(i, 1).match(/^\w+$/ig)) {
			return false;
		}
	}
	return true;
}

// 文件名 -----------------------------------------------------------------------
function isExtension(fileName, extensions) {
	var ext = getExtension(fileName).toLowerCase();
	for (var i = 0; i < extensions.length; i++) {
		if (ext == extensions[i].toLowerCase()) {
			return true;
		}
	}
	return false;
}

function getExtension(fileName) {
	var extensionPos = fileName.lastIndexOf(".");
	if (extensionPos == -1)
		return "";
	return fileName.substring(extensionPos + 1);
}

function getFileName(path) {
	var separator = getOSName() == "Windows" ? "\\" : "/";
	var pos = path.lastIndexOf(separator);
	if (pos == -1)
		return path;
	return path.substring(pos + 1);
}

// String ----------------------------------------------------------------------
String.prototype.endsWith = function(str) {
	if (str == null || str == "" || this.length == 0
			|| str.length > this.length)
		return false;
	if (this.substring(this.length - str.length) == str)
		return true;
	else
		return false;
};

String.prototype.startsWith = function(str) {
	if (str == null || str == "" || this.length == 0
			|| str.length > this.length)
		return false;
	if (this.substr(0, str.length) == str)
		return true;
	else
		return false;
};

/**
 * 返回一个去除首尾空白字符的新字符串
 * 
 * @return {String} 一个去除首尾空白字符的新字符串
 */
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g, "");
};

/**
 * 将字符串中的回车换行都替换成<br/>标记
 * 
 * @return {String} 一个替换后的新字符串
 */
String.prototype.nl2br = function() {
	return this.replace(/\r\n/g, "<br/>").replace(/\n/g, "<br/>");
};

/**
 * 将字符串中的空格都替换成 &nbsp;
 * 
 * @return {String} 一个替换后的新字符串
 */
String.prototype.space2nbsp = function() {
	return this.replace(/\s/g, "&nbsp;");
};

String.prototype.toArray = function() {
	var array = this.replace(/\s+/g, "").replace(/，/g, ",").replace(/、/g, ",")
			.split(",");
	return array;
};

/**
 * 将字符串中特殊字符替换成相应 XML 实体
 * 
 * @return {String} 一个替换后的新字符串
 */
String.prototype.escapeXml = function() {
	return this.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g,
			"&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
};

/**
 * 将字符串中 XML 实体替换成它们所表示字符
 * 
 * @return {String} 一个替换后的新字符串
 */
String.prototype.unescapeXml = function() {
	return this.replace(/&#39;/g, "'").replace(/&quot;/g, "\"").replace(
			/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&amp;/g, "&");
};

/**
 * 去掉字符串中 HTML 或 XML 标记
 * 
 * @return {String} 一个去掉所有标记后的新字符串
 */
String.prototype.stripTags = function() {
	return this.replace(/<\/?[^>]+>/gi, "");
};

/**
 * 从字符串中截取指定长度
 * 
 * @return {String} 截取后的新字符串
 */
String.prototype.cut = function(length) {
	if (this.bytes() == length)
		return this;
	var len = 0;
	var buff = "";
	for (var i = 0; i < this.length; i++) {
		if (len >= length - 2) {
			buff += "…";
			return buff;
		}
		var c = this.charAt(i);
		buff += c;
		if (c > 127) {
			len++;
		} else if (c == '&') { // 避免实体截短
			for (var l = 3; l <= 10; l++) {
				var t = this.substring(i + 1, i + 1 + l);
				if (t.endsWith(";")) {
					buff += t;
					i = i + l;
					break;
				}
			}
		}
		len++;
	}
	return this;
};

/**
 * 获得字符串中的字节数
 * 
 * @return {Integer} 字符串中的字节数
 */
String.prototype.bytes = function() {
	var len = 0;
	for (var i = 0; i < this.length; i++) {
		if (this.charCodeAt(i) > 127) {
			len++;
		}
		len++;
	}
	return len;
};

// Array -----------------------------------------------------------------------
/**
 * 返回指定对象在数组中的索引. 如果指定的对象不存在, 则返回 -1
 * 
 * @param {Object}
 *            obj 要测试的对象
 * @return {Number} 指定对象在数组中的索引. 如果指定的对象不存在, 则返回 -1
 */
Array.prototype.indexOf = function(obj) {
	var result = -1;
	for (var i = 0; i < this.length; i++) {
		if (this[i] == obj) {
			result = i;
			break;
		}
	}
	return result;
};

/**
 * 若数组中存在指定对象则返回 true, 否则返回 false
 * 
 * @param {Object}
 *            obj 要测试的对象
 * @return {Boolean} 若数组中存在指定对象则返回 true, 否则返回 false
 */
Array.prototype.contains = function(obj) {
	return (this.indexOf(obj) >= 0);
};

/**
 * 在数组末尾增加对象, nodup 参数用于指定是否增加重复对象
 * 
 * @param {Object}
 *            obj 要增加的对象
 * @param {Boolean}
 *            nodup 指定 true 不增加重复对象, 指定 false 增加重复对象. 默认为 false
 */
Array.prototype.append = function(obj, nodup) {
	if (!(nodup && this.contains(obj))) {
		this[this.length] = obj;
	}
};

/**
 * 清空数组
 */
Array.prototype.clear = function() {
	this.length = 0;
};

/**
 * 在数组中的指定索引位置插入对象, 后续数组元素的索引加1
 * 
 * @param {Number}
 *            index 要插入位置的索引
 * @param {Object}
 *            obj 要插入的对象
 * @exception {Error}
 *                如果索引不在(index < 0 || index > this.length)的范围之内
 */
Array.prototype.insertAt = function(index, obj) {
	if (index < 0 || index > this.length)
		throw new Error("索引越界");
	this.splice(index, 0, obj);
};

/**
 * 移除数组中指定索引位置的对象, 后续数组元素的索引减1
 * 
 * @param {Number}
 *            index 要移除位置的索引
 * @exception {Error}
 *                如果索引不在(index < 0 || index >= this.length)的范围之内
 */
Array.prototype.removeAt = function(index) {
	if (index < 0 || index >= this.length)
		throw new Error("索引越界");
	this.splice(index, 1);
};

/**
 * 从数组中移除指定对象. 若数组中存在指定对象则返回 true, 否则返回 false
 * 
 * @param {Object}
 *            obj 要移除的对象
 * @return {Boolean} 若数组中存在指定对象则返回 true, 否则返回 false
 */
Array.prototype.remove = function(obj) {
	var index = this.indexOf(obj);
	if (index >= 0) {
		this.removeAt(index);
		return true;
	}
	return false;
};

// FCKeditorUtil ---------------------------------------------------------------
var FCKeditorUtil = {
	GetHTML : function(instanceName) {
		return FCKeditorAPI.GetInstance(instanceName).GetXHTML(true);
	},
	SetHTML : function(instanceName, html) {
		var doc = this.GetDocument(instanceName);
		doc.body.innerHTML = html;
	},
	AppendHTML : function(instanceName, html) {
		var s = this.GetHTML(instanceName);
		var doc = this.GetDocument(instanceName);
		doc.body.innerHTML = s + html;
	},
	GetDocument : function(instanceName) {
		var iframe = document.getElementById(instanceName + "___Frame");
		var doc = iframe.contentWindow.document;
		iframe = doc.getElementById("xEditingArea").firstChild;
		doc = iframe.contentWindow.document;
		return doc;
	}
};

// 以下脚本需要 jquery.js -------------------------------------------------------
if (window.jQuery) {
	// Tabs
	// ------------------------------------------------------------------------
	function Tabs(id, selected, option, eventType) {
		this.id = id;
		this.selected = selected;
		this.option = option;
		this.eventType = eventType || "mouseover";
		this.showTab(selected);
		var tabs = this;
		$("#" + id + " .tab-nav").bind(this.eventType, function() {
					var id = $(this).find("input[type=hidden]").attr("value");
					tabs.showTab(id);
				});
	}
	Tabs.prototype.showTab = function(tabId) {
		this.selected = tabId;
		$("#" + this.id + " .tab-nav-normal").removeClass("hidden");
		$("#" + this.id + " .tab-nav-selected").addClass("hidden");
		$("#" + this.id + " .tab-panel").addClass("hidden");

		var parents = $("#" + this.id + " input[value=" + tabId + "]")
				.parents();
		parents.filter(".tab-nav-normal").addClass("hidden");
		parents.filter(".tab-nav-selected").removeClass("hidden");
		$("#" + tabId).removeClass("hidden");

		var index = null;
		for (var i = 0; i < this.option.length; i++) {
			if (this.option[i].id == tabId) {
				index = i;
				break;
			}
		}
		if (index == null)
			return;

		if (this.option[index].url && !this.option[index].loading
				&& !this.option[index].loaded) {
			var tabs = this;
			tabs.option[index].loading = true;
			$.get(this.option[index].url, {
						t : new Date().getTime()
					}, function(html) {
						tabs.option[index].loaded = true;
						tabs.option[index].loading = false;
						$("#" + tabId).html(html);
						if (tabs.option[index].onload) {
							tabs.option[index].onload(tabs.option[index]);
						}
					}, "html");
		}

		if (this.option[index].onshow) {
			this.option[index].onshow(this.option[index]);
		}
	};
	// Dialog
	// ----------------------------------------------------------------------
	/*
	 * 注意: 使用此脚本需要包含 jquery.js 使用此脚本时最好将文档声明为 <!DOCTYPE HTML PUBLIC "-//W3C//DTD
	 * HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
	 */

	/**
	 * 创建对话框
	 * 
	 * @param {String}
	 *            id 指定对话框的id
	 * @param {Object}
	 *            option 对话框参数, 如果不指定则使用默认值
	 * @param {Object}
	 *            parent 指定父元素, 需要符合jquery的选择器的要求, 默认值为 body
	 */
	function Dialog(id, option, parent) {
		Dialog.instances[this.id = id] = this;
		option = option || {};
		for (var name in Dialog.option) {
			if (!(name in option))
				option[name] = Dialog.option[name];
		}
		this.option = option;
		parent = parent || document.body;

		var html = "";
		html += "<div id='"
				+ id
				+ "' class='dialog moveable "
				+ option.css
				+ "' style='visibility:hidden' onmousedown='Dialog.top(this.id)'>";
		html += option.titlebar
				? "<div class='titlebar move'><span class='title'>&nbsp;</span><span class='close' onclick='Dialog.get(\""
						+ id + "\").close()'></span></div>"
				: "";
		html += "<div class='body content' style='overflow:"
				+ (option.scrolling ? "auto" : "hidden") + "'></div>";
		html += $.browser.msie ? "<iframe class='select-free'></iframe>" : "";
		html += "</div>";
		html += this.hasShadow() ? "<div id='" + id + "-shadow' class='shadow "
				+ option.css + "-shadow' style='visibility:hidden'></div>" : "";
		html += this.isModal() ? "<div id='" + id + "-overlay' class='overlay "
				+ option.css + "-overlay' style='display:none'></div>" : "";
		$(parent).append(html); // DOM Leak

		this.setSize(option.width, option.height); // 初使化窗口大小, 位置. 必须在设置内容前进行!
		this.setLocation(option.x, option.y, option.ref);
		if (option.fixed) {
			if (option.fixed == "css") {
				if ($.browser.msie && parseInt($.browser.version) == 6) { // IE6
					$("html").css("overflow", "hidden");
					$("body").css({
								height : "100%",
								overflow : "auto",
								margin : 0
							});
					if (!(document.body.firstChild.tagName && document.body.firstChild.tagName == "DIV")) { // 创建包装div
						var div = document.createElement("div");
						div.id = this.option.wrapper;
						while (document.body.hasChildNodes()) {
							var node = document.body.firstChild;
							document.body.removeChild(node);
							div.appendChild(node);
						}
						document.body.appendChild(div);
					}
				} else if ($.browser.msie && parseInt($.browser.version) < 6) { // IE6以下
					// TODO
				} else { // IE7 及其它
					$("#" + id + ", #" + id + "-shadow").css("position",
							"fixed");
				}
			} else {
				$(window).bind("scroll", function() {
							var d = Dialog.get(id);
							if (d.isVisible())
								d.resetLocation();
						});
			}
		}
		if (option.fastClose) {
			$("#" + id).click(function() {
						Dialog.get(id).close();
					});
		}
		if (this.isModal() && option.fastClose) {
			$("#" + id + "-overlay").click(function() {
						Dialog.get(id).close();
					});
		}
		this.onclose = function() {
			return true;
		}; // 默认的制定事件处理器 "onclose", 默认行为是隐藏窗口
	}

	/**
	 * 设置大小
	 * 
	 * @param {Number,
	 *            String} width 宽度
	 * @param {Number,
	 *            String} height 高度
	 */
	Dialog.prototype.setSize = function(width, height) {
		this.option.width = width;
		this.option.height = height;
		var id = this.id;
		$("#" + id).width(parseInt(width) + "px");
		$("#" + id + " .body").height(parseInt(height) + "px");
		if (this.hasShadow()) {
			$("#" + id + "-shadow").css({
						width : $("#" + id).outerWidth() + "px",
						height : $("#" + id).outerHeight() + "px"
					});
		}
	};

	/**
	 * 设置内容
	 * 
	 * @param {Element,
	 *            String} content 要显示的内容, 当指定 String 时可以包含 HTML 标记
	 */
	Dialog.prototype.setContent = function(content) {
		var id = this.id;
		$("#" + id + " .body").empty().append(content);
		$("#" + id + " .body .close").click(function() {
					Dialog.get(id).close();
				});
	};

	/**
	 * 设置标题
	 * 
	 * @param {String}
	 *            title
	 */
	Dialog.prototype.setTitle = function(title) {
		$("#" + this.id + " .title").empty().append(title);
	};

	/**
	 * 设置是否可见
	 * 
	 * @param {Boolean}
	 *            b 指定 true 可见, 指定 false 不可见
	 * @parem {Object} option 可选参数, 包括下以属性 timeout 如果 b 为 true 则在指定时间过后, 自动隐藏
	 */
	Dialog.prototype.setVisible = function(b, option) {
		if (b == this.isVisible())
			return;
		if (b && this.option.relocation)
			this.resetLocation();

		option = option || {};
		var _option = {
			timeout : -1,
			timeoutText : "本窗口将在%s秒后关闭"
		};
		for (var name in _option) {
			if (!(name in option))
				option[name] = _option[name];
		}
		var id = this.id;

		if (b) {
			if (this.isModal()) { // 显示 overlay 层
				var o = Dialog.getOverlaySize();
				$("#" + id + "-overlay").css({
							width : o.width + "px",
							height : o.height + "px",
							zIndex : Dialog.zIndex++,
							display : "block"
						});
			}
			if (this.hasShadow())
				$("#" + id + "-shadow").css({
							zIndex : Dialog.zIndex++,
							visibility : "visible"
						});
			$("#" + id).css({
						zIndex : Dialog.zIndex++,
						visibility : "visible"
					}); // 当窗口显示时增加它的 z-index, 保证新显示的窗口在最上面
		} else {
			if (this.isModal()) // 隐藏 overlay 层
				$("#" + id + "-overlay").css("display", "none");
			if (this.hasShadow())
				$("#" + id + "-shadow").css("visibility", "hidden");
			$("#" + id).css("visibility", "hidden");
		}

		if ($.browser.msie && this.isModal()) {
			if (b) {
				$("select").css("visibility", "hidden");
				$("#" + id + " select").css("visibility", "inherit");
			} else {
				var next = null;
				var zIndex = 0;
				for (var name in Dialog.instances) {
					if (!Dialog.instances.hasOwnProperty(name))
						continue;
					if (name != id && Dialog.get(name).isModal()
							&& Dialog.get(name).isVisible()) {
						var z = parseInt($("#" + name).css("zIndex"));
						if (z > zIndex) {
							zIndex = z;
							next = name;
						}
					}
				}
				var selector = next == null
						? "select"
						: ("#" + next + " select");
				$(selector).css("visibility", "inherit");
			}
		}

		// 处理定时关闭
		if (this.timer) {
			window.clearTimeout(this.timer);
			this.timer = null;
			$("#" + id + " .timeout").empty();
		}
		if (b && option.timeout != -1) {
			$("#" + id + " .timeout").empty().append(option.timeoutText
					.replace(/%s/i, option.timeout));
			this.timer = window.setTimeout(function() {
						Dialog.get(id).setVisible(false);
					}, option.timeout * 1000);
		}
	};

	/**
	 * 相对于可视区定位
	 * 
	 * @param {Number,
	 *            String} x 与可视区左侧(或右侧)的距离
	 * @param {Number,
	 *            String} y 与可视区顶部(或底部)的距离
	 */
	Dialog.prototype.setLocation = function(x, y, ref) {
		this.option.x = x = x + "";
		this.option.y = y = y + "";
		this.option.ref = ref || false;
		var elem = $("#" + this.id).get(0);
		var w = elem.offsetWidth;
		var h = elem.offsetHeight;
		var v = Dialog.getViewport();

		var left = this.option.fixed == "css" ? 0 : v.offsetX;
		if (x.substr(0, 1) == "*" && ref) {
			var s = x.substring(1);
			left = $(ref).offset().left + parseInt(s);
		} else if (x == "left")
			left = left;
		else if (x == "center")
			left += (v.width - w) / 2;
		else if (x == "right")
			left += v.width - w;
		else if (parseInt(x) < 0)
			left += v.width - w - Math.abs(parseInt(x)); // right
		else
			left += parseInt(x);
		if (this.option.fixed == "css" && $.browser.msie
				&& parseInt($.browser.version) == 6) { // IE6
			left -= 17; // TODO
			if (this.hasShadow())
				left -= this.option.shadow;
		}
		left = Math.max(parseInt(left), this.option.minX);

		var top = this.option.fixed == "css" ? 0 : v.offsetY;
		if (y.substr(0, 1) == "*" && ref) {
			var s = y.substring(1);
			top = $(ref).offset().top + parseInt(s);
		} else if (y == "top")
			top = top;
		else if (y == "middle" || y == "center")
			top += (v.height - h) / 2;
		else if (y == "bottom")
			top += v.height - h;
		else if (parseInt(y) < 0)
			top += v.height - h - Math.abs(parseInt(y)); // bottom
		else
			top += parseInt(y);
		top = Math.max(parseInt(top), this.option.minY);

		Dialog.setLocation(this.id, left, top);
	};

	/**
	 * 根据指定元素的位置进行定位
	 * 
	 * @param {Object}
	 *            selector 符合jquery的选择器的要求
	 */
	Dialog.prototype.attach = function(selector, x, y) {
		var id = this.id;
		if (!this.attachTo || this.attachTo != selector) {
			this.attachTo = selector;
			$(selector).click(function() {
						Dialog.get(id).toggle();
					});
		}
		this.option.x = x = x || 0;
		this.option.y = y = y || 0;
		var offset = $(selector).offset();
		var left = offset.left + x;
		var top = offset.top + $(selector).outerHeight() + y;
		Dialog.setLocation(id, left, top);
	};

	/**
	 * 可见返回 true, 否则返回 false
	 * 
	 * @return {Boolean} 可见返回 true, 否则返回 false
	 */
	Dialog.prototype.isVisible = function() {
		return $("#" + this.id).css("visibility") == "visible";
	};

	/**
	 * 在显示/隐藏之间切换
	 */
	Dialog.prototype.toggle = function(option) {
		if (this.isVisible())
			this.setVisible(false, option);
		else
			this.setVisible(true, option);
	};

	Dialog.prototype.resetLocation = function() {
		if (this.attachTo)
			this.attach(this.attachTo, this.option.x, this.option.y);
		else
			this.setLocation(this.option.x, this.option.y, this.option.ref);
	};
	Dialog.prototype.isModal = function() {
		return this.option.modal;
	};
	Dialog.prototype.hasShadow = function() {
		return this.option.shadow > 0;
	};
	Dialog.prototype.close = function() {
		var b;
		try {
			b = this.onclose();
		} catch (err) { // 在非IE浏览器中, 所有的错误都被捕获, 因此仅运行下面的代码
			b = true;
		} finally { // 在IE中, 不是所有的错误都被捕获. 所以在这种情况下检测变量是否没有被定义
			if ((typeof b) == "undefined") {
				alert("在 onclose 事件处理器的某个地方发生了错误");
				b = true;
			}
		}
		if (b) // 如果制定的事件处理器函数返回 true
			this.setVisible(false);
	};

	Dialog.instances = [];
	Dialog.zIndex = 10000;
	Dialog.option = {
		width : "400px", // 宽 px
		height : "280px", // 高 px
		x : "center", // 与可视区左则的距离 left|center|right|px
		y : "middle", // 与可视区顶部的距离 top|middle|bottom|px
		ref : false, // 位置参考元素
		minX : 0,
		minY : 0,
		css : "dialog-default",// 指定CSS class
		titlebar : false, // 是否产生标题栏 true|false
		scrolling : false, // 是否显示滚动条 true|false
		fixed : false, // 是否固定位置 true|false|"css" // FIXME: 使用css有问题
		wrapper : "wrapper", // 当 fixed 值为 "css" 时, 指定包装元素的id, 如果不存在就自动创建
		relocation : true, // 是否在显示前重定位 true|false
		modal : false, // 是否是模态窗口 true|false
		fastClose : false, // 是否点窗口任意地方可以关闭窗口 true|false
		shadow : 0
		// 阴影, 0为无阴影
	};
	Dialog.get = function(id) {
		return Dialog.instances[id];
	};
	Dialog.top = function(id) {
		if (Dialog.get(id).hasShadow())
			$("#" + id + "-shadow").css("zIndex", Dialog.zIndex++);
		$("#" + id).css("zIndex", Dialog.zIndex++);
	};
	Dialog.setLocation = function(id, left, top) {
		var d = Dialog.get(id);
		if (d.hasShadow()) {
			var shadow = d.option.shadow;
			var elem = $("#" + id).get(0);
			var v = Dialog.getViewport();
			if (left + elem.offsetWidth + shadow > v.offsetX + v.width)
				left -= shadow; // 调整 left
			if (top + elem.offsetHeight + shadow > v.offsetY + v.height)
				top -= shadow; // 调整 top
			$("#" + id + "-shadow").css({
						left : (left + shadow) + "px",
						top : (top + shadow) + "px"
					});
		}
		$("#" + id).css({
					left : left + "px",
					top : top + "px"
				});
	};

	/**
	 * 获得有关浏览器可视区的参数
	 * 
	 * @return {Object}
	 */
	Dialog.getViewport = function() {
		var v = {};
		var standardBody = (document.compatMode == "CSS1Compat")
				? document.documentElement
				: document.body; // 创建通用的跨 doctypes 的 "body" 的引用
		if (!$.browser.msie) { // 非 IE
			v.width = Math.min(standardBody.clientWidth, window.innerWidth); // 可视区宽度
			v.height = Math.min(standardBody.clientHeight, window.innerWidth); // 可视区高度
			v.offsetX = window.pageXOffset; // 可视区相对于文档左上角的水平位置(水平滚动条的位置)
			v.offsetY = window.pageYOffset; // 可视区相对于文档左上角的垂直位置(垂直滚动条的位置)
		} else { // IE
			v.width = standardBody.clientWidth;
			v.height = standardBody.clientHeight;
			v.offsetX = standardBody.scrollLeft;
			v.offsetY = standardBody.scrollTop;
		};
		v.pageWidth = Math.max(standardBody.offsetWidth,
				standardBody.scrollWidth); // 页面宽度
		v.pageHeight = Math.max(standardBody.offsetHeight,
				standardBody.scrollHeight); // 页面高度
		return v;
	};
	Dialog.getOverlaySize = function() {
		var v = Dialog.getViewport();
		var size = {
			width : v.pageWidth,
			height : v.pageHeight
		};
		if ($.browser.msie && parseInt($.browser.version) < 7) { // 修正 IE6
			// 滚动条问题
			if (v.pageWidth - v.width == 20)
				size.width -= 20;
			if (v.pageHeight - v.height == 4)
				size.height -= 4;
		}
		return size;
	};

	/**
	 * 移动
	 */
	Dialog.move = {
		init : function() {
			$(document).bind("mousedown", this.start);
		},
		start : function(event) {
			var e = event || window.event;

			// 事件发生在其上的文档结点(不一定是正在运行事件处理器的那个结点)
			var target = e.target || e.srcElement;
			if (!$(target).hasClass("move"))
				return true;

			// 向上查找父结点, 直到找到一个可拖拽的结点
			var ie = $.browser.msie;
			var topElement = (!ie) ? "HTML" : "BODY";
			while (target.tagName != topElement
					&& !$(target).hasClass("moveable")) {
				target = (!ie) ? target.parentNode : target.parentElement;
			}

			if ($(target).hasClass("moveable")) {
				var d = Dialog.move;
				d.target = target; // this = document
				d.initMouseX = e.clientX; // 保存 onmousedown 事件发生时鼠标的 x 坐标
				d.initMouseY = e.clientY;
				d.initX = parseInt(target.offsetLeft); // 保存 onmousedown
				// 事件发生时拖拽目标对象的 x 坐标
				d.initY = parseInt(target.offsetTop);
				$(document).bind("mousemove", d.moving).bind("mouseup", d.stop);
				return false;
			}
			return true;
		},
		moving : function(event) {
			var e = event || window.event;
			var d = Dialog.move;
			var target = d.target; // this = document
			d.distanceX = e.clientX - d.initMouseX; // 相对于起始点移动的水平距离
			d.distanceY = e.clientY - d.initMouseY;
			var left = d.distanceX + d.initX;
			var top = d.distanceY + d.initY;

			// 限制在页面已有范围内移动
			var w = target.offsetWidth;
			var h = target.offsetHeight;
			var v = Dialog.getViewport();
			if (left < 0)
				left = 0;
			else if ((left + w) > v.pageWidth)
				left = v.pageWidth - w;
			if (top < 0)
				top = 0;
			else if ((top + h) > v.pageHeight)
				top = v.pageHeight - h;

			Dialog.setLocation(target.id, left, top);
			return false; // 取消默认的 moving 行为
		},
		stop : function(event) {
			// 清理
			var d = Dialog.move;
			d.target = null; // this = document
			$(document).unbind("mousemove", d.moving).unbind("mouseup", d.stop);
		}
	};
	Dialog.move.init();

	// ImageResize
	// -----------------------------------------------------------------
	/**
	 * 重新调整图片大小
	 */
	var ImageResize = {
		bind : function(selector, option) {
			$(document).ready(function() {
						$(selector).each(function(index, domElement) {
									this; // this == domElement
									if (this.complete == true) {
										ImageResize.resize(this, option);
									} else {
										this.onload = function() {
											ImageResize.resize(this, option);
										};
									}
								});
					});
		},
		resize : function(imgElem, option) {
			option = option || {};
			var _option = {
				maxWidth : -1,
				maxHeight : -1,
				wrap : false
			};
			for (var name in _option) {
				if (!(name in option))
					option[name] = _option[name];
			}

			var img = new Image();
			img.src = imgElem.src;
			if (img.width < 0 || img.height < 0)
				return;
			if ($.browser.msie) { // for IE
				if (img.width == 0 || img.height == 0) {
					window.setTimeout(function() {
								ImageResize.resize(imgElem, option);
							}, 1000); // 1秒后再次尝试
					return;
				}
				imgElem.onload = null; // 重要!
			}

			var iwidth = imgElem.width;
			var iheight = imgElem.height
			if (option.maxWidth > 0)
				iwidth = Math.min(iwidth, option.maxWidth);
			if (option.maxHeight > 0)
				iheight = Math.min(iheight, option.maxHeight);
			if (iwidth <= 0 || iheight <= 0) {
				return;
			}

			var h, w;
			if (img.width / img.height >= iwidth / iheight) {
				if (img.width > iwidth) {
					w = iwidth;
					h = (img.height * iwidth) / img.width;
				} else {
					w = img.width;
					h = img.height;
				}
			} else {
				if (img.height > iheight) {
					h = iheight;
					w = (img.width * iheight) / img.height;
				} else {
					w = img.width;
					h = img.height;
				}
			}

			$(imgElem).css({
						width : w + "px",
						height : h + "px"
					});
			if (!option.wrap)
				return;

			var top = Math.floor((iheight - h) / 2);
			var left = Math.floor((iwidth - w) / 2);
			var divCssClasses = imgElem.className || "";
			$(imgElem).css({
						position : "relative",
						top : top + "px",
						left : left + "px",
						className : ""
					}).attr("className", "");
			var str = "<div class='" + divCssClasses
					+ "' style='text-align:left;width:" + iwidth + "px;height:"
					+ iheight + "px;'></div>";
			var parentElem = $(imgElem).parent().get(0);
			if (parentElem.tagName == "A")
				$(parentElem).wrap(str);
			else
				$(imgElem).wrap(str);
		}
	};
	// CascadedSelect
	// --------------------------------------------------------------
	function CascadedSelect(cfg, data) {
		var level = 0;
		this.create(level, cfg, data, true);
	}
	CascadedSelect.prototype.create = function(level, cfg, data, init) {
		init = init || false;
		for (var i = level; i < cfg.length; i++) {
			$(cfg[i].selector).html("");
		}
		var elem = $(cfg[level].selector).get(0);
		this.createTip(elem, cfg[level].tipValue, cfg[level].tipText);
		if (data) {
			if (init) {
				var retData = this.createOptions(elem, data,
						cfg[level].selectedValue);
				if (retData != null && level < cfg.length - 1)
					this.create(level + 1, cfg, retData, true);
			} else {
				this.createOptions(elem, data);
			}
		}
		var _this = this;
		if (level < cfg.length - 1) {
			elem.onchange = function() {
				var selectedOption = this.options[this.selectedIndex];
				if ("childrenData" in selectedOption) {
					var data = selectedOption.childrenData;
				} else {
					var data = null;
				}
				_this.create(level + 1, cfg, data);
			};
		}
	};
	CascadedSelect.prototype.createTip = function(elem, tipValue, tipText) {
		var option = document.createElement("option");
		option.value = tipValue;
		option.innerHTML = tipText;
		elem.appendChild(option);
	};
	CascadedSelect.prototype.createOptions = function(elem, data, selectedValue) {
		selectedValue = selectedValue || null;
		var childrenData = null;
		for (var i = 0; i < data.length; i++) {
			option = document.createElement("option");
			option.value = data[i].value;
			option.innerHTML = data[i].text;
			option.childrenData = data[i].children;
			if (selectedValue == data[i].value) {
				option.setAttribute("selected", "selected");
				childrenData = data[i].children;
			}
			elem.appendChild(option);
		}
		return childrenData;
	};
	// dhtmlxCalendarObject
	// --------------------------------------------------------
	if (window.dhtmlxCalendarObject) {
		var dhtmlxCalendarLangModules = new Array();
		dhtmlxCalendarLangModules['zh-cn'] = {
			langname : 'zh-cn',
			dateformat : '%Y-%m-%d',
			monthesFNames : ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月",
					"九月", "十月", "十一月", "十二月"],
			monthesSNames : ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月",
					"九月", "十月", "十一月", "十二月"],
			daysFNames : ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
			daysSNames : ["日", "一", "二", "三", "四", "五", "六"],
			weekend : [0, 6],
			weekstart : 0,
			msgClose : "关闭",
			msgMinimize : "最小化",
			msgToday : "今天",
			msgClear : "清除"
		};
		function attachCalendar(selector, option) {
			option = option || {};
			var currentYear = new Date().getFullYear();
			var _option = {
				x : null,
				y : null,
				minYear : currentYear - 2,
				maxYear : currentYear + 2,
				skin : "default"
			};
			for (var name in _option) {
				if (!(name in option))
					option[name] = _option[name];
			}

			$(selector).each(function(index, domElement) {
				var div = document.createElement("div");
				div.style.display = "none";
				document.body.appendChild(div);
				var cal = new dhtmlxCalendarObject(div, false, {
							isYearEditable : true,
							isMonthEditable : true
						});
				cal.draw();
				cal.setSkin(option.skin);
				cal.loadUserLanguage("zh-cn");
				cal.setYearsRange(option.minYear, option.maxYear);
				if (this.value != "" && isDate(this.value, "yyyy-MM-dd"))
					cal.setDate(this.value);
				cal.attachEvent("onClick", function(date) {
							domElement.value = this.getFormatedDate("%Y-%m-%d",
									date);
							this.hide();
							return true;
						});
				$(this).bind("click", function() {
					if (cal.isVisible()) {
						cal.hide();
					} else {
						var x = (option.x == null)
								? $(this).outerWidth()
								: option.x;
						var y = (option.y == null) ? 0 : option.y;
						var offset = $(this).offset();
						cal.setPosition(offset.top + y, offset.left + x);
						cal.show();
					}
				}).bind("change", function() {
					if (this.value != "" && isDate(this.value, "y-M-d")) {
						this.value = formatDate(parseDate(this.value, "y-M-d"),
								"yyyy-MM-dd");
						cal.setDate(this.value);
					}
				});
			});
		} // end function
	} // end if (window.dhtmlxCalendarObject)

} // end if (window.jQuery)

// 提交用户表单
function goActionWithTarget(index, action, target) {
	var myForm = document.forms[index];
	myForm.action = action;
	if (target.length != 0) {
		myForm.target = target;
	}
	myForm.submit();
}

function goActionWithTargetAppendMessate(index, action, target, message) {
	var myForm = document.forms[index];
	myForm.action = action;
	if (target.length != 0) {
		myForm.target = target;
	}
	if(window.confirm(message)) {
		myForm.submit();
	}else {
		return;
	}
}


function pageGoAction(index, para) {
  var myForm = document.forms[index];
  myForm.action += para;
  myForm.target = '_self';
  myForm.submit();
}
/*
 * ====================================== 功能：全选或全部取消checkBox 参数：checkBoxObj:
 * 被全选或取消的checkBox控件对象 functionBox: 发生事件的checkBox控件 例：<input type="checkbox"
 * name="all" onclick="checkAll(document.all.ids,this);"> author: carroll
 * ======================================
 */
function checkAll(checkBoxObj,functionBox){
    if(functionBox.checked){
        choiceAll(checkBoxObj);
    }else{
        deselect(checkBoxObj);
    }
}

// 设置checkbox全选
// author carroll
function choiceAll(checkBoxObj){
        
    if(checkBoxObj != null){
        if(checkBoxObj.length == null){
        	if(checkBosObj.disabled != true)
        		checkBoxObj.checked = true;
        }else{
            for(var i=0; i < checkBoxObj.length; i++){
            	//alert(checkBoxObj[i].disabled);
            	if(checkBoxObj[i].disabled != true)
            		checkBoxObj[i].checked = true;
            }
        }
        
    }else{
        alert("No items can be choice!");
        return;
    }
}

// 设置checkbox全部取消
// author carroll
function deselect(checkBoxObj){
  
    if(checkBoxObj !=null){
        if(checkBoxObj.length == null){
            checkBoxObj.checked = false;
        }else{
            for(var i = 0; i < checkBoxObj.length; i++){
                checkBoxObj[i].checked = false;
            }
        }
        
    }else{
        alert('No items can be cancel!');
    }
    
}

// 判断在多选的checkbox是否有选中，如果有则返回true，否则返回false
// auth kang
function checkboxvalidate(checkboxobj) {
 var isCheck=false;
	if(checkboxobj !=null ){
		if(checkboxobj.length==null && checkboxobj.checked) {
			isCheck = true;
		}else{
			for(i=0;i<checkboxobj.length;i++){
				if(checkboxobj[i].checked)
					isCheck = true;
			}
		}
	}
	return isCheck;
}

function goActionWithTargetByCustomIDs(index,action,target,ids){
	  var myForm = document.forms[index];
	  if( checkboxvalidate(ids) ) {
	      if( confirm("您确定要操作所选的项目吗？") ) {
	          if(myForm.current!=null) {
	              myForm.current.value = 1;
	          }
	          goActionWithTarget(index,action,target);
	      }
	  }else{
	      alert('没有可以操作的项目！');
	  }
}

