kefu.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. //QQ客服弹出对话框
  2. var online= new Array();
  3. var urlroot = "http://gdp.istudy.com.cn/";
  4. var tOut = -1;
  5. var drag = false;
  6. var g_safeNode = null;
  7. lastScrollY = 0;
  8. var kfguin;
  9. var ws;
  10. var companyname;
  11. var welcomeword;
  12. var type;
  13. var wpadomain;
  14. var eid;
  15. var Browser = {
  16. ie:/msie/.test(window.navigator.userAgent.toLowerCase()),
  17. moz:/gecko/.test(window.navigator.userAgent.toLowerCase()),
  18. opera:/opera/.test(window.navigator.userAgent.toLowerCase()),
  19. safari:/safari/.test(window.navigator.userAgent.toLowerCase())
  20. };
  21. if(kfguin)
  22. {
  23. //_Ten_rightDivHtml = '<div id="_Ten_rightDiv" style="position:absolute; top:160px; right:1px; display:none;">';
  24. //_Ten_rightDivHtml += kf_getPopup_Ten_rightDivHtml(kfguin,ws,wpadomain);
  25. //_Ten_rightDivHtml += '</div>';
  26. //document.write(_Ten_rightDivHtml);
  27. if(type==1 && kf_getCookie('hasshown')==0)
  28. {
  29. companyname = companyname.substr(0,15);
  30. welcomeword = kf_processWelcomeword(welcomeword);
  31. kfguin = kf_getSafeHTML(kfguin);
  32. companyname = kf_getSafeHTML(companyname);
  33. welcomeword = welcomeword.replace(/<br>/g,'\r\n');
  34. welcomeword = kf_getSafeHTML(welcomeword);
  35. welcomeword = welcomeword.replace(/\r/g, "").replace(/\n/g, "<BR>");
  36. window.setTimeout("kf_sleepShow()",200);
  37. }
  38. window.setTimeout("kf_moveWithScroll()",1);
  39. }
  40. function kf_getSafeHTML(s)
  41. {
  42. var html = "";
  43. var safeNode = g_safeNode;
  44. if(!safeNode){
  45. safeNode = document.createElement("TEXTAREA");
  46. }
  47. if(safeNode){
  48. if(Browser.moz){
  49. safeNode.textContent = s;
  50. }
  51. else{
  52. safeNode.innerText = s;
  53. }
  54. html = safeNode.innerHTML;
  55. if(Browser.moz){
  56. safeNode.textContent = "";
  57. }
  58. else{
  59. safeNode.innerText = "";
  60. }
  61. g_safeNode = safeNode;
  62. }
  63. return html;
  64. }
  65. function kf_moveWithScroll()
  66. {
  67. if(typeof window.pageYOffset != 'undefined') {
  68. nowY = window.pageYOffset;
  69. }
  70. else if(typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
  71. nowY = document.documentElement.scrollTop;
  72. }
  73. else if(typeof document.body != 'undefined') {
  74. nowY = document.body.scrollTop;
  75. }
  76. percent = .1*(nowY - lastScrollY);
  77. if(percent > 0)
  78. {
  79. percent=Math.ceil(percent);
  80. }
  81. else
  82. {
  83. percent=Math.floor(percent);
  84. }
  85. //document.getElementById("_Ten_rightDiv").style.top = parseInt(document.getElementById("_Ten_rightDiv").style.top) + percent+"px";
  86. if(document.getElementById("kfpopupDiv"))
  87. {
  88. document.getElementById("kfpopupDiv").style.top = parseInt(document.getElementById("kfpopupDiv").style.top) + percent+"px";
  89. }
  90. lastScrollY = lastScrollY + percent;
  91. tOut = window.setTimeout("kf_moveWithScroll()",1);
  92. }
  93. function kf_hide()
  94. {
  95. if(tOut!=-1)
  96. {
  97. clearTimeout(tOut);
  98. tOut=-1;
  99. }
  100. //document.getElementById("_Ten_rightDiv").style.visibility = "hidden";
  101. //document.getElementById("_Ten_rightDiv").style.display = "none";
  102. kf_setCookie('hasshown', 1, '', '/', wpadomain);
  103. }
  104. function kf_hidekfpopup()
  105. {
  106. if(tOut!=-1)
  107. {
  108. clearTimeout(tOut);
  109. tOut=-1;
  110. }
  111. document.getElementById("kfpopupDiv").style.visibility = "hidden";
  112. document.getElementById("kfpopupDiv").style.display = "none";
  113. tOut=window.setTimeout("kf_moveWithScroll()",1);
  114. kf_setCookie('hasshown', 1, '', '/', wpadomain);
  115. }
  116. function kf_getPopupDivHtml(kfguin,reference,companyname,welcomeword, wpadomain)
  117. {
  118. var temp = '';
  119. temp += '<span class="zixun0704_x"><a href="javascript:void(0);" onclick="kf_hidekfpopup();return false;"><!--关闭--></a></span>';
  120. temp += '<img src="'+urlroot+'web/pic_zixun0704_nv.jpg" class="zixun0704_img" />';
  121. temp += '<p class="zixun0704_font">'+welcomeword+'</p>';
  122. temp += '<div class="zixun0704_button"><a href="javascript:void(0);" onclick="kf_openChatWindow(1,\'b\',\''+kfguin+'\')"><img src="'+urlroot+'web/pic_zixun0704QQ.jpg" /></a>&nbsp;<a href="javascript:void(0);" onclick="kf_hidekfpopup();return false;"><img src="'+urlroot+'web/pic_zixun0704_later.jpg" /></a></div>';
  123. return temp;
  124. }
  125. //function kf_getPopup_Ten_rightDivHtml(kfguin,reference, wpadomain)
  126. //{
  127. // var temp = "";
  128. //
  129. // temp += '<div style="width:90px; height:150px;">';
  130. // temp += '<div style="width:8px; height:150px; float:left; background:url('+urlroot+'bg_1.gif);"></div>';
  131. // temp += '<div style="float:left; width:74px; height:150px; background:url('+urlroot+'middle.jpg); background-position: center;">';
  132. // temp += '<div ><h1 style="line-height:17px; font-size:14px; color:#FFFFFF; margin:0px; padding:10px 0 13px 8px; display:block; background:none; border:none; float:none; position:static;">&nbsp;</h1></div>';
  133. // temp += '<div style="height:83px; padding:0 0 0 2px; clear:both;"><div style="width:70px; height:70px; float:left; background:url('+urlroot+'face.jpg);"></div></div>';
  134. // temp += '<div style="clear:both;"><a href="#" onclick="kf_openChatWindow(0,\''+wpadomain+'\',\''+kfguin+'\')" style="width:69px; height:21px; background:url('+urlroot+'btn_2.gif); margin:0 0 0 2px; display:block;"></a></div></div>';
  135. // temp += '<div style="width:8px; height:150px; float:left; background:url('+urlroot+'bg_1.gif) right;"></div></div>';
  136. //
  137. // return temp;
  138. //}
  139. //added by simon 2008-11-04
  140. function kf_openChatWindow(flag, wpadomain, kfguin)
  141. {
  142. window.open('http://b.qq.com/webc.htm?new=0&sid='+kfguin+'&eid='+eid+'&o=&q=7', '_blank', 'height=544, width=644,toolbar=no,scrollbars=no,menubar=no,status=no');
  143. if(flag==1)
  144. {
  145. kf_hidekfpopup();
  146. }
  147. return false;
  148. }
  149. //added by simon 2008-11-04 end
  150. function kf_validateWelcomeword(word)
  151. {
  152. var count = 0;
  153. for(var i=0;i<word.length;i++)
  154. {
  155. if(word.charAt(i)=='\n')
  156. {
  157. count++;
  158. }
  159. if(count>2)
  160. {
  161. return 2;
  162. }
  163. }
  164. if(word.length > 57+2*count)
  165. {
  166. return 1;
  167. }
  168. count = 0;
  169. var temp = word.indexOf('\n');
  170. while(temp!=-1)
  171. {
  172. word = word.substr(temp+1);
  173. if(temp-1<=19)
  174. {
  175. count += 19;
  176. }
  177. else if(temp-1<=38)
  178. {
  179. count += 38;
  180. }
  181. else if(temp-1<=57)
  182. {
  183. count += 57;
  184. }
  185. temp = word.indexOf('\n');
  186. }
  187. count+=word.length;
  188. if(count>57)
  189. {
  190. return 3;
  191. }
  192. return 0;
  193. }
  194. function kf_processWelcomeword(word)
  195. {
  196. word = word.substr(0,57+10);
  197. var result = '';
  198. var count = 0;
  199. var temp = word.indexOf('<br>');
  200. while(count<57 && temp!=-1)
  201. {
  202. if(temp<=19)
  203. {
  204. count += 19;
  205. if(count<=57)
  206. {
  207. result += word.substr(0,temp+5);
  208. }
  209. else
  210. {
  211. result += word.substr(0,57-count>word.length?word.length:57-count);
  212. }
  213. }
  214. else if(temp<=38)
  215. {
  216. count += 38;
  217. if(count<=57)
  218. {
  219. result += word.substr(0,temp+5);
  220. }
  221. else
  222. {
  223. result += word.substr(0,57-count>word.length?word.length:57-count);
  224. }
  225. }
  226. else if(temp<=57)
  227. {
  228. count += 57;
  229. if(count<=57)
  230. {
  231. result += word.substr(0,temp+5);
  232. }
  233. else
  234. {
  235. result += word.substr(0,57-count>word.length?word.length:57-count);
  236. }
  237. }
  238. word = word.substr(temp+5);
  239. temp = word.indexOf('<br>');
  240. }
  241. if(count<57)
  242. {
  243. result += word.substr(0,57-count>word.length?word.length:57-count);
  244. }
  245. return result;
  246. }
  247. function kf_setCookie(name, value, exp, path, domain)
  248. {
  249. var nv = name + "=" + escape(value) + ";";
  250. var d = null;
  251. if(typeof(exp) == "object")
  252. {
  253. d = exp;
  254. }
  255. else if(typeof(exp) == "number")
  256. {
  257. d = new Date();
  258. d = new Date(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes() + exp, d.getSeconds(), d.getMilliseconds());
  259. }
  260. if(d)
  261. {
  262. nv += "expires=" + d.toGMTString() + ";";
  263. }
  264. if(!path)
  265. {
  266. nv += "path=/;";
  267. }
  268. else if(typeof(path) == "string" && path != "")
  269. {
  270. nv += "path=" + path + ";";
  271. }
  272. if(!domain && typeof(VS_COOKIEDM) != "undefined")
  273. {
  274. domain = VS_COOKIEDM;
  275. }
  276. if(typeof(domain) == "string" && domain != "")
  277. {
  278. nv += "domain=" + domain + ";";
  279. }
  280. document.cookie = nv;
  281. }
  282. function kf_getCookie(name)
  283. {
  284. var value = "";
  285. var cookies = document.cookie.split("; ");
  286. var nv;
  287. var i;
  288. for(i = 0; i < cookies.length; i++)
  289. {
  290. nv = cookies[i].split("=");
  291. if(nv && nv.length >= 2 && name == kf_rTrim(kf_lTrim(nv[0])))
  292. {
  293. value = unescape(nv[1]);
  294. }
  295. }
  296. return value;
  297. }
  298. function kf_sleepShow()
  299. {
  300. kf_setCookie('hasshown', 0, '', '/', wpadomain);
  301. var position_1 = (document.documentElement.clientWidth-381)/2+document.body.scrollLeft;
  302. var position_2 = (document.documentElement.clientHeight-159)/2+document.body.scrollTop;
  303. popupDivHtml = '<div class="zixun0704" id="kfpopupDiv" onmousedown="MyMove.Move(\'kfpopupDiv\',event,1);" style="z-index:10000; position: absolute; top: '+position_2+'px; left: '+position_1+'px;color:#000;font-size: 12px;cursor:move;height: 159px;width: 381px;">';
  304. popupDivHtml += kf_getPopupDivHtml(kfguin,ws,companyname,welcomeword, wpadomain);
  305. popupDivHtml += '</div>';
  306. if(document.body.insertAdjacentHTML)
  307. {
  308. document.body.insertAdjacentHTML("beforeEnd",popupDivHtml);
  309. }
  310. else
  311. {
  312. $("#footer").before(popupDivHtml);
  313. // sWhere="beforeEnd";
  314. // sHTML=popupDivHtml;
  315. // alert(HTMLElement.prototype.insertAdjacentHTML);
  316. // HTMLElement.prototype.insertAdjacentHTML = function(sWhere, sHTML){
  317. // var df = null,r = this.ownerDocument.createRange();
  318. // switch (String(sWhere).toLowerCase()) {
  319. // case "beforebegin":
  320. // r.setStartBefore(this);
  321. // df = r.createContextualFragment(sHTML);
  322. // this.parentNode.insertBefore(df, this);
  323. // break;
  324. // case "afterbegin":
  325. // r.selectNodeContents(this);
  326. // r.collapse(true);
  327. // df = r.createContextualFragment(sHTML);
  328. // this.insertBefore(df, this.firstChild);
  329. // break;
  330. // case "beforeend":
  331. // r.selectNodeContents(this);
  332. // r.collapse(false);
  333. // df = r.createContextualFragment(sHTML);
  334. // this.appendChild(df);
  335. // break;
  336. // case "afterend":
  337. // r.setStartAfter(this);
  338. // df = r.createContextualFragment(sHTML);
  339. // this.parentNode.insertBefore(df, this.nextSibling);
  340. // break;
  341. // }
  342. // };
  343. }
  344. }
  345. function kf_dealErrors()
  346. {
  347. kf_hide();
  348. return true;
  349. }
  350. function kf_lTrim(str)
  351. {
  352. while (str.charAt(0) == " ")
  353. {
  354. str = str.slice(1);
  355. }
  356. return str;
  357. }
  358. function kf_rTrim(str)
  359. {
  360. var iLength = str.length;
  361. while (str.charAt(iLength - 1) == " ")
  362. {
  363. str = str.slice(0, iLength - 1);
  364. iLength--;
  365. }
  366. return str;
  367. }
  368. window.onerror = kf_dealErrors;
  369. var MyMove = new Tong_MoveDiv();
  370. function Tong_MoveDiv()
  371. {
  372. this.Move=function(Id,Evt,T)
  373. {
  374. if(Id == "")
  375. {
  376. return;
  377. }
  378. var o = document.getElementById(Id);
  379. if(!o)
  380. {
  381. return;
  382. }
  383. evt = Evt ? Evt : window.event;
  384. o.style.position = "absolute";
  385. o.style.zIndex = 9999;
  386. var obj = evt.srcElement ? evt.srcElement : evt.target;
  387. var w = o.offsetWidth;
  388. var h = o.offsetHeight;
  389. var l = o.offsetLeft;
  390. var t = o.offsetTop;
  391. var div = document.createElement("DIV");
  392. document.body.appendChild(div);
  393. div.style.cssText = "filter:alpha(Opacity=10,style=0);opacity:0.2;width:"+w+"px;height:"+h+"px;top:"+t+"px;left:"+l+"px;position:absolute;background:#000";
  394. div.setAttribute("id", Id +"temp");
  395. this.Move_OnlyMove(Id,evt,T);
  396. }
  397. this.Move_OnlyMove = function(Id,Evt,T)
  398. {
  399. var o = document.getElementById(Id+"temp");
  400. if(!o)
  401. {
  402. return;
  403. }
  404. evt = Evt?Evt:window.event;
  405. var relLeft = evt.clientX - o.offsetLeft;
  406. var relTop = evt.clientY - o.offsetTop;
  407. if(!window.captureEvents)
  408. {
  409. o.setCapture();
  410. }
  411. else
  412. {
  413. window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
  414. }
  415. document.onmousemove = function(e)
  416. {
  417. if(!o)
  418. {
  419. return;
  420. }
  421. e = e ? e : window.event;
  422. var bh = Math.max(document.body.scrollHeight,document.body.clientHeight,document.body.offsetHeight,
  423. document.documentElement.scrollHeight,document.documentElement.clientHeight,document.documentElement.offsetHeight);
  424. var bw = Math.max(document.body.scrollWidth,document.body.clientWidth,document.body.offsetWidth,
  425. document.documentElement.scrollWidth,document.documentElement.clientWidth,document.documentElement.offsetWidth);
  426. var sbw = 0;
  427. if(document.body.scrollWidth < bw)
  428. sbw = document.body.scrollWidth;
  429. if(document.body.clientWidth < bw && sbw < document.body.clientWidth)
  430. sbw = document.body.clientWidth;
  431. if(document.body.offsetWidth < bw && sbw < document.body.offsetWidth)
  432. sbw = document.body.offsetWidth;
  433. if(document.documentElement.scrollWidth < bw && sbw < document.documentElement.scrollWidth)
  434. sbw = document.documentElement.scrollWidth;
  435. if(document.documentElement.clientWidth < bw && sbw < document.documentElement.clientWidth)
  436. sbw = document.documentElement.clientWidth;
  437. if(document.documentElement.offsetWidth < bw && sbw < document.documentElement.offsetWidth)
  438. sbw = document.documentElement.offsetWidth;
  439. if(e.clientX - relLeft <= 0)
  440. {
  441. o.style.left = 0 +"px";
  442. }
  443. else if(e.clientX - relLeft >= bw - o.offsetWidth - 2)
  444. {
  445. o.style.left = (sbw - o.offsetWidth - 2) +"px";
  446. }
  447. else
  448. {
  449. o.style.left = e.clientX - relLeft +"px";
  450. }
  451. if(e.clientY - relTop <= 1)
  452. {
  453. o.style.top = 1 +"px";
  454. }
  455. else if(e.clientY - relTop >= bh - o.offsetHeight - 30)
  456. {
  457. o.style.top = (bh - o.offsetHeight) +"px";
  458. }
  459. else
  460. {
  461. o.style.top = e.clientY - relTop +"px";
  462. }
  463. }
  464. document.onmouseup = function()
  465. {
  466. if(!o) return;
  467. if(!window.captureEvents)
  468. {
  469. o.releaseCapture();
  470. }
  471. else
  472. {
  473. window.releaseEvents(Event.MOUSEMOVE|Event.MOUSEUP);
  474. }
  475. var o1 = document.getElementById(Id);
  476. if(!o1)
  477. {
  478. return;
  479. }
  480. var l0 = o.offsetLeft;
  481. var t0 = o.offsetTop;
  482. var l = o1.offsetLeft;
  483. var t = o1.offsetTop;
  484. //alert(l0 + " " + t0 +" "+ l +" "+t);
  485. MyMove.Move_e(Id, l0 , t0, l, t,T);
  486. document.body.removeChild(o);
  487. o = null;
  488. }
  489. }
  490. this.Move_e = function(Id, l0 , t0, l, t,T)
  491. {
  492. if(typeof(window["ct"+ Id]) != "undefined")
  493. {
  494. clearTimeout(window["ct"+ Id]);
  495. }
  496. var o = document.getElementById(Id);
  497. if(!o) return;
  498. var sl = st = 8;
  499. var s_l = Math.abs(l0 - l);
  500. var s_t = Math.abs(t0 - t);
  501. if(s_l - s_t > 0)
  502. {
  503. if(s_t)
  504. {
  505. sl = Math.round(s_l / s_t) > 8 ? 8 : Math.round(s_l / s_t) * 6;
  506. }
  507. else
  508. {
  509. sl = 0;
  510. }
  511. }
  512. else
  513. {
  514. if(s_l)
  515. {
  516. st = Math.round(s_t / s_l) > 8 ? 8 : Math.round(s_t / s_l) * 6;
  517. }
  518. else
  519. {
  520. st = 0;
  521. }
  522. }
  523. if(l0 - l < 0)
  524. {
  525. sl *= -1;
  526. }
  527. if(t0 - t < 0)
  528. {
  529. st *= -1;
  530. }
  531. if(Math.abs(l + sl - l0) < 52 && sl)
  532. {
  533. sl = sl > 0 ? 2 : -2;
  534. }
  535. if(Math.abs(t + st - t0) < 52 && st)
  536. {
  537. st = st > 0 ? 2 : -2;
  538. }
  539. if(Math.abs(l + sl - l0) < 16 && sl)
  540. {
  541. sl = sl > 0 ? 1 : -1;
  542. }
  543. if(Math.abs(t + st - t0) < 16 && st)
  544. {
  545. st = st > 0 ? 1 : -1;
  546. }
  547. if(s_l == 0 && s_t == 0)
  548. {
  549. return;
  550. }
  551. if(T)
  552. {
  553. o.style.left = l0 +"px";
  554. o.style.top = t0 +"px";
  555. return;
  556. }
  557. else
  558. {
  559. if(Math.abs(l + sl - l0) < 2)
  560. {
  561. o.style.left = l0 +"px";
  562. }
  563. else
  564. {
  565. o.style.left = l + sl +"px";
  566. }
  567. if(Math.abs(t + st - t0) < 2)
  568. {
  569. o.style.top = t0 +"px";
  570. }
  571. else
  572. {
  573. o.style.top = t + st +"px";
  574. }
  575. window["ct"+ Id] = window.setTimeout("MyMove.Move_e('"+ Id +"', "+ l0 +" , "+ t0 +", "+ (l + sl) +", "+ (t + st) +","+T+")", 1);
  576. }
  577. }
  578. }
  579. function wpa_count()
  580. {
  581. var body = document.getElementsByTagName('body').item(0);
  582. var img = document.createElement('img');
  583. var now = new Date();
  584. img.src = "http://"+wpadomain+".qq.com/cgi/wpac?kfguin=" + kfguin + "&ext=0" + "&time=" + now.getTime() + "ip=172.23.30.15&";
  585. img.style.display = "none";
  586. body.appendChild(img);
  587. }