  var userAgent = navigator.userAgent.toLowerCase();
  mbrowser = {
	version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
	safari: /webkit/.test( userAgent ),
	opera: /opera/.test( userAgent ),
	msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
	mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
  };
function loadAJAXDiv(url,obj){
		var divobj=GE(obj);
		var xhttp=getXmlhttp();		
			xhttp.onreadystatechange=function(){
				if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
				{					
					var str=xhttp.responseText;
					if(str.replace(/\r\n/g,'').length>2){
						divobj.innerHTML=str;
					}
				}
			}
		xhttp.open("GET",url,true);
		xhttp.setRequestHeader("If-Modified-Since","0");
		xhttp.send(null);
}
function getXmlhttp()
{
	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 loadAjaxJson(url,callback){
	    var div = arguments[2];
		var cassurl = arguments[3];
		var cacheurl = arguments[4];
		var xhttp=getXmlhttp();	
			xhttp.onreadystatechange=function(){
				if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
				{	
				    
					var json = eval('(' + xhttp.responseText + ')'); 
						
                    if(div){
					  callback(json,div,cassurl,cacheurl);
					}else{
					  callback(json);
					}
				}
			}
		xhttp.open("GET",url,true);
		xhttp.setRequestHeader("If-Modified-Since","0");
		xhttp.send(null);
}
function GE(id) {
	if (typeof(id) != "string" || id == "") return null;
	if (document.getElementById && document.getElementById(id)) {
		return document.getElementById(id);
	} else if (document.all && document.all[id]) {
		return document.all[id];
	} else if (document.layers && document.layers[id]) {
		return document.layers[id];
	} else {
		return null;
	}
}
function mainShow(obj,n){
   	if(mbrowser.msie){
		obj.nextSibling.nextSibling.style.display="block";
		var div = obj.parentElement;
		for(var i=3;i<div.children.length;i++){
		  if(div.children[i].style.display=="block"){
			   div.children[i].style.display="none";
		  }	
		}
		changeColor(obj.nextSibling.children[0],true);
		obj.nextSibling.lastChild.setAttribute('pos',n);
		obj.nextSibling.lastChild.previousSibling.setAttribute('pos',n);
		if(cache[obj.firstChild.href]){dataShow(cache[obj.firstChild.href],obj.nextSibling.nextSibling,obj.firstChild.href);}
    }else{
		
	  	obj.nextSibling.nextSibling.nextSibling.nextSibling.style.display="block";
		var div = obj.parentNode;
		for(var i=6;i<div.childNodes.length;i++){
		  if(div.childNodes[i].nodeType!=3&&div.childNodes[i].style.display=="block"){
			   div.childNodes[i].style.display="none";
		  }	
		}
		
	   changeColor(obj.nextSibling.nextSibling.children[0],true);	
	    obj.nextSibling.nextSibling.lastChild.setAttribute('pos',n);
		obj.nextSibling.nextSibling.lastChild.previousSibling.setAttribute('pos',n);

		if(cache[obj.firstChild.href]){dataShow(cache[obj.firstChild.href],obj.nextSibling.nextSibling.nextSibling.nextSibling,obj.firstChild.href);}
	}
	 
     event.returnValue = false; 
     event.cancelBubble = true; 	
	 
}
function toggleShow(obj,n){
	  	if(mbrowser.msie){
		    var div = obj.parentElement.nextSibling;
				div.style.display = "none";
				div = getNextSiblingByN(div,n);
				callData(obj,div);
				changeColor(obj);
				div.style.display = "block";
				obj.parentElement.lastChild.setAttribute('pos',n+4);
				obj.parentElement.lastChild.previousSibling.setAttribute('pos',n+4);
		}else{
			
		    var div = obj.parentNode.nextSibling.nextSibling;
			   
			  	div.style.display = "none";
				
				div = getNextSiblingByNFF(div,n);
				callData(obj,div);
				changeColor(obj);
				div.style.display = "block";
                obj.parentNode.lastChild.setAttribute('pos',n+4);
				obj.parentNode.lastChild.previousSibling.setAttribute('pos',n+4);
		}
		
	
}
/**
*排序调用
*/
function toggleShowSc(obj,n,sc){
	  	if(mbrowser.msie){
		    var div = obj.parentElement.nextSibling;
				div.style.display = "none";
				div = getNextSiblingByN(div,n);
				callData(obj,div,sc);
				div.style.display = "block";
		}else{
			
		    var div = obj.parentNode.nextSibling.nextSibling;
			   
			  	div.style.display = "none";
				
				div = getNextSiblingByNFF(div,n);
				callData(obj,div,sc);
				div.style.display = "block";

		}
		
	
}
function changeColor(obj){
	var p = obj.parentElement||obj.parentNode;
	var c = p.children||p.childNodes;
	for(var i=0;i<c.length;i++){
	  if(mbrowser.msie){
	     c[i].style.color=""; 	
	  }else{
	   if(c[i].nodeType!=3){
		   c[i].style.color=""; 
	   }
	  }
	}
	if(arguments[1]){
	 
	}else{
	   obj.style.color = "red";	
	}
  	
}
function getNextSiblingByNFF(obj,n){
	var i=0;
	var div='';
	while(true&&i++<n){
	   div = obj.nextSibling;
	   obj = div;
	   if(div.nodeType==3){
	      n++;
		  continue;
	   }
	   obj.style.display = "none";
	}
	if(obj.parentNode){
      	var a = obj.parentNode;
		a = a.childNodes;
		for(var i=6;i<a.length;i++){
		  if(a[i].nodeType!=3&&a[i].style.display=="block"){
			   a[i].style.display="none";
		  }	
		}
	}
	return div;
}
function getNextSiblingByN(obj,n){
	var i=0;
	var div='';
	while(true&&i++<n){
	   div = obj.nextSibling;
	   obj = div;
	   obj.style.display = "none";
	}
	if(obj.parentElement){
      	var a = obj.parentElement
		a = a.children
		for(var i=3;i<a.length;i++){
		  if(a[i].style.display=="block"){
			   a[i].style.display="none";
		  }	
		}
	}
	return div;
}
var cache = {};
function callData(obj,div){
 //alert(callData.caller==toggleShowSc);
 if(callData.caller==toggleShowSc){
	 
	 loadAjaxJson(obj.href.replace('list','ajaxindex')+'&sc='+arguments[2],dataShow,div,obj.href); 	 
  }else{

	  if(cache[obj.href]){//如果有缓存直接读取缓存
		  
		dataShow(cache[obj.href],div,obj.href);  
		  return;
	  }
	  loadAjaxJson(obj.href.replace('list','ajaxindex'),dataShow,div,obj.href); 
  }

}


function dataShow(datas,div,url,cacheurl){
	if(!datas) return;
	if(cacheurl){
		if(!cache[cacheurl]){//之前没有就缓存起来
		   cache[cacheurl] = datas;
		}
	}else{
		if(!cache[url]){//之前没有就缓存起来
		   cache[url] = datas;
		}
	}
	/*
    var str ="<div style='clear:both;background-color:#F3FDFF;width:653px;height:180px;'>";
	for(var i=0;i<datas.length;i++){
        if(i==29){	       
		   str += "<div class='ajaxdiv'><a href='"+url+"' target='_blank'>&#x66F4;&#x591A;..</a></div>";
		}else{
		   str += "<div class='ajaxdiv'><a href='"+datas[i]['Link']+"' target='_blank'>"+Trim(datas[i]["louName"])+"</a></div>";	
		}

	}*/
    var str ="";
		var cc = "";
		var cs ="";
	for(var i=0;i<datas.length;i++){
		
        if(i==23){	       
		   str += "<div class='quyu_more'><span class='blackwords'><a href='"+url+"' target='_blank'>&#x66F4;&#x591A;..</a></span></div>";
		}else{
        str +="<div  class='quyu_case'>";
		if(datas[i]['recommend2']==1){
		   cc = "red";
		   cs ="&#x63A8;&#x8350;";
		}else if(datas[i]['recommend2']==2){
			cc = "#E4B704";
			cs ="&#x89C2;&#x5BDF;";
		}else{
			cc = "#83C50B";
			cs ="&#x8C28;&#x614E;";
		}
		str += '<div class="blackwords"  style="float:left;color:'+cc+'">['+cs+']</div>';
        str +='<div class="blackwords" style="float:left"><a href="'+datas[i]['Link']+'" target="_blank" title="'+datas[i]['louName']+'">'+datas[i]['louName']+'</a>';
        str +='</div><div class="bluewords" style="float:left">·'+datas[i]['price']+'</div>';
		  str+="</div>" 
		}
     
	}	
	 if(dataShow.caller==mainShow){
	   str += "<div class='quyu_more'><span class='blackwords'><a href='"+url+"' target='_blank'>&#x66F4;&#x591A;..</a></span></div>";
	 }
	div.innerHTML = str;
}
function Trim(str){   
    return str.replace(/(^\s*)|(\s*$)/g, "");   
}  

function rshow(obj,id){
	for(var i=1;i<4;i++){
	   if(i==id){	
	     document.getElementById("p"+i).className="tag_blue";	
	     document.getElementById("r"+i).style.display="";	
	   }
	   else{
		   document.getElementById("p"+i).className="";	
	     document.getElementById("r"+i).style.display="none";	
	   }
	}
 	
}

function rrshow(obj,id){
	for(var i=1;i<4;i++){
	   if(i==id){	
	     document.getElementById("pp"+i).className="tag_blue";
		 topCharts(obj,i);
	   }
	   else{
		   document.getElementById("pp"+i).className="";	
	   }
	}
 	
}

function position(obj){
	
	var pos = obj.getAttribute('pos');
	var sc = obj.getAttribute('sc');
    var sc = sc=='0'?'asc':'desc';
	if(pos<5){//东西南北排序	
	  if(mbrowser.msie){
   	     loadAjaxJson('/indexajax.php?position='+pos+'&sc='+sc,dataShow,obj.parentNode.parentNode.childNodes[2],obj.parentNode.parentNode.childNodes[0].childNodes[0].href,'/indexajax.php?position='+pos+'&sc='+sc);
	  }else{
		 
		 loadAjaxJson('/indexajax.php?position='+pos+'&sc='+sc,dataShow,(function(obj){
					var i=0;
					
					var div='';
					
					var obj1 = obj.parentNode;
					while(true){
					   div = obj1.nextSibling;
					   obj1 = div;
					   if(div.nodeType==3){
						  continue;
					   }
					   i++;
					   if(i==1)break;
					}

					return div;	})(obj),obj.parentNode.parentNode.childNodes[1].childNodes[0].href,'/indexajax.php?position='+pos+'&sc='+sc);  
	  }
	}else{//其他排序
	
	  if(mbrowser.msie){
	   	toggleShowSc(obj.parentElement.children[pos-5],pos-4,sc);
	  }else{
		 
		toggleShowSc((function(obj,pos){
					var i=0;
					
					var div='';					
					var obj1 = obj.parentNode;
					var p = 0;
					while(true){
					   div = obj1.childNodes[i++];					
					   if(div.nodeType==3){
						  continue;
					   }
					   
					   if(p++==(pos-5))break;
					  
					}

					return div;   })(obj,pos),pos-4,sc); 
	  }
	}
	
}

function setData(id,data){
	cache[id]=data;
}
 function hiddenDi(obj,e){
    var e = e||window.event;
	if (e.currentTarget) {
      if (e.relatedTarget != obj) {
		if (obj != e.relatedTarget.parentNode&&obj != e.relatedTarget.parentNode.parentNode) {
		  obj.style.display="none";
		}
	  }
	} else {
	   if (e.toElement != obj) {
		if (obj != e.toElement.parentNode&&obj != e.toElement.parentNode.parentNode) {
		  obj.style.display="none";
		}
	   }
	}
 }
function showMM(id){
	document.getElementById("js01").style.display="block"//很奇怪IE6,7须这样才正常
	document.getElementById("js01").style.display="none"//很奇怪IE6,7须这样才正常
	document.getElementById(id).style.display="block";
	document.getElementById("js01").style.display="block"//很奇怪IE6,7须这样才正常
}

/**
*排行榜调用
*/
function topCharts(obj,n)
  {
      var parent=obj.parentNode.parentNode;
	  parent.lastChild.innerHTML='数据加载中..';
      loadAjaxJson('ajaxtop.php?&price='+n,dataShows,parent,'ajaxtop.php?&price='+n); 
  }

function dataShows(datas,div,url,cacheurl)
  {
  var html='';
  var lastDiv = div.lastChild;
    if(lastDiv.nodeName!="DIV")
	  {
	    lastDiv =document.createElement('div');
	    div.appendChild(lastDiv);
	  }
    if(datas=='' || datas==null)html='抱歉，暂无数据。';
    else
  for(var i=0;i<datas.length;i++)
      {
	    html +='<div class="Nrelou_case">';
	    html +='<div class="Nrelou_pic"><a href="'+datas[i]["Link"]+'" target="_blank">';
	    html +='<img height="66" border="0" width="86" src="'+datas[i]["fileUrl"]+'" alt="'+datas[i]["Title"]+'"></a></div>';
	    html +='<div class="Nrelou_zi"><span class="blackwords" style="">';
	    html +='<a href="'+datas[i]["Link"]+'">'+datas[i]["Title"]+'</a></span></div></div>';
      }
        html +='<div class="clear"></div>';
	    lastDiv.innerHTML=html;
  }
  
  
