﻿// JavaScript Document

//概览分页代码
var pageCount,pageName,pageExt;
function createPageHTML(_ChnlCount,_nPageCount, _nCurrIndex, _sPageName, _sPageExt){
	if(_nPageCount == null || _nPageCount<=1){
		return;
	}

	var nCurrIndex = _nCurrIndex || 0;
	var s = "<span>总共" + _nPageCount + "页<\/span>&nbsp;<span>共" + _ChnlCount + "条<\/span>&nbsp;<span>当前第<\/span>" + (_nCurrIndex+1) + "<span>页<\/span>&nbsp;";
	
	if(nCurrIndex == 0){
		s = s + "<a disabled=\"disabled\">首页<\/a>";
		s = s + "<a disabled=\"disabled\">上一页<\/a>";
		s = s + "1";
	}
	else{
		s = s + "<a href=\"" + _sPageName  + "." + _sPageExt + "\">首页<\/a>";
		s = s + "<a href=\"" + _sPageName  + ( ( nCurrIndex ==1) ? "" :("_" + (nCurrIndex-1)) ) + "." + _sPageExt + "\">上一页<\/a>";
		s = s + "<a href=\"" + _sPageName  + "." + _sPageExt + "\">1<\/a>";
	}
	
	if (nCurrIndex >4){
		s = s + "<a disabled>..<\/a>"
	}
	//  ... 3 4 5 6  *  8 9 10 11 ..
	for(var i= ( (nCurrIndex >4)?(nCurrIndex-3):1 ); i < nCurrIndex; i++){
		s = s + "<a href=\"" + _sPageName + "_" + i + "." + _sPageExt + "\">" + (i+1) + "<\/a>";
	}
	//49
	if ( nCurrIndex > 0 && nCurrIndex < (_nPageCount-1) ){
		s = s + (nCurrIndex+1) ;
	}
	//48  i=49  -50
	for(var i= (nCurrIndex+1); i < ( (nCurrIndex+4)<_nPageCount ? ( nCurrIndex+4) : (_nPageCount-1) ); i++){
		s = s + "<a href=\"" + _sPageName + "_" + i + "." + _sPageExt + "\">" + (i+1) + "<\/a>";
	}
	if ((nCurrIndex+4)<_nPageCount){
		s = s + "<a disabled>..<\/a>"
	}
	
	
	if(nCurrIndex == (_nPageCount - 1)){
		s = s +  _nPageCount ;
		s = s + "<a disabled=\"disabled\">下一页<\/a>";
		s = s + "<a disabled=\"disabled\">尾页<\/a>";
	}
	else{
		s = s + "<a href=\"" + _sPageName  + "_" + ( _nPageCount - 1 ) + "." + _sPageExt + "\">" + _nPageCount + "<\/a>";
		s = s + "<a href=\"" + _sPageName  + "_" + (  nCurrIndex + 1 ) + "." + _sPageExt + "\">下一页<\/a>";
		s = s + "<a href=\"" + _sPageName  + "_" + ( _nPageCount - 1 ) + "." + _sPageExt + "\">尾页<\/a>";
	}
	
	s = s + "&nbsp;<span>转到第<\/span><input type='text' name='thisNum' id='thisNum' class='lb_input' onkeypress='if (event.keyCode < 45 || event.keyCode > 57 ) event.returnValue = false;' \/><span>页<\/span>";
    s = s + "<label><input type='submit' name='button' id='button' value='go' class='go' onclick='toPage()' \/><\/label>";
	
	pageCount = _nPageCount;
	pageName = _sPageName;
	pageExt = _sPageExt;
	
	$("#page_bar").html(s);
}
function toPage(){
	thisPageNum = thisNum.value;
	if (thisPageNum <= 1) thisPageNum = 1;
	else if (thisPageNum >= pageCount) thisPageNum = pageCount;
	if (thisPageNum == 1){
		window.location.href = pageName + "." + pageExt;
	}
	else{
		window.location.href = pageName + "_" + (thisPageNum-1) + "." + pageExt;
	}
}

//细览简单的分页代码
function createDetailPageHTML(_nPageCount, _nCurrIndex, _sPageName, _sPageExt){
	if(_nPageCount == null || _nPageCount<=1){
		return;
	}
	var s = "";
	var nCurrIndex = _nCurrIndex || 0;
	if(nCurrIndex == 0)
		s = s + "1&nbsp;";
	else
		s = s + "<a href=\""+_sPageName+"."+_sPageExt+"\">1</a>&nbsp;";

	for(var i=1; i<_nPageCount; i++){
		if(nCurrIndex == i)
			s = s + (i+1) + "&nbsp;";
		else
			s = s + "<a href=\""+_sPageName+"_" + i + "."+_sPageExt+"\">"+(i+1)+"</a>&nbsp;";
	}
	$("#page_bar").html(s);
}



//高级搜索按钮
function initSearchForm(){
//alert("11111");
$("#button_advsearch").click(function(){window.location.href="/search/"});

$("#putsearchword").focus(function(){if ($("#putsearchword").val() == "站内搜索") $("#putsearchword").val("")});
//简单搜索accept-charset="utf-8"
$("#searchForm").submit(function(){
	var s = $("#putsearchword").val();
	//alert(s);
	if(s == "" || s == "站内搜索"){
		alert("请输入搜索关键词");$("#searchForm #searchword").focus();return false;
	}else{
		$("#searchForm #searchword").val("like("+s+")");
		return true;
	}
	});

}
$(document).ready(function(){initSearchForm();});


//网站纠错


