﻿/**
 * 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="current" onclick="return false;"' : '') + '>' + (i + 1) + '</a>');
            } else {
                document.write('<a href="' + _sPageName + '_' + i + '.' + _sPageExt + '"' + ((nCurrIndex == i) ? ' class="current" 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;">共' +  + _nPageCount + ' 页 </a>');
	}else{
	    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;
	}

	//alert(url+'||'+fileName);
    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();
		}
	});
    
})();

var format = function (vl) {
	var si = vl + 100000;
	var temp = si + '';
	var stext = (si + '').substr(1);
	document.write(stext);
};


/*
URL的参数&参数名1=XXXX&参数名2=XXXX&参数名3=XXXX  
alert(GetQueryString("参数名1")); 
alert(GetQueryString("参数名2")); 
alert(GetQueryString("参数名3"));
*/
var GetQueryString = function (name) { 
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); 
	var r = window.location.search.substr(1).match(reg); 
	if (r!=null) {
		return unescape(r[2]);
	}
	return null; 
};

/**
 * 跨域访问动态数据
 * 要访问session数据，必须用这种方式去访问，否则无法访问同一个session
 */
var dynamicScript = function (_oPs) {
    if (_oPs) {
        var script = "<script type=\"text/javascript\" src=\"" + _oPs.src + "\"></script>";
        $("body").append(script);
    }
};

var loginCheck = function (_oPs) {
    if (_oPs) {
        if (_oPs.logined) {
            
        } else {
			if (0 < window.location.href.indexOf("/nblm")) {
				window.location.href = "/";
			}
		}
    } else {
        var _sParams = $.param({
            method: "check",
            callback: "loginCheck",
			r: Math.random()
        });
        dynamicScript({src: "/gxwcm/loginAjax.jsp?" + _sParams});
    }
};


// 附件显示及下载处理
if($){


	var fjs = $("p.files a");
if(fjs){
if (0 === fjs.length) {
    var fjsp = $("p.files");
		fjsp.css({display: "none"});
	} else {
		fjs.click(function () {
			//download(this.innerHTML, this.href);
		//	return false;
		});
	}
}

$(function() {

	loginCheck();

	$("td").each(function(i, d) {
		if (!$.trim(d.innerHTML)) {
			d.innerHTML ="&nbsp;";
		}
	});

	// 最新导读
	var latestnews = $("#latestnews");
	if (0 < latestnews.length) {
		var RandomTime= new Date();
		var minute = RandomTime.getMinutes()

		$.ajax({
			url: "/gxwcm/zxdd/zxdd.jsp?r="+minute,
		    success: function(data) {
				if (data) {
					latestnews.html(data);
				}
			},
			error: function() {}
		});
	}

	var xxgkifr = $("iframe[name=target]")[0];
	if (xxgkifr) {
		var id = GetQueryString("id");
		if (id) {
			var lia = $("#" + id + " a")[0];
			if (lia) {
				xxgkifr.src = lia.href;
			}
		}
	}

    $("#xxgk div.ztfl").css("display", "none");
	var xxgkh3 = $("#xxgk h3");
	if (0 < xxgkh3.length) {
		xxgkh3.css("cursor", "pointer").click(function() {
			if (this.opened) {
				this.opened = false;
				$(this).next().css("display", "none");
			} else {
				xxgkh3.each(function(i, d) {
					if (d.opened) {
						$(d).click();
					}
				});
				this.opened = true;
				$(this).next().css("display", "block");
			}
		});
		xxgkh3[xxgkh3.length - 1].click();
	}

	window.SUM = [0, 0, 0];
	$("ul.menu_xxgk").each(function(i, d) {
		if (false) {
			return false;
		}
		$.ajax({
			url: "/gxwssb/pages/epb/front/xxkgfl/xxkgCount.jsp",
			data: {P_TYPE: i + 1, P_CHANNLEID: d.id, r: Math.random()},
			dataType: "json",
			success: function(data) {
				if (data) {
					c = data;
					$(d).children("li").each(function(j, dom) {
						window.c = 0;
						window.has = false;
						$(dom).children("ul.s_menu").children().each(function(k, e) {
							window.has = true;
							var cc = data[e.id];
							if (!cc) {
								cc = 0;
							}
							$(e).children("a").append("<font style=\"font-weight: normal;\" color=\"#858585\">(" + cc + ")</font>");
							window.c += cc;
						});
						if (window.has) {
							$(dom).children("a").append("<font style=\"font-weight: normal;\" color=\"#858585\">(" + window.c + ")</font>");
							window.SUM[i] += window.c;
						} else {
							var _c = data[dom.id];
							if (!_c) {
								_c = 0;
							}
							$(dom).children("a").append("<font style=\"font-weight: normal;\" color=\"#858585\">(" + _c + ")</font>");
							window.SUM[i] += _c;
						}
					});
					if (0 === i) {
						$($("div#xxgk h3")[i]).append("<font color=\"\">(" + data["null"] + ")</font>");
					} else {
						$($("div#xxgk h3")[i]).append("<font color=\"\">(" + window.SUM[i] + ")</font>");
					}
				}
			},
			error: function() {}
		});
		
	});

	$("#xxgk ul.s_menu").each(function(i, d) {
		if (0 === $(d).children("li").length) {
			$(d).parent().addClass("none");
		} else {
			$(d).css("display", "none");
			var p = $(d).parent();
			$(d).prev().prev().click(function() {
				if (this.opened) {
					this.opened = false;
					$(this).next().next().css("display", "none");
					p.removeClass("open");
				} else {
					$("#xxgk ul.s_menu").each(function(i, d) {
						var a = $(d).prev().prev()[0];
						if (a && a.opened) {
							$(a).click();
						}
					});

					this.opened = true;
					p.addClass("open");
					$(this).next().next().css("display", "block");
				}
				return false;
			});
		}
	});

	$("#xxgk ul.s_menu a").click(function(i, d) {
		$("#xxgk ul.s_menu a").removeClass("cur");
		$(this).addClass("cur");
	});

	$("#xxgktable table a").hover(function() {
		var left = $(this).offset().left;
		var top = $(this).offset().top;
		var bodyh = $("body").height();
		var h = $(this).next().height();
		var bottom = top + 8;
		$(this).next().css({
			"display": "block",
			left: left,
			top: (bottom > bodyh) ? (top - 8) : bottom
		});
	}, function() {
		$(this).next().css({
			"display": "none"
		});
	});

	$("div.mulu a").each(function(i, d) {
		var patha = $("div.path a");
		for (var i = patha.length - 1; i >= 0; i -= 1) {
			if (patha[i].innerHTML === d.innerHTML) {
				$(d).addClass("current");
				return false;
			}
		}
	});

	$("td.xxgkchannel").each(function(i, d) {
		d.innerHTML = getChannel(d.innerHTML);
	});

	$("div.maplist a").each(function(i, d) {
		if ("频道JS" === d.innerHTML || "最新导读" === d.innerHTML) {
			$(d).css("display", "none");
		}
	});

	var tqdate = $("#tqdate")[0];
	if (tqdate) {
		$.get("/tqdate.html?reqeustversion="+Math.random(),{},function(data){
		tqdate.innerHTML = data;
		//alert(data);
		});
	}
	
});

}
	
