﻿
//可以打包为js文件;
var nx0=0,ny0=0,nx1=0,ny1=0;
var noffx=6,noffy=6;
var nmoveable=false;
var nhover='orange',nnormal='#3399FF';//color;
var nindex=10000;//z-index;
var nn;

//开始拖动;
function ncstartDrag(obj)
{
         if(event.button==1)
         {
                 //锁定标题栏;
                 obj.setCapture();
                 //定义对象;
                 var win = obj.parentNode;
                 var sha = win.nextSibling;
                 //记录鼠标和层位置;
                 nx0 = event.clientX;
                 ny0 = event.clientY;
                 nx1 = parseInt(win.style.left);
                 ny1 = parseInt(win.style.top);
                 //记录颜色;
                 nnormal = obj.style.backgroundColor;
                 //改变风格;
                 obj.style.backgroundColor = nhover;
                 win.style.borderColor = nhover;
                 obj.nextSibling.style.color = nhover;
                 sha.style.left = nx1 + noffx;
                 sha.style.top   = ny1 + noffy;
                 nmoveable = true;
         }
}
//拖动;
function ncdrag(obj)
{
         if(nmoveable)
         {
                 var win = obj.parentNode;
                 var sha = win.nextSibling;
                 win.style.left = nx1 + event.clientX - nx0;
                                 sha.style.left = parseInt(win.style.left) + noffx;
                                 if ((ny1 + event.clientY - ny0)>0 && (ny1 + event.clientY - ny0)<600){
                 win.style.top   = ny1 + event.clientY - ny0;
                 sha.style.top   = parseInt(win.style.top) + noffy;
                 }
         }
}
//停止拖动;
function ncstopDrag(obj)
{
         if(nmoveable)
         {
                 var win = obj.parentNode;
                 var sha = win.nextSibling;
                 var msg = obj.nextSibling;
                 win.style.borderColor      = nnormal;
                 obj.style.backgroundColor = nnormal;
                 msg.style.color            = nnormal;
                 sha.style.left = obj.parentNode.style.left;
                 sha.style.top   = obj.parentNode.style.top;
                 obj.releaseCapture();
                 nmoveable = false;
         }
}
//获得焦点;
function ncgetFocus(obj)
{
         if(obj.style.zIndex!=nindex)
         {
                 nindex = nindex + 2;
                 var idx = nindex;
                 obj.style.zIndex=idx;
                 obj.nextSibling.style.zIndex=idx-1;
         }
}
//最小化;
function ncmin(obj)
{
         var win = obj.parentNode.parentNode;
         var sha = win.nextSibling;
         var tit = obj.parentNode;
         var msg = tit.nextSibling;
         var flg = msg.style.display=="none";
         if(flg)
         {
                 win.style.height   = parseInt(msg.style.height) + parseInt(tit.style.height) + 2*2;
                 sha.style.height   = win.style.height;
                 msg.style.display = "block";
                 obj.innerHTML = "0";
         }
         else
         {
                 win.style.height   = parseInt(tit.style.height) + 2*2;
                 sha.style.height   = win.style.height;
                 obj.innerHTML = "2";
                 msg.style.display = "none";
         }
}
//关闭;
function nccls(obj)
{
         var win = obj.parentNode.parentNode.parentNode;
         //var sha = win.nextSibling;
         win.style.visibility = "hidden";
         //sha.style.visibility = "hidden";
}
//显示/隐藏;
function ShowHideNC()
{
	       if (nn!=null)
	       {
	       //alert("aaa");
                if (nn.style.visibility == "hidden")
                        nn.style.visibility = "visible";
                else if (nn.style.visibility == "visible")
                        nn.style.visibility = "hidden";
            }
}
//创建一个对象;
function UpdateNC()
{
	this.ncinitform=function(id,w,h,l,t,tit,msg)
	{
         nindex = nindex+2;
         this.id       = id;
         this.width    = w;
         this.height   = h;
         this.left     = l;
         this.top      = t;
         this.zIndex   = nindex;
         this.title    = tit;
         this.message = msg;
         this.obj      = null;
         this.ncbulid    = ncbulid;
         this.ncbulid();
         nn = document.getElementById('ncallx');
         //xx.style.visibility = show;
         nn.style.visibility = "hidden";

	}
	
	this.updatenc=function()
	{
		var uname = getValueById('ncname');
		var yname = getValueById('yname');	
			
		var tmp=uname;		
		if(uname==null || uname=="" || tmp.replace(/[ ]/g,"")=="")
		{
			alert("用户名不可为空！");
			return;
		}
		
		var ReturnVal=AjaxMethod.UpdateNC(yname,uname).value;
		if(ReturnVal!="")
		{
			alert(ReturnVal);
			return;
		}			
		
		
		window.location.href=window.location.href; 
		window.location.reload(1);		
		//window.location.reload(1);
		//window.location.reload(1);
		//window.location.href=window.location.href+ "?v=" + Math.floor(100 * Math.random() + 1);
		
	}	
	
}

//初始化;
function ncbulid()
{     
		
		
		var  colorTable='请填入昵称以激活个人空间(提供博客、论坛、收藏、留言、找朋友、亲友团....等网络服务)：<br><br>激活后将不再出现本提示框.<br><br>昵 称：<br><input type="text" name="ncname" id="ncname" onkeydown="if(event.keyCode==13){ nc.updatenc(); }" ><br><br>昵称为6～20位汉字、字母、数字组合。昵称具有唯一性，如出现重复请重新设置<br><br>'
		+'<input id="aaa" onclick="nc.updatenc()" type="button" value="激活我的空间"><br><br>';
		
        var str = ""
                 + "<div id='ncallx'><div id='ncxMsg'" + this.id + " "
                 + "style='"
                 + "z-index:" + this.zIndex + ";"
                 + "width:" + (this.width-10) + ";"
                 + "height:" + this.height + ";"
                 + "left:" + this.left + ";"
                 + "top:" + this.top + ";"
                 + "background-color:" + nnormal + ";"
                 + "color:" + nnormal + ";"
                 + "font-size:11px;"
                 + "font-family:Verdana;"
                 + "position:absolute;"
                 + "cursor:default;"
                 + "border:2px solid " + nnormal + ";"
                 + "' "
                 + "onmousedown='ncgetFocus(this)'>"
                         + "<div "
                         + "style='"
                         + "background-color:" + nnormal + ";"
                         + "width:" + (this.width-2*2) + ";"
                         + "height:20;"
                         + "color:white;"
                         + "' "
                         + "ondblclick='ncmin(this.childNodes[1])'"
                         + ">"
                                 + "<span style='width:" + (this.width-2*14-4) + ";padding-left:3px;'>" + this.title + "</span>"
                                 + "<span style='width:14;border-width:0px;color:white;font-family:webdings;' onclick='ncmin(this)'>0</span>"
                                 + "<span style='width:14;border-width:0px;color:white;font-family:webdings;' onclick='nccls(this)'>r</span>"
                         + "</div>"
                                 + "<div style='"
                                 + "width:100%;"
                                 + "height:" + (this.height-20-4) + ";"
                                 + "background-color:white;"
                                 + "line-height:14px;"
                                 + "word-break:break-all;"
                                 + "padding:3px;"
                                 + "'>" + colorTable+ "</div>"
                 + "</div>"
                 + "<div id='ncxshadow' style='"
                 + "width:" + this.width + ";"
                 + "height:" + this.height + ";"
                 + "top:" + this.top + ";"
                 + "left:" + this.left + ";"
                 + "z-index:" + (this.zIndex-1) + ";"
                 + "position:absolute;"
                 + "background-color:black;"
                 + "filter:alpha(opacity=40);"
                 + "'>by wildwind</div></div>";
                 
         
        document.getElementById('ncbox').innerHTML = str;
              
                
}