﻿if(typeof(top.__setting)!="object") 
{ 
    top.__setting = {};
    top.__setting._values = new Array();
    top.__setting.getValue = function(AName, ADefault) { var v =this._values[AName]; if (! v) v = ADefault; return v;}
    top.__setting.setValue = function(AName, AValue) { this._values[AName] = AValue;}
    top.__setting.initValue = function(AName, AValue) {if (! this._values[AName]) this._values[AName] = AValue;}
};
var _setting = top.__setting;
var NewMeetingRentRecordInfo = new Array();
_setting.setValue("NewMeetingRentRecordInfo",NewMeetingRentRecordInfo);


var isFinished = false;
var isLoaded = false;
var drawFinished = false;

var browserWidth;
var browserHeight;
var tableWidth;
var tableHeight;


var startDate;
var days=1;
var daysDefaultItemCount =3;

//会议室相关信息
var checkedResourceArray = new Array();
var checkedResourceHashMap = new Array();
var resourceHashMap = new Array();
var resourceLendLogArray = new Array();
var resourceLendLogGotBack = false;

var divArray;

var headColorList = new Array(
"#125a96", //预约
"#2c2c2c", //预约确定
"#007803", //拒绝
"#ab9500",  //预定
"#9e2626"   //结算
);
var colorList = new Array(
"#239aff", //预约
"#999999", //预约确定
"#5abc1f",//拒绝
"#d8a800", //预定
"#ee6e6e"   //结算
);


var globalLendLogId = -1;
var globalResourceId = -1;

function ResizeWindow()
{
    GetBrowserInfo();
    if(resourceLendLogGotBack)
    {//已经拥有日期了
        RefreshMe();
    }    
}

function PaddingLeft(value, paddingChar, len)
{
    var str = value+"";
    var cLen = str.length;
    if(cLen<len)
    {
        for(var i=0;i<len-cLen; i++)
        {
            str = paddingChar+str;
        }    
    }
    return str;
}

function IntToDate(dateValue)
{
    dateValue =""+dateValue;
    var dateStr = dateValue.substring(0,4) + "/" + dateValue.substring(4,6) +"/"+ dateValue.substring(6,8);
    return new Date(dateStr);
}

function DateToStr(date, split)
{
    var year = date.getFullYear();
    var month = date.getMonth()+1;
    var day = date.getDate();
    var str = year +split+ (month<10?("0"+month):month) +split+ (day<10?("0"+day):day);
    return str;
}

function DateDiff(date1,date2)
{
    var diffDays = (date1.getTime()-date2.getTime())/(24*60*60*1000);
    return diffDays;
}

function AddDays(myDate,days)
{
    return new Date(myDate.getTime()+days*24*60*60*1000)
}

function AddHours(myDate,hours)
{
    return new Date(myDate.getTime()+hours*60*60*1000)
}


function GetBrowserInfo()
{
    browserWidth =document.body.clientWidth ;
    browserHeight =document.body.clientHeight ;
    tableWidth = browserWidth ;
    tableHeight = browserHeight - 20;
    
    var table = document.getElementById("ShowFlat");
    table.style.width = tableWidth + "px";
    table.style.height = tableHeight + "px";
}

function Loading()
{
    if(GetParentFrame("frmTop") && GetParentFrame("frmTop").isLoaded&&
    GetParentFrame("frmBottom") && GetParentFrame("frmBottom").isLoaded)
    {
        GetBrowserInfo();
        userid =document.getElementById("hUserID").value;
        isLoaded = true;
        isFinished = true;
    }
    else
    {
        setTimeout("Loading()", 300);
    }
}

function GetParentFrame(aFrameId)
{
    return parent.document.frames ? parent.frames[aFrameId] : parent.document.getElementById(aFrameId).contentWindow;
}

function NextDays(_days)
{
    GetParentFrame("frmTop").NextDays(startDate, _days);
}

function SetBannerDiv()
{
    var bannerLeftDivObj = document.getElementById('BannerLeftDiv');    
    var sDate = IntToDate(startDate.date);
    var eDate = AddDays(sDate, days-1);
    var sDateStr = sDate.getFullYear() + "年" + (sDate.getMonth()+1) + "月" + sDate.getDate() +"日";
    var eDateStr = eDate.getFullYear() + "年" + (eDate.getMonth()+1) + "月" + eDate.getDate() +"日";
    var dateStr = sDateStr;
    if(days>1)
    {
        dateStr +=" - " +eDateStr;
    }
    bannerLeftDivObj.innerHTML = dateStr;
    var bannerRightDivObj = document.getElementById('BannerRightDiv');
    var str ="";
    //str += '<a style="cursor:pointer" onclick="NextDays(1);">日</a> ';
    //str += '<a style="cursor:pointer" onclick="NextDays(7);">周</a> ';
    //str += '<a style="cursor:pointer" onclick="NextDays(14);">接下来二周</a> ';
    //str += '<a style="cursor:pointer" onclick="NextDays(21);">接下来三周</a> ';
    //str += '<a style="cursor:pointer" onclick="NextDays(31);">月</a> &nbsp;&nbsp;';
    //str +="日程";
    
    str += '<a style="cursor:pointer" onclick="NextDays(-7);"> 上一周</a> ';
    str += '<a style="cursor:pointer" onclick="NextDays(7);">下一周</a> ';
    str += '<a style="cursor:pointer" onclick="NextDays(0);">本周</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
    bannerRightDivObj.innerHTML = str;
}

function GetCheckedResource()
{
    checkedResourceArray = new Array();
    var resourceArray = GetParentFrame("frmBottom").BuildingArray;
    for(var i=0; i<resourceArray.length; i++)
    {
        if(resourceArray[i].Checked)
        {
            for(var y = 0; y< resourceArray[i].Meeting.length; y++)
            {
                checkedResourceArray[checkedResourceArray.length] = resourceArray[i].Meeting[y];
                //checkedResourceHashMap["_"+resourceArray[i].Id] = resourceArray[i].Checked;
                resourceHashMap["_"+resourceArray[i].Meeting[y].Id] = resourceArray[i].Meeting[y];
            }
        }
    }
}

function ClearInnerHTML(object)
{
    if(object.innerHTML !="")
    {
        object.innerHTML = "";
        object.style.height = "1px";
    }
}

function RefreshMe()
{
    RedrawTable();
    LoadResource();
}

function DrawTable(_startDate,_days)//startDate,days
{
    resourceLendLogGotBack = false;
    startDate = _startDate;
    days = _days;
    RedrawTable();    
}

function RedrawTable()
{
    ClearDivs();
    GetCheckedResource();
    
    if(checkedResourceArray.length==0){
        return;
    }
    
    //更新BannerDiv
    SetBannerDiv();
    
    var headCell,bodyCell;
    headCell = document.getElementById("HeadCell");
    bodyCell = document.getElementById("BodyCell");
    ClearInnerHTML(headCell);
    ClearInnerHTML(bodyCell);
    
    DrawDaysHead(headCell);
    
    if(days==1)
    {
        DrawOneDayBody(bodyCell);
    }
    else if(days>1)
    {
        DrawDaysBody(bodyCell);
    }
    drawFinished = true;
    
}

function LoadResource()
{
    if(arguments.length==1)
    {
        resourceLendLogGotBack = arguments[0];
    }
    if(!resourceLendLogGotBack)
    {
        //得到所有会议室状态
        GetResourceLendLogsByType();
        setTimeout("LoadResource()", 1000);
        return;
    }
    else if(!drawFinished)
    {
        setTimeout("LoadResource()", 1000);
        return;
    }
    else
    {
        ClearDivs();
        ShowResourceLendLogs();
    }

}

function TableDefine(width,leftWidth,rightWidth, cellWidth, headCellHeight, cellHeight, border, itemSpacing)
{
    this.Width = width;
    this.LeftWidth = leftWidth;
    this.RightWidth = rightWidth;
    this.CellWidth = cellWidth;
    this.HeadCellHeight = headCellHeight;
    this.CellHeight = cellHeight;
    this.Border = border;
    this.ItemSpacing = itemSpacing;
}

function GetHeadCellDefine()
{
    var border =1;
    var leftWidth = 83;
    var rightWidth = 15;
    var headCellHeight = 20;
    var cellHeight = 20;
    var itemSpacing =0;
    var cellWidth = Math.floor((browserWidth-leftWidth-rightWidth-(2+checkedResourceArray.length)*border)/checkedResourceArray.length);
    var width = cellWidth*checkedResourceArray.length+(2+checkedResourceArray.length)*border + leftWidth + rightWidth;
    leftWidth = leftWidth + browserWidth - width;
    width = browserWidth;
    return new TableDefine(width,leftWidth,rightWidth, cellWidth, headCellHeight, cellHeight, border, itemSpacing);
}

function SetHeadTd(tdObj,tableDefine, j)
{
    tdObj.className ="listcenter ItemStyle"; 
    tdObj.onselectstart = function(){return false;}; 
    tdObj.width = "100px";   
    tdObj.align = "center";
    tdObj.id = "HeadTd_" + j;
    tdObj.innerHTML = BoundTextByWidth(checkedResourceArray[j].Name, tableDefine.CellWidth);
    tdObj.style.backgroundColor ="#E8F4FF";
    tdObj.style.cursor = "pointer";
    tdObj.onclick=function()
    {
        setHeadbgColor(checkedResourceArray[j].Id);
    }
}
//设置点击会议室背景颜色
function setHeadbgColor(aresourceId)
{
    //if (aresourceIndex < 0 || aresourceIndex >= checkedResourceArray.length) return;
    var aresourceIndex = 0;
    for(var rIndex =0;rIndex<checkedResourceArray.length;rIndex++)            
    {
        document.getElementById("HeadTd_" + rIndex).style.backgroundColor="#EBF4FF";
        if(checkedResourceArray[rIndex].Id == aresourceId)
        {
            aresourceIndex = rIndex;
        }
    }
    document.getElementById("HeadTd_" + aresourceIndex).style.backgroundColor = "#87CEEB";
    ShowMeetingInfo(checkedResourceArray[aresourceIndex].About);
}

function DrawDaysHead(headCell)
{
    var tableDefine = GetHeadCellDefine();
    headTableObj = document.createElement ("TABLE");
    headTableObj.style.width = "100%";
    headTableObj.id = "HeadTable";
    headTableObj.cellPadding = "0px";
    headTableObj.cellSpacing = "0px";
    headTableObj.className = "TableStylem";
    var headRow = headTableObj.insertRow(-1);
    var headCell1 = headRow.insertCell(-1);//left
    var headCell2 = headRow.insertCell(-1);//center
    var headCell3 = headRow.insertCell(-1);//right    
    
    headCell3.style.width = tableDefine.RightWidth + "px";
    //headCell3.bgColor = "#E8F4FF";
    //headCell3.className ="ItemStyle"; 
    headCell3.style.borderTop = "1px";
    
    headCell1.className ="ItemStyle"; 
    headCell1.bgColor = "#E8F4FF";
    headCell1.innerHTML=BoundTextByWidth("时间范围", tableDefine.LeftWidth + "px");
    headCell1.align ="center";
    
    //headCell2.style.borderBottom = "0px solid #999";
    
    var centerWidth = tableDefine.Width -tableDefine.LeftWidth -tableDefine.RightWidth -tableDefine.Border;
    headCell2.style.width = centerWidth +"px";
    var tableObj = document.createElement("TABLE");
    tableObj.id = "HeadCenterTable";
    //tableObj.className = "TableStyle";
    //tableObj.style.width = "100%";
    tableObj.style.borderTop = "none";
    tableObj.style.border = "0";
    tableObj.cellPadding = "0px";
    tableObj.cellSpacing = "0px";
    var newRow = tableObj.insertRow(-1);
    newRow.style.height = tableDefine.HeadCellHeight + "px";//title row
    for(j =0;j<checkedResourceArray.length;j++)
    {
        var newCell = newRow.insertCell(-1);
      //  SetHeadTd(newCell, tableDefine, i,j);
        SetHeadTd(newCell, tableDefine,j);
    }
    headCell2.insertBefore(tableObj,null); 
    headCell.insertBefore(headTableObj,null);
}

function GetBodyCellDefine(){
    var border =1;
    var leftWidth = 83;
    var rightWidth = 15;
    var headCellHeight = 20;
    var cellHeight = 20;
    var itemSpacing = 5;
    var cellWidth = Math.floor((browserWidth-leftWidth-rightWidth-(2+checkedResourceArray.length)*border)/checkedResourceArray.length);
    var width = cellWidth*checkedResourceArray.length+(2+checkedResourceArray.length)*border + leftWidth + rightWidth;
    leftWidth = leftWidth + browserWidth - width;
    width = browserWidth;
    
    return new TableDefine(width,leftWidth,rightWidth, cellWidth, headCellHeight, cellHeight, border, itemSpacing);
}
//显示日 画表格
function SetBodyTd(tdObj,tableDefine, rowCount, columnCount, i, j)
{
    tdObj.onselectstart = function(){return false;};
    if(i<rowCount-1)
    {
        tdObj.onmousedown = TDMouseDown;
    }
    tdObj.onmouseover = TDMouseOver;
    tdObj.onmouseup = TDMouseUp;
    
    tdObj.id = "BodyTd" + i +"_" + j;     
    if(i%2==0 && j==0)//第一列
    {
        tdObj.style.width = tableDefine.LeftWidth + "px" ;
        tdObj.rowSpan = 2;
        tdObj.vAlign = "top";
        tdObj.innerHTML = BoundTextByWidth(GetBodyTdText(rowCount, columnCount, i,j), tableDefine.LeftWidth + "px");
        if(tdObj.innerHTML=="")
        {
            tdObj.innerHTML = "&nbsp;" ;
        }
        tdObj.className ="listcenter ItemStyle jobcolor";
        tdObj.style.backgroundColor = "#E8F4FF"; 
    }
    else
    { 
        tdObj.style.height = tableDefine.CellHeight + "px";
        tdObj.style.width = tableDefine.CellWidth + "px";
        tdObj.innerHTML = "&nbsp;" ; 
        if(i%2==0)
        {
            tdObj.className ="listcenter ItemdashedStyle";     
        }
        else
        {        
            tdObj.className ="listcenter ItemStyle"; 
        } 
    }
}
var WeekDayXQ = new Array("星期天","星期一","星期二","星期三","星期四","星期五","星期六");
function GetBodyTdText(rowCount, columnCount, i, j)
{
    var text ="";
    if(days==1)
    {//一天的处理方式
        if(i==0)
        {
            text = "00:00<br>|<br>09:00";
        }
        else if(i==rowCount-2)
        {
            text = "21:00<br>|<br>24:00";
        }
        else if(i<rowCount)
        {   
            var hour = 8 + Math.floor(i/2) ;
            text = (hour<10?("0"+hour):hour)+":00";
        }
        return text;
    }
    else
    {//大于一天的处理方式
        text = new Array();
        var sDate = IntToDate(startDate.date);
        var cDate = AddDays(sDate, Math.floor(i/3));
        text[text.length] = cDate.getFullYear() + "年";
        text[text.length] = (cDate.getMonth()+1) + "月" + cDate.getDate() +"日";
        text[text.length] = WeekDayXQ[cDate.getDay()];
      //  text = DateToStr(cDate,"-");  
      return text;  
    }

}
//日 画表格
function DrawOneDayBody(bodyCell)
{
    var tableDefine = GetBodyCellDefine();
    var divObj = document.createElement("DIV");
    divObj.id = "BodyDiv";
    divObj.style.position = "absolute";
    divObj.style.width = "100%";
    divObj.style.top = "0px";
    divObj.style.left = "0px";
    divObj.style.display = "block";
    divObj.style.overflowX = "hidden";
    divObj.style.overflowY = "auto";

    var headTable = document.getElementById('HeadTable');
    bodyHeight = tableHeight - headTable.offsetHeight;
    divObj.style.top = headTable.offsetHeight + "px";
    divObj.style.height = bodyHeight + "px";
    var tableObj = document.createElement("TABLE");
    tableObj.id = "BodyTable";
    tableObj.className = "TableStyle";
    tableObj.cellPadding = "0px";
    tableObj.cellSpacing = "0px";
    tableObj.style.width = tableDefine.Width-tableDefine.RightWidth+"px";
    
    var columnCount = 0;
    var rowCount = 28;
    for(i=0;i<rowCount;i++)
    {
        if(i % 2 ==0)
        {
            columnCount = checkedResourceArray.length;
        }
        else
        {
            columnCount = checkedResourceArray.length - 1;
        }
        newRow = tableObj.insertRow(-1);
        for(j=0;j<=columnCount;j++)
        {
            var newCell = newRow.insertCell(-1);
            SetBodyTd(newCell,tableDefine, rowCount, columnCount, i, j);
        }
    }

    divObj.insertBefore(tableObj,null);
    bodyCell.insertBefore(divObj,null); 
}

function SetDaysBodyTd(tdObj,tableDefine, rowCount, columnCount, i, j)
{
    tdObj.onselectstart = function(){return false;};
    
    tdObj.onmousedown = TDMouseDown;
    tdObj.onmouseover = TDMouseOver;
    tdObj.onmouseup = TDMouseUp;
    
    tdObj.id = "BodyTd" + i +"_" + j;     //????
    if(i%3==0&&j==0)//第一列
    {
        tdObj.style.width = tableDefine.LeftWidth + "px" ;
        tdObj.rowSpan = 3;
        //tdObj.vAlign = "top";
        //tdObj.innerHTML = BoundTextByWidth(GetBodyTdText(rowCount, columnCount, i,j), tableDefine.LeftWidth + "px");
        //if(tdObj.innerHTML==""){
          //  tdObj.innerHTML = "&nbsp;" ;
        //}
     
        tdObj.style.height = tableDefine.CellHeight *daysDefaultItemCount + tableDefine.ItemSpacing*(daysDefaultItemCount+1) + "px";
        tdObj.className ="listcenter ItemStyle jobcolor";
        tdObj.style.backgroundColor = "#E8F4FF"; 
        
        var text = GetBodyTdText(rowCount, columnCount, i,j);
        
        var _tableobj = document.createElement("TABLE");
        _tableobj.style.border = 0;
        _tableobj.style.width = "100%"
        var _newrows = _tableobj.insertRow(-1);
        var _newCells = _newrows.insertCell(-1);
        _newCells.style.height = tableDefine.CellHeight + "px";
       // _newCells.rowSpan = 3;
        _newCells.innerHTML = text[0]?text[0]:"";
        if(_newCells.innerHTML=="")
        {
            _newCells.innerHTML = "&nbsp;" ;
        }
        _newCells = _newrows.insertCell(-1);
        _newCells.style.height = tableDefine.CellHeight + "px";
        _newCells.innerHTML = "上午";
        
        _newrows = _tableobj.insertRow(-1);
        _newCells = _newrows.insertCell(-1);        
         _newCells.innerHTML = text[1]?text[1]:"";
         _newCells = _newrows.insertCell(-1);
        _newCells.style.height = tableDefine.CellHeight + "px";
        _newCells.innerHTML = "下午";
        _newrows = _tableobj.insertRow(-1);
        _newCells = _newrows.insertCell(-1);        
         _newCells.innerHTML = text[2]?text[2]:"";
         _newCells = _newrows.insertCell(-1);
        _newCells.style.height = tableDefine.CellHeight + "px";
        _newCells.innerHTML = "晚上";
        tdObj.insertBefore(_tableobj, null);
    }
    else
    { 
        tdObj.style.height = tableDefine.CellHeight + "px";
        tdObj.style.width = tableDefine.CellWidth + "px";
        tdObj.innerHTML = "&nbsp;" ; 
        if(i%3!=2)
        {
            tdObj.className ="listcenter ItemdashedStyle"; 
    
        }else
        {
        
            tdObj.className ="listcenter ItemStyle"; 
        }        
    }
}

function DrawDaysBody(bodyCell)
{
    var tableDefine = GetBodyCellDefine();
    var divObj = document.createElement("DIV");
    divObj.id = "BodyDiv";
    divObj.style.position = "absolute";
    divObj.style.width = "100%";
    divObj.style.top = "0px";
    divObj.style.left = "0px";
    divObj.style.display = "block";
    divObj.style.overflowX = "hidden";
    divObj.style.overflowY = "auto";
    var headTable = document.getElementById('HeadTable');
    bodyHeight = tableHeight - headTable.offsetHeight;
    divObj.style.top = headTable.offsetHeight;
    divObj.style.height = bodyHeight;
    var tableObj = document.createElement("TABLE");
    tableObj.id = "BodyTable";
    tableObj.className = "TableStyle";
    tableObj.cellPadding = "0px";
    tableObj.cellSpacing = "0px";
    tableObj.style.width = tableDefine.Width-tableDefine.RightWidth+"px";
    
    var columnCount = 0;
    var rowCount = days*3 ;
    for(i=0;i<rowCount;i++)
    {
        if(i % 3 ==0)
        {
            columnCount = checkedResourceArray.length;
        }
        else
        {
            columnCount = checkedResourceArray.length - 1;
        }
        newRow = tableObj.insertRow(-1);
        for(j=0;j<=columnCount;j++)
        {
            var newCell = newRow.insertCell(-1);
            SetDaysBodyTd(newCell,tableDefine, rowCount, columnCount, i, j);
        }
    }
    divObj.insertBefore(tableObj,null);
    bodyCell.insertBefore(divObj,null);  
}



function GetResourceLendLogsByType(){
    
    if(resourceLendLogGotBack)
    {
        return;
    }    
    var sDate = IntToDate(startDate.date);
    var eDate = AddDays(sDate, days-1);
    
    var sDateStr = DateToStr(sDate,"");
    var eDateStr = DateToStr(eDate,"");
    
    var sTimeStr ="000000";
    var eTimeStr ="235959";
    
    EQD.SciencePark.Meeting.MeetingAjax.GetAllLendLogs(sDateStr,sTimeStr,eDateStr,eTimeStr, ParseResourceLendLogs);
}

function ResourceLendLog(lendLogId, resourceId, state, color, sYear, sMonth, sDay,sHour, sMinute, sSecond, eYear, eMonth, eDay,eHour, eMinute, eSecond, privilege, username, aSubject, afuwu, ashebei, acompany, aRentMoney_Real, aRentPersonName, aStandardForegift, aStandardForegift_Real, asubScription_DeadLine, asubScription_Real, aApplyWhys, abalance_DeadLine, abalance_Real, aRentSomeMoney_Real, aJuJueYuanYin,aRentLogRentStartDate)
{
    this.LendLogId = lendLogId;//租赁记录Id
    this.ResourceId = resourceId;//会议室Id
    this.State = state;//状态
    this.Color = color;//状态div颜色
    this.SYear = PaddingLeft(sYear, '0',4);
    this.SMonth = PaddingLeft(sMonth, '0',2);
    this.SDay = PaddingLeft(sDay, '0',2);
    this.SHour = PaddingLeft(sHour, '0',2);
    this.SMinute = PaddingLeft(sMinute, '0',2);
    this.SSecond = PaddingLeft(sSecond, '0',2);
    this.EYear = PaddingLeft(eYear, '0',2);
    this.EMonth = PaddingLeft(eMonth, '0',2);
    this.EDay = PaddingLeft(eDay, '0',2);
    this.EHour = PaddingLeft(eHour, '0',2);
    this.EMinute = PaddingLeft(eMinute, '0',2);
    this.ESecond = PaddingLeft(eSecond, '0',2);
    this.Privilege = privilege;//权限
    this.Username = username;//用户名称
    this.Subject = aSubject;//租赁标题
    this.fuwu = afuwu;//服务
    this.shebei = ashebei;//设备
    this.company = acompany;//租赁公司
    this.RentMoney_Real = aRentMoney_Real;//用户实际缴纳租金
    this.RentPersonName = aRentPersonName;//租赁人
    this.StandardForegift = aStandardForegift;//用户应缴纳押金
    this.StandardForegift_Real = aStandardForegift_Real;//实际缴纳押金
    this.subScription_DeadLine = asubScription_DeadLine;//定金缴纳最后期限
    this.subScription_Real = asubScription_Real;//实际缴纳定金时间
    this.ApplyWhys = aApplyWhys;//申请原因
    this.balance_DeadLine = abalance_DeadLine;//费用结算最后时间
    this.balance_Real = abalance_Real;//实际结算时间
    this.RentSomeMoney_Real = aRentSomeMoney_Real;//预计会议的费用
    this.JuJueYuanYin = aJuJueYuanYin;//拒绝原因
    
    this.RentLogStartDate = aRentLogRentStartDate;
}

function ParseResourceLendLogs(result)
{
    resourceLendLogGotBack = true;
    resourceLendLogArray = new Array();
    
    if(result!=null && result.value!=null && result.value != "")
    {
        var resourceLendLogs = result.value.split("\x1d");
        
        if(resourceLendLogs != null)
        {
            for(i=0;i<resourceLendLogs.length;i++)
            {
                var newResourceLendLog = ParseResource(resourceLendLogs[i]);
                if(newResourceLendLog==null)
                {
                    continue;
                }
                var key = "_"+newResourceLendLog.ResourceId;
                if(resourceLendLogArray[key]==null)
                {
                    resourceLendLogArray[key] = new Array();
                }
                newResourceLendLog.resourceStr = resourceLendLogs[i];
                resourceLendLogArray[key][resourceLendLogArray[key].length]= newResourceLendLog;
            }            
        }
    }     
}

function ParseResource(resourceInfo)
{
    if(resourceInfo != null)
    {
        var infoArray = resourceInfo.split("\x1c");
        var i = -1;
        if(infoArray.length == 34)
        {
            var lendLogId = infoArray[++i];
            var resourceId = infoArray[++i];
            var state = infoArray[++i];
            var color = infoArray[++i];                
            var sYear = infoArray[++i];
            var sMonth = infoArray[++i];
            var sDay = infoArray[++i];
            var sHour = infoArray[++i];
            var sMinute = infoArray[++i];
            var sSecond = infoArray[++i];
            var eYear = infoArray[++i];
            var eMonth = infoArray[++i];
            var eDay = infoArray[++i];
            var eHour = infoArray[++i];
            var eMinute = infoArray[++i];
            var eSecond = infoArray[++i];                
            var privilege = infoArray[++i];
            var username = infoArray[++i];
            var subject = infoArray[++i];
            var fuwu = infoArray[++i];
            var shebei = infoArray[++i];
            var acompany = infoArray[++i];
            var aRentMoney_Real = infoArray[++i];
            var aRentPersonName = infoArray[++i];
            var aStandardForegift = infoArray[++i];
            var aStandardForegift_Real = infoArray[++i];
            var asubScription_DeadLine = infoArray[++i];
            var asubScription_Real = infoArray[++i];
            var aApplyWhys = infoArray[++i];
            var abalance_DeadLine = infoArray[++i];
            var abalance_Real = infoArray[++i];
            var aRentSomeMoney_Real = infoArray[++i];
            var aJuJueYuanYin = infoArray[++i];
            var aRentLogStartDate = infoArray[++i];
            return new ResourceLendLog(lendLogId, resourceId, state, color, sYear, sMonth, sDay,sHour, sMinute, sSecond, eYear, eMonth, eDay,eHour, eMinute, eSecond, privilege, username, subject, fuwu, shebei, acompany, aRentMoney_Real, aRentPersonName, aStandardForegift, aStandardForegift_Real, asubScription_DeadLine, asubScription_Real, aApplyWhys, abalance_DeadLine, abalance_Real, aRentSomeMoney_Real, aJuJueYuanYin,aRentLogStartDate);
        }
    }
    return null;
}
function ShowResourceLendLogs()
{
    isFinished = false;
    if(days==1)
    {
        ShowOneDayResourceLendLogs();    
    }
    else if(days>1)
    {
        ShowDaysResourceLendLogs();    
    }
    isFinished = true;
}


function ShowOneDayResourceLendLogs(){
    //先根据时间排序
    SortCheckedResourceLendLogs();
    var count = GetBeginEndCount();
    DrawOneDayResourceLendLogDivs(count);
}

function GetAbsolutePostion(node)
{
    var top = node.offsetTop;
    
    var left = node.offsetLeft;
    while(node.tagName != "BODY")
    {
    	node = node.offsetParent;
        top += node.offsetTop;
        left += node.offsetLeft;
    }
    return [top,left];
}


function DrawOneDayResourceLendLogDivs(count)
{
    var tableDefine = GetBodyCellDefine();
    SetBeginEndHeight(count, tableDefine);
    divArray = new Array();
    for(var i=0; i<checkedResourceArray.length; i++)
    {
       var key="_"+ checkedResourceArray[i].Id;
       var array = resourceLendLogArray[key];
       if(array==null)continue;
       for(var j=0; j<array.length; j++)
       {
             DrawResourceLendLogDiv(i,j, tableDefine,count, array[j]);    
       }
    }
}
function SetBeginEndHeight(count, tableDefine)
{
    var beginCount = count[0];
    var endCount = count[1];
    if(beginCount>1)
    {
        var row = 0;
        var column = 1;
        var objTd = document.getElementById('BodyTd'+row+'_'+column);
        objTd.style.height =tableDefine.CellHeight* beginCount; 
    }
    if(endCount>1)
    {
        var row = 27;
        var column = 1;
        var objTd = document.getElementById('BodyTd'+row+'_'+column);
        objTd.style.height =tableDefine.CellHeight* endCount;     
    }
}
function GetDivHeightOffset(resourceLendLog, row, count)
{
    var top;
    var len;
    var beginEnd = false;
    if(parseInt(resourceLendLog.SHour, 10)< 9 && parseInt(resourceLendLog.EHour, 10)<= 9)
    {
        top = resourceLendLog.Row;
        len = 1;
        beginEnd = true;    
    }
    else if(parseInt(resourceLendLog.SHour, 10)<9 && parseInt(resourceLendLog.EHour, 10)>9&& parseInt(resourceLendLog.EHour, 10)<=21)
    {
        top = count[0];
        len = 1+ (parseInt(resourceLendLog.EHour, 10) - 9 + parseFloat(resourceLendLog.EMinute)/60 )*2 ;
    }
    else if(parseInt(resourceLendLog.SHour, 10)<9 && parseInt(resourceLendLog.EHour, 10)>21)
    {
        top = count[0];
        len = 1+ 12*2+1;
    
    }
    else if(parseInt(resourceLendLog.SHour, 10)>=9 &&parseInt(resourceLendLog.SHour, 10)<21 && parseInt(resourceLendLog.EHour, 10)<=21)
    {
        top = count[0]+1 + (parseInt(resourceLendLog.SHour, 10)-9 + parseFloat(resourceLendLog.SMinute)/60)*2;
        len = (parseInt(resourceLendLog.EHour, 10) - parseInt(resourceLendLog.SHour, 10) + parseFloat(resourceLendLog.EMinute)/60 - parseFloat(resourceLendLog.SMinute)/60)*2 ;
        
    
    }
    else if(parseInt(resourceLendLog.SHour, 10)>=9 &&parseInt(resourceLendLog.SHour, 10)<21 && parseInt(resourceLendLog.EHour, 10)>21)
    {
        top = count[0]+1 + (parseInt(resourceLendLog.SHour, 10) +parseFloat(resourceLendLog.SMinute)/60 - 9)*2;
        len = (21 - parseInt(resourceLendLog.SHour, 10)-parseFloat(resourceLendLog.SMinute)/60)*2 +1;
    }
    else if(parseInt(resourceLendLog.SHour, 10)>=21)
    {
        top = count[0] + 1 + 12*2+ 1 + resourceLendLog.Row;
        len = 1;
        beginEnd = true;
    }
    
    
    if(resourceLendLog.SHour=='00'&&resourceLendLog.SMinute=='00')
    {
        top -=count[0];
        len +=count[0];
    }
    if(resourceLendLog.SHour=='21'&&resourceLendLog.SMinute=='00')
    {
        top -=1;
    }
    if(resourceLendLog.EHour=='23'&&resourceLendLog.EMinute=='59')
    {
        len += count[1];
    }
    
    return [top, len, beginEnd];


}

function GetStateText(state){
    var text;
    switch(parseInt(state, 10)){
        case 70:
            text = "闲置";
            break;
        case 71:
            text = "已预约";
            break;
        case 72:
            text = "预约确定";
            break;
        case 73:
            text = "预约拒绝";
            break;
        case 74:
            text = "预定";
            break;
        case 75:
            text = "租金结清";
            break; 
    }
    return text;
}

function DrawResourceLendLogDiv(column, row, tableDefine, count, resourceLendLog)
{
    
    var bodyDivObj = document.getElementById('BodyDiv');
    var divObj = document.createElement("div");
    divObj.onclick = function(){ShowResourceState(resourceLendLog.resourceStr);};
    divArray[divArray.length] = divObj;
    bodyDivObj.insertBefore(divObj,null);
    
    divObj.style.position="absolute";
    divObj.style.cursor="hand";
    var cellWidth = tableDefine.CellWidth;
    var border = tableDefine.Border;
    var leftWidth = tableDefine.LeftWidth + tableDefine.Border*2;
    var cellHeight = tableDefine.CellHeight;
    divObj.style.width=cellWidth;
    divObj.style.left = leftWidth + (cellWidth+border)*column + "px";
    //高度计算
    var topLen;
    topLen = GetDivHeightOffset(resourceLendLog, row, count);
    var divTop= cellHeight*topLen[0]+4;
    if(topLen[0]==0){
        divTop -=4;
    }
    divObj.style.top = divTop + "px";
    var divHeight=cellHeight*topLen[1]-1;
    if(topLen[0]==0)
    {
        divHeight +=4;
    }
    divObj.style.height = divHeight + "px";
    divObj.style.overflow="hidden";
    divObj.id = "d"+resourceLendLog.LendLogId+""+resourceLendLog.ResourceId;
    
    divObj.style.backgroundColor =headColorList[resourceLendLog.Color];
    
    var timeStr = PaddingLeft(resourceLendLog.SHour,'0',2) +":"+ PaddingLeft(resourceLendLog.SMinute,'0',2)
                    +" - "+ PaddingLeft(resourceLendLog.EHour,'0',2)+":"+PaddingLeft(resourceLendLog.EMinute,'0',2);
    var stateText = GetStateText(resourceLendLog.State); 
    
    var username = resourceLendLog.Username;
    
    if(topLen[1]==1)
    {
        divObj.style.padding="3";
        divObj.title =username+"("+timeStr+") "+stateText;
        divObj.innerHTML = "<NOBR>"+username+"("+timeStr+") "+stateText+"</NOBR>";
        divObj.style.fontSize="12px";
        divObj.style.color="#FFFFFF";
        divObj.style.overflow="hidden";
        divObj.style.textOverflow="ellipsis";
    
    }
    else if(topLen[1]>1)
    {
        divObj.style.padding="1px";
        divObj.style.paddingTop="2px";
        divObj.style.paddingBottom="1px";
    
        var tableObj = document.createElement("Table");
        tableObj.id="t"+resourceLendLog.LendLogId+''+resourceLendLog.ResourceId;
        tableObj.cellSpacing = "0px";
        tableObj.cellPadding = "0px";
        var newRow = tableObj.insertRow(-1);
        var newCell = newRow.insertCell(-1);
        var newRow1 = tableObj.insertRow(-1);
        var newCell1 = newRow1.insertCell(-1);
        
        tableObj.style.width ="100%";
        tableObj.style.borderWidth ="0px";
        tableObj.style.borderStyle ="solid";
        tableObj.style.borderColor = headColorList[resourceLendLog.Color];
        newCell.style.backgroundColor = headColorList[resourceLendLog.Color];
        newCell.style.width="100%";
        newCell.style.paddingLeft="2px";
        newCell.style.height=cellHeight-1 -2>0?(cellHeight-1-2 ):0;
        newCell.style.fontSize="12px";
        newCell.style.color="#FFFFFF";
        
        var divObj2 = document.createElement('div');
        divObj2.title = username+"("+timeStr+")";
        divObj2.style.width = cellWidth-4 + "px";
        divObj2.innerHTML = "<NOBR>"+username+"("+timeStr+")</NOBR>";
        divObj2.style.fontSize="12px";
        divObj2.style.overflow="hidden";
        divObj2.style.textOverflow="ellipsis";
        newCell.insertBefore(divObj2,null);
        
        newCell1.style.backgroundColor = colorList[resourceLendLog.Color];
        newCell1.style.width="100%";
        newCell1.style.paddingTop="0px";
        newCell1.style.paddingLeft="2px";
        newCell1.style.height=(divHeight-cellHeight+1 -1  )>0?(divHeight-cellHeight +1 -1):0;
        newCell1.style.fontSize="12px";
        newCell1.style.color="#FFFFFF";
        newCell1.style.verticalAlign="top";    
        var newHTML = "[" + stateText + "]";
        newHTML += "<br><b>" + resourceLendLog.Subject + "</b>";
        newCell1.innerHTML = newHTML;
        
        divObj.insertBefore(tableObj,null);
    
    }    
    Nifty('div#'+divObj.id,'small');
}



function GetBeginEndCount()
{
    var beginCount = 1, endCount = 1;
    for(var i=0; i<checkedResourceArray.length; i++)
    {
       var key="_"+ checkedResourceArray[i].Id;
       var array = resourceLendLogArray[key];
       if(array==null)continue;
       var cBeginCount = 1, cEndCount = 1;
       for(var j=0; j<array.length; j++)
       {
            if(parseInt(array[j].SHour, 10)<9 && parseInt(array[j].EHour, 10)<=9)
            {
                array[j].Row = cBeginCount -1;
                cBeginCount++;
            
            }
            else if(parseInt(array[j].SHour, 10)>=21)
            {
                array[j].Row = cEndCount -1;
                cEndCount++;
            
            }        
       }
       if(cBeginCount>beginCount)
       {
            beginCount = cBeginCount;
       }
       if(cEndCount>endCount)       
       {
            endCount = cEndCount;
       }
    
    }
    return [beginCount, endCount];
}

function SortCheckedResourceLendLogs()
{
    //先根据时间排序
    for(var i=0; i<checkedResourceArray.length; i++)
    {
        var key="_"+ checkedResourceArray[i].Id;
        if(resourceLendLogArray[key]!=null)
            SortResourceLendLogs(resourceLendLogArray[key]);
    }

}

//租赁记录按时间排序
function SortResourceLendLogs(array)
{
    var tmp;
    var ischange= false;
    for(var i=array.length-1; i>0; i--)
    {
        for(var j =0;j<i; j++)
        {
            if(array[j].SYear>array[j+1].SYear)
            {//先比较年
                tmp = array[j];
                array[j]=array[j+1];
                array[j+1]=tmp;
                ischange = true;
                continue;
            }
            else if(array[j].SYear<array[j+1].SYear)
            {
                continue;
            }
            if(array[j].SMonth>array[j+1].SMonth)
            {
                tmp = array[j];
                array[j]=array[j+1];
                array[j+1]=tmp;
                ischange = true;
                continue;
            }
            else if(array[j].SMonth<array[j+1].SMonth)
            {
                continue;
            }
            
            
            
            if(array[j].SDay>array[j+1].SDay)
            {
                tmp = array[j];
                array[j]=array[j+1];
                array[j+1]=tmp;
                ischange = true;
                continue;
            }
            else if(array[j].SDay<array[j+1].SDay)
            {
                continue;
            }
            
            
            if(array[j].SHour>array[j+1].SHour)
            {
                tmp = array[j];
                array[j]=array[j+1];
                array[j+1]=tmp;
                ischange = true;
                continue;
            }
            else if(array[j].SHour<array[j+1].SHour)
            {
                continue;
            }
            
            if(array[j].SMinute>array[j+1].SMinute)
            {
                tmp = array[j];
                array[j]=array[j+1];
                array[j+1]=tmp;
                ischange = true;
                continue;
            }
            else if(array[j].SMinute<array[j+1].SMinute)
            {
                continue;
            }
            
            
            if(array[j].SSecond>array[j+1].SSecond)
            {
                tmp = array[j];
                array[j]=array[j+1];
                array[j+1]=tmp;
                ischange = true;
                continue;
            }
            else if(array[j].SSecond<array[j+1].SSecond)
            {
                continue;            
            }        
        }
        //没有交换位置
        if(!ischange)
        {
            break;
        }
        ischange = false;    
    }
}


function SetDaysResourceLendLogs(){


}


function ShowDaysResourceLendLogs()
{    
    //先根据时间排序
    SortCheckedResourceLendLogs();
    var maxResourceDaysRows = GetResourceDaysRowsCount();
    SetBodyTds(maxResourceDaysRows);
    DrawDaysResourceLendLogDivs(maxResourceDaysRows);
}

function SetBodyTds(maxResourceDaysRows)
{
    var tableDefine = GetBodyCellDefine();
    var cellHeight = tableDefine.CellHeight;
    var itemSpacing = tableDefine.ItemSpacing;
    var column = 0;
    var row;
    for(var i=0; i<days; i++)
    {
        var bodyTdObj = document.getElementById('BodyTd'+i+"_"+column);
        if(maxResourceDaysRows[i]>3)
        {
            bodyTdObj.style.height = cellHeight*maxResourceDaysRows[i] + itemSpacing*(maxResourceDaysRows[i]+1) + "px";
        }    
    }
}

function GetResourceDaysRowsCount()
{
    var resourceDaysRows = new Array();
    for(var i=0; i<checkedResourceArray.length; i++)
    {
        var key="_"+ checkedResourceArray[i].Id;
        resourceDaysRows[i] = new Array();
        if(resourceLendLogArray[key]!=null)
            GetResourceRowsCount(resourceLendLogArray[key], resourceDaysRows[i]);
    }
    
    var maxResourceDaysRows = new Array();
    for(var j=0;j<days; j++)
    {
         maxResourceDaysRows[j] = daysDefaultItemCount;                
    }
    
    for(var i=0; i<checkedResourceArray.length; i++)
    {
        var key="_"+ checkedResourceArray[i].Id;
        if(resourceLendLogArray[key]!=null)
        {
            
            for(var j=0;j<days; j++)
            {
                if(maxResourceDaysRows[j] < resourceDaysRows[i][j])
                {
                    maxResourceDaysRows[j] = resourceDaysRows[i][j];
                }
            }
        }
    }
    return maxResourceDaysRows;
}



function GetResourceRowsCount(resourceLendLogArray, daysRows)
{
    for(var i=0; i<days; i++)
    {
        daysRows[i] = 0;    
    }
    for(var i=0; i<resourceLendLogArray.length; i++)
    {
        var sDateStr = resourceLendLogArray[i].SYear 
        +PaddingLeft(resourceLendLogArray[i].SMonth,'0',2)
        +PaddingLeft(resourceLendLogArray[i].SDay,'0',2);
        var sDate = IntToDate(sDateStr);
        var eDateStr = resourceLendLogArray[i].EYear 
        +PaddingLeft(resourceLendLogArray[i].EMonth,'0',2)
        +PaddingLeft(resourceLendLogArray[i].EDay,'0',2);
        var eDate = IntToDate(eDateStr);
        
        var calendarStartDate = IntToDate(startDate.date);
        
        
        var offset = DateDiff(sDate, calendarStartDate);
        var len = DateDiff(eDate, sDate);
        if(PaddingLeft(resourceLendLogArray[i].EHour,'0',2)!='00'
            ||PaddingLeft(resourceLendLogArray[i].EMinute,'0',2)!='00'
            ||PaddingLeft(resourceLendLogArray[i].ESecond,'0',2)!='00')
        {
            len = len+1;            
        }
        for(var j=0; j<len; j++)
        {
            daysRows[offset+j]++;
        } 
    }
}
//画所有的租赁记录div
function DrawDaysResourceLendLogDivs(maxResourceDaysRows)
{
    var tableDefine = GetBodyCellDefine();
    divArray = new Array();
    for(var i=0; i<checkedResourceArray.length; i++){
       var key="_"+ checkedResourceArray[i].Id;
       var array = resourceLendLogArray[key];
       if(array==null)continue;
       var daysRowArray = new Array();
       for(var j=0; j<days; j++)
       {
            daysRowArray[j] = 0;
       }
       for(var j=0; j<array.length; j++)
       {             
             DrawDaysResourceLendLogDiv(i, tableDefine, daysRowArray,maxResourceDaysRows, array[j]);    
       }
    }
}
function CountResult(a,b,c)
{
    var temp = parseInt(a,10);
    var temp1 = temp-b;
    var temp2 = temp1/c;
    return Math.floor((parseInt(a,10)-b)/c);
}

function GetDaysDivHeightOffset(resourceLendLog, daysRowArray, maxResourceDaysRows){
    var top =0;
    var len =0;
    var beginZero = false;
    var endZero = false;
    var endIn=true;
        
     var sDateStr = resourceLendLog.SYear 
        +PaddingLeft(resourceLendLog.SMonth,'0',2)
        +PaddingLeft(resourceLendLog.SDay,'0',2);
    var sDate = IntToDate(sDateStr);
    var eDateStr = resourceLendLog.EYear 
        +PaddingLeft(resourceLendLog.EMonth,'0',2)
        +PaddingLeft(resourceLendLog.EDay,'0',2);
    var eDate = IntToDate(eDateStr);
    var calendarStartDate = IntToDate(startDate.date);    
    
    var offset = DateDiff(sDate, calendarStartDate);
    var diffDays = DateDiff(eDate, sDate);    
        
    if (offset<0) 
    {
        diffDays+=offset;
        offset=0;        
    }   
    else 
    {
        top +=3*offset+CountResult(resourceLendLog.SHour,8,5);
        len -=CountResult(resourceLendLog.SHour,8,5);
    }
    if (diffDays+offset>maxResourceDaysRows.length) 
    {
        diffDays=maxResourceDaysRows.length-offset;        
        endIn=false;
    }
    else
        len +=CountResult(resourceLendLog.EHour,12,5);
     
    if(diffDays<1)
    {
        if(PaddingLeft(resourceLendLog.EHour,'0',2)=='00'
            && PaddingLeft(resourceLendLog.EMinute,'0',2)=='00'
            && PaddingLeft(resourceLendLog.ESecond,'0',2)=='00')
       {
            if (maxResourceDaysRows[offset]&&daysRowArray[offset])
                len +=maxResourceDaysRows[offset]-daysRowArray[offset];
        }
        else
        {
            len +=1;
        }
    }
    else
    {
          len +=3*diffDays-daysRowArray[offset];
          if (endIn) len+=1;
    }
    
    for(var i=0;i<diffDays+1; i++)
    {
        daysRowArray[offset+i]++;
    } 
      
    return [top, len, offset, diffDays, beginZero, endZero];


}

//在表格上画上租赁记录
function DrawDaysResourceLendLogDiv(column, tableDefine, daysRowArray,maxResourceDaysRows, resourceLendLog)
{
    if ((resourceLendLog.State == "73") && (resourceLendLog.Privilege.substring(6,7) != "1"))
    {
        return;
    }
    var bodyDivObj = document.getElementById('BodyDiv');
    //var divObj = document.createElement('<DIV onclick="ShowResourceState(\''+resourceLendLog.resourceStr+'\')">');
    var divObj = document.createElement("Div");
    if(resourceLendLog.Privilege.substring(6, 7) == "1" || resourceLendLog.Privilege.substring(7, 8) == "1")
    {
        divObj.onclick = function(){ShowResourceState(resourceLendLog.resourceStr);};
    }
    divArray[divArray.length] = divObj;
    bodyDivObj.insertBefore(divObj,null);
    divObj.style.position="absolute";
    divObj.style.cursor="hand";
    var cellWidth = tableDefine.CellWidth;
    var border = tableDefine.Border;
    var leftWidth = tableDefine.LeftWidth + tableDefine.Border*2;
    var cellHeight = tableDefine.CellHeight;
    var itemSpacing = tableDefine.ItemSpacing;
    divObj.style.width=cellWidth + "px";
    //alert(divObj.style.width);
    divObj.style.left = leftWidth + (cellWidth+border)*column + "px";
    //alert(divObj.style.left);
    //高度计算
    var array = GetDaysDivHeightOffset(resourceLendLog, daysRowArray, maxResourceDaysRows);
    var top = array[0];
    var len = array[1];
    var offset = array[2];
    var diffDays = array[3];
    var beginZero = array[4];
    var endZero = array[5];
    var divTop = cellHeight*top+ itemSpacing*(top+offset+1) +1 ;//+ offset*border;
    var divHeight = cellHeight*len+ itemSpacing*(len+diffDays-1) -1 ;//+ diffDays*border;
    if(beginZero)
    {
        divTop -= itemSpacing;
        if(len>1)
        {
            divHeight += itemSpacing;
        }
    }
    if(endZero)
    {
        if(len>1)
        {
            divHeight +=itemSpacing;
        }
    }
    resourceLendLog.divTop = divTop;
    resourceLendLog.divHeight = divHeight;
    divObj.style.top = divTop + "px";
    divObj.style.height= divHeight + "px";
    //alert(divObj.style.top+":"+divObj.style.height);
    divObj.style.overflow="hidden";
    divObj.id = "d"+resourceLendLog.LendLogId+""+resourceLendLog.ResourceId;
    var bgColore = "";
    var bgValueColore = "";
    if(resourceLendLog.Privilege.substring(6, 7) == "1" || resourceLendLog.Privilege.substring(7, 8) == "1")
    {
        bgColore = headColorList[resourceLendLog.Color];
        bgValueColore = colorList[resourceLendLog.Color];
        
    }
    else
    {
        bgColore = headColorList[2];
        bgValueColore = colorList[2];
    }
    divObj.style.backgroundColor =bgColore;
    
    var timeStr = PaddingLeft(resourceLendLog.SMonth, '0', 2) +"/"+ PaddingLeft(resourceLendLog.SDay, '0', 2)
                    +" - "+ PaddingLeft(resourceLendLog.EMonth, '0', 2) +"/"+ PaddingLeft(resourceLendLog.EDay, '0', 2);
    var stateText = ((resourceLendLog.Privilege.substring(6, 7) == "1" || resourceLendLog.Privilege.substring(7, 8) == "1"))?GetStateText(resourceLendLog.State):"已租借";
    //var stateText = GetStateText(resourceLendLog.State);
    var username = resourceLendLog.Username;
    
    if(len==1)
    {
        divObj.style.padding="2px";
        divObj.style.paddingBottom="4px";
        divObj.title = stateText+"("+timeStr+")";;//username+" "+stateText+"("+timeStr+")";
        divObj.innerHTML = "<NOBR>"+stateText+"("+timeStr+")"+"</NOBR>";//"<NOBR>"+username+" "+stateText+"("+timeStr+")"+"</NOBR>";
        divObj.style.fontSize="12px";
        divObj.style.color="#FFFFFF";
        divObj.style.overflow="hidden";
        divObj.style.textOverflow="ellipsis";
    
    }
    else
    {
        divObj.style.padding="1px";
        divObj.style.paddingTop="2px";
        divObj.style.paddingBottom="1px";
    
        //var tableObj = document.createElement('<Table id="t'+resourceLendLog.LendLogId+''+resourceLendLog.ResourceId+'" cellspacing="0" cellpadding="0">');
        var tableObj = document.createElement("Table");
        tableObj.id="t"+resourceLendLog.LendLogId+''+resourceLendLog.ResourceId;
        tableObj.cellSpacing = "0px";
        tableObj.cellPadding = "0px";
        var newRow = tableObj.insertRow(-1);
        var newCell = newRow.insertCell(-1);
        var newRow1 = tableObj.insertRow(-1);
        var newCell1 = newRow1.insertCell(-1);
        
        tableObj.style.width ="100%";
        tableObj.style.borderWidth ="0px";
        tableObj.style.borderStyle ="solid";
        
        tableObj.style.borderColor = bgColore;
        newCell.style.backgroundColor = bgColore;
        newCell.style.width="100%";
        newCell.style.paddingLeft="2px";
        newCell.style.height=cellHeight-1 -2>0?(cellHeight-1-2 )+"px":"0px";
        newCell.style.fontSize="12px";
        newCell.style.color="#FFFFFF";
        var divObj2 = document.createElement('div');
        divObj2.title = timeStr;//username+"("+timeStr+")";
        divObj2.style.width = cellWidth-4 + "px";
        divObj2.innerHTML = "<NOBR>"+timeStr+"</NOBR>";//"<NOBR>"+username+"("+timeStr+")</NOBR>";
        divObj2.style.fontSize="12px";
        divObj2.style.overflow="hidden";
        divObj2.style.textOverflow="ellipsis";
        //newCell.insertBefore(divObj2);
        newCell.insertBefore(divObj2,null);
        
        newCell1.style.backgroundColor = bgValueColore;
        newCell1.style.width="100%";
        newCell1.style.paddingTop="0px";
        newCell1.style.paddingLeft="2px";
        var height = divHeight - cellHeight ;
        newCell1.style.height=height>0?height+"px":"0px";
        newCell1.style.fontSize="12px";
        newCell1.style.color="#FFFFFF";
        newCell1.style.verticalAlign="top";    
        newCell1.innerHTML = stateText;
        divObj.insertBefore(tableObj,null);
    }
    Nifty('div#'+divObj.id,'small');
}



function ClearDivs()
{
    if(divArray==null)return;
    try
    {
        for(var i=0; i<divArray.length ;i++)
        {
            UnNifty('div#d'+divArray[i].LendLogId+"_"+divArray[i].ResourceId);
            if(divArray[i].parentNode)
                divArray[i].parentNode.removeChild(divArray[i]);
        }
    }catch(e){
    }
}


var colorSelect = "#deeafa";
var beginTd = null;
var endTd = null;
var tdArray = null;
var mouseDown = false;
var changed = false;
function TDMouseDown(evt)
{
    mouseDown = true;
    ClearColor();
    beginTd = null;
    endTd = null;
    
    var oEvent = evt ? evt : window.event;
    beginTd = oEvent.target ? oEvent.target : oEvent.srcElement;
}

function TDMouseOver(evt){
    if(!mouseDown)return;
    
    ClearColor();
    
   var oEvent = evt ? evt : window.event;
   
    endTd = oEvent.target ? oEvent.target : oEvent.srcElement;
    ChangeTd();
}

function TDMouseUp(evt){
    if(!mouseDown){return;}
    
   var oEvent = evt ? evt : window.event;
   if(!oEvent.y)
    oEvent.y = oEvent.pageY;
    beginTd.y = oEvent.y;
     mouseDown = false;
     var type = beginTd.id.substring(0, 6);
    
    if(type == "BodyTd")
    {
        var rc = beginTd.id.substring(6, beginTd.id.length);
        var rcArray = rc.split('_');
        var cell = parseInt(rcArray[1], 10);
        var row = parseInt(rcArray[0],10);
        
        if(days==1)
        {
            if(row%2==0&&cell==0)
            {
                return;
            }
        }
        else if(days>1)
        {
            if(row%3==0&&cell==0)
            {
                return;
            }
        }
        
        if(days==1)
        {
            if(endTd==null || endTd.id == beginTd.id)
            {
                if(row%2==0)
                {
                    cell = cell -1;
                }
                else
                {
                    cell = cell +1;
                }
                var obj = document.getElementById(type+""+eval(row+1)+"_"+cell);
                endTd = obj;
                ChangeTd();
            
            }
        }
        else if(days>1)
        {
            if(endTd == null)
            {
                endTd = beginTd;
                ChangeTd();
            }
        }
    }
    else
    {
        return;
    }
    
    if(changed)
    {
        var temp = beginTd;
        beginTd = endTd;
        endTd = temp;  
    }
    AddResourceState();    
}


function ChangeTd()
{
    var type = beginTd.id.substring(0, 6);
    var type2 = endTd.id.substring(0, 6);
    changed = false;
    if(type == "BodyTd" && type2 =="BodyTd" )
    {        
        var rc = beginTd.id.substring(6, beginTd.id.length);
        var rcArray = rc.split('_');
        var cell = parseInt(rcArray[1], 10);
        var row = parseInt(rcArray[0],10);
        
        //第一列不处理
       if(days==1)
       {
            if(row%2==0&&cell==0)return;       
       }
       else if(days>1)
       {
            if(row%3==0&&cell == 0)return;
       }
        var rc2 = endTd.id.substring(6, endTd.id.length);
        var rc2Array = rc2.split('_');
        var cell2 = parseInt(rc2Array[1], 10);
        var row2 = parseInt(rc2Array[0],10);
        
       
       if(row>row2)
       {
       
            if(days==1)
            {
                if(row%2==0&&row2%2==0)
                {
                    cell2 = cell;
                }
                else if(row%2==0&&row2%2==1)
                {
                    cell2 = cell-1;
                }
                else if(row%2==1&&row2%2==0)
                {
                    cell2 = cell+1;
                }
                else if(row%2==1&&row2%2==1)
                {
                    cell2 = cell;
                }
            
            }
            else if(days>1)
            {
                
                if(row%3==0&&row2%3==0){
                    cell2 = cell;
                }
                else if(row%3==0&&row2%3!=0)
                {
                    cell2 = cell-1;
                }
                else if(row%3!=0&&row2%3==0)
                {
                    cell2 = cell+1;
                }
                else if(row%3!=0&&row2%3!=0)
                {
                    cell2 = cell;
                }            
            }
            
            endTd = document.getElementById(type+""+row2+"_"+cell2);
       
            var temp = beginTd;
            beginTd = endTd;
            endTd = temp;       
            
            
            
            rc = beginTd.id.substring(6, beginTd.id.length);
            rcArray = rc.split('_');
            cell = parseInt(rcArray[1], 10);
            row = parseInt(rcArray[0],10);
            
            rc2 = endTd.id.substring(6, endTd.id.length);
            rc2Array = rc2.split('_');
            cell2 = parseInt(rc2Array[1], 10);
            row2 = parseInt(rc2Array[0],10);            
            changed = true;
        }     
        
        tdArray = new Array();
        
        for(var i=row; i<row2+1; i++)
        {
            var newCell = cell;
            if(days==1)
            {
                if(row%2==0&&(i-row)%2 ==1)
                {
                    newCell = cell -1;
                }
                else if(row%2==1&&(i-row)%2 ==1)
                {
                    newCell = cell +1;
                }
            }
            else
            {
                if(row%3==0&&(i-row)%3 !=0)
                {
                    newCell = cell -1;
                }else if(row%3!=0&& i%3 ==0)
                {
                    newCell = cell +1;
                }
            }
            RevertColor(type+""+i+"_"+newCell);
            tdArray[tdArray.length] = type+""+i+"_"+newCell;
        }
    }
    if(changed)
    {
        var temp = beginTd;
        beginTd = endTd;
        endTd = temp;    
    }
}
function RevertColor(id)
{
    try
    {
        var obj = document.getElementById(id);
        obj.style.backgroundColor = colorSelect;
    }catch(e){};
}

function ClearColor()
{
    try
    {
        for(var i=0;tdArray!=null&& i<tdArray.length; i++)
        {
            var obj = document.getElementById(tdArray[i]);
            obj.style.backgroundColor = "#FFFFFF";
        }
    }catch(e){
    }
    tdArray = null;
}

function AddResourceState()
{
    if(!isFinished){
        return;
    }
    isFinished = false;
    
    AddResource();
    
    isFinished = true;
}

//添加会议室一条租赁记录
function ApplyResource(resourceId)
{

    var sYearObj = document.getElementById('sYear');
    var sMonthObj = document.getElementById('sMonth');
    var sDayObj = document.getElementById('sDay');
    
    var sHourObj = document.getElementById('sHour');
    var sMinuteObj = document.getElementById('sMinute');
    var sSecondObj = document.getElementById('sSecond');
    
    var eYearObj = document.getElementById('eYear');
    var eMonthObj = document.getElementById('eMonth');
    var eDayObj = document.getElementById('eDay');
    
    var eHourObj = document.getElementById('eHour');
    var eMinuteObj = document.getElementById('eMinute');
    var eSecondObj = document.getElementById('eSecond');

    var startDate = sYearObj.value+sMonthObj.value+sDayObj.value;
    var endDate = eYearObj.value+eMonthObj.value+eDayObj.value;
    var startTime = sHourObj.value+sMinuteObj.value + sSecondObj.value;
    var endTime = eHourObj.value+eMinuteObj.value + eSecondObj.value;
    EQD.SciencePark.Meeting.MeetingAjax.CheckAddMeetingRentRecordAjax(resourceId, startDate, startTime, endDate, endTime, ApplyResourceValue);

}
function ApplyResourceValue(result)
{
    if(result.value != null && result.value != "1")
    {
        var resourceId = result.value;
        var milesToRunObj;
        var milesToRun;
        var conferenceTitleObj;
        var conferenceTitle;
        var conferenceMemberObj;
        var conferenceMember;
         conferenceTitleObj = document.getElementById('conferenceTitle');
         conferenceTitle = conferenceTitleObj.value;    
         if(conferenceTitle=="")
         {
            alert("会议室标题不能为空！");
            conferenceTitleObj.focus();
            return;    
        }
            
        var rentorNameObj = document.getElementById('rentorName');
        if(rentorNameObj.value=="")
        {
            alert("申请人姓名不能为空");
            rentorNameObj.focus();
            return;
        }
        var rentorCompanyObj = document.getElementById('rentorCompany');
        if(rentorCompanyObj.value=="")
        {
            alert("申请公司不能为空");
            rentorCompanyObj.focus();
            return;
        }
        var rentorTelObj = document.getElementById('rentorTel');
        if(rentorTelObj.value=="")
        {
            alert("联系电话不能为空");
            rentorTelObj.focus();
            return;
        }
        var curDate  = new Date();
        var rentLogStartDate = curDate.getYear()+"-"+(curDate.getMonth()+1)+"-"+curDate.getDate();//document.getElementById("tbRentLogStartDate").value
        
        var sYearObj = document.getElementById('sYear');
        var sMonthObj = document.getElementById('sMonth');
        var sDayObj = document.getElementById('sDay');
        
        var sHourObj = document.getElementById('sHour');
        var sMinuteObj = document.getElementById('sMinute');
        var sSecondObj = document.getElementById('sSecond');
        
        var eYearObj = document.getElementById('eYear');
        var eMonthObj = document.getElementById('eMonth');
        var eDayObj = document.getElementById('eDay');
        
        var eHourObj = document.getElementById('eHour');
        var eMinuteObj = document.getElementById('eMinute');
        var eSecondObj = document.getElementById('eSecond');
        
        var reasonObj = document.getElementById('Reason');    
        var rentorTexObj = document.getElementById('rentorTex');
            
        var rentorName=rentorNameObj.value;
        var rentorCompany=rentorCompanyObj.value;
        var rentorTel=rentorTelObj.value;
        var rentorTex=rentorTexObj.value; 
        
        var startDate = sYearObj.value+sMonthObj.value+sDayObj.value;
        var endDate = eYearObj.value+eMonthObj.value+eDayObj.value;
        var startTime = sHourObj.value+sMinuteObj.value + sSecondObj.value;
        var endTime = eHourObj.value+eMinuteObj.value + eSecondObj.value;
        var reason = reasonObj.value;
        
        EQD.SciencePark.Meeting.MeetingAjax.AddRoomLendLog(resourceId, startDate, startTime, endDate, endTime, conferenceTitle, rentorName,  rentorCompany,  rentorTel,  rentorTex,reason,"",rentLogStartDate, AddResourceStateReturn);
        isFinished = true;
    }
    else
    {
        alert("不能在这个时间段申请租赁");
    }
}

//添加一条租赁记录成功后 取值刷新表格
function AddResourceStateReturn(result)
{    
    isFinished = false;
    if(result.value != null)
    {
        var lendLogId = result.value;
                    
        var sDate = IntToDate(startDate.date);
        var eDate = AddDays(sDate, days-1);
        
        var sDateStr = DateToStr(sDate,"");
        var eDateStr = DateToStr(eDate,"");
        
        var sTimeStr ="000000";
        var eTimeStr ="235959";   
        EQD.SciencePark.Meeting.MeetingAjax.GetLendLogByLendLogID(lendLogId, GetLendLogByLendLogIDReturn);
        ClosePopWindow();             
    }
    else
    {
        //ClosePopWindow();   
        alert("添加失败！");            
        isFinished = true;
    }
}
function ChangeResourceStateReturn(lendLogId)
{
    EQD.SciencePark.Meeting.MeetingAjax.GetLendLogByLendLogID(lendLogId, GetLendLogByLendLogIDReturn);
    RefreshMe();
}
function GetLendLogByLendLogIDReturn(result)
{
    if(result!=null && result.value!=null && result.value != "")
    {
        var resourceInfo = result.value;
        var newResourceLendLog = ParseResource(resourceInfo);
        if(newResourceLendLog==null)
        {
            return;
        }
        var key = "_"+newResourceLendLog.ResourceId;
        if(resourceLendLogArray[key]==null)
        {
            resourceLendLogArray[key] = new Array();
        }
        newResourceLendLog.resourceStr = resourceInfo;
        var index = GetExistedLendLog(resourceLendLogArray[key], newResourceLendLog.LendLogId);
        if(index ==-1)
        {
            resourceLendLogArray[key][resourceLendLogArray[key].length]= newResourceLendLog;  
        }
        else
        {
            resourceLendLogArray[key][index]= newResourceLendLog; 
        }        
        RefreshMe(); 
    } 
    globalLendLogId = -1;
    isFinished = true;
}

function GetExistedLendLog(resourceLendLogs, lendLogId)
{
    for(var i=0;i<resourceLendLogs.length; i++)
    {
        if(resourceLendLogs[i].LendLogId == lendLogId)
        {
            return i;
        }
    }
    return -1;
}


//删除一条预约租赁记录成功刷新表格
function DeleteResourceStateReturn(result)
{
    if(result!=null && result.value!=null && result.value != "")
    {
        if(result.value=="0")
        {
            var lendLogId = globalLendLogId;
            var resourceId = globalResourceId;
            if(lendLogId!=-1)
            {
                var key = "_"+resourceId;
                if(resourceLendLogArray[key]!=null)
                {
                    var index = GetExistedLendLog(resourceLendLogArray[key], lendLogId);
                    if(index >-1)
                    {
                        for(var i=index;i<resourceLendLogArray[key].length-1; i++)
                        {
                            resourceLendLogArray[key][i]= resourceLendLogArray[key][i+1]; 
                        }
                        resourceLendLogArray[key].length = resourceLendLogArray[key].length-1;
                        RefreshMe();  
                    }        
                }
            }        
        }
    }         
    isFinished = true;
    globalLendLogId = -1;
    globalResourceId =-1;
}
//显示一条租赁记录信息
function ShowResourceState(resourceStr)
{
    if(!isFinished)
    {
        return;
    }
    
    isFinished = false;
    var infoArray = resourceStr.split("\x1c");
    var lendLogId = infoArray[0];
    var resourceId = infoArray[1];
    var state = infoArray[2];
    var color = infoArray[3];
    var sYear = infoArray[4];
    var sMonth = infoArray[5];
    var sDay = infoArray[6];
    var sHour = infoArray[7];
    var sMinute = infoArray[8];
    var sSecond = infoArray[9];
    var eYear = infoArray[10];
    var eMonth = infoArray[11];
    var eDay = infoArray[12];
    var eHour = infoArray[13];
    var eMinute = infoArray[14];
    var eSecond = infoArray[15];
    var privilege = infoArray[16];
    var username = infoArray[17];
    var reason = infoArray[18];
    var fuwu = infoArray[19];
    var shebei = infoArray[20];
    var timeStr = sYear +"年"+ PaddingLeft(sMonth,'0', 2) +"月"+PaddingLeft(sDay,'0', 2) +"日" +PaddingLeft(sHour,'0', 2)+"时";//+PaddingLeft(sMinute,'0', 2)+"分"
                    +" - "+eYear +"年"+ PaddingLeft(eMonth,'0', 2) +"月"+PaddingLeft(eDay,'0', 2) +"日" +PaddingLeft(eHour,'0', 2)+"时";//+PaddingLeft(eMinute,'0', 2)+"分";
    
    var resourceName = resourceHashMap["_"+resourceId].Name;
    var about = resourceHashMap["_"+resourceId].About;
    var stateText = GetStateText(state);
    var popWindowObj = document.getElementById('PopWindow');
    
    str = '<table style="width:100%;background-color:#FFFFFF;" cellspacing="0" cellpadding="0" class="table_1" border="1"><tr><td  colspan="2" class="CommonText"><div style="float:right;display:inline;position:relative;top:1px;right:1px;cursor:pointer" onclick="ClosePopWindow();"><img src="images/close-small.gif"></div>';
    str +='</td></tr>';
    str +='<tr><td class="CommonText"><strong>状态：</strong></td>';
    str +='<td style="color:#3e5c9c">&nbsp;' +stateText + '</td></tr>';
    
//    str +='<tr><td class="CommonText"><strong>租赁起始时间：</strong></td>';
//    str +='<td style="color:#3e5c9c">&nbsp;'+infoArray[33]+'</td></tr>';
    
    str +='<tr><td class="CommonText"><strong>时间：</strong></td>';
    str +='<td style="color:#3e5c9c">&nbsp;' +timeStr + '</td></tr>';
    if(parseInt(privilege.substring(0,1), 10)==1 || parseInt(privilege.substring(1,2), 10)==1 || parseInt(privilege.substring(2,3), 10)==1 || parseInt(privilege.substring(3,4), 10)==1 || parseInt(privilege.substring(4,5), 10)==1 || parseInt(privilege.substring(5,6), 10)==1 || parseInt(privilege.substring(8,9), 10)==1)
    {
        str +='<tr><td class="CommonText" ><strong>会议议题：</strong></td>';
        str +='<td style="color:#3e5c9c">&nbsp;' +reason + '</td></tr>';
        str +='<tr><td class="CommonText"><strong>申请公司：</strong></td>';
        str +='<td style="color:#3e5c9c">&nbsp;' +infoArray[21] + '</td></tr>';  
        
        
        str +='<tr><td class="CommonText"><strong>申请人：</strong></td>';
        str +='<td style="color:#3e5c9c">&nbsp;' +infoArray[23] + '</td></tr>';  
        
        
        str +='<tr><td class="CommonText"><strong>申请原因：</strong></td>';
        str +='<td style="color:#3e5c9c">&nbsp;' +infoArray[28] + '</td></tr>';        
        
        str +='<tr><td class="CommonText"><strong>申请服务：</strong></td>';
        str +='<td style="color:#3e5c9c">&nbsp;' +fuwu + '</td></tr>';
        str +='<tr><td class="CommonText"><strong>申请设备：</strong></td>';
        str +='<td style="color:#3e5c9c">&nbsp;' +shebei + '</td></tr>';  
        
            
        switch(parseInt(state, 10))
        {
            case 72:
                //预约确定
                str += '<tr><td><strong>应缴纳订金：</strong></td><td style="color:#3e5c9c">&nbsp;'+infoArray[24]+'</td></tr>';
                str += '<tr><td><strong>订金缴纳期限：</strong></td><td style="color:#3e5c9c">&nbsp;'+infoArray[26]+'时</td></tr>';
                str += '<tr><td td colspan="2">您的申请已经审核通过，请在'+infoArray[26]+'时前缴纳订金</td></tr>';
                break;
            case 74:
                //预定
                str += '<tr><td><strong>实际缴纳订金：</strong></td><td style="color:#3e5c9c">&nbsp;'+infoArray[25]+'</td></tr>';
                str += '<tr><td><strong>缴纳订金实际时间：</strong></td><td style="color:#3e5c9c">&nbsp;'+infoArray[27]+'时</td></tr>';
                str += '<tr><td><strong>估计费用：</strong></td><td style="color:#3e5c9c">&nbsp;'+infoArray[31]+'</td></tr>';                
                str += '<tr><td><strong>费用结算时间：</strong></td><td style="color:#3e5c9c">&nbsp;'+infoArray[29]+'时</td></tr>';
                str += '<tr><td td colspan="2">您的申请已经成功预定，请在'+infoArray[29]+'时前缴纳费用</td></tr>';
                break;
            case 75:
                //租金结清
                str += '<tr><td><strong>实际缴纳费用：</strong></td><td style="color:#3e5c9c">&nbsp;'+infoArray[22]+'</td></tr>';
                str += '<tr><td><strong>缴纳费用实际时间：</strong></td><td style="color:#3e5c9c">&nbsp;'+infoArray[30]+'时</td></tr>';
                str += '<tr><td td colspan="2">租金结清</td></tr>';
                break; 
            case 73:
                //拒绝
                str += '<tr><td><strong>拒绝原因：</strong></td><td style="color:#3e5c9c">&nbsp;'+infoArray[32]+'</td></tr>';
                //str += '<tr><td td colspan="2">拒绝</td></tr>';
        }
        
    }
    str +='<tr><td colspan="2">';
    if(parseInt(privilege.substring(0,1), 10)==1&&parseInt(privilege.substring(1,2), 10)==1)//既是管理员也是申请人
    {
        str += '<input type="button" onclick="ShowLendLogInfo(\''+resourceId+'\',\''+lendLogId+'\')" value="查看详情" class="admin_btn1_1" >&nbsp;&nbsp;';
        str += '<input type="button" onclick="DeleteResourceState(\''+lendLogId+'\',\''+resourceId+'\')" value="删除" class="admin_btn1">&nbsp;&nbsp;';
        str += '<input type="button" onclick="FullApplyUpdate(\''+resourceId+'\',\''+lendLogId+'\')" value="修改" class="admin_btn1">&nbsp;&nbsp;';
        str += '<input type="button" onclick="ApproveResourceState(\''+lendLogId+'\')" value="批准" class="admin_btn1">&nbsp;&nbsp;';
    }
    else
    {
        if(parseInt(privilege.substring(0,1), 10)==1)//是自己的可进行查看修改 删除
        {
            str += '<input type="button" onclick="ShowLendLogInfo(\''+resourceId+'\',\''+lendLogId+'\')" value="查看详情" class="admin_btn1_1" >&nbsp;&nbsp;';
            str += '<input type="button" onclick="DeleteResourceState(\''+lendLogId+'\',\''+resourceId+'\')" value="删除" class="admin_btn1">&nbsp;&nbsp;';
            str += '<input type="button" onclick="FullApplyUpdate(\''+resourceId+'\',\''+lendLogId+'\')" value="修改" class="admin_btn1">&nbsp;&nbsp;';
        }
        else if(parseInt(privilege.substring(1,2), 10)==1)//管理员批准
        {
            str += '<input type="button" onclick="ShowLendLogInfo(\''+resourceId+'\',\''+lendLogId+'\')" value="查看详情" class="admin_btn1_1" >&nbsp;&nbsp;';
            str += '<input type="button" onclick="ApproveResourceState(\''+lendLogId+'\')" value="批准" class="admin_btn1">&nbsp;&nbsp;';
        }
        else if(parseInt(privilege.substring(8,9), 10)==1)//是否被拒绝
        {
            str += '<input type="button" onclick="DeleteResourceState(\''+lendLogId+'\',\''+resourceId+'\')" value="删除" class="admin_btn1">&nbsp;&nbsp;';
        }
        else if(parseInt(privilege.substring(6,7), 10)==1 && parseInt(privilege.substring(3,4), 10)!=1 && parseInt(privilege.substring(4,5), 10)!=1)//是否是自己
        {
            str += '<input type="button" onclick="ShowLendLogInfo(\''+resourceId+'\',\''+lendLogId+'\')" value="查看详情" class="admin_btn1_1" >&nbsp;&nbsp;';
        }
    }
    if(parseInt(privilege.substring(2,3), 10)==1)
    {
        str += '<input type="button" onclick="RefuseResourceState(\''+lendLogId+'\')" value="拒绝" class="admin_btn1">&nbsp;&nbsp;';
    }
    if(parseInt(privilege.substring(3,4), 10)==1)
    {
        str += '<input type="button" onclick="ShowLendLogInfo(\''+resourceId+'\',\''+lendLogId+'\')" value="查看详情" class="admin_btn1_1" >&nbsp;&nbsp;';
    
        str += '<input type="button" onclick="LendResourceState(\''+lendLogId+'\')" value="预定" class="admin_btn1">&nbsp;&nbsp;';
    }
    if(parseInt(privilege.substring(4,5), 10)==1)
    {
        str += '<input type="button" onclick="ShowLendLogInfo(\''+resourceId+'\',\''+lendLogId+'\')" value="查看详情" class="admin_btn1_1" >&nbsp;&nbsp;';
    
        str += '<input type="button" onclick="ReturnResourceState(\''+lendLogId+'\')" value="结算" class="admin_btn1">';
    }
    str +='</td></tr>';
    str +='</table>';
    popWindowObj.innerHTML = str;
    var x = event.clientX;
    var y = event.clientY;
    var width = 360;
    var height = 350;
    if(x+width > browserWidth)
    {
        x = browserWidth - width;
    }
    
    if(y+height>browserHeight)
    {
        y = browserHeight - height;
    }
    
    popWindowObj.style.left = x + "px";
    popWindowObj.style.top = y + "px";
    popWindowObj.style.display = 'block';
    popWindowObj.style.padding = '0 0 0 0';
    popWindowObj.style.backgroundColor = '#999';
    popWindowObj.style.borderWidth="1px";    
    isFinished = true;
}
//删除
function DeleteResourceState(lendLogId, resourceId)
{
    if(confirm("真的要删除选定记录吗？"))
    {
        globalLendLogId = lendLogId;
        globalResourceId = resourceId;
        EQD.SciencePark.Meeting.MeetingAjax.DelLendLog(lendLogId,DeleteResourceStateReturn);
    }
    ClosePopWindow();
}

//批准租借
function ApproveResourceState(lendLogId,standardForegift,StartDate,StartTime)
{
    globalLendLogId = lendLogId;
    parent.ShowTopDlg("RentRecordOperation.aspx?LendLogId="+lendLogId+"&Operation=1");
    
    ClosePopWindow();

}
//拒绝
function RefuseResourceState(lendLogId){
    globalLendLogId = lendLogId;    
    parent.ShowTopDlg("RentRecordOperation.aspx?LendLogId="+lendLogId+"&Operation=2");
    ClosePopWindow();

}
//付订金
function LendResourceState(lendLogId){

    globalLendLogId = lendLogId;
    parent.ShowTopDlg("RentRecordOperation.aspx?LendLogId="+lendLogId+"&Operation=3");
    ClosePopWindow();

}
//结算
function ReturnResourceState(lendLogId){

    globalLendLogId = lendLogId;
    parent.ShowTopDlg("RentRecordOperation.aspx?LendLogId="+lendLogId+"&Operation=4");
    ClosePopWindow();
}



//关闭 弹出窗口
function ClosePopWindow()
{
    try{
        var popWindowObj = document.getElementById('PopWindow');
        popWindowObj.innerHTML="";
        popWindowObj.style.display = 'none';
    }catch(e){}    
    ClearColor();
}




function AddResource()
{
    var type = beginTd.id.substring(0, 6);
    if(type!="BodyTd")return;
    
    var topRowColumn = beginTd.id.substring(6, beginTd.id.length).split("_");
    var topRow = parseInt(topRowColumn[0], 10);
    var topColumn = parseInt(topRowColumn[1], 10);
    
    var bottomRowColumn = endTd.id.substring(6, endTd.id.length).split("_");
    var bottomRow = parseInt(bottomRowColumn[0], 10);
    var bottomColumn = parseInt(bottomRowColumn[1],10);
    
    //alert(topRow+":"+topColumn+","+bottomRow+":"+bottomColumn);
    var offset = topColumn;
    if(days==1)
    {
        if(topRow%2==0)
        {
            offset = topColumn -1;
        }
    }
    else if(days>1)
    {
        if(topRow%3==0)
        {
            offset = topColumn -1;
        }
    }
    var resourceName = checkedResourceArray[offset].Name;
    var resourceId = checkedResourceArray[offset].Id;
    var user ="";
    
    
    var sYear;
    var sMonth;
    var sDay;
    var sHour;
    var sMinute;
    var sSecond;
    var eYear;
    var eMonth;
    var eDay;
    var eHour;
    var eMinute;
    var eSecond;
    
    var dateStr = startDate.date+"";
    
    if(days==1){
        sYear = dateStr.substring(0,4);
        sMonth = dateStr.substring(4,6);
        sDay = dateStr.substring(6,8);
        
        if(topRow<2){
            sHour ="00";
            sMinute ="00";
            sSecond ="00";
        }else if(topRow>25){
            sHour ="21";
            sMinute ="00";
            sSecond ="00";
        }else{
        
            sHour =PaddingLeft((8+Math.floor(topRow/2)), '0',2);
            sMinute =PaddingLeft(topRow%2*30, '0',2);
            sSecond ="00";        
        }
        eYear = dateStr.substring(0,4);
        eMonth = dateStr.substring(4,6);
        eDay = dateStr.substring(6,8);
        
        if(bottomRow<2){
            eHour ="09";
            eMinute ="00";
            eSecond ="00";
        }else if(bottomRow>26||topRow>25){
            eDay = PaddingLeft(parseInt(eDay, 10)+1,'0',2);
            eHour ="00";
            eMinute ="00";
            eSecond ="00";
        }else{
        
            eHour =PaddingLeft((8+Math.floor((bottomRow+1)/2)), '0',2);
            eMinute =PaddingLeft((bottomRow+1)%2*30, '0',2);
            eSecond ="00";
        }       
    }
    else if(days>1)
    {
        var calendarStartDate = IntToDate(dateStr);
        var sDate = AddDays(calendarStartDate, Math.floor(topRow/3));
        var eDate = AddDays(calendarStartDate, Math.floor(bottomRow/3));
        //sYear = sDate.getYear();
        sYear = sDate.getFullYear();
        sMonth = PaddingLeft(sDate.getMonth()+1, '0', 2);
        sDay = PaddingLeft(sDate.getDate(), '0', 2);
        //eYear = eDate.getYear();
        eYear = eDate.getFullYear();
        eMonth = PaddingLeft(eDate.getMonth()+1, '0', 2);
        eDay = PaddingLeft(eDate.getDate(), '0', 2);
    
        sHour ="00";
        sMinute ="00";
        sSecond ="00";
        sHour=(topRow%3)*5+8;
        eHour ="00";
        eMinute ="00";
        eSecond ="00";
        eHour=(bottomRow%3)*5+12;
        
    }
    
    
    var popWindowObj = document.getElementById('PopWindow');

    str = '<table style="width:100%;background-color:#FFFFFF;height:100px;" ><tr><td class="CommonText">';
    str +='<div style="float:right;display:inline;position:relative;top:1px;right:1px;cursor:pointer" onclick="ClosePopWindow();"><img src="images/close-small.gif"></div>';
    str +='</td></tr>';
    str +='<tr><td class="text_font text_title" align="center">'+resourceName+'会议室租赁申请</td></tr>';
    str +='<tr><td class="CommonText"><font color="red">*</font><strong>会议室名称：</strong>';
    str +=resourceName;
    str +='</td></tr>';
    str +='<tr><td class="CommonText"><font color="red">*</font><strong>会议议题：</strong><input type="text" id="ConferenceTitle" class="login" style="float:none;width:177px" >';
    str +='</td></tr>';
    
    str +='</td></tr>';
    str +='<tr><td class="CommonText"><font color="red">*</font><strong>申请人名：</strong><input type="text" id="rentorName"  class="login"  style="float:none;width:177px"/>';
    str +='</td></tr>';
    str +='<tr><td class="CommonText"><font color="red">*</font><strong>申请公司：</strong><input type="text" id="rentorCompany" class="login" style="float:none;width:177px"/>';
    str +='</td></tr>';
    str +='<tr><td class="CommonText"><font color="red">*</font><strong>联系电话：</strong><input type="text" id="rentorTel" class="login" style="float:none;width:177px"/>';
    str +='</td></tr>';
    str +='<tr><td class="CommonText">&nbsp;&nbsp;<strong>发票抬头：</strong><input type="text" id="rentorTex" class="login" style="float:none;width:177px"/>';
    str +='</td></tr>';
    
    str +='<tr><td class="CommonText">&nbsp;&nbsp;<strong>申请原因：</strong><input type="text" id="Reason" class="login" style="float:none;width:177px"/>';
    str +='</td></tr>';
//    var curDate  = new Date();
//    var date = curDate.getYear()+"-"+(curDate.getMonth()+1)+"-"+curDate.getDate();
//    str +='<tr><td class="CommonText">&nbsp;&nbsp;<strong>租赁起始时间：</strong><input type="text" id="tbRentLogStartDate" class="login" style="float:none;width:150px" value="'+date+'" /> ';
//    str +='</td></tr>';
    str +='<tr><td class="">&nbsp;&nbsp;<strong>出借时间：</strong>';
    str +='<input type="text" id="sYear" value="' +sYear+'" class="login" disabled style="float:none;width:50px">年';
    str +='<input type="text" id="sMonth" value="' +sMonth+'" class="login" disabled style="float:none;width:30px">月';
    str +='<input type="text" id="sDay" value="' +sDay+'" class="login" disabled style="float:none;width:30px">日';
    str +='<input type="text" id="sHour" value="' +sHour+'" class="login" disabled style="float:none;width:30px">时';
    if (days==1)
    {
        str +='<input type="text" id="sMinute" value="' +sMinute+'" disabled class="login" style="float:none;width:30px">分';       
    }
    else
    {
        str +='<input type="hidden" id="sMinute" style="visibility:hidden" value="' +sMinute+'">';       
    }
    str +='<input type="hidden" id="sSecond"  style="visibility:hidden" value="' +sSecond+'">';
    str +='</td></tr>';
    str +='<tr><td class="CommonText">&nbsp;&nbsp;<strong>归还时间：</strong>';
    str +='<input type="text" id="eYear" value="' +eYear+'" class="login" disabled style="float:none;width:50px">年';
    str +='<input type="text" id="eMonth" value="' +eMonth+'" class="login" disabled style="float:none;width:30px">月';
    str +='<input type="text" id="eDay" value="' +eDay+'" class="login" disabled style="float:none;width:30px">日';
    str +='<input type="text" id="eHour" value="' +eHour+'" class="login" disabled style="float:none;width:30px" >时';
    if (days==1)
    {
        str +='<input type="text" id="eMinute" value="' +eMinute+'" disabled class="login" style="float:none;width:30px">分';       
    }
    else
    {
        str +='<input type="hidden" id="eMinute" style="visibility:hidden" value="' +eMinute+'">';       
    }
    str +='<input type="hidden"id="eSecond"  style="visibility:hidden" value="' +eSecond+'">';
    str +='</td></tr>';
    str +='<tr><td>';
    str +='<tr><td align="center">';    
    str += '<input type="button" onclick="ApplyResource(\''+resourceId+'\')" value="申请" class="admin_btn1">';
    str += '<input type="button" onclick="FullApply(\''+resourceId+'\',\''+resourceName+'\')" value="申请详细" class="admin_btn1_1">';
    str +='</td></tr>';
    str +='</table>';
    
    popWindowObj.innerHTML = str;
    
    EQD.SciencePark.Meeting.MeetingAjax.GetUserInfo(GetUserInfoReturn);
    
    var x = event.clientX;
    var y = event.clientY;
    var width = 360;
    var height = 350;
    if(x+width > browserWidth){
        x = browserWidth - width;
    }
    
    if(y+height>browserHeight){
        y = browserHeight - height;
    }
    
    popWindowObj.style.left = x + "px";
    popWindowObj.style.top = y + "px";
    popWindowObj.style.display = 'block';
    popWindowObj.style.padding = '0 0 0 0';
    popWindowObj.style.backgroundColor = '#999';
    popWindowObj.style.borderWidth="1px";
    //alert("x:"+event.clientX+",y:"+event.clientY);
}
function $(id)
{
    return document.getElementById(id);
}
function FullApply(aId,aMeetingName)
{
    var i = 0;
    NewMeetingRentRecordInfo[i++] = encodeURI(aMeetingName);
    var meetingTitle = encodeURI($("ConferenceTitle").value);
    NewMeetingRentRecordInfo[i++]=meetingTitle;
    
    NewMeetingRentRecordInfo[i++]= encodeURI($("rentorName").value);
    NewMeetingRentRecordInfo[i++]= encodeURI($("rentorCompany").value);
    NewMeetingRentRecordInfo[i++]= encodeURI($("rentorTel").value);
    NewMeetingRentRecordInfo[i++]= encodeURI($("rentorTex").value);
    NewMeetingRentRecordInfo[i++]= encodeURI($("Reason").value);
    var sYear = $("sYear").value;
    var sMonth = $("sMonth").value;
    var sDay = $("sDay").value;
    var sHour = $("sHour").value;
    var sMinute = $("sMinute").value;
    var sSecond = $("sSecond").value;
    NewMeetingRentRecordInfo[i++]=sYear+"-"+sMonth+"-"+sDay+" "+sHour+":"+sMinute+":"+sSecond;
    var eYear = $("eYear").value;
    var eMonth = $("eMonth").value;
    var eDay = $("eDay").value;
    var eHour = $("eHour").value;
    var eMinute = $("eMinute").value;
    var eSecond = $("eSecond").value;
    NewMeetingRentRecordInfo[i++]= eYear +"-" +eMonth+"-"+eDay+" " +eHour+":"+eMinute+":"+eSecond;

    parent.ShowTopDlg("FullApply.aspx?meetingID="+aId);
    ClosePopWindow();
}
function FullApplyUpdate(aMeetingId, aId)
{
    parent.ShowTopDlg("FullApply.aspx?lendLogID="+ aId + "&meetingID=" + aMeetingId);
    ClosePopWindow();
}
function GetUserInfoReturn(result)
{
    if(result!=null && result.value!=null && result.value != "")
    {
        var rentorNameObj = document.getElementById('rentorName');
        var rentorCompanyObj = document.getElementById('rentorCompany');
        var rentorTelObj = document.getElementById('rentorTel');
        var rentorTexObj = document.getElementById('rentorTex');
        var userInfo = result.value.split("\x1d");
        if(userInfo[0]=="0")
        {
               rentorNameObj.value=userInfo[1];
               //rentorNameObj.disabled = true;
               
               rentorCompanyObj.value=userInfo[2];
               if(userInfo[2] != "")
               {
                   rentorCompanyObj.disabled = true;
               }
               rentorTelObj.value=userInfo[3];
               rentorTexObj.value=userInfo[4];
        }
        else
        {
               rentorNameObj.removeAttribute("readonly");
        }
    }
}
function ShowLendLogInfo(aMeeintID,aLendLogID)
{
    parent.ShowTopDlg("FullApply.aspx?lendLogID="+ aLendLogID + "&meetingID=" + aMeeintID+"&type=show");
    ClosePopWindow();
}

