var Browser = new Object();
Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument!='undefined');
Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox")!=-1);
Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera")!=-1);
Browser.isIE = window.ActiveXObject &&navigator.userAgent.toLowerCase().indexOf("msie")!=-1&&(document.all&&!Browser.isOpera)? true : false;
if (Browser.isFirefox) { // entend Event Mod for FireFox
    extendEventObject();
}
if(!Browser.isIE){ //firefox innerText define
   HTMLElement.prototype.__defineGetter__(     "innerText",
    function(){
     var anyString = "";
     var childS = this.childNodes;
     for(var i=0; i<childS.length; i++) {
      if(childS[i].nodeType==1)
       anyString += childS[i].tagName=="BR" ? '\n' : childS[i].innerText;
      else if(childS[i].nodeType==3)
       anyString += childS[i].nodeValue;
     }
     return anyString;
    }
   );
   HTMLElement.prototype.__defineSetter__(     "innerText",
    function(sText){
     this.textContent=sText;
    }
   );
}
function extendEventObject() {
    Event.prototype.__defineGetter__("srcElement", function () {
        var node = this.target;
        while (node.nodeType != 1) node = node.parentNode;
        return node;
    });

    Event.prototype.__defineGetter__("fromElement", function () {
        var node;
        if (this.type == "mouseover")
        node = this.relatedTarget;
        else if (this.type == "mouseout")
        node = this.target;
        if (!node) return;
        while (node.nodeType != 1) node = node.parentNode;
        return node;
    });

    Event.prototype.__defineGetter__("toElement", function () {
        var node;
        if (this.type == "mouseout")
        node = this.relatedTarget;
        else if (this.type == "mouseover")
        node = this.target;
        if (!node) return;
        while (node.nodeType != 1) node = node.parentNode;
        return node;
    });
}
function $(strId){
	return document.getElementById(strId);
	}
function IsChild(cNode,pNode){
    while(cNode!=null){
        cNode=cNode.parentNode;
        if(cNode==pNode) return true;
    }
    return false;
}
var ajccache=new Object();
var waitInterval;
var tempref;
var MouseDelayTime=150;//延迟时间
function startajaxtabs(){
    for(var i=0;i<arguments.length;i++)
    {
        var ulobj=document.getElementById(arguments[i]);
        ulist=ulobj.getElementsByTagName("div");
		if(ulist.length==0){
			ulist=ulobj.getElementsByTagName("a");
			}
        for(var j=0;j<ulist.length;j++)
        {
            var thelist=ulist[j];
            if(thelist.parentNode!=ulobj){
			continue;
			}else if(thelist.tagName=="DIV"){
			var ulistlink=thelist.getElementsByTagName("a")[0];
			}else if(thelist.tagName=="A"){
			ulistlink=thelist;
			}
            var ulistlinkurl=ulistlink.getAttribute("urn");
            var ulistlinktarget=ulistlink.getAttribute("rel");
			var ulistlinkcontent=ulistlink.getAttribute("ctr");
            thelist.setActive=function(bactive){
                if(bactive){
                    this.status="active";
                        this.className=this.className+"on";
						if(this.tagName=="DIV")
                         this.getElementsByTagName("a")[0].className=this.getElementsByTagName("a")[0].className+"on";
                }else{
                    this.status="normal";
					  this.className=this.className.replace("on","");
					  if(this.tagName=="DIV")
                       this.getElementsByTagName("a")[0].className="";
                }
            }
            thelist.LoadTab=function(){
                this.setActive(true);
                this.parentNode.activetab.setActive(false);
                this.parentNode.activetab=this;
				if(this.tagName!="A")
                var ulistlink=this.getElementsByTagName("a")[0];
				else
				var ulistlink=this;
                loadAJAXTab(ulistlink.getAttribute("urn"),ulistlink.getAttribute("rel"),ulistlink.getAttribute("ctr"));
            }
            thelist.onmouseover=function(aEvent){
                var myEvent = window.event ? window.event : aEvent;
                var fm=myEvent.fromElement;
                if(IsChild(fm,this) || fm==this) return;//
                if(this.status=="active") return;
                tempref=this;
                clearTimeout(waitInterval);
                waitInterval=window.setTimeout("tempref.LoadTab();",MouseDelayTime);
            }

            thelist.onmouseout=function(aEvent){
                var myEvent = window.event ? window.event : aEvent;
                var em=myEvent.toElement;
                if(IsChild(em,this) || em==this) return; //
                if(this.status=="active") return;
                clearTimeout(waitInterval);
            }

            if(ulistlinkurl.indexOf("#default")!=-1){

                thelist.setActive(true);
                ulobj.activetab=thelist;
                ajccache[ulistlinkurl]=document.getElementById(ulistlinktarget).innerHTML;
            }else{
                thelist.setActive(false);
            }

        }
        if(ulobj.activetab==null) ulobj.activetab=ulist[0];
    }
}


function getXmlhttp()//定义xmlhttp
{
    var http_request;

    if(window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType("text/xml");
        }
    }
    else if (window.ActiveXObject) {
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    if (!http_request) {
        window.alert("can't create XMLHttpRequest object.");
        return null;
    }
    return http_request;
}

function loadAJAXTab(url,contentid,relcontent){

  var ocontent=document.getElementById(contentid);
	var ncontent=document.getElementById(relcontent);
    if(ajccache[url]==null) {
        var xhttp=getXmlhttp();
        xhttp.onreadystatechange=function(){
            if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
            {
                ocontent.innerHTML=xhttp.responseText;
								//runResponse(ocontent, xhttp.responseText)//运行script,解决ie Bug
                ajccache[url]=ocontent.innerHTML;
            }
			else{
				ocontent.innerHTML=ncontent.innerHTML;
				}
        }
		if(url.indexOf("url","?")!=-1){
        url=url+"?";
		}
		else{
			url=url+"&";
			}
		xhttp.open("GET",url+"rand="+Math.random(),true);
        xhttp.send(null);
    }else{

        ocontent.innerHTML=ajccache[url];
    }
}
window.onerror=function(){return true}


function AddObject_Event(){
for (i=0;i<Event_attachObject.length;i++){
var EventObject=$(Event_attachObject[i][0]);
if (EventObject!=null){
AddEvent(EventObject,Event_attachObject[i][1],changeCssName);
AddEvent(EventObject,Event_attachObject[i][2],changeCssName);
}
}
}
 
function runResponse(obj, html) {
//IE的极其白痴
 var ie = navigator.appVersion.match(/MSIE/);
    var ie = navigator.appVersion.match(/MSIE/);
    var opera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);
    if (ie && !opera) {
        html = "<span style=\"display: none\">to take on IE's bug</span>" + html;
    }
    obj.innerHTML = html;
	runScript(obj)
}
function runScript(obj,scriptsLeft,htmlLeft)
{	
    var scripts = obj.getElementsByTagName("script");
    if (scripts) {
	var cripts=[]
	tHtml=""+obj.innerHTML
	for (var i = 0; i < scripts.length; i++) {cripts[i]=scripts[i].text.replace(/(^\s*)|(\s*$)/g, "")
	tHtml=tHtml.replace(scripts[i].text,"")
	}
	if(scriptsLeft)cripts=cripts.concat(scriptsLeft)
        document.write = function (str) {
            obj.innerHTML += str;
        }
        document.writeln = function (str) {
            obj.innerHTML += str + "<br>";
        }
//取得非脚本html代码
HTMLcodeWithoutScript=tHtml.replace(/<script[\s\S]+?<\/script>/ig,"┡").split("┡")
if(htmlLeft){htmlLeft[0]=HTMLcodeWithoutScript[HTMLcodeWithoutScript.length-1]+htmlLeft[0]
HTMLcodeWithoutScript.pop()
HTMLcodeWithoutScript=HTMLcodeWithoutScript.concat(htmlLeft)}
//向目标元素写入第一段脚本之前的html内容
obj.innerHTML=HTMLcodeWithoutScript[0]
         for (var i = 0; i < cripts.length; i++) {
            script = cripts[i]
                if (cripts[i].src) {
                    script = document.createElement("script");
                    script.src = cripts[i].src;
                    script.defer = true;
                    script.type =  cripts[i].type;
                    var head = document.getElementsByTagName("head").item(0);
                    head.appendChild(script);
                }
                else if (script.substr(0, 4) == "<!--") {
                    eval(script.substr(4));
                }
                else {
                    eval(script);
                }
//如果存在用document.write()写scripts的情况，则递归调用本函数
if(scripts.length>0){runScript(objId,cripts.slice(i+1),HTMLcodeWithoutScript.slice(i+1))
return}
//向目标元素写入每段脚本之后的html内容
obj.innerHTML+=HTMLcodeWithoutScript[i+1]
        }
    }
}
function loadpage(uri,container){
  var ocontent=document.getElementById(container);
	var ncontent=document.getElementById("loading");
    if(ajccache[uri]==null) {
        var xhttp=getXmlhttp();
        xhttp.onreadystatechange=function(){
            if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
            {
                //ocontent.innerHTML=xhttp.responseText;
								runResponse(ocontent, xhttp.responseText)//运行script,解决ie Bug
                ajccache[uri]=ocontent.innerHTML;
            }
			else{
				ocontent.innerHTML=ncontent.innerHTML;
				}
        }
		if(uri.indexOf("uri","?")!=-1){
        uri=uri+"?";
		}
		else{
			uri=uri+"&";
			}
		xhttp.open("GET",uri+"rand="+Math.random(),true);
        xhttp.send(null);
    }else{

        ocontent.innerHTML=ajccache[uri];
    }
}
function InitAjax()
{
 var ajax=false; 
 try { 
  ajax = new ActiveXObject("Msxml2.XMLHTTP"); 
 } catch (e) { 
  try { 
   ajax = new ActiveXObject("Microsoft.XMLHTTP"); 
  } catch (E) { 
   ajax = false; 
  } 
 }
 if (!ajax && typeof XMLHttpRequest!='undefined') { 
  ajax = new XMLHttpRequest(); 
 } 
 return ajax;
}
function saveUserInfo(frm)
{
frm=document.getElementById(frm);
 var msg = document.getElementById("msg");
 var url = frm.action;
 var postStr  = formToRequestString(frm);
 var ajax = InitAjax();
 ajax.open("POST", url, true); 
 ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
 ajax.send(postStr);
 ajax.onreadystatechange = function() {
  if (ajax.readyState == 4 && ajax.status == 200) { 
   msg.innerHTML = ajax.responseText; 
  } 
 } 
}
function formToRequestString(frm){
	var query_string='';
	var and='';
	//alert(frm.length);
	for (i=0;i<frm.length ;i++ ){
		e=frm[i];
		if (e.name!=''){
			if (e.type=='select-one'){
				element_value=e.options[e.selectedIndex].value;
			}
			else if (e.type=='checkbox' || e.type=='radio'){
			if (e.checked!=false){
			  element_value=e.value;
				}
			}
		else{
			element_value=e.value;
			}
		query_string+=and+e.name+'='+element_value.replace(/\&/g,"%26");
		and="&"
		}
	}
	return query_string;
}

function strip(str) {
str = str.replace(/<\/?[^>]*>/g,'');
str.value = str.replace(/[ | ]*\n/g,'\n');
str = str.replace(/\n[\s| | ]*\r/g,'\n');
return str;
}

