function httpGet(object, url) { object.open("GET", url, true); object.send(null); } function getXHTTPObject() { var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); return x; } function loadJsAsync(url) { var x = getXHTTPObject(); x.onreadystatechange = function() { if (x.readyState == 4 && x.status == 200) { var headTag = document.getElementsByTagName('head')[0]; setjs = document.createElement('script'); setjs.setAttribute('type', 'text/javascript'); headTag.appendChild(setjs); setjs.text = x.responseText; loadCount++; if (loadCount == 6) { setTimeout('onScriptsLoaded()', 1); } } } httpGet(x, url); } function showContentPreload(){ var contentElement = document.getElementById('contentPreload'); contentElement.style.display = 'block'; } function hideContentPreload(){ var contentElement = document.getElementById('contentPreload'); contentElement.style.display = 'none'; } function loadContent(title, contentType, id) { var x = getXHTTPObject(); x.onreadystatechange = function() { if (x.readyState == 4 && x.status == 200) { hideContentPreload(); contentElement = document.getElementById('content_column'); contentElement.innerHTML = x.responseText; document.title = title + ' VALSTYBINĖ TERITORIJŲ PLANAVIMO IR STATYBOS INSPEKCIJA prie Aplinkos ministerijos'; if('' != contentType && '' != id){ window.location.href = appendHashToCurrentUrl("#" + contentType + "/" + id); } window.scroll(0,0); if(contentType == 'a' || contentType == 'r') { var links = contentElement.getElementsByTagName("a"); for(var i = 0; i < links.length; i++){ var link = links[i]; if(link.hash != "" && (link.hash.indexOf('r/') > 0 || link.hash.indexOf('a/') > 0) && ( link.hostname != "" && link.hostname == window.location.hostname || link.hostname == "" && link.pathname.indexOf('index.php') >0 ) && (!link.onclick || link.onclick == null) ) { //alert("OK " + link + " onclick: " + link.onclick); addEvent(link, 'click', function(){loadByUrl("", this.hash);return false;}); } else { //alert("NO: " + link + " onclick: " + link.onclick + " host " + link.hostname + " =? " + window.location.hostname + " pathname: " + link.pathname.indexOf('index.php') ); } } } } } showContentPreload(); var url = ''; if (contentType == 'r') { url = 'http://www.vtpsi.lt/rubric-new.php?rubric_id=' } else if (contentType == 'a') { url = 'http://www.vtpsi.lt/article-new.php?article_id=' } else if (contentType == 'news') { url = 'http://www.vtpsi.lt/news.php'; id = ''; } else { hideContentPreload(); return; } url = url + id; httpGet(x, url); } function loadSearchResults(q, start){ var x = getXHTTPObject(); x.onreadystatechange = function() { if (x.readyState == 4 && x.status == 200) { hideContentPreload(); var contentElement = document.getElementById('content_column'); contentElement.innerHTML = x.responseText; document.title = 'Paieškos rezultatai - VALSTYBINĖ TERITORIJŲ PLANAVIMO IR STATYBOS INSPEKCIJA PRIE APLINKOS MINISTERIJOS '; } } showContentPreload(); q = escape(q); httpGet(x, "http://www.vtpsi.lt/searchGoogleRes.php?q=" + q + "&start=" + start); } function loadNavigationLine(contentType, id) { var x = getXHTTPObject(); x.onreadystatechange = function() { if (x.readyState == 4 && x.status == 200) { var contentElement = document.getElementById('navigationPath'); contentElement.innerHTML = x.responseText; } } var url = "http://www.vtpsi.lt/navigationPath.php"; if ('a' == contentType) { url = url + "?aid="; } else { url = url + "?rid="; } url = url + id; httpGet(x, url); } function loadByUrl(title, newUrl) { var newUrlHash = ''; debug('lUrl: ' + newUrl); if (0 == arguments.length) { newUrl = window.location.href; newUrlHash = window.location.hash; title = ''; } else { if('#' == newUrl.charAt(0)){ newUrlHash = newUrl; newUrl = appendHashToCurrentUrl(newUrl); } else { newUrlHash = getHashFromUrl(newUrl); } } if (lastUrlLoaded == newUrl) { return; } lastUrlLoaded = newUrl; if (document.iframesfix) { document.getElementById('ajaxnav').setAttribute('src', 'http://www.vtpsi.lt/mock-page.php?currHash=' + newUrlHash.substr(1, newUrlHash.length-1)); } //alert('title: ' + title + ' newUrl: ' + newUrl + ' newUrlhash: ' + newUrlHash); if ('' != newUrlHash) { var ct = newUrlHash.substr(1, 1); var id = newUrlHash.substr(3, newUrlHash.length - 1); loadContent(title, ct, id); loadNavigationLine(ct, id); } else { if(window.location.href.indexOf('ka.php') > 0 || window.location.href.indexOf('rubric.php') > 0 || window.location.href.indexOf('article.php') > 0 || window.location.href.indexOf('treeFull.php') > 0 || window.location.href.indexOf('favoriteRubrics.php') > 0 || window.location.href.indexOf('lrs_search_form.php3') > 0 || window.location.href.indexOf('lrs_search.php3') > 0 || window.location.href.indexOf('ta.php3') > 0 || window.location.href.indexOf('top10prj-nut.php3') > 0 || window.location.href.indexOf('top10prj-ist.php3') > 0 || window.location.href.indexOf('taproj.php3') > 0 || window.location.href.indexOf('rubric_archive.php3') > 0 || window.location.href.indexOf('searchGoo.php') > 0 || window.location.href.indexOf('registration/') > 0 || window.location.href.indexOf('LSP/') > 0 ) { hideContentPreload(); } else { loadContent('Naujienos', 'news', ''); } var articleIdPos = window.location.href.indexOf('article_id'); var rubricIdPos = window.location.href.indexOf('rubric_id'); if(articleIdPos > 0) { var aid = window.location.href.substr(articleIdPos + 11, window.location.href.length - 1); loadNavigationLine('a', aid); } else if(rubricIdPos > 0) { var rid = window.location.href.substr(rubricIdPos + 10, window.location.href.length - 1); loadNavigationLine('r', rid); } else { loadNavigationLine('', ''); } } } function addEvent( obj, type, fn ) { if (obj.addEventListener) { obj.addEventListener( type, fn, false ); EventCache.add(obj, type, fn); } else if (obj.attachEvent) { obj["e"+type+fn] = fn; obj[type+fn] = function() { obj["e"+type+fn]( window.event ); } obj.attachEvent( "on"+type, obj[type+fn] ); EventCache.add(obj, type, fn); } else { obj["on"+type] = obj["e"+type+fn]; } } var EventCache = function(){ var listEvents = []; return { listEvents : listEvents, add : function(node, sEventName, fHandler){ listEvents.push(arguments); }, flush : function(){ var i, item; for(i = listEvents.length - 1; i >= 0; i = i - 1){ item = listEvents[i]; if(item[0].removeEventListener){ item[0].removeEventListener(item[1], item[2], item[3]); }; if(item[1].substring(0, 2) != "on"){ item[1] = "on" + item[1]; }; if(item[0].detachEvent){ item[0].detachEvent(item[1], item[2]); }; item[0][item[1]] = null; }; } }; }(); addEvent(window,'unload',EventCache.flush); function debug(msg) { document.getElementById('debugdib').innerHTML+="
"+msg; }