﻿
//
function $(e){return document.getElementById(e);}
function F_$(f,e){return window.frames[f].document.getElementById(e);}
function CreateDivAndIframe(Unid, Tnid, Tid){
	if (GetCookieValue("User", "Uid") != null && GetCookieValue("User", "Uid") !="") {
		var divBigName = "div_" + Tid;
		if (!$(divBigName)) {
			var ey = 0, ex = 0, lx = 0, ly = 0, canDrg = false, thiso = null;
			var _x, _y, rw, rh;
			var ttop, tleft;
			var cDiv = top.document.createElement;
			var _$ = top.document.getElementById;
			ttop = Math.floor(Math.random() * 100 + 1) + 60;
			tleft = Math.floor(Math.random() * 100 + 1) + 10;
			var divT = cDiv("div");
			divT.id = "div_" + Tid;
			divT.style.position = "absolute";
			divT.style.left = 260 + tleft + "px";
			divT.style.top = ttop + "px";
			divT.style.width = "630px";
			divT.style.height = "463px";
			divT.onmousedown = function(){
				thiso = this;
				canDrg = true;
				if (!top.document.all) {
					lx = event.clientX;
					ly = event.clientY;
				}
				else {
					lx = event.x;
					ly = event.y;
				}
				if (top.document.all) 
					thiso.setCapture();
			}
			
			divT.onmousemove = function(){
				if (!top.document.all) {
					_x = e.clientX;
					_y = e.clientY;
				}
				else {
					_x = event.x;
					_y = event.y;
				}
				if (canDrg) {
					var ofsx = _x - lx;
					thiso.style.left = parseInt(thiso.style.left) + ofsx;
					lx = _x;
					var ofsy = _y - ly;
					thiso.style.top = parseInt(thiso.style.top) + ofsy;
					ly = _y;
				}
			}
			
			divT.onmouseup = function(){
				canDrg = false;//拖拽变量设为false
				if (top.document.all && thiso != null) { //ie下，将清捕获;
					thiso.releaseCapture();
					thiso = null;
				}
			}
			
			divT.onclick = function(){
				var nextDiv = null;
				var nextIndex = 9999;
				var selectdiv = _$("div_" + Tid);
				var fIndex = _$("div_" + Tid).style.zIndex;
				var Elements = top.document.getElementsByTagName("div");
				
				for (var i = 0; i < Elements.length; i++) {
					if (Elements[i].style.height == "463px") {
						var index = Elements[i].style.zIndex;
						if (index > fIndex && index < nextIndex) {
							nextDiv = Elements[i];
							nextIndex = index;
						}
						else {
							var _tt = Math.floor(Math.random() * 10 + 1);
							Elements[i].style.zIndex = _tt;
						}
					}
				}
				//交换zIndex 
				if (nextDiv) {
					selectdiv.style.zIndex = nextIndex;
					nextDiv.style.zIndex = fIndex;
				}
			}
			
			top.document.body.appendChild(divT);
			var divTT = cDiv("div");
			divTT.className = "l_top";
			divT.appendChild(divTT);
			
			var _h = cDiv("h1");
			_h.innerHTML = Unid + "与" + Tnid + "聊天中"
			_h.style.cursor = "move";
			divTT.appendChild(_h);
			
			var _u = cDiv("ul");
			divTT.appendChild(_u);
			
			var _l1 = cDiv("li");
			_u.appendChild(_l1);
			
			var _img1 = cDiv("img");
			_img1.src = "/images/l_top_btn1.gif";
			_l1.appendChild(_img1);
			
			var _l2 = cDiv("li");
			_u.appendChild(_l2);
			
			var _img2 = cDiv("img");
			_img2.src = "/images/l_top_btn2.gif";
			_img2.onclick = function(){
				var divTmp = _$("div_" + Tid);
				divTmp.parentNode.removeChild(divTmp);
			}
			_l2.appendChild(_img2);
			var _img3 = cDiv("img");
			_img3.src = "/images/l_bqimg.gif";
			_img3.style.position = "absolute";
			_img3.style.left = "20px";
			_img3.style.top = "314px";
			_img3.onclick = function(){
				//记录被调用iframeID号
				var divName = "divPicList_" + Tid;
				if (!$(divName)) {
					var _div0 = document.createElement("div");
					_div0.style.position = "absolute";
					_div0.style.left = "20px";
					_div0.style.top = "332px";
					_div0.style.zIndex = "10000";
					_div0.id = "divPicList_" + Tid;
					_l2.appendChild(_div0);
					var _table0 = document.createElement("table");
					_table0.style.width = "445px";
					_table0.setAttribute("border", "0");
					_table0.cellPadding = "0px";
					_table0.cellSpacing = "0px";
					_div0.appendChild(_table0);
					var _tbody0 = document.createElement("tbody");
					_table0.appendChild(_tbody0);
					//***头部分***
					var _tr0 = document.createElement("tr");
					_tbody0.appendChild(_tr0);
					var _td0 = document.createElement("td");
					_tr0.appendChild(_td0);
					var _div1 = document.createElement("div");
					_div1.style.position = "absolute";
					_div1.style.paddingLeft = "413px";
					_div1.style.paddingTop = "8px";
					_div1.style.cursor = "hand";
					_div1.innerHTML = "关闭";
					_div1.onclick = function(){
						var tmpName = "divPicList_" + Tid;
						$(tmpName).style.display = "none";
					}
					_td0.appendChild(_div1);
					var _img0 = document.createElement("img");
					_img0.src = "/images/l_qqh1.gif";
					_td0.appendChild(_img0);
					//***体部分***
					var _tr1 = document.createElement("tr");
					_tbody0.appendChild(_tr1);
					var _td1 = document.createElement("td");
					_td1.className = "l_qq";
					_tr1.appendChild(_td1);
					var _table1 = document.createElement("table");
					_table1.style.width = "433px";
					_table1.setAttribute("border", "0");
					_table1.cellPadding = "0px";
					_table1.cellSpacing = "1px";
					_table1.bgColor = "#eacde7";
					_table1.className = "tbPic";
					_td1.appendChild(_table1);
					//***创建隐藏值，保存被谁调用***
					var _hidfrm_Id = document.createElement("hidden");
					_hidfrm_Id.id = "hidfrm_Id";
					_hidfrm_Id.value = Tid;
					_td1.appendChild(_hidfrm_Id);
					for (var i = 0; i < 6; i++) {
						//添加行   
						var row = _table1.insertRow();
						//添加列 
						for (var j = 1; j <= 15; j++) {
							loadCells(row, i, j, Tid);
						}
					}
				}
				else {
					$(divName).style.display = "block";
				}
			}
			_l2.appendChild(_img3);
			
			var _l3 = cDiv("li");
			_u.appendChild(_l3);
			
			var frm = cDiv("iframe");
			frm.id = "frm_" + Tid;
			frm.setAttribute('frameborder', '0', 0);
			frm.style.width = "630px";
			frm.style.height = "406px";
			frm.src = "http://www.liehunwang.com/newChats/Chats.aspx?to_id=" + Tid;
			divTT.appendChild(frm);
			reloadfrm(Tid);
		}
	}
	else {
	ShowMask();
	CreatDiv3(Tid);
		//alert("您还不是猎婚会员,不能使用此功能！");
		return false;
	}
}
  //添加单元格    
  function loadCells(r, _c, _r, ttid){
  	var m;
  	m = 15 * _c + _r;
  	//限制数量
			if (m <= 76) {
				var cell = r.insertCell();
				cell.bgColor = "#ffffff";
				cell.align = "center";
				cell.innerHTML = "<a href='javascript:void(0)' onclick='sys_writePic(" + m + "," + ttid + ")'><img src='/Face/" + parseInt(m) + ".gif' width='24' height='24'/></a>";
			}
		}  
  
  //写入数据至文本框
  function sys_writePic(pid, tttid){
  	var picUrl = "<img src='/Face/" + pid + ".gif'/>";
  	var frmName = "frm_" + tttid;
  	F_$(frmName, "txtContent").value += formatO_N_Str(picUrl);
  	var divName = "divPicList_" + tttid;
  	$(divName).style.display = "none";
  } 
  
 function formatO_N_Str(str){
 	str = str.replace(new RegExp("<img src='/Face/", "gm"), "<em>");
 	str = str.replace(new RegExp(".gif'/>", "gm"), "</em>");
 	return str;
 } 
 
 //获取登录后Cookie名称
function GetCookie(name) 
 { 
 cookie_name = name + "="; 
 cookie_length = document.cookie.length; 
 cookie_begin = 0; 
 while (cookie_begin < cookie_length) 
  { 
   value_begin = cookie_begin + cookie_name.length; 
   if (document.cookie.substring(cookie_begin, value_begin) == cookie_name) 
    { 
     var value_end = document.cookie.indexOf ( ";", value_begin); 
     if (value_end == -1) 
        { 
         value_end = cookie_length; 
        } 
        return unescape(document.cookie.substring(value_begin, value_end)); 
     } 
   cookie_begin = document.cookie.indexOf ( " ", cookie_begin) + 1; 
   if (cookie_begin == 0) 
      { 
       break; 
      } 
   } 
   return null; 
 } 
 
 //获取登录后的Cookie的值
 function GetCookieValue(P_strName,strValueName){
  if(GetCookie(P_strName)!=null){
   if(GetCookie(P_strName).split('=')[0]==strValueName){
      return GetCookie(P_strName).split('=')[1]
     }
   }
 }
 
function reloadfrm(Tid){
 var strTmpName="frm_"+Tid;
 window.frames[strTmpName].location.reload();
} 