﻿function listItem_mouseOver(obj)
{
	obj.className = "mouseover";
}
function listItem_mouseOut(obj)
{
	obj.className = "mouseout";
}
function SelectOne(obj) {
	var es = document.getElementsByTagName("input");
	for (var i = 0; i < es.length; i++) {
		var e = es[i];
		if (e.type == "checkbox") {
			if (e.id == obj.id)
				e.checked = obj.checked;
			else
				e.checked = false;
		}
	}
}
function SelectAll()
		{
		var es = document.all.tags("input") ;
				for (var i=0;i<es.length;i++)
				{
					var e = es[i];
					if (e.type=="checkbox")
					{	
						    e.checked=true;  
					}
				}
		}
function ClearAll()
		{
		var es = document.all.tags("input") ;
				for (var i=0;i<es.length;i++)
				{
					var e = es[i];
					if (e.type=="checkbox")
					{	
						    e.checked=!e.checked;
					}
				}
		}


// 取得元素内部的 Checkbox
// element 包含 Checkbox 的元素，当为 string 时代表该元素的ID
// idContain Checkbox 控件的 ID 必须包含的字符
function GetInnerCheckbox(element, idContain)
{
	var checkBoxs = new Array();
	
	try
	{
		if( typeof(element) == "string" ) element = document.getElementById(element);		// 如果提供的参数 element 为字符串则当成元素的 ID，用以取得元素。		
		var es = element.getElementsByTagName("INPUT");
		for( var i = 0; i < es.length; i++ )
		{
			var e = es[i];
			if ( e.type=="checkbox" )
			{
				if ( idContain )		// 如果 idContain 存在则当 Checkbox 控件的 ID 必须包含 idContain 才进行操作。
				{
					if ( !e.id || e.id.indexOf( idContain ) == -1 );
						continue;
				}
				
				checkBoxs[checkBoxs.length] = e;
			}
		}
	}
	catch(e){alert("运行时错误，请与管理员联系！");}
	
	return checkBoxs;
}

// 全部选择某个元素内的 Checkbox 控件
// element 包含进行选择的 Checkbox 的元素，当为 string 时代表该元素的ID
// idContain Checkbox 控件的 ID 必须包含的字符
function SelectAllInner(element, idContain)
{
	selectAll( GetInnerCheckbox(element, idContain) );
}

// 反向选择某个元素内的 Checkbox 控件
// element 包含进行选择的 Checkbox 的元素，当为 string 时代表该元素的ID
// idContain Checkbox 控件的 ID 必须包含的字符
function SelectReverseInner(element, idContain)
{
	selectReverse( GetInnerCheckbox(element, idContain) );
}

		
function selectAll(obj)
{
	try
	{
		if(obj)
		{
			var i;
			if(typeof(obj.length) == "undefined")
				obj.checked = true;
			else
			{
				for(i = 0; i < obj.length; i++)
					obj[i].checked = true;
			}
		}
	}
	catch(e){alert("运行时错误，请与管理员联系！");}
}

function selectReverse(obj)
{
	try
	{
		if(obj)
		{
			var i;
			if(typeof(obj.length) == "undefined")
				obj.checked = !obj.checked;
			else
			{
				for(i = 0; i < obj.length; i++)
					obj[i].checked = !obj[i].checked;
			}
		}
	}
	catch(e){alert("运行时错误，请与管理员联系！");}
}

function runConfirm(cue, action, actionType, target, form)
{
	//try
	//{
		if(cue)
		{
			if(confirm(cue))
				letGo();
		}
		else
			letGo();
	//}
	//catch(e){alert("运行时错误，请与管理员联系！");}
	
	function letGo()
	{
		if(actionType == "form")
		{
			form.action = action;
			if(target) form.target = target;
			form.submit();
		}
		else if(actionType == "script")
			eval(action);
		else
		{
			if(target == "_top")
				window.top.location.href = action;
			else if(target == "_parent")
				window.parent.location.href = action;
			else if(target == "_blank")
				window.open(action);
			else
				window.location.href = action;
				
		}
	}
}


function SubmitPreview(form, action, target)
{
	if( typeof(form) == "string" ) form = document.getElementById(form);
	
	try
	{
		var _action, _target;
		// 保存表单原有状态
		_action = form.action;
		_target = form.target;
		
		// 设置表单的提交预览状态
		form.action = action;
		form.target = target;
		
		// 预览提交
		form.submit();
		
		// 恢复表单状态
		form.action = _action;
		form.target = _target;
	}
	catch(e){alert("运行时错误，请与管理员联系！");}
}


function OpenWindow(url, width, height)
{
	if(isNaN(width)) width = screen.width * 0.7;
	if(isNaN(height)) height = screen.height * 0.7;
	window.open(url, "_blank", "width=" + width + ",height=" + height + ",scrollbars=yes,resizable=yes,status=yes");
}

function OpenWindowCenter(url, width, height)
{
	var tmpTop,tmpLeft;
	
	if(isNaN(width)) width = screen.width * 0.7;
	if(isNaN(height)) height = screen.height * 0.7;
	
    tmpTop=parseInt((window.screen.height-height)/2.2);
    tmpLeft=parseInt((window.screen.width-width)/2.2);
    
	window.open(url, "_blank", "left=" + tmpLeft + ",top="+ tmpTop + ",width=" + width + ",height=" + height + ",toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=yes");
}



function ReloadOpener( reloadFunction )
{
	if( reloadFunction )
	{
		if( typeof(reloadFunction) == "string" )
		{
			try
			{
				reloadFunction = eval(reloadFunction);
			}
			catch(e)
			{
				reloadFunction = "window.top.opener." + reloadFunction;
				
				try
				{
					reloadFunction = eval(reloadFunction);
				}
				catch(e)
				{
					return;
				}
			}
		}
	}
	else
	{
		if( window.top.opener )
		{
			reloadFunction = window.top.opener.ReloadPage;
		}
	}
	
	if( reloadFunction )
		reloadFunction();
}

function getElementPos(element) {
	var ua = navigator.userAgent.toLowerCase();
	var isOpera = (ua.indexOf('opera') != -1);
	var isIE = (ua.indexOf('msie') != -1 && !isOpera); // not opera spoof
	var el = element;
	var parent = null;
	var pos = [];
	if (el.parentNode === null || el.style.display == 'none') {
		return pos;
	}
	var box;
	if (el.getBoundingClientRect) //IE
	{
		box = el.getBoundingClientRect();
		var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
		var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
		return { x: box.left + scrollLeft, y: box.top + scrollTop };
	}
	else if (document.getBoxObjectFor) // gecko
	{
		box = document.getBoxObjectFor(el);
		var borderLeft = (el.style.borderLeftWidth) ? parseInt(el.style.borderLeftWidth) : 0;
		var borderTop = (el.style.borderTopWidth) ? parseInt(el.style.borderTopWidth) : 0;
		pos = [box.x - borderLeft, box.y - borderTop];
	}

	else // safari & opera
	{
		pos = [el.offsetLeft, el.offsetTop];
		parent = el.offsetParent;
		if (parent != el) {
			while (parent) {
				pos[0] += parent.offsetLeft;
				pos[1] += parent.offsetTop;
				parent = parent.offsetParent;
			}
		}
		if (ua.indexOf('opera') != -1 || (ua.indexOf('safari') != -1 && el.style.position == 'absolute')) {
			pos[0] -= document.body.offsetLeft;
			pos[1] -= document.body.offsetTop;
		}
	}

	if (el.parentNode) { parent = el.parentNode; }
	else { parent = null; }
	while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML') { // account for any scrolled ancestors

		pos[0] -= parent.scrollLeft;
		pos[1] -= parent.scrollTop;
		if (parent.parentNode) { parent = parent.parentNode; }
		else { parent = null; }
	}

	return { x: pos[0], y: pos[1] };
} 	
