kefu.js 14 KB

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