﻿function StrCode(str)
{
	if(encodeURIComponent)
		return encodeURIComponent(str);
	if(escape)
		return escape(str);
}
function UnStrCode(str)
{
	if(decodeURIComponent )
		return decodeURIComponent (str);
	if(unescape)
		return unescape(str);
}
function Trim(s)
{
	var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);return (m == null)?"":m[1];
}
function HtmlEncode(text)
{
	var re = {'<':'&lt;','>':'&gt;','&':'&amp;','"':'&quot;'};
	for (i in re) text = text.replace(new RegExp(i,'g'), re[i]);
	return text;
}
function HtmlDecode(text)
{
	var re = {'&lt;':'<','&gt;':'>','&amp;':'&','&quot;':'"'};
	for (i in re) text = text.replace(new RegExp(i,'g'), re[i]);
	return text;
}
function gid(id)
{
	return document.getElementById?document.getElementById(id):null;
}
function gname(name)
{
	return document.getElementsByTagName?document.getElementsByTagName(name):new Array()
}
var get_e_src = function(e){if(e) return e.target;if(window.event) return window.event.srcElement;return null;};
function addEvent(obj,evType,fn,useCapture )
{
	if (obj.addEventListener){obj.addEventListener( evType, fn, useCapture );return true;}
	if (obj.attachEvent) return obj.attachEvent( "on" + evType, fn );
	alert( "Unable to add event listener for " + evType + " to " + obj.tagName );
}
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 ClickButton(event, buttonid)
{
	var btnObj = gid(buttonid);
	if (btnObj)
	{
		var e = (event||window.event);
		if (e.keyCode == 13){btnObj.click();return false;}
	}
	return true;
}
function WarpClass(eObj, fID)
{
	var fObj = document.getElementById(fID);
	if (eObj.className == "mktitleleft2")
	{
		if (fObj) fObj.style.display = "block";
		eObj.className = "mktitleleft";
	}
	else
	{
		if (fObj) fObj.style.display = "none";
		eObj.className = "mktitleleft2";
	}
}
function mcl(show, div, btn, over, padd)
{
	var objdiv = gid(div);
	var objbtn = gid(btn);
	if (objdiv && objbtn)
	{
		var browser = new Browser();
		if (show)
		{
			objdiv.style.display = "block";
			if (browser.isIE && over)
			{
				var allselect = gname("select");
				for (var i=0; i<allselect.length; i++)
				{
					allselect[i].style.visibility = "hidden";
				}
			}
			objdiv.style.top = (objbtn.offsetTop + objbtn.offsetHeight - 2) + "px";
			objdiv.style.left = (objbtn.offsetLeft - (padd?0:50)) + "px";
		}
		else
		{
			objdiv.style.display = "none";
			if (browser.isIE && over)
			{
				var allselect = gname("select");
				for (var i=0; i<allselect.length; i++)
				{
					allselect[i].style.visibility = "visible";
				}
			}
		}
	}
}
function CopyURL()
{
	if (window.clipboardData)
	{
		var copy = window.location.href;
		var ok = window.clipboardData.setData("Text", copy);
		if (ok){alert("已经把当前网址复制到剪贴板，\n\n"+"您可以使用(Ctrl+V或鼠标右键)粘贴功能，\n\n"+"发送到MSN、QQ、Blog或者论坛。\n");
		}
	}
}
function SelectTagGet(tid, svalue, ktid)
{
	var TObj = gid(tid);
	if (TObj && svalue)
	{
		var PostData = "do=selecttagget&target=" + StrCode(tid) + "&svalue=" + StrCode(svalue) + "&kt=" + StrCode(ktid);
		PostRequest(window.location.protocol + "//" + window.location.host + "/AJAX_Comm.aspx", PostData);
	}
}
function SelectTagInit(tid, sbody)
{
	var TObj = gid(tid);
	if (TObj && sbody)
	{
		TObj.length = 0;
		for (var i=0;i<sbody.length;i++)
		{
			TObj.options[TObj.length] = new Option(HtmlDecode(sbody[i][0]), HtmlDecode(sbody[i][1]));
		}
	}
}
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, data)
{
	var AjaxRequestObj = InitRequest();
	if (AjaxRequestObj != null)
	{
		AjaxRequestObj.onreadystatechange = function ()
		{
			if (AjaxRequestObj.readyState == 4 && AjaxRequestObj.responseText)
			{
				//alert(AjaxRequestObj.responseText);
				ProcessAjaxData(AjaxRequestObj.responseText);
			}
		};
		AjaxRequestObj.open("POST", url, true);
		AjaxRequestObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		AjaxRequestObj.send(data);
	}
}
function ProcessAjaxData(data)
{
	eval(data);
}

function DoRssRequest(url, modid, num)
{
	var AjaxRequestObj = InitRequest();
	if (AjaxRequestObj != null)
	{
		AjaxRequestObj.onreadystatechange = function ()
		{
			if (AjaxRequestObj.readyState == 4 && AjaxRequestObj.responseXML)
			{
				RendRssFeed(AjaxRequestObj.responseXML, modid, num);
			}
		};
		AjaxRequestObj.open("GET", "/TScript/CHome/xmlProxy.asp?url="+url, true);
		AjaxRequestObj.send(null);
	}
}

function RendRssFeed(results, modid, num)
{
    var title = null;
    var item = null;
	var link = null;
	var itemCount = num;

	var ulObj = document.createElement("ul");

    var items = results.getElementsByTagName("item");
	if(itemCount > items.length) itemCount = items.length;
    for(var i = 0; i < itemCount; i++)
	{
        item = items[i];
        title = item.getElementsByTagName("title")[0].firstChild.nodeValue;
		link =  item.getElementsByTagName("link")[0].firstChild.nodeValue;

		var rowObj = document.createElement("li");

		var textNode = document.createTextNode("·");

		var titleLinkObj = document.createElement("a");
		titleLinkObj.innerHTML = title;
		titleLinkObj.href = link;
		titleLinkObj.target = "_blank";

		rowObj.appendChild(textNode);
		rowObj.appendChild(titleLinkObj);
		ulObj.appendChild(rowObj); 
    }

	var modObj = gid("RssConT_" + modid);
	if (modObj)
	{
		 while(modObj.childNodes.length > 0)
		{
			modObj.removeChild(modObj.childNodes[0]);
		 }
		 if(ulObj.childNodes.length > 0)
		{
			modObj.appendChild(ulObj);
		 }
		 else
		{
			modObj.innerHTML = "读取失败，请修改Rss地址";
		}		
	}
}

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 = "#FFF";
	}
	else
	{
		oS.background = "#FFF";
	}
	oS.filter = "alpha(opacity=1)";
	oS.opacity = 1/100;
	oS.MozOpacity = 1/100;
	document.body.appendChild(objScreen);
	var allselect = gname("select");
	for (var i=0; i<allselect.length; i++) 
		allselect[i].style.visibility = "hidden";
}
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";
}
var t_DiglogX,t_DiglogY,t_DiglogW,t_DiglogH;
function DialogLoc()
{
	var dde = document.documentElement;
	if (window.innerWidth)
	{
		var ww = window.innerWidth;
		var wh = 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 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";
	objDialog.className = "toolpopup";
	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.background = "#F5F5F5";
	oS.zIndex = "5";
	objDialog.innerHTML = showdata;
	document.body.appendChild(objDialog);
}
function DialogHide()
{
	ScreenClean();
	var objDialog = document.getElementById("DialogMove");
	if (objDialog) objDialog.style.display = "none";
}

function MM_openBrWindow(theURL)
{
  window.open(theURL,"","width=400,height=306");
}

function PlayZMusic()
{
	var obj = document.getElementsByName("chkMusicBox");
	var objLen= obj.length;
	var objYN = "";
	var i;
	for (i = 0;i< objLen;i++)
	{
		if (obj [i].checked==true)
		{
			objYN += obj [i].value + ",";
		}
	}
	if(objYN.length == 0)
	{
		alert("请选中至少一首");
	}
	else
	{
		var vdObj = gid("ZMusicPlayer");
		vdObj.URL = "/Hompy/MusicList.aspx?UID=0&MID=" +objYN;
		vdObj.controls.Play();
	}
}

function PlayZMusicAll(uid)
{
	var vdObj = gid("ZMusicPlayer");
	vdObj.URL = "/Hompy/MusicList.aspx?V=1&UID=" +uid;
	vdObj.controls.Play();
}

function PlayZMusicSingle(mid)
{
	var vdObj = gid("ZMusicPlayer");
	vdObj.URL = "/Hompy/MusicList.aspx?V=1&MID=" +mid;
	vdObj.controls.Play();
}

function PlayZVideo(url)
{
	var vdObj = gid("ZMoviePlayer");
	vdObj.movie = "/Hompy/flvplayer.swf?FVN=" + url;
}

function ReloadZonePage()
{
	var retUrl = location.href.replace("#", "");
	location.href = retUrl;
}

function LoadCustomConent(modid, body)
{
	var obj = gid(modid);
	if (obj)
	{
		if (body) obj.innerHTML = HtmlDecode(body);
	}
}


function DoLogout()
{
	ScreenConvert();
	var PostData = "do=logout";		
	DialogShow("<div class=\"loading\">正在退出,请稍候...</div>",150,25,150,25);
	PostRequest(window.location.protocol + "//" + window.location.host + "/Hompy/AjaxPage/CommPage.aspx", PostData);
}

function GetLoginForm()
{
	ScreenConvert();
	var PostData = "do=login";		
	DialogShow("<div class=\"loading\">正在加载,请稍候...</div>",150,25,150,25);
	PostRequest(window.location.protocol + "//" + window.location.host + "/Hompy/AjaxPage/CommPage.aspx", PostData);
}

function DoLoginOk()
{
	var objDoor = gid("ddlDoor");
	var objName = gid("txtUNickName");
	var objPwd = gid("txtUPWD");
	
	if(objName && objPwd)
	{
		var door =  objDoor.value;
		if (Trim(objName.value).length < 1 ){if(door==1){alert("昵称不能为空！");}else{alert("邮箱不能为空！");}objName.focus();return false;}
		if (Trim(objPwd.value).length < 1 ){alert("密码不能为空！");objPwd.focus();return false;}
		var PostData = "do=dologin&intDoor="+ door +"&txtUNickName=" + StrCode(objName.value) +"&txtUPWD=" + StrCode(objPwd.value);		
		DialogShow("<div class=\"loading\">正在发送,请稍候...</div>",150,25,150,25);
		PostRequest(window.location.protocol + "//" + window.location.host + "/Hompy/AjaxPage/CommPage.aspx", PostData);
	}
	else{DialogShow("<div class=\"loading\">读取失败,请<a href=\"javascript:DialogHide();\">稍候再试</a>...</div>",180,10,180,25);return false;}
}

function doPageTitleEvent(myweb) {
	var div = gid("pageTitle");
	div.firstChild.onmouseover = function() {
		this.style.backgroundColor = "#eee";
		//this.style.border = "1px solid #ccc";
	}
	div.firstChild.onmouseout = function() {
		this.style.backgroundColor = "transparent";
		this.style.border = "none";
	}
	div.firstChild.onclick = function() {
		this.onclick = null;
		this.onmouseout();
		this.onmouseover = null;
		var titleValue = this.firstChild.nodeValue;
		var titleWidth = this.offsetWidth;
		this.innerHTML = '<input type="text" maxlength="50" value="'+titleValue+'" style="width:'+titleWidth+'px"/>';
		var inputElm = this.firstChild;
		inputElm.focus();
		inputElm.select();		
		inputElm.onkeyup = function() {
			this.style.width = (this.value.length*18)+18 + "px";
		}
		inputElm.onblur = function() {		
			var value = (this.value=='') ? myweb : HtmlEncode(this.value);				
			this.parentNode.innerHTML = value;
			if (this.value != titleValue) {
				document.title = value;
				ScreenConvert();
				var PostData = "do=pagetitle"+"&txtPageTitle=" + StrCode(value);		
				DialogShow("<div class=\"loading\">正在保存我的空间名称,请稍候...</div>",250,25,250,25);
				PostRequest(window.location.protocol + "//" + window.location.host + "/Hompy/AjaxPage/CommPage.aspx", PostData);
			}
			doPageTitleEvent();
		}
	}
}

function doPageTitleEventTwo(myweb) {
	var div = gid("pageTitleTwo");
	div.firstChild.onmouseover = function() {
		this.style.backgroundColor = "#eee";
		//this.style.border = "1px solid #ccc";
	}
	div.firstChild.onmouseout = function() {
		this.style.backgroundColor = "transparent";
		this.style.border = "none";
	}
	div.firstChild.onclick = function() {
		this.onclick = null;
		this.onmouseout();
		this.onmouseover = null;
		var titleValue = this.firstChild.nodeValue;
		var titleWidth = this.offsetWidth;
		this.innerHTML = '<input type="text" maxlength="50" value="'+titleValue+'" style="width:'+titleWidth+'px"/>';
		var inputElm = this.firstChild;
		inputElm.focus();
		inputElm.select();		
		inputElm.onkeyup = function() {
			this.style.width = (this.value.length*18)+18 + "px";
		}
		inputElm.onblur = function() {		
			var value = (this.value=='') ? '' : HtmlEncode(this.value);				
			this.parentNode.innerHTML = value;
			if (this.value != titleValue) {
				ScreenConvert();
				var PostData = "do=pagetitletwo"+"&txtPageTitleTwo=" + StrCode(value);		
				DialogShow("<div class=\"loading\">正在保存我的空间名称,请稍候...</div>",250,25,250,25);
				PostRequest(window.location.protocol + "//" + window.location.host + "/Hompy/AjaxPage/CommPage.aspx", PostData);
			}
			doPageTitleEventTwo();
		}
	}
}

function changeMyCss(attr, value, iIndex)
{
	var browser = new Browser();
	var st = null;
	if (browser.isIE)
	{
		st = document.styleSheets["Hompy_MyStyle"].rules;
	}
	else
	{
		st = document.getElementById('Hompy_MyStyle').sheet.cssRules;
	}	
	switch(attr)
	{
		case "color":
			st[iIndex].style.color = value;
			break;
		case "backgroundColor":
			st[iIndex].style.backgroundColor = value;
			break;
		case "backgroundPosition":
			st[iIndex].style.backgroundPosition = value;
			break;
		case "backgroundAttachment":
			st[iIndex].style.backgroundAttachment = value;
			break;
		case "backgroundRepeat":
			st[iIndex].style.backgroundRepeat = value;
			break;
		case "backgroundImageClient":
			st[iIndex].style.backgroundImage = "url(" + value + ")";
			break;
		case "backgroundImageWeb":
			st[iIndex].style.backgroundImage = "url(/ZoneImages/" + value + ")";
			break;
		case "cursor":
			st[iIndex].style.cursor = value;
			break;
		case "textDecoration":
			st[iIndex].style.textDecoration = value;
			break;
		case "width":
			st[iIndex].style.width = value + "px";
			break;
		case "height":
			st[iIndex].style.height = value + "px";
			break;
		case "borderWidth":
			st[iIndex].style.borderWidth =  value + "px";
			break;
		case "borderColor":
			st[iIndex].style.borderColor = value;
			break;
		case "borderStyle":
			st[iIndex].style.borderStyle = value;
			break;
		case "lineHeight":
			st[iIndex].style.lineHeight =  value + "px";
			break;
		case "alpha":
			st[iIndex].style.filter = "alpha(opacity="+ value +")";
			st[iIndex].style.opacity = value/100;
			st[iIndex].style.MozOpacity = value/100;
		default:
			break;
	}
}
