﻿/**
 * TRS分页方法
 * @param _nPageCount 总页数
 * @param _nCurrIndex 当前页
 * @param _sPageName 文件名
 * @param _sPageExt 文件后缀
 * @param _nRecordCount 记录数
 */
function createPageHTML (_nPageCount, _nCurrIndex, _sPageName, _sPageExt, _nRecordCount) {
    if (_nPageCount && _nPageCount > 1) {
        document.write('<a href="' + _sPageName + '.' + _sPageExt + '" class="s1">首页</a>');
        var nCurrIndex = _nCurrIndex || 0;
        if (nCurrIndex == 0) {
            //document.write('<a href="#none">上一页</a>');
            //document.write('<a href="#none" class="s2">1</a>');
        } else {
            if (nCurrIndex == 1) {
                document.write('<a href="' + _sPageName + '.' + _sPageExt + '">上一页</a>');
            } else {
                document.write('<a href="' + _sPageName + '_' + (nCurrIndex - 1) + '.' + _sPageExt + '">上一页</a>');
            }
            //document.write('<a href="' + _sPageName + '.' + _sPageExt + '">1</a>');
        }
        for (var i = 0; i < _nPageCount; i++) {
            if (10 < _nPageCount && (i < (_nCurrIndex - 5) || i > (_nCurrIndex + 5))) {
                continue;
            }
            if (i == 0) {
                document.write('<a href="' + _sPageName + '.' + _sPageExt + '"' + ((nCurrIndex == i) ? ' class="s2" onclick="return false;"' : '') + '>' + (i + 1) + '</a>');
            } else {
                document.write('<a href="' + _sPageName + '_' + i + '.' + _sPageExt + '"' + ((nCurrIndex == i) ? ' class="s2" onclick="return false;"' : '') + '>' + (i + 1) + '</a>');
            }
        }
        if (nCurrIndex === (_nPageCount - 1) && _nPageCount > 1) {
            //document.write('<a href="#none">下一页</a>');
        } else {
            document.write('<a href="' + _sPageName + '_' + (nCurrIndex + 1) + '.' + _sPageExt + '">下一页</a>');
        }
        document.write('<a href="' + _sPageName + '_' + (_nPageCount - 1) + '.' + _sPageExt + '" class="s1">末页</a>');
    }
    if(_nRecordCount === "${RECORD_COUNT}"){
		_nRecordCount = 0;
	}
	//document.write('<a href="#none" class="s1" onclick="return false;">共' + _nRecordCount + '条</a>');
    document.write('<a href="#none" class="s4" onclick="return false;">共 ' + _nPageCount + ' 页 ' + _nRecordCount + ' 条</a>');
}

function flashNews(imgInfo, width, height,flushTime,fontSize,viewDivID){
    // imgs, urls, titles: flash的内容参数(关键点)
    // imgUrl: flash图片的路径, imgText: 图片的描述文字, imgLink: 图片和文字的链接地址
    var imgs = "";
    var titles = "";
    var urls = "";
    for (var i = 0; i < imgInfo.length; i++) {
        imgs += (i === 0 ? "" : "|") + imgInfo[i].imgUrl;
        titles += (i === 0 ? "" : "|") + imgInfo[i].imgText;
        urls += (i === 0 ? "" : "|") + imgInfo[i].imgLink;
    }
	
	var pw = width;
	var ph = height;
	var sizes = fontSize;
	var Times = flushTime;
	var umcolor = 0xFFFFFF;
	var btnbg =0xFF7E00;
	var txtcolor =0xFFFFFF;
	var txtoutcolor = 0x000000;
	var flash = new SWFObject('focus1.swf', 'mymovie', pw, ph, '7', '');
	flash.addParam('allowFullScreen', 'true');
	flash.addParam('allowScriptAccess', 'always');
	flash.addParam('quality', 'high');
	flash.addParam('wmode', 'Transparent');
	flash.addVariable('pw', pw);
	flash.addVariable('ph', ph);
	flash.addVariable('sizes', sizes);
	flash.addVariable('umcolor', umcolor);
	flash.addVariable('btnbg', btnbg);
	flash.addVariable('txtcolor', txtcolor);
	flash.addVariable('txtoutcolor', txtoutcolor);
	flash.addVariable('urls', urls);
	flash.addVariable('Times', Times);
	flash.addVariable('titles', titles);
	flash.addVariable('imgs', imgs);
	flash.write(viewDivID);
}

function flashNews(imgInfo, width, height, textHeight, contextPath) {

    // pics, links, texts: flash的内容参数(关键点)
    // imgUrl: flash图片的路径, imgText: 图片的描述文字, imgLink: 图片和文字的链接地址
    var pics = "";
    var texts = "";
    var links = "";
    for (var i = 0; i < imgInfo.length; i++) {
        pics += (i === 0 ? "" : "|") + imgInfo[i].imgUrl;
        texts += (i === 0 ? "" : "|") + imgInfo[i].imgText;
        links += (i === 0 ? "" : "|") + imgInfo[i].imgLink;
    }

    var swfHeight = height + textHeight;
    
    // flash的界面参数(外观)
    var flashVars = "pics=" + pics + "&texts=" + texts + "&links=" + links + "&borderwidth=" + width + "&borderheight=" + height + "&textheight=" + textHeight;
    var flash = "" +
        "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\"\n" +
        "    codebase=\"" + contextPath + "/swflash.cab#version=6,0,0,0\"\n" +
        "    width=\"" + width + "\" height=\"" + swfHeight + "\">\n" +
        "    <param name=\"allowScriptAccess\" value=\"sameDomain\">\n" +
        "    <param name=\"movie\" value=\"" + contextPath + "/pixviewer.swf\">\n" +
        "    <param name=\"quality\" value=\"high\">\n" +
        "    <param name=\"bgcolor\" value=\"#E3E3E3\">\n" +
        "    <param name=\"menu\" value=\"false\">\n" +
        "    <param name=wmode value=\"opaque\">\n" +
        "    <param name=\"FlashVars\" value=\"" + flashVars + "\">\n" +
        "    <embed src=\"" + contextPath + "/pixviewer.swf\" wmode=\"opaque\" FlashVars=\"" + flashVars + "\" \n" +
        "        menu=\"false\" bgcolor=\"#E3E3E3\" quality=\"high\" \n" +
        "        width=\"" + width + "\" height=\"" + height + "\" \n" +
        "        allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" \n" +
        "        pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />\n" +
        "</object>";
    
    document.writeln(flash);
}
//设置字体大小
function setFont(x)
{
	//alert(x);
  switch (x){
    case 1:
		document.getElementById("word").className="endbig";		
		document.getElementById("e_b").className="sel";
		document.getElementById("e_n").className="unsel";
		document.getElementById("e_s").className="unsel";
	break;
	case 2:
		document.getElementById("word").className="endnomal";
		document.getElementById("e_n").className="sel";
		document.getElementById("e_b").className="unsel";
		document.getElementById("e_s").className="unsel";
	break;
	case 3:
		document.getElementById("word").className="endsmall";
		document.getElementById("e_s").className="sel";
		document.getElementById("e_n").className="unsel";
		document.getElementById("e_b").className="unsel";
      break;
	}
} 
/**
*自适应高度
*/
function autoFitsHeight(object) {
    var height = object.contentWindow.document.documentElement.scrollHeight;
    object.style.height = height;
}
/**
 * 加入收藏夹
 * @param title
 * @param url
 */
function addFavorite(title, url) {
    if (window.sidebar) { 
        window.sidebar.addPanel(title, url, ""); 
    } else if (window.external) {
        window.external.AddFavorite(url, title);
    }
    return false;
}

function checkXgfj() {
    var xgfj = document.getElementById("xgfj");
    if (xgfj && xgfj.getElementsByTagName("a").length < 1) {
        xgfj.style.display = "none";
    }
}

function checkXgnr() {
    var xgnr = document.getElementById("xgnr");
    if (xgnr && xgnr.getElementsByTagName("a").length < 1) {
        xgnr.style.display = "none";
    }
}

/**
 * 为顶部菜单着色
 */
function colorMenu() {
    var c_p = document.getElementById("current_position");
    if (!c_p) {
        return;
    }
    var c_ps = c_p.value.split(">>")
    var menus = document.getElementById("menu");
    var as = menus.getElementsByTagName("a");
    end: for (var i = as.length - 1; i >= 0; i--) {
        for (var j = 0; j < c_ps.length; j++) {
            if (c_ps[j] === as[i].innerHTML) {
                as[i].className = "current";
                break end;
            }
        }
    }
}
/**
 * 附件下载调用的JS方法
 * @param url
 * @param fileName
 * @return
 */
function download(url, fileName) {

	if (url.lastIndexOf("/") === (url.length - 1)) {
		return false;
	}

    var form = document.getElementById("appendixform");
    document.getElementById("_path").value = url;
    document.getElementById("_fileName").value = fileName;
	//alert("url:"+url+"<------>fileName:"+fileName);
    form.submit();
    form = null;
    return false;
}
/***************************************
* 根据id查找document对象                                     *
****************************************/
function $E(id) {
	var obj = null;
	obj = document.getElementById(id);
	if(obj===null){
		try{
				var frm = document.forms[document.forms.length-1];
          		obj = frm[id];
		}catch(e){}
	}
	if(obj===null){
			try{
				obj = document.getElementsByName(id)[0];
     		}catch(e){}	
	}
    return obj;
}
(function () {
    window.setEvent = function (e, f) {
        window[e] = f;
    };
    
    window.appendEvent = function (e, f) {
        var preEvent = window[e];
        window[e] = function () {
            if (preEvent) {
                preEvent();
            }
            f();
        }
    };
    window.appendEvent("onload", checkXgfj);
	window.appendEvent("onload", colorMenu);	
    window.appendEvent("onload", function () {
		var e_n = document.getElementById("e_n");
		if (e_n && e_n.click) {
			document.getElementById("e_n").click();
		}
	});
    
})();