//根据值选择下拉列表
selectOption = function (name, v) {
	var select = document.getElementsByName(name);
	if (select) {
		for (var i = 0; i < select[0].options.length; ++i) {
			if (v == select[0].options[i].value) {
				select[0].options[i].selected = true;
			}
		}
	}
};
//循环根据值选择下拉列表 ay1-名数组|ay2-值数组
selectOptions = function (ay1, ay2) {
	if (ay1.length == ay2.length) {
		for (var i = 0; i < ay1.length; ++i) {
			selectOption(ay1[i], ay2[i]);
		}
	}
};
//显示或隐藏指定的对象(根据对象id)
displayTab = function (id) {
	var obj = document.getElementById(id);
	if (obj) {
		displayTabObj(obj);
	}
};
//显示或隐藏指定的对象(根据对象)
displayTabObj = function (obj) {
	var status = obj.style.display;
	if ("none" == status) {
		obj.style.display = "";
	} else {
		obj.style.display = "none";
	}
};
//显示或隐藏指定的对象数组
displayTabs = function (ids) {
	for (var i = 0; i < ids.length; ++i) {
		displayTab(ids[i]);
	}
};

//文件域图片预览
prv_preview = function (fileObj) {
	var preview = document.getElementById("preview");
	var imgObjUrl = getFullPath(fileObj);
	if (imgObjUrl != "") {
		preview.innerHTML = "<img id=\"imgObj\" src=\"" + imgObjUrl + "\" width=\"300\" height=\"300\" />";
	}
};
//缩小预览
prv_preview_ratio_change = function () {
	var imgObj = document.getElementById("imgObj");
	var ratio = document.getElementById("ratio");
	imgObj.style.width = (300 * (ratio.value)) + "px";
	imgObj.style.height = (300 * (ratio.value)) + "px";
};
//关闭预览
prv_close = function () {
	var prv_win = document.getElementById("prv_win");
	var pic = document.getElementById("imgObj");
	if (prv_win && pic) {
		prv_win.removeChild(pic);
		prv_win.parentNode.removeChild(prv_win);
	}
};
//获取预览对象
getObjPreview = function (fileObj) {
	var imgObjUrl = getFullPath(fileObj);
	if (imgObjUrl != "") {
		var left = fileObj.offsetLeft;
		var top = fileObj.offsetTop;
		var id = "prv_win";
		var div = document.getElementById(id);
		if (!div) {
			div = document.createElement("div");
			div.id = id;
			document.body.appendChild(div);
		}
		var imgObj = document.createElement("img");
		imgObj.id = "imgObj";
		imgObj.src = imgObjUrl;
		imgObj.style.width = "500px";
		imgObj.style.height = "500px";
		div.appendChild(imgObj);
		displayTabObj(div);
		return div;
	} else {
		return null;
	}
};
//从文件域中获取文件路径
getFullPath = function (obj) {
	if (obj) {
		if (window.navigator.userAgent.indexOf("MSIE") >= 1) {
			obj.select();
			return document.selection.createRange().text;
		} else {
			if (window.navigator.userAgent.indexOf("Firefox") >= 1) {
				if (obj.files) {
					if (obj.files.item(0)) {
						return obj.files.item(0).getAsDataURL();
					}
				}
				return obj.value;
			}
		}
		return obj.value;
	}
};
//设置浮动窗口的高度
setWinHeight = function (obj) {
	var id = obj.id;
	var subWeb = document.frames ? document.frames[id].document : obj.contentDocument;
	if (obj != null && subWeb != null) {
		obj.height = subWeb.body.scrollHeight;
	}
};
//复制
copy = function (content) {
	if (window.clipboardData) {
		window.clipboardData.clearData();
		window.clipboardData.setData("Text", content);
	} else {
		if (navigator.userAgent.indexOf("Opera") != -1) {
			window.location = content;
		} else {
			if (window.netscape) {
				try {
					netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
				}
				catch (e) {
					alert("\u88ab\u6d4f\u89c8\u5668\u62d2\u7edd\uff01\n\u8bf7\u5728\u6d4f\u89c8\u5668\u5730\u5740\u680f\u8f93\u5165'about:config'\u5e76\u56de\u8f66\n\u7136\u540e\u5c06 'signed.applets.codebase_principal_support'\u8bbe\u7f6e\u4e3a'true'");
				}
				var clip = Components.classes["@mozilla.org/widget/clipboard;1"].createInstance(Components.interfaces.nsIClipboard);
				if (!clip) {
					return;
				}
				var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
				if (!trans) {
					return;
				}
				trans.addDataFlavor("text/unicode");
				var str = new Object();
				var len = new Object();
				var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
				var copytext = content;
				str.data = copytext;
				trans.setTransferData("text/unicode", str, copytext.length * 2);
				var clipid = Components.interfaces.nsIClipboard;
				if (!clip) {
					return false;
				}
				clip.setData(trans, null, clipid.kGlobalClipboard);
				alert("\u5df2\u590d\u5236\u5230\u526a\u5207\u677f");
			}
		}
	}
};
subLen = function (str, size) {
	var l = str.length;
	if (l >= size) {
		return str.substring(0, size) + "...";
	} else {
		return str;
	}
};
calculateSize = function (l) {
	var str;
	if (l < (1024 * 1024)) {
	    l=(l / 1024);
		str = formatFloat(l,2) + "KB";
	} else {
	    l=l / (1024 * 1024);
		str = formatFloat(l,2) + "MB";
	}
	return str;
}

formatFloat=function(src, pos) {
   return Math.round(src*Math.pow(10, pos))/Math.pow(10, pos);
}


