/*车类型弹出框*/
function showclass(){
	document.getElementById('show_class').style.display='block';
}

function hiddenclass(){
	document.getElementById('show_class').style.display='none';
}

var c_obj = "";
var t_settime = "";
var c_spell = "";
var old_spell = "";

//拼音找车
$(".nonow").hover(
function(){
	c_obj = this;
	c_spell = $(this).attr("rel");
	show_ping_area();
},function(){
	$(this).attr("class","nonow");
	$("#find_show").hide();
}
)

//监控
//$("#car_class").find("a").click(function(){
//	var temp_url = $(this).attr("href");
//	temp_url = temp_url.replace(/\?.*/,"");
//	var hash=temp_url+"?from=private";
//	$(this).attr("href",hash);
//})

//$("#nav").find("a").click(function(){
//var temp_url = $(this).attr("href");
///temp_url = temp_url.replace(/\?.*/,"");
//var hash=temp_url+"?from=navi";
//$(this).attr("href",hash);
//})


function show_ping_area(){
	var p_arr = getElementPosition(c_obj);
	if (old_spell !=$(c_obj).attr("rel")){
		$("#find_show").load("http://www.xgo.com.cn/spell_abc/"+$(c_obj).attr("rel")+".html?rand="+Math.random(),"",function(back){
		});
	}

	//判断是否超过用户的分辨率
	var c_width = p_arr.left+398;

	if (parseInt(c_width)>screen.width){
		var sub_width = p_arr.left-Math.floor(398/2)-30;
		$("#find_show").css("left",sub_width);
	}else{
		$("#find_show").css("left",p_arr.left-25);
	}

	if ($(c_obj).attr("rel")!==c_spell){
		return false;
	}


	$(c_obj).attr("class","now");

	$("#find_show").css("top",p_arr.top+c_obj.offsetHeight-1);

	old_spell = $(c_obj).attr("rel");

	$("#find_show").show();
}

//拼音模块显示
$("#find_show").hover(
function(){
	$(c_obj).attr("class","now");
	$(this).show();
},function(){
	$(c_obj).attr("class","nonow");
	$(this).hide();
}
)

//获取对应的top和left
//元素位置
//返回值:数组
//注意:在ie下不包括父元素的变宽,在火狐下就没问题
function getElementPosition(targetElm){
	var elmTop = 0;
	var elmLeft = 0;
	while (targetElm != null) {
		elmTop=elmTop+targetElm.offsetTop;
		elmLeft=elmLeft+targetElm.offsetLeft;
		targetElm=targetElm.offsetParent;
	}
	return {'left': elmLeft,'top': elmTop};
}

//显示品牌
function show_manu(){
	$.post("/ajax/ajax_show_manu.php","",function(back){
		$("#manu_id").html(back);
	}
	);

}

//显示车系
function show_line(val){
	//alert(val);
	if (!parseInt(val)) {
		$("#lineid").html('<option value="0">全部车系</option>');
		$("#productid").html('<option value="0">全部车型</option>');
	}
	var manu_id = parseInt(val);
	$.post("/ajax/ajax_show_line.php",{manu_id:manu_id},function(back){
		$("#lineid").html(back);
		$("#lineid").attr("disabled",false);
		$("#productid").html('<option value="0">全部车型</option>');
	});
}

//显示产品
function show_pro(val,manu_id){
	if (!parseInt(val)) return false;
	if (!parseInt(manu_id)) return false;
	var lineid = parseInt(val);
	var manu_id = parseInt(manu_id);
	$.post("/ajax/ajax_show_pro.php",{"manu_id":manu_id,"lineid":lineid},function(back){
		$("#productid").html(back);
		$("#productid").attr("disabled",false);
	});
}

//品牌找车
function manu_check(){
	var form_obj = document.manu_form;
	var manu_id = parseInt(form_obj.manu_id.value);
	var line_id = parseInt(form_obj.lineid.value);
	var productid = form_obj.productid.value;

	if (manu_id && line_id && productid!="0"){
		form_obj.action=productid;
	}else if (manu_id && line_id && productid=="0"){
		form_obj.action="http://www.xgo.com.cn/"+line_id+"/";
	}else if (manu_id && !line_id && productid=="0"){
		form_obj.action="http://product.xgo.com.cn/price_list/brand_"+manu_id+"_1.shtml";
	}else{
		form_obj.action="http://product.xgo.com.cn/";
	}
	return true;
}

//级别造车
function price_check(){
	var form_obj = document.price_form;
	var type_id = parseInt(form_obj.type_id.value);
	var price_url = form_obj.price_id.value;
	if (type_id && price_url!="0"){
		form_obj.action=price_url;
	}else{
		form_obj.action="http://product.xgo.com.cn/";
	}
	return true;
}

//根据车级别显示对应的价格范围
function show_type_price(type_id){
	var form_obj = document.price_form.price_id;
	if (!parseInt(type_id)) return false;
	var temp_arr = price_arr[type_id];
	if (temp_arr){
		var url = "";
		form_obj.options.length = 0;
		form_obj.options[form_obj.options.length]=new Option("请选择价格",0);
		for(url in temp_arr){
			form_obj.options[form_obj.options.length]=new Option(temp_arr[url],url);
		}
	}
}

var o_show_id = "";
var show_tag = 1;
var obj="";

document.onmouseover=function(e){

	e=e?e:window.event;

	if (e.target){
		obj = e.target;
	}else{
		obj = e.srcElement;
	}

	if (obj.nodeName!="BODY"){
		while(obj && obj.nodeName!="DIV"){
			obj=obj.parentNode;
		}
	}

	if (obj){
		var nameid = obj.id;
		if (nameid){
			if (nameid.indexOf("area_")<0 && o_show_id && document.getElementById(o_show_id).style.display!="none") {
				document.getElementById(o_show_id).style.display='none';
			}
		}else if (!nameid && obj.className.indexOf("car_class")!=0 && o_show_id && document.getElementById(o_show_id).style.display!="none"){
			document.getElementById(o_show_id).style.display='none';
		}
	}
}

//显示模块内容
function show_type_area(id,obj){
	var strlen = get_strlen(obj.innerHTML);
	if (strlen<5){
		sub_num = 45;
	}else if(strlen>=5 && strlen<=6){
		sub_num = 38;
	}else if(strlen>6 && strlen<10){
		sub_num = 36;
	}else if(strlen==10){
		sub_num = 28;
	}else{
		sub_num= 45;
	}
	show_tag =0;
	var p_arr = getElementPosition(obj);
	if (o_show_id) $("#"+o_show_id).hide();
	/*	$("#"+id).css("left",p_arr.left-sub_num-350);
	$("#"+id).css("top",p_arr.top-253);*/
	$("#"+id).css("left",p_arr.left-sub_num);
	$("#"+id).css("top",p_arr.top-3);
	o_show_id = id;
	$("#"+id).show();
}

//隐藏out模块
/*function hide_type_area(e,obj){
show_tag = 1;
e=e?e:window.event;
if (e.target){
var nodename = e.target.nodeName;
}else{
var nodename = e.srcElement.nodeName;
}
//alert(nodename);
if (nodename.toUpperCase()=="A" || nodename.toUpperCase()=="P"){
return false;
}else{
document.getElementById(o_show_id).style.display="none";
}
}*/
var m_time="";

$(".show_class").mouseout(function(){
	m_time=setTimeout('timeMouse()');
})

$(".show_class").mouseover(function(){
	if (document.getElementById(o_show_id).style.display=="none"){
		document.getElementById(o_show_id).style.display="";
	}
	if (m_time) clearTimeout(m_time);
})

function timeMouse(){
	document.getElementById(o_show_id).style.display="none";
}

/*function hide_type_area(e,obj){
e=e?e:window.event;
if (isMouseLeaveOrEnter){
document.getElementById(o_show_id).style.display="none";
}
}*/

/*function isMouseLeaveOrEnter(e, handler) {
e=e?e:window.event;
if (e.type != 'mouseout' && e.type != 'mouseover') return false;
var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement;
while (reltg && reltg != handler){
reltg = reltg.parentNode;
}
return (reltg != handler);
}*/

/*$("#car_class").mouseout(function(){
document.getElementById(o_show_id).style.display="none";
})*/

//获取汉字的字符
function get_strlen(s){
	if (!s) return false;
	var w=0;
	for (var i=0; i<s.length; i++) {
		var c = s.charCodeAt(i);
		//单字节加1
		if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {
			w++;
		} else {
			w+=2;
		}
	}
	return w;
}

//焦点大图相关js
var c_img_index = 1;
var img_num = 5;
var img_interval = setInterval("change_image()",3000);

//焦点大图核心函数
function change_image(img_index){
	var temp_index = 0;
	var img_o_arr = document.getElementById("focus_id").getElementsByTagName("a");
	var title_o_arr = document.getElementById("tittle_id").getElementsByTagName("a");
	var num_o_arr = document.getElementById("focus_num").getElementsByTagName("span");
	if (typeof img_index=="undefined") {
		img_index = 0;
		temp_index = c_img_index;
		if (c_img_index ==img_num) c_img_index=1;
		else c_img_index = c_img_index+1;
	}else if (parseInt(img_index)){
		if (img_index == c_img_index) return false;
		clearInterval(img_interval);
		temp_index = c_img_index;
		c_img_index = img_index;
	}

	img_o_arr[c_img_index-1].style.display="";
	img_o_arr[temp_index-1].style.display="none";
	num_o_arr[c_img_index-1].className="now";
	num_o_arr[temp_index-1].className="";
	title_o_arr[c_img_index-1].style.display="";
	title_o_arr[temp_index-1].style.display="none";

	if (parseInt(img_index)){
		img_interval = setInterval("change_image()",5000);
	}
}

//show_manu();


var cur = 'bbs';
function show_div(id){
	document.getElementById(cur).className = 'active';
	document.getElementById('content_'+cur).style.display = 'none';

	document.getElementById(id).className = 'normal';
	document.getElementById('content_'+id).style.display = '';
	cur = id;
}

$("[id^='ph_id']>div").mouseover(function (){
	var current_id = $(this).attr("rel");
	var prefix = current_id.substr(current_id.length-1,1);
	var str = current_id.substr(0,current_id.length-1);
	$("#pinglun"+prefix).hide();
	$("#hot_id"+prefix).hide();
	$("#oil"+prefix).hide();

	$("#ph_id"+prefix+">div").each(function(){
		if ($(this).attr("rel")==current_id){
			$(this).attr("class","normal");
		}else{
			$(this).attr("class","active");
		}
	})

	$("#"+current_id).show();
})


function post_view_count(post_id,system_url)
{
	request_url = system_url + "/tools/actions.php?act=view&pid=" + post_id;
//	alert(request_url);
	$.ajax({
		url: request_url,
		type: 'GET',
		dataType: 'html',
		timeout: 25000,
		error: function(){
		},
		success: function(html){
		}
	});
}


function show_all_website()
{
	document.getElementById('cat_list').style.display = '';
	$("#show_close").html("关闭");
}

function hide_all_website()
{
	document.getElementById('cat_list').style.display = 'none';
	$("#show_close").html("显示");
}

function show_hide_all_website()
{
	var text = $("#show_close").html();
	if(text == "关闭"){
		$("#show_close").html("显示");
	}else{
		$("#show_close").html("关闭");
	}
	$("#cat_list").toggle();
}