var count = 0; var pos = 0; $(document).ready(function() { centerULMenu('.centerThis1',0) centerULMenu('.centerThis2',0) $('#sokform').bind('submit', function() { //if(!($('.searchBox0').is(':visible'))) //{ if($('#search').val() != "") { cleanSearchResult(); $.ajax({ dataType: 'xml', url: $(this).attr('action'), data: 'sokvarde=' + $('#search').val(), success: function(xml) { handleAndPaintSearch(xml); }, error: function() { alert('Response were not valid XML'); }, type: 'POST' }); } else { alert('You must fill in at least one keyword.'); } //} /* else { cleanUp(); postaSokning(); }*/ return false; }); }); function postaSokning() { var formularet = document.getElementById('sokform'); //if(!($('.searchBox0').is(':visible'))) //{ if($('#search').val() != "") { cleanSearchResult(); $.ajax({ dataType: 'xml', url: $(formularet).attr('action'), data: 'sokvarde=' + $('#search').val(), success: function(xml) { handleAndPaintSearch(xml); }, error: function() { alert('Response were not valid XML'); }, type: 'POST' }); } else { alert('You must fill in at least one keyword.'); } //} /* else { cleanUp(); postaSokning(); }*/ return false; } // Skicka in XML-datat för uppritning av sökrutan. function handleAndPaintSearch(xml) { var sizes = $.winSize(); // Hämta storlekar på fönstret if($(".searchBox0").size() == 0){ $('body').append('
'); // Skapa sökrutan $('body').append('
'); var lPos = eval(sizes.clientwidth / 2 - (250 / 2) + 260 - 50) + 'px' // Räkna ut placering av sökrutan var options1 = { background:'#CCCCCC', width:'300px', height:'245px', position:'absolute', top:'172px', left:lPos, zIndex:'10001', opacity:'0.9' }; // CSS $('.searchBox0').css(options1); // Koppla CSS till sökrutorna var options2 = { width:'300px', height:'235px', position:'absolute', top:'172px', left:lPos, zIndex:'10002', overflow:'hidden' }; $('.searchBox1').css(options2); } $('.searchBox1').append('
Quicksearch:
close
'); // Lägg till den övre bordern $('.searchBox1 a:first').bind('click', function() { cleanUp(); }); // Bind onclick-event till close-länken (första länken i sökrutan) var urlen, titlen; if($('result', xml).size() == 0){ //put "no search result" here $('.searchBox1').append('

Couldn\'t find any matching pages for your search.

') }else{ $('result', xml).each(function() // För varje "result"-post i XML man fått som retur; gör detta { urlen = $('url', this).text(); titlen = $('title', this).text(); introt = $('intro', this).text(); introt = introt.replace('&','and'); if (titlen.length > 40) titlen = titlen.substr(0,40) + ' ...'; //$('.searchBox1').append('test'); //$('.searchBox1').append('
' + titlen + 'Visit page
'); $('.searchBox1').append('
' + titlen + '
'); // code 12-fel om man skickar in ett &-tecken. //$('.searchBox1').append('
' + titlen + 'Visit page »
'); // Skapa länk till sökträffen }); } //setTimeout("cleanUp()", 15000); // Göm rutan efter 15 sekunder } function cleanUp() { $('.searchBox0, .searchBox1').slideUp('slow',function() { $('.searchBox0').remove(); $('.searchBox1').remove(); }); } function cleanSearchResult(){ //$('.searchBox0').html(''); $('.searchBox1').html(''); } function centerULMenu(obj, intoAccount) { $(obj).find('li').each(function(i) { count = eval(count + $(this).width() + intoAccount /* the last value is padding and margin */); }).end().css({ width: eval(count) + 'px'}); pos = eval($(obj).parent().width() / 2) - (count / 2); $(obj).css({ marginLeft: pos + 'px'}); pos = 0; count = 0; } jQuery.winSize = function() { var myWidth = 0, myHeight = 0; if( typeof( window.innerWidth ) == 'number' ) { //Non-IE myWidth = window.innerWidth; myHeight = window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight; } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible myWidth = document.body.clientWidth; myHeight = document.body.clientHeight; } return {clientwidth: myWidth, clientheight: myHeight}; }