var lid = "-1";
var cid = "-1";
var lid_ersc = "-1";
var cid_ersc = "-1";
var province_val = -1;
var city_val = -1;

/*
$('#ad_pos_1915').ready(function(){
	$('#ad_pos_1915').hide(); 
});
*/
$().ready(function(){
	func_tab_seller();
	//热门车滑动门
	$("#tab_price > li").mouseover(function(){
		$("#tab_price > li").attr("class", "");
		$(this).attr("class", "now");
		$("#block_price").find(".tabbox").hide();
		for(var i=0; i < $("#tab_price > li").length; i++){
			if($("#tab_price > li").eq(i).attr("class") == "now"){
				$("#block_price").find(".tabbox").eq(i).show();
			}
		}
		if($("#focus_frag_block")){
			$("#focus_frag_block").hide();
        }
	});
	//论坛滑动门
	$("#tab_bbs > .tabul > li").mouseover(function(){
		$("#tab_bbs > .tabul > li").attr("class", "");
		$(this).attr("class", "now");
		$("#block_bbs").find(".tab").hide();
		for(var i=0; i<$("#tab_bbs > .tabul > li").length; i++){
			if($("#tab_bbs > .tabul > li").eq(i).attr("class") == "now"){
				$("#block_bbs").find(".tab").eq(i).show();
			}
		}
		if($("#focus_frag_block")){
			$("#focus_frag_block").hide();
        }
	});
	//问答滑动门
	$("#tab_faq > li").mouseover(function(){
		$("#tab_faq > li").attr("class", "");
		$(this).attr("class", "now");
		$("#block_faq > .tab").hide();
		for(var i=0; i<$("#tab_faq > li").length; i++){
			if($("#tab_faq > li").eq(i).attr("class") == "now"){
				$("#block_faq > .tab").eq(i).show();
			}
		}
	});
	//车系排行榜滑动门
	$("#tab_hot_series > li").mouseover(function(){
		$("#tab_hot_series > li").attr("class", "");
		$(this).attr("class", "now");
		$("#block_hot_series > .div").hide();
		for(var i=0; i<$("#tab_hot_series > li").length; i++){
			if($("#tab_hot_series > li").eq(i).attr("class") == "now"){
				$("#block_hot_series > .div").eq(i).show();
			}
		}
	});
	//品牌排行榜滑动门
	$("#tab_hot_sign > li").mouseover(function(){
		$("#tab_hot_sign > li").attr("class", "");
		$(this).attr("class", "now");
		$("#block_hot_brand > .div").hide();
		for(var i=0; i<$("#tab_hot_sign > li").length; i++){
			if($("#tab_hot_sign > li").eq(i).attr("class") == "now"){
				$("#block_hot_brand > .div").eq(i).show();
			}
		}
	});
	//热门新闻排行榜滑动门
	$("#tab_hot_news > li").mouseover(function(){
		$("#tab_hot_news > li").attr("class", "");
		$(this).attr("class", "now");
		$("#hot_news > .div").hide();
		for(var i=0; i<$("#tab_hot_news > li").length; i++){
			if($("#tab_hot_news > li").eq(i).attr("class") == "now"){
				$("#hot_news > .div").eq(i).show();
			}
		}
	});
	//二手车搜索
	$("#btn_search").click(function(){
		var province = $("#province").val();
		var city = $("#city").val();
		var useage = $("#age").val();
		var mileage = $("#mileage").val();
		var logoid = $("#logo_ersc").val();
		var seriesid = $("#series_ersc").val();
		var param = logoid > 0 ? "logo="+logoid : "";
		param += seriesid > 0 ? param.length > 0 ? "&series="+seriesid : "series="+seriesid : "";
		param += useage > 0 ? param.length > 0 ? "&age="+useage : "age="+useage : "";
		param += mileage > 0 ? param.length > 0 ? "&mileage="+mileage : "mileage="+mileage : "";
		param += province > 0 ? param.length > 0 ? "&province="+province : "province="+province : "";
		param += city > 0 ? param.length > 0 ? "&city="+city : "city="+city : "";
		param = param.length>0 ? "?"+param : "";

		window.open("http://2sc.cheshi.com/search_sell_list.php"+ param);
	});
	//车型搜索
	$("#search_go").click(function(){
		var logo = $("#logo").val();
		var series = $("#series").val();
		if(logo == "-1"){
			alert("请选择您要查询的车型");
			return false;
		}else{
			if(series == "-1"){
				window.open("http://product.cheshi.com/logo_"+logo+"/", "_blank");
				//$("#frm_search").attr("action", "http://product.cheshi.com/logo_"+logo+"/");
				//$("#frm_search").submit();
				return;
			}
			if(series != "-1"){
				if(series.indexOf("b")>0){
					var brand = series.replace(/_b/,"");
					window.open("http://product.cheshi.com/brand_"+brand+"/", "_blank");
					//$("#frm_search").attr("action", "http://product.cheshi.com/brand_"+brand+"/");
					//$("#frm_search").submit();
					return;
				}else{
					window.open("http://product.cheshi.com/bseries_"+series+"/", "_blank");
					//$("#frm_search").attr("action", "http://product.cheshi.com/bseries_"+series+"/");
					//$("#frm_search").submit();
					return;
				}
			}
		}
	});
	//报价搜索
	$("#price_go").click(function(){
		var logo = $("#logo").val();
		var series = $("#series").val();
		if(logo == "-1"){
			alert("请选择您要查询的车型");
			return false;
		}else{
			if(series == "-1"){
				window.open("http://product.cheshi.com/logo_"+logo+"/", "_blank");
				//$("#frm_search").attr("action", "http://product.cheshi.com/logo_"+logo+"/");
				//$("#frm_search").submit();
				return;
			}
			if(series != "-1"){
				if(series.indexOf("b")>0){
					var brand = series.replace(/_b/,"");
					window.open("http://product.cheshi.com/brand_"+brand+"/", "_blank");
					//$("#frm_search").attr("action", "http://product.cheshi.com/brand_"+brand+"/");
					//$("#frm_search").submit();
					return;
				}else{
					window.open("http://product.cheshi.com/bseries_"+series+"/price.html", "_blank");
					//$("#frm_search").attr("action", "http://product.cheshi.com/bseries_"+series+"/");
					//$("#frm_search").submit();
					return;
				}
			}
		}
	});
        //图片搜索
	$("#pic_go").click(function(){
		var logo = $("#logo").val();
		var series = $("#series").val();
		if(logo == "-1"){
			alert("请选择您要查询的车型");
			return false;
		}else{
			if(series == "-1"){
				window.open("http://pic.cheshi.com/logopic_"+logo+".html", "_blank");
				return;
			}
			if(series != "-1"){
				if(series.indexOf("b")>0){
					var brand = series.replace(/_b/,"");
					window.open("http://pic.cheshi.com/brandpic_"+brand+".html", "_blank");
					return;
				}else{
					window.open("http://pic.cheshi.com/bseriespic_"+series+".html", "_blank");
					return;
				}
			}
		}
	});
	//load_gdhq_news(0);
	initAutoList_ersc();
	initProvince();
});
function initAutoList(){
	initSelectLogo("logo", "series", lid, cid);
}
function initAutoList_ersc(){
	initSelectLogo_ersc("logo_ersc", "series_ersc", lid_ersc, cid_ersc);
}
function LogoOnChange(){
	selectLogoOnChange("logo","series");
}
function LogoOnChange_ersc(){
	selectLogoOnChange_ersc("logo_ersc","series_ersc");
}
function ProvinceOnChange(){
	selectProvinceOnChange("province","city");
}
function initProvince(){
	initSelectProvince("province", "city", province_val, city_val);
}
function load_commend_seller_price(com_province){
	$("#tab_commend_seller > li").attr("class", "");
	$("#tab_selprice > li").attr("class", "");
	$("#tab_seller_"+com_province).attr("class", "now");
	$("#tab_selprice_"+com_province).attr("class", "now");
	$("#commend_seller").load($("#tab_seller_"+com_province).attr("link")+"?"+Math.random(),function(){func_tab_seller();});
	$("#block_selprice").load($("#tab_selprice_"+com_province).attr("link")+"?"+Math.random(),function(){func_tab_seller();});
	func_tab_seller();
}

function load_commend(com_province){
	var jsonurl_seller='http://seller.cheshi.com/ajax/seller_data.php?act=commend_seller&pid='+ com_province +'&callback=?';
	$.getJSON(jsonurl_seller, '', function(data){ $("#ajax_seller_icon").html(data); func_tab_seller(); });
	
	var jsonurl_price='http://seller.cheshi.com/ajax/seller_data.php?act=commend_price&pid='+ com_province +'&callback=?';
	$.getJSON(jsonurl_price, '', function(data){ $("#ajax_seller_price").html(data); });
	
}

function func_tab_seller(){
	//国产、进口报价页签切换
	$("#tab_seller > li").mouseover(function(){
		$("#tab_seller > li").attr("class", "");
		$(this).attr("class", "now");
		$("#block_seller > .seller_icon").hide();
		for(var i=0; i<$("#tab_seller > li").length; i++){
			if($("#tab_seller > li").eq(i).attr("class") == "now"){
				$("#block_seller > .seller_icon").eq(i).show();
			}
		}
	});
}

function load_commend_price(){
	//推荐报价地区切换
	$("#tab_selprice > li").click(function(){
		if($(this).attr("class")!= "now"){
			$("#tab_selprice > li").attr("class", "");
			$(this).attr("class", "now");
			$("#block_selprice").load($(this).attr("link")+"?"+Math.random(),function(){load_commend_price();});
		}
	});
}
function load_commend_seller_price_1(com_province){
	$("#tab_commend_seller > li").attr("class", "");
	$("#tab_selprice > li").attr("class", "");
	$("#tab_seller_"+com_province).attr("class", "now");
	$("#tab_selprice_"+com_province).attr("class", "now");
	$("#commend_seller").load($("#tab_seller_"+com_province).attr("link")+"?"+Math.random(),function(){func_tab_seller();});
	$("#block_selprice").load($("#tab_selprice_"+com_province).attr("link")+"?"+Math.random(),function(){func_tab_seller();});
	func_tab_seller();
}
function load_gdhq_news(counter){
	i = counter+1;		//递归计数器
	if(i > 1) return;
	$("#menu_gdhq_down").click(function(){
		$("#china_price_box > .city_boxs > div").hide();
		$("#china_price_box").show();
	});
	$("#china_price_box").mouseover(function(){
		$("#china_price_box").show();
	});
	$("#china_price_box").mouseout(function(){
		$("#china_price_box").hide();
	});
	/*
	$("#china_price_box > .city_boxs > span > a").click(function(){
		$("#city_news_201007").load($(this).attr("link")+"?"+Math.random(),function(){load_gdhq_news(i);});
		$("#china_price > a").text($(this).text()+"行情");
		$("#china_price > a").attr("href", $(this).attr("type"));
		$("#china_price_box").hide();
	});
	*/
	$("#china_price_box .show_city_list").click(function(){
		$("#city_news_201007").load($(this).attr("link")+"?"+Math.random(),function(){load_gdhq_news(i);});
		$("#china_price > a").text($(this).text()+"行情");
		$("#china_price > a").attr("href", $(this).attr("type"));
		$("#china_price_box").hide();
	});
}

function show_citys(id){
	$("#china_price_box > .city_boxs > div").hide();
	$("#mark_div").show();
	$("#"+id).show();
}
function close_citys(id){
	$("#"+id).hide();
	$("#mark_div").hide();
}
