﻿/*这部分JS依赖于 jQuery 1.3.2*/
jQuery.fn.extend({
	//去掉首尾和中间连续的空格
	trim: function() {
	   if (typeof this.val() != "string") { return inputString; }
	   var retValue = this.val();
	   var ch = retValue.substring(0, 1);
	   while (ch == " ") { // Check for spaces at the beginning of the string
		  retValue = retValue.substring(1, retValue.length);
		  ch = retValue.substring(0, 1);
	   }
	   ch = retValue.substring(retValue.length-1, retValue.length);
	   while (ch == " ") { // Check for spaces at the end of the string
		  retValue = retValue.substring(0, retValue.length-1);
		  ch = retValue.substring(retValue.length-1, retValue.length);
	   }
	   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
		  retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
	
	   }
	   return retValue; // Return the trimmed string back to the user
	}
});


//原生JS	实现按类索引
function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all :
        oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i < arrElements.length; i++){
        oElement = arrElements[i];
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}


function ChangeSearch(index)
{
	var searchBox = getElementsByClassName(document,"ul","naviUL")[0];
	var lis = searchBox.getElementsByTagName("li");
	alert(lis[index].innerHTML);
	
}


$(function(){
	////////////顶部搜索////////////
	$(".searchBox ul li").each(function(index){
		$(this).click(function(){
			switch (index)
			{
				case 0:	 $("#searchForm").attr("action","search_cp.asp").find("input[name='key']").val("cp");break;//找产品
				case 1:	 $("#searchForm").attr("action","search_yp.asp").find("input[name='key']").val("yp");break;//找公司
				default: $("#searchForm").attr("action","search_cp.asp").find("input[name='key']").val("cp")
			};
			$(".searchBox ul li.on").removeClass("on");
			$(this).addClass("on");				   
		});						   					   
	}).eq(0).click();//默认选中哪个()
	
	$("#searchTxt").focus(function(){
		if($(this).trim() == "请输入关键字")
		{
			$(this).val("");	
		}
	})
	.blur(function(){
		if($(this).trim() == "")
		{
			$(this).val("请输入关键字");	
		}
	});
	$("#searchBtn").click(function(){
		if($("#searchTxt").val() =="请输入关键字")
		{
			$("#searchTxt").val("");	
		}
	});
	
	
})













/*收藏本站 兼容代码*/
function addCookie()
{
 if (document.all)
    {
       window.external.addFavorite('http://www.buddha35.com','中国佛事用品采购网');
    }
    else if (window.sidebar)
    {
       window.sidebar.addPanel('中国佛事用品采购网', 'http://www.buddha35.com', "");
 	}
}

/*设为首页 兼容代码*/
function setHomepage()
{
 if (document.all)
    {
        document.body.style.behavior='url(#default#homepage)';
  		document.body.setHomePage('http://www.buddha35.com');
    }
    else if (window.sidebar)
    {
    	if(window.netscape)
    	{
        	try
   			{ 
            	netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
        	} 
        	catch (e) 
        	{ 
    			alert( "该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true" ); 
        	}
    	}
 	}
}
