﻿

//============================检查浏览器*start========================================
//设置允许的浏览器
var G_browsers=new Array(
"MSIE 6.0",
"MSIE 7.0",
"MSIE 8.0","MSIE 9.0")


function checkBrowser()
{
    var userAgent=navigator.userAgent;
    var canUse=false;
    for(var i=0;i<G_browsers.length;i++){
        if(userAgent.indexOf(G_browsers[i])>-1){
            canUse=true;
            break;
        }
    }
    //if(navigator.userAgent.indexOf("MSIE 7.0") == -1 && navigator.userAgent.indexOf("MSIE 6.0") == -1 && navigator.userAgent.indexOf("MSIE 8.0") == -1){
    if(!canUse){
        location.replace("checkBrowser.aspx");
        return;
    }
    
    if(Detect())
    {
      alert("您的网页开启或者安装了 [拦截弹出窗口] 程序，可能会对 [建造师系统] 使用产生影响，\r\n请您最好先关闭 [拦截弹出窗口] 程序，然后进入系统！");
    }  
}
//检查是否允许弹出窗口
function Detect()
{
	var e = false;
	var pw1 = null;
	var pw2 = null;
	try
	{
		do
		{
			var d = new Date();
			var wName = "ptest_" + d.getTime();
			var testUrl ="checkwinopen.htm";
			pw1 = window.open(testUrl,wName,"width=0,height=0,left=5000,top=5000",true);
		    
			if (null == pw1 || true == pw1.closed)
			{
				e = true;
				break;
			}			
			pw1.close();
			pw1 = null;
		}
		while(false);
	}
	catch(ex)
	{
		e = true;
	}
	if (null != pw1)
	{
		try { if (!pw1.closed) pw1.close(); } catch(ex){}
	}
	return e;
}
//============================检查浏览器*end========================================

///弹出dialog页面窗口,不带参数
//返回模式窗口返回值
function openDialogWindow(sUrl,oArgus,iWidth,iHeight,wintitle)
{
    if(arguments.length<1){
        alert("openDialogWindow方法:缺少url参数!");
        return;
    }
    if(arguments.length<2){
        oArgus=window;
    }
    if(arguments.length<3){
        iWidth = 800;
    }
    if(arguments.length<4){
        iHeight=700;
    }
    
	var urld = "../uitools/dproxy.aspx?url="+escape(sUrl) + (typeof(wintitle)=="string"?"&wintitle=" + escape(wintitle):"");
	return showDialog(urld,oArgus,iWidth,iHeight);
}
//dialog窗体
//返回模式窗口返回值
function showDialog(sUrl,oArgus,iWidth,iHeight)
{
	if(!oArgus) oArgus=null;
	if(!iWidth)	iWidth=400;
	if(!iHeight) iHeight=300;
	
	var feature = 'dialogWidth:'+iWidth+'px;dialogHeight:'+iHeight+'px;scroll:auto;status:yes;resizeable:no;edge:raised';
	return window.showModalDialog(sUrl,oArgus,feature)
	
}
//全屏锁定，并显示提示
 function lockScreen(msg){
         $.blockUI({ 
             css: { 
                border: 'none', 
                padding: '15px', 
                backgroundColor: '#000', 
                '-webkit-border-radius': '10px', 
                '-moz-border-radius': '10px', 
                opacity: .5, 
                color: '#fff' 
            },
            message:msg,// "<h1>系统正在读取数据,请稍候...</h1>", 
            timeout: 300000  //超时5分钟
        }); 
    }
    //全屏解除锁定
    function unLockScreen(){
        $.unblockUI();
    }
    
    //将字符串转成Date类型
    //支持字符串格式：yyyy-MM-dd  yyyy-m-d  yy-MM-dd yy-m-d
    function parseDate(strDate){
        var _p=/^((?:(?:19)|(?:20)){0,1}[0-9]{2})[-\/]((?:0[1-9])|(?:1[012])|[1-9])[-\/]((?:0[1-9])|(?:[12][0-9])|(?:3[01])|[1-9])$/i;
        var _r=strDate.match(_p);
        if(_r==null) return null;
        
        if(_r.length!=4) return null;
        
        var _date=new Date(_r[1],_r[2],_r[3]);
        return _date;

    }
    //检查键盘按下的时候是数字（用于限制数字输入）
    var key_isNumber = function(e) {
        if ($.browser.msie) {
            if (((event.keyCode > 47) && (event.keyCode < 58)) ||
                  (event.keyCode == 8)) {
                return true;
            }
            else {
                return false;
            }
        }
        else {
            if (((e.which > 47) && (e.which < 58)) ||
                  (e.which == 8)) {
                return true;
            }
            else {
                return false;
            }
        }
    }
