// JavaScript Document
function selectButton(id) {
	function list(obj) {
		var type = obj.getElementsByTagName('div')[0];
		var list = obj.getElementsByTagName('ul')[0];
		var listItem = list.getElementsByTagName('li');
		var listNum = listItem.length;
		var isFocus = false;
		type.onclick = function() {
			if(list.style.display != 'block') {
				list.style.display = 'block';
				if(!window.XMLHttpRequest && (parseInt(list.offsetHeight) > 300)) {
					list.style.height = '300px';
				}
			} else { 
				list.style.display = 'none';
			}
		}
		type.tabIndex = 0;
		type.hideFocus = true;
		type.style.outline = 0;
		type.onblur = function() {
			if(isFocus == false) {
				list.style.display = 'none';
			}
		}
		list.onmouseover = function() {
			isFocus = true;
			this.tabIndex = 0;
			this.hideFocus = true;
			this.style.outline = 0;
		}
		list.onmouseout = function() {
			isFocus = false;
		}
		list.onblur = function() {
			list.style.display = 'none';
		}
		for(var i=0; i<listNum; i++) {
			listItem[i].onmouseover = function() { 
				isFocus = true;
				if(!window.XMLHttpRequest) {
					this.style.background = '#4080B0';
					this.style.color = '#fff';
				}
			}
			listItem[i].onmouseout = function() { 
				isFocus = false;
				if(!window.XMLHttpRequest) {
					this.style.background = '#eee';
					this.style.color = '#333';
				}
			}
			listItem[i].onclick = function() { 
				list.style.display = 'none';
				type.innerHTML = this.innerHTML;
				if(this.id) {
					gId('sForm').action = '/' + this.id;
				} else if (this.className) {
					this.parentNode.parentNode.getElementsByTagName('input')[0].value = this.className;
				} else {
					this.parentNode.parentNode.getElementsByTagName('input')[0].value = this.innerHTML;
				}
			}
		}
	}
	var sb = gClass('selectButton','div',id);
	var sbNum = sb.length;
	for(var j=0; j<sbNum; j++) {
		list(sb[j]);
	}	
}
function checkSubmit(f) {
	var t;
	try {
		if(f.tagName.toLowerCase() == 'form') {
			t = f.getElementsByTagName('input')[1];
		}
	} catch(e) {
		t = gId(f);		
	}
	if(t.value == '' || t.value.indexOf('请输入') >= 0) {
		if(t.title) {
			alert(t.title);
		} else {
			alert('请输入搜索关键字。');
		}		
		return false;
	}
}
function homeSearchBar() {
	selectButton('searchModel');
	selectButton('sForm');
	gId('searchModel').onsubmit = function() {
		if(gId('b1').getElementsByTagName('input')[0].value == '' && gId('b2').getElementsByTagName('input')[0].value == '' && (gId('b3').value.indexOf('请输入') >= 0 || gId('b3').value == '')) {
			alert('请选择或输入至少一个搜索条件。');
			return false;
		} else {
			if(gId('b3').value.indexOf('请输入') >= 0) {
				gId('b3').value = '';
			}
		}		
	}
	gId('b3').onclick = function() {
		if(gId('b3').value.indexOf('请输入') >= 0) {
			gId('b3').value = '';
		}
	}
	gId('b3').onblur = function() {
		if(gId('b3').value == '' && gId('b1').getElementsByTagName('input')[0].value == '' && gId('b2').getElementsByTagName('input')[0].value == '') {
			gId('b3').value = '请输入公告型号';
		}
	}
	gId('sForm').onsubmit = function() {
		return checkSubmit('sKeyword');
	}
}
function noticeCheck() {
	var input = document.getElementById('noticeSearch').getElementsByTagName('input');
	for(var i=1; i<input.length; i++) {
		input[i].value = input[i].title;
		input[i].style.color = '#bbb';
		input[i].onfocus = function() {
			this.style.color = '#333';
			if(this.value.indexOf('例：') >= 0) {
				this.value = '';
			}
		}
		input[i].onblur = function() {
			if(this.value == '') {
				this.value = this.title;
				this.style.color = '#bbb';
			}					
		}					 
	}
	document.getElementById('noticeSearch').getElementsByTagName('form')[0].onsubmit = function() {
		var flag = 0;
		for(var i=1; i<input.length; i++) {
			if(input[i].value.indexOf('例：') >= 0 || input[i].value == '') {
				input[i].disabled= true;			
			} else {
				flag += 1;				
			}
		}
		function ind() {
			for(var i=1; i<input.length; i++) {
				input[i].value = input[i].title;
				input[i].disabled= false;
			}
			return false;
		}
		if(!flag) {
			alert('搜索条件不能为空！');
			ind();
			return false;
		} else {
			return (confirm('开始查询？') || ind());
		}
	}
}
function ajaxInit() {
	var xmlHttp = false; 
	try {
		 xmlHttp = new XMLHttpRequest();
	} catch (e) {
		try {
			xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
			try {
				xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
			} catch (e) {
				alert('您的浏览器不支持 AJAX！');
				return false;
			}
		}
	}
}
// 注册输入提示
function  regTip() {
	var input = gId('userInput').getElementsByTagName('input');
	var len = input.length - 2;
	for(var i=0; i < len; i++) {
		input[i].onfocus = function() {
			this.parentNode.parentNode.getElementsByTagName('div')[0].style.display='block';
		}
		input[i].onblur = function() {
			this.parentNode.parentNode.getElementsByTagName('div')[0].style.display='none';
			if(this.name == 'username') {
				regCheck.username();
			} else if (this.name == 'password') {
				regCheck.password();				
			} else if (this.name == 'confirm_password') {
				regCheck.confirmPassword();			
			} else if (this.name == 'email') {
				regCheck.email();
			}
		}
	}
	input[len].onblur = function() {
		regCheck.captcha();		
	}
}
// 首页页面兼容性处理
function homeIE6() {
	var li = gClass('i', 'li', 'mall');
	var liLength = li.length;
	for(var i=0; i<liLength; i++) {
		li[i].onmouseover = function() {
			this.style.background = '#FFFBE1'; 
			this.style.border = '1px solid #FEBF90';
			this.style.paddingBottom = '4px';
		}
		li[i].onmouseout = function() {
			this.style.background = '#fff'; 
			if(this.getAttribute('className').indexOf('f') >= 0) {
				this.style.borderTop = '1px solid #D3DDEB';
			} else {
				this.style.borderTop = '1px solid #EBEBEB';
			}			
			this.style.borderRight = '1px solid #D3DDEB';
			this.style.borderBottom = 'none';
			this.style.borderLeft = '1px solid #D3DDEB';
			this.style.paddingBottom = '5px';
		}
	}
	var mcp = gClass('mcBox3', 'ul');
	var mcpLength = mcp.length;
	for(var j=0; j<mcpLength; j++) {
		var mc = mcp[j].getElementsByTagName('li');
		var mcLength = mc.length;
		for(i=0; i<mcLength; i++) {
			mc[i].onmouseover = function() {
				this.style.background = '#FFFBE1'; 
				this.style.border = '1px solid #FEBF90';
			}
			mc[i].onmouseout = function() {
				this.style.background = '#FFFFFF'; 
				this.style.border = '1px solid #D3DDEB';
			}
		}
	}
}
// 热门车型
function hotAuto() {
	var hotAuto = gId('hotAuto');
	var t = hotAuto.getElementsByTagName('ul')[0].getElementsByTagName('li');
	var len = t.length;
	var ul = gClass('mc2List','div','hotAuto')[0].getElementsByTagName('ul');
	var i = 0;
	for(i=0; i<len; i++) {
		t[i].suf = i;
		t[i].onmouseover = function() {
			for(var j=0; j<len; j++) {
				ul[j].className = '';
				t[j].className = '';
			}
			ul[this.suf].className = 'cur';
			t[this.suf].className = 'cur';
		}
	}	
}
// 热贴排行
function hotPost() {
	var hotPost = gId('hotPost');
	var span = hotPost.getElementsByTagName('div')[0].getElementsByTagName('span');
	var len = span.length;
	var ul = gClass('mcList1','ul','hotPost');
	var i = 0;
	for(i=0; i<len; i++) {
		span[i].suf = i;
		span[i].onmouseover = function() {
			for(var j=0; j<len; j++) {
				ul[j].style.zIndex = 1;
				span[j].className = '';
			}
			ul[this.suf].style.zIndex = 2;
			span[this.suf].className = 'cur';
		}
	}
}
// 多屏图片切换
function scroll() {
	var span = gId('scroll').getElementsByTagName('span');
	var len = span.length;
	var ul = gClass('mcBox6','ul','scroll');
	var cur = 0, next = 1;
	function autoPlay() {
		next = (cur+1) % len;
		for(var m=0; m<len; m++) {
			ul[m].style.zIndex = 1;
			span[m].className = '';
		}
		ul[next].style.zIndex = 2;
		span[next].className = 'cur';
		cur++;
	}
	var at = setInterval(autoPlay, 2500);
	var i = 0;
	for(i=0; i<len; i++) {
		span[i].suf = ul[i].suf = i;
		span[i].onmouseover = function() {
			clearInterval(at);
			for(var j=0; j<len; j++) {
				ul[j].style.zIndex = 1;
				span[j].className = '';
			}
			ul[this.suf].style.zIndex = 2;
			span[this.suf].className = 'cur';
		}
		span[i].onmouseout = function() {
			cur = this.suf;
			at = setInterval(autoPlay, 2500);
		}
		ul[i].onmouseover = function() {
			clearInterval(at);
		}
		ul[i].onmouseout = function() {
			cur = this.suf;
			at = setInterval(autoPlay, 2500);
		}
	}
}
	
// 文章字体调整
function fontAdjust() {
	var span = gId('fontAdjust').getElementsByTagName('span');
	var a = ['18px','14px','12px'];
	for(var i=0; i<3; i++) {	
		span[i].flag = i;
		span[i].onclick = function() {
			gId('articleContent').style.fontSize = a[this.flag];
			span[0].className = '';
			span[1].className = '';
			span[2].className = '';
			this.className = 'cur';
		}
	}
}
// 标签切换
function switchTabs(id, className1, className2) {
	var length = obj.length;
	for(var i=0; i<length; i++) {
		var a = obj[i].parentNode.childNodes;
		var al = a.length;
		for(var j=0; j<al; j++) {
			a[j].onfocus = function() {
				this.className = obj[i].className;
			}
		}
	}
}
