//获取当前网址，如： http://localhost:8083/myproj/view/my.jsp
var curWwwPath=window.document.location.href;
//获取主机地址之后的目录，如： myproj/view/my.jsp
var pathName=window.document.location.pathname;
var pos=curWwwPath.indexOf(pathName);
//获取主机地址，如： http://localhost:8083
var localhostPaht=curWwwPath.substring(0,pos);
//获取带"/"的项目名，如：/myproj
var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
//得到了 http://localhost:8083/myproj
var realPath=localhostPaht+projectName;

//获取url参数
function GetQueryString(name){
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return  decodeURI(r[2]); return null;
}
function closelayer(){
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}
function openDialogre(title,url,width,height){
    if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端，就使用自适应大小弹窗
        width='auto';
        height='auto';
    }else{//如果是PC端，根据用户设置的width和height显示。

    }
    parent.layer.open({
        type: 2,
        area: [width, height],
        title: title,
        maxmin: true, //开启最大化最小化按钮
        content: url ,
    });
}
function openDialogViewPre(title,url,width,height){

    if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端，就使用自适应大小弹窗
        width='auto';
        height='auto';
    }else{//如果是PC端，根据用户设置的width和height显示。

    }
    top.layer.open({
        type: 2,
        area: [width, height],
        title: title,
        maxmin: true, //开启最大化最小化按钮
        content: url ,
        btn: ['关闭'],
        btn1: function(index){
            top.layer.close(index);
            $.ajax({
                type:'post',
                url:realPath + '/a/previewController/deleteUrl',
                success:function(data){
                }
            })
        },
        end:function(){
            $.ajax({
                type:'post',
                url:realPath + '/a/previewController/deleteUrl',
                success:function(data){
                }
            })
        }
    });
}
function preview(title,url,width,height,type){
    if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端，就使用自适应大小弹窗
        width='auto';
        height='auto';
    }else{//如果是PC端，根据用户设置的width和height显示。

    }
    //var u = 'http://ow365.cn/?i=14411&furl='+url;
    if(url.indexOf("http://gangwan-app.oss-cn-hangzhou.aliyuncs.com")>-1) {
        var u = 'https://view.officeapps.live.com/op/view.aspx?src='+encodeContent(url);
    }else{
        var u = 'https://view.officeapps.live.com/op/view.aspx?src='+encodeContent(url);
    }

    function encodeContent(data){
        return encodeURI(data).replace(/&/g,'%26').
        replace(/\+/g,'%2B').replace(/\s/g,'%20').
        replace(/#/g,'%23').replace(/ /g,'%20');
        replace(/\//g,'%3F').replace(/=/g,'%3D');
    }

    if(type == 1){
        u = url;
    }
    parent.layer.open({
        type: 2,
        area: [width, height],
        title: title,
        maxmin: true, //开启最大化最小化按钮
        content:  u,
        btn: ['关闭'],
        cancel: function(index){
        }
    });
}


var chnNumChar = ["零","一","二","三","四","五","六","七","八","九"];
function NumberToChinese(num){
    var unitPos = 0;
    var strIns = '', chnStr = '';
    var needZero = false;

    if(num === 0){
        return chnNumChar[0];
    }

    while(num > 0){
        var section = num % 10000;
        if(needZero){
            chnStr = chnNumChar[0] + chnStr;
        }
        strIns = SectionToChinese(section);
        strIns += (section !== 0) ? chnUnitSection[unitPos] : chnUnitSection[0];
        chnStr = strIns + chnStr;
        needZero = (section < 1000) && (section > 0);
        num = Math.floor(num / 10000);
        unitPos++;
    }

    return chnStr;
}