var defID="-1";
var defaultNavID="-1";
function navHover(id){
	if(id != defID)
	{
		$("#nav_"+defID).removeClass("current");
		$("#nav_"+id).addClass("current");
		
		//$("#subnav_"+defID).addClass("hide");
		//$("#subnav_"+id).removeClass("hide");
		$("#subnav_"+defID).hide();
		$("#subnav_"+id).show();
		defID=id;
	}
}
function setDefaultNav(id)
{
	defaultNavID=id;
	navHover(id);
}
//调整字体大小
function ChangeFontSize(id,size)
{
    $('#' + id+" p,td").css("font-size", size + 'px');
}
var stid=1;
function searchTabClick(id) {
	if(id != stid)
	{
		$("#st_"+stid).removeClass("current");
		$("#st_"+id).addClass("current");

		$("#sf_"+stid).hide();
		$("#sf_"+id).show();
		stid=id;
	}
}
function GetSearch()
{
	var key=$("#key").val();
	if(key =="")
	{
		alert("请输入关键！");
		$("#key").focus();
		return false;
	}
	else
	{
		window.location.href='/Search.aspx?key='+escape(key);
		return false;
	}
}
//刷新验证码
function ChangeValidateCode()
{
	$('#validatecode').attr( 'src','/images/common/validatecode.aspx?rnd=' + Math.random());
}
//图片自动缩放，居中
function imgAutoCenter(panel, imgMaxWidth, imgMaxHeight) {
    $(panel + " img").each(function (i) {
        var imgw = $(this).width();
        var imgh = $(this).height();
        //如果比例大于设置的，说明图片比较“长”
        if ((imgMaxWidth / imgMaxHeight) > (imgw / imgh)) {
            if (imgMaxHeight > imgh) {
                //图片比例小于最大设定，则居中即可
                var margintop = (h - $(this).height()) / 2;
                if (margintop < 0) {
                    margintop = 0;
                }
                $(this).css("margin-top", margintop + "px");
            } else {
                $(this).css("height", imgMaxHeight + "px");
                //$(this).css("width", imgh * imgMaxWidth / imgMaxHeight + "px");
            }
        } else {
            //图片比较窄,需要缩放到最大宽度
            if (imgMaxWidth > imgw) {
                var margintop = (imgMaxHeight - $(this).height()) / 2;
                if (margintop < 0) {
                    margintop = 0;
                }
                $(this).css("margin-top", imgMaxWidth + "px");
				//$(this).css("height", "auto");
				//$(this).css("width", imgMaxWidth + "px");

            } else {
                thumImgHeight = imgh * imgMaxWidth / imgMaxWidth;
                //alert(thumImgHeight);
                //$(this).css("height", thumImgHeight + "px");
                $(this).css("width", imgMaxWidth + "px");
				//$(this).css("height", "auto");
                //alert($(this).height());
                $(this).css("margin-top", (imgMaxHeight - $(this).height()) / 2 + "px");
            }
        }
    });
}

/*********
验证是否是数字
**********/
function checkIsInteger(str)
{
  //如果为空，则通过校验
  if(str == "")
    return true;
     if(/^(\-?)(\d+)$/.test(str))
       return true;
     else
       return false;
}
//头部搜索
function topSearch1() {
	
	var keys= $("#tsForm_1 #anywords").val();
	var seachtype = $("#tsForm_1 input[name=searchtype]:checked").val();
	if(keys !="") {
		window.open('http://202.192.1.15:8080/smu_new/opac/searchlist.html?act=searchqk&keywords='+keys+'&sourcetype='+seachtype+'&searchtype=1&searchmodel=1&sort=1&schooltype=1505&page=1&module=Myopac&_nc=486041&form_id=1&test=0.24855657247826457');
				/*$.ajax({
                    type: 'POST',
                    url: '/ajax/server.ashx?action=utf2gbk',
                    data: 'str=' + escape(keys),
                    success: function (data) {
                        window.open('http://opac.smu.edu.cn:83/searchresult.aspx?anywords='+data,'ts1'+Math.round());
                    },
                    error: function () {
                        alert("提交错误，请联系管理员！");
                        return false;
                    }
                });*/
	} else {
		alert('搜索关键字不能为空！');
		$("#tsForm_1 #anywords").focus();
	}

}
function topSearch2() {
	var keys= $("#tsForm_2 #keys").val();
	var seachtype = $("#tsForm_2 input[name=searchtype]:checked").val();
	if(keys !="") {
		window.open('http://lib.smu.edu.cn/JournalNavigateSys/index.aspx?DDKey='+seachtype+'&DDMode=0&anyword='+encodeURI(keys),'ts2'+Math.round());
	} else {
		alert('搜索关键字不能为空！');
		$("#tsForm_2 #keys").focus();
	}
}
function topSearch3() {
	var keys= $("#tsForm_3 #keys").val();
	if(keys !="") {
		window.open('http://202.192.1.15:8080/smu_new/resource/articlelist.html?act=searchqk&keywords=(3)%2C('+keys+')%2C(and)|||%40%40%40%5B%5B(all%2Call)%5D%5D***%5B%5B(time)%5D%5D&searchtype=3&schooltype=8,10,115&form_id=6');
		//window.open('http://192.168.169.16:8080/poweb/s_search.jsp?searchFiled=1&KWord='+encodeURI(keys)+'&sClass=0','ts3'+Math.round());
	} else {
		alert('搜索关键字不能为空！');
		$("#tsForm_3 #keys").focus();
	}
}

function topSearch4() {
	var keys= $("#tsForm_4 #keys").val();
	var seachtype = $("#tsForm_4 input[name=searchtype]:checked").val();
	//alert (seachtype);
	//return;
	if(keys !="") {
		window.open('http://202.192.1.15:8080/smu_new/resource/articlelist.html?act=searchqk&keywords=('+seachtype+'),('+keys+'),(and)|||%40%40%40[[(all,all)]]***[[(time)]]&searchtype=3&schooltype=133,139,116,145,137,140,114,8,10,115&form_id=6');
		
		//window.open('http://scholar.google.com/scholar?q='+encodeURI(keys)+'&hl=zh-CN&btnG=%E6%90%9C%E7%B4%A2&lr=','ts4'+Math.round());
	} else {
		alert('搜索关键字不能为空！');
		$("#tsForm_4 #keys").focus();
	}
}

function topSearch5() {
	var keys= $("#tsForm_5 #keys").val();
	var seachtype = $("#tsForm_5 input[name=searchtype]:checked").val();
	if(keys !="") {
				$.ajax({
                    type: 'POST',
                    url: '/ajax/server.ashx?action=utf2gbk',
                    data: 'str=' + escape(keys),
                    success: function (data) {
						window.open('http://book.th.superlib.net/search?sw='+data+'&allsw=&bCon=&ecode=GBK&channel=search&Field='+seachtype);
                    },
                    error: function () {
                        alert("提交错误，请联系管理员！");
                        return false;
                    }
                });
	} else {
		alert('搜索关键字不能为空！');
		$("#tsForm_5 #keys").focus();
	}

}
