﻿// JScript 文件

LoadScript("/JS/JerryDate/WdatePicker.js");
function LoadScript(url)
{
  var script = document.createElement("script");
  script.setAttribute("src", url); 
　//添加到文档中
  document.getElementsByTagName("head")[0].appendChild(script);
}

//Div点击显示隐藏
function setdiv(e,val) 
{     
    if(document.getElementById(e+val).style.display!="inline") 
    {        
        for(var i=0;i<200;i++)
        {
            if(document.getElementById(e+i)!=null)
            {
                document.getElementById(e+i).style.display = "none"; 
            }
        }        
        document.getElementById(e+val).style.display = "inline";        
        if((document.getElementById(e+val).offsetWidth + document.getElementById(e+val).offsetLeft) > document.body.clientWidth)
        {
            document.getElementById(e+val).style.left = document.getElementById(e+val).offsetLeft - (document.getElementById(e+val).offsetWidth + document.getElementById(e+val).offsetLeft - document.body.clientWidth);
            //document.getElementById(e+val).style.top =document.getElementById(e+val).offsetTop +30;
            if(document.getElementById(e+val).style.left < 30)
            {
                document.getElementById(e+val).style.left=30;
            }
        }
    } 
    else 
    {    
        document.getElementById(e+val).style.display = "none"; 
    } 
}
function setdivOver(e) 
{      
    document.getElementById(e).style.display = "inline";  
}
function setdivOut(e) 
{  
    document.getElementById(e).style.display = "none";  
}

//以下是拖动DIV的
var divMove=false; 
var divtop=0,divleft=0;     
function StartDrag(obj)                       
{
    if(event.button==1&&event.srcElement.tagName.toUpperCase()=="DIV")
    {
        obj.setCapture();
        obj.parentNode.style.background="#cccccc";
        divtop = event.clientY - getY(obj);
        divleft= event.clientX - getX(obj);
        divMove=true;        
    } 
}

function Drag(obj)                   
{
    if(divMove)
    { 
        var oldwin=obj.parentNode.parentNode.parentNode.parentNode.parentNode;
        oldwin.style.left=  event.clientX-divleft -2;
        oldwin.style.top=event.clientY-divtop - 4;
       
    } 
 }

function StopDrag(obj)
{
    obj.parentNode.style.background="#EFEFEF";
    obj.releaseCapture();
    divMove=false;
} 

function getX(obj){
	var ParentObj=obj;
	var divX=obj.offsetLeft;
	while(ParentObj=ParentObj.offsetParent){
		divX+=ParentObj.offsetLeft;
	}
	return divX;
}

function getY(obj){
	var ParentObj=obj;
	var divY=obj.offsetTop;
	while(ParentObj=ParentObj.offsetParent){
		divY+=ParentObj.offsetTop;
	}
	return divY;
}
//拖动Div End




//公司选择
function openCompany(IDControl,NameControl)
{
    if(window.showModalDialog!=null)
    {
        showModalDialog('/SelectForm/SelectCompanyT.aspx?IDControl=' + IDControl + '&NameControl=' + NameControl + '',window,'dialogWidth:800px;DialogHeight=480px;scroll=1;help=0;Status=no;resizable:Yes');
    }
    else
    {
        window.open('/SelectForm/SelectCompanyT.aspx?IDControl=' + IDControl + '&NameControl=' + NameControl + '',o,"modal=yes") 
    }
}

//部门选择
function openDepartment(IDControl,NameControl)
{
    if(document.all)
    {
        showModalDialog('/SelectForm/SelectDepartmentT.aspx?IDControl=' + IDControl + '&NameControl=' + NameControl + '',window,'dialogWidth:800px;DialogHeight=480px;scroll=1;help=0;Status=no;resizable:Yes');
    }
    else
    {
        window.open('/SelectForm/SelectDepartmentT.aspx?IDControl=' + IDControl + '&NameControl=' + NameControl + '',window,"modal=yes,Height=480px,menubar=no,toolbar=no,location=no;") 
    }    
}
//选择代理
function openAgent(IDControl,NameControl)
{
    if(document.all)
    {
        showModalDialog('/Admin/Product/SelectAgentT.aspx?IDControl=' + IDControl + '&NameControl=' + NameControl + '',window,'dialogWidth:800px;DialogHeight=480px;scroll=1;help=0;Status=no;resizable:Yes');
    }
    else
    {
        window.open('/Admin/Product/SelectAgent.aspx?IDControl=' + IDControl + '&NameControl=' + NameControl + '',window,"modal=yes,Height=480px,menubar=no,toolbar=no,location=no;") 
    }    
}

//function Select(ID,Name)
//{        
//    var IDControl = '<%= Request.QueryString["IDControl"] %>';
//    var NameControl = '<%= Request.QueryString["NameControl"] %>';        
//    //当有指定的按钮取值的时候
//    if(IDControl!=null && IDControl !='undefined' && NameControl!=null && NameControl !='undefined' )
//    {       
//        if(document.all)
//        {                
//            dialogArguments.form1.<%= Request.QueryString["IDControl"]%>.value = ID;
//            dialogArguments.form1.<%= Request.QueryString["NameControl"]%>.value = Name;                             
//        }
//        else
//        {                
//            window.parent.opener.document.getElementById('<%= Request.QueryString["IDControl"]%>').value = ID;
//            window.parent.opener.document.getElementById('<%= Request.QueryString["NameControl"]%>').value = Name;                
//        }
//    }
//    else
//    {
//        //以下是默认按钮
//        if(document.all)
//        {
//            dialogArguments.form1.txtID.value = ID;
//            dialogArguments.form1.txtName.value = Name;                             
//        }
//        else
//        {
//            window.parent.opener.document.getElementById('txtID').value = ID;
//            window.parent.opener.document.getElementById('txtName').value = Name;
//        }
//    }                
//    //关闭
//    if(document.all)
//    {
//        window.close();
//        window.close();
//    }
//    else
//    {
//        window.parent.close();
//    }
//    
//}

//用户选择
function openCompanyUser(IDControl,NameControl)
{
    showModalDialog('/SelectForm/SelectCompanyUserT.aspx?IDControl=' + IDControl + '&NameControl=' + NameControl + '',window,'dialogWidth:800px;DialogHeight=480px;scroll=1;help=0;Status=no;resizable:Yes');
}

//选择管理员
function openManage(IDControl,NameControl)
{
    showModalDialog('/SelectForm/SelectManageT.aspx?IDControl=' + IDControl + '&NameControl=' + NameControl + '',window,'dialogWidth:800px;DialogHeight=480px;scroll=1;help=0;Status=no;resizable:Yes');
}

//选择产品
function openProduct(IDControl,NameControl)
{
    showModalDialog('/Admin/Product/SelectProductT.aspx?IDControl=' + IDControl + '&NameControl=' + NameControl + '',window,'dialogWidth:800px;DialogHeight=480px;scroll=1;help=0;Status=no;resizable:Yes');
}

//选择供应员
function openSupplier(IDControl,NameControl)
{
    showModalDialog('/SelectForm/SelectSupplierT.aspx?IDControl=' + IDControl + '&NameControl=' + NameControl + '',window,'dialogWidth:800px;DialogHeight=480px;scroll=1;help=0;Status=no;resizable:Yes');
}

//选择供应员 是否显示临时供应商
function openSupplier(IDControl,NameControl,Type)
{
    showModalDialog('/SelectForm/SelectSupplierT.aspx?IDControl=' + IDControl + '&NameControl=' + NameControl + '&Type=' + Type,window,'dialogWidth:800px;DialogHeight=480px;scroll=1;help=0;Status=no;resizable:Yes');
}


//自动控件图片对像大小
function DrawImage(ImgD,Width,Height)
{     
    var image=new Image(); 
    image.src=ImgD.src; 
    if(image.width>0 && image.height>0)
    {    
        if(image.width/image.height>= Width/Height)
        { 
            if(image.width>Width)
            { 
                ImgD.width=Width; 
                ImgD.height=(image.height*Height)/image.width; 
            }
            else
            { 
                ImgD.width=image.width; 
                ImgD.height=image.height; 
            } 
            /*ImgD.alt="bigpic" */ 
        } 
        else
        { 
            if(image.height>Height)
            { 
                ImgD.height=Height; 
                ImgD.width=(image.width*Height)/image.height;              
            }
            else
            { 
                ImgD.width=image.width; 
                ImgD.height=image.height; 
            }
        }
    } 
} 
