function getIE6()  
{   
	if(navigator.userAgent.indexOf("MSIE")>0)  
	{   
		//是否是IE6浏览器   
		if(navigator.userAgent.indexOf("MSIE 6.0")>0)  
			return true;
		else
			return false;
	}
	else
	{
		return false;
	}

}






function trim(str)
{
	var RegExp1 = new RegExp("[ \n\r]","g");
	return str.replace(RegExp1,"");
}

function chkDate(str)
{
	//xxxx eg:1943
	var regx1 = /^\d{4}($|-$)/;

	//xxxx-xx  eg:1943-1/1943-01/1943-10
	var regx2 = /^\d{4}(-|.)[1-9]{1}($|-$)/;
	var regx3 = /^\d{4}(-|.)0[1-9]{1}($|-$)/;
	var regx4 = /^\d{4}(-|.)1[0-2]{1}($|-$)/;

	//xxxx-x-xx  eg:1943-1-1/1943-1-01/1943-1-10
	var regx5 = /^\d{4}(-|.)[1-9]{1}(-|.)[1-9]{1}($|-$)/;
	var regx6 = /^\d{4}(-|.)[1-9]{1}(-|.)0[1-9]{1}($|-$)/;
	var regx7 = /^\d{4}(-|.)[1-9]{1}(-|.)[1-3]{1}[0-9]{1}($|-$)/;


	//xxxx-x-xx  eg:1943-01-1/1943-01-01/1943-01-10
	var regx8 = /^\d{4}(-|.)0[1-9]{1}(-|.)[1-9]{1}($|-$)/;
	var regx9 = /^\d{4}(-|.)0[1-9]{1}(-|.)0[1-9]{1}($|-$)/;
	var regx10 = /^\d{4}(-|.)0[1-9]{1}(-|.)[1-3]{1}[0-9]{1}($|-$)/;

	//xxxx-xx-xx  eg:1943-10-1/1943-10-01/1943-10-10
	var regx11 = /^\d{4}(-|.)1[0-2]{1}(-|.)[1-9]{1}($|-$)/;
	var regx12 = /^\d{4}(-|.)1[0-2]{1}(-|.)0[1-9]{1}($|-$)/;
	var regx13 = /^\d{4}(-|.)1[0-2]{1}(-|.)[1-3]{1}[0-9]{1}($|-$)/;


	if(regx1.test(trim(str)))
		strng = true;		
	else if(regx2.test(trim(str)))
		strng = true;
	else if(regx3.test(trim(str)))
		strng = true;
	else if(regx4.test(trim(str)))
		strng = true;
	else if(regx5.test(trim(str)))
		strng = true;
	else if(regx6.test(trim(str)))
		strng = true;
	else if(regx7.test(trim(str)))
		strng = true;
	else if(regx8.test(trim(str)))
		strng = true;
	else if(regx9.test(trim(str)))
		strng = true;
	else if(regx10.test(trim(str)))
		strng = true;
	else if(regx11.test(trim(str)))
		strng = true;
	else if(regx12.test(trim(str)))
		strng = true;
	else if(regx13.test(trim(str)))
		strng = true;
	else
		strng = false;

	return strng;
}

function checkAll(str)
{
	var a = document.getElementsByName(str);
	var x = document.getElementsByName('all');
	for (var i=0;i<a.length;i++)
	{
		if (x[0].checked == true)
			a[i].checked = true;
		else
			a[i].checked = false;		
	}
}

function checkItem(str)
{
	var a = document.getElementsByName(str);
	var x = document.getElementsByName('all');
	var chk = true;
	for (var i=0;i<a.length;i++)
	{
		if (a[i].checked == false)
		{
			chk = false;
			break;
		}
	}	
	x[0].checked = chk;
}

function showContent(id)
{
	whichEl = document.getElementById(id);
	if (whichEl.style.display == "none")
	{
		whichEl.style.display = "block";
	}
	else
	{
		whichEl.style.display = "none";
	}
}


function init()
{
	var left_height = $('left').getHeight();
	var right_height = $('right').getHeight();

	var body_height = document.viewport.getHeight()+17;
	var top_height = $('top').getHeight();
	//var top_height = 0;
	var bottom_height = $('bottom').getHeight();
	var center_height = body_height - top_height - bottom_height;

	//alert(document.viewport.getHeight());

	if(center_height>left_height && center_height>right_height)
	{
		$('right').style.height = center_height+'px';
		$('left').style.height = center_height+'px';
		$('innerLeft').style.height = center_height+'px';
	}
	else
	{
		if(left_height>right_height)
		{
			$('right').style.height = left_height+'px';
			$('left').style.height = left_height+'px';
			$('innerLeft').style.height = left_height+'px';
		}
		else
		{
			$('right').style.height = right_height+'px';
			$('left').style.height = right_height+'px';
			$('innerLeft').style.height = right_height+'px';

		}
	}
}

function newLink(t)
{
	var id = "selectLink"+t;
	var link = $(id).value;

	if(link=="0")
	{
		alert("请选择网站");
		$(id).focus();
	}
	else
	{
		location.href = link;
	}

	
	//document.location.href = link;
	//$(id).onsubmit();

	//$(id).action = link;
	//$(id).submit();
                

}

function Login()
{
	if(trim(document.login.username.value)=="")
	{
		alert("请输入用户名");
		document.login.username.focus();
		return false;
	}
	if(trim(document.login.password.value)=="")
	{
		alert("请输入密码");
		document.login.password.focus();
		return false;
	}

	return true;
}

function Search()
{
	if(trim(document.search.search.value)=="")
	{
		alert("请输入关键字");
		document.search.search.focus();
		return false;
	}

	return true;
}


function chkMuseum()
{
	if(trim(document.form.name.value)=="")
	{
		alert("请输入名称");
		document.form.name.focus();
		return false;
	}
	if(trim(document.form.resnum.value)=="")
	{
		alert("请输入总登记号");
		document.form.resnum.focus();
		return false;
	}
	if(!chkDate(document.form.dbdate.value)&&trim(document.form.dbdate.value)!="")
	{
		alert("入库时间格式不正确");
		document.form.dbdate.focus();
		return false;
	}
	if(document.form.isresnum.value==1)
	{
		alert("总登记号重复");
		document.form.resnum.focus();
		return false;
	}

	return true;
}


function chkGrave()
{
	if(trim(document.form.name.value)=="")
	{
		alert("请输入名称");
		document.form.name.focus();
		return false;
	}
	if(trim(document.form.resnum.value)=="")
	{
		alert("请输入总登记号");
		document.form.resnum.focus();
		return false;
	}
	if(!chkDate(document.form.dbdate.value)&&trim(document.form.dbdate.value)!="")
	{
		alert("入库时间格式不正确");
		document.form.dbdate.focus();
		return false;
	}
	if(document.form.isresnum.value==1)
	{
		alert("总登记号重复");
		document.form.resnum.focus();
		return false;
	}

	return true;
}


function chkBattle()
{
	if(trim(document.form.name.value)=="")
	{
		alert("请输入名称");
		document.form.name.focus();
		return false;
	}
	if(trim(document.form.resnum.value)=="")
	{
		alert("请输入总登记号");
		document.form.resnum.focus();
		return false;
	}
	if(!chkDate(document.form.dbdate.value)&&trim(document.form.dbdate.value)!="")
	{
		alert("入库日期格式不正确");
		document.form.dbdate.focus();
		return false;
	}
	if(document.form.isresnum.value==1)
	{
		alert("总登记号重复");
		document.form.resnum.focus();
		return false;
	}

	return true;
}


function chkUser()
{
	if(trim(document.form.username.value)=="")
	{
		alert("请输入会员名");
		document.form.username.focus();
		return false;
	}
	if(trim(document.form.password.value)=="")
	{
		alert("请输入会员密码");
		document.form.password.focus();
		return false;
	}
	if(document.form.isusername.value==1)
	{
		alert("会员名重复");
		document.form.username.focus();
		return false;
	}

	return true;
}


function chkSearchMartyr()
{
	if(!chkDate(document.form.se_birthday1.value)&&trim(document.form.se_birthday1.value)!="")
	{
		alert("出生年月格式不正确");
		document.form.se_birthday1.focus();
		return false;
	}
	if(!chkDate(document.form.se_birthday2.value)&&trim(document.form.se_birthday2.value)!="")
	{
		alert("出生年月格式不正确");
		document.form.se_birthday2.focus();
		return false;
	}

	return true;
}

function chkSearchRelic()
{
	if(!chkDate(document.form.se_dbdate1.value)&&trim(document.form.se_dbdate1.value)!="")
	{
		alert("入库时间格式不正确");
		document.form.se_dbdate1.focus();
		return false;
	}
	if(!chkDate(document.form.se_dbdate2.value)&&trim(document.form.se_dbdate2.value)!="")
	{
		alert("入库时间格式不正确");
		document.form.se_dbdate2.focus();
		return false;
	}

	return true;
}

function chkSearchMuseum()
{
	if(!chkDate(document.form.se_dbdate1.value)&&trim(document.form.se_dbdate1.value)!="")
	{
		alert("入库时间格式不正确");
		document.form.se_dbdate1.focus();
		return false;
	}
	if(!chkDate(document.form.se_dbdate2.value)&&trim(document.form.se_dbdate2.value)!="")
	{
		alert("入库时间格式不正确");
		document.form.se_dbdate2.focus();
		return false;
	}

	return true;
}

function chkSearchGrave()
{
	if(!chkDate(document.form.se_dbdate1.value)&&trim(document.form.se_dbdate1.value)!="")
	{
		alert("日期格式不正确");
		document.form.se_dbdate1.focus();
		return false;
	}
	if(!chkDate(document.form.se_dbdate2.value)&&trim(document.form.se_dbdate2.value)!="")
	{
		alert("日期格式不正确");
		document.form.se_dbdate2.focus();
		return false;
	}

	return true;
}

function chkSearchBattle()
{
	if(!chkDate(document.form.se_dbdate1.value)&&trim(document.form.se_dbdate1.value)!="")
	{
		alert("入库日期格式不正确");
		document.form.se_dbdate1.focus();
		return false;
	}
	if(!chkDate(document.form.se_dbdate2.value)&&trim(document.form.se_dbdate2.value)!="")
	{
		alert("入库日期格式不正确");
		document.form.se_dbdate2.focus();
		return false;
	}

	return true;
}

function chkSearchReport()
{
	if(!chkDate(document.form.se_dbdate1.value)&&trim(document.form.se_dbdate1.value)!="")
	{
		alert("生成时间格式不正确");
		document.form.se_dbdate1.focus();
		return false;
	}
	if(!chkDate(document.form.se_dbdate2.value)&&trim(document.form.se_dbdate2.value)!="")
	{
		alert("生成时间格式不正确");
		document.form.se_dbdate2.focus();
		return false;
	}

	return true;
}

function chkSearchFix()
{

	return true;
}

function chkImport()
{
	//alert(document.getElementsByName('operate').value);
	//alert(document.import1.import.value);	

	if (trim(document.form.xls.value) == "")
	{
		alert("请上传EXCEL文件");
		document.form.xls.focus();
		return false;
	}

	return true;
}

function operation(url, str, t)
{
	var id = "0";
	var con;
	if (t=="del")
	{
		con = "将删除选定的资料，不能恢复，确定吗";
	}
	else if (t=="backup")
	{
		con = "将删除选定的备份文件，不能恢复，确定吗";
	}
	else if (t=="deluser")
	{
		con = "将删除选定的会员，不能恢复，确定吗";
	}
	else
	{
		con = "程序错误";
		url = "#";	
	}	
	
	if (confirm(con))
	{
		var a = document.getElementsByName(str);
		for (var i=0;i<a.length;i++)
		{
			if (a[i].checked == true)
				id += ", " + a[i].value;
		}
		
		url += "id="+id;
		document.list.action = url;
		document.list.submit();
	}
}

function page(url)
{
	document.list.action = url;
	document.list.submit();
}


function outAdmin()
{
	var url;
	url = "login.php?action=out";
	parent.top.window.location = url;
}



function transInt(str)
{
	var regx = /\d/;
	if(trim(str) == "")
		str = false;
	else if(!regx.test(str))
		str = false;
	else
		str = true;

	return str;
}
function transTime(str)
{
	var regx = /\d{1,2}\:\d{2}/;
	if(str != "")
	{
		if(!regx.test(str))
			str = false;
		else
			str = true;
	}
	else
	{
		str = true;
	}

	return str;
}



function checkBox(str)
{
	var chk = true;
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++)
	{		
		if (x[i].type == 'checkbox' && x[i].className == 'del')
		{
			if (x[i].checked == true)
			{
				if (confirm(str))
					chk = true;
				else
					chk = false;
					
				break;
			}
		}
	}
	return chk;
}


function chkDateTime(str)
{
	var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
	if(r==null) return false;
	var d = new Date(r[1], r[3]-1, r[4]);
	return(d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]);
}

function selectFile()
{
	var file_file = document.getElementById("file_file");
	var file_text = document.getElementById("file_text");

	file_text.value = file_file.value;
}


function chkResnum(db)
{
	var resnum = $F('resnum');
	var id = $F(db+'id');

	var url = "../resnum.php";       // 请求url
	var pars = 'resnum='+resnum+'&id='+id+'&db='+db; //请求参数

	var myAjax = new Ajax.Request(
		url,
		{method: 'get', parameters: pars, onComplete: wIsresnum}
	);
}

function wIsresnum(originalRequest)
{
	//put returned XML in the textarea
	$('isresnum').value = originalRequest.responseText;

	if(trim($('resnum').value)=="")
	{
		$('showResnum').innerHTML = '<img src="../images/check_error.gif"> 总登记号不能为空';
		$('showResnum').className = 'warning';
	}
	else if($('isresnum').value==0)
	{
		$('showResnum').innerHTML = '<img src="../images/check_right.gif">';
		$('showResnum').className = 'nowarn';
	}
	else
	{
		$('showResnum').innerHTML = '<img src="../images/check_error.gif"> 总登记号重复';
		$('showResnum').className = 'warning';
	}
}


function chkName(db)
{	
	var chkname;

	if(db=="martyr")
		chkname = "姓名";
	else
		chkname = "名称";
		

	if(trim(document.form.name.value)=="")
	{
		$('showName').innerHTML = '<img src="../images/check_error.gif"> '+chkname+'不能为空';
		$('showName').className = 'warning';
	}
	else
	{
		$('showName').innerHTML = '<img src="../images/check_right.gif">';
		$('showName').className = 'nowarn';
	}
}


function chkUsername()
{
	var username = $F('username');
	var userid = $F('userid');

	var url = "../user.php";       // 请求url
	var pars = 'username='+username+'&userid='+userid; //请求参数

	var myAjax = new Ajax.Request(
		url,
		{method: 'get', parameters: pars, onComplete: wIsusername}
	);
}

function wIsusername(originalRequest)
{
	//put returned XML in the textarea
	$('isusername').value = originalRequest.responseText;

	if(trim($('username').value)=="")
	{
		$('showUsername').innerHTML = '<img src="../images/check_error.gif"> 会员名不能为空';
		$('showUsername').className = 'warning';
	}
	else if($('isusername').value==0)
	{
		$('showUsername').innerHTML = '<img src="../images/check_right.gif">';
		$('showUsername').className = 'nowarn';
	}
	else
	{
		$('showUsername').innerHTML = '<img src="../images/check_error.gif"> 会员名重复';
		$('showUsername').className = 'warning';
	}
}


function chkPassword()
{	
	if(trim(document.form.password.value)==""&&document.form.operate.value==1)
	{
		$('showPassword').innerHTML = '<img src="../images/check_error.gif"> 密码不能为空';
		$('showPassword').className = 'warning';
	}
	else
	{
		$('showPassword').innerHTML = '<img src="../images/check_right.gif">';
		$('showPassword').className = 'nowarn';
	}
}


function chkExport(t)
{
	t = t.replace('+', '%2B');

	var rand = Math.random();

	rand = rand.toString();

	var file = rand.substr(rand.length-12, rand.length)+".xls";
	var action = "?xlsname="+file;

	$('xls').value = file;

	var url = t;       //请求url
	var pars = action; //请求参数

	$('showPrint').innerHTML = "";
	$('imgExport').innerHTML = "";
	$('showExport').innerHTML = "";	

	$('imgExport').innerHTML = "&nbsp;<img src=\"./images/indicator.gif\">";
	$('showExport').innerHTML = "&nbsp;文件生成中…&nbsp;";
	//$('showExport').className = "loading";

	var myAjax = new Ajax.Request(
		url,
		{method: 'get', parameters: pars, onComplete: wExport}
	);
}

function wExport(originalRequest)
{
	//put returned XML in the textarea

	var request = originalRequest.responseText;
	var dirxls = request.split(',');

	if(dirxls[1]==$('xls').value)
	{
		$('imgExport').innerHTML = "";
		$('showExport').innerHTML = "&nbsp;<a href=\""+dirxls[0]+dirxls[1]+"\">下载</a>&nbsp;";
		$('showExport').className = "down";
	}
}


function chkPrint(t)
{
	$('imgExport').innerHTML = "";
	$('showExport').innerHTML = "";

	t = t.replace('+', '%2B');

	var Sys = {};

	var user = navigator.userAgent.toLowerCase();  

	if(user.match(/msie/) == "msie")
		Sys.ie = "ie";
	else if(user.match(/firefox/) == "firefox")
		Sys.firefox = "ff";	

	//if(Sys.ie) document.write('IE: '+Sys.ie);
	//if(Sys.firefox) document.write('Firefox: '+Sys.firefox);

	var oldVersion = LODOP.Version;


	//alert(Sys.firefox)
	if(!(Sys.ie||Sys.firefox))
	{
		alert('此浏览器不支持打印功能，请使用IE或者Firefox');
	}
	else if(oldVersion==null)
	{
		alert('打印控件未安装，点击下载插件执行安装，安装后请刷新页面');
		$('showPrint').innerHTML = "";
		$('showPrint').innerHTML+= "&nbsp;<a href=\"install_lodop.exe\" target=\"_blank\">下载插件</a>&nbsp;";

	}
	else if(Sys.firefox)
	{
		$('showPrint').innerHTML = "";
		$('showPrint').innerHTML+= "&nbsp;<a href='npActiveX0712SFx31.xpi'>Firefox运行环境</a>";
		$('showPrint').innerHTML+= "&nbsp;<a href=\""+t+"\" target=\"_blank\">打印设置</a>&nbsp;";	
	}
	else
	{
		$('showPrint').innerHTML = "";
		$('showPrint').innerHTML+= "&nbsp;<a href=\""+t+"\" target=\"_blank\">打印设置</a>&nbsp;";
	}	

	//var username = $F('username');
	//var userid = $F('userid');


	/*
	var url = t;       // 请求url
	var pars = ""; //请求参数
	//var pars = 'username='+username+'&userid='+userid; //请求参数


	var myAjax = new Ajax.Request(
		url,
		{method: 'get', parameters: pars, onComplete: wExport}
	);

	*/
}

//表宽，全局变量
var global_table_width;
var Sys = {};

//列表页初始化，设置各宽
function init1()
{
	iefirefox();

	countTable(0);
	
	widthTop();
	widthBottom();	

	rightTitle();
	printTable();	
	rightMinute();
}

//打印设置页初始化，设置表宽，打印机
function init2()
{
	iefirefox();

	countTable(1);	
	printTable();

	var cols = document.getElementById('cols');

	for(var i=0;i<cols.options.length;i++)
	{
		cols.options[i].selected = true;
	}	
	
	var num = LODOP.GET_PRINTER_COUNT();

	for(var i=0; i<num; i++)
	{

		var name = LODOP.GET_PRINTER_NAME(i);
		document.getElementById('printer').options.add(new Option(name, i)); 
	}	
}

//判断浏览器
function iefirefox()
{
	var ua = navigator.userAgent.toLowerCase();
	if(window.ActiveXObject)
		Sys.ie = ua.match(/msie ([\d.]+)/)[1];
	else if(document.getBoxObjectFor)
		Sys.firefox = ua.match(/firefox\/([\d.]+)/)[1];
}

//计算table width
function countTable(t)
{
	
	var print_table = document.getElementById('print_table');
	var print_thead = document.getElementById('print_thead');
	var table_width = 0;
	var table_len = print_thead.rows[t].cells.length;

	for(var i=0;i<table_len;i++)
	{
		var td = print_thead.rows[t].cells[i];
		var td_width = td.style.width;
		var len = td_width.length-2;
		
		table_width += parseInt(td_width.substr(0, len));

	}

	global_table_width = table_width;
	
	
}

//设置table width
function printTable()
{	
	var print_table = document.getElementById('print_table');		

	print_table.style.width = global_table_width;
	
}

//设置title width
function rightTitle()
{
	var right_title = document.getElementById('rightTitle');

	if(Sys.ie)
		right_title.style.width = global_table_width;
	else if(Sys.firefox)
		right_title.style.width = global_table_width-10;
}

//设置minute width 分页线
function rightMinute()
{
	var right_minute = document.getElementById('minute');

	if(Sys.ie)
		right_minute.style.width = global_table_width;
	else if(Sys.firefox)
		right_minute.style.width = global_table_width;
}

//设置top width
function widthTop()
{
	var top = document.getElementById('top');

	top.style.width = global_table_width + 232;
}

//设置bottom width
function widthBottom()
{
	var bottom = document.getElementById('bottom');

	bottom.style.width = global_table_width + 232;
}


//选择打印列
function changeCol()
{
	var print_table = document.getElementById('print_table');
	var print_thead = document.getElementById('print_thead');
	var print_tbody = document.getElementById('print_tbody');

	//alert(document.getElementById("print_table").style.width); 

	var col_value;
	var cols = document.getElementById('cols');

	for(var i=0;i<cols.options.length;i++)
	{
		col_value = cols.options[i].value;	//取select值

		if(cols.options[i].selected)
		{
			print_thead.rows[1].cells[col_value].style.display = "";		//标题栏

			for(var j=0; j<print_tbody.rows.length; j++)
				print_tbody.rows[j].cells[col_value].style.display = "";
		}
		else
		{
			print_thead.rows[1].cells[col_value].style.display = "none";		//标题栏

			for(var j=0; j<print_tbody.rows.length; j++)
				print_tbody.rows[j].cells[col_value].style.display = "none";
		}
	}
	
	var table_width = 0;

	for(var i=0; i<print_thead.rows[1].cells.length; i++)
	{
		var td = print_thead.rows[1].cells[i];
		var td_width = td.style.width;
		var len = td_width.length-2;	

		if(td.style.display!="none")
			table_width += parseInt(td_width.substr(0, len));

	}

	print_table.style.width = table_width;

	//var se = document.getElementById('sex').style.display="none";
	
}

