// JavaScript Document
$(document).ready(function(){
	//top 滚动新闻
	function newListAct(){
		$('#topNewList').animate({top:'-=18px'},'slow',function(){
																var li1=$('#topNewList span')[0];
																$(this).append($(li1).clone());
																$(li1).remove();
																$('#topNewList').css({top:'0'})
																});
		}
		var act=setInterval(newListAct,5000);
		$('#topNewList').mouseover(function(){
											clearInterval(act);
											})
						.mouseout(function(){
										   act=setInterval(newListAct,5000);
										   });
	//买家搜索 TAB 切换
	$('#buyerTab').mouseover(function(){
									$('#coopTab').removeClass('checked');
									$('#buyerTab').addClass('checked');
									$('#buySearchFm').css('display','inline');
									$('#cooperSearchFm').css('display','none');
									});
	
	$('#coopTab').mouseover(function(){
									$('#buyerTab').removeClass('checked');
									$('#coopTab').addClass('checked');
									$('#buySearchFm').css('display','none');
									$('#cooperSearchFm').css('display','inline');
									});
	//产品切换
	$.each($('#proTabList > li'),function(i,n){
										  $(n).mouseover(function(){															  
																  $.each($('#proTabList > li'),function(i,n){
																										$(n).removeClass('checked');																						
																										});
																  $(n).addClass('checked');
																  $.each( $("#fmContent > li"),function(r,n){
																										$(n).css('display','none');
																										});
																  $($("#fmContent > li")[i]).css('display','block');
																  
																  });										  
										  });
	//新闻资讯标签切换
	$.each($('#newTab > li'),function(i,n){
									  $(n).mouseover(function(){
																  $.each($('#newTab > li'),function(i,n){
																										$(n).removeClass('checked');																						
																										});
																  $(n).addClass('checked');
																  $.each( $("#newCtList > li"),function(r,n){
																										$(n).css('display','none');
																										});
																  $($("#newCtList > li")[i]).css('display','inline');
															  });
									  });
	//搜索click
	$('#searchBtn1').click(searchDo);
	$('#keyWord2').keyup(function(e){if(e.which==13){searchDo(); return false;}}).mouseover(function(){$(this).focus();if($(this).val()=='Please input the keyword')$(this).val('');});
	$('#searchBtn2').click(searchCustom);
	$('#ProIntrTxt').keyup(function(e){if(e.which==13){searchCustom(); return false;}});
	function searchDo(){
		var kw=$('#keyWord2').val();
		if($.trim(kw).length<1){
			alert('Please input keywords!');
			$('#keyWord2').focus();
			return false;
			}
		if(IsChinese(kw) ||  IsHtml(kw)){
			alert('您输入了非法字符，请更正后再搜索！');
			return false;
		}
		window.open('searchResult.shtml?kw='+kw.HTMLEncode());
		}
	function searchCustom(){
			var country=$('#countrySelect').val().HTMLEncode();
			var hsCode=$('#HSCodeTxt').val().HTMLEncode();
			var proIntr=$('#ProIntrTxt').val().HTMLEncode();
			if($.trim(hsCode).length<1){alert('请输入HS编码！');$('#HSCodeTxt').focus();return false;}
			var kw='ct='+country+'&hc='+hsCode+'&pi='+proIntr;
			window.open('searchCustom.shtml?'+kw);
									}	
	function IsChinese(str) {
        return /[\u4e00-\u9fa5]/.test(str);
    }

    //验证是否包含html标记
    function IsHtml(str) {
        return /<[^<]+>/.test(str);
    }						 
	//导航条选中样式
	try{
	var url=window.location.toString().match(/\/([^./]+){1,10}\.shtml/)[1];
	navRemoveCheck();
	switch(url){
		case 'product':case 'advantage':case 'introduct':
		$($('#navList > a')[1]).addClass('checked');
		break;
		case 'service':
		$($('#navList > a')[2]).addClass('checked');
		break;
		case 'index':
		$($('#navList > a')[3]).addClass('checked');
		break;
		case 'new':
		$($('#navList > a')[5]).addClass('checked');
		break;
		case 'aboutUs':
		$($('#navList > a')[6]).addClass('checked');
		break;
		}
	}catch(e){
		
		}
		function navRemoveCheck(){
			$.each($('#navList > a'),function(i,n){
											  $(n).removeClass('checked');
											  });	
		}
});
