// cms function cms(applyTo) { this.id = document.uniqueID; window[this.id] = this; // call by template this.applyTo = applyTo; this.apply = function (id) { if (id == null && this.applyTo != null) { id = this.applyTo; } else { this.applyTo = id; } var html = this.xmlDoc.documentElement.transformNode(this.xslDoc.documentElement); document.getElementById(id).innerHTML = html; }; this.applyByDoc = function (doc,id) { if (id == null && this.applyTo != null) { id = this.applyTo; } else { this.applyTo = id; } var html = doc.documentElement.transformNode(this.xslDoc.documentElement); document.getElementById(id).innerHTML = html; }; this.applyByElement = function (element,id) { if (id == null && this.applyTo != null) { id = this.applyTo; } else { this.applyTo = id; } var html = element.transformNode(this.xslDoc.documentElement); document.getElementById(id).innerHTML = html; }; this.trans = function (xmlText, xsltFile) { var text; if (typeof (window.ActiveXObject) != "undefined") { // is IE try { var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0"); var xslDoc = new ActiveXObject("Msxml2.DOMDocument.3.0"); xmlDoc.async = false; xslDoc.async = false; xmlDoc.load(xmlText); xslDoc.load(xsltFile); text = xmlDoc.documentElement.transformNode(xslDoc.documentElement); } catch (e) { alert(e.name + ": " + e.message); alert("Unable to do xml/xsl processing"); alert(e.name + ": " + e.message); } } else { if (document.implementation && document.implementation.createDocument) { // is Mozilla try { var oParser = new DOMParser(); var xmlDoc = oParser.parseFromString(xmlText, "text/xml"); xslDoc = document.implementation.createDocument("", "", null); xslDoc.async = false; xslDoc.load(xsltFile); var xsltProcessor = new XSLTProcessor(); xsltProcessor.importStylesheet(xslDoc); var result = xsltProcessor.transformToDocument(xmlDoc); var xmls = new XMLSerializer(); text = xmls.serializeToString(result); } catch (e) { if (isDebug) { alert(e.name + ": " + e.message); } alert("Unable to do xml/xsl processing"); } } } return text; }; this.createDocFromXml = function (xml) { var xmlDoc; if (typeof (window.ActiveXObject) != "undefined") { xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0"); xmlDoc.async = false; xmlDoc.loadXML(xml); } return xmlDoc; }; this.createDoc = function (uri) { var xmlDoc; if (typeof (window.ActiveXObject) != "undefined") { xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0"); xmlDoc.async = false; xmlDoc.setProperty("ServerHTTPRequest", true); var ret = xmlDoc.load(uri); var xmlError = xmlDoc.parseError; if (ret == false && xmlError != null) { var error = xmlError.errorCode + " " + xmlError.reason + " " + uri; alert(error); } } return xmlDoc; }; this.setParam = function(name,value){ var node = this.xslDoc.selectSingleNode("xsl:stylesheet/xsl:param[@name='" + name + "']"); if (node != null) { node.text = value; } }; this.init = function() { }; this.dyniframesize = function(controlID) { var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1] //extra height in px to add to iframe in FireFox 1.0+ browsers var FFextraHeight=getFFVersion>=0.1? 16 : 0 var pTar = null; if (document.getElementById) { pTar = document.getElementById(controlID); } else { eval('pTar = ' + controlID + ';'); } if (pTar && !window.opera) { //begin resizing iframe //pTar.style.display="block" var h1=0, h2=0, h3=0; if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight)//如果用戶的瀏覽器是NetScape { //ns6 syntax h1 = pTar.contentDocument.body.offsetHeight+FFextraHeight; } else if(document.body) { h3=document.body.scrollHeight; } else if (pTar.Document && pTar.Document.body.scrollHeight)//如果用戶的瀏覽器是IE { //ie5+ syntax //alert(pTar.Document.body.scrollHeight) // pTar.height = pTar.Document.body.scrollHeight; h2=document.documentElement.scrollHeight; // pTar.height = screen.availHeight; // alert(pTar.height); } var h=Math.max(h1, h2); h=Math.max(h, h3); if(document.all) {h += 4;} if(window.opera) {h += 1;} pTar.height = h-132; //pTar.height = screen.availHeight-150; //alert(pTar.height); } }; } // cms_blog function cms_blog() { cms.call(this); cms_blog.prototype = new cms(); this.xmlDoc = this.createDoc("https://first-aviva.com.tw:80/cms/chn/content/tw/actNews/index.xml"); // 過濾不是 blog 的資料 var nodeList = this.xmlDoc.selectNodes("//prod_list[tpeId != 'CEO Blog']"); for(var x = 0; x < nodeList.length; x++) { nodeList[x].parentNode.removeChild(nodeList[x]); } this.xmlDoc.setProperty("SelectionLanguage", "XPath"); this.xslDoc = this.createDoc("https://first-aviva.com.tw:80/cms/code/blog/index.xsl"); var node = this.xslDoc.selectSingleNode("xsl:stylesheet/xsl:param[@name='callback']"); node.text = this.id; this.detail = function (p,url) { var detailDoc = this.xmlDoc.selectSingleNode("root/prod_list[position()=" + p + "]"); var detailXsl = this.createDoc("https://first-aviva.com.tw:80/cms/code/blog/detail.xsl"); var node = detailXsl.selectSingleNode("xsl:stylesheet/xsl:param[@name='callback']"); node.text = this.id; var html = detailDoc.transformNode(detailXsl.documentElement); document.getElementById(this.applyTo).innerHTML = html; }; } // cmd_indexNews function cms_indexNews(applyTo) { cms.call(this,applyTo); cms_indexNews.prototype = new cms(); this.xmlDoc = this.createDoc("https://first-aviva.com.tw:80/xmlResource?xml=news/index.xml"); this.xmlDoc.setProperty("SelectionLanguage", "XPath"); this.xslDoc = this.createDoc("https://first-aviva.com.tw:80/cms/code/indexNews/index.xsl"); var node = this.xslDoc.selectSingleNode("xsl:stylesheet/xsl:param[@name='callback']"); node.text = this.id; // 顯示最新的年份 this.selectYear = this.xmlDoc.selectSingleNode("//selectYear").text; this.pageNo = 0; this.detail = function(position,url) { // create frame to show the detail document.getElementById(this.applyTo).innerHTML = ""; window.frames["cmsDetail"].history.obj = this; window.frames["cmsDetail"].history.back = function() { this.obj.page(this.obj.pageNo,this.obj.selectYear); }; this.dyniframesize("cmsDetail"); }; this.filterYear = function(root,year) { // 過濾不是該年份的資料 this.setParam("selectYear",year); var nodeList = root.selectNodes("//prod_list[year != '" + year + "']"); for(var x = 0; x < nodeList.length; x++) { root.removeChild(nodeList[x]); } }; this.page = function (pageno,year) { var doc = this.createDocFromXml(this.xmlDoc.xml); var root = doc.documentElement; this.pageNo = pageno; this.selectYear = year; // 過濾不是該年份的資料 this.filterYear(root,year); // 分頁 var pages = 0; var records = root.selectNodes("//prod_list").length; var current = this.xslDoc.selectSingleNode("xsl:stylesheet/xsl:param[@name='current']"); var pageSize = this.xslDoc.selectSingleNode("xsl:stylesheet/xsl:param[@name='page']").text * 1; current.text = pageno; if (records % pageSize == 0) { pages = records / pageSize; } else { pages = (Math.floor(records / pageSize)) + 1; } this.xslDoc.selectSingleNode("xsl:stylesheet/xsl:param[@name='pages']").text = pages; // next var pre = 0; var next = 0; if ((pageno * 1) > 1) { pre = ((pageno * 1) - 1); } if ((pageno * 1) < (pages * 1)) { next = ((pageno * 1) + 1); } this.xslDoc.selectSingleNode("xsl:stylesheet/xsl:param[@name='pre']").text = pre; this.xslDoc.selectSingleNode("xsl:stylesheet/xsl:param[@name='next']").text = next; this.applyByDoc(doc,this.applyTo); }; } // newsReleases function cms_newsReleases(applyTo) { cms.call(this,applyTo); cms_newsReleases.prototype = new cms(); this.xmlDoc = this.createDoc("https://first-aviva.com.tw:80/xmlResource?xml=chn/content/tw/actNews/index.xml"); this.xmlDoc.setProperty("SelectionLanguage", "XPath"); this.xslDoc = this.createDoc("https://first-aviva.com.tw:80/cms/code/newsReleases/index.xsl"); var node = this.xslDoc.selectSingleNode("xsl:stylesheet/xsl:param[@name='callback']"); node.text = this.id; // 顯示最新的年份 this.pageNo = 0; this.selectYear = this.xmlDoc.selectSingleNode("//selectYear").text; // 過濾不是 new releases 的資料 var nodeList = this.xmlDoc.selectNodes("//prod_list[tpeId != 'News Releases']"); for(var x = 0; x < nodeList.length; x++) { nodeList[x].parentNode.removeChild(nodeList[x]); } this.detail = function(position,url) { // create frame to show the detail document.getElementById(this.applyTo).innerHTML = ""; window.frames["cmsDetail"].history.obj = this; window.frames["cmsDetail"].history.back = function() { this.obj.page(this.obj.pageNo,this.obj.selectYear); }; this.dyniframesize("cmsDetail"); }; this.filterYear = function(root,year) { // 過濾不是該年份的資料 this.setParam("selectYear",year); var nodeList = root.selectNodes("//prod_list[year != '" + year + "']"); for(var x = 0; x < nodeList.length; x++) { root.removeChild(nodeList[x]); } }; this.page = function (pageno,year) { var doc = this.createDocFromXml(this.xmlDoc.xml); var root = doc.documentElement; this.pageNo = pageno; this.selectYear = year; // 過濾不是該年份的資料 this.filterYear(root,year); // 分頁 var pages = 0; var records = root.selectNodes("//prod_list").length; var current = this.xslDoc.selectSingleNode("xsl:stylesheet/xsl:param[@name='current']"); var pageSize = this.xslDoc.selectSingleNode("xsl:stylesheet/xsl:param[@name='page']").text * 1; current.text = pageno; if (records % pageSize == 0) { pages = records / pageSize; } else { pages = (Math.floor(records / pageSize)) + 1; } this.xslDoc.selectSingleNode("xsl:stylesheet/xsl:param[@name='pages']").text = pages; // next var pre = 0; var next = 0; if ((pageno * 1) > 1) { pre = ((pageno * 1) - 1); } if ((pageno * 1) < (pages * 1)) { next = ((pageno * 1) + 1); } this.xslDoc.selectSingleNode("xsl:stylesheet/xsl:param[@name='pre']").text = pre; this.xslDoc.selectSingleNode("xsl:stylesheet/xsl:param[@name='next']").text = next; this.applyByDoc(doc,this.applyTo); }; } // index_news function cms_index_news() { cms.call(this); cms_index_news.prototype = new cms(); this.xmlDoc = this.createDoc("https://first-aviva.com.tw:80/cms/news/index.xml"); this.xmlDoc.setProperty("SelectionLanguage", "XPath"); this.xslDoc = this.createDoc("https://first-aviva.com.tw:80/cms/code/index/news/index.xsl"); this.dyniframesize("cms_index_news_div");; } // index_prods function cms_index_prods() { cms.call(this); cms_index_prods.prototype = new cms(); this.xmlDoc = this.createDoc("https://first-aviva.com.tw:80/cms/chn/content/tw/actNews/index.xml"); // 過濾不是 Promotion 的資料 var nodeList = this.xmlDoc.selectNodes("//prod_list[tpeId != 'Promotion']"); for(var x = 0; x < nodeList.length; x++) { nodeList[x].parentNode.removeChild(nodeList[x]); } this.xmlDoc.setProperty("SelectionLanguage", "XPath"); this.xslDoc = this.createDoc("https://first-aviva.com.tw:80/cms/code/index/products/index.xsl"); } // index_blog function cms_index_blog() { cms.call(this); cms_index_blog.prototype = new cms(); this.xmlDoc = this.createDoc("https://first-aviva.com.tw:80/cms/chn/content/tw/actNews/index.xml"); this.xmlDoc.setProperty("SelectionLanguage", "XPath"); // 過濾不是 blog 的資料 var nodeList = this.xmlDoc.selectNodes("//prod_list[tpeId != 'CEO Blog']"); for(var x = 0; x < nodeList.length; x++) { nodeList[x].parentNode.removeChild(nodeList[x]); } this.xslDoc = this.createDoc("https://first-aviva.com.tw:80/cms/code/index/blog/index.xsl"); } // cms_lifeInsur function cms_lifeInsur(applyTo) { cms.call(this,applyTo); cms_lifeInsur.prototype = new cms(); this.xmlDoc = this.createDoc("https://first-aviva.com.tw:80/xmlResource?xml=chn/content/tw/lifeInsur/index_1.xml"); this.xmlDoc.setProperty("SelectionLanguage", "XPath"); this.xslDoc = this.createDoc("https://first-aviva.com.tw:80/cms/code/lifeInsur/index.xsl"); var node = this.xslDoc.selectSingleNode("xsl:stylesheet/xsl:param[@name='callback']"); node.text = this.id; this.selectType = function (type) { var doc = this.createDocFromXml(this.xmlDoc.xml); var root = doc.documentElement; this.setParam("_selectType",type); var nodeList = null; if (type != '全部') { var typeList = root.selectNodes("/root/types/type"); for(var i = 0; i < typeList.length; i++) { var typeTag = typeList[i]; var prodList = typeTag.selectNodes("prod_list[tpeId != '" + type + "']"); for(var j = 0; j < prodList.length; j++) { typeTag.removeChild(prodList[j]); } } } this.applyByDoc(doc,this.applyTo); }; } // cms_lifeInsur_1 function cms_lifeInsur_1(applyTo) { cms.call(this,applyTo); cms_lifeInsur_1.prototype = new cms(); this.xmlDoc = this.createDoc("https://first-aviva.com.tw:80/xmlResource?xml=chn/content/tw/lifeInsur/index_2.xml"); this.xmlDoc.setProperty("SelectionLanguage", "XPath"); this.xslDoc = this.createDoc("https://first-aviva.com.tw:80/cms/code/lifeInsur/index.xsl"); var node = this.xslDoc.selectSingleNode("xsl:stylesheet/xsl:param[@name='callback']"); node.text = this.id; this.selectType = function (type) { var doc = this.createDocFromXml(this.xmlDoc.xml); var root = doc.documentElement; this.setParam("_selectType",type); var nodeList = null; if (type != '全部') { var typeList = root.selectNodes("/root/types/type"); for(var i = 0; i < typeList.length; i++) { var typeTag = typeList[i]; var prodList = typeTag.selectNodes("prod_list[tpeId != '" + type + "']"); for(var j = 0; j < prodList.length; j++) { typeTag.removeChild(prodList[j]); } } } this.applyByDoc(doc,this.applyTo); }; } // cms_lifeInsur_2 function cms_lifeInsur_2(applyTo) { cms.call(this,applyTo); cms_lifeInsur_2.prototype = new cms(); this.xmlDoc = this.createDoc("https://first-aviva.com.tw:80/xmlResource?xml=chn/content/tw/lifeInsur/index_3.xml"); this.xmlDoc.setProperty("SelectionLanguage", "XPath"); this.xslDoc = this.createDoc("https://first-aviva.com.tw:80/cms/code/lifeInsur/index.xsl"); var node = this.xslDoc.selectSingleNode("xsl:stylesheet/xsl:param[@name='callback']"); node.text = this.id; this.selectType = function (type) { var doc = this.createDocFromXml(this.xmlDoc.xml); var root = doc.documentElement; this.setParam("_selectType",type); var nodeList = null; if (type != '全部') { var typeList = root.selectNodes("/root/types/type"); for(var i = 0; i < typeList.length; i++) { var typeTag = typeList[i]; var prodList = typeTag.selectNodes("prod_list[tpeId != '" + type + "']"); for(var j = 0; j < prodList.length; j++) { typeTag.removeChild(prodList[j]); } } } this.applyByDoc(doc,this.applyTo); }; } // cms_prod function cms_prod(applyTo) { cms.call(this,applyTo); cms_prod.prototype = new cms(); this.xmlDoc = this.createDoc("https://first-aviva.com.tw:80/xmlResource?xml=cms-prod"); this.xmlDoc.setProperty("SelectionLanguage", "XPath"); // 過濾不是 prod 的資料 var nodeList = this.xmlDoc.selectNodes("//prod_list[tpeId != 'Investor Bi-weekly Updates']"); for(var x = 0; x < nodeList.length; x++) { nodeList[x].parentNode.removeChild(nodeList[x]); } this.xslDoc = this.createDoc("https://first-aviva.com.tw:80/cms/code/prod/index.xsl"); var node = this.xslDoc.selectSingleNode("xsl:stylesheet/xsl:param[@name='callback']"); node.text = this.id; // 顯示最新的年份 this.selectYear = this.xmlDoc.selectSingleNode("//selectYear").text; // 顯示最新的月份 this.selectMonth = this.xmlDoc.selectSingleNode("//selectMonth").text; this.pageNo = 0; this.detail = function(position,url) { // create frame to show the detail document.getElementById(this.applyTo).innerHTML = ""; window.frames["cmsDetail"].history.obj = this; window.frames["cmsDetail"].history.back = function() { this.obj.page(this.obj.pageNo,this.obj.selectYear,obj.selectMonth); }; this.dyniframesize(this.applyTo); }; this.filterYear = function(root,year,month) { // 過濾資料 this.setParam("selectYear",year); if (year != '') { var nodeList = root.selectNodes("//prod_list[year != '" + year + "']"); if (nodeList != null) { for(var x = 0; x < nodeList.length; x++) { root.removeChild(nodeList[x]); } } } this.setParam("selectMonth",month); if (month != '') { nodeList = root.selectNodes("//prod_list[month != '" + month + "']"); if (nodeList != null) { for(var x = 0; x < nodeList.length; x++) { root.removeChild(nodeList[x]); } } } //alert(root.xml); }; this.page = function (pageno,year,month) { var doc = this.createDocFromXml(this.xmlDoc.xml); var root = doc.documentElement; this.pageNo = pageno; this.selectYear = year; this.selectMonth = month; // 過濾不是該年份的資料 this.filterYear(root,year,month); // 分頁 var pages = 0; var records = root.selectNodes("//prod_list").length; var current = this.xslDoc.selectSingleNode("xsl:stylesheet/xsl:param[@name='current']"); var pageSize = this.xslDoc.selectSingleNode("xsl:stylesheet/xsl:param[@name='page']").text * 1; current.text = pageno; if (records % pageSize == 0) { pages = records / pageSize; } else { pages = (Math.floor(records / pageSize)) + 1; } this.xslDoc.selectSingleNode("xsl:stylesheet/xsl:param[@name='pages']").text = pages; // next var pre = 0; var next = 0; if ((pageno * 1) > 1) { pre = ((pageno * 1) - 1); } if ((pageno * 1) < (pages * 1)) { next = ((pageno * 1) + 1); } this.xslDoc.selectSingleNode("xsl:stylesheet/xsl:param[@name='pre']").text = pre; this.xslDoc.selectSingleNode("xsl:stylesheet/xsl:param[@name='next']").text = next; this.applyByDoc(doc,this.applyTo); }; }