window.shq={};
shq.isIE=window.ActiveXObject ? true : false;
shq.isFirefox=(navigator.userAgent.toLowerCase().indexOf("firefox")!=-1);
shq.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera")!=-1);
//getElementById
shq.$=function(o){return typeof(o)=="string"?document.getElementById(o):o}
//getElementByTagNames 
//params (obj,tagNames)
shq.$$=function(){
	var es=[],e;
	for(var i=1,ags=arguments.length-1,o,oo;i<=ags;i++)
	{   o=arguments[0];
		e=arguments[i];
		if(typeof e=='string'){
		  oo=o.getElementsByTagName(e);
		  for(var j=0;j<oo.length;j++)
		    es.push(oo[j])
		  //es[es.length]=oo[j];
		}
	}
	return es;
}
//getElementByTagClass 
//params (tagName,classname)
shq.$$$=function(tagname,classname,obj){
    var es=[];
    var objs=document.body.getElementsByTagName(tagname);
	 for(var i=0;i<objs.length;i++)
	  {
		 if(objs[i].className==classname)
		  {
			 es.push(objs[i])
			// es[es.length]=objs[i];
		  }
	  }
	return es;
}

shq.getNextElement=function(obj){
    for(obj=obj.nextSibling;obj!=null;obj=obj.nextSibling)
	  if(obj.nodeType==1)return obj;
	 if(obj==null)return null;
}

/* get location.search params*/
shq.QueryString=function(str){var qs=location.search;if(qs==""){return ""}var re=new RegExp("&?"+str+"=(.*?)(?:&|$)","i");var v=re.exec(qs);if(v==null){return ""}else{return v[1]}}
_file=(function(){var fileName=document.URL; var file=fileName.replace(/(.+)(?=(?:\/|\\))(?:\/|\\)(\w+)\.\w{1,3}.*/i,function($0,$1,$2){ return $1+','+$2});return file.split(",")})()
if(_file.length>1){
shq.filePath=_file[0];
shq.fileName=_file[1];
}else
{
shq.fileName='index';
}
//shq.url='http://localhost/wow_thsale/';
shq.url='./gamexml/';

shq.cs={"019,001":"Alliance","019,002":"Horde","013,001":"Alliance","013,002":"Horde","002,002":"EVIL","002,001":"GOOD"}
shq.my_games={'1':'003',
              '2':'013',
              '3':'019',
			  '4':'001',
			  '5':'002',
			  '6':'012',
			  '7':'015',
			  '8':'007',
			  '9':'011',
			  '10':'004',
			  '11':'005',
			  '12':'006',
			  '13':'008',
			  '14':'009',
			  '15':'014',
			  '16':'016',
			  '17':'020',
			  '18':'022',
			  '19':'025',
			  '20':'027'
		 };

/* check the string is email true if is email or false if not found*/
if(String.prototype.isEmail==undefined){
	String.prototype.isEmail=function(){
		if(this.length==0){return false}
        if(/^[\w_\-\.]{1,12}@[\w\-]+\.[a-z]{1,4}(?:\.[a-z]{2})?$/i.test(this))
		{
			return true;
		}else{return false;}
	}
}
/* check the string is chinese true if is chinese or false if not found*/
if(String.prototype.isHz==undefined){
	String.prototype.isHz=function(){
     if(/^[\u4e00-\u9fa5]+$/.test(this)){return true}else{return false}
	}
}
/* check the string is telphone true if is telphone or false if not found*/
if(String.prototype.isTel==undefined){
	String.prototype.isTel=function(){
		if(this.length<6){return false}
     if(/^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/.test(this)){return true}else{return false}
	}
}
/* check the string is [a-z][0-9][_] true if is username or false if not found*/
if(String.prototype.isVar==undefined){
	String.prototype.isVar=function(){
		if(this.length<2){return false}
		if(/[^\w\d_]+/g.test(this)){return false}else{return true}
	}
}

/* return l long this string */
if(String.prototype.string==undefined){
	String.prototype.string=function(l){
		return new Array(l+1).join(this)
	}
}

Function.prototype.bindNode=function(oNode){
    var foo=this,iNodeItem

    //使用了全局数组__bindNodes，通过局部变量iNodeItem进行跨函数传值，如果直接传送oNode，也将造成闭包
    if(window.__bindNodes==null)
        __bindNodes=[]
    __bindNodes.push(oNode)
    iNodeItem=__bindNodes.length-1
    oNode=null
    return function(e){
        foo.call(__bindNodes[iNodeItem],e||event)
    }
}


if(window.Event){// 修正Event的DOM
     /*
                                 IE5         MacIE5         Mozilla         Konqueror2.2         Opera5
     event                         yes         yes             yes             yes                     yes
     event.returnValue             yes         yes             no             no                     no
     event.cancelBubble             yes         yes             no             no                     no
     event.srcElement             yes         yes             no             no                     no
     event.fromElement             yes         yes             no             no                     no
    
     */
     Event.prototype.__defineSetter__("returnValue",function(b){//
         if(!b)this.preventDefault();
         return b;
         });
     Event.prototype.__defineSetter__("cancelBubble",function(b){// 设置或者检索当前事件句柄的层次冒泡
         if(b)this.stopPropagation();
         return b;
         });
     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;
         });
     Event.prototype.__defineGetter__("offsetX",function(){
         return this.layerX;
         });
     Event.prototype.__defineGetter__("offsetY",function(){
         return this.layerY;
         });
     }

if(window.Document){// 修正Document的DOM
     /*
                                 IE5         MacIE5         Mozilla         Konqueror2.2         Opera5
     document.documentElement     yes         yes             yes             yes                     no
     document.activeElement         yes         null         no             no                     no
    
     */
     }
if(window.Node){// 修正Node的DOM
     /*
                                 IE5         MacIE5         Mozilla         Konqueror2.2         Opera5
     Node.contains                 yes         yes             no             no                     yes
     Node.replaceNode             yes         no             no             no                     no
     Node.removeNode                 yes         no             no             no                     no
     Node.children                 yes         yes             no             no                     no
     Node.hasChildNodes             yes         yes             yes             yes                     no
     Node.childNodes                 yes         yes             yes             yes                     no
     Node.swapNode                 yes         no             no             no                     no
     Node.currentStyle             yes         yes             no             no                     no
    
     */
     Node.prototype.replaceNode=function(Node){// 替换指定节点
         this.parentNode.replaceChild(Node,this);
         }
     Node.prototype.removeNode=function(removeChildren){// 删除指定节点
         if(removeChildren)
             return this.parentNode.removeChild(this);
         else{
             var range=document.createRange();
             range.selectNodeContents(this);
             return this.parentNode.replaceChild(range.extractContents(),this);
             }
         }
     Node.prototype.swapNode=function(Node){// 交换节点
         var nextSibling=this.nextSibling;
         var parentNode=this.parentNode;
         node.parentNode.replaceChild(this,Node);
         parentNode.insertBefore(node,nextSibling);
         }
     }
if(window.HTMLElement){
     HTMLElement.prototype.__defineGetter__("all",function(){
         var a=this.getElementsByTagName("*");
         var node=this;
         a.tags=function(sTagName){
             return node.getElementsByTagName(sTagName);
             }
         return a;
         });
     HTMLElement.prototype.__defineGetter__("parentElement",function(){
         if(this.parentNode==this.ownerDocument)return null;
         return this.parentNode;
         });
     HTMLElement.prototype.__defineGetter__("children",function(){
         var tmp=[];
         var j=0;
         var n;
         for(var i=0;i<this.childNodes.length;i++){
             n=this.childNodes[i];
             if(n.nodeType==1){
                 tmp[j++]=n;
                 if(n.name){
                     if(!tmp[n.name])
                         tmp[n.name]=[];
                     tmp[n.name][tmp[n.name].length]=n;
                     }
                 if(n.id)
                     tmp[n.id]=n;
                 }
             }
         return tmp;
         });
     HTMLElement.prototype.__defineGetter__("currentStyle", function(){
         return this.ownerDocument.defaultView.getComputedStyle(this,null);
         });
     HTMLElement.prototype.__defineSetter__("outerHTML",function(sHTML){
         var r=this.ownerDocument.createRange();
         r.setStartBefore(this);
         var df=r.createContextualFragment(sHTML);
         this.parentNode.replaceChild(df,this);
         return sHTML;
         });
     HTMLElement.prototype.__defineGetter__("outerHTML",function(){
         var attr;
         var attrs=this.attributes;
         var str="<"+this.tagName;
         for(var i=0;i<attrs.length;i++){
             attr=attrs[i];
             if(attr.specified)
                 str+=" "+attr.name+'="'+attr.value+'"';
             }
         if(!this.canHaveChildren)
             return str+">";
         return str+">"+this.innerHTML+"</"+this.tagName+">";
         });
     HTMLElement.prototype.__defineGetter__("canHaveChildren",function(){
         switch(this.tagName.toLowerCase()){
             case "area":
             case "base":
             case "basefont":
             case "col":
             case "frame":
             case "hr":
             case "img":
             case "br":
             case "input":
             case "isindex":
             case "link":
             case "meta":
             case "param":
                 return false;
             }
         return true;
         });

     HTMLElement.prototype.__defineSetter__("innerText",function(sText){
         var parsedText=document.createTextNode(sText);
         this.innerHTML=parsedText;
         return parsedText;
         });
     HTMLElement.prototype.__defineGetter__("innerText",function(){
         var r=this.ownerDocument.createRange();
         r.selectNodeContents(this);
         return r.toString();
         });
     HTMLElement.prototype.__defineSetter__("outerText",function(sText){
         var parsedText=document.createTextNode(sText);
         this.outerHTML=parsedText;
         return parsedText;
         });
     HTMLElement.prototype.__defineGetter__("outerText",function(){
         var r=this.ownerDocument.createRange();
         r.selectNodeContents(this);
         return r.toString();
         });
     HTMLElement.prototype.attachEvent=function(sType,fHandler){
         var shortTypeName=sType.replace(/on/,"");
         fHandler._ieEmuEventHandler=function(e){
             window.event=e;
             return fHandler();
             }
         this.addEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);
         }
     HTMLElement.prototype.detachEvent=function(sType,fHandler){
         var shortTypeName=sType.replace(/on/,"");
         if(typeof(fHandler._ieEmuEventHandler)=="function")
             this.removeEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);
         else
             this.removeEventListener(shortTypeName,fHandler,true);
         }
     HTMLElement.prototype.contains=function(Node){// 是否包含某节点
         do if(Node==this)return true;
         while(Node=Node.parentNode);
         return false;
         }
     HTMLElement.prototype.insertAdjacentElement=function(where,parsedNode){
         switch(where){
             case "beforeBegin":
                 this.parentNode.insertBefore(parsedNode,this);
                 break;
             case "afterBegin":
                 this.insertBefore(parsedNode,this.firstChild);
                 break;
             case "beforeEnd":
                 this.appendChild(parsedNode);
                 break;
             case "afterEnd":
                 if(this.nextSibling)
                     this.parentNode.insertBefore(parsedNode,this.nextSibling);
                 else
                     this.parentNode.appendChild(parsedNode);
                 break;
             }
         }
     HTMLElement.prototype.insertAdjacentHTML=function(where,htmlStr){
         var r=this.ownerDocument.createRange();
         r.setStartBefore(this);
         var parsedHTML=r.createContextualFragment(htmlStr);
         this.insertAdjacentElement(where,parsedHTML);
         }
     HTMLElement.prototype.insertAdjacentText=function(where,txtStr){
         var parsedText=document.createTextNode(txtStr);
         this.insertAdjacentElement(where,parsedText);
         }
     HTMLElement.prototype.attachEvent=function(sType,fHandler){
         var shortTypeName=sType.replace(/on/,"");
         fHandler._ieEmuEventHandler=function(e){
             window.event=e;
             return fHandler();
             }
         this.addEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);
         }
     HTMLElement.prototype.detachEvent=function(sType,fHandler){
         var shortTypeName=sType.replace(/on/,"");
         if(typeof(fHandler._ieEmuEventHandler)=="function")
             this.removeEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);
         else
             this.removeEventListener(shortTypeName,fHandler,true);
         }
     }
//-->




/**********  xml dom  ****************/
function getChildNode(node, name) {
	for (var i=0;i<node.childNodes.length;i++) {
		if (node.childNodes[i].nodeName == name) {
			return node.childNodes[i];
		}
	}
	throw "Node "+name+" is not a child node of "+node.nodeName;
}

function getNodeText(node, name) {
	return getInnerText(getChildNode(node,name));
}
function getInnerText (node) {
	if (node.textContent) {
		return node.textContent;
	} else if (node.text) {
		return node.text;
	} else if (node.innerText) {
		return stripcdata(node.innerText);
	} else {
		switch (node.nodeType) {
		case 3:
		case 4:
			return "nodeValue"+node.nodeValue;
			//break;
		case 1:
		case 11:
			var innerText = '';
			for (var i = 0; i < node.childNodes.length; i++) {
				innerText += getInnerText(node.childNodes[i]);
			}
			return innerText;
			//break;
		default:
			return '';
		}
	}
}

/* Finds the Submatches of the RegExp  */
if(typeof RegExp.prototype._exec=="undefined"){
RegExp.prototype._exec=function(str){var arr=[];if(this.global){this.lastIndex=0;while((a=this.exec(str))!=null){arr.push(a[1])}return arr;}else{return arr.concat(this.exec(str))}}
}
/* Finds s1 to s2 of the String if g is true return contains s1 and s2. if m return s1 to s2 some line*/
if(typeof String.prototype._search=="undefined"){
String.prototype._search=function(s1,s2,g,m){
   if(!m){
     re=new RegExp(s1+"((?:.|\n)+)?"+s2,"igm");
	 if(g)re.compile("("+s1+"(?:(?:.|\n)+)?"+s2+")","igm")
	 this.search(re)
	 return RegExp.lastParen;
     }
   else
     {
     re=new RegExp(s1+"(.|\n)+?"+s2,"igm")
     return [].concat(this.match(re))
     }
   }
}



/* Finds the index of the first occurence of item in the array, or -1 if not found */
if (typeof Array.prototype.indexOf == "undefined") {
    Array.prototype.indexOf = function(item) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] === item) {
                return i;
            }
        }
        return -1;
    }
}

/* Check whether array contains given string */
if (typeof Array.prototype.contains == "undefined") {
    Array.prototype.contains = function(s) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] === s) {
                return true;
            }
        }
        return false;
    }
}

/* Counts the number of substring occurrences */
if (typeof String.prototype.substrCount == "undefined") {
    String.prototype.substrCount = function(s) {
        return this.split(s).length - 1;
    }
}

/* Get the last element from the array */
if (typeof Array.prototype.getLast == "undefined") {
    Array.prototype.getLast = function() {
        return this[this.length-1];
    }
}

