﻿/*
'=========================================================
' Software name::The Internet Pharmacies of JianKe
' Version:ver6.0
' Copyright (C) 2006-2009 jianke.com. All rights reserved.
' Web: http://www.jianke.com

'=========================================================
*/
var iedomain="http://www.jianke.com";
var so_iedomain="http://so.jianke.com";


document.getElementById("SearchInPut").onclick=function()
{
	document.getElementById("AutoAutomatic").style.display="block";
}

document.getElementById("SearchInPut").onkeyup=function()
{
	AutoComplete();
}

document.getElementById("SearchInPut").onmouseover=function()
{
	document.getElementById("SearchInPut").focus();
}

document.onclick=function()
{
	var evt=getEvent();
	var ob=evt.srcElement ? evt.srcElement : evt.target;
	var act = ob.tagName.toLowerCase();
	
	if(ob.id !="SearchRadio" && ob.id !="SearchBox" && ob.id !="SearchList" && ob.id !="SearchFooter" && ob.id !="SearchInPut" && act !="input" && act !="label")
	{
	    document.getElementById("SearchList").style.display="none";
		document.getElementById("AutoAutomatic").style.display="none";
    }
}

//*清除内空的html代码
function DelHtml(str){
	var re=new RegExp('\<scr'+'ipt([^\<\>]+)\>','ig');
	str=str.replace(re,'&lt;script$1&gt;');
	re=new RegExp('\<\/scr'+'ipt\>','ig');
	str=str.replace(re,'&lt;/script&gt;');
	delete re;

	str=str.replace(/\<iframe(\/| \/|)\>/ig,'&lt;iframe$1&gt;');
	str=str.replace(/\<\/iframe\>/ig,'&lt;/iframe&gt;');

	str=str.replace(/\<br(\/| \/|)\>/ig,'<br/>');

	return str;
}

//获取点击
function getEvent()
{
    if(document.all)
    {
    return window.event;//如果是ie
	}
	func=getEvent.caller;
	
	while(func!=null)
	{
    var arg0=func.arguments[0];
    if(arg0)
    {
        if((arg0.constructor==Event || arg0.constructor ==MouseEvent)
        ||(typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation))
        {
        return arg0;
        }
    }
        func=func.caller;
    }
    return null;
}
//按条件获取浏览器参数值
function RequestTitle(paras)
{
	var url = location.href;  
	var paraString = url.substring(url.indexOf("?")+1,url.length).split("&");  
	var paraObj = {}  
	for (i=0; j=paraString[i]; i++)
	{
		paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length);  
	}
	
	var returnValue = paraObj[paras.toLowerCase()];  
	if(typeof(returnValue)=="undefined")
	{
		return "";  
	}
	else
	{
		return returnValue;
	}
}
//进行获取出错图片
function ErrorPic(ImgD)
{
      ImgD.src=""+iedomain+"/images/nopic.gif";
}
//获取当前搜索条
function SearchRequestQuery()
{
	var StrTmp = "<ul>";
	
	switch (RequestTitle("type"))
	{
		case "yp":
			StrTmp = StrTmp + "<li class=\"so_top_now\">药品搜索</li>";
			StrTmp = StrTmp + "<li><a href=\"/Search.aspx?so="+RequestTitle("so")+"&type=wd\" target=\"_self\" title=\"问答搜索\">问答搜索</a></li>";
			StrTmp = StrTmp + "<li><a href=\"/Search.aspx?so="+RequestTitle("so")+"&type=bk\" target=\"_self\" title=\"病症搜索\">病症搜索</a></li>";
			StrTmp = StrTmp + "<li><a href=\"/Search.aspx?so="+RequestTitle("so")+"&type=zx\" target=\"_self\" title=\"资讯搜索\">资讯搜索</a></li>";
			break;
		case "wd":
		        StrTmp = StrTmp + "<li><a href=\"/Search_Prod.aspx?so="+RequestTitle("so")+"&type=yp\" target=\"_self\" title=\"药品搜索\">药品搜索</a></li>";
			StrTmp = StrTmp + "<li class=\"so_top_now\">问答搜索</li>";
			StrTmp = StrTmp + "<li><a href=\"/Search.aspx?so="+RequestTitle("so")+"&type=bk\" target=\"_self\" title=\"病症搜索\">病症搜索</a></li>";
			StrTmp = StrTmp + "<li><a href=\"/Search.aspx?so="+RequestTitle("so")+"&type=zx\" target=\"_self\" title=\"资讯搜索\">资讯搜索</a></li>";
			break;
		case "bk":
		        StrTmp = StrTmp + "<li><a href=\"/Search_Prod.aspx?so="+RequestTitle("so")+"&type=yp\" target=\"_self\" title=\"药品搜索\">药品搜索</a></li>";
			StrTmp = StrTmp + "<li><a href=\"/Search.aspx?so="+RequestTitle("so")+"&type=wd\" target=\"_self\" title=\"问答搜索\">问答搜索</a></li>";
			StrTmp = StrTmp + "<li class=\"so_top_now\">病症搜索</li>";
			StrTmp = StrTmp + "<li><a href=\"/Search.aspx?so="+RequestTitle("so")+"&type=zx\" target=\"_self\" title=\"资讯搜索\">资讯搜索</a></li>";
			break;
		case "zx":
		        StrTmp = StrTmp + "<li><a href=\"/Search_Prod.aspx?so="+RequestTitle("so")+"&type=yp\" target=\"_self\" title=\"药品搜索\">药品搜索</a></li>";
			StrTmp = StrTmp + "<li><a href=\"/Search.aspx?so="+RequestTitle("so")+"&type=wd\" target=\"_self\" title=\"问答搜索\">问答搜索</a></li>";
			StrTmp = StrTmp + "<li><a href=\"/Search.aspx?so="+RequestTitle("so")+"&type=bk\" target=\"_self\" title=\"病症搜索\">病症搜索</a></li>";
			StrTmp = StrTmp + "<li class=\"so_top_now\">资讯搜索</li>";
			break;
	}
	StrTmp = StrTmp + "</ul>";
	
	document.write(StrTmp);
}
//对输入框进行赋值
function GetSearchInput()
{
	paras="type";
	
	var url = location.href;  
	var paraString = url.substring(url.indexOf("?")+1,url.length).split("&");  
	var paraObj = {}  
	for (i=0; j=paraString[i]; i++)
	{
		paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length);  
	}
	
	var returnValue = paraObj[paras.toLowerCase()];  
	if(typeof(returnValue)=="undefined")
	{
		returnValue="";  
	}
	
	switch(returnValue)
	{
		case "yp":
		    document.getElementById("SearchDrug").checked=true;
			break;
		case "wd":
		    document.getElementById("SearchHelp").checked=true;
			break;
		case "bk":
		    document.getElementById("SearchBaiKe").checked=true;
			break;
		case "zx":
		    document.getElementById("SearchNews").checked=true;
			break;	
    }
}
//按键盘提交
function KeyDownSubmit()
{	
	document.getElementById("SearchButton").onclick();
	return false;
}
//提交搜索
function SearchSubmit()
{
	try
	{
		var key = document.getElementById("SearchInPut");
		var keystr=key.value;
		
		if(key.value == "")
		{
			alert("请输入要搜索的关键字！");
			key.focus();
			return false
		}
		else if(key.value.indexOf("\"") != -1 || key.value.indexOf(".") != -1 || key.value.indexOf("*") != -1 || key.value.indexOf("%") != -1 || key.value.indexOf("=") != -1  || key.value.indexOf(":") != -1   || key.value.indexOf("#") != -1|| key.value.indexOf("&") != -1 || key.value.indexOf("^") != -1|| key.value.indexOf("'") != -1|| key.value.indexOf("-") != -1|| key.value.indexOf("+") != -1|| key.value.indexOf(";") != -1|| key.value.indexOf("(") != -1|| key.value.indexOf(")") != -1)
		{
			alert("请不要在关键字中包含特殊字符！");
			key.focus();
			return false;
		}
		
		if(document.getElementById("SearchHelp").checked==true)
		{
			window.location.href=""+so_iedomain+"/Search.aspx?so="+encodeURI(keystr).toLowerCase()+"&type=wd";	
		}
		else if(document.getElementById("SearchBaiKe").checked==true)
		{
			window.location.href=""+so_iedomain+"/Search.aspx?so="+encodeURI(keystr).toLowerCase()+"&type=bk";
		}
		else if(document.getElementById("SearchNews").checked==true) 
		{
			window.location.href=""+so_iedomain+"/Search.aspx?so="+encodeURI(keystr).toLowerCase()+"&type=zx";
		}
		else
		{
			window.location.href=""+so_iedomain+"/Search_Prod.aspx?so="+encodeURI(keystr).toLowerCase()+"&type=yp";
		}
	}
	catch(e){}  
}

//==================================================================
//智能搜索开始    
function AutoCompletePost(AutoUrl)
{
    if(!GetAutoCompleteOb("ScriptBox"))
    {
        var DivOb = document.createElement("div");
        DivOb.id = "ScriptBox";
        DivOb.style.display = "none";
        document.body.appendChild(DivOb);
    }
    
    var Snode = document.createElement("script");
    Snode.setAttribute("type", "text/javascript");
    Snode.setAttribute("language", "javascript");
    Snode.setAttribute("src", AutoUrl);
    
    GetAutoCompleteOb("ScriptBox").innerHTML = "";
    GetAutoCompleteOb("ScriptBox").appendChild(Snode);
    Snode=null;
    delete Snode;
}
function GetAutoCompleteOb(ObName)
{
    if(document.getElementById)
    {
         return eval('document.getElementById("' + ObName + '")');
    }
    else
    {
         return eval('document.all.' + ObName);
    }
}
//下拉智能进行请求
function AutoComplete()
{   
	TxtInput = document.getElementById("SearchInPut");
		
	for (i=0;i<document.SearchForm.t.length;i++)
	{
		if(document.SearchForm.t[i].checked==true)
		{
			TxtGroup=document.SearchForm.t[i].value;
		}
	}
	
	if (TxtInput.value!="" && TxtGroup!="")
	{		
		AutoCompletePost(""+iedomain+"/SearchAutoComplete.aspx?opt=EndAutoComplete&key="+ escape(DelHtml(TxtInput.value))+"&t="+TxtGroup+"&NoCache="+Math.random()+"") //请求页面(必须请求一次改变一次URL参数，否则不能get到服务器) 		
	}			
}
//请求后的回调函数（获取服务器返回的信息）
function EndAutoComplete(value)
{
  document.getElementById("SearchList").style.display="block";
  document.getElementById("SearchList").innerHTML=value;
}