/** * Library to be used when a page is called by the overlay mechanism * Show panel must be called by the source page to invoke the overlay page * The source page must implement the functions * o beforeOverlay (typically to hide the division of the source page), is called before * any action is taken to load the overlay panel. * o onOverlayLoad (typically to generate dynamic html on the overlay page), is called * when the overlay source has been loaded and panel is set visible. * o afterOverlay (typically to show the division of the source page), is called when * the user leaves the overlay panel and the source panel is back visible. * The target page must call codeSelected() when done */ var callback; var afterCall; function getClient() { var xmlhttp=null; try { xmlhttp = new XMLHttpRequest(); } catch (e) {} if (xmlhttp != null) return xmlhttp; try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {} if (xmlhttp != null) return xmlhttp; try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) {} return xmlhttp; } /** * Open a new panel to the given page. * @param target : the page to be loaded */ function showPanel(target, funct, after, errDivName) { beforeOverlay(); callback = funct; afterCall = after; // var client = new XMLHttpRequest(); var client = getClient(); client.open("GET", target, true); client.onreadystatechange = function() { if(client.readyState == 4) { if (client.status != 999) showPanelContent(client.responseText); else { alert(client.responseText); var errDesc = document.getElementById(errDivName); if (errDesc != null) errDesc.innerHTML = client.responseText; if (afterCall != null) afterCall(); } } } //Note: Firefox does not have the "client.send()" function signature required by the standard, hence the following: client.send(null); } function showPanelContent(content){ var panel = document.getElementById("overlayPanel"); if (panel == null) throw new Exception("A div named overlayPanel must exist in the source page"); //we need to restore the height since we may have collapsed it previously (see the codeSelected function) panel.innerHTML = content; var style = panel.style.cssText; style = style.replace(/display:\s*none/i, "display: block"); panel.style.cssText = style; if (afterCall != null) afterCall(); } function highlightOnLoad(searchItem,activateFilter) { var tagsArray = new Array(); if(searchItem == null) searchItem = ""; // If trim.length == 0 if(searchItem.replace(/ /gi,"").length<=0) return; tagsArray.push("td"); tagsArray.push("span"); highlightArray(searchItem, tagsArray,activateFilter); } function highlightArray(searchedStr, tagsArray, activateFilter) { if (activateFilter==null) activateFilter = false; if(searchedStr == null || searchedStr.length<=0) return; if(tagsArray==null) return; // "or" and "and" are terms delimiters var splitter =new RegExp(" or | and ","ig"); var searchTerms = searchedStr.split(splitter); // If exact String (between "...") taken the exact string only if(searchedStr.charAt(0)=='"' && searchedStr.charAt(searchedStr.length-1)=='"') { searchTerms = new Array(); searchedStr = searchedStr.substring(1,searchedStr.length-1); searchTerms.push(searchedStr); } // table of terms trimed var i=0; for (i=0; i=0 || currentNode.className.indexOf("chapter")>=0)){ if (activateFilter){ currentNode.style.display = 'none'; } else if (currentNode.id != "section" && currentNode.id != "chapter"){ currentNode.style.display = 'block'; } } else { currentNode2 = currentNode.parentNode.parentNode.parentNode.parentNode; if (currentNode2.className != null && currentNode2.className.indexOf("nomenclaturecode")>=0) { if (activateFilter){ currentNode2.style.display = 'none'; } else if (currentNode2.id.indexOf("to_be_copied")<0){ currentNode2.style.display = 'block'; } } } continue; } descriptions[descr].innerHTML = highlight(descriptions[descr].innerHTML, cleanSearchTerm.toUpperCase().replace(" ", "( | )"), cleanSearchTerm); // pattern search for specific cases like "10 kg" "12 %" ... } } } } function highlight(text, regStr, originalString) { if (text==undefined || text == null) return; var toProcess = text; var reg = new RegExp(regStr,"gi"); var splitDescr = toProcess.split(reg); var matches = toProcess.match(reg); var finalString = ""; for (var idxSplit = 0; idxSplit < splitDescr.length; idxSplit++) { finalString += splitDescr[idxSplit]; if (idxSplit < matches.length) finalString += ""+matches[idxSplit]+""; } return finalString; } /** * Function called by the overlay page when values have been selected. In addition to call the callback set by * the calling page with the parameters, this method hide the overlay panel and reset the scrolling information. * @param v may be a string or an array of object. */ function codeSelected(v){ callback(v); //if we had scrolled the overlay, we need to reposition the viewport, or else the main panel will reappear //with the same scrolling //if the overlayPanel caused a scrollbar to appear or expand, it will not be restored to its correct state // unless we collapse the overlayPanel (simply hiding the overlayPanel is not sufficient) hideOverlayPanel(); afterOverlay(); } function hideOverlayPanel(){ var panel = document.getElementById("overlayPanel"); var style = panel.style.cssText; style = style.replace(/display:\s*block/i, "display: none"); panel.style.cssText = style; panel.innerHTML=""; } function trimStr (myString) { var str = myString.replace(/^\s+/g,'').replace(/\s+$/g,''); str = str.replace(/^\'/g,'').replace(/\'$/g,''); return str; } function prepareCalendarPanel(dateStr, language) { var url = "calendar/calendar.jsp"; if(language != null) url += "?Lang="+language; var connectCallback = { success: function(o) { var msg = "OK : status = " + o.status + "\nstatusText = " + o.statusText + " \nresponse = " + o.responseText; calendarPanel.body.innerHTML = o.responseText; }, failure: function(o) { var msg = "NOK : status = " + o.status + "\nstatusText = " + o.statusText + " \nresponse = " + o.responseText; }, cache:false } var transaction = YAHOO.util.Connect.asyncRequest('GET', url, connectCallback, null) transaction.conn.onreadystatechange = function() { if(transaction.conn.readyState == 4) { calendarPanel.setHeader(""); calendarPanel.setBody(transaction); calendarPanel.render(); } }; } function showTaricConsultationCalendar(dateStr, dateParameterName, language, event, keepParam) { overlayTarConsultPanelClicked=true; showCalendarModalPanel(dateStr, dateParameterName, language, event, keepParam); } function showRegulationSearchCalendarModalPanel(dateStr, dateParameterName, language, event, keepParam) { overlayRegulationSearchConsultPanelClicked=true; showCalendarModalPanel(dateStr, dateParameterName, language, event, keepParam); } function showGeoSearchCalendarModalPanel(dateStr, dateParameterName, language, event, keepParam) { overlayGeoSearchConsultPanelClicked=true; showCalendarModalPanel(dateStr, dateParameterName, language, event, keepParam); } function showCalendarModalPanel(dateStr, dateParameterName, language, event, keepParam) { var x = event.clientX + document.body.scrollLeft; var y = event.clientY + document.body.scrollTop; calendarPanel.moveTo(x, y); document.getElementById("calendar_panel").style.display = "block"; calendarPanel.show(); var date = new Date(); if (dateStr.length == 8){ date = new Date(); var month = parseInt(dateStr.substring(4,6),10);//month 0-11 if(isValidDate(dateStr.substring(0,4),month,dateStr.substring(6,8))) month = month -1; date.setFullYear(dateStr.substring(0,4),month,dateStr.substring(6,8)); } reload(date.getTime(), dateParameterName, keepParam); document.getElementById("input_day").focus(); document.getElementById("input_day").select(); } function buildDate(dateStr) { var date = new Date(); if (dateStr.length == 8){ date = new Date(); var month = parseInt(dateStr.substring(4,6),10);//month 0-11 if(isValidDate(dateStr.substring(0,4),month,dateStr.substring(6,8))) month = month -1; date.setFullYear(dateStr.substring(0,4),month,dateStr.substring(6,8)); } var monthStr = ""+(date.getMonth()+1); if(monthStr.length==1) monthStr = "0"+monthStr; var dayStr = ""+date.getDate(); if(dayStr.length==1) dayStr = "0"+dayStr; return date.getFullYear()+""+monthStr+""+dayStr; } function closeCalendar(event) { if(canCloseModalPanel(calendarPanel, event)) { calendarPanel.hide(); } } function closeCountryChoice(event) { if(canCloseModalPanel(countryPanel, event)) { countryPanel.hide(); } } function showCountryModalPanel(dateStr, language, event, zone) { overlayTarConsultPanelClicked=true; if (document.getElementById("dropDown").disabled) return; document.getElementById("dropDown").disabled=true; var link = new url("include/country_selection.jsp"); link.setParameter("SimDate",dateStr); link.setParameter("Lang",language); link.setParameter("Code",document.getElementById("taricArea").value); var connectCallback = { success: function(o) { var msg = "OK : status = " + o.status + "\nstatusText = " + o.statusText + " \nresponse = " + o.responseText; countryPanel.body.innerHTML = o.responseText; }, failure: function(o) { var msg = "NOK : status = " + o.status + "\nstatusText = " + o.statusText + " \nresponse = " + o.responseText; }, cache:false } var curleft = 0; var curtop = zone.offsetHeight; do { curleft += zone.offsetLeft; curtop += zone.offsetTop; } while (zone = zone.offsetParent); var x = curleft; var y = curtop; var transaction = YAHOO.util.Connect.asyncRequest('GET', link.currentUrl, connectCallback, null) transaction.conn.onreadystatechange = function() { if(transaction.conn.readyState == 4) { countryPanel.setHeader(""); countryPanel.setBody(transaction); countryPanel.render(); countryPanel.moveTo(x, y); document.getElementById("country_panel").style.display = "block"; countryPanel.show(); document.getElementById("dropDown").disabled=false; } }; } function expandGoods(code) { var link = new url(window.location.href); link.setParameter("Taric",code); link.setParameter("Expand","true"); link.setParameter("Screen","0"); if(code!=null) { var codeOnTen = code; while(codeOnTen.length != 10) { codeOnTen = codeOnTen+"0"; } window.location.href = link.currentUrl+"#"+codeOnTen; } else window.location.href = link.currentUrl; } function closeTarConsultOverlayPanels(event) { if(overlayTarConsultPanelClicked==true) overlayTarConsultPanelClicked=false; else { closeCalendar(event); } } function closeGeoSearchOverlayPanels(event) { if(overlayGeoSearchConsultPanelClicked==true) overlayGeoSearchConsultPanelClicked=false; else { closeCalendar(event); } } function closeRegulationSearchOverlayPanels(event) { if(overlayRegulationSearchConsultPanelClicked==true) overlayRegulationSearchConsultPanelClicked=false; else { closeCalendar(event); } } function canCloseModalPanel(panel, event) { if (event==null) return true; if(panel==null) return false; var cursorX = event.clientX + document.body.scrollLeft; var cursorY = event.clientY + document.body.scrollTop; var panelX = panel.cfg.config.x.value; var panelY = panel.cfg.config.y.value; if(panel.body == null) return true; var panelWidth = panel.body.offsetWidth; var panelHeight = panel.body.offsetHeight; if( cursorX < panelX || cursorY < panelY || cursorX > (0+parseInt(panelX)+parseInt(panelWidth)) || cursorY > (0+parseInt(panelY)+parseInt(panelHeight))) { return true; } else return false; } function isValidDate(year, month, day) { var date = new Date(); date.setFullYear(year,(month-1),day); if(year != date.getFullYear()) return null; if(month != date.getMonth()+1) return null; if(day != date.getDate()) return null; return date; } function isNumeric(text) { var validChars = "0123456789"; var char; for (i = 0; i < text.length; i++) { char = text.charAt(i); if (validChars.indexOf(char) == -1) { return false; } } return true; } function loadjs(file) { //Create a 'script' element var scrptE = document.createElement("script"); //Set 'type' and 'language' attribs scrptE.setAttribute("type", "text/javascript"); scrptE.setAttribute("language", "JavaScript"); scrptE.setAttribute("src", file); // create an object of the head element of current page var hdEl = document.getElementsByTagName("head")[0]; //check for previously appended child //(it ensures that each time the button is pressed it // removes the previously loaded script element) if (hdEl.childNodes.length > 1) { hdEl.removeChild(hdEl.lastChild); } hdEl.appendChild(scrptE); }