var use_focus_blur1 = true;
var use_focus_blur2 = true;
var use_focus_blur3 = true;
$().ready(function(){
        
	$('#show_brand_c').blur(function(){if(use_focus_blur1){$('#show_brand_c').hide();$('#show_brand_t').attr('class','ear_02');}});
	$('#show_series_c').blur(function(){if(use_focus_blur2){$('#show_series_c').hide();$('#show_series_t').attr('class','ear_03');}});
	div_toggle('more_tool_t','more_tool_c');
	div_toggle('city_list_t','city_list_c');
	div_click_toggle1('show_brand_t','show_brand_c');
	div_click_toggle2('show_series_t','show_series_c');
	div_toggle3('search_type_t','search_type_c');
	$('#show_brand_c .close').click(function(){$('#show_brand_c').hide();$('#show_brand_t').attr('class','ear_02');}).mouseover(function(){$('#show_brand_c .now').attr('class','');});
	$('#show_brand_c .fltbottom em b').mouseover(function(){$('#show_brand_c .now').attr('class','');$(this).attr('class','now');});
	$('#show_brand_c .flttop li').mouseover(function(){$('#show_brand_c .now').attr('class','');$(this).attr('class','now');});
	$('#show_brand_c .fltbottom em b,#show_brand_c .flttop li').click(function(){
		if($('#show_brand_t b').text() == $(this).attr('title')){
			$('#show_brand_c').hide();$('#show_brand_t').attr('class','ear_02');
			return true;
		}
		$('#show_brand_t b').text($(this).attr('title'));
		$('#show_brand_t b').attr('title',$(this).attr('title'));
		$('#signid_input').val($(this).attr('signid'));
		$('#show_brand_c').hide();
		$('#show_brand_t').attr('class','ear_02');
		$('#show_series_t b').text('选择车系');
		$('#show_series_t b').attr('title','选择车系');
		$('#mixed_id_input').val(0);
		$('#show_series_c').html('<i>加载中...</i>').css('height','auto');
		$.getJSON("http://product.cheshi.com/js/data/sign_series_list.php?signid="+$(this).attr('signid')+"&cheshicallback=?", function(series_date){
			var t_html = "";
			for(var kid in series_date['series']){
				if(series_date['series'][kid]['id'].indexOf('_b')>0){
					t_html += "<b title='"+series_date['series'][kid]['name']+"' seriesid='"+series_date['series'][kid]['id']+"'>=="+series_date['series'][kid]['name']+"==</b>";
				}else{
					t_html += "<i title='"+series_date['series'][kid]['name']+"' seriesid='"+series_date['series'][kid]['id']+"'>"+series_date['series'][kid]['name']+"</i>";
				}
			}
			$('#show_series_c').html(t_html);
			if(series_date['series'].length > 8){
				$('#show_series_c').css('height','200px');
			}
			$('#show_series_c i,#show_series_c b').mouseover(function(){
				$('#show_series_c .now').attr('class','');
				$(this).attr('class','now');
			});
			$('#show_series_c i,#show_series_c b').click(function(){
				$('#show_series_t b').text($(this).attr('title'));
				$('#show_series_t b').attr('title',$(this).attr('title'));
				$('#mixed_id_input').val($(this).attr('seriesid'));
				$('#show_series_c').hide();
				$('#show_series_t').attr('class','ear_03');
			});
		});
	});
	$('#search_go').click(function(){
		if($('#mixed_id_input').val().indexOf('_c')>0){
			var pid = $('#mixed_id_input').val().replace('_c','')
			var gourl = "http://product.cheshi.com/bseries_"+pid+"/";
		}else if($('#mixed_id_input').val().indexOf('_b')>0){
			var pid = $('#mixed_id_input').val().replace('_b','')
			var gourl = "http://product.cheshi.com/brand_"+pid+"/";
		}else{
			var gourl = "";
		}
		
		if($('#signid_input').val() != 0 && gourl==''){
			var gourl = "http://product.cheshi.com/logo_"+$('#signid_input').val()+"/";
		}
		if(gourl!=''){
			$('#search_go_form').attr('action',gourl);
			$('#search_go_form').submit();
		}else{
			alert('请选择品牌和车系!');
			return true;
		}
	});
	$('#price_go').click(function(){
		if($('#mixed_id_input').val().indexOf('_c')>0){
			var pid = $('#mixed_id_input').val().replace('_c','')
			var gourl = "http://product.cheshi.com/bseries_"+pid+"/price.html";
		}else if($('#mixed_id_input').val().indexOf('_b')>0){
			var pid = $('#mixed_id_input').val().replace('_b','')
			var gourl = "http://product.cheshi.com/brand_"+pid+"/";
		}else{
			var gourl = "";
		}
		
		if($('#signid_input').val() != 0 && gourl==''){
			var gourl = "http://product.cheshi.com/logo_"+$('#signid_input').val()+"/";
		}
		if(gourl!=''){
			$('#search_go_form').attr('action',gourl);
			$('#search_go_form').submit();
		}else{
			alert('请选择品牌和车系!');
			return true;
		}
	});
});
function div_toggle(div1,div2){
	$('#'+div1).mouseover(function(){
		$('#'+div2).show();	 
	});
	$('#'+div1).mouseout(function(){
		$('#'+div2).hide();	 
	});
	$('#'+div2).mouseout(function(){
		$('#'+div2).hide();	 
	});
	$('#'+div2).mouseover(function(){
		$('#'+div2).show();	 
	});
}
function div_toggle3(div1,div2){
	$('#key_q').blur(function(){if(use_focus_blur3){$('#'+div2).hide();$('#'+div1).attr('class','ear_02');}});
	$('#'+div1).click(function(){
		$('#'+div2).toggle();
		if($('#'+div2).css('display') == 'none'){
			$('#'+div1).attr('class','ear_02 ear_02_down_on');
		}else{
			$('#key_q').focus();
			$('#'+div1).attr('class','ear_02 ear_02_up_on');
		}
	}).mouseover(function(){
		use_focus_blur3 = false;
		if($('#'+div2).css('display') == 'none'){
			$('#'+div1).attr('class','ear_02 ear_02_down_on');
		}else{
			$('#'+div1).attr('class','ear_02 ear_02_up_on');
		}
	}).mouseout(function(){
		use_focus_blur3 = true;
		if($('#'+div2).css('display') == 'none'){
			$('#'+div1).attr('class','ear_02');
		}else{
			$('#'+div1).attr('class','ear_02 ear_02_up_out');
		}
	});
	$('#'+div2).mouseover(function(){
		use_focus_blur3 = false;
	}).mouseout(function(){
		use_focus_blur3 = true;
	});
}
function div_click_toggle1(div1,div2){
	$('#'+div1).click(function(){
		$('#'+div2).toggle();	 
		if($('#'+div2).css('display') == 'none'){
			$('#'+div1).attr('class','ear_02 ear_02_down_on');
		}else{
			$('#show_brand_c').focus();
			$('#'+div1).attr('class','ear_02 ear_02_up_on');
		}
		$('#show_series_c').hide();
		$('#show_series_t').attr('class','ear_03');
		
	}).mouseover(function(){
		use_focus_blur1 = false;
		if($('#'+div2).css('display') == 'none'){
			$('#'+div1).attr('class','ear_02 ear_02_down_on');
		}else{
			$('#'+div1).attr('class','ear_02 ear_02_up_on');
		}
	}).mouseout(function(){
		use_focus_blur1 = true;
		if($('#'+div2).css('display') == 'none'){
			$('#'+div1).attr('class','ear_02');
		}else{
			$('#'+div1).attr('class','ear_02 ear_02_up_out');
		}
	});
	$('#'+div2).mouseover(function(){use_focus_blur1 = false;}).mouseout(function(){use_focus_blur1 = true;});
}
function div_click_toggle2(div1,div2){
	$('#'+div1).click(function(){
		$('#'+div2).toggle();	 
		if($('#'+div2).css('display') == 'none'){
			$('#'+div1).attr('class','ear_03 ear_03_down_on');
		}else{
			$('#show_series_c').focus();
			$('#'+div1).attr('class','ear_03 ear_03_up_on');
		}
		$('#show_brand_c').hide();
		$('#show_brand_t').attr('class','ear_02');
	}).mouseover(function(){
		use_focus_blur2 = false;
		if($('#'+div2).css('display') == 'none'){
			$('#'+div1).attr('class','ear_03 ear_03_down_on');
		}else{
			$('#'+div1).attr('class','ear_03 ear_03_up_on');
		}
	}).mouseout(function(){
		use_focus_blur2 = true;
		if($('#'+div2).css('display') == 'none'){
			$('#'+div1).attr('class','ear_03');
		}else{
			$('#'+div1).attr('class','ear_03 ear_03_up_out');
		}
	});
	$('#'+div2).mouseover(function(){use_focus_blur2 = false;}).mouseout(function(){use_focus_blur2 = true;});
}
function init_sign_series_select(signid,seriesid)
{
	var right_signid = false;
	if(signid>0){
		var sign_list = $('#show_brand_c b');
		var s_length = sign_list.length;
		for(var i = 0 ; i < s_length ; i ++ )
		{
			if(sign_list.eq(i).attr('signid')==signid){
				$('#show_brand_t b').text(sign_list.eq(i).attr('title'));
				right_signid = true;
				break;
			}
		}
		if(right_signid){
			$('#signid_input').val(signid);
			$('#mixed_id_input').val(seriesid);
			$.getJSON("http://product.cheshi.com/js/data/sign_series_list.php?signid="+signid+"&cheshicallback=?", function(series_date){
				var t_html = "";
				for(var kid in series_date['series']){
					if(series_date['series'][kid]['id'] == seriesid){
						$('#show_series_t b').text(series_date['series'][kid]['name']);
					}
					if(series_date['series'][kid]['id'].indexOf('_b')>0){
						t_html += "<b title='"+series_date['series'][kid]['name']+"' seriesid='"+series_date['series'][kid]['id']+"'>=="+series_date['series'][kid]['name']+"==</b>";
					}else{
						t_html += "<i title='"+series_date['series'][kid]['name']+"' seriesid='"+series_date['series'][kid]['id']+"'>"+series_date['series'][kid]['name']+"</i>";
					}
				}
				$('#show_series_c').html(t_html);
				if(series_date['series'].length > 8){
					$('#show_series_c').css('height','200px');
				}
				$('#show_series_c i,#show_series_c b').mouseover(function(){
					$('#show_series_c .now').attr('class','');
					$(this).attr('class','now');
				});
				$('#show_series_c i,#show_series_c b').click(function(){
					$('#show_series_t b').text($(this).attr('title'));
					$('#show_series_t b').attr('title',$(this).attr('title'));
					$('#mixed_id_input').val($(this).attr('seriesid'));
					$('#show_series_c').hide();
					$('#show_series_t').attr('class','ear_03');
				});
			});
		}
	}
}

$(document).ready(function(){						   
	$("#search_type_c i").click(function(){
		var title = $(this).attr("title");		
		var tab = $(this).attr("tab");
		$("#search_type_t").text(title);
		//$("#search_type_c i").show();
		$("#search_type_t").attr('class','ear_02');
		$("#key_q").focus();
		$(this).attr('class','now');
        $("#search_type_c").hide();
		$("#newtags").val(tab);
	});	
	$("#search_type_c i").mousemove(function(){
		$("#search_type_c i").attr('class','');
		$(this).addClass("now");										
	});
});

function send_form_new(event){
    if(event.keyCode==13) { 
         search_word_new(); 
     	 return false; 
   }  
}

function search_word_new(){
	var type = $("#newtags").val();
	var q = $('#key_q').val();
	if(q == undefined || q == '' ){
		var url_id = 0;
		  switch(type){
			  case "news":
				  url_id = 1;
				  break;
			  case "car":
				  url_id = 2;
				  break;
			  case "price":
				  url_id = 3;
				  break;
			  case "image":
				  url_id = 4;
				  break;
			  case "video":
				  url_id = 6;
				  break;
			  case "faq":
				  url_id = 5;
				  break;
			  case "seller":
				  url_id = 7;
				  break;
			}
		window.open("http://search.cheshi.com/index.php?t="+url_id);
		return false;	
	}
	if(type == 'faq'){
		q = escape(q);
		window.open("http://faq.cheshi.com/search.php?q="+q);
		return false;
	}
	if(type == 'seller'){
		window.open("http://seller.cheshi.com/index.php?action=seller&sellername="+q);
		return false;
	}
	q = escape(q);
	window.open("http://search.cheshi.com/"+type+".php?q="+q);
	return false;

}
