﻿// JScript 文件
var vUrl="./";
//document.domain = "127.0.0.1";

//=============================================================发送小纸条==========================================================
function SentMessage(SendType,VoteName)
{
   var HtmlUrl=document.getElementById("hidUrl").value;
   //var Url=document.getElementById("Url").value;
   var UserName=document.getElementById("hidUser").value;
   var FUserId=document.getElementById("FUserId").value;
   var TUserId=document.getElementById("TUserId").value;
	ScreenConvert();
	
	if (FUserId=="")
	{
	var AJAX_LoginBody="<div id=\"layer_box\"><div id=\"layer_title\"><div id=\"layer_left\">请您登陆后发送小纸条<\/div><div id=\"close\"><a href=\"#\"><img onmouseover=this.style.cursor=\'pointer\'; src=\"images\/close.gif\" onclick=\"return DialogHide();\"  border=0\/><\/a><\/div><\/div><div id=\"layer_input\">友情提示：如果您还没注册,请通过快速注册<\/div><div id=\"layer_but\"><button id=\"AjaxMainLogin\" onclick=\"window.location=\'login.aspx?ReturnUrl="+HtmlUrl+"';\">立即登录<\/button>&nbsp;&nbsp;&nbsp;&nbsp;<button id=\"AjaxMainReg\" onclick=\"window.location=\'CreateUser.aspx?ReturnUrl="+HtmlUrl+"';\">快速注册<\/button><\/div><\/div>";
	}
	else{
	var AJAX_LoginBody="<div id=\"layer_box1\" onmousedown=\"divBlock_event_mousedown(arguments[0]);\"><div id=\"layer_title\"><div id=\"layer_left\">发送小纸条<\/div><div id=\"close\"><img src=\"images\/close.gif\" onmouseover=\"this.style.cursor=\'pointer\';\" onclick=\"return DialogHide();\" \/><\/div><\/div><div id=\"title\"><div id=\"title_left\">小纸条发送给:<span id=\"username\"> "+UserName+"<\/span><\/div><div id=\"itlte_right\">可输入140<\/div><\/div><div id=\"layer_input\"><ul><li style=\"padding-left:5px;\"><textarea name=\"txtMemo\" cols=\"50\" rows=\"4\" id=\"txtMemo\" style=\"text\" maxlength=\"140\" onkeyup=\"return ismaxlength(this)\" onbeforepaste=\"return ismaxlength(this)\" onpaste=\"return ismaxlength(this)\"><\/textarea><\/li><\/ul><\/div><div id=\"layer_but\"><input type=\"submit\" onclick=\"return CRecomment();\" value=\"发送小纸条\" \/><input type=\"hidden\" ID=\"url\" value=\""
	    + HtmlUrl +"\"/><input type=\"hidden\" ID=\"txtFUserID\" value=\""+FUserId +"\" \/><input type=\"hidden\" ID=\"txtTUserID\" value=\""+TUserId+ "\" \/><input type=\"hidden\" ID=\"txtUserName\" value=\""+UserName+ "\" \/><\/div><\/div>";
	}
	DialogShow(AJAX_LoginBody,400,120,280,100);
}

function SentMessageP(SendType,VoteName,fuserid,tuserid,username)
{
   var HtmlUrl=document.getElementById("hidUrl").value;
   //var Url=document.getElementById("Url").value;
   var UserName=username;
   var FUserId=fuserid;
   var TUserId=tuserid;
	ScreenConvert();
	
	if (FUserId=="")
	{
	var AJAX_LoginBody="<div id=\"layer_box\"><div id=\"layer_title\"><div id=\"layer_left\">请您登陆后发送小纸条<\/div><div id=\"close\"><a href=\"#\"><img onmouseover=this.style.cursor=\'pointer\'; src=\"images\/close.gif\" onclick=\"return DialogHide();\"  border=0\/><\/a><\/div><\/div><div id=\"layer_input\">友情提示：如果您还没注册,请通过快速注册<\/div><div id=\"layer_but\"><button id=\"AjaxMainLogin\" onclick=\"window.location=\'login.aspx?ReturnUrl="+HtmlUrl+"';\">立即登录<\/button>&nbsp;&nbsp;&nbsp;&nbsp;<button id=\"AjaxMainReg\" onclick=\"window.location=\'CreateUser.aspx?ReturnUrl="+HtmlUrl+"';\">快速注册<\/button><\/div><\/div>";
	}
	else{
	var AJAX_LoginBody="<div id=\"layer_box1\" onmousedown=\"divBlock_event_mousedown(arguments[0]);\"><div id=\"layer_title\"><div id=\"layer_left\">发送小纸条<\/div><div id=\"close\"><img src=\"images\/close.gif\" onmouseover=\"this.style.cursor=\'pointer\';\" onclick=\"return DialogHide();\" \/><\/div><\/div><div id=\"title\"><div id=\"title_left\">小纸条发送给:<span id=\"username\"> "+UserName+"<\/span><\/div><div id=\"itlte_right\">可输入140<\/div><\/div><div id=\"layer_input\"><ul><li style=\"padding-left:5px;\"><textarea name=\"txtMemo\" cols=\"50\" rows=\"4\" id=\"txtMemo\" style=\"text\" maxlength=\"140\" onkeyup=\"return ismaxlength(this)\" onbeforepaste=\"return ismaxlength(this)\" onpaste=\"return ismaxlength(this)\"><\/textarea><\/li><\/ul><\/div><div id=\"layer_but\"><input type=\"submit\" onclick=\"return CRecomment();\" value=\"发送小纸条\" \/><input type=\"hidden\" ID=\"url\" value=\""
	    + HtmlUrl +"\"/><input type=\"hidden\" ID=\"txtFUserID\" value=\""+FUserId +"\" \/><input type=\"hidden\" ID=\"txtTUserID\" value=\""+TUserId+ "\" \/><input type=\"hidden\" ID=\"txtUserName\" value=\""+UserName+ "\" \/><\/div><\/div>";
	}
	DialogShow(AJAX_LoginBody,400,120,280,100);
}

//未登陆对话框
function login(retUrl)
{
	var HtmlUrl=retUrl;
	var strJs;	
    strJs = "ScreenConvert();"
    strJs += "var AJAX_LoginBody=\"<div id=\'layer_box\'><div id=\'layer_title\'><div id=\'layer_left\'>请您登陆后发送小纸条<\/div><div id=\'close\'><a href=\'#\'><img border=\'0\' onclick=\'return DialogHide();\' src=\'images\/close.gif\' onmouseover=\'this.style.cursor=\'pointer\';\'\/><\/a><\/div><\/div><div id=\'layer_input\'>友情提示：如果您还没注册,请通过快速注册<\/div><div id=\'layer_but\'><button onclick=\'window.location=\'login.aspx?ReturnUrl="+HtmlUrl+"\';\' id=\'AjaxMainLogin\'>立即登录<\/button>    <button onclick=\'window.location=\'CreateUser.aspx?ReturnUrl="+HtmlUrl+"\';\' id=\'AjaxMainReg\'>快速注册<\/button><\/div><\/div>\";"
    strJs += "DialogShow(AJAX_LoginBody,400,250,280,100);";
    window.document.getElementById("ret").value=strJs;
	interval=window.setInterval(GetRet,100);	
}

//显示提示信息
function AlertMessage(title,content)
{
	var strJs;	
    strJs = "ScreenConvert();"
    strJs += "var AJAX_LoginBody=\"<div id=\'layer_box\'><div id=\'layer_title\'><div id=\'layer_left\'>\"+title+\"<\/div><div id=\'close\'><img src=\'images\/close.gif\' onclick=\'return DialogHide();\' \/><\/div><\/div><div id=\'layer_input\'><ul><li style=\'text-align: center;\'>\"+content+\"<\/li><li>&nbsp;<\/li><li><input type=\'button\' onclick=\'return DialogHide();\' value=\'关 闭\' \/><\/li><li><\/li><\/ul><\/div><\/div>\";";
    strJs += "DialogShow(AJAX_LoginBody,400,250,280,100);";
    window.document.getElementById("ret").value=strJs;
	interval=window.setInterval(GetRet,100);
	
}

function CRecomment()
{

   //var HtmlUrl=document.getElementById("hidUrl").value;
   //var Url=document.getElementById("Url").value;
   var UserName=document.getElementById("txtUserName").value;
   var FUserId=document.getElementById("txtFUserID").value;
   var TUserId=document.getElementById("txtTUserID").value;
   var vLink=vUrl+"ajax.aspx?fuserid="+escape(document.getElementById ("txtFUserID").value)+"&tuserid="+document.getElementById ("txtTUserID").value+"&txtMemo="+escape(document.getElementById ("txtMemo").value)+"&k=msg&URL="+document.getElementById ("url").value;
    PostFrame(vLink);
	DialogHide();
}


//================================================================处理============================================================
var interval;
function PostOpen(posturl)
{
	popup = window.open(posturl,"TripodPopup",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=0,height=0,left=500,top=350');
	popup.blur();
	interval=window.setInterval(GetRet,10);
}
function PostFrame(posturl)
{
	document.getElementById ("ret").value="1";
	var oblog_bIsIE5=document.all;
	if (oblog_bIsIE5){
	window.document.frames("iframehide").location.href=posturl;
	}
	else
	{
	window.document.getElementById("iframehide").contentWindow.location.href=posturl;
	}
	interval=window.setInterval(GetRet,100);
}

function GetRet()
{
	if(document.getElementById ("ret").value!="1")
	{
		eval(document.getElementById ("ret").value);
		document.getElementById ("ret").value="1";
		GetStop();
	}
}

function GetStop()
{
	document.getElementById ("ret").value="1";
	clearInterval(interval);
}
//================================================================公用============================================================
function ScreenConvert(){var browser = new Browser();var objScreen = gid("ScreenOver");if(!objScreen) var objScreen = document.createElement("div");var oS = objScreen.style;objScreen.id = "ScreenOver";oS.display = "block";oS.top = oS.left = oS.margin = oS.padding = "0px";if (document.body.clientHeight)	{var wh = document.body.clientHeight + "px";}else if (window.innerHeight){var wh = window.innerHeight + "px";}else{var wh = "100%";}oS.width = "100%";oS.height = wh;oS.position = "absolute";oS.zIndex = "3";if ((!browser.isSF) && (!browser.isOP)){oS.background = "#181818";}else{oS.background = "#F0F0F0";}oS.filter = "alpha(opacity=40)";oS.opacity = 40/100;oS.MozOpacity = 40/100;document.body.appendChild(objScreen);var allselect = gname("select");for (var i=0; i<allselect.length; i++) allselect[i].style.visibility = "hidden";}


function gid(id){return window.document.getElementById?window.document.getElementById(id):null;}

function gname(name){return window.document.getElementsByTagName?window.document.getElementsByTagName(name):new Array()}

function DialogLoc(){var dde = window.document.documentElement;if (window.innerWidth){var ww = window.window.innerWidth;var wh = window.window.innerHeight;var bgX = window.pageXOffset;var bgY = window.pageYOffset;}else{var ww = dde.offsetWidth;var wh = dde.offsetHeight;var bgX = dde.scrollLeft;var bgY = dde.scrollTop;}t_DiglogX = (bgX + ((ww - t_DiglogW)/2));t_DiglogY = (bgY + ((wh - t_DiglogH)/2));}

function Browser(){var ua, s, i;this.isIE = false;this.isNS = false;this.isOP = false;this.isSF = false;ua = navigator.userAgent.toLowerCase();s = "opera";if ((i = ua.indexOf(s)) >= 0){this.isOP = true;return;}s = "msie";if ((i = ua.indexOf(s)) >= 0) {this.isIE = true;return;}s = "netscape6/";if ((i = ua.indexOf(s)) >= 0) {this.isNS = true;return;}s = "gecko";if ((i = ua.indexOf(s)) >= 0) {this.isNS = true;return;}s = "safari";if ((i = ua.indexOf(s)) >= 0) {this.isSF = true;return;}}

function DialogHide(){ScreenClean();var objDialog = document.getElementById("DialogMove");if (objDialog) objDialog.style.display = "none";}
function DialogHide2(){ScreenClean();var objDialog = document.getElementById("DialogMove");if (objDialog) objDialog.style.display = "none";window.frames[0].location.reload();}

function ScreenClean(){var objScreen = document.getElementById("ScreenOver");if (objScreen) objScreen.style.display = "none";var allselect = gname("select");for (var i=0; i<allselect.length; i++) allselect[i].style.visibility = "visible";}

function DialogShow(showdata,ow,oh,w,h){var objDialog = document.getElementById("DialogMove");if (!objDialog) objDialog = document.createElement("div");t_DiglogW = ow;t_DiglogH = oh;DialogLoc();objDialog.id = "DialogMove";var oS = objDialog.style;oS.display = "block";oS.top = t_DiglogY + "px";oS.left = t_DiglogX + "px";oS.margin = "0px";oS.padding = "0px";oS.width = w + "px";oS.height = h + "px";oS.position = "absolute";oS.zIndex = "5";oS.background = "#FFF";objDialog.innerHTML = showdata;document.body.appendChild(objDialog);}
function WishListAction(ActionType, ReferID, WishType, update,SendType,ID)
{
	ScreenConvert();
	DialogShow("<div id=\"DialogLoading\">正在读取,请稍候...</div>",110,24,124,24);
	if (update == null)
	{
		update = true;
	}
	update = (update)?1:0;
	if (ActionType != null && ReferID != null && WishType != null)
	{
		var PostData = "do=" + ((ActionType == 0)?"delmsgwishlist":"addwishlist") + "&referid=" + ReferID + "&wishtype=" + WishType + "&update=" + update;
		PostRequest(vUrl+"ajax_recomment2.aspx?k="+SendType+"&ID="+ID, PostData);
	}
}
function InitRequest(){var C_req = null;try{C_req = new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{C_req = new ActiveXObject("Microsoft.XMLHTTP");}catch(oc){C_req = null;}}if (!C_req && typeof XMLHttpRequest != "undefined"){try{C_req = new XMLHttpRequest();}catch(fa){alert("对不起!您的浏览器不支持该功能,请使用Internet Explorer 6.0或FireFox浏览器!");C_req = null;}}return C_req;}

function PostRequest(url){var AjaxRequestObj = InitRequest();if (AjaxRequestObj != null){AjaxRequestObj.onreadystatechange = function (){if (AjaxRequestObj.readyState == 4 && AjaxRequestObj.responseText){ProcessAjaxData(AjaxRequestObj.responseText);}};AjaxRequestObj.open("get", url, true);AjaxRequestObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");AjaxRequestObj.send(null);}}

function ProcessAjaxData(data){
	//alert(data);
	eval(data);
}

//--------把中文字符转换成Utf8编码------------------------//
function EncodeUtf8(s1)
  {
      var s = escape(s1);
      var sa = s.split("%");
      var retV ="";
      if(sa[0] != "")
      {
         retV = sa[0];
      }
      for(var i = 1; i < sa.length; i ++)
      {
           if(sa[i].substring(0,1) == "u")
           {
               retV += Hex2Utf8(Str2Hex(sa[i].substring(1,5)));
               
           }
           else retV += "%" + sa[i];
      }
      
      return retV;
  }
  function Str2Hex(s)
  {
      var c = "";
      var n;
      var ss = "0123456789ABCDEF";
      var digS = "";
      for(var i = 0; i < s.length; i ++)
      {
         c = s.charAt(i);
         n = ss.indexOf(c);
         digS += Dec2Dig(eval(n));
           
      }
      //return value;
      return digS;
  }
  function Dec2Dig(n1)
  {
      var s = "";
      var n2 = 0;
      for(var i = 0; i < 4; i++)
      {
         n2 = Math.pow(2,3 - i);
         if(n1 >= n2)
         {
            s += '1';
            n1 = n1 - n2;
          }
         else
          s += '0';
          
      }
      return s;
      
  }
  function Dig2Dec(s)
  {
      var retV = 0;
      if(s.length == 4)
      {
          for(var i = 0; i < 4; i ++)
          {
              retV += eval(s.charAt(i)) * Math.pow(2, 3 - i);
          }
          return retV;
      }
      return -1;
  } 
  function Hex2Utf8(s)
  {
     var retS = "";
     var tempS = "";
     var ss = "";
     if(s.length == 16)
     {
         tempS = "1110" + s.substring(0, 4);
         tempS += "10" +  s.substring(4, 10); 
         tempS += "10" + s.substring(10,16); 
         var sss = "0123456789ABCDEF";
         for(var i = 0; i < 3; i ++)
         {
            retS += "%";
            ss = tempS.substring(i * 8, (eval(i)+1)*8);
            
            
            
            retS += sss.charAt(Dig2Dec(ss.substring(0,4)));
            retS += sss.charAt(Dig2Dec(ss.substring(4,8)));
         }
         return retS;
     }
     return "";
  }
  
  function ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}
//加入弹出窗口拖动
function divBlock_event_mousedown(e){
	var e, obj, temp;
  obj=document.getElementById("DialogMove");
  e=window.event?window.event:e;
  obj.startX=e.clientX-obj.offsetLeft;
  obj.startY=e.clientY-obj.offsetTop;
  
  document.onmousemove=document_event_mousemove;
  temp=document.attachEvent?document.attachEvent("onmouseup",document_event_mouseup):document.addEventListener("mouseup",document_event_mouseup,"");
}
function document_event_mousemove(e){
  var e, obj;
  obj=document.getElementById("DialogMove");
  e=window.event?window.event:e;
  
  with(obj.style){
  	position="absolute";
  	left=e.clientX-obj.startX+"px";
  	top=e.clientY-obj.startY+"px";
  }
}
function document_event_mouseup(e){
	var temp;
	document.onmousemove="";
	temp=document.detachEvent?document.detachEvent("onmouseup",document_event_mouseup):document.removeEventListener("mouseup",document_event_mouseup,"");
}
