﻿// JScript 文件

function $(obj)
{
    return document.getElementById(obj);
}

if (window.addEventListener)
{
    window.addEventListener('load', function(event)
    {
        if (window.document.DocumentLoaded != null && typeof (window.document.DocumentLoaded) == 'function')
        {
            window.document.DocumentLoaded();
        }
    }, false);
}
else if (window.attachEvent)
{
    window.attachEvent('onload', function()
    {
        if (window.document.DocumentLoaded != null && typeof (window.document.DocumentLoaded) == 'function')
        {
            window.document.DocumentLoaded();
        }
    });
}
else
{

    window.onload = function()
    {
        if (window.document.DocumentLoaded != null && typeof (window.document.DocumentLoaded) == 'function')
        {
            window.document.DocumentLoaded();
        }
    }
}

//通过咨询单的ID取得对应咨询单处理的相关信息
function GetTable(guid)
{
    var list = Page.GetTreatmentRecordList(guid).value;

    if (list != null && list.length > 0)
    {
        for (var i = 0; i < list.length; i++)
        {

            var tr = TreatmentRecordTable.insertRow(-1);

            var td1 = tr.insertCell(-1);
            var td2 = tr.insertCell(-1);
            var td3 = tr.insertCell(-1);
            var td4 = tr.insertCell(-1);
            if (list[i].Dealinger != null)
            {
                td1.innerHTML = list[i].Dealinger.Name;
            }
            else
            {
                td1.innerHTML = "";
            }
            td2.innerHTML = list[i].CreateDate.format("yyyy-MM-dd hh :mm:ss");
            if (list[i].Type == 1)
            {
                td3.innerHTML = "首次咨询";
            }
            else if (list[i].Type == 2)
            {
                td3.innerHTML = "主叫回复";
            }
            else if (list[i].Type == 3)
            {
                td3.innerHTML = "被叫回复";
            }
            else
            {
                td3.innerHTML = "";
            }
            td4.style.textAlign = "left";
            if (list[i].Note != null && list[i].Note != "null")
            {
                td4.innerHTML = list[i].Note;
            }
        }
    }
}

//设置点击修改背景
function ShowData(index)
{
    var childNodesLength = $("ulList").childNodes.length;
    //数据初始化
    for (var i = 0; i < childNodesLength; i++)
    {
        $("ulList").childNodes[i].className = '';
    }
    $("ulList").childNodes[index].className = 'BgImg';

    //加载对应数据
    var where = null;
    where = GetWhereOql(); //window["SeachPageHelper"].WhereOql;
    if (where.length <= 0)
    {
        where = " 1=1";
    }
    if (index > 0)
    {
        where += " and AdvisorySingleDTO.State='" + index + "'";
    }

    ClearTable();

    window["SeachPageHelper"] = new SeachPageHelper_Class("CITSECOS.CITSECS.DTO.AdvisorySingleDTO", 10, where, loaded);

}

//加载默认条数 0,全部 1，等待处理 2，处理中  3，处理成功  4，放弃处理
function GetTotalCounts()
{
    var childNodesLength = $("ulList").childNodes.length;
    var returnValue = null;
    var where = null;
    window["SeachPageHelper"];
    for (var i = 0; i < childNodesLength; i++)
    {
        where = window["SeachPageHelper"].WhereOql;
        if (where.length <= 0)
        {
            where = " 1=1 ";
        }
        if (i > 0)
        {
            where += " and AdvisorySingleDTO.State=" + i;
        }

        returnValue = Page.GetTotal("CITSECOS.CITSECS.DTO.AdvisorySingleDTO", where).value;
        if (i == 0)
        {
            $("ulList").childNodes[i].childNodes[0].innerHTML = "全部";
        }
        else if (i == 1)
        {
            $("ulList").childNodes[i].childNodes[0].innerHTML = "等待处理";
        } else if (i == 2)
        {
            $("ulList").childNodes[i].childNodes[0].innerHTML = "处理中";
        }
        else if (i == 3)
        {
            $("ulList").childNodes[i].childNodes[0].innerHTML = "处理成功";
        }
        else if (i == 4)
        {
            $("ulList").childNodes[i].childNodes[0].innerHTML = "放弃处理";
        }
        if (returnValue != null)
        {
            $("ulList").childNodes[i].childNodes[0].innerHTML += "(" + returnValue + ")";
        }
        else
        {
            $("ulList").childNodes[i].childNodes[0].innerHTML += "(0)";
        }
    }
}

//取得右上方页面登录信息
function SetLoginInfo(value)
{
    if (value != null && value.error != null && value.error.Message == 'NoLogin')
    {
        alert('请先登录');
        window.location = Uri.RootRequest() + '/CallCenter/CallCenterLogin.html';
        return;
    }
    if (value.value == null)
    {
        alert('请先登录');
        window.location = Uri.RootRequest() + '/CallCenter/CallCenterLogin.html';
        return;
    }
    $("pLoginInfo").innerHTML = value.value.Name + ",您好";
    $("aHelper").href = "javascript:openW('http://chat7.looyu.com/chat/chat/p.do?g=28086&md=2&c=31203&v=e3369d4c36d242bda5510a2802ccdd84&u=791715b91c5a43048f8239d508240c3b&f=75012&site=0&ct=74&refer=&loc=CallCenter:" + encodeURI(encodeURI(value.value.Name)) + "(" + value.value.LoginName + ")')"
}

function openW(v)
{
    window.open(v, '', 'width=580,height=500,left=200,top=200,status=no,scrollbars=no,menubar=no,toolbar=no,resizable=no,location=no');
}

//系统退出
function LoginOut()
{
    Page.LoginOut(LoginOuted);
}

function LoginOuted(value)
{
    window.location = Uri.RootRequest() + '/CallCenter/CallCenterLogin.html';
}

//选中所有
function CheckCheckBox(obj)
{
    var checks = window.document.getElementsByName("CheckBox");
    var i = 1;
    while (checks.length >= i)
    {
        checks[i - 1].checked = obj.checked;
        i++;
    }
}

function DeleteCheckBox()
{
    var checks = window.document.getElementsByName("CheckBox");
    var ids = "";
    if (checks.length <= 0)
    {
        alert("请选择要删除的项");
        return;
    }

    for (var i = 0; i < checks.length; i++)
    {
        if (checks[i].checked)
        {
            ids += checks[i].getAttribute("id") + ",";
        }
    }
    if (ids.length <= 0)
    {
        alert("请选择要删除的项");
        return;
    }

    var returnValue = Page.DeleteCheckBox(ids).value;
    //var returnValue = null;
    if (returnValue == "OK")
    {
        alert("删除成功");

        ClearTable();
        GetTotalCounts();
        window["SeachPageHelper"] = new SeachPageHelper_Class("CITSECOS.CITSECS.DTO.AdvisorySingleDTO", 10, window["SeachPageHelper"].WhereOql, loaded);
    }
    else
    {
        alert(returnValue);
    }
}

//共享OnChange(),1.当共享是个人的时候，才显示所属人
function ShareChanged(obj)
{
    if (obj.value == "1")
    {
        $("OwenDiv").style.display = "";
    } else
    {
        $("OwenDiv").style.display = "none";
    }
}

function SetReadonly(objID)
{
    if (objID != null)
    {
        var returnValue = Page.CheckIsOwner(objID).value;
        if (!returnValue)
        {
            var inputEle = document.getElementsByTagName("input");
            for (var i = 0; i < inputEle.length; i++)
            {
                //        inputEle[i].setAttribute("readonly", "true", 0);
                //        inputEle[i].onclick = function setClickFalse() { return false; }
                //        inputEle[i].onfocus = function setFocusFalse() { return false; }
                //        inputEle[i].onblur = function setBlurFalse() { return false; }
                if (inputEle[i].type != "button")
                {
                    inputEle[i].setAttribute("disabled", "disabled");
                }
            }
            // select readonly   
            var selectEle = document.getElementsByTagName("select");
            for (var i = 0; i < selectEle.length; i++)
            {
                selectEle[i].setAttribute("disabled", "disabled");
            }

            // textarea readonly   
            var textareaEle = document.getElementsByTagName("textarea");
            for (var i = 0; i < textareaEle.length; i++)
            {
                if (textareaEle[i].id != "TreatmentRecords")
                {
                    textareaEle[i].setAttribute("disabled", "disabled");
                }
            }
        }
    }
}

//select readonly   
function setSelectReadOnly(obj)
{
    obj.onmouseover = function()
    {
        obj.setCapture();
    }
    obj.onmouseout = function()
    {
        obj.releaseCapture();
    }
    obj.onfocus = function()
    {
        obj.blur();
    }
    
    obj.onbeforeactivate = function()
    {
        return false;
    }
    obj.onclick = function()
    {
        return false;
    }
} 