function sch_select(id,len)
{
	for(var i=0;i<=len-1;i++)
	{
		$("#bsch_radiofield_"+i).removeClass("select");
	}
	$("#bsch_radiofield_"+id).addClass("select");
	bsch_setField(id);
}

//改变搜索条件：0 全部 1 歌名 2 歌手 3 价格
function bsch_setField(id)
{
	newsch_hideSuggest();
    $i("bsch_form").field.value = id;
	checkflag = id;
	if(id==3)
	{
		 $i("bsch_cont1_div").style.display = "none";
		 $i("bsch_cont2_div").style.display = "block"; 
		 $i('bsch_cont2').value = $i("search_price").value;
	}
	else
	{
		$i("bsch_cont1_div").style.display = "block";
		$i("bsch_cont2_div").style.display = "none";
	}
}
//普通搜索 可以没有参数
function bsch_search(content,field)
{
   
	if(typeof(field)=="undefined") 
	{
		$i("bsch_form").field.value = checkflag;
	} 
	else
	{
		bsch_setField(field);
	}
    var sfg=$i("bsch_form").field.value;
    sch_select(sfg,4);
	var mid=parseInt(sfg)+1;
	AJLOG.G_mod('2.1.1.'+mid)

	if(typeof(content)=="undefined")
	{
		if($i("bsch_form").field.value=="3") //按价格
		{
            $i("bsch_form").content.value = $i("bsch_cont2").value.trim();
		}
		else
		{
			$i("bsch_form").content.value = $i("bsch_cont1").value.trim();
		}
	}
	else
	{
		$i("bsch_form").content.value = content;
		if($i("bsch_form").field.value=="3") //按价格
		{
            $i("bsch_cont2").value = content;
			$i("search_price").value = content;
		}
		else
		{
			$i("bsch_cont1").value = content;
		}
	}

    if($i("bsch_form").field.value!="3" && nsch_initword == $i("bsch_cont1").value.trim()) return; //防止nsch_initword
 
	//判断条件，是否合格
	if($i("bsch_form").content.value.trim() == "")
	{
		alert("请输入要搜索的关键字");
		try{ $i("bsch_cont1").focus(); }catch(e){}
		return;
	}
	else if(bsch_con_reg.test($i("bsch_form").content.value.trim()))
	{ 
		alert("您输入关键字含有非法字符，请重新输入");
		try{ $i("bsch_cont1").select(); }catch(e){}
		return;
	}
    
	var conkey=$i("bsch_form").content.value;
    doZero(conkey);

    if(zeroret){
	
	  //显示关键字
		try{ bsch_showkw($i("bsch_form").content.value); }catch(e){}
		
		newschSuggestPause = true;
		newschSuggestCloseFlag = true;


		 //判断是否搜索页面
		if(window.location.href.indexOf("bsch_result") > 0&&$("#bsch_maindiv_3").length>0)
		{
			bsch_searchAll();
		}
		else
		{
			if(sub_mod2!="")
			   $i("bsch_form").action = "bsch_result.screen?auto=1&subm2="+sub_mod2;
			else  $i("bsch_form").action = "bsch_result.screen?auto=1";
			$i("bsch_form").submit();
		}
	}
   
}
var zeroret=true;
function doZero(con){
      var zerokey=['0','0.00','0元','0元彩铃','免费彩铃','免费歌曲','免费铃声','0.','0.0','0.00彩铃','00','000','0000'];
	  for(var i=0;i<zerokey.length;i++){
	         if(zerokey[i]==con){
                    if(window.location.href.indexOf("bsch_result") < 0){
					       $i("bsch_form").action = "bsch_result.screen?auto=1";
						   $i("bsch_form").submit();
					}
                     $.get("bsch_zero_tone.jsp",function(data){
						var obj=$(".top_rightdiv");
						obj=obj.length==0?$(".center_box_right"):obj;
						obj.html($.trim(data));
		            });
					zeroret=false;
			        break;
			 }else{
			        zeroret=true;
			 }
	  }
}
var timefn;
//全查
function bsch_searchAll(two_obj)
{	
	bsch_allinit_sch();
	bsch_content = $i("bsch_form").content.value;
	bsch_field = $i("bsch_form").field.value;
	var tem_two = "0";
	var tem_tname = "";
	var tem_tsinger = "";
	var tem_tprice = "";
	if(two_obj != null)
	{
		tem_two = Sys.undf(two_obj.two) ? "0":"1";
		tem_tname =  Sys.undf(two_obj.tname)? "":two_obj.tname;
		tem_tsinger = Sys.undf(two_obj.tsinger)? "":two_obj.tsinger;
		tem_tprice = Sys.undf(two_obj.tprice)? "":two_obj.tprice;
	}

	//bsch_doSearch({
			//content:bsch_content,
			//field:bsch_field,
			//type:1,
			//page:1,
			//sqflag:0,
			//two: tem_two,
			//tname: tem_tname,
			//tsinger: tem_tsinger,
			//tprice: tem_tprice
	//});
	//bsch_doSearch({
			//content:bsch_content,
			//field:bsch_field,
			//type:2,
			//page:1,
			//sqflag:0,
			//two: tem_two,
			//tname: tem_tname,
			//tsinger: tem_tsinger,
			//tprice: tem_tprice
	//});
	
	if(bsch_field==0){
	    bsch_doSearch({
				content:bsch_content,
				field:bsch_field,
				type:3,
				page:1,
				sqflag:0,
				two: tem_two,
				tname: tem_tname,
				tsinger: tem_tsinger,
				tprice: tem_tprice,
				sertype:1
		});
		bsch_doSearch({
			content:bsch_content,
			field:bsch_field,
			type:3,
			page:1,
			sqflag:0,
			two: tem_two,
			tname: tem_tname,
			tsinger: tem_tsinger,
			tprice: tem_tprice,
			sertype:2
		});
		if(bsch_content.indexOf("+")>-1||bsch_content.indexOf(" ")>-1){
			 var idx=bsch_content.indexOf(" ");
			 idx=idx==-1?bsch_content.indexOf("+"):idx;

		     tem_tname=bsch_content.substring(0,idx).trim();
             tem_tsinger=bsch_content.substring(idx+1,bsch_content.length).trim();
			 bsch_doSearch({
					content:bsch_content,
					field:bsch_field,
					type:3,
					page:1,
					sqflag:0,
					two: tem_two,
					tname: tem_tname,
					tsinger: tem_tsinger,
					tprice: tem_tprice,
					sertype:0
			});
		}else{
		   bsch_arrall_noresult_flag[2]=0;
		}
		var repce=false;
		var arr1=["0.5","0.50","1","1.0","1.00","1.5","1.50","2","2.0","2.00",'2.5','2.50','3','3.0','3.00'];
		for(var i=0;i<arr1.length;i++){
		   if(arr1[i]==bsch_content){
		      // bsch_content=Math.floor(parseFloat(bsch_content)*100);
		       repce=true;
			   break;
		   }
		}
		
		if(repce){
		  repce=false;
		  bsch_doSearch({
				content:bsch_content,
				field:bsch_field,
				type:3,
				page:1,
				sqflag:0,
				two: tem_two,
				tname: tem_tname,
				tsinger: tem_tsinger,
				tprice: tem_tprice,
				sertype:3
			});
		}else{
		   bsch_arrall_noresult_flag[3]=0;
		}
        timefn=window.setInterval(bsch_checkNoAllResult,1000); 
        jlcount=true;
	}else{
		toHideTitle(2);
		if(bsch_field==2&&bsch_content.indexOf(" ")>-1){
		     var idx=bsch_content.indexOf("+");
			 idx=idx==-1?bsch_content.indexOf(" "):idx;
			 bsch_content=bsch_content.substring(0,idx).trim()+" "+bsch_content.substring(idx+1,bsch_content.length).trim();
		}
		if(bsch_field==2&&bsch_content.indexOf("+")>-1){
		     var idx=bsch_content.indexOf("+");
			 idx=idx==-1?bsch_content.indexOf(" "):idx;
			 bsch_content=bsch_content.substring(0,idx).trim()+"+"+bsch_content.substring(idx+1,bsch_content.length).trim();
		}
		bsch_doSearch({
				content:bsch_content,
				field:bsch_field,
				type:3,
				page:1,
				sqflag:0,
				two: tem_two,
				tname: tem_tname,
				tsinger: tem_tsinger,
				tprice: tem_tprice,
				sertype:-1
		});
	}
	
}
function handle_bsearch(e)
{
	Sys.hKey(e,13,function(e){bsch_search();});
}
function bsch_focuscontentstyle()
{
	if($i("bsch_cont1").value.trim() != nsch_initword  &&  $i("bsch_cont1").style.color=="#999999")
	    $i("bsch_cont1").style.color="#000000";
}
//**************************
//建议（联想）
function newsch_contentPropertyCh(v)
{
	var c1 = $i("bsch_form").content.value.trim();
	var c2 = $i("bsch_form").field.value.trim();

	if(c1 != c2 && c1 != nsch_initword && v=="")
	{
		newsch_hideSuggest();
		newschSuggestCloseFlag = true;
	}

	$i("bsch_form").content.value =v;
		newsch_getSuggest(c2,v);
}
function bsch_focuscontent()
{
	if($i("bsch_cont1").value.trim() == nsch_initword)
	{
		$i("bsch_cont1").value = "";
		$i("bsch_cont1").style.color="#000000";
	}
}
//全查初始化
function bsch_allinit_sch()
{
    $i("bsch_noresultdiv").style.display = "none";
	//$i("bsch_maindiv_1").style.display="block";
	//$i("bsch_maindiv_2").style.display="block";
	$i("bsch_maindiv_3").style.display="block";
    $(".search_int").show();

	if($i("bsch_maindiv_4")){$i("bsch_maindiv_4").style.display = "none";}
    if($i("bsch_maindiv_5")){$i("bsch_maindiv_5").style.display = "none";}
    if($i("bsch_maindiv_6")){$i("bsch_maindiv_6").style.display = "none";}

	bsch_arr_noresult_flag = [0,0,0];
	bsch_arr_tishiflag = [0,0,0];
	bsch_arr_totalpage = [0,0,0];
	bsch_arrall_noresult_flag=[-1,-1,-1,-1];
	bsch_count = 0;
}

//热门关键词搜索日志
function bsch_searchKW(c,f,p){
    sub_mod2='2.7';
	if(f=='4'){//铃音
		AJLOG.G_mod('2.7.1');
	    window.open("http://bj.12530.com/user/lis_sina.screen?mid=sina.3&t="+p);
	}else if(f=='5'){//专题
		AJLOG.G_mod('2.7.2');
	    window.open(p);
	}else if(f=='6'){//榜单
		AJLOG.G_mod('2.7.3');
	     window.open("http://bj.12530.com/user/lis_sina.screen?mid=sina.3&t=b"+p);
	}else{
	    bsch_search(c,f);
	}
}
