﻿function StrCode(str)
{
//    str = HtmlEncode(str);
//	if(escape)
//		return escape(str);
	if(str == undefined || str == null) 
        return "";
//    var re = {'&':'&amp;'};
//	for (i in re) str = str.replace(new RegExp(i,'g'), re[i]);
//	alert(str);
   str = HtmlEncode(str);
    if(escape)
		return escape(str);
    //return str.replace(/(^(\s|\u0000)*|(\s|\u0000)*$)/g, "");
    //return str;
}

function gid(id)
{
	return document.getElementById?document.getElementById(id):null;
}
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;
}
//===============================================================
var _arr_DragModule = [];
var _arr_DragLand = [];
var _arr_DragSplitID = "_Split";
var _DragLandLabelID = "_Label";
var _DragLandLinkID = "_Link";
var _DragLandContentID = "_Content";
var _DragLandMoreID = "_More";
var _DragLandEditID = "_Edit";
var _DragLandBtnID = "_Btn";
var _DragMovingEventTime = 0;
var _str_UserName = 0;
var _str_RoleID = 0;
//装载可移动对象的方法//
function DragInit(allow, arr, mod, username, roleid)
{
	_arr_DragLand = arr;
	_arr_DragModule = mod;
	_str_UserName = username;
	_str_RoleID = roleid;
	if (_arr_DragLand.length > 0)
	{
		for(var s = 0;s < _arr_DragLand.length;s++)
		{
			var lObj = _arr_DragLand[s];
			var sObj = gid(lObj.id + _arr_DragSplitID);
			var smod = mod[s];
			for (var m=0;m<smod.length;m++)
			{		
				_drag_AddModule(lObj, smod[m][0], smod[m][1], null, smod[m][2] ,smod[m][3], allow, false, smod[m][4]);
			}
		}
		window.setTimeout("_drag_gc()", 600);
	}
}
function _drag_AddModule(dragland, id, title, content, ki ,wp, allow, update, link)
{
	var loadObj = gid("ModuleLoading");
	if (loadObj) loadObj.innerHTML = "";	
	if (dragland)
	{
		var cModule = gid(id);
		if (!cModule)
		{   
			var module = _drag_CreatModule(id, title, content, ki, wp, link);			
			dragland.insertBefore(module, _drag_GetLandFirstModule(dragland));
			if (allow) _drag_InitModuleEvent(module);
			if (update) _drag_UpdateModuleArray();
		}
	}
}
function _drag_CreatModule(id, title, content, ki, wp, link)
{
	var cModule = gid(id);
	if (!cModule)
	{
		var mainDivObj = document.createElement("div");
		mainDivObj.className = "mkall";
		mainDivObj.id = id;
		mainDivObj.Killable = ki;
		mainDivObj.Warpable = wp;
		mainDivObj.MoreLink = link;
		mainDivObj.EventInit = false;
		
		var headDivObj = document.createElement("div");
		headDivObj.className = "mktitle";

		var contentObj = document.createElement("div");
		contentObj.id = id + _DragLandContentID;
		contentObj.className = "mkshow";
		if (wp)
		{
			contentObj.style.display = "block";
		}
		else
		{
			contentObj.style.display = "none";
		}
		if (content)
		{
			contentObj.innerHTML = content;
		}
		else
		{
			contentObj.innerHTML =  "<div class=\"loading\">正在读取内容...</div>";
		}
		
		var titleLinkObj = document.createElement("div");
		titleLinkObj.id = id + _DragLandLinkID;
		titleLinkObj.title = "展开/收拢";
		titleLinkObj.innerHTML =  title;

		if (wp)
		{
			titleLinkObj.className = "mktitleleft";
		}
		else
		{
			titleLinkObj.className = "mktitleleft2";
		}
		titleLinkObj.WarpContent = contentObj;
		titleLinkObj.WarpParent = mainDivObj;
		titleLinkObj.onclick = function ()
		{
			this.blur();
			if (this.className == "mktitleleft2")
			{
				if (this.WarpContent) this.WarpContent.style.display = "block";
				this.className = "mktitleleft";
				if (this.WarpParent) this.WarpParent.Warpable = true;
			}
			else
			{
				if (this.WarpContent) this.WarpContent.style.display = "none";
				this.className = "mktitleleft2";
				if (this.WarpParent) this.WarpParent.Warpable = false;
			}
			if(_str_RoleID==1)	_drag_UpdateModuleArray();
			return false;
		};

		var cellDragObj = document.createElement("div");
		cellDragObj.title = "点击并拖动此模块...";
		cellDragObj.id = id + _DragLandLabelID;

		var divRightObj = document.createElement("div");
		divRightObj.className = "right";
		if(_str_RoleID==1)
		{
			if (link)
			{
				var cellMoreObj = document.createElement("span");
				cellMoreObj.id = id + _DragLandMoreID;
			}

			if(ki)
			{
				var cellBtnObj = document.createElement("span");
				cellBtnObj.id = id + _DragLandBtnID;
			}
		}

		headDivObj.appendChild(titleLinkObj);
		if(_str_RoleID==1)
		{
			if (link) divRightObj.appendChild(cellMoreObj);
			if (ki) divRightObj.appendChild(cellBtnObj);
		}
		headDivObj.appendChild(divRightObj);
		headDivObj.appendChild(cellDragObj);

		mainDivObj.appendChild(headDivObj);
		mainDivObj.appendChild(contentObj);
		cModule = mainDivObj;
	}
	return cModule;
}
function _drag_GetLandFirstModule(dragland)
{
	var landFirstObj = null;	
	if (dragland)
	{
		var dlcN = dragland.childNodes;
		for(var n = 0;n<dlcN.length;n++)
		{
			var nodeObj = dlcN[n];
			if (nodeObj.id)
			{
				var nodeLinkObj = gid(nodeObj.id + _DragLandLinkID);
				if (nodeLinkObj)
				{
					landFirstObj = nodeObj;
					break;
				}
			}
		}
		if (!landFirstObj)
		{
			landFirstObj = gid(dragland.id + _arr_DragSplitID);
		}
	}
	return landFirstObj;
}


function _drag_InitModuleEvent(module)
{
	if (!module.EventInit)
	{
		var nodeObj = module;
		var mlObj = gid(nodeObj.id + _DragLandLabelID);
		mlObj.module = nodeObj;
		DragEventObj.init(mlObj);
		module.EventInit = true;
		mlObj.style.cursor = "move";
		mlObj.innerHTML = "&nbsp;";
		
		var _isKillable = nodeObj.Killable;
		var btnObj = gid(nodeObj.id + _DragLandBtnID);
		if (btnObj && _isKillable)
		{
			btnObj.innerHTML = "关闭";
			btnObj.title = "关闭此模块";
			btnObj.style.cursor = "pointer";
			btnObj.module = nodeObj;
			btnObj.onclick = function() {this.blur();_drag_RemoveModule(this.module);return false;};
			nodeObj.killbtn = btnObj;
		}
		
		var _HavaMoreLink = nodeObj.MoreLink;
		var moreObj = gid(nodeObj.id + _DragLandMoreID);
		if (moreObj && _HavaMoreLink)
		{
			moreObj.innerHTML = "编辑 ";
			moreObj.title = "编辑此模块";
			moreObj.style.cursor = "pointer";
			moreObj.onclick = function() {this.blur();return false;};
			moreObj.onclick = function ()
			{
				this.blur();
				var editObj = gid(nodeObj.id + _DragLandEditID);
				if(editObj)
				{
					if (editObj.style.display == "none")
					{
						editObj.style.display = "block";
						this.innerHTML = "取消 ";
						this.title = "取消编辑";
					}
					else
					{
						editObj.style.display = "none";
						this.innerHTML = "编辑 ";
						this.title = "编辑此模块";
					}
				}
				return false;
			}

			moreObj.module = nodeObj;
			nodeObj.morelinkbtn = moreObj;
		}
		
		mlObj.onDragStart = function(left, top)
		{
			clearInterval(_DragMovingEventTime);
			var oObj = this.module;
			_drag_FormatChild(oObj);
			oObj.origNextSibling = oObj.nextSibling;
			_drag_FormatDragLand(oObj, true);					

			var mObj = _drag_CreatDiv();
			mObj.style.left = _drag_LeftTop(oObj, true) + "px";
			mObj.style.top = _drag_LeftTop(oObj, false) + "px";
			mObj.style.height = oObj.offsetHeight + "px";
			mObj.style.width = oObj.offsetWidth + "px";
			mObj.style.border = "#f00 1px dashed";
			mObj.style.filter = "alpha(opacity=60)";
			mObj.style.opacity = 0.6;
			mObj.style.MozOpacity = 0.6;
			mObj.style.display = "block";
			mObj.innerHTML = oObj.innerHTML;
			mObj.className = oObj.className;
			this.dragged = false;
		};

		mlObj.onDrag=function(left, top)
		{
			_drag_Moving(this.module, left, top);
			this.dragged = true;
		};

		mlObj.onDragEnd=function(left, top)
		{
			if(this.dragged)
			{
				_DragMovingEventTime = _drag_MovingEvent(this.module, 1, 1);
			}
			else
			{
				_drag_CreatDiv().style.display = "none";
			}
			if (this.module.nextSibling != this.module.origNextSibling)
			{
				_drag_UpdateModuleArray();
			}
		}
	}
}
//function PageModuleRequest(url,data,moduleID)
//{
//    //"<div class=\"loading\">正在读取内容...</div>"
//    _drag_ModuleConentInit(moduleID, "<div class=\"loading\">正在读取内容...</div>");
//	var AjaxRequestObj = InitRequest();
//	if (AjaxRequestObj != null)
//	{
//		AjaxRequestObj.onreadystatechange = function ()
//		{
//			if (AjaxRequestObj.readyState == 4 && AjaxRequestObj.responseText)
//			{
//                var AJAX_Modules = moduleID;
//                var AJAX_ModuleContent = AjaxRequestObj.responseText;
//                _drag_ModuleConentInit(AJAX_Modules, AJAX_ModuleContent);
//				//ProcessAjaxData(AjaxRequestObj.responseText);
//			}
//		};
//		AjaxRequestObj.open("POST", url, true);
//		AjaxRequestObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
//		AjaxRequestObj.send(data);
//	}
//}
function ModuleRequest(url, data,moduleID)
{
	var AjaxRequestObj = InitRequest();
	if (AjaxRequestObj != null)
	{
		AjaxRequestObj.onreadystatechange = function ()
		{
			if (AjaxRequestObj.readyState == 4 && AjaxRequestObj.responseText)
			{
                var AJAX_Modules = moduleID;
                var AJAX_ModuleContent = AjaxRequestObj.responseText;
                _drag_ModuleConentInit(AJAX_Modules, AJAX_ModuleContent);
				//ProcessAjaxData(AjaxRequestObj.responseText);
			}
		};
		AjaxRequestObj.open("POST", url, true);
		AjaxRequestObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		AjaxRequestObj.send(data);
	}
}
var DragEventObj=
{
	obj:null,
	init:function(event)
	{
		event.onmousedown = DragEventObj.start;
		if(isNaN(parseInt(_drag_CreatDiv().style.left))) _drag_CreatDiv().style.left = "0px";
		if(isNaN(parseInt(_drag_CreatDiv().style.top))) _drag_CreatDiv().style.top = "0px";
		event.onDragStart = new Function();
		event.onDragEnd = new Function();
		event.onDrag = new Function()
	}
	,start:function(event)
	{
		var eObj = DragEventObj.obj = this;
		event = DragEventObj.fixE(event);
		if(event.button == 2 || event.button == 3)
		{
			return true;
		}
		var top = parseInt(_drag_CreatDiv().style.top);
		var left = parseInt(_drag_CreatDiv().style.left);
		eObj.onDragStart(left, top, event.clientX, event.clientY);
		eObj.lastMouseX = event.clientX;
		eObj.lastMouseY = event.clientY;
		document.onmousemove = DragEventObj.drag;
		document.onmouseup = DragEventObj.end;
		return false;
	}
	,drag:function(event)
	{
		event = DragEventObj.fixE(event);
		var eObj = DragEventObj.obj;
		var etop = event.clientY;
		var eleft = event.clientX;
		var otop = parseInt(_drag_CreatDiv().style.top);
		var oleft = parseInt(_drag_CreatDiv().style.left);
		var mleft, mtop;
		mleft = oleft + eleft - eObj.lastMouseX;
		mtop = otop + etop - eObj.lastMouseY;
		_drag_CreatDiv().style.left = mleft + "px";
		_drag_CreatDiv().style.top = mtop + "px";
		eObj.lastMouseX = eleft;
		eObj.lastMouseY = etop;
		eObj.onDrag(mleft, mtop, eleft, etop);
		return false
	}
	,end:function()
	{
		document.onmousemove = null;
		document.onmouseup = null;
		DragEventObj.obj.onDragEnd(parseInt(_drag_CreatDiv().style.left), parseInt(_drag_CreatDiv().style.top));
		DragEventObj.obj = null;
	}
	,fixE:function(event)
	{
		if(typeof event == "undefined") event = window.event;
		if(typeof event.layerX=="undefined") event.layerX = event.offsetX;
		if(typeof event.layerY=="undefined") event.layerY = event.offsetY;
		return event;
	}
};

function _drag_upc()
{
//	var PostData = "Mods=" + _drag_GetModuleString();
	var PostData = "Type=UpdateMods&Mods=" +  _drag_GetModuleString();
				
	PostRequest(path + "Space/Tool.aspx", PostData);
	//PostRequest(path + "Ajax/Space/UpdateMods.aspx", PostData);
}

function _drag_gc()
{
	for(var p=0;p<=_arr_DragModule.length-1;p++)
	{
		for (var m=_arr_DragModule[p].length-1; m>=0 ; m--)
		{
		    var PostData = "userName="+ _str_UserName +"&roleID="+ _str_RoleID +"&modID=" + _arr_DragModule[p][m][0];
		    var temp = gid("Temp_"+_arr_DragModule[p][m][0]);
		    
		    if (temp) 
		    {
		        _drag_ModuleConentInit(_arr_DragModule[p][m][0], temp.innerHTML );
		    }
		    
		    
//		    if(_arr_DragModule[p][m][0].indexOf('_Main')>0)
//		    {
//			     ModuleRequest(path + "Ajax/Space/MainModQuery.aspx", PostData,_arr_DragModule[p][m][0]);
//			}
//			else
//			{
//			    if(_arr_DragModule[p][m][0]=="Mod_Photo")
//			    {
//			        
//			        GetAlbumModule(path + "Ajax/Space/PicPlayModule.aspx", PostData,_arr_DragModule[p][m][0]);
//			        
//			    }
//			    else
//			    {
//			        ModuleRequest(path + "Ajax/Space/ModQuery.aspx", PostData,_arr_DragModule[p][m][0]);
//			    }
//			}
		}
	}
}

function showModuleAll()
{
    for(var p=0;p<=_arr_DragModule.length-1;p++)
	{
		for (var m=_arr_DragModule[p].length-1; m>=0 ; m--)
		{
			var mObj = gid(_arr_DragModule[p][m][0] + _DragLandLinkID);
			if (mObj.className == "mktitleleft2")
			{
				if (mObj.WarpContent) mObj.WarpContent.style.display = "block";
				mObj.className = "mktitleleft";
			}
		}
	}
}

function hideModuleAll()
{
    for(var p=0;p<=_arr_DragModule.length-1;p++)
	{
		for (var m=_arr_DragModule[p].length-1; m>=0 ; m--)
		{
			var mObj = gid(_arr_DragModule[p][m][0] + _DragLandLinkID);
			if (mObj.className == "mktitleleft")
			{
				if (mObj.WarpContent) mObj.WarpContent.style.display = "none";
				mObj.className = "mktitleleft2";
			}
		}
	}
}

function _drag_GetModuleString()
{
	var tmdModules = [];
	for (var p in _arr_DragModule)
	{
		var tmpModule = [];
		for (var m in _arr_DragModule[p])
		{
			var tmpNewModule = [];
			tmpNewModule[0] = _arr_DragModule[p][m][0];
			//tmpNewModule[1] = _arr_DragModule[p][m][3];
			tmpModule[m] = tmpNewModule;
		}
		tmdModules[p] = tmpModule.join("|");
	}
	var tmpString = tmdModules.join("-");
	return tmpString;
}



function _drag_ModuleConentInit(modid, body)
{
	var obj = gid(modid + _DragLandContentID);
	if (obj)
	{
		if (body) obj.innerHTML = body;
	}
}

//function AddModule(modID, clubID)
//{
//	if (modID)
//	{
//		var cModule = gid(modID);
//		if (!cModule)
//		{
//			var loadObj = gid("ModuleLoading");
//			if (loadObj) loadObj.innerHTML = "<img src=\"/skin/v2/images/main/Loading.gif\" alt=\"正在加载\" />";
//			var PostData = "modID="+ modID +"&clubID=" + clubID;

//			PostRequest(window.location.protocol + "//" + window.location.host + "/CMS/AjaxPage/FreeModEdit.aspx", PostData);
//		}
//	}
//}

//修改后操作
function _drag_ModifyModule(modObj, title)
{
	if (modObj)
	{
		if(title.length > 0)
		{
			var modObjLink = gid(modObj.id + _DragLandLinkID);
			if (modObjLink) modObjLink.innerHTML =  title;
		}

		var moreObj = gid(modObj.id + _DragLandMoreID);
		if (moreObj) 
		{
			moreObj.innerHTML = "编辑 ";
			moreObj.title = "编辑此模块";
		}
		PostData = "Type=GetModHTML&ModID=" + modObj.id;
		ModuleRequest(path+ "Space/Tool.aspx", PostData,modObj.id);
	}
}



function _drag_RemoveModule(modObj)
{
	if (modObj)
	{
		if (modObj.parentNode)
		{
			modObj.parentNode.removeChild(modObj);
			_drag_UpdateModuleArray();
		}
	}
}

function _drag_UpdateModuleArray()
{
	var tmpLand = [];
	for(var s = 0;s < _arr_DragLand.length;s++)
	{
		var dlcN = _arr_DragLand[s].childNodes;
		var tmpModules = [];
		var tmpc = 0;
		for(var n = 0;n<dlcN.length;n++)
		{
			var nodeObj = dlcN[n];
			if (nodeObj.id)
			{
				var nodeObjID = nodeObj.id;
				var nodeLinkObj = gid(nodeObjID + _DragLandLinkID);
				if (nodeLinkObj)
				{
					var tmpModule = [];
					tmpModule[0] = nodeObjID;
					tmpModule[1] = nodeLinkObj.innerHTML;
					tmpModule[2] = nodeObj.Killable;
					tmpModule[3] = nodeObj.Warpable;
					tmpModules[tmpc] = tmpModule;
					tmpc++;
				}
			}
		}
		tmpLand[s] = tmpModules;
	}
	_arr_DragModule = tmpLand;
	_drag_upc();
}

var _drag_creatDivObj = null;
function _drag_CreatDiv()
{
	if(!_drag_creatDivObj)
	{
		_drag_creatDivObj = document.createElement("DIV");
		_drag_creatDivObj.style.display = "none";
		_drag_creatDivObj.style.position = "absolute";
		_drag_creatDivObj.style.cursor = "move";
		_drag_creatDivObj.style.backgroundColor = "#fff";
		_drag_creatDivObj.style.paddingBottom = "0px";
		document.body.appendChild(_drag_creatDivObj);
	}
	return _drag_creatDivObj;
}

function _drag_HideDiv()
{
	_drag_CreatDiv().style.display="none";
}

function _drag_LeftTop(obj, LT)
{
	var v = 0;
	while(obj != null)
	{
		v += obj["offset" + (LT?"Left":"Top")];
		obj = obj.offsetParent
	}
	return v;

}

function _drag_FormatChild(obj)
{
	for(var s = 0;s<_arr_DragLand.length;s++)
	{
		var dlcN = _arr_DragLand[s].childNodes;
		var h = 0;
		for(var n = 0;n<dlcN.length;n++)
		{
			var nodeObj = dlcN[n];
			if(nodeObj == obj) h = nodeObj.offsetHeight;
			nodeObj.pagePosLeft = _drag_LeftTop(nodeObj, true);
			nodeObj.pagePosTop = _drag_LeftTop(nodeObj, false) - h;
		}
	}
}

function _drag_FormatDragLand(obj, style)
{
	/*
	if (obj)
	{
		var dlcN = obj.childNodes;
		for(var n = 0;n<dlcN.length;n++)
		{
			var nodeObj = dlcN[n];
			nodeObj.style.visibility  = (style)?"hidden":"visible";
		}
		obj.style.border = ((style)?1:0) + "px dashed #f00";
	}
	*/
}

function _drag_Moving(obj, left, top)
{
	var bObj = null;
	var mp = 100000000;
	for(var s=0;s<_arr_DragLand.length;s++)
	{
		var dlcN = _arr_DragLand[s].childNodes;
		for(var n=0;n<dlcN.length;n++)
		{
			var nodeObj = dlcN[n];
			if(nodeObj == obj) continue;
			var ms = Math.sqrt(Math.pow(left - nodeObj.pagePosLeft, 2) + Math.pow(top - nodeObj.pagePosTop, 2));
			if(isNaN(ms)) continue;
			if(ms < mp)
			{
				mp = ms;
				bObj=nodeObj;
			}
		}
	}
	if(bObj!=null && obj.nextSibling != bObj)
	{
		bObj.parentNode.insertBefore(obj, bObj);
		obj.parentNode.style.display="none";
		obj.parentNode.style.display=""
	}
}

function _drag_MovingEvent(obj, len, step)
{
	var left = parseInt(_drag_CreatDiv().style.left);
	var top = parseInt(_drag_CreatDiv().style.top);
	var leftstep = (left - _drag_LeftTop(obj, true)) / step;
	var topstep = (top - _drag_LeftTop(obj, false)) / step;
	_drag_FormatDragLand(obj, false);
	return setInterval(
		function()
		{
			if(step < 1)
			{
				clearInterval(_DragMovingEventTime);
				_drag_HideDiv();
				return;
			}
			step--;
			left -= leftstep;
			top -= topstep;
			_drag_CreatDiv().style.left = parseInt(left) + "px";
			_drag_CreatDiv().style.top = parseInt(top) + "px"
		}
		, len/step
	);
}


function PostGuestBook(uid)
{
    document.getElementById("messageError").innerHTML="";
    var objValue = document.getElementById("message").value;
	if (objValue.length < 1 )
	{
	    document.getElementById("messageError").innerHTML="<div><font color='red'>留言内容不能为空(1-1000个字符)！</font></div>";
	    document.getElementById("message").focus();
	    return;
	}
	
	if( objValue.length > 1000)
	{
	    document.getElementById("messageError").innerHTML="<div><font color='red'>留言内容不能超过1000个字符！</font></div>";
	    document.getElementById("message").focus();
	   return;
	}
	var url = path+"Space/AddGuestBook.aspx?UserID="+uid+"&Message="+StrCode(objValue); 
	
	if (window.XMLHttpRequest) { // Non-IE browsers
		req = new XMLHttpRequest();
		try {
			req.open("GET", url, false);
		} catch (e) {
			alert(e);
		}
		req.send(null);
	} else if (window.ActiveXObject) { // IE
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.open("GET", url, false);
			req.send();
		}
	}
	if (req.readyState == 4) { 
		if (req.status == 200) { 
//		   if (req.responseText == 0) {
//				document.getElementById("messageError").innerHTML="<div><font color='red'>您还未登录，不能进行留言。<a href='"+path+"Space/LoginInModal.aspx' id='loginInModalButton'>登录</a></font></div>";
//	            document.getElementById("message").focus();
//		   }
//		   else
//		   {
                
               var eLI = document.createElement("LI")
               eLI.innerHTML=req.responseText;
               document.getElementById("GBook").insertBefore(eLI) 
		       document.getElementById("message").value ="";
		       document.getElementById("messageSucc").innerHTML="<div class=\"hint\"><img align=\"absmiddle\" src=\""+path+"Image/default/standard_msg_ok.gif\"/>非常感谢您的留言！</div>";
		       $(document).ready(function(){ setTimeout(function(){ $("div.hint").fadeOut("normal"); },3000);});
//		   }
		}
	} else {
	    document.getElementById("messageError").innerHTML="<div><font color='red'>暂时不能进行留言！</font></div>";
	}


}



//======================================
function PostGuestBook(uid)
{
    document.getElementById("messageError").innerHTML="";
    var objValue = document.getElementById("message").value;
	if (objValue.length < 1 )
	{
	    document.getElementById("messageError").innerHTML="<div><font color='red'>留言内容不能为空(1-1000个字符)！</font></div>";
	    document.getElementById("message").focus();
	    return;
	}
	
	if( objValue.length > 1000)
	{
	    document.getElementById("messageError").innerHTML="<div><font color='red'>留言内容不能超过1000个字符！</font></div>";
	    document.getElementById("message").focus();
	   return;
	}
	document.getElementById("btnGuestBook").disabled= true; 
	

	var url = path+"Space/AddGuestBook.aspx?UserID="+uid+"&Message="+StrCode(objValue); 
	
	if (window.XMLHttpRequest) { // Non-IE browsers
		req = new XMLHttpRequest();
		try {
			req.open("GET", url, false);
		} catch (e) {
			alert(e);
		}
		req.send(null);
	} else if (window.ActiveXObject) { // IE
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.open("GET", url, false);
			req.send();
		}
	}
	if (req.readyState == 4) { 
		if (req.status == 200) { 
//		   if (req.responseText == 0) {
//				document.getElementById("messageError").innerHTML="<div><font color='red'>您还未登录，不能进行留言。<a href='"+path+"Space/LoginInModal.aspx' id='loginInModalButton'>登录</a></font></div>";
//	            document.getElementById("message").focus();
//		   }
//		   else
//		   {
                alert(req.responseText)
               var eLI = document.createElement("LI")
               eLI.innerHTML=req.responseText;
               document.getElementById("GBook").insertBefore(eLI,null);
		       document.getElementById("message").value ="";
		       document.getElementById("messageSucc").innerHTML="<div class=\"hint\"><img align=\"absmiddle\" src=\""+path+"Image/default/standard_msg_ok.gif\"/>非常感谢您的留言！</div>";
		       $(document).ready(function(){ setTimeout(function(){ $("div.hint").fadeOut("normal"); },3000);});
//		   }
		}
	} else {
	    document.getElementById("messageError").innerHTML="<div><font color='red'>暂时不能进行留言！</font></div>";
	}

    document.getElementById("btnGuestBook").disabled= 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() {
		    if(this.value=='')
		    {
		        alert("修改空间名称失败,空间名称不能为空！");
		        this.parentNode.innerHTML = myweb;
		        doPageTitleEvent(myweb);
		        return;
		    }
		    		
			var value = (this.value=='') ? myweb : HtmlEncode(this.value);	
						
			this.parentNode.innerHTML = value;
			if (this.value != titleValue) {
				document.title = value+" - 群游网 | Qun2.com";
				DialogShow("<div class=\"loading\">正在保存我的空间名称,请稍候...</div>",250,25,250,25);
				var PostData = "Type=UpdateTitle&Title=" + StrCode(value);			
				
				PostRequest(path + "Space/Tool.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);	
			if(this.value!='')
			{
			    this.parentNode.innerHTML = value;
			}
			else
			{
			    this.parentNode.innerHTML ='点击添加副标题';
			}			
			
			if (this.value != titleValue) {
				//ScreenConvert();
				var PostData = "Type=UpdateDescription&Description=" + StrCode(value);			
				DialogShow("<div class=\"loading\">正在保存我的空间副标题,请稍候...</div>",250,25,250,25);
				PostRequest(path + "Space/Tool.aspx", PostData);
			}
			doPageTitleEventTwo();
			
		}
	}
}

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)
			{
				ProcessAjaxData(AjaxRequestObj.responseText);				
			}
		};
		//alert(url);
		//alert(data);
		AjaxRequestObj.open("POST", url, true);
		AjaxRequestObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		//AjaxRequestObj.setRequestHeader("Content-Type","no-cache");
		AjaxRequestObj.send(data);
	}
}
function ProcessAjaxData(data)
{
    
    try
	{
	    if(data!="")
	    {
		    eval(data);
		}
	}
	catch(e)
	{
        //alert(e.description);
	}
	
}

//dia
function gname(name)
{
	return document.getElementsByTagName?document.getElementsByTagName(name):new Array();
}
function ScreenClean()
{
	var objScreen = document.getElementById("divCover");
	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)
{
//    $(document).ready(function()
//    {
	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 = "100000001";
	//oS.border="2px solid #e1e1e1";
	objDialog.innerHTML = showdata;
	document.body.appendChild(objDialog);
//	 });		
}
function DialogHide()
{
	//ScreenClean();
	var objDialog = document.getElementById("DialogMove");
	if (objDialog) objDialog.style.display = "none";
}
//=
function Trim(s)
{
	var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);return (m == null)?"":m[1];
}
function SetModIntroOK(modID)
{
	var objMark = gid("txtMarkName" + modID);
	var objDesc = gid("txtIntroDesc" + modID);
	
	if(objMark && objDesc &&  modID)
	{
		if (Trim(objMark.value).length < 1 )
		{
		    alert("修改个人介绍失败,标题不能为空！");
		    gid('txtMarkName' + modID).focus();
		    return false;
		}
		if (Trim(objDesc.value).length < 1 )
		{
		    alert("修改个人介绍失败,介绍内容不能为空！");
            gid('txtIntroDesc' + modID).focus();
		    return false;
		}
		var intLen = objMark.value.length;
		var intLenDesc = objDesc.value.length;
		
		if( intLen > 50)
		{
		    alert("修改个人介绍失败,标题不能超过50个字符！");
		    gid('txtMarkName' + modID).focus();
		   
		    return false;
		}
		if( intLenDesc >4000)
		{
		    alert("修改个人介绍失败,介绍内容不能超过4000个字符！");
            gid('txtIntroDesc' + modID).focus();
		    return false;
		}
		var PostData = "Type=UpdateIntro&Intro=" + StrCode(objDesc.value)+"&MarkName=" + StrCode(objMark.value) ;			
		alert(PostData);
		DialogShow("<div class=\"loading\">正在发送,请稍候...</div>",150,25,150,25);
		PostRequest(path + "Space/Tool.aspx", PostData);
	}
	else
	{
	    alert("读取数据失败,请重新操作！");
	    return false;
	}
}
function SetModSingleOK(modID)
{
	var objMark = gid("txtMarkName" + modID);
	
	if(objMark && modID)
	{
		if (Trim(objMark.value).length < 1 )
		{
		    alert("修改个人介绍失败,标题不能为空！");
		    gid('txtMarkName' + modID).focus();
		    return false;
		}
		var intLen = objMark.value.length;
		if( intLen >50)
		{
		    alert("修改个人介绍失败,标题不能超过50个字符！");
		    gid('txtMarkName' + modID).focus();
		   
		    return false;
		}
		var PostData = "Type=UpdateSingleMod&MarkName=" + StrCode(objMark.value)+"&ModID="+modID ;			
		DialogShow("<div class=\"loading\">正在发送,请稍候...</div>",150,25,150,25);
		PostRequest(path + "Space/Tool.aspx", PostData);
	}
	else
	{
	    alert("读取数据失败,请重新操作！");
	    return false;
	}
}
function SetModMiddleOK(modID)
{
	var objMark = gid("txtMarkName" + modID);
	var objNumber = gid("txtModNumber" + modID);
	
	if(objMark && objNumber &&  modID)
	{
		if (Trim(objMark.value).length < 1 )
		{
		    alert("操作失败,标题不能为空！");
		    gid('txtMarkName' + modID).focus();
		    return false;
		}
		if (Trim(objNumber.value).length < 1 )
		{
		    alert("操作失败,显示条数不能为空！");
		    gid('txtModNumber' + modID).focus();
		    return false;
		}
		if(objNumber.value.match(/\d+/)!=objNumber.value){   
            alert("操作失败,显示条数必须为数字！");
		    gid('txtModNumber' + modID).focus();  
            return   false;   
        }   

		var intLen = objMark.value.length;
		if( intLen >50)
		{
		    alert("修改个人介绍失败,标题不能超过50个字符！");
		    gid('txtMarkName' + modID).focus();
		    return false;
		}
		var PostData = "Type=UpdateMiddleMod&MarkName=" + StrCode(objMark.value)+"&ModID="+modID + "&ModNumber=" + objNumber.value;		
		DialogShow("<div class=\"loading\">正在发送,请稍候...</div>",150,25,150,25);
		PostRequest(path + "Space/Tool.aspx", PostData);
	}
	else
	{
	    alert("读取数据失败,请重新操作！");
	    return false;
	}
}
function DoModLayOut(Layout)
{
	var PostData = "Type=UpdateLayOut&Layout=" + Layout;	

//	DialogShow("<div class=\"loading\">正在发送,请稍候...</div>",150,25,150,25);
	PostRequest(path + "Space/Tool.aspx", PostData);
}
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 DialogBox(isoverLay,title,ow,oh,w,h,url,isdrag)
{
    var screenClean = "";
    if(isoverLay)
    {
        screenClean = "ScreenClean();";
    }
     
    var dialogF ="<div class=\"popuptitle\" id=\"DialogTitle\"><div class=\"left\"><strong>"+title+"</strong></div><div class=\"right\"><a id=\"closeBut\" href=\"#\" onclick=\"DialogHide();"+screenClean+"\" title=\"close\">Close</a></div></div>\
    <div id=\"popupcontent\" style=\"overflow: auto;\"><div id=\"DialogBoxLoading\">Loading...</div></div>";
    if(isoverLay)
    {
        ScreenConvert();
    }		
    DialogShow(dialogF,ow,oh,w,h);
    
    if(isdrag)
    {
        Drag.init(gid('DialogTitle'), gid('DialogMove'));
    }
    if(!isIE )
    {
        document.getElementById("popupcontent").style.height =  (h-25)+"px"; 
    }
    var AjaxRequestObj = InitRequest();
	if (AjaxRequestObj != null)
	{
		AjaxRequestObj.onreadystatechange = function ()
		{
			if (AjaxRequestObj.readyState == 4 && AjaxRequestObj.responseText)
			{
//			    $(document).ready(function() {
			   
                document.getElementById("popupcontent").innerHTML=AjaxRequestObj.responseText;
                // initialize overlay trigger
//                });					  
			}
		};
		//alert(url);
		//alert(data);
		AjaxRequestObj.open("POST", url, true);
		AjaxRequestObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		//AjaxRequestObj.setRequestHeader("Content-Type","no-cache");
		AjaxRequestObj.send(null);
	}
//    var dialogF = '<a id="closeBut" href="#" onclick="DialogHide();'+screenClean+'" title="close">Close</a>\
//        <div class="wrapper">\
//            <div id="nyroModalContent" style="overflow: auto;">\
//            </div>\
//        </div>\
//        </div>\
//        <div id="nyroModalLoading" style="margin-top: -166px;\
//        display: none; z-index: 102; filter: ; left: 50%; margin-left: -235px; width: 462px;\
//        zoom: 1; position: absolute; top: 50%; height: 325px">\
//        </div>';
    //if(!this.OverLay)
    
}
function stateChangeIE(_frame,w,h)
{ 
     if (_frame.readyState=="interactive")//state: loading ,interactive,   complete
     {
        var loader = document.getElementById("DialogBoxLoading"); 
        loader.innerHTML      = "";    
        loader.style.display = "none"; 
        _frame.style.visibility = "visible";   
        _frame.style.width = w+"px";  
        _frame.style.height = h+"px";  
     }   
}
function stateChangeFirefox(_frame,w,h)
{ 
    var loader = document.getElementById("DialogBoxLoading"); 
    loader.innerHTML      = "";    
    loader.style.display = "none"; 
    _frame.style.visibility = "visible";   
    _frame.style.width = w+"px";  
    _frame.style.height = h+"px"; 
}

function DialogBoxFrame(title,ow,oh,w,h,url,isdrag)
{
    var screenClean = "";
    if(!isIE )
    {
        h =h-25; 
    }
    var dialogF ="<div class=\"popuptitle\" id=\"DialogTitle\"><div class=\"left\"><strong>"+title+"</strong></div><div class=\"right\"><a id=\"closeBut\" href=\"#\" onclick=\"DialogHide();"+screenClean+"\" title=\"close\">Close</a></div></div>\
    <div id=\"popupcontent\"><div id=\"DialogBoxLoading\">Loading...</div><iframe frameborder=\"0\" scrolling=\"no\" src=\"" + url + "\" style=\"width:"+"0"+"px; height:"+"0"+"px;\" style=\"visibility:hidden\" onreadystatechange=\"stateChangeIE(this,"+w+","+h+")\" onload=\"stateChangeFirefox(this,"+w+","+h+")\"></iframe></div></div>";
//    var dialogF ="<div class=\"popuptitle\" id=\"DialogTitle\"><div class=\"left\"><strong>"+title+"</strong></div><div class=\"right\"><a id=\"closeBut\" href=\"#\" onclick=\"DialogHide();\" title=\"close\">Close</a></div></div>\
//    <div id=\"popupcontent\"><iframe frameborder=\"0\" scrolling=\"no\" src=\"" + url + "\" style=\"width:"+w+"px; height:"+h+"px;\"></iframe></div>";

    DialogShow(dialogF,ow,oh,w,h);
    if(isdrag)
    {
        Drag.init(gid('DialogTitle'), gid('DialogMove'));
    }
    if(!isIE )
    {
        document.getElementById("popupcontent").style.height =  (h-25)+"px"; 
    }
}

//=
var isIE = (document.all) ? true : false;

var isIE6 = isIE && ([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == 6);
function ScreenConvert()
{
	var _Color= "#fff";//背景色
	var _Opacity = 50;//透明度(0-100)
	var _zIndex = 100000000;//层叠顺序
	oDivCover=gid("divCover");
	if(!oDivCover){ 
		oDivCover=document.createElement("div");
		oDivCover.setAttribute("id","divCover");
		document.body.scroll="no";
		document.body.appendChild(oDivCover);
	
        var _w = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth) + "px";
	    var _h = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) + "px";
	    with(oDivCover.style){
		    zIndex = _zIndex; left = top = 0; position = "fixed"; width =_w; height = _h; 
		    isIE ? filter = "alpha(opacity:" + _Opacity + ")" : opacity = _Opacity / 100;
		    backgroundColor = _Color; display = "block";
//            position="absolute";
//		    left=0;
//		    top=0;
//		    display="block";
//		    zIndex=99;
//		    height=_page.h+"px";
//		    width=_page.w+"px";
//		    if ((!browser.isSafari)&&(!browser.isOPera)) background="#181818";	
//		    else background="#F0F0F0";
//		    backgroundImage="url("+path+"Image/Overlay/overlay.png)";
//		    filter="alpha(opacity=60)";
//		    opacity=40/100;
//		    MozOpacity=40/100;
	    }
	    if(isIE6){
		    oDivCover.style.position = "absolute";
		    //ie6设置覆盖层大小程序
            window.attachEvent("onresize", Resize);
		    //遮盖select
		    oDivCover.innerHTML = '<iframe style="position:absolute;top:0;left:0;width:100%;height:100%;filter:alpha(opacity=0);"></iframe>'
	    }

	    oDivCover.onselectstart=function(){return false;};
	    oDivCover.ondragstart=function(){return false;};
	}
	else
	{
	    oDivCover.style.display = "";
	}
}

function Resize()
{
    var oDivCover=gid("divCover");
    oDivCover.style.width = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth) + "px";
	oDivCover.style.height = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) + "px";
}

function ScreenClean()
{
	var objScreen = document.getElementById("divCover");
	if (objScreen) objScreen.style.display = "none";
//	var allselect = gname("select");
//	for (var i=0; i<allselect.length; i++) allselect[i].style.visibility = "visible";
}

function login_submit()
{
    if(document.getElementById('loginInModalUserName').value==''|document.getElementById('loginInModalPassword').value=='')
    {
        document.getElementById('errorInfoContent').innerHTML='用户名和密码必须填写！';
		document.getElementById('errorInfo').style.display='';
		document.getElementById('errorInfoContent').className = "errorInfo";
		
    }
    else
    {
		document.getElementById('errorInfo').style.display='';
		document.getElementById('errorInfoContent').innerHTML ="正在登录,请稍候......";
		document.getElementById('errorInfoContent').className = "loading";
        var PostData = "UserName=" + StrCode(document.getElementById('loginInModalUserName').value)+"&Password="+StrCode(document.getElementById('loginInModalPassword').value) ;		
		PostRequest(path + "Space/LoginInModal.aspx", PostData);
    }
}

//刷新当前页面

function refresh() {

    var currentPageURL = unescape(window.location.href.replace("#", ""));
    window.location.href = currentPageURL;
}
function logout()
{
	PostRequest(path + "Space/Logout.aspx", "");
}

//主题选择
var rowid=0;
function ov(obj){if(rowid==obj.rowIndex)return;obj.style.background="#F6F6F6"}
function out(obj){if(rowid==obj.rowIndex)return;obj.style.background="#FFFFFF"}
function ck(obj,num){
    
	obj.style.background="#D5E0DD"
	if(rowid!=obj.rowIndex)
	obj.parentNode.parentNode.rows[rowid].style.background="#FFFFFF"
	rowid=obj.rowIndex
	for(var n=1;n<=2;n++)
	{
	    if(n==num)
	    {
	        
	        document.getElementById('TemplatePre_'+n).style.display='';
	    }
	    else
	    {
	        document.getElementById('TemplatePre_'+n).style.display='none';
	    }
	}
	
//	$("page").innerHTML=""
//	showtmpl(obj.getAttribute("info"))
}
function imgov(obj){
	if(obj.innerHTML=="")
		return
	obj.style.cursor="pointer"
	obj.style.background="#F3F3F3"
}
function imgout(obj){
	if(obj.innerHTML=="")
		return
	obj.style.background="#FFFFFF"
}
function imgck(obj){
	var val=obj.getAttribute("val");
    setTheme(val);
}

function setTheme(o)
{
    DoTemplatePick(o);
}
//套用模板
function DoTemplatePick(sid)
{
    var PostData = "Type=UpdateTemplate&TemplateID=" + sid;	

//	DialogShow("<div class=\"loading\">正在发送,请稍候...</div>",150,25,150,25);
	PostRequest(path + "Space/Tool.aspx", PostData);
}


function getMyCss(attr, iIndex)
{
	
	var st = null;
	var ua;
	ua = navigator.userAgent.toLowerCase();
    if ((i = ua.indexOf("msie")) >= 0)
	{
		st = document.styleSheets["Hompy_MyStyle"].rules;
	}
	else
	{
	    //st = document.styleSheets["Hompy_MyStyle"].rules;
		st = document.getElementById('Hompy_MyStyle').sheet.cssRules;
	}	
	switch(attr)
	{
		case "color":
			value = st[iIndex].style.color;
			break;
		case "backgroundColor":
			//value =  ColorStringToRgb(st[iIndex].style.backgroundColor);
            value = st[iIndex].style.backgroundColor;

			break;
		case "backgroundPosition":
			value = st[iIndex].style.backgroundPosition;
			break;
		case "backgroundAttachment":
			value = st[iIndex].style.backgroundAttachment;
			break;
		case "backgroundRepeat":
			value = st[iIndex].style.backgroundRepeat;
			break;
		case "backgroundImageClient":
			value = st[iIndex].style.backgroundImage;
			break;
		case "backgroundImageWeb":
			value = st[iIndex].style.backgroundImage;
			break;
		case "cursor":
			value = st[iIndex].style.cursor;
			break;
		case "textDecoration":
			value = st[iIndex].style.textDecoration;
			break;
		case "width":
			value = st[iIndex].style.width;
			break;
		case "height":
			value = st[iIndex].style.height;
			break;
		case "borderWidth":
			value = st[iIndex].style.borderWidth;
			break;
		case "borderColor":
			value = st[iIndex].style.borderColor;
			break;
		case "borderStyle":
			value = st[iIndex].style.borderStyle;
			break;
		case "lineHeight":
			value = st[iIndex].style.lineHeight;
			break;
		case "alpha":
//			st[iIndex].style.filter = "alpha(opacity="+ value +")";
            value = st[iIndex].style.opacity*100;
//			st[iIndex].style.opacity = value/100;
//			st[iIndex].style.MozOpacity = value/100;
		default:
			break;
	}
	
	if(value)
	{   
	    if(typeof(value)=="string")
	    if(value.indexOf('rgb(')!=-1)
	    {
	        value = ColorStringToRgb(value);
	    }
	}
	return value;
}

function changeMyCss(attr, value, iIndex)
{
	//var browser = new Browser();
	var st = null;
	var ua;
	ua = navigator.userAgent.toLowerCase();
	if ((i = ua.indexOf("msie")) >= 0)
	{
		st = document.styleSheets["Hompy_MyStyle"].rules;
	}
	else
	{
	    //st = document.styleSheets["Hompy_MyStyle"].rules;
		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 + ")";
            st[iIndex].style.backgroundImage =  value ;
			break;
		case "backgroundImageWeb":
//			st[iIndex].style.backgroundImage = "url(/ZoneImages/" + value + ")";
            st[iIndex].style.backgroundImage = 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 ;
			break;
		case "height":
			st[iIndex].style.height = value ;
			break;
		case "borderWidth":
			st[iIndex].style.borderWidth =  value;
			break;
		case "borderColor":
			st[iIndex].style.borderColor = value;
			break;
		case "borderStyle":
			st[iIndex].style.borderStyle = value;
			break;
		case "lineHeight":
			st[iIndex].style.lineHeight =  value ;
			break;
		case "alpha":
			st[iIndex].style.filter = "alpha(opacity="+ value +")";
			st[iIndex].style.opacity = value/100;
			st[iIndex].style.MozOpacity = value/100;
		default:
			break;
	}
}

function ColorStringToRgb(_str){
    //rgb(255, 255, 255)
    
    _str = _str.match(/^\s*(\S+(\s+\S+)*)\s*$/)[1];
    _str = _str.substring(4,_str.length-1);
    
    var red=_str.split(",")[0];
    var green=_str.split(",")[1];
    var blue=_str.split(",")[2];
	
	red = toHex(red);
	green = toHex(green);
	blue = toHex(blue);

	rgbColor = "#" + red + "" + green + "" + blue;
//	//alert(blue);
	return rgbColor.toUpperCase();
}
    
function toHex(d)
{
    //alert(d);
    if (isNaN(d))
    {
        d=0;
    }
    var n=new Number(d).toString(16);
    
    return (n.length==1?"0"+n:n);
}

function DoGCursorHand(cur)
{
    changeMyCss("cursor", path + "Mouses/Cursor/"+cur, 0)
    //alert(path + "Mouses/Cursor/"+cur);
	var PostData = "Type=UpdateTemplateStr&Data=" + document.getElementById("Hompy_MyStyle").innerHTML;
	//alert(PostData);		
	PostRequest(path + "Space/Tool.aspx", PostData);
}