﻿//鼠标经过提示
//使用 document.onmousemove = titleEffect;
function titleEffect(e) {
	e = e || event;
	var element = e.srcElement || e.target;
	var body = document.body;
	var tip = document.getElementById("tip-div");
	if (!tip) {
		tip = document.createElement("div");
		tip.id = "tip-div";
		with (tip.style)
		{
			display = "none";
			position = "absolute";
			left = "0";
			top = "0";
			zIndex = 9999999; // 一个足够大的数，保证层会处于最上层
		}
		body.appendChild(tip);
	}

	var title = element.getAttribute("title") || element.getAttribute("_title");
	if (!title) return (tip.style.display=="block") && (tip.style.display="none");
	if (element.getAttribute("title")) {
		element.setAttribute("title", "");
		element.setAttribute("_title", title);
	}

	tip.style.display = "block";

	if (tip.innerHTML == title) return ;
	else tip.innerHTML = title;

	var left = body.scrollLeft + e.clientX + 10;
		left = (left>body.clientWidth-tip.clientWidth) ? (left-tip.clientWidth) : left;
	var top = body.scrollTop + e.clientY + 10;
		top = (top>body.clientHeight-tip.clientHeight) ? (top-tip.clientHeight) : top;
	tip.style.left = left + "px";
	tip.style.top = top + "px";
}




function checkLocation(objPathID, varNowTitle) {
	try {
		var Path = document.getElementById(objPathID);
		var a = Path.getElementsByTagName("a");
		var str = "";
		if (a.length > 1) {
			for(var i=2; i<a.length; i++) {
				str += "&nbsp;→&nbsp;<a href=\"" + a[i].href + "\" title=\"" + a[i].innerHTML + "\">" + a[i].innerHTML + "</a>"
			}
		}
		if (a.length > 0) {
			str = "<a href=\"" + a[1].href + "\" title=\"" + a[1].innerHTML + "\">首页</a>" + str + "&nbsp;→&nbsp;";
		}
		Path.innerHTML = str + varNowTitle;
	}
	catch (e) {
	}
}

function checkComment(Obj, name, min, max) {
	if (Obj.value.length < min) {
		alert('您输入的' + name + '为空或者太少！');
		return false;
	}
	if (Obj.value.length > max) {
		alert(name + '不能大于 ' + max + ' 字符！');
		return false;
	}
	return true;
}




function ShowListIndex(listID,itemTag,indexID,varCount) {
	try {
		var varPage = parseInt(0 + location.search.replace("?", ""));
		var List = document.getElementById(listID);
		var arrItem = List.getElementsByTagName(itemTag);

		if (arrItem.length < 1) {
			return false;
		}

		varCount = parseInt(varCount);
		if (varCount < 1) {
			varCount = 5
		}

		var MaxPage = Math.ceil(arrItem.length / varCount);

		if (MaxPage > 1) {
			var strIndex = "";

			if (varPage > MaxPage) {
				varPage = MaxPage
			}

			if (varPage < 1) {
				varPage = 1
			}

			var maxID = varPage * varCount
			var minID = varPage * varCount - varCount

			for (var i = 0; i < arrItem.length; i++) {
				if (i < maxID && i >= minID) {
					arrItem[i].style.display = ""
				} else {
					arrItem[i].style.display = "none"
				}
			}

			if (varPage > 1) {
				strIndex += "<a href=\"?" + (varPage - 1) + "."  + Math.random() + "\" style=\"font-family:Webdings\">3</a>"
			}
			for (var i = 1; i <= MaxPage; i++) {
				if (varPage == i) {
					strIndex += "<strong>" + i + "</strong>"
				} else {
					strIndex += "<a href=\"?" + i + "."  + Math.random() + "\">" + i + "</a>"
				}
			}

			if (varPage < MaxPage) {
				strIndex += "<a href=\"?" + (varPage + 1) + "."  + Math.random() + "\" style=\"font-family:Webdings\">4</a>"
			}

			var objIndex = document.getElementById(indexID);
			objIndex.innerHTML = strIndex;
		}
	}
	catch (e) {
	}
}


//=======================================================================
// Firefox 没有 outerHTML,必须添加以下代码使之存在此属性
var setOuterHtml = function(s){
   var range = this.ownerDocument.createRange();
   range.setStartBefore(this);
   var fragment = range.createContextualFragment(s);
   this.parentNode.replaceChild(fragment, this);
};

if(window.HTMLElement) {
  HTMLElement.prototype.__defineSetter__("outerHTML", setOuterHtml);
}
//=======================================================================

/* 加入收藏夹 */
function favorite(title, url) {
	if (!title) {
		title = document.title;
	}
	if (!url) {
		url = location.href;
	}

	if (window.sidebar) {
		// firefox
		window.sidebar.addPanel(title, url, "");
	} else {
		if (window.opera && window.print) {
			// opera
			var elem = document.createElement('a');
			elem.setAttribute('href',url);
			elem.setAttribute('title',title);
			elem.setAttribute('rel','sidebar');
			elem.click();
		} else {
			if (document.all) {
				// ie
				window.external.AddFavorite(url, title);
			}
		}
	}
}


function copyUrl(info) {
	window.clipboardData.setData("text",info);
	alert("链接已经复制，您可以直接粘贴!");
}


// 自动处理指定对象中的缩略图
// objID	对象名称的ID
// rWidth	要调整后的宽度
// dHeight	对高度间隔的要求
function ResizeImg(objID, rWidth, dHeight) {
	var obj = GetID(objID);
	if (typeof(obj) == "object") {
		var ObjImg = GetTag("img", obj)
		var h;
		for (var i=0; i<ObjImg.length; i++)
		{
			var img = ObjImg[i];
			if (img.width > rWidth)
			{
				/*
				h = Math.floor(img.height * rWidth / img.width);
				if (dHeight > 0)
				{
					h = h - h % dHeight;
				}
				img.outerHTML = "<a href=\"" + img.src + "\" title=\"" + img.alt + "\" target=\"_blank\"><img src=\"" + img.src + "\" style=\"height:" + h + "px;\" alt=\"" + img.alt + "[点击查看大图]\" border=\"0\" /></a>";
				*/
				//img.outerHTML = "<a href=\"" + img.src + "\" title=\"" + img.alt + "\" target=\"_blank\"><img src=\"" + img.src + "\" style=\"width:" + h + "px;\" alt=\"" + img.alt + "[点击查看大图]\" border=\"0\" /></a>";
				img.style.width = rWidth + "px";
			}
			else
			{
				img.outerHTML = "<img src=\"" + img.src + "\" alt=\"" + img.alt + "\" border=\"0\" />";
			}
		}
	}
}


//===============================================================================
function GetID(id, obj) {
	if (!obj) {
		obj = document
	}
	return obj.getElementById(id);
}

function GetName(name, obj) {
	if (!obj) {
		obj = document
	}
	return obj.getElementsByName(name);
}


function GetTag(tag, obj) {
	if (!obj) {
		obj = document
	}
	return obj.getElementsByTagName(tag);
}

function OutStr(obj, val) {
	var e = GetID(obj);
	if (e) {
		e.innerHTML = val;
	}
}


//显示选项卡的初始项目，用于多个 Div 组成选项内容卡
function ShowIndexCardID(ID, objName) {
	var ObjIndex;
	var ObjHead = new Array();
	var ObjBody = new Array();
	var n = 0;
	var b = 0;

	ObjIndex = document.getElementById(objName).getElementsByTagName("div");

	for (var i = 0; i < ObjIndex.length; i ++) {
		if (ObjIndex[i].className == "enabled" || ObjIndex[i].className == "disabled" ) {
			ObjHead[b] = ObjIndex[i]
			ObjHead[b].className = "disabled"
			b++;
		}
		//if (ObjIndex[i].className == "body") {
		if (ObjIndex[i].className.indexOf("body") == 0) {
			ObjIndex[i].style.display = "none";
			ObjBody[n] = ObjIndex[i]
			n++;
		}
	}
	if (ID>n) {
		return false;
	} else if (ObjHead[ID].className == "enabled") {
		return false;
	} else {
		ObjHead[ID].className = "enabled"
		ObjBody[ID].style.display = "";
	}
}
