function jsGroupTypeDetail(){

};

jsGroupTypeDetail.PageState=null;
jsGroupTypeDetail.userID=App.CurrentUser(App.Virsion.main).UserID;

$(function(){
    $("#htxtCNName").focus();
    jsGroupTypeDetail .PageState=App.query("PageState");
    if(jsGroupTypeDetail.PageState=="Add")
    {
        if(App.query("TypeID")!=null)
        {
                $("#htxtParentTypeName").val(App.query("TypeName"));
                $("#hhidParentTypeID").val(App.query("TypeID"));
        }
    }
    if(jsGroupTypeDetail.PageState=="Edit")
    {
         jsGroupTypeDetail.BindDataByID();/*修改时初始化控件*/
     }         
});

jsGroupTypeDetail.ChkGroupName=function(strName){
    
}

/*确定*/
jsGroupTypeDetail.ConfirmBtnClick=function(){
        var result=-1;
        var formIndex=q("FormIndex");
        var loadAction=q("LoadAction");       
        var strName=$.trim($("#htxtCNName").val()).split('\"').join('“');strName=strName.split('\'').join('‘');  
        var pid=$("#hhidParentTypeID").val()==""?0:$("#hhidParentTypeID").val();
        if(strName!="")
        {
            if(jsCommonLogic.selColumnData("count(*)","T_GROUPDEF","where GROUPNAME='"+strName+"' and GROUPNAME<>'"+$("#hidetxtName").val()+"' and PID="+pid)==0)
            {
                var entity=jsEntity.CreateEntityByTableName_access("T_GROUPDEF");    
                entity.Fields.PID=pid;
                entity.Fields.GROUPNAME=strName;
              
                if(jsGroupTypeDetail.PageState=="Edit")
                {
                        entity.Fields.ID=$("#hideID").val();
                        result=entity.Update(entity);
                }
                else
                {  
                        entity.Fields.USERID=jsGroupTypeDetail.userID;
                        result=entity.Insert(entity);
                }
               DBReader.DisposeEntity(entity);
               if(result)
                {
                        if(loadAction!=null&&loadAction!=undefined)
                        {
                             ShowWindow.opener.execScript(formIndex,"jsIndexPage.freshItemPage('tab-addressBook','"+loadAction+"')");
                        }
                         ShowWindow.close();     
                }
                else
                {
                        alert("操作失败！");
                }     
            }   
            else
            {
                alert("名称不能重复！");
            }    
        }
        else
        {
                alert("名称不能为空！");
        }
       result,formIndex,loadAction,strName,strEName=null;
      CollectGarbage();
};

/*取消*/
jsGroupTypeDetail.Cancel=function(){
     ShowWindow.close();
};

/*清空所属上级*/
jsGroupTypeDetail.resetDataItem=function(){
    $("#htxtParentTypeName").val("");
    $("#hhidParentTypeID").val("");
};

/*根据类型ID获得实体*/
jsGroupTypeDetail.GetTypeById=function(typeID){
        var entity=jsEntity.CreateEntityByTableName_access("T_GROUPDEF");      
        jsEntity.FillEntity(entity,"select * from T_GROUPDEF where ID="+typeID);
        return entity;
};

/*修改页面时绑定控件*/
jsGroupTypeDetail.BindDataByID=function(){
       var currentSelType=App.query("TypeID");
       var entity=jsGroupTypeDetail.GetTypeById(currentSelType); 
        
       if( entity.Fields.PID!=0)
       {
           var strParentName= jsCommonLogic.selColumnData("GROUPNAME","T_GROUPDEF","where ID="+entity.Fields.PID);  
           $("#htxtParentTypeName").val(strParentName);
       }
       
       $("#hhidParentTypeID").val(entity.Fields.PID);
       $("#htxtCNName").val(entity.Fields.GROUPNAME);
       $("#hidetxtName").val(entity.Fields.GROUPNAME);
       
       $("#hideID").val(entity.Fields.ID);        
        DBReader.DisposeEntity(entity);
        entity=null;
        currentSelBillType=null;
        CollectGarbage();
};

/*选择上级弹出框*/
jsGroupTypeDetail.GetGroupType=function(){
        var FormIndex=ShowWindow.getFormIdx();
        ShowWindow.ShowMoledDialog("Application/TeleSecretary/frmCommunication/frmGroupTree.htm?hideID="+$("#hideID").val()+"&FormIndex="+FormIndex+"&LoadAction=jsGroupTypeDetail.SetValue(@str)","所属上级",260,500);                 
};

/*根据弹出框中双击选择的上级设置类型值*/
jsGroupTypeDetail.SetValue=function(id,text)
{
    if(id!="")
    {
        $("#htxtParentTypeName").val(text);
        $("#hhidParentTypeID").val(id);
    }
}
