﻿// JScript 文件

function $(id)
{
    if(document.getElementById)
    {
        return document.getElementById(id);
    }
    else if(document.all)
    {
        return document.all(id);
    }
    else
    {
        return null;
    }
}


//以下是该函数的参数说明
/*
    isDropDownList:选择是否为下拉式列表框，如果是请传入true,否则传入false;
    obj:待绑定对象的引用，要将返回对象的bindProperty属性赋值的对象,可用$(id)来获得，其中id为对应均元素的客户端id;如果没有则用传 null
    url:弹出式窗口的地址,其中可带参数
    width:弹出窗口的宽度
    height:弹出窗口的高度
    bindProperty:绑定的属性的名称;
    returnProperty:返回属性的名称;
    
    *其中必填参数：isDropDownList,obj,url
    详细的使用过程请参考页面:~/App_Government/EnterpriseInfo/Default.aspx
*/

function updatePageElements(url,width,height,elementIds,properties)
{
    if(url==undefined||url=="")
    {
        alert("没有给弹出式对话框指定url");
        return;
    }
    if(height==undefined)
    {
        height=30;
    }
    if(width==undefined)
    {
        width=150;
    }
    var features="dialogHeight="+height+"px;dialogWidth="+width+"px;status=no;location=no;scroll=yes;dialogLeft="+event.clientX+"px;dialogTop="+event.clientX+"px;";
    var value=window.showModalDialog(url,null,features);
    if(typeof(value)=="object")
    {

        if(typeof(elementIds)=="object"&&typeof(properties)=="object")
        {
            for(var i=0;i<elementIds.length;i++)
            {
                if(value[properties[i]]!=undefined)
                {
                    $(elementIds[i]).value=value[properties[i]];
                }
            }
         }

            //return value;
    }
    else
    {
        alert("Return undefined!");
    }

}
function updateTextBoxByRef(isDropDownList,obj,url,width,height,bindProperty,returnProperty)
{
    if(url==undefined||url=="")
    {
        alert("没有给弹出式对话框指定url");
        return;
    }
    if(height==undefined)
    {
        height=30;
    }
    if(width==undefined)
    {
        width=150;
    }
    var features="dialogHeight="+height+"px;dialogWidth="+width+"px;status=no;location=no;scroll=yes;dialogLeft="+event.clientX+"px;dialogTop="+event.clientX+"px;";
    var value=window.showModalDialog(url,null,features);

    if(value)
    {
        if(isDropDownList==true)
        {
            bindProperty="text";
            returnProperty="value";
        }
        if(typeof(value)=="string")
        {
            if(obj!=null)
            {
                obj.value=value;
            }
            return value;
        }
        
        else if(typeof(value)=="object")
        {
            if(obj!=null)
            {
                if(bindProperty!=undefined)
                {
                    if(value[bindProperty])
                    {
                        obj.value=value[bindProperty];
                    }
                    else
                    {
                        alert('绑定属性不存在');
                    }
                 }
            }
            if(returnProperty)
            {
                if(value[returnProperty])
                {
                    return value[returnProperty];
                }
                else
                {
                    alert('返回属性不存在');
                }
            }
        }
    }

}

function updateTextBoxById(isDropDownList,id,url,width,height,bindProperty,returnProperty)
{
    if(url==undefined)
    {
        url="default2.aspx";
    }
    if(height==undefined)
    {
        height=50;
    }
    if(width==undefined)
    {
        width=150;
    }
    var features="dialogHeight="+height+"px;dialogWidth="+width+"px;status=no;location=no;scroll=yes;dialogLeft="+event.clientX+"px;dialogTop="+event.clientX+"px;";
    var value=window.showModalDialog(url,null,features);
    var obj=$(id);
    if(value)
    {
        if(isDropDownList==true)
        {
            bindProperty="text";
            returnProperty="value";
        }
        if(typeof(value)=="string")
        {
            obj.value=value;
            return value;
        }
        else if(typeof(value)=="object")
        {

            if(obj!=null)
            {
                if(bindProperty!=undefined)
                {
                    if(value[bindProperty])
                    {
                        obj.value=value[bindProperty];
                    }
                    else
                    {
                        alert('绑定属性不存在');
                    }
                 }
            }
            if(returnProperty)
            {
                if(value[returnProperty])
                {
                    return value[returnProperty];
                }
                else
                {
                    alert('返回属性不存在');
                }
            }
            
        }
    }
}


function getPrjID(id,url,width,height)
{
    
    var features="dialogHeight="+height+"px;dialogWidth="+width+"px;status=no;location=no;scroll=yes;dialogLeft="+event.clientX+"px;dialogTop="+event.clientX+"px;";
    var value=window.showModalDialog(url,null,features);
    
    var obj=document.getElementById(id);

    if(value==undefined)
    {
        
    }
    else
    {
        obj.value=value
    }   


}


function updateDLLReturnValue(Id)
{
    var obj=document.getElementById(Id);
    if(obj!=undefined)
    {
        var value=new Object();
        value["value"]=obj.value;
        value["text"]=obj.options[obj.selectedIndex].innerHTML;
        window.returnValue=value;
        window.close();
    }
}
