﻿// JScript File

// 搜索框
function getNavigatorType()
{
    if(navigator.appName == "Microsoft Internet Explorer")
	    return 1;  
    else if(navigator.appName == "Netscape")
	    return 2;	
    else 
	    return 0;
}

function getObject(objectId)
{ 
    // checkW3C DOM, then MSIE 4, then NN 4.1 
    if(document.getElementById && document.getElementById(objectId)){ 
	    return document.getElementById(objectId);
    }else if (document.all && document.all(objectId)){ 
	    return document.all(objectId); // IE4,5.0 
    }else if (document.layers && document.layers[objectId]){ 
	    return document.layers[objectId];  // Netscape 4.x 
    }else{ 
	    return false; 
    } 
}

function wValChg(idx,sts)
{
    if(idx == "web") getObject("wn_"+ sts +"").innerHTML = "综合";
    if(idx == "medicine") getObject("wn_"+ sts +"").innerHTML = "药品";
    if(idx == "drugstore") getObject("wn_"+ sts +"").innerHTML = "药店";
	if(idx == "facture") getObject("wn_"+ sts +"").innerHTML = "企业";
    if(idx == "disease") getObject("wn_"+ sts +"").innerHTML = "疾病";
    if(idx == "article") getObject("wn_"+ sts +"").innerHTML = "资讯";
    if(idx == "question") getObject("wn_"+ sts +"").innerHTML = "问题";

    if(sts == "h")
    {
	    getObject("w").value = idx;
    }
    
    getObject("sbArea_"+ sts +"").style.display = "none";
}

function wValDisp(sts,idx)
{
    if(getObject("sbArea_"+ sts +"").style.display == "none"){
	    getObject("sbArea_"+ sts +"").style.display = "";
    }else{
	    getObject("sbArea_"+ sts +"").style.display = "none";
    }
}

function setSelBox(event)
{
    var _event;
    switch (getNavigatorType()) {
	    case 1 : // IE
		    _event = window.event;
		    node = _event.srcElement;
		    nodeName = _event.srcElement.className;
		    break;
	    case 2 : // Netscape
		    _event = event;
		    node = _event.target;
		    nodeName = _event.target.className;
		    break;
	    default :
		    nodeName = "None"; 
		    break;
    }
    
    if(nodeName == "dselObj")
    {
    }
    else
    {
	    try
	    {
		    document.getElementById("sbArea_h").style.display = "none";
	    }catch(e){}
    }
}

document.onmousedown = setSelBox;

function onwordskeypress(evt)
{
    var k = evt.which || evt.keyCode;
    if (k == 13)
    {
        onSiteSearch();
                
        if (window.event)
            evt.returnValue = false;
        else
            evt.preventDefault();
    }
}

// 动画导航
function Timer()
{
	this.obj = (arguments.length) ? arguments[0]:window;
	return this;
}

Timer.prototype.setInterval = function(func, msec)
{
	var i = Timer.getNew();
	var t = Timer.buildCall(this.obj, i, arguments);
	Timer.set[i].timer = window.setInterval(t,msec);
	return i;
}

Timer.prototype.setTimeout = function(func, msec)
{
	var i = Timer.getNew();
	Timer.buildCall(this.obj, i, arguments);
	Timer.set[i].timer = window.setTimeout("Timer.callOnce("+i+");",msec);
	return i;
}

Timer.prototype.clearInterval = function(i)
{
	if(!Timer.set[i]) return;
	window.clearInterval(Timer.set[i].timer);
	Timer.set[i] = null;
}

Timer.prototype.clearTimeout = function(i)
{
	if(!Timer.set[i]) return;
	window.clearTimeout(Timer.set[i].timer);
	Timer.set[i] = null;
}

Timer.set = new Array();
Timer.buildCall = function(obj, i, args)
{
	var t = "";
	Timer.set[i] = new Array();
	if(obj != window){
		Timer.set[i].obj = obj;
		t = "Timer.set["+i+"].obj.";
	}
	t += args[0]+"(";
	if(args.length > 2){
		Timer.set[i][0] = args[2];
		t += "Timer.set["+i+"][0]";
		for(var j=1; (j+2)<args.length; j++){
			Timer.set[i][j] = args[j+2];
			t += ", Timer.set["+i+"]["+j+"]";
		}
	}
	t += ");";
	Timer.set[i].call = t;
	return t;
}

Timer.callOnce = function(i)
{
	if(!Timer.set[i]) return;
	eval(Timer.set[i].call);
	Timer.set[i] = null;
}

Timer.getNew = function()
{
	var i = 0;
	while(Timer.set[i]) i++;
	return i;
}

function $() 
{
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++)
	{
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	
	return elements;
}

if (typeof(_sy_animator) == "undefined")
	_sy_animator = {};

if (typeof(_sy_animator.Animator) == "undefined")
	_sy_animator.Animator = {};

_sy_animator.Animator = function(containerId, initialPosX, initialPosY, motionTime, stepX, stepY, titleText, aColor)
{	
	this.container = $(containerId);
	this.container.style.backgroundPosition = initialPosX + "px " + initialPosY + "px";
	this.container.style.color = aColor;
	this.startPosX = 0;
	this.startPosY = 0;
	this.endPosX = 0;
	this.endPosY = 0;
	this.isForwardX = true;
	this.isForwardY = true;
	this.motionTime = motionTime;
	this.timer = new Timer( this );
	this.stepX = stepX;
	this.stepY = stepY;
	this.titleText = titleText;
}
		
_sy_animator.Animator.prototype.move = function()
{	
	if (this.isForwardX) {
		if (this.startPosX < this.endPosX) {
			this.timer.setTimeout('move', this.motionTime);
			this.startPosX += this.stepX;
		}
	}
	else {
		if (this.startPosX > this.endPosX) {
			this.timer.setTimeout('move', this.motionTime);
			this.startPosX -= this.stepX;
		}
	}
	
	if (this.isForwardY) {
		if (this.startPosY < this.endPosY) {
			this.timer.setTimeout('move', this.motionTime);
			this.startPosY += this.stepY;
		}
	}
	else {
		if (this.startPosY > this.endPosY) {
			this.timer.setTimeout('move', this.motionTime);
			this.startPosY -= this.stepY;
		}
	}

	this.container.style.backgroundPosition = this.startPosX + "px " + this.startPosY + "px";
}
		
_sy_animator.Animator.prototype.animate = function( startX, endX, startY, endY )
{
	this.startPosX = startX;
	this.endPosX = endX;
	this.startPosY = startY;
	this.endPosY = endY;
	
	this.isForwardX = startX <= endX;
	this.isForwardY = startY <= endY;
				
	this.move();
}

_sy_animator.Animator.prototype.showTitle = function()
{
	var div = $("animator_title");
	if (div == null)
		return;
		
	var txtDiv = $("animator_title_text");
	if (txtDiv == null)
		return;
	txtDiv.innerHTML = this.titleText;
	
	var e = this.container;	
	var t = e.offsetTop;
	var l = e.offsetLeft;
	var w = e.offsetWidth;
	while(e = e.offsetParent)
	{
		t += e.offsetTop;
		l += e.offsetLeft;
	}
	
	div.style.position = "absolute";
	div.style.width = (this.titleText.length * 12 + 10) + "px";
	div.style.display = "block";
	div.style.zIndex = 1000;
	
	var ll = ((l + w / 2) - (div.offsetWidth / 2));
	if (ll < 0)
		ll = 4;
		
	div.style.left = ll  + "px";
	div.style.top = (t - 14) + "px";
}

_sy_animator.Animator.prototype.hideTitle = function()
{
	var div = $("animator_title");
	if (div == null)
		return;
	
	if (div.style.display != "none")
	{
		div.style.display = "none";
	}
}

var animators = [];
animators[0] = null;
animators[1] = null;
animators[2] = null;
animators[3] = null;
animators[4] = null;

var ani_titles = [];
ani_titles[0] = '每日更新的各种药品说明书';
ani_titles[1] = '执业药师、咨询师参与的会员用药经验交流';
ani_titles[2] = '全国药店地图和消费信息';
ani_titles[3] = '快速更新的用药资讯报道';
ani_titles[4] = '简便实用的“药历网个人用药记录”';

var ani_colors = [];
ani_colors[0] = '#EA0101';
ani_colors[1] = '#1053A5';
ani_colors[2] = '#20A744';
ani_colors[3] = '#9E7EB3';
ani_colors[4] = '#848484';

function go(obj, u)
{
    if (animators[u] == null)
        animators[u] = new _sy_animator.Animator(obj, 0, -56 * u, 80 ,52, 0, ani_titles[u], ani_colors[u]);
    
    if (animators[u] == null)
        return;
        
    animators[u].animate(0, -312, -56 * u,  -56 * u);
    animators[u].showTitle();
}
	
function back(obj, u)
{
    if (animators[u] == null)
        animators[u] = new _sy_animator.Animator(obj, 0, -56 * u, 80 ,52, 0, ani_titles[u], ani_colors[u]);
    
    if (animators[u] == null)
        return;
        
    animators[u].animate(-312, 0, -56 * u,  -56 * u);
    animators[u].hideTitle();
}

function onSiteSearch()
{
    var w = document.getElementById('w').value;
    var k = document.getElementById('words').value;
    if (k==""||k==null)
    {
        alert("请填写搜索内容！"); 
    }
    else
    {
        window.open("http://www.yaolee.net.cn/searchchk.aspx?w=" + w + "&words=" + encodeURI(k));
    }
}
