﻿// JScript 文件
/*
    主要功能函数，前置导入prototype.js,timer.js,popup.js
    
    Author:Diego
    Date:2009-03-18
*/

var currentselectitem=null; 

function locationAddParam(url, paramName, paramValue) {
	paramValue = encodeURIComponent(paramValue)
	if (url == "" || url.length == 0) {
		url = window.location.href;
	}
	if (url.substring(url.length-1,url.length) == "#") {
		url = url.substring(0,url.length-1);
	}
	var pos = url.indexOf("&"+paramName+"=");
	if (pos == -1) {
		pos = url.indexOf("?"+paramName+"=");
	}
	if (pos != -1) {
		if (url.indexOf("&",pos+1) == -1) {
			url = url.substring(0,url.indexOf("=",pos+1)+1)+paramValue;
		}
		else {
			var tempStr = url.substring(url.indexOf("&",pos+1),url.length);
			url = url.substring(0,url.indexOf("=",pos+1)+1)+paramValue+tempStr;
		}
	}
	else {
		if (url.indexOf("?") != -1) {
			url = url+"&"+paramName+"="+paramValue;
		}
		else {
			url = url+"?"+paramName+"="+paramValue;
		}
	}
	return url;
}

//会员登录
function chincaUserLogin(username, pwd)
{
    if(username == '' || pwd == '')
    {
        g_ModelShowAlert('用户名或密码不能为空!','提示',340,80);
        return false;
    }
    var url = '/ajax.aspx?type=UserLogin&username=' + encodeURIComponent(username) + '&pwd='+ encodeURIComponent(pwd) + '&time='+new Date().getTime();
    new Ajax.Request(url, {
                 method: 'get',
                 asynchronous: false,
                 onSuccess: function(transport) {
                    var response = transport.responseText.split(':');
                    if(response[0]=="succeed")
                    {
                        window.location.href=window.location.href;
                        return false;
                    }
                    else
                    {
                        g_ModelShowAlert('用户名或密码错误!','登录失败',340,80);
                    }
                }
            });
    return false;
}
//直接回车登录
function chincaKeydownUserLogin(event,username, pwd)
{
    var keynum;
    if (window.event) // IE
  	{
  		keynum = event.keyCode;
  	}
	else
	{
	    keynum = event.which;
    }
    if (keynum == 13)
    {
        chincaUserLogin(username, pwd);
        return false;
    }
}
//站内搜索
function chincaSearch(keyword)
{
    //直接跳到搜索模块
    var url = '/templates/content/index.aspx?nodeid=82&keyword=' + encodeURIComponent(keyword);
    window.location.href = url;
    return false;
}
//直接回车搜索
function chincaKeyDownSearch(event, keyword)
{
    var keynum;
    if (window.event) // IE
  	{
  		keynum = event.keyCode;
  	}
	else
	{
	    keynum = event.which;
    }
    if (keynum == 13)
    {
        chincaSearch(keyword);
    }
}
//tab页切换
function chincaTab(current, total)
{
    tabs = total.split('|');
    for(i=0;i<tabs.length;i++)
    {
        $('a'+tabs[i]).style.display='none';
        $('ul'+tabs[i]).style.display='none';
    }
    $('a'+current).style.display='';
    $('ul'+current).style.display='';
}

//member_tab页切换
function chincaMemberTab(current, total)
{
    tabs = total.split('|');
    for(i=0;i<tabs.length;i++)
    {
        $('a'+tabs[i]).className='';
        $('tbl_'+tabs[i]).style.display='none';
        $('tbl_'+tabs[i]).style.visibility='hidden';
    }
    $('a'+current).className='navon';
    $('tbl_'+current).style.display='';
    $('tbl_'+current).style.visibility='visible';
}

//导航多级
function chincaShowNav(id)
{
    var lis = $(id);
    var currentDisplay = $(id.replace('li','subMenu'));
    if(currentDisplay.childElements().length==0)
        return;
    lis.className = 'current';
    $('searcharea').style.display = 'none';
    currentDisplay.style.display = 'block';
    
    var subMenuWidth = 0;
    currentDisplay.childElements().each(function(item){subMenuWidth+=item.getWidth();});
    
    
    var leftAreaWidth = lis.positionedOffset()["left"] - $('mainNav').positionedOffset()["left"] - 23;
    var rightAreaWidth = 870-leftAreaWidth;
    
    var subMenuOffsetX = (subMenuWidth-86)*leftAreaWidth/870;
    currentDisplay.style.left = '-' + subMenuOffsetX + 'px';
    
    subMenuWidth += 30;
    currentDisplay.style.width = subMenuWidth + 'px';
    
}
function chincaHiddenNav(id)
{
    var lis = $(id);
    var currentDisplay = $(id.replace('li','subMenu'));
    if(currentDisplay.childNodes.length==0)
        return;
    if(currentselectitem != lis)
    {
        lis.className = '';
    }
    $('searcharea').style.display = 'block';
    currentDisplay.style.display = 'none';
}

function chincaShowSummary(id)
{   
    $('divTitle'+id).className = 'current';
    $('divSummary' + id).style.display = '';
    $('spanText' + id).className='text2';
    $('spanName' + id).className='name2';
}

function chincaCloseSummary(id)
{
    $('divTitle'+id).className = '';
    $('divSummary' + id).style.display = 'none';
    $('spanText' + id).className='text1';
    $('spanName' + id).className='name1';
}

//显示期刊搜索菜单
function chincaShowMenu(ip, p)
{
    $('divPeriodical').style.display = '';
    leftx = p.positionedOffset()["left"] + ip.positionedOffset()["left"];
    $('divPeriodical').style.left = leftx + 'px';
    topy = p.positionedOffset()["top"] + ip.positionedOffset()["top"] + 23;
    $('divPeriodical').style.top = topy + 'px';
    
}

//期刊搜索
function chincaPeriodicalSearch()
{
    var url = 'periodicalsearch.aspx?prdn=' + encodeURIComponent($('ipPeriodicalNumber').value) + '&prdk=' + encodeURIComponent($('ipPeriodicalKeyword').value)
    window.location.href = url;
    return false;
}

function chincaArticleSearch()
{
    var url = 'periodicalsearch.aspx?ak=' + encodeURIComponent($('ipArticleKeyword').value);
    window.location.href = url;
    return false;
}

function chincaPeriodicalKeydownSearch(event)
{
    var keynum;
    if (window.event) // IE
  	{
  		keynum = event.keyCode;
  	}
	else
	{
	    keynum = event.which;
    }
    if (keynum == 13)
    {
        chincaPeriodicalSearch();
    }
}

function chincaArticleKeydownSearch(event)
{
    var keynum;
    if (window.event) // IE
  	{
  		keynum = event.keyCode;
  	}
	else
	{
	    keynum = event.which;
    }
    if (keynum == 13)
    {
        chincaArticleSearch();
    }
}

function chincaSearchMember()
{
    var url = 'memberlist.aspx?type='+$('sltMemberType').options[$('sltMemberType').selectedIndex].value+'&mk=' + encodeURIComponent($('ipMemberKeyword').value) + '&cid=' + $('sltProductCategory').options[$('sltProductCategory').selectedIndex].value + "&t=" +  encodeURIComponent($('sltTypeCategory').options[$('sltTypeCategory').selectedIndex].value);
    window.location.href = url;
    return false;
}

//站内搜索
function chincaEnSearch(keyword)
{
    //直接跳到搜索模块
    var url = '/templates/en/index.aspx?nodeid=132&keyword=' + encodeURIComponent(keyword);
    window.location.href = url;
    return false;
}
//直接回车搜索
function chincaKeyDownEnSearch(event, keyword)
{
    var keynum;
    if (window.event) // IE
  	{
  		keynum = event.keyCode;
  	}
	else
	{
	    keynum = event.which;
    }
    if (keynum == 13)
    {
        chincaEnSearch(keyword);
    }
}

function chincaCreditSearch()
{
    var url = '/creditlist.aspx?keyword=' + encodeURIComponent($('ipMemberKeyword').value);
    window.location.href = url;
    return false;
}

function chincaCreditKeydownSearch(event)
{
    var keynum;
    if (window.event) // IE
  	{
  		keynum = event.keyCode;
  	}
	else
	{
	    keynum = event.which;
    }
    if (keynum == 13)
    {
        chincaCreditSearch();
    }
}

function isIE8()
{
    if(window.ActiveXObject)
    {
        var s=navigator.userAgent.indexOf("MSIE");
        var e=navigator.userAgent.indexOf(";",s);
        var v=navigator.userAgent.substring(s+5,e);
        if(v=='8.0')
        {
            return true;
        }
    }
    return false;
}

function chincaMainNavInit()
{
    //get all li child
    if (window.XMLHttpRequest || isIE8())
    {
        $$('#nav1 iframe').each(function(item){item.setStyle({display:'none'})});
    }
    else
    {
        $$('#nav1 iframe').each(function(item){item.setStyle({display:''})});
    }
    var lis = $('nav1').childElements();
    lis.each(function(item){
        Event.observe(item, 'mouseover', function(event){
            if(this.getElementsBySelector('ul').length>0)
            {
                this.getElementsBySelector('ul')[0].className = 'nav2';
            }
            var count=0;
            $('nav1').childElements().each(function(i){
                if(i == item)
                {
                    throw $break;
                }
                count ++;
            });
            if(count<6)
            {
               $('nav1').childElements()[count + 6].setStyle({position:'static'}); 
            }
        });
        Event.observe(item, 'mouseout', function(event){
            if(this.getElementsBySelector('ul').length>0)
            {
                this.getElementsBySelector('ul')[0].className = 'nva2hidden';
            }
            //ff
            if(event.currentTarget)
            {
                if (event.relatedTarget != this && event.relatedTarget != null) 
                {
                    if (this != event.relatedTarget.parentNode.parentNode.parentNode) 
                    {
                        $('nav1').childElements().each(function(i){
                            i.setStyle({position:''});
                        });
                    }
                }
            }
            else//ie
            {
                if (event.toElement != this) 
                {
                    if (this != event.toElement.parentNode && this != event.toElement.parentNode.parentNode.parentNode) 
                    {
                        $('nav1').childElements().each(function(i){
                            i.setStyle({position:''});
                        });
                    }
                }
            }
        });
    });
}