/*############################################### Quicklinks #############################################*/ document.observe("dom:loaded", function() { if($('qlid')) { var quicklinks = new Quicklinks(); //alert(get_GET_param("qlid")); } if($('quicklinkSubmit')) { $('quicklinkSubmit').hide(); } }); /* * class controles countrie-adress-select boxes */ var Quicklinks = Class.create(); Quicklinks.prototype = { initialize: function() { this.getJSON(); }, getJSON : function() { var sUrl = 'html-files/quicklinks-json.htm'; var sLang = 'de'; sUrl = sUrl.replace('html-files', '/' + sLang); var myAjax = new Ajax.Request( sUrl, { method: 'post', onSuccess: function (oXHR, oJson) { this.initializeQuicklinks(oXHR.responseText); }, onFailure: function(oXHR, oJson) { alert("An error occurred: " + oXHR.statusText); } }); } } function initializeQuicklinks(jsonData) { jsonData = jsonData.stripTags(); var data = jsonData.evalJSON(true); removeSections(data); $('qlid').observe('change', function(event) { if(event.target.value.strip() != "") { setPages(event.target.value.strip(), data); } else { $('qlpagediv').hide(); $('quicklinkSubmit').hide(); } }); // setAdressOption(sCountry, data, iAdress); } function setPages(value, data) { sSection = ""; if($F('qlid') != "") sSection = $F('qlid'); if ($F('qlid') != "") { for(var k = 0; k < $('qlpage').childElements('option').length; k++) { if($('qlid').childElements('option')[k].value == sSection.strip()) { $('qlid').childElements('option')[k].selected = true; break; } } } //clear all options except default for(var l = $('qlpage').childElements('option').length - 1; l >= 0; l--) { $('qlpage').childElements('option')[$('qlpage').childElements('option').length - 1].remove(); } //set options for(var i = 0; i < data.sections.length; i++) { if(data.sections[i].guid.strip() == sSection) { for(var j = 0; j < data.sections[i].pages.length; j++) { if(Prototype.Browser.IE) { var optn = document.createElement("OPTION"); optn.text = data.sections[i].pages[j].name; optn.value = data.sections[i].pages[j].guid; $('qlpage').options.add(optn); } else { var newOption = ''; new Insertion.Bottom($('qlpage'), newOption); } $('qlpage').childElements('option')[0].selected = true; $('qlpagediv').show(); $('quicklinkSubmit').show(); } } } } // Remove sections without quicklinks function removeSections(data) { if ($('qlid') != "") { for(var k = 0; k < $('qlid').childElements('option').length; k++) { sSection = $('qlid').childElements('option')[k].value; for(var i = 0; i < data.sections.length; i++) { if(data.sections[i].guid.strip() == sSection && data.sections[i].pages.length <= 1) { $('qlid').childElements('option')[k].remove(); } } } } }