
function openWindow(url, left, top, width, height) {
	var param = "height=" + height + "px,width=" + width + "px,left=" + left + "px,top=" + top + "px,resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no";
	window.open(url, "", param);
}
function openDiv(element_id) {
	var theElement = document.getElementById(element_id);
	if (theElement) {
		theElement.style.display = "block";
	}
}
function closeDiv(element_id) {
	var theElement = document.getElementById(element_id);
	if (theElement) {
		theElement.style.display = "none";
	}
}
function openPopup(url, width, height) {
	openWindow(url, 150, 100, width, height);
}
function selectCategory(id_1, id_2) {
	openWindow("/script/systemGroup/select.jsp?sysGroupId=" + id_1 + "&sysGroupName=" + id_2, 150, 100, 700, 620);
}
function selectRootCategory(id_1, id_2) {
	openWindow("/script/systemGroup/rootCatalogSelect.jsp?sysGroupId=" + id_1 + "&sysGroupName=" + id_2, 150, 100, 700, 620);
}
function selectCategoryMulitple(select_id, userType) {
	openWindow("/script/systemGroup/selectMore.jsp?sysGroupId=" + select_id + "&type=" + userType, 150, 100, 700, 620);
}
function selectCategoryMulitpleDiv(select_id) {
	openWindow("/script/systemGroup/selectMore.jsp?sysGroupId=" + select_id + "&type=10&action=div", 150, 100, 700, 620);
}
function removeCategory(id_1, id_2) {
	document.getElementById(id_1).value = "";
	document.getElementById(id_2).value = "";
}
function removeOption(select_id) {
	var select = document.getElementById(select_id);
	if (!select || select.length < 1) {
		return;
	}
	if (select.selectedIndex == -1) {
		select.options[0].selected = true;
	}
	for (var index = 0; index < select.length; index++) {
		if (select.options[index].selected) {
			select.remove(index);
		}
	}
	if (select.length < 1) {
		return;
	}
	if (select.selectedIndex >= (select.length - 1) && select.length >= 1) {
		select.options[0].selected = true;
	} else {
		select.options[select.selectedIndex + 1].selected = true;
	}
}
/**
 * 选中所有复选框
 */
function chooseAllCheckbox(checkboxName, boolean) {
	for (var i = 0; i < document.getElementsByName(checkboxName).length; i++) {
		if (document.getElementsByName(checkboxName)[i].type == "checkbox") {
			document.getElementsByName(checkboxName)[i].checked = boolean;
		}
	}
}
/**
 * 检测是否至少选中了一个复选框
 */
function isChecked(checkboxName) {
	var checked = false;
	var boxs = document.getElementsByName(checkboxName);
	for (var i = 0; i < boxs.length; i++) {
		if (boxs[i].type == "checkbox" && boxs[i].checked) {
			checked = true;
			break;
		}
	}
	return checked;
}
/**
 * 文本框字符长度统计限制
 */
function textLimitCheck(thisArea, showArea, maxLength) {
	if (thisArea.value.length > maxLength) {
		alert(maxLength + " characters limit. \r Excessive data will be truncated.");
		thisArea.value = thisArea.value.substring(0, maxLength - 1);
		thisArea.focus();
	}
	showArea.value = thisArea.value.length;
}
/**
 * 进入询盘Email发送页面
 * @param basket_item_type - 购物栏item类型
 * @param basket_item - 购物栏item值
 */
function singleInquiryNow(basket_item_type, basket_item) {
	document.SingleInquiryForm.action = "/inquiry.html";
	document.SingleInquiryForm.from_type.value = "from_type_single";
	document.SingleInquiryForm.basket_item_type.value = basket_item_type;
	document.SingleInquiryForm.basket_item.value = basket_item;
	document.SingleInquiryForm.submit();
}
function singleProductInquiry(basket_item) {
	singleInquiryNow("basket_item_product", basket_item);
}
function singleTradeInquiry(basket_item) {
	singleInquiryNow("basket_item_trade", basket_item);
}
function singleCompanyInquiry(basket_item) {
	singleInquiryNow("basket_item_company", basket_item);
}
/**
 * 添加item到购物篮中
 */
function addBasket(basket_item_type) {
	if (!isChecked("basket_item")) {
		alert("No item(s) selected");
	} else {
		document.InquiryForm.action = "/inquiry-basket/addItems.html";
		document.InquiryForm.basket_item_type.value = basket_item_type;
		document.InquiryForm.submit();
	}
}
function addProductToBasket() {
	addBasket("basket_item_product");
}
function addTradeToBasket() {
	addBasket("basket_item_trade");
}
function addCompanyToBasket() {
	addBasket("basket_item_company");
}
/**
 * 将当前的信息添加到收藏夹，兼容IE和firefox
 *
 * @param title string 添加到收藏夹中本条标签的名字
 * @param url string 收藏的地址
 */
function addBookMark(title, url) {
	if (window.sidebar) {
		window.sidebar.addPanel(title, url, "");
	} else {
		if (window.external) {
			window.external.AddFavorite(url, title);
		} else {
			return true;
		}
	}
}
/**
 * 调节图片的长度和宽度做限制,自定义高宽
 * 长度和宽度哪个超出就限制哪个，如果都不超出则原尺寸
 * img src="image" onload="setImgWH(this.src,this,imgW,imgH)"
 * @param theURL  - img 地址
 * @param sImage  - img object
 * @param imgW  - 限制宽度
 * @param imgH  - 限制高度
 */
function setImgWH(theURL, sImage, imgW, imgH) {
	var imgObj;
	imgObj = new Image();
	imgObj.src = theURL;
	if ((imgObj.width != 0) && (imgObj.height != 0)) {
		if (imgObj.width >= imgW || imgObj.height >= imgH) {
			var iHeight = imgObj.height * imgW / imgObj.width;
			if (iHeight <= imgH) {
				sImage.width = imgW;
				sImage.height = iHeight;
			} else {
				var iWidth = imgObj.width * imgH / imgObj.height;
				sImage.width = iWidth;
				sImage.height = imgH;
			}
		} else {
			sImage.width = imgObj.width;
			sImage.height = imgObj.height;
		}
	} else {
		sImage.width = imgW;
		sImage.height = imgH;
	}
}
function tqopen(url) {
	var params = "height=440,width=592,left=150px,top=80px,resizable=yes,scrollbars=no,status=no,toolbar=no,menubar=no,location=no";
	window.open(url, "", params);
}
function tqchat(tqId) {
	tqopen("http://webchat.tq.cn/sendmain.jsp?uin=" + tqId + "&ltype=100&agentid=1012160&tq_right_infocard_url=http://www.hisupplier.com/tq/infocard");
}
function tqleavemsg(tqId) {
	tqopen("http://qtt.tq.cn/leavemsg.do?agentid=1012160&uin=" + tqId + "&ltype=100&page=http3A//www.thldl.org.cn/courses/html/1564.html&ispaymoney=1&localurl=http://qtt.tq.cn");
}
/**
 * 图片循环滚动类 
 * 用例:	
 *	首先 <script type="text/javascript">
 * 			slidePhoto.load("1.jpg,2.jpg,3.jpg");
 *		</script> 
 *	然后 <body onload="imgSlidePhoto.run()">;
 */
ImgSlidePhoto = new function () {
	var timeout = 2000;				// 延时2秒
	var images = new Array();	// 滚动的图片组
	var index = 0;		// 当前图片索引
	this.run = function () {
		var imgObj = document.getElementById("showPhoto");
		if (!imgObj || images.length <= 0) {
			return;
		}
		imgObj.src = images[index].src;
		index++;
		if (index >= images.length) {
			index = 0;
		}
		if (images.length > 1) {
			setTimeout("ImgSlidePhoto.run()", timeout);
		}
	};
	this.load = function (str) {
		if (str == null || str == "") {
			return;
		}
		var array = str.split(",");
		for (var i = 0; i < array.length; i++) {
			var img = new Image();
			img.src = array[i];
			images.push(img);
		}
	};
};
function XHTMLDecode(str) {
	if (isEmpty(str)) {
		return "";
	}
	str = str.replace(/\&amp;/g, "&");
	str = str.replace(/\&lt;/g, "<");
	str = str.replace(/\&gt;/g, ">");
	str = str.replace(/\&apos;/g, "'");
	str = str.replace(/\&quot;/g, "\"");
	str = str.replace(/\&nbsp;/g, " ");
	return str;
}
function setImgWHMin(img) {
	setImgWH2(img, 100, 100);
}
function setImgWHMinForAd(img) {
	setImgWH2(img, 75, 75);
}
function setImgWH2(img, imgW, imgH) {
	var imgObj;
	imgObj = new Image();
	imgObj.src = img.src;
	if ((imgObj.width != 0) && (imgObj.height != 0)) {
		if (imgObj.width >= imgW || imgObj.height >= imgH) {
			var iHeight = imgObj.height * imgW / imgObj.width;
			if (iHeight <= imgH) {
				img.width = imgW;
				img.height = iHeight;
			} else {
				var iWidth = imgObj.width * imgH / imgObj.height;
				img.width = iWidth;
				img.height = imgH;
			}
		} else {
			img.width = imgObj.width;
			img.height = imgObj.height;
		}
	} else {
		img.width = imgW;
		img.height = imgH;
	}
}
