function bindEnter(event,objInput,perPage)
{
	if (event.keyCode==13)
	{
		var pageNum=objInput;
		gotoPageLib(pageNum,perPage);
	}
}

function gotoPage(objInput,perPage)
{
	var pageNum=$(objInput).parent().find("input.pl-text").val();
	gotoPageLib(pageNum,perPage);
}

function gotoPageLib(pageNum,perPage)
{
	var url=document.location.href;
	var page='';
	var pageIcon=url.indexOf("per_page");
	if(pageNum=='' || isNaN(pageNum))
	{
		alert('请输入页码');
		return false;
	}
	var fuhao=url.indexOf("?");
	if(pageIcon==-1)
	{
		if(fuhao==-1)
		{
			page=url+'?op=list&per_page='+perPage*(pageNum-1);
		}
		else
		{
			page=url+'&per_page='+perPage*(pageNum-1);
		}
	}
	else
	{
		var number='';
		var start=url.indexOf("per_page=");
		var end=url.indexOf("&",start);
		if(end==-1)
		{
			number=url.substring(Number(start)+9);
		}
		else
		{
			number=url.substr(Number(start)+9,end);
		}
		page=url.replace("per_page="+number,"per_page="+perPage*(pageNum-1));
	}
	window.location.href=page;
}

//cookie 
function SetCookie(name,value)
{
    var Days = 7;
    var exp  = new Date();
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString()+";path=/";
}
function getCookie(name)       
{
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return null;

}
function delCookie(name)
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}
//leftnav start
var oneMenu=getCookie('oneMenu');
var twoMenu=getCookie('twoMenu');
$().ready(function(){
	$("div .c_sub h5").each(function(i){
		$(this).next("ul").hide();
		$(this).click(function(){
			if(i==0)
			{
				return false;
			}
			SetCookie('oneMenu',i);
			if($(this).next("ul").is(":visible")==false)
			{
				$(this).next("ul").siblings(".sub1").hide();
				$(this).next("ul").show();
				$("div .c_sub").find("ul").first().show();
				if(i > 0)
				{
					showSubMenuDefault($(this));//h5
				}
			}
			else
			{
				$(this).next("ul").hide();
			}
		});
	});
	showDefaultMenu();
	//sub menu
	$("ul.sub1 li").each(function(k){
		$(this).click(function(){
			SetCookie('twoMenu',k);
			if($(this).find("ul").is(":visible")==false)
			{
				$(this).siblings().find("ul").hide();
				$(this).find("ul").show();
				$(this).find("span").show();
			}
			else
			{
				$(this).find("ul").hide();
			}
		});
	});
	if(oneMenu!=null && oneMenu>1)
	{
		$("div .c_sub h5").each(function(i){
			if(i==oneMenu){$(this).click();}
		})
	}
	if(twoMenu!=null && twoMenu >0)
	{
		$("ul.sub1 li").each(function(k){
			if(k==twoMenu){$(this).click();}
		});
	}
});
function showDefaultMenu()
{
	$("div .c_sub").find("ul").first().show();
	var showItem=$("div .c_sub").find("ul").eq(1);//default show
	showItem.show();
	showItem.find("li").find("ul").hide();
	showItem.find("li").eq(0).find("ul,li").show();
}
function showSubMenuDefault(root)
{
	root.next("ul").find("li").each(function(){
		$(this).find("ul").hide();
	});
	root.next("ul").find("li").first().find("ul").show();
}
//leftnav end

//topnav
$(document).ready(function () {		
	$('.topnav li').hover(
		function () {
			$('.hiddenbox', this).slideDown(100);
			$(this).addClass('current');
		}, 
		function () {
			//hide its submenu
			$('.hiddenbox', this).slideUp(100);	
			$(this).removeClass('current');
		}
	);

	$("#searchWhois").click(function(){
		var domain=$("#searchDomain").val();
		if(domain==""){alert('请输入要搜索WHOIS信息的域名');return false;}
		window.open("http://whois.ename.net/"+domain);
	});
	
});
//topnavnav end

//enterSearch
document.onkeydown = function (e) {
	if ($("#searchDomain").val() !== ""){
		var theEvent = window.event || e; 
		var code = theEvent.keyCode || theEvent.which; 
		if (code == 13) { 
			$("#searchWhois").click(); 
		} 
	}
}
//enterSearch end
