String.prototype.LenGB=function(){
		var arr=this.match(/[^\x00-\x80]/g);
		return this.length+(!arr?0:arr.length);
}
String.prototype.Trim=function()
{return this.replace(/^\s*/g,"").replace(/\s*$/g,"");}

//管理员登录验证
function AdminChkLogin()
{
    var obj=document.getElementsByTagName("input");
    for(var i=0;i<obj.length;i++)
    {
        if(obj[i].type=="text")
            if(obj[i].value.length<5)
            {
                alert("用户名要大于5个字!");
                obj[i].focus();
                return false;
            }
        if(obj[i].type=="password")
            if(obj[i].value.length<6)
            {
                alert("密码要大于6个字!");
                obj[i].focus();
                return false;
            }
    }
    return true;
}
//确认删除
function ckDel()
{
	return confirm('此次操作不可恢复,是否确认?');
}
//Option 添加
function OptionAdd(d,text,value)
{
  for(var i=0;i<d.options.length;i++) 
	  if(d.options(i).value==value)
		  return 0;
  d.options.add(new Option(text,value));
  d.options(d.options.length-1).selected=true;
}
//添加选择的项
function SelectAdd(s,d)
{
	for(var i=0;i<s.options.length;i++)
	{
		if(s.options(i).selected)
		{
			  OptionAdd(d,s.options(i).text,s.options(i).value);
		}
	}
}
//删除所选
function SelectDel(d)
{
  for(var i=d.options.length -1 ;i>=0;i--)
	  if(d.options(i).selected)
		  d.options.remove(i);
}
//选择全部
function SelectAll(obj)
{
	for(var i=0;i<obj.options.length;i++)
	{
		obj.options(i).selected=true;
	}
}
//顶部表格改变样式
function on(obj,Color)
{
	if(typeof(Color)=="undefined")
		obj.style.background="#DCF7AD";
	else if(Color==1)
		obj.style.background="#ADD7F7";
	else
		obj.style.background="#FFD866";
}
//顶部表格恢复样式
function off(obj,Color)
{
	if(typeof(Color)=="undefined")
		obj.style.background="#EFFDD5";
	else if(Color==1)
		obj.style.background="#D5ECFD";
	else
		obj.style.background="#FFF0AE";
}
//顶部公共搜索验证
function frmSearch()
{
	if(document.search.KeyWord.value=="" || document.search.KeyWord.value=="关键字")
	{
		alert("请输入搜索关键字")
		document.search.KeyWord.select();
		document.search.KeyWord.focus();
		return false;
	}
	return true;
}
//复选框全选
function CheckBoxSelectAll()
{
var obj=document.getElementsByTagName("INPUT");
	for(var i=0;i<obj.length;i++)
		if(obj[i].type=="checkbox")
		{
			obj[i].checked=true;
			if(obj[i].onclick && obj[i].onclick.toString().indexOf("CheckBoxSetColor")!=-1)
			{
				CheckBoxSetColor(obj[i]);
			}
		}
}
//复选框全取消
function CheckBoxUNSelectAll()
{
var obj=document.getElementsByTagName("INPUT");
	for(var i=0;i<obj.length;i++)
		if(obj[i].type=="checkbox")
		{
			obj[i].checked=false;
			if(obj[i].onclick && obj[i].onclick.toString().indexOf("CheckBoxSetColor")!=-1)
			{
				CheckBoxSetColor(obj[i]);
			}
		}
}
//复选框反选
function CheckBoxReverseSelect()
{
var obj=document.getElementsByTagName("INPUT");
	for(var i=0;i<obj.length;i++)
		if(obj[i].type=="checkbox")
		{
			obj[i].checked=!obj[i].checked;
			if(obj[i].onclick && obj[i].onclick.toString().indexOf("CheckBoxSetColor")!=-1)
			{
				CheckBoxSetColor(obj[i]);
			}
		}
}
//**********************************************************
function CheckBoxSetColor(obj)
{
	if(obj.type && obj.type=="checkbox")
		if(obj.parentElement && obj.parentElement.parentElement && obj.parentElement.parentElement.tagName == "TR" && obj.checked)
			obj.parentElement.parentElement.style.backgroundColor	=	"#FFFFCC";
		else
			obj.parentElement.parentElement.style.backgroundColor	=	"#FFFFFF";
}
//**********************************************************
function SetColor(obj, color)
{
	obj.style.backgroundColor	=	color;
}
//**********************************************************
function CheckIsChecked(Key)
{
	var obj	=	document.getElementsByName(Key);
	for(var i=0;i<obj.length;i++)
		if(obj[i].checked)
			return true;
	alert("请至少选择一个");
	return false;	
}
//**********************************************************
function TableInsertRow(obj, Color, RowIndex)
{
	if(!(obj && obj.tagName=="TABLE"))
	{
		return;
	}
	if(obj.rows.length>1 && Color!='')
		return;
	else if(obj.rows.length==1)
		RowIndex	=	1;
	else
		RowIndex	=	-1;	

	var tr	=	obj.insertRow(RowIndex);
	try
	{
		tr.style.color	=	Color;
		tr.align	=	"center";
	}
	catch(e){}
	for(var i=3;i<arguments.length;i++)
	{
		var td	=	tr.insertCell(tr.cells.length);
		td.innerHTML	=	arguments[i];
	}
}
//**********************************************************
function frmElementSet_innerHTML(target, value)
{
	var obj	=	document.getElementById(target);
	if(!obj)return;
	obj.innerHTML	=	value;
}
//**********************************************************
function frmElementSetValue(obj, value)
{
	if(typeof(obj)!="object"){return;}
	if(!obj.tagName || (obj.tagName != "INPUT" && obj.tagName!="SELECT" && obj.tagName!="TEXTAREA")){return;}
	if(!obj.type){return;}
	switch(obj.type.toUpperCase())
	{
		case "SELECT":
			for(var i=0;i<obj.options.length;i++)
			{
				if(obj.options[i].value == value)
				{
					obj.selectedIndex	=	i;
					break;
				}
			}
			break;
		case "CHECKBOX":
			if(obj.value==value)
				obj.checked=true;
			else
				obj.checked=false;
			break;
		default:
			{
				obj.value	=	value;
			}
	}
}
//**********************************************************
function PopupWindow(theURL, Width, Height) { //v3.0
 if (! window.focus) return true;
  var href;
  if (typeof(theURL) == 'string')
    href=theURL;
  else
    href=theURL.href;
  window.open(href, "", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + Width + ",height=" + Height);
  return false;
}
//**********************************************************
function set_cookie(sKey, sValue) {
	var tcookie_time = new Date();
	var tcookie_expiry = new Date(tcookie_time.getTime() + 1000 * 3600 * 24);
	document.cookie = sKey + "=" + sValue + "; expires=" + tcookie_expiry.toGMTString();
}
//**********************************************************
function get_cookie(Name) {
	var search = Name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		if (offset != -1) {
			offset += search.length
			end = document.cookie.indexOf(";", offset);
			if (end == -1)
			end = document.cookie.length;
			returnvalue = unescape(document.cookie.substring(offset, end))
		}
	}
	return returnvalue;
}
//**********************************************************
// Author:	陈世华
// QQ:		47210879
//**********************************************************
function ShowPage(PageCount, ShowNumber, ShowCNNext, ShowGO)
{
	var PageSize	=	10;
	var queryStr	=	location.search;
	var CurrentPage	=	1;
	if(queryStr != "")
		queryStr	=	queryStr.replace("?","");
	if(queryStr.toLowerCase().indexOf("page=") == -1)
	{
		if(queryStr == "")
			queryStr	=	"Page=1";
		else
			queryStr	+=	"&Page=1";
	}
	else
	{
		CurrentPage	=	queryStr.toLowerCase().replace(/^[^\ ]*page=(\d+)[^\ ]*$/gi,"$1");
	}

	PageCount	=	parseInt(PageCount);
	if(isNaN(PageCount) || PageCount < 0)
		PageCount	=	0;
	CurrentPage	=	parseInt(CurrentPage);
	if(isNaN(CurrentPage) || CurrentPage < 0)
		CurrentPage	=	1;
	CurrentPage	=	CurrentPage>PageCount?PageCount:CurrentPage;

	//首页,上一页
	this.ShowFirstPrevious	=	function(PageCount, CurrentPage, FirstText, PreviousText, PageSize)
	{
		if(isNaN(parseInt(PageSize)))
			PageSize	=	0;
		if(PageSize > 0)
		{
			if(CurrentPage > 1)
			{
				document.write("<a href='?" + queryStr.replace(/page=(\d+)/gi,"Page=1") + "'>" + FirstText + "</a> ");
			}
			if(parseInt(CurrentPage / PageSize) + (CurrentPage % PageSize==0?0:1) > 1)
			{
				document.write("<a href='?" + queryStr.replace(/page=(\d+)/gi,"Page=" + ((parseInt(CurrentPage / PageSize) - (CurrentPage % PageSize==0?1:0)) * PageSize).toString()) + "'>" + PreviousText + "</a> ");
			}
		}
		else
		{
			if(CurrentPage > 1)
			{
				document.write("<a href='?" + queryStr.replace(/page=(\d+)/gi,"Page=1") + "'>" + FirstText + "</a> ");
			}
			if(CurrentPage > 1)
			{
				document.write("<a href='?" + queryStr.replace(/page=(\d+)/gi,"Page=" + (CurrentPage - 1).toString()) + "'>" + PreviousText + "</a> ");
			}
		}
	}
	//下一页,尾页
	this.ShowLastNext	=	function(PageCount, CurrentPage, NextText, LastText, PageSize)
	{
		if(isNaN(parseInt(PageSize)))
			PageSize	=	0;
		if(PageSize > 0)
		{
			if((parseInt(CurrentPage / PageSize) + (CurrentPage % PageSize==0?0:1)) * PageSize < PageCount)
			{
				document.write("<a href='?" + queryStr.replace(/page=(\d+)/gi,"Page=" + ((parseInt(CurrentPage / PageSize) + (CurrentPage % PageSize==0?0:1)) * PageSize + 1).toString()) + "'>" + NextText + "</a> ");
			}
			if(CurrentPage < PageCount)
			{
				document.write("<a href='?" + queryStr.replace(/page=(\d+)/gi,"Page=" + PageCount.toString()) + "'>" + LastText + "</a> ");
			}
		}
		else
		{
			if(CurrentPage < PageCount)
			{
				document.write("<a href='?" + queryStr.replace(/page=(\d+)/gi,"Page=" + (CurrentPage + 1).toString()) + "'>" + NextText + "</a> ");
			}
			if(CurrentPage < PageCount)
			{
				document.write("<a href='?" + queryStr.replace(/page=(\d+)/gi,"Page=" + PageCount.toString()) + "'>" + LastText + "</a> ");
			}
		}
	}
	//显示1..10
	if(ShowNumber)
	{
		var tmp	=	parseInt(CurrentPage / PageSize);
		if(CurrentPage % PageSize == 0)
			tmp--;
		tmp	=	tmp<0?0:tmp;
		this.ShowFirstPrevious(PageCount, CurrentPage, "<font face=webdings>9</font>", "<font face=webdings>7</font>", PageSize);
		for(var i = tmp * PageSize + 1; i <= PageSize * (tmp + 1); i++)
		{
			if(i > PageCount)break;
			if(CurrentPage != i)
				document.write("<a href='?" + queryStr.replace(/page=(\d+)/gi,"Page=" + i.toString()) + "'>" +  i.toString() + "</a> ");
			else
				document.write("<font color=red><b>" +  i.toString() + "</b></font> ");
		}
		this.ShowLastNext(PageCount, CurrentPage, "<font face=webdings>8</font>", "<font face=webdings>:</font>", PageSize);
	}
	//显示上一页,下一页
	if(ShowCNNext)
	{
		this.ShowFirstPrevious(PageCount, CurrentPage, "首页", "上一页");
		this.ShowLastNext(PageCount, CurrentPage, "下一页", "尾页");
	}
	//显示转到第几页
	if(ShowGO)
	{
		document.write('转到 <INPUT NAME="PageNumber" id="PageNumber" value="' + CurrentPage.toString() + '" TYPE="text" onchange="javascript:javascript:this.value=this.value.replace(/[^0-9]/gi,\'\');" onKeyUp="javascript:this.value=this.value.replace(/[^0-9]/gi,\'\');" SIZE="3" MAXLENGTH="5"> 页 ');
		document.write("<input type=button name=Submit value=GO onclick='var obj = document.getElementById(\"PageNumber\").value;if(!isNaN(parseInt(obj))){location.href=\"?" + queryStr.replace("\\","\\\\").replace(/\"/gi,"\\\"").replace(/\'/gi,"&#39;") + "\".replace(/page=(\\\d+)/gi,\"Page=\" + obj);}else{alert(\"请输入正确的页码!\");}'>");
	}
	//window.status	=	queryStr;//set_cookie("71C570102EE77010556F615C1FC82B7F", "");
}
