﻿function killErrors() { 
return true; 
} 
window.onerror = killErrors;  
 
//通用的收藏夹
function bookmark(){
	var title="狂插-KuangCha.com"
	var url="http://www.kuangcha.com"
	if (window.sidebar) window.sidebar.addPanel(title, url,"");
	else if( window.opera && window.print ){
	var mbm = document.createElement('a');
	mbm.setAttribute('rel','sidebar');
	mbm.setAttribute('href',url);
	mbm.setAttribute('title',title);
	mbm.click();}
	else if( document.all ) window.external.AddFavorite( url, title);
	}
//导航菜单
function inits(){
	var nav = document.getElementById("menus");
  	var links = nav.getElementsByTagName("a");
	var currenturl = window.location.href;
	var LinkTypeNum = 0;
	
  	for (var i=0; i<links.length; i++) {
    var linkurl = links[i].getAttribute("href");
	
	  if (currenturl.indexOf(linkurl) != -1) {
      links[i].className = "here";
	  LinkTypeNum++;
	  }
	}
	if(LinkTypeNum==0){links[0].className = "here";}
	
}

//广告切换	
var timeout2=3000;  
var timeout3=4000; 
var now_content=0;
var total_content=5;
var way=1;
var start_content=Math.round(Math.random()*(total_content-1))+1; 
function content_mouse(num){
	now_content=num;
	window.clearInterval(theTimer2);   
		for (var i=1;i<=total_content;i++){
			document.getElementById('divhl0'+i).style.display='none';
		}
			document.getElementById('divhl0'+num).style.display='block';
			theTimer2=setTimeout('change_content()', timeout3);
}
						
function change_content(){
	for (var i=1;i<=total_content;i++){
		document.getElementById('divhl0'+i).style.display='none';
		}
		document.getElementById('divhl0'+now_content).style.display='block';
	if (way) now_content++;
	else now_content--;
	if(now_content>total_content) {now_content=total_content-1;way=0;}
	else if(now_content==0) {now_content=1;way=1;}
		theTimer2=setTimeout('change_content()', timeout2);
}
theTimer2=setTimeout(function(){now_content=1;change_content();}, timeout2);
//图片滑动门
$ = function (id){
	return document.getElementById(id);
}
String.prototype.trim = function(){
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.trimLeft = function(){
	return this.replace(/(^\s*)/g, "");
}
String.prototype.trimRight = function(){
	return this.replace(/(\s*$)/g, "");
}
var DfJs = {};//namespace
////////////////////////////////////////////////////////////
DfJs.tabs = {};//tabs
DfJs.tabs.SimpleTabsPanel = function(id){
	this.id=id;
	this.tabs = new Array();
	this.currentTab;
	this.addTab = function(tab){
		this.tabs[this.tabs.length] = tab;
		tab.setTabPanel(this);
	}
	this.activeTab = function(id){
		var size = this.tabs.length
		for(var i = 0 ;i < size; i++){
			var tab = this.tabs[i];
			if(tab.tabId==id){
				tab.selected();
				if(this.currentTab){
					this.currentTab.unselected();
				}
				this.currentTab=tab;
			}
		}
	}
};
DfJs.tabs.TabPanel = function(tabId,tabImgId,activeImg,inactiveImg,onMouseOverImg,panelId){
	this.tabId = tabId;
	this.tabElement = $(tabId);
	var tabImgElement = $(tabImgId);
	var panelElement=$(panelId);
	var tabsPanel;
	var isSelected = false;
	function setImg(img){
		//tabImgElement.src=img;
		tabImgElement.style.background="url("+img+") no-repeat";
	}
	this.tabElement.onmouseover=function(){
		if(!isSelected){
			setImg(onMouseOverImg);
		}
	};
	this.tabElement.onmouseout=function(){
		if(!isSelected){
			setImg(inactiveImg);
		}else{
			setImg(activeImg);
		}
	};
	this.active = function(){
		if(!isSelected){
			tabsPanel.activeTab(tabId);
		}
	};
	this.tabElement.onclick=this.active;

	setImg(inactiveImg);
	this.tabElement.style.cursor="hand";
	panelElement.style.display="none";

	this.setTabPanel = function(parentTabsPanel){
		tabsPanel = parentTabsPanel;
	};
	this.selected = function(){
		setImg(activeImg);
		panelElement.style.display="block";
		isSelected = true;
	};
	this.unselected = function(){
		setImg(inactiveImg);
		panelElement.style.display="none";
		isSelected = false;
	};
}
DfJs.tabs.SlideTabPanel = function(tabId,tabImgId,activeImg,inactiveImg,onMouseOverImg,panelId){
	var superTab = new DfJs.tabs.TabPanel(tabId,tabImgId,activeImg,inactiveImg,onMouseOverImg,panelId);
	superTab.tabElement.onmouseover=function(){
		superTab.active();
	};
	return superTab;
}
/////////////////////////////////////////////////
DfJs.input = {};//input
DfJs.input.TextFieldTooltip = function(id,tip){
	var ele = $(id);
	if(ele.value.trim()==''){
		ele.value=tip;
	}
	ele.onfocus=function(){
		if(ele.value==tip){
			ele.value='';
		}
	};
	ele.onblur=function(){
		if(ele.value.trim()==''){
			ele.value=tip;
		}
	}
}

//加载
window.onload =function() { inits();  init(); }
 
