﻿var c = GetArgsFromHref(window.location.href,"c");
var v = GetArgsFromHref(window.location.href,"v");
var t = GetArgsFromHref(window.location.href,"t");
var siteID = 2;
if(t=="")
	document.write('<script src="http://hotpic.sky-fire.com/Utility/'+c+'/'+v+'.js"></script>');
else document.write('<script src="http://hotpic.sky-fire.com/Utility/'+c+'/'+t+'/'+v+'.js"></script>');

var curIndex = GetArgsFromHref(window.location.href, "p");
function NextPage()
{
    if(curIndex<picCount){
    curIndex++;
	window.location.href = window.location.href.replace(/p=(\d+)/i,"p="+curIndex);
    }
    else window.location.href = "http://comic.sky-fire.com/LastPage/?c="+GetArgsFromHref(window.location.href,"c")+"&v="+nv+"&siteID="+siteID;
}
function NextVolume()
{
    window.location.href = nextVolume;
}

function PrePage()
{
    if(curIndex>1){
	curIndex--;
	window.location.href = window.location.href.replace(/p=(\d+)/i,"p="+curIndex);
    }
    else alert("已经是第一页拉!! :)");
}
function PreVolume()
{
    window.location.href = preVolume;
}
function FirstPage()
{
    if(curIndex!=1){
	curIndex = 1;
	window.location.href = window.location.href.replace(/p=(\d+)/i,"p="+curIndex);
    }
    else alert("已经是第一页拉!! :)");
}

function LastPage()
{
    if(curIndex!=picCount){
	curIndex = picCount;
	window.location.href = window.location.href.replace(/p=(\d+)/i,"p="+curIndex);
    }
    else alert("已经是最后一页拉!! :)");
}

function GoSelPage()
{
    if(curIndex!=document.getElementById("pageSel").value){
	curIndex = document.getElementById("pageSel").value;
	window.location.href = window.location.href.replace(/p=(\d+)/i,"p="+curIndex);
    }

}

function InitialList()
{
    document.getElementById("CurrentPage").innerHTML = curIndex;
    document.getElementById("TotalPage").innerHTML = picCount+1;
    var i;
    for(i = 1;i<=picCount;i++)
    {
	document.getElementById("pageSel").options[i-1] = new Option('第'+i+'页',i);
    }
}

document.onkeydown = function(evt)
{
  evt = evt ? evt : (window.event ? window.event : null);
  if (evt.keyCode == 65)
  {
      NextPage();
  }
  if (evt.keyCode == 81)
  {
      PrePage();
  }
 }

function GetArgsFromHref(sHref, sArgName) 
{ 
    var args = sHref.split("?"); 
    var retval = ""; 

    if(args[0] == sHref) /*参数为空*/ 
    { 
        return retval; /*无需做任何处理*/ 
    } 
    var str = args[1]; 
    args = str.split("&"); 
    for(var i = 0; i < args.length; i ++) 
    { 
        str = args[i]; 
        var arg = str.split("="); 
        if(arg.length <= 1) continue; 
        if(arg[0] == sArgName) retval = arg[1]; 
    } 
    return retval; 
}