﻿//屏蔽右键
/*
function click() 
{ 
    if(event.button == 2) 
    { 
         document.body.oncontextmenu=function(){return false;}
    } 
    return false;
} 
document.onmousedown = click; 
*/

var oldcolor="";
var selIndex=0;
String.prototype.Trim = function() 
{ 
    return this.replace(/(^\s*)|(\s*$)/g, ""); 
}
function rowmove(item)
{
	oldcolor=item.style.backgroundColor;
	item.style.backgroundColor="#D6D6D6";
}
function rowout(item)
{
	item.style.backgroundColor=oldcolor;
}
function openDlg(_url,_width,_height)
{
	window.open(_url, '', 'height='+_height+', width='+_width+', top=0,left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
}

function openDlgs(_url,_width,_height)
{
	window.open(_url, '', 'height='+_height+', width='+_width+', top=200,left=300, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no ,status=no');
}

function openScrollDlgs(_url,WindowName,_width,_height)
{
	new_window = window.open(_url, WindowName, 'height='+_height+', width='+_width+', top=100,left=200, toolbar=YEs, scrollbars=yes, resizable=yes,location=yes ,directories=no,status=yes,menubar=yes,copyhistory=yes');
	new_window.focus();
}
function openSimpleDlgs(_url,_width,_height)
{    
	window.open(_url, '', 'height='+_height+', width='+_width+', top=20,left=150, toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no ,status=no');
}


function _ShowDlg(_url,_width,_height,fixed)
{
    
	if(_height==0||_width==0)
	 {
		_height=300;
		_width=400;
	 }
	 if(fixed==null)
	 {
		fixed="No";
	}
	 var _left=window.document.body.clientWidth/2+screenLeft-_width/2;
	 var _top=window.document.body.clientHeight/2+screenTop-_height-60;
	 var result=window.showModalDialog(_url,null,"dialogHeight: "+_height+"px; dialogWidth: "+_width+"px; dialogTop:"+_top+"px; dialogLeft: "+_left+"px; edge: raised; help: no; resizable: "+fixed+"; status: no;");	
	
	var PagePath=window.location.toString();	
	
	if (PagePath.indexOf('?Del') != -1)		
		PagePath = PagePath.substring(0,PagePath.indexOf("?Del"));		
	
	if (PagePath.indexOf("&Del") != -1)	
		PagePath = PagePath.substring(0,PagePath.indexOf("&Del"));	
	
	if(result=="ok")
	{	    
		window.location.href = PagePath;		
	}
	else
		return result;
}
function closeDlg()
{

	window.close();
}
//初始化用户选择列表
function initSelList()
{
	if(document.all.ReturnID.value=="")
		return;
		
	var _array=new Array();
	
	_array=document.all.ReturnID.value.split(',');
	
	var ctl=document.all.SelCtl_lstUser;
	var _ctl=document.all.SelCtl_lstSelUser;
		
	for(var j=0;j<_array.length;j++)
	{
		for(i=ctl.options.length-1;i>=0;i--)
		{
			var tmp=document.createElement("OPTION");
			if(ctl.options(i).value==_array[j])
			{
				ctl.options(i).selected=true;
			}
		}
	}
	document.all.ReturnID.value="";
	L2R(ctl,_ctl);
	
}
function InitDlg(str)
{
	window.document.all[str].focus();
}
function saveview(ctlStr,noteStr)
{
	if(chkSave(ctlStr,noteStr))
	{
		//window.document.all.KeyValue.value=selId;
		window.document.forms[0].submit();
	}
	else
		return false;
}
function savefrm(ctlStr,selId,noteStr)
{
	if(chkSave(ctlStr,noteStr))
	{
		window.document.all.KeyValue.value=selId;
		window.document.forms[0].submit();
		//closeDlg();
	}
	else
		return false;
}
function chkSave(ctlStr,noteStr)
{
	if(ctlStr=="")
	{
		window.returnValue='ok';
		return true;
	}
	var var_array=ctlStr.split(";");
	var note_array=noteStr.split(";");
	for (var loop=0;loop<var_array.length;loop++)
	{	
		if(chkEmpt(document.all[var_array[loop]],note_array[loop]))
			return false;	
	}

	window.returnValue='ok';
	return true;
}
function chkEmpt(ctl,msg)
{
	if(ctl.value.Trim()=="" || ctl.value=="这里必须输入合法的数字！")
	{
		showmsg(ctl,msg);
		ctl.value="";			
	    if (ctl.tagName !="SELECT" && ctl.type != "hidden") 
	    {
		  ctl.focus();
		}		
		return true;
	}
	else
		return false;
}
function AskDlg(msg)
{
	return confirm(msg);
}
function showmsg(ctl,text,Path)
{
	var oPopup = window.createPopup();
	var _width=text.length*14+30;
	var _height=-36;
	text='<DIV NOWRAP align=center STYLE="height:28px; background:#FFFFdd; border:1px solid #575757; padding:4px;"><IMG vspace=1 align=absmiddle src="'+Path+'Images/icon_err.gif"><font style="font-size:13px;" color=#DC0C0C>&nbsp;'+text+'</font></DIV>'

	oPopup.document.body.innerHTML=text;	
	oPopup.show(0, _height, _width, 28,ctl);	
}
function ArrayObj(x,y)
{
	this.length=x;
	for(var i = 0; i < this.length; i++)
		this[i] = new Array(y);
}
function selRow(id,ctl)
{
	copyArray(id);
	for(var i=document.all.gridList.rows.length-1;i>0;i--)
	{
		document.all.gridList.rows[i].cells[0].innerText="";
	}
	if(ctl!=null)
		ctl.cells[0].innerHTML="<img src='../../images/arrow.gif'>";
	selIndex=id;
}
function overRow(id)
{
	copyArray(id);
}
function selout()
{
	if(selIndex<0)
		selIndex=0;
	copyArray(selIndex);
}
function copyArray(id)
{
	window.document.all.sp.innerText=infoArray[id][1];
	window.document.all.sp1.innerText=infoArray[id][2];
	window.document.all.sp2.innerText=infoArray[id][3];
	window.document.all.sp3.innerText=infoArray[id][4];
}

//检查IP格式
function checkip(ctl) 
{ 
var scount=0; 
var ip = document.form3.ccc.value; 
var iplength = ip.length; 
var Letters = "1234567890."; 
for (i=0; i < document.form3.ccc.value.length; i++) 
  { 
   var CheckChar = document.form3.ccc.value.charAt(i); 
   if (Letters.indexOf(CheckChar) == -1) 
   { 
    showmsg (ctl,"IP地址格式不对!!，只能输入数字和“.”,格式为XXX.XXX.XXX.XXX 例如：192.168.0.1"); 
    document.form3.ccc.value=""; 
    document.form3.ccc.focus(); 
    return false; 
   } 
  } 

for (var i = 0;i<iplength;i++) 
  (ip.substr(i,1)==".")?scount++:scount; 
if(scount!=3) 
{ 
  showmsg (ctl,"IP地址格式不对!，只能输入数字和“.”,格式为XXX.XXX.XXX.XXX 例如：192.168.0.1"); 
    document.form3.ccc.value=""; 
    document.form3.ccc.focus(); 
  return false; 
} 

first = ip.indexOf("."); 
last = ip.lastIndexOf("."); 
str1 = ip.substring(0,first); 
subip = ip.substring(0,last); 
sublength = subip.length; 
second = subip.lastIndexOf("."); 
str2 = subip.substring(first+1,second); 
str3 = subip.substring(second+1,sublength); 
str4 = ip.substring(last+1,iplength); 

if (str1=="" || str2=="" ||str3== "" ||str4 == "") 
{showmsg (ctl,"数字不能为空！格式为XXX.XXX.XXX.XXX 例如：192.168.0.1"); 
    document.form3.ccc.value=""; 
    document.form3.ccc.focus(); 
return false; 
} 
if (str1< 0 || str1 >255) 
{showmsg (ctl,"数字范围为0~255！"); 
    document.form3.ccc.value=""; 
    document.form3.ccc.focus(); 
    return false; 
} 
else if (str2< 0 || str2 >255) 
{showmsg (ctl,"数字范围为0~255！"); 
    document.form3.ccc.value=""; 
    document.form3.ccc.focus(); 
return false; 
} 
else if (str3< 0 || str3 >255) 
{showmsg (ctl,"数字范围为0~255！"); 
    document.form3.ccc.value=""; 
    document.form3.ccc.focus(); 
return false; 
} 
else if (str4< 0 || str4 >255) 
{showmsg (ctl,"数字范围为0~255！"); 
    document.form3.ccc.value=""; 
    document.form3.ccc.focus(); 
return false; 
} 
window.document.forms[0].submit();
} 

//函数名：fucCheckNUM
//功能介绍：检查是否为数字
//参数说明：要检查的数字
//返回值：1为是数字，0为不是数字
function fucCheckNUM(ctl,NUM)
{
 var i,j,strTemp;
 strTemp="0123456789"; 
 for (i=0;i<NUM.length;i++)
 {
  j=strTemp.indexOf(NUM.charAt(i)); 
  if (j==-1)
  {   
  return false;
  }
 } 
 return true;
}

function setAttach()
{
  var ReturnValue=window.showModalDialog("../../../upLoad.aspx?FileAdd=1","","help:no;scroll:no;status:no;dialogWidth:400px;dialogHeight:250px");
  if(ReturnValue!=null)
  {
     if(document.all.edFileId.value!="")
     {
	     document.all.edFileId.value=document.all.edFileId.value+","+ReturnValue.ID;
	     document.all.edfileName.value=document.all.edfileName.value+","+ReturnValue.Name;
	 }
	 else
	 {
	     document.all.edFileId.value=ReturnValue.ID;		    
	     document.all.edfileName.value=ReturnValue.Name;	 
	 }
  }  
}

function setUser(ctl,_ctl)
{
   var ReturnValue=window.showModalDialog("seluser.aspx","","help:no;scroll:no;status:no;dialogWidth:460px;dialogHeight:360px");
   if(ReturnValue!=null)
   {
        ctl.value=ReturnValue.Name;
	    _ctl.value=ReturnValue.ID;  
   }
}

function OthersetUser(ctl,_ctl)
{
   var ReturnValue=window.showModalDialog("../../plan/dlg/seluser.aspx","","help:no;scroll:no;status:no;dialogWidth:460px;dialogHeight:360px");
   if(ReturnValue!=null)
   {
        ctl.value=ReturnValue.Name;
	    _ctl.value=ReturnValue.ID;  
   }
}

function setDepart(ctl,_ctl)
{
   var ReturnValue=window.showModalDialog("Depart.aspx","","help:no;scroll:no;status:no;dialogWidth:460px;dialogHeight:360px");
   if(ReturnValue!=null)
   {
        ctl.value=ReturnValue.Name;
	    _ctl.value=ReturnValue.ID;  
   }
}

function OthersetDepart(ctl,_ctl)
{
   var ReturnValue=window.showModalDialog("../../plan/dlg/Depart.aspx","","help:no;scroll:no;status:no;dialogWidth:460px;dialogHeight:360px");
   if(ReturnValue!=null)
   {
        ctl.value=ReturnValue.Name;
	    _ctl.value=ReturnValue.ID;  
   }
}

//日期加number1天
function DayClick(ctl,_ctl,number1)
{   
    if(ctl.value=="")
    {
        alert("请先选择结束日期!");
        return;
    }
    var str = ctl.value;
    var arr = str.split("-");
    var d = new Date(parseInt(arr[0],10),parseInt(arr[1],10)-1
                     ,parseInt(arr[2],10));
    DateAdd("d",number1,d);       
    _ctl.value=DateToStr(d); 
}

//日期转换成字符串
function DateToStr(dt){
var str="";
if(dt.getFullYear){
  var y,m,d;
  y=dt.getFullYear();
  m=dt.getMonth()+1;  //1-12
  d=dt.getDate();
  str=""+y+"-"+m+"-"+d;
}
return str;
}

//字符串转换成日期
function StrToDate(strDate){
var splitArray;
var str="";
str=strDate;
splitArray=str.split("-")
if(splitArray.length!=3)
  return new Date();
for(var i=0; i<splitArray.length; i++)
{
  if( isNaN(splitArray) ) return new Date();
}
return new Date(splitArray[0],splitArray[1]-1,splitArray[2]);
}

//javascript　的自定义DateAdd函数
function   DateAdd(interval,number,date)   
  {  
    
          switch(interval)   
          {   
                  case   "y"   :   {   
                          date.setFullYear(date.getFullYear()+number);   
                          return   date;   
                          break;   
                  }   
                  case   "q"   :   {   
                          date.setMonth(date.getMonth()+number*3);   
                          return   date;   
                          break;   
                  }   
                  case   "m"   :   {   
                          date.setMonth(date.getMonth()+number);   
                          return   date;   
                          break;   
                  }   
                  case   "w"   :   {   
                          date.setDate(date.getDate()+number*7);   
                          return   date;   
                          break;   
                  }   
                  case   "d"   :   {   
                          date.setDate(date.getDate()+number);   
                          return   date;   
                          break;   
                  }   
                  case   "h"   :   {   
                          date.setHours(date.getHours()+number);   
                          return   date;   
                          break;   
                  }   
                  case   "m"   :   {   
                          date.setMinutes(date.getMinutes()+number);   
                          return   date;   
                          break;   
                  }   
                  case   "s"   :   {   
                          date.setSeconds(date.getSeconds()+number);   
                          return   date;   
                          break;   
                  }   
                  default   :   {   
                          date.setDate(d.getDate()+number);   
                          return   date;   
                          break;   
                  }   
          }   
  }   
  
 

//判断密码两次输入是否一样
function checkpwd(ctl,_ctl)
{

    if(ctl.value!=_ctl.value)
    {
        alert("两次密码不一样!");
        ctl.focus();
        return false;
    }
    else
    {    
      chkFrm();       
    }
}
//AJAX的调用
function AjaxObject()
{
	this.sendMsg=function(doc,url)
	{	var poster;
		try
		{			
			poster= new ActiveXObject("Msxml2.XMLHTTP");
			poster.open("Post",url,false);
			poster.setRequestHeader("Content-Type","text/xml");
			poster.send(doc);			
			return poster.responseText;
		}
		catch(e)
		{
		   try
		   {
			    poster=new ActiveXObject("Microsoft.XMLHTTP");			
				poster.open("Post",url,false);
				poster.setRequestHeader("Content-Type","text/xml");
				poster.send(doc);
				return poster.responseText;
			}
			catch(e2)
			{		      
		      return 'ERROR';
		    }
		}
	}
}
//将一个TABLE的内容变成一个XML
function TableToXML(Columns,Table)
{

	var strCol="",strRow="",strXML="";
	
	for(var i=1;i<Table.rows.length;i++)
	{
        strCol="";
		for(var j=0;j<Columns.length;j++)
		{			                        
			strCol+="<"+Columns[j]+">"+Table.rows[i].cells[j].innerText+"</"+Columns[j]+">";
		}
		strRow+="<row>"+strCol+"</row>";
	}

	strXML="<root>"+strRow+"</root>";;
	
	return strXML;
}
//检查输入的是否是合法的数字
function chkNum()
{
	var obj=event.srcElement;
	var st="0123456789."; 
	if (obj.value.length >0)
	{
	    var str = obj.value;	    		
	    var j;
		for (i=0;i<str.length;i++)
		{
			j=st.indexOf(str.charAt(i)); 
			if (j==-1)
			{
				alert("这里必须输入合法的数字！");		
				obj.focus();
				return;
	         }	      
	    }
	}
}
function seletedAirport()
{
	document.getElementById("edAirportID").value=document.getElementById("Airport").value;
}


var step = 30;

function prorgt()
{
    while($("proccc").scrollLeft<828)
    {
        $("proccc").scrollLeft = $("proccc").scrollLeft+step;
    }
    $("proccc").scrollLeft = 828;
    $("srbtn").style.backgroundImage = "url(images/righta.gif)";
    $("slbtn").style.backgroundImage = "url(images/leftb.gif)";
}

function prolft()
{
    while($("proccc").scrollLeft>0)
    {
       $("proccc").scrollLeft = $("proccc").scrollLeft-step;
    }
    $("proccc").scrollLeft = 0;
    $("srbtn").style.backgroundImage =  "url(images/rightb.gif)";
    $("slbtn").style.backgroundImage = "url(images/lefta.gif)";
}
String.prototype.isEmail = function()
{
    return (/^(\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)$/.test(this.Trim()));
}

//等比缩放

var flag=false;
function thispic1(ImgD,I_width,I_height)
{
	var image=new Image();
	var iwidth = I_width; //定义允许图片宽度，当宽度大于这个值时等比例缩小


	var iheight = I_height; //定义允许图片高度，当宽度大于这个值时等比例缩小


	image.src=ImgD.src;
	if(image.width>0 && image.height>0)
	{
		flag=true;
		if(image.width/image.height>= iwidth/iheight)
		{
			if(image.width>iwidth)
			{ 
				ImgD.width=iwidth;
				ImgD.height=(image.height*iwidth)/image.width;
			}
			else
			{
				ImgD.width=image.width; 
				ImgD.height=image.height;
			}
			ImgD.alt=image.width+"×"+image.height;
		}
		else
		{
			if(image.height>iheight)
			{ 
				ImgD.height=iheight;
				ImgD.width=(image.width*iheight)/image.height; 
			}
			else
			{
				ImgD.width=image.width; 
				ImgD.height=image.height;
			}
			ImgD.alt=image.width+"×"+image.height;
		}
	}
}
var OpenedWindow;
function OpenWindow(url,width,height,locationWidth,locationHeight)
{
   OpenedWindow =  window.open(url,'','height='+height+',width='+width+',toolbar=no,menubar=no,resizable=no,location=no,status=no');
   //hdc.moveTo((screen.width-locationWidth)/2,(screen.height-locationHeight)/2);
  // return hdc;
}

///生成随机数
rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd(){
 rnd.seed = ( rnd.seed*9301+49297) % 233280;
 return rnd.seed/(233280.0);
}

function rand(number) {
    return Math.ceil(rnd()*number);
}



