
AuthorizationAdmin.Init();
/*--------主页涮新--------*/
function ProcMPageReload(){
    AuthorizationAdmin.Init();
    if(AuthorizationAdmin.Islogined)
    {
        ResetLoginState(true);
    }
    else
    {
        ResetLoginState(false);
    }
}
//设置控件值
function ResetLoginState(flag)
{
    if(flag)
    {
        if(AuthorizationAdmin.IsCurAdmin)
        {  
            $('SpModifyAddress').style.display='block';
            $('SpDescribe').style.display = 'block';
//             $('SpWriteAccount').style.display = 'block';
        }
        else if(AuthorizationAdmin.EqualsFamily)
        {
            $('SpModifyAddress').style.display='block';
             $('SpDescribe').style.display = 'none';
//              $('SpWriteAccount').style.display = 'block';
        }
       else if(!AuthorizationAdmin.HasFamily)
        {
              $('SpWriteAccount').style.display = 'block';
        }
        else if(AuthorizationAdmin.HasFamily && !AuthorizationAdmin.EqualsFamily)
        {
             $('SpDescribe').style.display = 'none';
            $('SpModifyAddress').style.display='none';
//             $('SpWriteAccount').style.display = 'none';
        }
        else
        {
            $('SpDescribe').style.display = 'none';
            $('SpModifyAddress').style.display='none';
             $('SpWriteAccount').style.display = '';
        }
    }
    else
    {
        $('SpWriteAccount').style.display = 'none';
        $('SpModifyAddress').style.display='none';
         $('SpDescribe').style.display = 'none';
         window.location.assign('/family_'+$('HdFamillyID').value+'.htm');
    }  
}
function pareseResultText()
{
    var result = this.req.responseText;
    if(result)
    {
        eval(result);
    }
}

//加载自定义分类 填充下拉框
function LoadCustomType()
{
    var dropdow = $('customType');
    if(dropdow)
    {
        var url = '/Family/AjaxProc/AccountBook.aspx?cmd=selectAllCate&accountId='+$('HdAccountID').value+'&rc='+Math.random();
       Ajax.Request(url,pareseResultText,null,null,'text',null,'');
    }
}
function CreateSelect(objResult)
{
    if(objResult)
    {
        if(typeof objResult == 'string')
        {
            return;
        }
        var select =  $('customType');
        select.options.length=0;
        select.options.add(new Option("未分类",""));
        var id = "";
        var name = "";
        for(obj in objResult)
        {
            id = obj;
            name = objResult[obj];
            var opto = new Option(name,id);
            select.options.add(opto);
        }
    }
}
function CheckSaveAccontInfo(frm)
{
   if(frm){
        var fname = frm.id;
        if(FormValidMgr.FormIsValid(fname) && CheckDateTime())
        {
            frm.submit();                    
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }
}
//设置个人可见,家人可见,所有人可见
function DisplayAuthenSetq(type)
{
    var imgOwn = $('imgOwner');
    var imgFamily = $('imgFamily');
    var imgAll = $('imgAll');
    var hostPath = $('hdImgHostPath');
    var level = $('DisplayAuthenSet');
    if(type=='owner')//个人可见
    {
        imgOwn.src = hostPath.value+"/sojj/family/zb_title15.gif";
        imgFamily.src = hostPath.value+"/sojj/family/gl_title01b_1.gif";
        imgAll.src = hostPath.value+"/sojj/family/gl_title01_1.gif";
        level.value = "2";
    }
    else if(type=='family')//家人可见
    {
        imgOwn.src = hostPath.value+"/sojj/family/zb_title15a.gif";
        imgFamily.src = hostPath.value+"/sojj/family/gl_title01b.gif";
        imgAll.src = hostPath.value+"/sojj/family/gl_title01_1.gif";
        level.value="1";
    }
    else if(type=='all')//所有人可见
    {
        imgOwn.src = hostPath.value+"/sojj/family/zb_title15a.gif";
        imgFamily.src = hostPath.value+"/sojj/family/gl_title01b_1.gif";
        imgAll.src = hostPath.value+"/sojj/family/gl_title01.gif"; 
        level.value="0";
    }
}
//选择账目类别
function ChangSetType()
{
    var sel = $('HdFirstType');
    var downlist = $('AccountType');
    var ftype = $('HdFirstType').value;
    var inputTime  = $('Birthday');
    var curday = new Date();
    if(downlist.options.selectedIndex>0)
    {
        var value = downlist.options[downlist.options.selectedIndex].value;
        sel.value = value;
    }
   
    if(sel.value=='想挣'||sel.value=='想花')
    {
        inputTime.value = curday.getFullYear()+"-"+(curday.getMonth()+1)+'-'+(curday.getDate()+1); 
    }
    else
    {
        inputTime.value = curday.getFullYear()+"-"+(curday.getMonth()+1)+'-'+curday.getDate(); 
    }
   CheckDateTime();
}
//选择自定义分类
function ChangeSecondType()
{
    var selId = $('HdCustomerID');
    var selName = $('HdCustomerName');
    var downlist = $('customType');
    if(downlist.options.selectedIndex>0)
    {
        var val = downlist.options[downlist.options.selectedIndex];
        selId.value = val.value;
        selName.value = val.text;
    }
    else
    {
        selId.value='';
        selName.value = '未分类';
    }
}

function SaveCustomName()
{
    if(event.keyCode==13)
    {
         ChCategoryName($('HdAccID').value,$('HdFamillyID').value);
    }
}
function createEvent()
{
    if(Browser.IE)
    {   
        document.attachEvent("onkeydown",SaveCustomName);   
    }
    else
    {
        document.addEventListener("keydown",SaveCustomName,false);

    }
} 
function removeEvent()
{
    if(Browser.IE)
    {
        document.detachEvent("onkeydown",SaveCustomName);   
    }
    else
    {
        document.removeEventListener("keydown",SaveCustomName,false);
    }
}
//检查记账日期是否正确
//挣了 花了 只能记已经过去日子里的账目。不能记还没有到时间的账目。如今天是13号就不能记14号挣了和花了的账目。
//想挣 想花  只能记还没有到来的日子，如今天是13 号只能记14号以后的账目。
function CheckDateTime()
{
    var ftype = $('HdFirstType').value;
    var inputTime  = $('Birthday').value;
    var time = new Array();
    var today = new Date();
    time = inputTime.split('-');
    var inYear = time[0];
    var inMonth= time[1];
    var inDay  = time[2];
    if(ftype=='挣了'||ftype=='花了')
    {
        if(CompareTime(inYear,inMonth,inDay)>0)
        {
            $('Birthday').value = '';
            $('spCheckDay').innerHTML = '<font color=red>请您输入今天之前的日期!</font>';
            return false;
        }
        else
        {
             $('spCheckDay').innerHTML = '';
            return true;
        }
    }
    else if(ftype=='想挣'||ftype=='想花')
    {
           if(CompareTime(inYear,inMonth,inDay)<0)
        {
            $('Birthday').value = '';
            $('spCheckDay').innerHTML = '<font color=red>请您输入今天之后的日期!</font>';
            return false;     
        }
        else
        {
            $('spCheckDay').innerHTML = '';
            return true;
        }
    }
    else
    {
        return true;
    }
}
function CompareTime(pYear,pMonth,pDay)
{
    var cDay = new Date();
    var cYear = cDay.getFullYear();
    var cMonth= cDay.getMonth()+1;
    var cDate = cDay.getDate();
    if(pYear<cYear)
    {
       return -1; 
    }
    else if(pMonth<cMonth)
    {
        return -1;
    }
    else if(pDay<cDate)
    {
        return -1;
    }
    else if(pDay==cDate)
    {
        return 0;
    }
    else if(pDay>cDate)
    {
        return 1;
    }
    
}

window.onload=function(){ProcMPageReload();}