﻿//Grid变色的效果
element=document.all.tags("tr");
count=element.length;
for (i=1;i<count;i++){
  element(i).onmouseover=swapon;
  element(i).onmouseout=swapoff;}

  function swapon(){
  if (this.className=="HeadStyleOfDataGridItemStyle"){
     this.className="blueon";}
     if (this.className=="HeadStyleOfDataGridAlternatingItemStyle"){
     this.className="blueon1";}
     
     }
function swapoff(){
  if (this.className=="blueon"){
     this.className="HeadStyleOfDataGridItemStyle";}
     if (this.className=="blueon1"){
     this.className="HeadStyleOfDataGridAlternatingItemStyle";}
     }
//结束：Grid变色的效果		

function AjaxSwap()
{
    element=document.all.tags("tr");
    count=element.length;
    for (i=1;i<count;i++)
    {
        element(i).onmouseover=swapon;
        element(i).onmouseout=swapoff;
    }

}

function selectall(value)
	 { 
       var checkboxes = document.getElementsByTagName("input");
       for (i = 0; i < checkboxes.length; i++)
       { 
           if(checkboxes[i].type=='checkbox'&&checkboxes[i].id!='ctl00_ContentPlaceHolder1_selectDate')
           {
                if (value.checked)
                 { 
                    checkboxes[i].checked = true; // this checks all the boxes 
                 }
                else
                 { 
                    checkboxes[i].checked = false; // this unchecks all the boxes 
                 } 
             }
       } 
     } 

//自动显示：页面右侧的返回或关闭按钮
function Show_Back_Or_Close()
{
    if (window.opener==null)
      {
        document.all("spanClose").style.display="none";
        document.all("spanReturn").style.display="";
      }
      else
      {
         document.all("spanClose").style.display="";
         document.all("spanReturn").style.display="none";
      } 
 }
 
 function MoveWindow(left,top)
{
  window.moveTo(left>0?left:0,top>0?top:0);
}

 //========================
//刷新父窗口页面
//========================

function refreshParent() 
{ 
	try
	{
		var temp=top.window.opener.location.href; 
		if(temp.indexOf("#") != -1)
			temp=temp.substring(0,temp.length-1);
		if(top.window.opener.location.href.indexOf("mainGeneral.aspx")<=0)
		{
			top.window.opener.location.href=temp; 
		}
	}
	catch(err)
	{top.window.close();}
}

 //========================
//刷新新窗口的父框架页面
//========================

function refreshOpenerParent() 
{ 
	try
	{
		var temp=top.window.opener.parent.location.href; 
		if(temp.indexOf("#") != -1)
			temp=temp.substring(0,temp.length-1);
		if(top.window.opener.parent.location.href.indexOf("mainGeneral.aspx")<=0)
		{
			top.window.opener.parent.location.href=temp; 
		}
	}
	catch(err)
	{top.window.close();}
}

//========================
//选择多级代码
//========================
function CodeLevSelect(txt,Url)
	{
		var strFeatures="dialogWidth=400px;dialogHeight=600px;help=no;status=no";
		var temp=window.showModalDialog(Url,'',strFeatures);
		if(temp!=null&&temp!='')
		{
			txt.value=temp;
		}		
	}

//========================
//弹出一个对话框，选择后返回值，赋给文本框
//========================
function SelectUrl(txt,Url)	
{	
	var strFeatures="dialogWidth=500px;dialogHeight=300px;help=no;status=no";
	var temp=window.showModalDialog(Url,'',strFeatures);
	if(temp!=null&&temp!='')
	{
		txt.value=temp;
	}
}

//========================
//选择日期
//========================

function seldate(txt)
{
	strFeatures="dialogWidth=180px;dialogHeight=210px;help=no;status=no";
	var url='/ShaoXingZtbMis/EpointMis/javascript/calender.htm'
	var temp;
 	temp=window.showModalDialog(url,txt.value,strFeatures);
 	if(temp!='')
 	{
 		txt.value=temp;
 	}
 }

//========================
//窗口大小调整
//========================
 
function ResizeWindow(width,height)
{
  if (width==screen.width)
    width=screen.availWidth;
  if (height==screen.height)
    height=screen.availHeight;
  var left=(screen.availWidth-width)/2;
  var top=(screen.availHeight-height)/2;
  window.moveTo(left>0?left:0,top>0?top:0);
  window.resizeTo(width,height);
}

//========================
//打开窗口
//========================
function OpenWindow(url,width,height)
{
  if (width==null)
    width=788;
  else
    width=width-12;
  if (height==null)
    height=569;
  else
    height=height-31;
  window.open(url,'_blank','channelmode=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=yes,toolbar=no,left='+(screen.availWidth<'+width+'?0:(screen.availWidth-'+width+')/2)+',top='+(screen.availHeight<'+height+'?0:(screen.availHeight-'+height+')/2)+',width='+width+',height='+height);
}

function OpenWindow(url,width,height,left,top)
{
  if (width==null)
    width=788;
  else
    width=width-12;
  if (height==null)
    height=569;
  else
    height=height-31;
  window.open(url,'_blank','channelmode=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=yes,toolbar=no,left='+left+',top='+top+',width='+width+',height='+height);
}


//========================
//打开窗口
//========================
function OpenPrintWindow(url)
{ 
  window.open(url,'','width=1,height=1,top=10000,left=10000');
  //window.open("about:blank","","width=1,height=1,top=10000,left=10000");
}

//========================
//打开对话框
//========================

function OpenDialog(url,width,height)
{
  today=new Date();  
  if (url.indexOf("?")<0)
  {
     url=url+"?xxxx="+Math.random();
  }
  else
  {
     url=url+"&xxxx="+Math.random();
  }
  if (width==null)
    width=800;
  if (height==null)
    height=600;
  return window.showModalDialog(url,'','dialogHeight:'+height+'px;dialogWidth:'+width+'px;edge:raised;center:Yes;help:No;resizable:Yes;status:no;scroll:yes;unadorned:yes;');
}

//========================
//打开对话框
//========================

function OpenDialogArgs(url,args,width,height)
{   
  today=new Date();  
  if (url.indexOf("?")<0)
  {
     url=url+"?xxxx="+Math.random();
  }
  else
  {
     url=url+"&xxxx="+Math.random();
  }
  if (width==null)
    width=800;
  if (height==null)
    height=600;
  return window.showModalDialog(url,args,'dialogHeight:'+height+'px;dialogWidth:'+width+'px;edge:raised;center:Yes;help:No;resizable:Yes;status:no;scroll:yes;unadorned:yes;');
}

//========================
//打开对话框带IFrame,并刷新父窗体
//结合rtnValue使用 返回值为空 刷新父窗体
//请勿修改 lsx ,若要用返回值的函数 请使用OpenDialog or OpenDialogArgs
//========================

function OpenDialogRefresh(url,args,width,height)
{ 
  today=new Date();  
  if (url.indexOf("?")<0)
  {
     url=url+"?xxxx="+Math.random();
  }
  else
  {
     url=url+"&xxxx="+Math.random();
  }
  if (width==null)
    width=600;
  if (height==null)
    height=500;
  var rtnValue=window.showModalDialog(url,args,'dialogHeight:'+height+'px;dialogWidth:'+width+'px;edge:raised;center:Yes;help:No;resizable:Yes;status:no;scroll:yes;unadorned:yes;');

  if(rtnValue!=null)
    {
        window.location=window.location.href.replace("#","");
    }  
}

//========================
//带IFrame的对话框返回值
//结合OpenDialogRefresh使用 
//========================

function rtnValue(value)
{ 
    var win;
    if (window.parent==null)
    {
       win=window;
    }
    else
    {
       win=window.parent;
    }
    if(value=="")
    {
         win.returnValue="";	    
		 win.close();	
    }else if(value=="★")
    {
         win.returnValue="";
    } 
    else
    {
        alert(value);
    }
}

//========================
//带IFrame的对话框返回值
//========================

function rtnValueNoIFrame(value)
{ 
    if(value=="")
    {
         window.returnValue="";	    
		 window.close();	
    }else if(value=="★")
    {
         window.returnValue="";
    }else
    {
        alert(value);
    }
}

//========================
//变换datagrid中行的背景色
//========================
function swapon()
{
	if (this.className=="blueoff"){
		this.className="blueon";
		}
}

function swapoff()
{
	if (this.className=="blueon"){
		this.className="blueoff";
		}
}

//========================
//全选
//========================
function AllSelect(parentCheckBox)
{
	var participants = document.getElementsByTagName("input");
    //alert(parentCheckBox.name);
	for ( var i=0; i < participants.length; i++ ) 
	{
		//if(participants[i].name.indexOf('Check_RowSelect')!=-1  || participants[i].name.indexOf('chkAdd')!=-1)
		if(participants[i].name.indexOf(parentCheckBox.name)!=-1)
		//if(participants[i].name=parentCheckBox.name)
		{				
			var participant = participants[i];
			if ( participant != null ) {
				participant.checked = parentCheckBox.checked;
			}
		}
	}
}


//检查输入的键盘字符是否合法，只允许输入数字字符
function CheckInputKey()
{
	if (event.keyCode==59)		   
	event.returnValue = false;
	else
	{		      
			if ((event.keyCode >47 && event.keyCode <58)||event.keyCode==8|| 
			event.keyCode==46 || event.keyCode==37 || event.keyCode==39 ||event.keyCode==190) 
			{
				event.returnValue = true;
			}
			else event.returnValue = false;	
	}			
}	

//窗口最大化
function MaxWindow()
{
    try
    {
		window.moveTo(0,0);
		window.resizeTo(window.screen.availWidth,window.screen.availHeight);
    }
	catch(err)
	{}
   	
}

//========================
//全选、全不选
//========================
function SelectCheckbox(PrefixName,blnSelect)
{
	var participants = document.getElementsByTagName("input");

	for ( var i=0; i < participants.length; i++ ) 
	{
		if(participants[i].name.indexOf(PrefixName)!=-1)
		{				
			var participant = participants[i];
			if ( participant != null ) {
				participant.checked = blnSelect;
			}
		}
	}
}

//========================
//检查Grid中的第一列选择框是否选中
//========================
function Check_SelectedStatus(PrefixName,Message)
{
    if (PrefixName==null)
         PrefixName="chkAdd";
         
    var participants = document.getElementsByTagName("input");

	for ( var i=0; i < participants.length; i++ ) 
	{
		if(participants[i].name.indexOf(PrefixName)!=-1)
		{				
			var participant = participants[i];
			if ( participant != null ) {
			    if (participant.checked)
			    {
			        return true;
			    }				
			}
		}
	}
	if(Message==null)
	{
	   alert("请选择记录!");
	}
	else
	{
	   alert(Message);
	}	
	return false;

}

//检查允许上传的文件类型
function CheckFile(FileLst)
{
  //取得允许上传或不允许上传的文件属性
  FileLst = FileLst.toLowerCase();
  if(FileLst.substring(0,1)!=";")
      FileLst = ";" + FileLst;
  
  if(FileLst.substring(FileLst.length-1)!=";")
   FileLst =  FileLst + ";" ;
  
  var inputs = document.getElementsByTagName("INPUT");
  var inputFile;
  
  var uname;
  var ftype;
  for(var i=0;i<inputs.length;i++)
  {
	    inputFile = inputs[i];
		if(inputFile.type == "file")
		{
				uname = inputFile.value;
				if(uname != "")
				{
					ftype = uname.substring(uname.lastIndexOf(".")+1).toLowerCase();    
					if(FileLst.indexOf(";" + ftype + ";") < 0)
					{
						alert("您选择的文件:" + inputFile.value + " 不在系统允许上传的文件类型中!\r\n系统允许上传的文件格式有:" + FileLst);
						return false;
					}//IF 不在列表中
				}//IF 名称非空
			
    	}//IF FILE
    }//FOR
    return true; 
}//END

//===============================================
//检查上传的文件的类型和大小，如果不在允许范围内或超过最大值，就返回False
//===============================================
function CheckUploadFile(FileLst,maxsize)
{
    if (CheckFile(FileLst))
    {
        try   //这里一定要有try /catch
        {
            return chkUploadFileSize(maxsize);
        }
        catch(err)
        {           
            return true;     
        }
    }
    else
       return false;
}
//===============================================
//检查上传的文件大小，如果超过最大值，就返回False
//===============================================
function chkUploadFileSize(maxsize)
{
	var fso = new ActiveXObject('Scripting.FileSystemObject');
	//var spanId="idfilespan";
	//var span = document.getElementById(spanId);
	var inputFile;
	var File;
	if(document.getElementsByTagName("INPUT").length==1)
		return true;
	else
	{
		
		if(document.getElementsByTagName("INPUT").length>1)
		{
			
			for(var i=0;i<document.getElementsByTagName("INPUT").length;i++)
			{
				inputFile = document.getElementsByTagName("INPUT")[i];
				if(inputFile.type!="file")  continue;
				//alert(inputFile.value);
				if(!fso.FileExists(inputFile.value)) continue;
				File = fso.GetFile(inputFile.value);
				//alert(File.Size);
				if(File.Size>maxsize*1024*1024)
				{
					
					alert ("抱歉！您选择的上传文件超过了" + maxsize +"M，不能提交！");
					return false;
				}
			}
		}
	}
	return true;
}

//========================
//日期变量上加上指定时间间隔
//strInterval：s-秒；n-分；h-小时；d-天；w-周；m-月
//========================
function DateAdd(strInterval, NumDay, dtDate)
 {
	var dtTmp = new Date(dtDate);
	if (isNaN(dtTmp)) dtTmp = new Date();
	switch (strInterval) {
	case "s":return new Date(Date.parse(dtTmp) + (1000 * NumDay));
	case "n":return new Date(Date.parse(dtTmp) + (60000 * NumDay));
	case "h":return new Date(Date.parse(dtTmp) + (3600000 * NumDay));
	case "d":return new Date(Date.parse(dtTmp) + (86400000 * NumDay));
	case "w":return new Date(Date.parse(dtTmp) + ((86400000 * 7) * NumDay));
	case "m":return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + NumDay, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
	case "y":return new Date((dtTmp.getFullYear() + NumDay), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
	}
}

//========================
//日期变量之间的间隔
//strInterval：s-秒；n-分；h-小时；d-天；w-周；m-月
//========================
// DateDiff("m","2002/12/1 00:00:00","2004/12/1 00:00:00")
function DateDiff(strInterval, dtStart, dtEnd)
{
	var dtStart = new Date(dtStart);
	if (isNaN(dtStart)) dtStart = new Date();
	var dtEnd = new Date(dtEnd);
	if (isNaN(dtEnd)) dtEnd = new Date();
	switch (strInterval)
	{
		case "s":return parseInt((dtEnd - dtStart) / 1000);
		case "n":return parseInt((dtEnd - dtStart) / 60000);
		case "h":return parseInt((dtEnd - dtStart) / 3600000);
		case "d":return parseInt((dtEnd - dtStart) / 86400000);
		case "w":return parseInt((dtEnd - dtStart) / (86400000 * 7));
		case "m":return (dtEnd.getMonth()+1)+((dtEnd.getFullYear()-dtStart.getFullYear())*12) - (dtStart.getMonth()+1);
		case "y":return dtEnd.getFullYear() - dtStart.getFullYear();
	}
}


///read cookie function


function GetCookie (name)
{
    //alert("")
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0)	
			break;
	}
	return null;
}

function getCookieVal (offset)
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
///read cookie function



		
    //在指定的输入控件中插入文本
	function   InsertTextAtFocusPostion(InputControl,InsertText)
	{
		InputControl.focus();				
		document.selection.createRange().text+=InsertText;
	}