﻿var _mrptPS="p";
var _mrptCP=1;
var _mrptMP=1;
var _mrptURE=false;
var _mrptURF="";

function $(obj)
{
	if (typeof(obj) == 'object')
	{
		return obj;
	}
	else
	{
		return document.getElementById(obj);
	}	
}

function $Q(item)
{
	var sValue=location.search.match(new RegExp("[\?\&]"+item+"=([^\&]*)(\&?)","i"));
	return sValue?sValue.toString().split(",")[1]:null; 
}

function lhGotoPage()
{
    var url = document.URL.toString();
    var toPage = parseInt($("lhGoPage").value);
    if(toPage && toPage>0)
    {
        if(toPage==_mrptCP) return;
        if(toPage>_mrptMP)
        {
            alert("对不起！当前信息最多为 "+_mrptMP+" 页");
            $("lhGoPage").focus();
            return;
        }
        if(_mrptURE)
        {
            url = "http://" + document.domain + _mrptURF.replace("{0}",toPage);
        }
        else
        {
            if(toPage==parseInt($Q(_mrptPS))) return;
            if (url.indexOf(_mrptPS + "=") >  -1)
            {
                url = url.replace(_mrptPS + "=" + $Q(_mrptPS), _mrptPS+"=" + toPage);
            }
            else if (url.indexOf("?") ==  -1)
            {
                url += "?"+_mrptPS+"=" + toPage;
            }
            else
            {
                url += "&"+_mrptPS+"=" + toPage;
            }
        }
        window.location = url;
    }
    else
    {
        alert("请输入正整数");
        $("lhGoPage").value="";
        $("lhGoPage").focus();
    }
}

function SetPage()
{
    if($("lhGoPage"))
    {
        var page=$("lhGoPage");
        page.value=_mrptCP;
        page.onfocus=function(){this.value="";document.onkeydown=GotoPageOnKeyDown;};
        page.onblur=function(){if(this.value=="")this.value=_mrptCP;document.onkeydown=function(){}};
    }
}

function GotoPageOnKeyDown(e)
{
    if(!e) e = window.event;
    if(e.keyCode == 13)
    {
        e.keyCode = 9;
        lhGotoPage();
        $("lhGoPage").focus();
        if(e.keyCode==9) return false;
    }
}