﻿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();
}
