function killErrors() {
return true;
}
//window.onerror = killErrors;
var Util = new Object();
Util.getUserAgent = navigator.userAgent;
Util.isGecko = Util.getUserAgent.indexOf("Gecko") != -1;
Util.isOpera = Util.getUserAgent.indexOf("Opera") != -1;
Util.getOffset = function (el, isLeft) {
    var retValue = 0;
    while (el != null) {
        retValue += el["offset" + (isLeft ? "Left" : "Top")];
        el = el.offsetParent;
    }
    return retValue;
};
Util.bindFunction = function (el, fucName) {
    return function () {
        return el[fucName].apply(el, arguments);
    };
};
Util.re_calcOff = function (el) {
    for (var i = 0; i < Util.dragArray.length; i++) {
        var ele = Util.dragArray[i];
        ele.elm.pagePosLeft = Util.getOffset(ele.elm, true);
        ele.elm.pagePosTop = Util.getOffset(ele.elm, false);
    }
    var nextSib = el.elm.nextSibling;
    while (nextSib) {
        nextSib.pagePosTop -= el.elm.offsetHeight;
        nextSib = nextSib.nextSibling;
    }
};

Util.hide = function () {
    Util.rootElement.style.display = "none";
};
Util.show = function () {
    Util.rootElement.style.display = "";
};

ghostElement = null;
getGhostElement = function () {
    if (!ghostElement) {
        ghostElement = document.createElement("DIV");
        ghostElement.className = "modbox";
        ghostElement.backgroundColor = "";
        ghostElement.style.border = "2px dashed #aaa";
        ghostElement.innerHTML = "&nbsp;";
    }
    return ghostElement;
};

function draggable(el) {
    this._dragStart = start_Drag;
    this._drag = when_Drag;
    this._dragEnd = end_Drag;
    this._afterDrag = after_Drag;
    this.isDragging = false;
    this.elm = el;
    this.header = document.getElementById(el.id + "_h");
    this.hasIFrame = this.elm.getElementsByTagName("IFRAME").length > 0;
    if (this.header) {
        this.header.style.cursor = "move";
        Drag.init(this.header, this.elm);
        this.elm.onDragStart = Util.bindFunction(this, "_dragStart");
        this.elm.onDrag = Util.bindFunction(this, "_drag");
        this.elm.onDragEnd = Util.bindFunction(this, "_dragEnd");
    }
};

function start_Drag() {
    Util.re_calcOff(this);
    this.origNextSibling = this.elm.nextSibling;
    var _ghostElement = getGhostElement();
    var offH = this.elm.offsetHeight;
    if (Util.isGecko) {
        offH -= parseInt(_ghostElement.style.borderTopWidth) * 2;
    }
    var offW = this.elm.offsetWidth;
    var offLeft = Util.getOffset(this.elm, true);
    var offTop = Util.getOffset(this.elm, false);
    Util.hide();
    this.elm.style.width = offW + "px";
    _ghostElement.style.height = offH + "px";
    this.elm.parentNode.insertBefore(_ghostElement, this.elm.nextSibling);
    this.elm.style.position = "absolute";
    this.elm.style.zIndex = 100;
    this.elm.style.left = offLeft + "px";
    this.elm.style.top = offTop + "px";
    Util.show();
    this.isDragging = false;
    return false;
};
function when_Drag(clientX, clientY) {
    if (!this.isDragging) {
        this.elm.style.filter = "alpha(opacity=70)";
        this.elm.style.opacity = 0.7;
        this.isDragging = true;
    }
    var found = null;
    var max_distance = 100000000;
    for (var i = 0; i < Util.dragArray.length; i++) {
        var ele = Util.dragArray[i];
        var distance = Math.sqrt(Math.pow(clientX - ele.elm.pagePosLeft, 2) + Math.pow(clientY - ele.elm.pagePosTop, 2));
        if (ele == this) {
            continue;
        }
        if (isNaN(distance)) {
            continue;
        }
        if (distance < max_distance) {
            max_distance = distance;
            found = ele;
        }
    }
    var _ghostElement = getGhostElement();
    if (found != null && _ghostElement.nextSibling != found.elm) {
        found.elm.parentNode.insertBefore(_ghostElement, found.elm);
        if (Util.isOpera) {
            document.body.style.display = "none";
            document.body.style.display = "";
        }
    }
};
function end_Drag() {//移动后的操作。。。
    if (this._afterDrag()) {
    	save_Drag();
   			 }
    return true;
};
function dump_props(obj, objName) {//调试使用。。。
   var result = "";
   for (var i in obj) {
      result += objName + "." + i + " = " + obj[i] + "\r\n";
   }
   result += "\r\n";
   document.write("<textarea cols=120 rows=50>"+result+"</textarea>");
   return result;
} 

function save_Drag(){//拖动后的保存代码
try{
	    var alldiv=document.getElementsByTagName("div");
   		var result=new String();
    	 for (var i = 0; i < alldiv.length; i++) {
   			 var child = alldiv[i];
   			 var classNames = child.className;
   			 var id=child.id;
   			 var parent=child.parentNode;
   			 if(classNames=="modbox"&&child.style.display!="none"){//class为modbox的才保存,即登陆用户
   			 	result+=parent.id+"[]=" +id.replace("m_","")+"&";
   			 }
   		}
   		if(result.length>0)
  		send_index(result);
   		return ;
}catch(error)
	{
		alert(error);
	}
}
/*
function send_index(result)
{
var xmlHttp = false;
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest();
}
xmlHttp.open("POST","saveindex.php?" + result,true);
xmlHttp.send(null);
return ;
}*/

function after_Drag() {
    var returnValue = false;
    Util.hide();
    this.elm.style.position = "";
    this.elm.style.width = "";
    this.elm.style.zIndex = "";
    this.elm.style.filter = "";
    this.elm.style.opacity = "";
    var ele = getGhostElement();
    if (ele.nextSibling != this.origNextSibling) {
        ele.parentNode.insertBefore(this.elm, ele.nextSibling);
        returnValue = true;
    }
    ele.parentNode.removeChild(ele);
    Util.show();
    if (Util.isOpera) {
        document.body.style.display = "none";
        document.body.style.display = "";
    }
    return returnValue;
};
var Drag = {
	obj:null, 
	init:function (elementHeader, element) {
    	elementHeader.onmousedown = Drag.start;
	    elementHeader.obj = element;
	    if (isNaN(parseInt(element.style.left))) {
	        element.style.left = "0px";
	    }
	    if (isNaN(parseInt(element.style.top))) {
	        element.style.top = "0px";
	    }
	    element.onDragStart = new Function();
	    element.onDragEnd = new Function();
	    element.onDrag = new Function();
	},
	start:function (event) {
	    var element = Drag.obj = this.obj;
	    event = Drag.fixE(event);
	    if (event.which != 1) {
	        return true;
    	}
	    element.onDragStart();
	    element.lastMouseX = event.clientX;
	    element.lastMouseY = event.clientY;
	    document.onmouseup = Drag.end;
	    document.onmousemove = Drag.drag;
	    return false;
	}, 
	drag:function (event) {
	    event = Drag.fixE(event);
	    if (event.which == 0) {
	        return Drag.end();
    	}
	    var element = Drag.obj;
	    var _clientX = event.clientY;
	    var _clientY = event.clientX;
	    if (element.lastMouseX == _clientY && element.lastMouseY == _clientX) {
	        return false;
	    }
	    var _lastX = parseInt(element.style.top);
	    var _lastY = parseInt(element.style.left);
	    var newX, newY;
	    newX = _lastY + _clientY - element.lastMouseX;
	    newY = _lastX + _clientX - element.lastMouseY;
	    element.style.left = newX + "px";
	    element.style.top = newY + "px";
	    element.lastMouseX = _clientY;
	    element.lastMouseY = _clientX;
	    element.onDrag(newX, newY);
	    return false;
	},
	end:function (event) {
	    event = Drag.fixE(event);
	    document.onmousemove = null;
	    document.onmouseup = null;
	    var _onDragEndFuc = Drag.obj.onDragEnd();
	    Drag.obj = null;
	    return _onDragEndFuc;
	}, 
	fixE:function (ig_) {
	    if (typeof ig_ == "undefined") {
	        ig_ = window.event;
	    }
	    if (typeof ig_.layerX == "undefined") {
	        ig_.layerX = ig_.offsetX;
	    }
	    if (typeof ig_.layerY == "undefined") {
	        ig_.layerY = ig_.offsetY;
	    }
	    if (typeof ig_.which == "undefined") {
	        ig_.which = ig_.button;
	    }
    	return ig_;
	}
};
var _IG_initDrag = function (el) {
    Util.rootElement = el;
    Util._rows = Util.rootElement.tBodies[0].rows[0];
    Util.column = Util._rows.cells;
    Util.dragArray = new Array();
    var counter = 0;
    for (var i = 0; i < Util.column.length; i++) {
        var ele = Util.column[i];
        for (var j = 0; j < ele.childNodes.length; j++) {
            var ele1 = ele.childNodes[j];
            if (ele1.tagName == "DIV") {
                Util.dragArray[counter] = new draggable(ele1);
                counter++;
            }
        }
    }
};
 var  isIE  =   !! document.all;
function  parseXML(st){
try{
      var  parser  =   new  DOMParser();
      var  result  =  parser.parseFromString(st,"application/xml" );
   }catch(err)
    {
  	}
return  result;
}
function getValue(node,i)
{
	try{
	if(isIE)
		return node.item(i).text;
	else
		return node[i].textContent;
	}catch(err1)
		{
			return null;
		}
}
//加载rss的函数
/*var xmlHttp = false;
var rssid=Array();
function get_webxml(rsscount)
{
var url,id;
url=rssid[rsscount];
if(typeof(url)=="undefined")
	return ;
window.status="正在加载网络资源:"+url;
id=rsscount+1;
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest();
}
var temp=escape(url);
xmlHttp.open("GET","rss.php?url="+temp,true);
xmlHttp.onreadystatechange=function()
{
	if(changerxml(xmlHttp,id,url))
	{
		get_webxml(rsscount+1);
		window.status="完毕";
	}
}
xmlHttp.send(null);
}
changerxml=function(http,id,url)
{
var http,id,url;
if (http.readyState == 4) {
if(http.status==200){
var obj_xml=http.responseXML;
var rsstitle=document.getElementById("rss_"+id+"_title");
var rsscontent=document.getElementById("rss_"+id+"_content");
if(!isIE)
obj_xml=parseXML(http.responseText);
var temp=obj_xml.selectNodes("//rss/channel/title");
var link=obj_xml.selectNodes("//rss/channel/link");
var image=obj_xml.selectNodes("//rss/channel/image/url");
var content=new String();
rsstitle.innerHTML="RSS><a href="+getValue(link,0)+" target=_blank>"+getValue(temp,0)+"</a>";
var title_c,link_c,description,content;
var des=new String();
rsscontent.innerHTML="";
for(var i=0;i<6;i++)
{
title_c=obj_xml.selectNodes("//rss/channel/item/title");
link_c=obj_xml.selectNodes("//rss/channel/item/link");
description=obj_xml.selectNodes("//rss/channel/item/description");
if(link_c.length<i+1){
	break;
}
des=getValue(description,i);
des=des.replace(/'/g,"&#8216;");
content+="<a href="+getValue(link_c,i)+" target=_blank class=back title='"+des+"'>"+getValue(title_c,i)+"</a><br>";
}
rsscontent.innerHTML=content;
if(link_c.length==1)
rsscontent.innerHTML+=getValue(description,0);
if(image.length!=0)
rsscontent.innerHTML="<img src="+getValue(image,0)+" border=0><br>"+rsscontent.innerHTML;
return 1;
}}
return 0;
}
*/

//firefox...selectNodes
if (document.implementation.hasFeature("XPath","3.0"))
{
  // prototying the XMLDocument
  XMLDocument.prototype.selectNodes=function(cXPathString,xNode)
  {
    if (!xNode)
    {
        xNode=this;
    }
    var oNSResolver=this.createNSResolver(this.documentElement);
    var aItems=this.evaluate(cXPathString,xNode,oNSResolver,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
    var aResult=[];
    for (var i=0;i<aItems.snapshotLength;i++)
    {
        aResult[i]=aItems.snapshotItem(i);
    }
    return aResult;
  }
  
  // prototying the Element
  Element.prototype.selectNodes=function(cXPathString)
  {
    if (this.ownerDocument.selectNodes)
    {
        return this.ownerDocument.selectNodes(cXPathString, this);
    }
    else
    {
        throw "For XML Elements Only";
    }
  }
}

// Shut Up

window.onload=function HealOfChina() {
    table_load=document.getElementById("tInformation");
    _IG_initDrag(table_load);
}

