var tongHua_yn=0;
function AddInfo(sInf)
{
var box=gid("TestInfo");
if(box.value.length>9999)
{
box.value='';
}
box.value += sInf+"\r";
}
function check_oxc()
{
var ip=gid("txtHost").value;
try{
myOCX.EC_Connect(ip);
}
catch(e)
{
alert('没有正确安装控件')
return false;
}
var but=gid("btnDisConnect");
if(but.disabled==true)
{
alert('连接已经断开')
return false;
}
return true;
}
function ec_Connect(tiXin_yn)
{
var ip=gid("txtHost").value;
if (ip.length<1)
{
if(gid("not_link"))
{
not_link.innerHTML="没有设置呼叫中心服务器，如果你是管理员请点<a href=javascript:open_dialog('set.htm',888,555,0) target=_self>这里</a>设置";
not_link.style.display='';
div_statu.style.display='none';
}
return;
}
try{
myOCX.EC_Connect(ip);
}
catch(e)
{
if(tiXin_yn!='no'){	alert('没有安装控件')}
if(gid("not_link"))
{
not_link.innerHTML="你还没有安控件，<a href='../../plug/tel_ocx.rar'>安装</a>后就可以使用呼叫中心及来电<a href=javascript:fPopUpCallCstDlg(801,'13812345678');>弹屏</a>功能了。";
not_link.style.display='';
div_statu.style.display='none';
}
}
}
function ec_DisConnect()
{
myOCX.EC_DisConnect();
}
function ec_DownLoadFile()
{
myOCX.EC_DownLoadFile(document.getElementById("txtPlay").value, "C:\\mytest.wav");
AddInfo("下载后的文件是：C:\\mytest.wav");
}
function ec_PlayFile()
{
myOCX.EC_PlayFile(document.getElementById("txtPlay").value);
}
function ec_StartMonitor()
{
myOCX.EC_StartMonitor(document.getElementById("lbxMonitorCh").value);
}
function ec_StopMonitor()
{
myOCX.EC_StopMonitor();
}
function ec_SoftDialOut(toTel)
{
if(!check_oxc())return;
if(!toTel)toTel=gid('txtRemote').value;
if(toTel.length<1)
{
alert("拔出的电话号码不正确");
return;
}
var myTel=document.getElementById("local_tel").value;
if(myTel.length<1)
{
alert("没有为自己指定分机号");
return;
}
myOCX.EC_SoftDialOut(myTel,toTel);
}
function ec_StopSoftDialOut()
{
if(!check_oxc())return;
myOCX.EC_StopSoftDialOut(document.getElementById("local_tel").value);
}
function ec_TalkInvite()
{
myOCX.EC_3WayTalkInvite(document.getElementById("local_tel").value,document.getElementById("txtRemote").value,1);
}
function ec_TalkStart()
{
myOCX.EC_3WayTalkStart(document.getElementById("local_tel").value,2);
}
function ec_SetLoginInfo()
{
myOCX.EC_SetLoginInfo(document.getElementById("txtUser").value, document.getElementById("txtPassWord").value);
}
function ec_SetLimitedTel()
{
myOCX.EC_SetLimitedTel(document.getElementById("txtLimitedUser").value, document.getElementById("txtLimitedNum").value);
}
function ec_CCSetUserBusy()
{
if(!check_oxc())return;
var myNum=check_myNum();
if(!myNum)return;
myOCX.EC_CCSetUserBusy(myNum);
gid("but_busy").disabled=true;
gid("but_free").disabled=false;
}
function ec_CCSetUserFree()
{
if(!check_oxc())return;
var myNum=check_myNum();
if(!myNum)return;
var iCH=myOCX.EC_CCSetUserBusy(myNum);
myOCX.EC_CCSetUserFree(iCH,myNum);
gid("but_busy").disabled=false;
gid("but_free").disabled=true;
}
function check_myNum()
{
var myNum=gid("local_tel").value;
if(myNum.length<1)
{
alert("你没有设置分机号");
return false;
}
return myNum;
}
function OnConnect(sHost)
{
AddInfo("连接成功："+sHost);
gid("btnDisConnect").disabled=false;
gid("btnConnect").disabled=true;
if(gid("div_statu_td1"))
{
div_statu_td1.innerHTML="连接成功" ;
div_statu_td2.innerHTML="点<a href=javascript:fPopUpCallCstDlg(801,'13812345678');>这里</a>进行弹窗测试！" 
}
}
function OnDisConnect(sHost)
{
AddInfo("Warning!连接断开："+sHost);
gid("btnDisConnect").disabled=true;
gid("btnConnect").disabled=false;
if(gid("div_statu_td1"))
{
div_statu_td1.innerHTML="连接断开！" ;
div_statu_td2.innerHTML="" 
}
}
function OnCallIn(s1,s2)
{
if(gid("not_link"))
{
not_link.style.display='none';
div_statu.style.display='';
div_statu_td1.innerHTML="来电："+s2;
div_statu_td2.innerHTML="计时：<span id=span_tong_ount>00:00:00</span>";
}
AddInfo(s1+" 来电："+s2);
fPopUpCallCstDlg(s1,s2);
} 
function OnCallOut(s1,s2)
{
if(gid("not_link"))
{
not_link.style.display='none';
div_statu.style.display='';
div_statu_td1.innerHTML="去电："+s2;
div_statu_td2.innerHTML="计时：<span id=span_tong_ount>00:00:00</span>";
}
AddInfo(s1+" 拨出号码："+s2);
}
function OnRecFile(s1,s2,sDT,iIO,iLen,obj_num,who_stop)
{
AddInfo(s1+" 形成录音文件："+sDT);
var f=gid('txtPlay');
if(f)f.value = s2;
var url="../"+asp_php+"/tel."+asp_php;
url+="?exe=tel_save_record&local_num="+s1+"&filePath="+s2+"&sDT="+sDT+"&iIO="+iIO+"&iLen="+iLen+"&obj_num="+obj_num+"&who_stop="+who_stop;
gid('frame_blank').src=url;
}
function OnNoAnswer(s1,s2)
{
AddInfo(s1+" 未接来电："+s2);
}
function OnLeaveMessage(s1,s2,sDT,iLen)
{
AddInfo(s1+" 留言文件："+s2+","+sDT+","+iLen);
document.getElementById("txtPlay").value = s2
}
function OnHookOff(s1,s2)
{
tongHua_yn=1;
AddInfo(s1+" 摘机："+s2);
}
function OnHookOn(s1,s2)
{
AddInfo(s1+" 挂机："+s2);
tongHua_yn=0;
try
{
call_over();
gid('but_star').disabled=false;
gid('but_star').value='拔号';
}
catch(e){};
}
function OnRing(s1,s2)
{
AddInfo(s1+" 振铃："+s2);
}
function OnTransOut(s1,s2,s3)
{
AddInfo(s1+" 转其他电话：From:"+s2+"->"+s3);
}
function fPopUpCallCstDlg(myNum,inNum)
{
gid('frame_blank').src=asp_php_url+"?exe=tel_tan&myNum="+myNum+"&inNum="+inNum;
}
function tel_tan(fileName_ids,myNum,inNum)
{
var winName="win_"+inNum.replace(/[^0-9]/g,'');
window.open("../main/tel_tan.htm?fileName_ids="+fileName_ids+"&myNum="+myNum+"&inNum="+inNum,winName,"toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=800,height=600");
}
function jiShi()
{
if(tongHua_yn!=1)return;
if(!gid('span_tong_ount'))return;
var s=span_tong_ount.innerText;
if(s.length<1)return;
if(s.indexOf(":")<0)return;
var arr=s.split(":");
var hh=arr[0]-0;
var nn=arr[1]-0;
var ss=arr[2]-0;
ss++;
if(ss>59)
{
ss=0;
nn++;
}
if(nn>59)
{
nn=0;
hh++;
}
hh=right("00"+hh,2);
nn=right("00"+nn,2);
ss=right("00"+ss,2);
var s=hh+":"+nn+":"+ss;
span_tong_ount.innerHTML=s;
}
myOCX.attachEvent("OnConnect",OnConnect); 
myOCX.attachEvent("OnDisConnect",OnDisConnect); 
myOCX.attachEvent("OnCallOut",OnCallOut); 
myOCX.attachEvent("OnRecFile",OnRecFile); 
myOCX.attachEvent("OnNoAnswer",OnNoAnswer); 
myOCX.attachEvent("OnLeaveMessage",OnLeaveMessage); 
myOCX.attachEvent("OnHookOff",OnHookOff); 
myOCX.attachEvent("OnHookOn",OnHookOn); 
myOCX.attachEvent("OnRing",OnRing); 
myOCX.attachEvent("OnFlashTransOut",OnTransOut); 