// JavaScript Document
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
	window.onload = func;
	}else{
	window.onload = function() {
    oldonload();
    func();
    }
  }
}

function addClass(element,value) {
  if (!element.className) {
    element.className = value;
  } else {
    newClassName = element.className;
    newClassName+= " ";
    newClassName+= value;
    element.className = newClassName;
  }
}

function removeClass(element, value){
  var removedClass = element.className;
  var pattern = new RegExp("(^| )" + value + "( |$)");
  removedClass = removedClass.replace(pattern, "$1");
  removedClass = removedClass.replace(/ $/, "");
  element.className = removedClass;
  return true;
}

/*className */
function getElementsByClass(searchClass,node,tag) {
 var classElements = new Array();
 if ( node == null )
  node = document;
 if ( tag == null )
  tag = '*';
 var els = node.getElementsByTagName(tag);
 var elsLen = els.length;
 var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
 for (var i = 0, j = 0; i < elsLen; i++) {
  if ( pattern.test(els[i].className) ) {
   classElements[j] = els[i];
   j++;
  }
 }
 return classElements;
}

/*nextSibling*/
function get_nextSibling(n){
	var y = n.nextSibling;
	while (y.nodeType != 1) {
		y = y.nextSibling;
	}
	return y;	
}
/*firstChild*/
function get_firstChild(n){
	var y = n.firstChild;
	while (y.nodeType != 1) {
		y = y.nextSibling;
	}
	return y;		
}
/*lastChild*/
function get_lastChild(n){
	var y = n.lastChild;
	while (y.nodeType != 1) {
		y = y.previousSibling;
	}
	return y;		
}

/*previousSibling*/
function get_previousSibling(n){
	var y=n.previousSibling;
	while (y.nodeType!=1){
	y=y.previousSibling;
	}
	return y;
}


/*break ul tag*/
function breakul(ul_ID,li_num){
		if (!document.getElementById(ul_ID)) return false;
		var divid = document.getElementById(ul_ID).parentNode; 
		var sfEls = divid.getElementsByTagName("li"); 
		var loopCount = Math.ceil(sfEls.length/li_num) - 1; 
		for(var less = 0;less<loopCount;less++) {
			var bod = document.createElement("ul");  
			divid.appendChild(bod);
			for(var i = 0;i<li_num;i++) {
					   if(sfEls[li_num] && ((less+1)*li_num +i)<sfEls.length){
					   bod.appendChild(sfEls[li_num]);
			}  
		}   
	}
}

function all_func(){
	breakul('break_hangqing',6);
	breakul('break_weihu',6);
	breakul('break_shangjia',5);
	breakul('break_redian',8);
	tabs("car_tab_ul","data_table","best_car",true);
	tabs("car_tab_ul2","data_table2","best_car2",true);
	tabs("car_tab_ul3","data_table3",null,true);
	tabs("sub_ul","sub_con",null,true);
	tabs("sub_news","sub_news_con",null,true);	
	tabs("rank_newcar_tab","rank_newcar");
	tabs("pageTop","ctab");
	tabs("link_tab_ul","link_box",null,true);
}
addLoadEvent(all_func)
	
/*=======================tab=============================*/
function hide(id){var Div = document.getElementById(id);if(Div){Div.style.display="none"}}  
function show(id){var Div = document.getElementById(id);if(Div){Div.style.display="block"}}  

function tabsRemove(index,head,divs,div2s) { 		
	if (!document.getElementById(head)) return false;
	var tab_heads = document.getElementById(head);
	if (tab_heads) {
		var alis = tab_heads.getElementsByTagName("li");  
		for(var i=0;i<alis.length;i++){
			removeClass(alis[i], "current");
			
			hide(divs+"_"+i);
			if(div2s){hide(div2s+"_"+i)};
			
			if (i==index) {
				addClass(alis[i],"current");
			}
			}
			
			show(divs+"_"+index);
			if(div2s){show(div2s+"_"+index)};
		}
}

function tabs(head,divs,div2s,over){
	if (!document.getElementById(head)) return false;
	var tab_heads=document.getElementById(head);
	
	if (tab_heads) {
	   var alis=tab_heads.getElementsByTagName("li");
	   for(var i=0;i<alis.length;i++) {
		alis[i].num=i;
		
		
		if(over){
				alis[i].onmouseover = function(){
					var thisobj = this;
					thetabstime = setTimeout(function(){changetab(thisobj);},150);
					}
				alis[i].onmouseout = function(){
					clearTimeout(thetabstime);
					}			
		}
		else{			
					alis[i].onclick = function(){
						if(this.className == "current" || this.className == "last current"){
							changetab(this);
							return true;
						}
						else{
							changetab(this);						
							return false;
						}
					
				}
		}
		
		function changetab(thebox){
			tabsRemove(thebox.num,head,divs,div2s);			
		}
  
     } 
  }
}

/*bt login*/
function bt_login_more(overID,boxID,add_Class,iframeID,add_iframeClass){
	if (!document.getElementById(overID)) return false;
	var btli = document.getElementById(overID);	
	var btpop = document.getElementById(boxID);	
	btli.onmouseover = function(){
			addClass(btpop,add_Class);
			popiframeon();
		}
	btli.onmouseout = function(){
			removeClass(btpop,add_Class);
			popiframeout();
		}
	if (document.getElementById(iframeID)){		
		var btpopiframe = document.getElementById(iframeID);
		function popiframeon(){addClass(btpopiframe,add_iframeClass);	}
		function popiframeout(){removeClass(btpopiframe,add_iframeClass);	}	
	}
}
function all_login_box(){
	bt_login_more('bt_login_bt','bt_login_pop','pop_block','popiframe','popiframeblock');
	bt_login_more('bt_login_ibit','bt_login_ibitpop','ibitpop_block','ibitpopiframe','ibitpopiframeblock');
}
addLoadEvent(all_login_box);


/*reset fields*/
function resetFields(whichform) {	
   	if (!document.getElementById("txtkeyword")) return false;
	var element = document.getElementById("txtkeyword");

    element.onfocus = function() {
	//document.charset='gb2312';
    if (this.value == this.defaultValue) {
      this.value = "";
	  addClass(this,"on");
     }
    }
    element.onblur = function() {
      if (this.value == "") {
        this.value = this.defaultValue;
		removeClass(this, "on")
      }
	  
    }
}

function prepareForms() {
  for (var i=0; i<document.forms.length; i++) {
    var thisform = document.forms[i];
    resetFields(thisform);
  }
}
addLoadEvent(prepareForms);

/*city pop*/
function AreasTrans(BtnChange,BtnClose,AreaList) {
	var div=document.getElementById(AreaList);
	var btn=document.getElementById(BtnChange);
	if ((div) && (btn)) {
		btn.onclick = function() {
			if (div.style.display=="none"){
			div.style.display="block";
			btn.className="change_btn_open";
			} 
			else {
			div.style.display="none";		
			btn.className="change_btn_close";
			}		
		}
	var close_btn=document.getElementById(BtnClose);
		close_btn.onclick = function() {
			document.getElementById(AreaList).style.display="none";	
			btn.className="change_btn_close";
		}
	}
}
function allcitypop() { 
	AreasTrans("change_btn","area_list_close","area_list");
}
addLoadEvent(allcitypop);


function popprice(){
	if (!document.getElementById("data_table_8")) return false;
	popprice_div = document.getElementById("data_table_8");
	popprice_dl = popprice_div.getElementsByTagName("dl");
	
	for(var i=0;i<popprice_dl.length;i++){
		popprice_dl[i].onmouseover = function(){
			this.style.position = "relative";
		}
		popprice_dl[i].onmouseout = function(){
			this.style.position = "static";
		}


	}
	
	
}
addLoadEvent(popprice);

function closefestival(){
	if (!document.getElementById("close_f")) return false;
	close_festival = document.getElementById("close_f");
	festival_body = document.getElementsByTagName("body");
		close_festival.onclick = function(){
			festival_body[0].className = "";
			close_festival.style.display="none";
		}
		
}
addLoadEvent(closefestival);
