// JavaScript Document

// 车型对比所用 Cookie

function getcookie(name) {
	var cookie_start = document.cookie.indexOf(name);
	var cookie_end = document.cookie.indexOf(";", cookie_start);
	return cookie_start == -1 ? '' : unescape(document.cookie.substring(
			cookie_start + name.length + 1,
			(cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}

function setcookie(cookieName, cookieValue, seconds, path, domain, secure) {
	var expires = new Date();
	expires.setTime(expires.getTime() + seconds);
	document.cookie = escape(cookieName) + '=' + escape(cookieValue)
			+ (expires ? '; expires=' + expires.toGMTString() : '')
			+ (path ? '; path=' + path : '/')
			+ (domain ? '; domain=' + domain : '') + (secure ? '; secure' : '');
}

// 模拟下拉框
function searchBar(id, x1, x2) {
	var v = document.getElementById(id);
	var s = document.getElementById(id + 'List');
	var si = s.getElementsByTagName('li');
	s.isFocus = false;
	for ( var i = 0; i < si.length; i++) {
		si[i].onmouseover = function() {
			s.isFocus = true;
			this.style.backgroundColor = '#064D9F';
			this.style.color = '#fff';
		}
		si[i].onmouseout = function() {
			s.isFocus = false;
			this.style.backgroundColor = '#fff';
			this.style.color = '#333';
		}
		si[i].onclick = function() {
			if (document.getElementById(id + 'Type')) {
				var t = document.getElementById(id + 'Type');
				t.value = this.rel;
			}
			v.value = this.innerHTML;
			s.style.visibility = 'hidden';
		}
	}
	v.onclick = function() {
		if (s.style.visibility != 'visible') {
			s.style.visibility = 'visible';
		} else if (s.style.visibility == 'visible') {
			s.style.visibility = 'hidden';
		}
	}
	v.onblur = function() {
		if (s.isFocus == false) {
			s.style.visibility = 'hidden';
		}
	}
	v.onmouseover = function() {
		this.style.backgroundPosition = x1;
	}
	v.onmouseout = function() {
		this.style.backgroundPosition = x2;
	}
}
// 检查input输入文字
function checkValue(t, s, v) {
	if (v) {
		if (t.value == s) {
			t.value = '';
		} else {
			t.select();
		}
	} else {
		if (t.value == '' || t.value == ' ') {
			t.value = s;
		}
	}
}
function altFppTitle(id0, id1) {
	var ti = document.getElementById(id0).getElementsByTagName('li');
	var uList = document.getElementById(id1).getElementsByTagName('ul');
	for ( var i = 0; i < ti.length; i++) {
		ti[i].suf = i;
		ti[i].onclick = function() {
			for ( var j = 0; j < ti.length; j++) {
				ti[j].className = '';
			}
			this.className = 'cur';
			for ( var k = 1; k < uList.length; k++) {
				uList[k].style.visibility = 'hidden';
			}
			uList[this.suf + 1].style.visibility = 'visible';
		}
	}
}
function altTradeCat() {
	var a = document.getElementById('tradeCatList').getElementsByTagName('h3')[0]
			.getElementsByTagName('span');
	var b = gClass('tradeCatAlt', 'div', 'tradeCatList');
	a[0].onclick = function() {
		if (b[0].style.zIndex == 1) {
			b[0].style.zIndex = 3;
		}
		if (a[0].className != 'cur') {
			a[0].className = 'cur';
			a[1].className = '';
		}
	}
	a[1].onclick = function() {
		if (b[0].style.zIndex == 3) {
			b[0].style.zIndex = 1;
		}
		if (a[1].className != 'cur') {
			a[1].className = 'cur';
			a[0].className = '';
		}
	}
}
function checkSubmit(f) {
	var t;
	try {
		if(f.tagName.toLowerCase() == 'form') {
			t = f.getElementsByTagName('input')[1];
		}
	} catch(e) {
		t = document.getElementById(f);		
	}
	if(t.value == '' || t.value.indexOf('请输入') >= 0) {
		if(t.title) {
			alert(t.title);
		} else {
			alert('请输入搜索关键字。');
		}		
		return false;
	}
}
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 fontAdjust() {
	var span = document.getElementById('fontAdjust').getElementsByTagName('span');
	var a = ['18px','14px','12px'];
	for(var i=0; i<3; i++) {	
		span[i].flag = i;
		span[i].onclick = function() {
			document.getElementById('articleContent').style.fontSize = a[this.flag];
			span[0].className = '';
			span[1].className = '';
			span[2].className = '';
			this.className = 'cur';
		}
	}
}/* 自动播放图片 */

function altImg() {
	var a = document.getElementById('mcVideoMain').getElementsByTagName('li');
	var b = document.getElementById('mcVideoNumber').getElementsByTagName('a');
	var cur = 0, next = 1;
	function autoPlay() { 
		next = (cur + 1) % a.length;
		for(var i=0;i<a.length;i++) {
			a[i].style.zIndex = 100;
			a[i].style.filter = 'alpha(opacity=0)';
			a[i].style.opacity = 0;
			b[i].style.background = '#000';
			b[i].style.color = '#fff';
			b[i].style.fontWeight = 'normal';
		}
		a[cur].style.zIndex = 200;
		a[cur].style.filter = 'alpha(opacity=100)';
		a[cur].style.opacity = 1.0;
		a[next].style.zIndex = 150;
		b[cur].style.color = '#fff';
		// 当前图片渐隐		
		var countCur = 1.0;
		var countCurIe = 100;
		function opacityCur() {
			a[cur].style.filter = 'alpha(opacity=' + countCurIe + ')';
			a[cur].style.opacity = countCur;
			countCur-=0.1;
			countCurIe-=10;
			if(countCur<0 || countCurIe<0) {	
				clearInterval(oCur);
			}
		}
		var oCur = setInterval(opacityCur, 50);
		function nextImg() {
			// 下一图片渐出
			a[cur].style.zIndex =100;
			a[cur].style.filter = 'alpha(opacity=0)';
			a[cur].style.opacity = 0;
			b[cur].style.background = '#000';
			a[next].style.zIndex = 200;
			b[next].style.background = '#fff';
			b[next].style.color = '#f60';
			b[next].style.fontWeight = 'bold';
			var countNext = 0.0;
			var countNextIe = 0;				
			function opacityNext() {
				a[next].style.filter = 'alpha(opacity=' + countNextIe + ')';
				a[next].style.opacity = countNext;
				countNext+=0.1;
				countNextIe+=10;
				if(countNext>1 || countNextIe>100) {
					clearInterval(oNext);
				}
			}
			var oNext = setInterval(opacityNext, 50);
		}
		setTimeout(nextImg, 550);
		function delay() {
			cur++;
			cur %= a.length;
		}
		setTimeout(delay, 4000);				
	}
	var alt = setInterval(autoPlay, 5000);	
	for(var j=0; j<a.length; j++) {
		a[j].suffix = b[j].suffix = j;
		a[j].onmouseover = function() {
			clearInterval(alt);			
		}
		a[j].onmouseout = function() {
			cur = this.suffix;
			alt = setInterval(autoPlay, 5000);			
		}
		b[j].onmouseover = function() {
			clearInterval(alt);
			for(var k=0; k<a.length; k++) {
				a[k].style.zIndex = 100;
				b[k].style.background = '#000';
				b[k].style.color = '#fff';
				b[k].style.fontWeight = 'normal';
			}
			a[this.suffix].style.zIndex = 200;
			a[this.suffix].style.filter = 'alpha(opacity=100)';
			a[this.suffix].style.opacity = 1;
			this.style.color = '#f60';
			this.style.fontWeight = 'bold';
			this.style.background = '#fff';
		}
		b[j].onmouseout = function() {
			cur = this.suffix;
			alt = setInterval(autoPlay, 5000);
		}
	}	
}
// 注册输入提示
function  regTip() {
	var input = document.getElementById('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();
	}
}