﻿// JScript 文件

function DoClick()
{
	if (event.srcElement.alt=="删除")
	event.returnValue=confirm("您确定要删除吗?");
}
document.onclick=DoClick;

//模式对话框
function ShowDialog1(url,iWidth,iHeight,iLeft,iTop) { 
    window.showModalDialog( url,window,"dialogHeight: "+iHeight+"px;dialogWidth: "+iWidth+"px;dialogTop: "+iTop+"; dialogLeft: "+iLeft+"; resizable: no; status: no;scroll:yes");
}

//模式对话框 居中打开
function ShowDialog(url,iWidth,iHeight) { 
    var iLeft = (screen.availWidth -iWidth)/2;
	var iTop = (screen.availHeight -iHeight)/2;
    window.showModalDialog( url,window,"dialogHeight: "+iHeight+"px;dialogWidth: "+iWidth+"px;dialogTop: "+iTop+"; dialogLeft: "+iLeft+"; resizable: no; status: no;scroll:yes");
}

//模式对话框，居中打开,传一个对象参数
function ShowDialog2(url,obj,iWidth,iHeight) { 
    var iLeft = (screen.availWidth -iWidth)/2;
	var iTop = (screen.availHeight -iHeight)/2;
    window.showModalDialog( url,obj,"dialogHeight: "+iHeight+"px;dialogWidth: "+iWidth+"px;dialogTop: "+iTop+"; dialogLeft: "+iLeft+"; resizable: no; status: no;scroll:yes");
}
 
//非模式对话框
//2008-07-01 黄烈修改：在屏幕中央显示窗口
function openwin(winURL,form1,iWidth,iHeight)
{
	var iNewX = (screen.availWidth -iWidth)/2;
	var iNewY = (screen.availHeight -iHeight)/2;
    var sfeature = 'status=no,resizable=yes,menu=no,scrollbars=yes,width='+iWidth+'px,height='+iHeight+'px,left=' +iNewX +'px,top=' + iNewY + 'px';
	var w=window.open(winURL,form1,sfeature);
	w;
}

//非模式对话框
function openwin1(winURL,form1,iWidth,iHeight,iLeft,iTop)
{
    var sfeature = 'status=yes,resizable=no,toolbar=no,menubar=no,scrollbars=yes,width='+iWidth+'px,height='+iHeight+'px,left=' +iLeft +'px,top=' + iTop + 'px';
	var w=window.open(winURL,form1,sfeature);
	w;
}

//小数点后面保留几位
function   MyRound(number,i){   
  var   y=Math.pow(10,i);   
  number=number   *   y;   
  number=Math.round(number)   /y;   
  return   number;   
  }   

//字符串换行 num，多少个一行，换行后前面补几个空格 ,  flag , 0 加<BR> ，1加 \n\r
function FormatStrToLine(str,num,blank,flag)
{
    if (str==null)
    {
        return "";
    }
    var slength = str.length;
    //不够行，直接返回
    if (slength<=num)
    {
        return str;
    }
    //[初始化空格数
    var tempblank = "";
    for (var i = 0 ; i < blank ; i++ )
    {
        if (flag==0)
        {
            tempblank +="&nbsp;";
        }
        else
        {
            tempblank +=" ";
        }
    }
    
    var tempstr ="";
    while (str.length>num)
    {
        tempstr += str.substr(0,num);
        if (flag==0)
        {
            tempstr += "<br/>";
        }
        else
        {
             tempstr += "\n\r";
        }
        tempstr += tempblank;
        str = str.substr(num  );
    }
    
    //最后一段再加
     tempstr += str;
     return tempstr;
 }
 
//增加字符串的方法
String.prototype.Trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.LTrim = function()
{
    return this.replace(/(^\s*)/g, "");
}
String.prototype.Rtrim = function()
{
    return this.replace(/(\s*$)/g, "");
}
 
String.prototype.replaceAll  = function(s1,s2){    
return this.replace(new RegExp(s1,"gm"),s2);    
} 
 

//过滤数组里的重复数据
Array.prototype.strip=function()
{
 if(this.length<2) return [this[0]]||[];
 var arr=[];
 for(var i=0;i<this.length;i++)
 {
  arr.push(this.splice(i--,1));
  for(var j=0;j<this.length;j++)
  {
   if(this[j]==arr[arr.length-1])
   {
    this.splice(j--,1);
   }
  }
 }
 return arr;
}

//显示当前日期
function showdate(){
    var today=new Date();
    date=today.getDate();
    var strdate = "";
    if (date<10)
    {
    strdate = "0"+date;
    }else
    {
    strdate = date.toString();
    }
    month=today.getMonth();
    month=month+1;
    var strmonth ="";
    if (month<10)
    {
    strmonth = "0"+month;
    }else
    {
    strmonth = month.toString();
    }
    year=today.getYear();
    var nowDate=year+'-'+strmonth+'-'+strdate;
    //document.form1.text1.value=nowDate;
    return nowDate;
}
//显示当前时间
function showtime(){
    var d, s="";
    var c = ":";
    d = new Date();
    var strHours = "";
    if (d.getHours()<10)
    {
	    strHours = "0" + d.getHours().toString();
    }
    else
    {
	    strHours = d.getHours().toString();
    }
    s += strHours + c;

    var strMinutes = "";
    if (d.getMinutes()<10)
    {
	    strMinutes = "0" + d.getMinutes().toString();
    }
    else
    {
	    strMinutes = d.getMinutes().toString();
    }
    s += strMinutes + c;

    var strSeconds = "";
    if (d.getSeconds()<10)
    {
	    strSeconds = "0" + d.getSeconds().toString();
    }
    else
    {
	    strSeconds = d.getSeconds().toString();
    }
    s += strSeconds ;
    //s += d.getMilliseconds();
    return s;
    //document.form1.text2.value=s;
}

