﻿// JScript 文件

//arguments
function CheckUserLogin(){
    var requestSimpleService = SaveXML.CheckUserLogin(arguments[0],OnRequestCheckUserLoginComplete);
}
function OnRequestCheckUserLoginComplete(result){
    //GetConfigXML();
    if (result.length == 6){
        memparam = result[1];
        applytime = result[5];
        var ifself = result[2];
        var iflogin = result[3];
        
        var doc = null;
        doc = XmlDom2(result[4]);
        if (doc != null){
            var nodes = doc.documentElement.selectNodes("//Table");
            if (nodes != null){
                if (nodes.length > 0){
                    ////////////////////////////
                    document.getElementById("loginul").innerHTML = "";
                    if (!iflogin){
                        document.getElementById("loginul").innerHTML += "<li><a href=\"javascript:void(null)\" onclick=\"Login()\">登录</a></li>" + 
                                                                      "<li><a href=\"http://www.espnstar.com.cn/new/register.asp\" target=\"_blank\">注册</a></li>";
                    }else{
                        document.getElementById("loginul").innerHTML += "<li><a href=\"javascript:void(null);\" onclick=\"UserLoginout()\">登出</a></li>" + 
                                                                      "<li><a href=\"manage/default.aspx\">控制台</a></li>";
                    }
                    if (ifself){
                        //document.getElementById('tempdiv').style.display='block';
                        document.getElementById("loginul").innerHTML += "<li><a href=\"/members/custom.htm\" onclick=\"return GB_myShow('添加版块', this.href)\">自定义版块</a></li>";
                    }
                    ////////////////////////////////
                    
                    var myblogname = getMyBlogName();
                    if (myblogname == null)
                    	myblogname = "";
                    
                    if (document.all){
                        window.document.title = nodes[0].selectSingleNode("blogTitle").text + " - ESPNSTAR博客";
                        document.getElementById("usertop").innerHTML = "<h3><a href=\"/" + nodes[0].selectSingleNode("blogDefineName").text + "\">" + nodes[0].selectSingleNode("blogTitle").text + "</a></h3>" + 
                                                                        " <h4>" + nodes[0].selectSingleNode("blogDesc").text + "</h4>";
                                                                        
                        /////////////////////////////
                        if (iflogin && !ifself){
                            document.getElementById("loginul").innerHTML += "<li><a href=\"" + myblogname + "\">我的首页</a></li>";
                        }
                        ////////////////////////////
                        
                        document.getElementById("menu").innerHTML = "<ul>" + 
                                                                    "   <li><a href=\"javascript:void(null);\" class=\"ov\">首页</a></li>" + 
                                                                    "   <li><a href=\"" + nodes[0].selectSingleNode("blogDefineName").text + "/loglist\">日志</a></li>" + 
                                                                    "   <li><a href=\"" + nodes[0].selectSingleNode("blogDefineName").text + "/photolist\">相册</a></li>" + 
                                                                    "   <li><a href=\"" + nodes[0].selectSingleNode("blogDefineName").text + "/message\">留言</a></li>" + 
                                                                    "</ul>";
                    }else{
                        window.document.title = nodes[0].selectSingleNode("blogTitle").textContent + " - ESPNSTAR博客";
                        document.getElementById("usertop").innerHTML = "<h3><a href=\"/" + nodes[0].selectSingleNode("blogDefineName").textContent + "\">" + nodes[0].selectSingleNode("blogTitle").textContent + "</a></h3>" + 
                                                                        " <h4>" + nodes[0].selectSingleNode("blogDesc").textContent + "</h4>";
                        /////////////////////////////
                        if (iflogin && !ifself){
                            document.getElementById("loginul").innerHTML += "<li><a href=\"" + myblogname + "\">我的首页</a></li>";
                        }
                        ////////////////////////////
                        
                        document.getElementById("menu").innerHTML = "<ul>" + 
                                                                    "   <li><a href=\"javascript:void(null);\" class=\"ov\">首页</a></li>" + 
                                                                    "   <li><a href=\"" + nodes[0].selectSingleNode("blogDefineName").textContent + "/loglist\">日志</a></li>" + 
                                                                    "   <li><a href=\"" + nodes[0].selectSingleNode("blogDefineName").textContent + "/photolist\">相册</a></li>" + 
                                                                    "   <li><a href=\"" + nodes[0].selectSingleNode("blogDefineName").textContent + "/message\">留言</a></li>" + 
                                                                    "</ul>";
                    }
                    
                    if (ifself)
                        GetConfigXML();
                    else
                        initDivList();
                }
            }
        }
    }else{
        window.location = "/";
    }
}

function GetBlogName(){
    var s,p;
    var s1,p1;

    s = document.URL;
    
    p = s.lastIndexOf("/");

    if (p>0)
    {
        s = s.substr(p+1,s.length-p);
    }
      
    return s;
}

/**************************** PageOper ************************************/
    /**************** 定义全局变量 *******************/    
    var selectItem = null;      //选择事件
    var boxName = "faux";
    var times = 0;
    /**************** 定义全局变量 End *******************/    
    
	/**************** 初始化首页DIV列表 ******************/
	function initDivList()
	{
	    var xmlsv = document.getElementById("errorinfo");	
		xmlsv.style.display = "block";
		
	    var requestSimpleService = SaveXML.RequestXML(memparam, applytime, OnRequestResultComplete);
	}
	function OnRequestResultComplete(result)
	{
	    var htmlstr = "";
	    var requestSimpleService = null;
	    var doc = null;
	    if(document.all){ 
　　　　     doc=new ActiveXObject( "Microsoft.XMLDOM")
　　　　     doc.loadXML(result.toLowerCase());
        } 
        else 
            doc=new DOMParser().parseFromString(result.toLowerCase(), "text/xml")
	    
	    if (doc != null)
	    {    
	        //解析xml文件，判断是否出错 
	        if(document.all)
	        {
                if(doc.parseError.errorCode != 0) 
                { 
                    alert(doc.parseError.reason); 
                    return;
                } 
            }
         
            var nodes;
            var childnode;
            nodes = doc.documentElement.selectNodes("//root/themefile");
            
            if (nodes.length > 0)
                document.getElementById("themefile").href = nodes[0].getAttributeNode("href").value;
            
            nodes = doc.documentElement.selectNodes("//root/fauxfile");
            if (nodes.length > 0)
                document.getElementById("fauxfile").href = nodes[0].getAttributeNode("href").value;
            
	        //查找接点
            nodes = doc.documentElement.selectNodes("//root/cols");
            
            var divtag;
            var divtag_child;
            var divtag_child_child;
            var parenttag;
            if (document.all){
                for(var i=0; i<nodes.length; i++)
                {
                    parenttag = document.getElementById(nodes[i].selectSingleNode("id").text);
                    childnode = nodes[i].selectNodes("rows/list");
                    for(var j=0; j<childnode.length; j++){
                        divtag = document.createElement("div");
                        divtag.id = "root_row";
                        divtag.style.display = "block";
                        divtag.className = "move";        
                            divtag_child = document.createElement("div");
                            divtag_child.className = "title_index";
                                divtag_child_child = document.createElement("div");
                                divtag_child_child.className = "title_guest";
                                divtag_child_child.innerHTML = childnode[j].selectSingleNode("title").text;
                            divtag_child.appendChild(divtag_child_child);
                        divtag.appendChild(divtag_child);
                        
                            divtag_child = document.createElement("div");
                            divtag_child.className = "content";
                            divtag_child.id = childnode[j].selectSingleNode("id").text;
                        divtag.appendChild(divtag_child);
                        
                        parenttag.appendChild(divtag);
                        
                        document.getElementById(childnode[j].selectSingleNode("id").text).innerHTML = "加载中。。。";
                        
                        times += 500;
                        setTimeout("SaveXML.RequestDIVContent('" + childnode[j].selectSingleNode("id").text + "','" + memparam + "'," + OnRequestGetDivContentComplete + ")",times);
                    }
                }
            }else{
                for(var i=0; i<nodes.length; i++)
                {
                    parenttag = document.getElementById(nodes[i].selectSingleNode("id").textContent);
                    childnode = nodes[i].selectNodes("rows/list");
                    for(var j=0; j<childnode.length; j++){
                        divtag = document.createElement("div");
                        divtag.id = "root_row";
                        divtag.style.display = "block";
                        divtag.className = "move";        
                            divtag_child = document.createElement("div");
                            divtag_child.className = "title_index";
                                divtag_child_child = document.createElement("div");
                                divtag_child_child.className = "title_guest";
                                divtag_child_child.innerHTML = childnode[j].selectSingleNode("title").textContent;
                            divtag_child.appendChild(divtag_child_child);
                        divtag.appendChild(divtag_child);
                        
                            divtag_child = document.createElement("div");
                            divtag_child.className = "content";
                            divtag_child.id = childnode[j].selectSingleNode("id").textContent;
                        divtag.appendChild(divtag_child);
                        
                        parenttag.appendChild(divtag);
                        
                        document.getElementById(childnode[j].selectSingleNode("id").textContent).innerHTML = "加载中。。。";
                        times += 500;
                        setTimeout("SaveXML.RequestDIVContent('" + childnode[j].selectSingleNode("id").textContent + "','" + memparam + "'," + OnRequestGetDivContentComplete + ")",times);
                    }
                }
            }
	    }
	    
	    var xmlsv = document.getElementById("errorinfo");	
		xmlsv.style.display = "none";
	}
	function OnRequestGetDivContentComplete(result){
        document.getElementById(result[0]).innerHTML = result[1];
    }
	function OnRequestDIVComplete(result)
	{
	    var arr = result.split('|||');
	    if (arr != null)
	    {
	        if (document.getElementById(arr[0]) != null)
	        {
	            var parent = document.getElementById(arr[0]);
	            
	            parent.innerHTML = "";
	            
	            var titleDiv = document.createElement("div");
	            titleDiv.className = "title1";
	            
	            var refreshImg = document.createElement("img");
                refreshImg.setAttribute ("src","members/images/refresh.gif");
                refreshImg.setAttribute("alt","刷新");
                refreshImg.className = "imgalignright";
                refreshImg.onclick = function(){
                    RefreshSingleDIV(arr[0]);
                }
                //parent.insertBefore(refreshImg,document.getElementById(arr[0]).firstChild);
                titleDiv.appendChild(refreshImg);
                //titleDiv.innerHTML = titleDiv.innerHTML + arr[1];
                
                var titleSpan = document.createElement("span");
                titleSpan.innerHTML = arr[1];
                titleSpan.style.display = "block";
                titleSpan.style.width = "70%";
	            titleDiv.appendChild(titleSpan);
                
                parent.appendChild(titleDiv);
                
                var contentDiv = document.createElement("div");
	            contentDiv.innerHTML = arr[2];
	            parent.appendChild(contentDiv);  
	        }
	    }
	}
/************************** PageOperEnd ***********************************/

/************************** PageOperLogin *********************************/
// JScript 文件
var databasearr;
var Class = {
//创建类
	create : function () {
		return function () {
			this.initialize.apply(this, arguments);
		};
	}
};

var $A = function (a) {
//转换数组
	return a ? Array.apply(null, a) : new Array;
};

var $ = function (id) {
//获取对象
	return document.getElementById(id);
};

Object.extend = function (a, b) {
//追加方法
	for (var i in b) a[i] = b[i];
	return a;
};

Object.extend(Object, {
	addEvent : function (a, b, c, d) {
	//添加函数
		if (a.attachEvent) a.attachEvent(b[0], c);
		else a.addEventListener(b[1] || b[0].replace(/^on/, ""), c, d || false);
		return c;
	},
	
	delEvent : function (a, b, c, d) {
		if (a.detachEvent) a.detachEvent(b[0], c);
		else a.removeEventListener(b[1] || b[0].replace(/^on/, ""), c, d || false);
		return c;
	},
	
	reEvent : function () {
	//获取Event
		return window.event ? window.event : (function (o) {
			do {
				o = o.caller;
			} while (o && !/^\[object[ A-Za-z]*Event\]$/.test(o.arguments[0]));
			return o.arguments[0];
		})(this.reEvent);
	}
});

Function.prototype.bind = function () {
//绑定事件
	var wc = this, a = $A(arguments), o = a.shift();
	return function () {
		wc.apply(o, a.concat($A(arguments)));
	};
};

var CDrag = Class.create();

CDrag.IE = /MSIE/.test(window.navigator.userAgent);

CDrag.load = function (obj_string, func, time) {
//加载对象
	var index = 0, timer = window.setInterval(function () {
		//try {
			if (eval(obj_string + ".loaded")) {
				window.clearInterval(timer);
				func(eval("new " + obj_string));
			}
		//} catch (exp) {}

		if (++ index == 20) window.clearInterval(timer);
	}, time + index * 3);
};

CDrag.database = {
//数据存储
	json : null,
	
	parse : function (id) {
	//查找资源
		var wc = this, json = wc.json(), i;
		for (i in json) {
			if (json[i][0] == id)
				return json[i];
		}
	}
};

CDrag.Ajax = Class.create();

CDrag.Ajax.prototype = {

	initialize : function (url) {
	//初始化
		var wc = this;
		wc.ajax = CDrag.Ajax.getTransport();
	},
	
	load : function (func) {
		var wc = this, ajax = wc.ajax;
		if (ajax.readyState == 4 && ajax.status == 200)
			func(ajax.responseText);
	},
	
	send : function (url, func) {
		var wc = this, ajax = wc.ajax,
			querys = url + "&" + new Date().getTime() + (10000 + parseInt(Math.random() * 10000));
		ajax.open("get", querys, true);
		ajax.onreadystatechange = wc.load.bind(wc, func);
		ajax.send(null);
	}
	
};

CDrag.Table = Class.create();

CDrag.Table.prototype = {
//列的拖拽暂时不考虑

	initialize : function () {
	//初始化
		var wc = this;
		wc.items = []; //创建列组
	},
	
	add : function () {
	//添加列
		var wc = this, id = wc.items.length, arg = arguments;
		return wc.items[id] = new CDrag.Table.Cols(id, wc, arg[0]);
	}
};

CDrag.Table.Cols = Class.create();

CDrag.Table.Cols.prototype = {
	
	initialize : function (id, parent, element) {
	//初始化
		var wc = this;
		wc.items = []; //创建列组
		wc.id = id;
		wc.parent = parent;
		wc.element = element;
	},
	
	add : function () {
	//添加行
		var wc = this, id = wc.items.length, arg = arguments;
		return wc.items[id] = new CDrag.Table.Rows(id, wc, arg[0], arg[1], arg[2]);
	},
	
	ins : function (num, row) {
	//插入行
		var wc = this, items = wc.items, i;
		
		if (row.parent == wc && row.id < num) num --; //同列向下移动的时候
		for (i = num ; i < items.length ; i ++) items[i].id ++;
		
		items.splice(num, 0, row);
		row.id = num, row.parent = wc;
		
		return row;
	},
	
	del : function (num) {
	//删除行
		var wc = this, items = wc.items, i;	
		if (num >= items.length) return;
		for (i = num + 1; i < items.length ; i ++) items[i].id = i - 1;
		return items.splice(num, 1)[0];
	}
	
};

CDrag.Table.Rows = Class.create();

CDrag.Table.Rows.prototype = {
	
	
	initialize : function (id, parent, element, window, locks) {
	//初始化
		var wc = this, temp;
		wc.id = id;
		wc.parent = parent;
		wc.root_id = element;
		wc.window = window;
		wc.element = wc.element_init();
		temp = wc.element.childNodes[0];	
		wc.title = temp.childNodes[4];
		wc.reduce = temp.childNodes[3];
		wc.lock = temp.childNodes[2], wc.locks = locks;
		wc.edit = temp.childNodes[1];
		wc.close = temp.childNodes[0];
		wc.content = wc.element.childNodes[1];
		
		wc.Class = wc.mousedown = wc.reduceFunc = wc.lockFunc = wc.editFunc = wc.closeFunc = null;
		
		wc.init();
		wc.load();
	},
	
	element_init : function () {
	//初始化元素
		var wc = this, div = $("root_row").cloneNode(true);
		
		wc.parent.element.appendChild(div);
		div.style.display = "block";
		return div;
	},
	
	init : function () {
	//初始化信息
		var wc = this;
		if (wc.window == 0) {
			wc.content.style.display = "none";
			wc.reduce.innerHTML = "放大";
		} else {
			wc.content.style.display = "block";
			wc.reduce.innerHTML = "缩小";
		}
		
		wc.lock.innerHTML = !wc.locks ? "" : "";
	},
	
	load : function () {
	//获取相关信息
		var wc = this, info = CDrag.database.parse(wc.root_id), script;
		if (info != null){	
			wc.title.innerHTML = info[1];		//info.title
			
			wc.content.innerHTML = "loading...";
			wc.RequestDIVContent(wc.id,info[0],info[4],memparam);
		}
	},
	
	upload : function (obj) {
	/*加载类信息
		注：这里给行加入了一个扩展类，这里行的内容可以通过扩展类来控制^o^
		不过扩展类的格式必须有open方法和edit方法，还有类名.静态成员loaded = true；为了检测是否加载完毕
		扩展类需放到单独的.js文件里，然后从database结构体内设定其参数即可
	*/
		var wc = this;
		wc.Class = obj;
		wc.Class.parent = wc;
		wc.editFunc = Object.addEvent(wc.edit, ["onclick"], wc.lockF(wc.Class, wc.Class.edit, wc));
		wc.Class.open();
	},
	
	lockF : function () {
	//检索锁定
		var wc = this, arg = $A(arguments), root = arg.shift(), func = arg.shift();
		return function () {
			if (!wc.locks) func.apply(root, arg.concat($A(arguments)));
		};
	},
	
	//arguments
    RequestDIVContent : function () {
        var wc = this;
        times += 500;
        setTimeout("SaveXML.GetDivContent('" + arguments[0] + "','" + arguments[1] + "','" + arguments[2] + "','" + arguments[3] + "'," + OnRequestGetDivContentCompleteInit + ")",times);
    }
};

CDrag.Add = Class.create();

CDrag.Add.prototype = {
	
	initialize : function (parent) {
	//初始化参数
		var wc = this;
		wc.div = document.createElement("div"); //最外层div
		wc.iframe = document.createElement("iframe"); //协助wc.div盖select的iframe
		wc.node = document.createElement("div"); //内容底层div
		wc.content = document.createElement("div"); //内容层div
		wc.button = document.createElement("button"); //内容处理按钮
		wc.parent = parent;
		wc.json = null;
		
		wc.button.onclick = wc.closeWin.bind(wc,wc.content); //向按钮指向方法
		wc.init_element();
	},
	closeWin : function(div){
	//关闭窗口		
		var wc = this;
		div.innerHTML = "";
		wc.close();
	},	
	init_element : function () {
	//初始化元素
		var wc = this;
		wc.div.setAttribute(CDrag.IE ? "className" : "class", "Dall_screen");
		wc.iframe.setAttribute(CDrag.IE ? "className" : "class", "Iall_screen");
		wc.node.setAttribute(CDrag.IE ? "className" : "class", "Nall_screen");
		wc.content.setAttribute(CDrag.IE ? "className" : "class", "Call_screen");
		wc.button.innerHTML = "修改";
		wc.node.appendChild(wc.content);
		wc.node.appendChild(wc.button);
		
	},
	
	init_json : function () {
	//初始化原始数据信息串
		var wc = this, parent = wc.parent,
			cols = parent.table.items, new_json = {}, init_json = CDrag.database.json(), r, i, j;
			
		for (i = 0 ; i < init_json.length ; i ++) //便利原始数据
			new_json[init_json[i][0]] = { id : init_json[i][0], row : null, title : init_json[i][1] };
			
		for (i = 0 ; i < cols.length ; i ++) //便利修改生成的串的属性
			for (r = cols[i].items, j = 0 ; j < r.length ; j ++)
				new_json[r[j].root_id].row = r[j];
		
		return new_json;
	},
	
	init_node : function () {
		//初始化内容层div的数据
	},
	
	execute : function (div) {
	//处理table类结构
		var wc = this, parent = wc.parent, json = wc.json, items = div.getElementsByTagName("input"), row, c, i;
		
		//try {
			for (i = 0 ; i < items.length ; i ++) {
				if (items[i].type != "checkbox") continue;
				row = json[items[i].value];
				
				if ((!!row.row) != items[i].checked) {
					if (row.row) parent.remove(row.row); //删除
					else parent.add(parent.table.items[0].add(row.id, 1, false)); //向第一行追加数据
					c = true;
				}
			}
			//div.innerHTML = "";
			if (c) parent.set_cookie();
			
		//} catch (exp) {}
		//wc.close();
		
	},
	
	add : function () {
	//添加数据
		var wc = this, div = wc.div, iframe = wc.iframe;
		wc.init_node();
		div.style.height = iframe.style.height = Math.max(document.documentElement.scrollHeight, document.documentElement.offsetHeight) + "px";
		div.style.width = iframe.style.width = Math.max(document.documentElement.scrollWidth, document.documentElement.offsetWidth) + "px";
		document.getElementsByTagName("html")[0].style.overflow = "hidden";
		document.body.appendChild(iframe);
		document.body.appendChild(div);
		document.body.appendChild(wc.node);
		
		$("imgclosewin").onclick = wc.closeWin.bind(wc,wc.content);
	},
	
	close : function () {
	//关闭添加框
		var wc = this, div = wc.div, iframe = wc.iframe;
		document.getElementsByTagName("html")[0].style.overflow = CDrag.IE ? "" : "auto";
		document.body.removeChild(iframe);
		document.body.removeChild(div);
		document.body.removeChild(wc.node);
	}
	
};

CDrag.prototype = {
	
	initialize : function () {
	//初始化成员
		var wc = this;
		wc.table = new CDrag.Table; //建立表格对象
		wc.addc = new CDrag.Add(wc); //建立添加对象
		wc.iFunc = wc.eFunc = null;
		wc.obj = { on : { a : null, b : "" }, row : null, left : 0, top : 0 };
		wc.temp = { row : null, div : document.createElement("div") };
		wc.temp.div.setAttribute(CDrag.IE ? "className" : "class", "CDrag_temp_div");
		wc.temp.div.innerHTML = "&nbsp;";
	},
	
	reMouse : function (a) {
	//获取鼠标位置
		var e = Object.reEvent();
		return {
			x : document.documentElement.scrollLeft + e.clientX,
			y : document.documentElement.scrollTop + e.clientY
		};
	},
	
	rePosition : function (o) {
	//获取元素绝对位置
		var $x = $y = 0;
		do {
			$x += o.offsetLeft;
			$y += o.offsetTop;
		} while ((o = o.offsetParent)); // && o.tagName != "BODY"
		return { x : $x, y : $y };
	},
	
	execMove : function (status, on_obj, in_obj, place) {
	//处理拖拽过程细节
		var wc = this, obj = wc.obj.on, temp = wc.temp, px;
		
		obj.a = on_obj, obj.b = status;
		
		if (place == 0) {
		//向上
			px = in_obj.element.clientWidth;
			in_obj.element.parentNode.insertBefore(temp.div, in_obj.element);
		} else if (place == 1) {
		//新加入
			px = in_obj.element.clientWidth - 2;
			in_obj.element.appendChild(temp.div);
		} else {
		//向下
			px = in_obj.element.clientWidth;
			in_obj.element.parentNode.appendChild(temp.div);
		}
		
		wc.obj.left = Math.ceil(px / temp.div.offsetWidth * wc.obj.left); //处理拖拽换行后宽度变化，鼠标距离拖拽物的距离的误差.
		temp.row.style.width = temp.div.style.width = px + "px"; //处理换列后对象宽度变化
	},
	
	sMove : function (o) {
	//当拖动开始时设置参数
		
		var wc = this;
		if (o.locks || wc.iFunc || wc.eFinc) return;
		
		var mouse = wc.reMouse(), obj = wc.obj, temp = wc.temp, div = o.element, position = wc.rePosition(div);
		
		obj.row = o;
		obj.on.b = "me";
		obj.left = mouse.x - position.x;
		obj.top = mouse.y - position.y;
		
		temp.row = document.body.appendChild(div.cloneNode(true)); //复制预拖拽对象
		temp.row.style.width = div.clientWidth + "px";
		
		with (temp.row.style) {
		//设置复制对象
			position = "absolute";
			left = mouse.x - obj.left + "px";
			top = mouse.y - obj.top + "px";
			zIndex = 100;
			opacity = "0.3";
			filter = "alpha(opacity:30)";
		}
		
		with (temp.div.style) {
		//设置站位对象
			height = div.clientHeight + "px";
			width = div.clientWidth + "px";
		}
		
		div.parentNode.replaceChild(temp.div, div);
		
		wc.iFunc = Object.addEvent(document, ["onmousemove"], wc.iMove.bind(wc));
		wc.eFunc = Object.addEvent(document, ["onmouseup"], wc.eMove.bind(wc));
		document.onselectstart = new Function("return false");
	},
	
	iMove : function () {
	//当鼠标移动时设置参数
		var wc = this, mouse = wc.reMouse(), cols = wc.table.items, obj = wc.obj, temp = wc.temp,
			row = obj.row, div = temp.row, t_position, t_cols, t_rows, i, j;
		
		with (div.style) {
			left = mouse.x - obj.left + "px";
			top = mouse.y - obj.top + "px";
		}
		
		for (i = 0 ; i < cols.length ; i ++) {
			t_cols = cols[i];
			//if (t_cols != obj.row.parent) continue;
			t_position = wc.rePosition(t_cols.element);
			if (t_position.x < mouse.x && t_position.x + t_cols.element.offsetWidth > mouse.x) {
				if (t_cols.items.length > 0) { //如果此列行数大于0
					if (t_cols.items[0] != obj.row && wc.rePosition(t_cols.items[0].element).y + 20 > mouse.y) {
						//如果第一行不为拖拽对象并且鼠标位置大于第一行的位置即是最上。。
						//向上
						wc.execMove("up", t_cols.items[0], t_cols.items[0], 0);
					} else if (t_cols.items.length > 1 && t_cols.items[0] == row &&
						wc.rePosition(t_cols.items[1].element).y + 20 > mouse.y) {
						//如果第一行是拖拽对象而第鼠标大于第二行位置则，没有动。。
						//向上
						wc.execMove("me", t_cols.items[1], t_cols.items[1], 0);
					} else {
						for (j = t_cols.items.length - 1 ; j > -1 ; j --) {
							//重最下行向上查询
							t_rows = t_cols.items[j];
							if (t_rows == obj.row) {
								if (t_cols.items.length == 1) {
								//如果拖拽的是此列最后一行
									wc.execMove("me", t_cols, t_cols, 1);
								}
								continue;
							}
							if (wc.rePosition(t_rows.element).y < mouse.y) {
								//如果鼠标大于这行则在这行下面
								if (t_rows.id + 1 < t_cols.items.length && t_cols.items[t_rows.id + 1] != obj.row) {
									//如果这行有下一行则重这行下一行的上面插入
									wc.execMove("down", t_rows, t_cols.items[t_rows.id + 1], 0);
								} else if (t_rows.id + 2 < t_cols.items.length) {
									//如果这行下一行是拖拽对象则插入到下两行，即拖拽对象返回原位
									wc.execMove("me", null, t_cols.items[t_rows.id + 2], 0);
								} else {
									//前面都没有满足则放在最低行
									wc.execMove("down", t_rows, t_rows, 2);
								}
								return;
							}
						}
					}
				} else {
				//此列无内容添加新行
					wc.execMove("new", t_cols, t_cols, 1);
				}
			}
		}
	},
	
	eMove : function () {
	//当鼠标释放时设置参数
		var wc = this, obj = wc.obj, temp = wc.temp, row = obj.row, div = row.element, o_cols, n_cols, number;
		
		if (obj.on.b != "me") {
			number = (obj.on.b == "down" ? obj.on.a.id + 1 : 0);
			n_cols = (obj.on.b != "new" ? obj.on.a.parent : obj.on.a);
			o_cols = obj.row.parent;
			n_cols.ins(number, o_cols.del(obj.row.id));
			
			wc.set_cookie();
		}
		
		temp.div.parentNode.replaceChild(div, temp.div);
		temp.row.parentNode.removeChild(temp.row);
		delete temp.row;
		
		Object.delEvent(document, ["onmousemove"], wc.iFunc);
		Object.delEvent(document, ["onmouseup"], wc.eFunc);
		document.onselectstart = wc.iFunc = wc.eFunc = null;
		
		wc.save_info();
	},
	
	reduce : function (o) {
	//变大变小
		var wc = this;
		if ((o.window = (o.window == 1 ? 0 : 1))) {
			o.content.style.display = "block";
			o.reduce.innerHTML = "缩小";
		} else {
			o.content.style.display = "none";
			o.reduce.innerHTML = "放大";
		}
		wc.set_cookie();
	},
	
	lock : function (o) {
	//锁定
		var wc = this;
		if (o.locks) {
			o.locks = false;
			o.lock.innerHTML = "";
		} else {
			o.locks = true;
			o.lock.innerHTML = "";
		}
		wc.set_cookie();
	},
	
	close : function (o) {
	//关闭对象
		var wc = this;
		wc.remove(o);
		wc.set_cookie();
	},
	
	remove : function (o) {
	//移除对象
		var wc = this, parent = o.parent;
		
		Object.delEvent(o.close, ["onclick"], o.closeFunc);
		if (o.editFunc) Object.delEvent(o.edit, ["onclick"], o.editFunc);
		Object.delEvent(o.lock, ["onclick"], o.lockFunc);
		Object.delEvent(o.reduce, ["onclick"], o.reduceFunc);
		Object.delEvent(o.title, ["onmousedown"], o.mousedown);
		
		o.mousedown = o.reduceFunc = o.lockFunc = o.editFunc = o.closeFunc = null;
		
		parent.element.removeChild(o.element);
		parent.del(o.id);
		delete wc.Class;
		delete o;
		
		wc.save_info();
	},
	
	create_json : function () {
	//生成json串
		var wc = this, cols = wc.table.items, a = [], b = [], i, j, r;
		for (i = 0 ; i < cols.length ; i ++) {
			for (r = cols[i].items, j = 0 ; j < r.length ; j ++)
				b[b.length] = "{id:'" + r[j].root_id + "',window:" + r[j].window + ",locks:" + r[j].locks + "}";
			a[a.length] = "cols:'" + cols[i].element.id + "',rows:[" + b.splice(0, b.length).join(",") + "]";
		}
		return escape("[{" + a.join("},{") + "}]");
	},
	
	save_info : function(){
		var wc = this;
		var cols = wc.table.items;
		var htmlstr = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
		htmlstr += "<root>\n";
		htmlstr += "<themefile href=\"" + document.getElementById("themefile").href + "\"></themefile>\n"
		htmlstr += "<fauxfile href=\"" + document.getElementById("fauxfile").href + "\"></fauxfile>\n"
		var nodestr = "";
		for (i = 0 ; i < cols.length ; i ++) {
			nodestr = "<rows>\n";
			for (r = cols[i].items, j = 0 ; j < r.length ; j ++){
				nodestr += "<list>\n<id>" + r[j].root_id + "</id>\n<window>" + r[j].window + "</window><locks>" + r[j].locks + "</locks><title>" + r[j].title.innerHTML + "</title>\n</list>\n";	
			}
			nodestr += "</rows>\n";
			htmlstr += "<cols>\n<id>" + cols[i].element.id + "</id>\n" + nodestr + "</cols>";
		}	
		htmlstr += "</root>";
		
		$("errorinfo").style.display = "block";
		
		var requestSimpleService = SaveXML.Save(htmlstr,memparam, OnRequestSaveComplete);
	},
	
	parse_json : function (cookie) {
	//解释json成对象
		return eval("(" + cookie + ")");
	},
	
	get_cookie : function () {
	//获取COOKIE
		return (/CDrag=([^;]+)(?:;|$)/.exec(document.cookie) || [,])[1];
	},
	
	set_cookie : function () {
	//设置COOKIE
		var wc = this, date = new Date;
		date.setDate(date.getDate() + 1);
		document.cookie = "CDrag=" + wc.create_json() + ";expires=" + date.toGMTString();
	},
	
	del_cookie : function () {
	//删除COOKIE
		var wc = this, cookie = wc.get_cookie(), date;
		if (cookie) {
			date = new Date;
			date.setTime(date.getTime() - 1);
			document.cookie = "CDrag=" + cookie + ";expires=" + date.toGMTString();
		}
	},
	
	parse : function (o) {
	//初始化成员
		//try {
			var wc = this, table = wc.table, cols, rows, div, i, j;
			for (i = 0 ; i < o.length ; i ++) {
				
				//o[i].cols o[i][0]
				div = $(o[i][0]), cols = table.add(div);
				//o[i].rows.length  o[i][1]
				//o[i].rows[j].id	o[i][1][j][0]
				//o[i].rows[j].window	o[i][1][j][1]
				//o[i].rows[j].locks	o[i][1][j][2]
				for (j = 0 ; j < o[i][1].length ; j ++){
					wc.add(cols.add(o[i][1][j][0], o[i][1][j][1], o[i][1][j][2]));
				}
			}
		//} catch (exp) {
		//	wc.del_cookie();
		//}
	},
	
	add : function (o) {
	//添加对象
		var wc = this;
		o.mousedown = Object.addEvent(o.title, ["onmousedown"], o.lockF(wc, wc.sMove, o));
		o.reduceFunc = Object.addEvent(o.reduce, ["onclick"], o.lockF(wc, wc.reduce, o));
		o.lockFunc = Object.addEvent(o.lock, ["onclick"], wc.lock.bind(wc, o));
		o.closeFunc = Object.addEvent(o.close, ["onclick"], o.lockF(wc, wc.close, o));
	},
	
	append : function () {
		var wc = this;
		wc.addc.add();
	}
};

CDrag.database.json = function(){
	return databasearr;
};

function OnRequestSaveComplete(result){
    $("errorinfo").style.display = "none";
}

function OnRequestGetDivContentCompleteInit(result){
    var id = parseInt(result[0]);
    getElementsByClassName(document.getElementById(result[2]),"div","content")[id].innerHTML = result[3];
    				
    //document.getElementById(result[0]).innerHTML = result[1];
}

//arguments
function GetConfigXML(){
    if (arguments.length == 0){
        var requestSimpleService = SaveXML.RequestXML(memparam, applytime, GetConfigXML);
    }else{
        var doc = null;
        doc = XmlDom2(arguments[0]);
        
        if (doc != null){
            /***** theme ****/
            var nodes;
            nodes = doc.documentElement.selectNodes("//root/themefile");
            
            if (nodes.length > 0)
            {
                document.getElementById("themefile").href = nodes[0].getAttributeNode("href").value;
                
                var themefile = nodes[0].getAttributeNode("href").value;
                themefile_fix = themefile.substring(themefile.lastIndexOf("/") + 1,themefile.length);
            }
            
            nodes = doc.documentElement.selectNodes("//root/fauxfile");
            if (nodes.length > 0)
            {
                document.getElementById("fauxfile").href = nodes[0].getAttributeNode("href").value;
                
                var fauxfile = nodes[0].getAttributeNode("href").value;
                fauxfile_fix = fauxfile.substring(fauxfile.lastIndexOf("/") + 1,fauxfile.length);
            }
            /***** theme ****/
            
            nodes = doc.documentElement.selectNodes("//root/cols");
            var childnodes;
            databasearr = new Array();
            var n = 0;
            for(var i=0; i<nodes.length; i++){
                childnodes = nodes[i].selectNodes("rows/list");
                if (document.all){
	                for(var j=0; j<childnodes.length; j++){
	                    databasearr[n++] = new Array(childnodes[j].selectSingleNode("id").text,childnodes[j].selectSingleNode("title").text,"",true,nodes[i].selectSingleNode("id").text);
	                }
                }else{
                    for(var j=0; j<childnodes.length; j++){
                        databasearr[n++] = new Array(childnodes[j].selectSingleNode("id").textContent,childnodes[j].selectSingleNode("title").textContent,"",true,nodes[i].selectSingleNode("id").textContent);
                    }
                }
            }
	           
	        var wc = new CDrag, cookie = wc.get_cookie();
	            
	            var locks = false;
	            json = new Array();
	            if (document.all){
	                for(var i=0; i<nodes.length; i++){
	                    json[i] = new Array();
	                    json[i][0] = nodes[i].selectSingleNode("id").text;
	                    json[i][1] = new Array();
	                    childnodes = nodes[i].selectNodes("rows/list");
	                    for(var j=0; j<childnodes.length; j++){
	                        locks = childnodes[j].selectSingleNode("locks").text;
	                        if (locks == "true")
	                            locks = true;
	                        else
	                            locks = false;
	                            
	                        json[i][1][j] = new Array(childnodes[j].selectSingleNode("id").text, parseInt(childnodes[j].selectSingleNode("window").text), locks);
	                    }
	                }
	            }else{
	                for(var i=0; i<nodes.length; i++){
	                    json[i] = new Array();
	                    json[i][0] = nodes[i].selectSingleNode("id").textContent;
	                    json[i][1] = new Array();
	                    childnodes = nodes[i].selectNodes("rows/list");
	                    for(var j=0; j<childnodes.length; j++){
	                        locks = childnodes[j].selectSingleNode("locks").textContent;
	                        if (locks == "true")
	                            locks = true;
	                        else
	                            locks = false;
	                            
	                        json[i][1][j] = new Array(childnodes[j].selectSingleNode("id").textContent, parseInt(childnodes[j].selectSingleNode("window").textContent), locks);
	                    }
	                }
	            }
	            
	            /*
		        json2 = new Array(
			        new Array("m_1",new Array(new Array("m_1_1",1,false),new Array("m_1_2",1,false),new Array("m_1_3",1,false))),
			        new Array("m_2",new Array(new Array("m_2_1",1,false),new Array("m_2_2",1,false),new Array("m_2_3",1,false))),
			        new Array("m_3",new Array(new Array("m_3_1",1,false),new Array("m_3_2",1,false),new Array("m_3_3",1,false),new Array("m_3_4",1,false)))
		        );
		        */
        	
	        wc.parse(json);
        	
	        (function (wc) {

	        })(wc);

	        wc = null;
        }
        
        //setTimeout("document.getElementById('tempdiv').style.display='none';",10000);
    }
}

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);	
    var arrReturnElements = new Array();	
    strClassName = strClassName.replace(/-/g, "\-");	
    var oRegExp = new RegExp("(^|\s)" + strClassName + "(\s|$)");	
    var oElement;	
    for(var i=0; i<arrElements.length; i++){		
        oElement = arrElements[i];		
        if(oRegExp.test(oElement.className)){			
            arrReturnElements.push(oElement);		
        }	
    }	
    return (arrReturnElements)
}

GB_myShow = function(caption, url, /* optional */ height, width, callback_fn) {
    var options = {
        caption: caption,
        height: height || 500,
        width: width || 280,
        fullscreen: false,
        show_loading: false,
        callback_fn: callback_fn
    }
    var win = new GB_Window(options);
    return win.show(url);
}
/************************* PageOperLoginEnd ******************************/

function getMyBlogName(){
	return (/blogDefineName=([^&amp;]+)/.exec(document.cookie) || [,])[1];
}

window.onload = function (){
    var blogdefiname = GetBlogName();
    if (blogdefiname == null || blogdefiname == "")
        window.location = "/";
        
    CheckUserLogin(blogdefiname);
}