var starttimestamp = Math.round( new Date().getTime() / 1000 ); var hint_text_delay = 550; var menupositionx; var municipalityid = ''; var municipality = ''; var frontpage_query_val = 'Søk på firmanavn, bransjer, produkter, tjenester...'; var listing_miniquery_val = frontpage_query_val; $(document).ready( function(){ var infopage_timer; // Insert weatherinfo if not already in static php-html code if ( $('header [id="weatherinfo"]').length > 0 ) { var new_municipalityid = $('header [id="weatherinfo"]').attr('title'); if ( new_municipalityid != '' ) { municipalityid = new_municipalityid; } $.get( '/get_weatherinfo?mid='+ municipalityid, function( weatherinfo ){ $('header [id="weatherinfo"]').html( weatherinfo ); }); } // Get posistion menupositionx = $('[id="menu"]' ).offset().left + $('[id="menu"]' ).width(); $( window ).resize(function() { menupositionx = $('[id="menu"]' ).offset().left + $('[id="menu"]' ).width(); }); // Aleay scroll to top $("html, body").scrollTop(0); // Remove hint text in search query box $('input[id="frontpage_query"]').focus( function (){ if ( $('input[id="frontpage_query"]').val() == frontpage_query_val ){ $('input[id="frontpage_query"]').val(''); } }); // Insert hint text in search query box if box is empty $('input[id="frontpage_query"]').blur( function (){ if ( $('input[id="frontpage_query"]').val() == '' ) { $('input[id="frontpage_query"]').val( frontpage_query_val ); } }); // Submit search on click on searchbox ( exclude search query box name=q ) $('fieldset[id="transtext"]').click( function ( evt ){ if ( evt.target.name != 'q' ) { $('fieldset[id="transtext"] form[id="'+ evt.target.id +'"]').submit(); } }); // Show hinttext on sections on mouseover $('.hoverinfo').hover( function (){ var el = this; infopage_timer = setTimeout(function(){ $(el).find('.text').show( 200 ) }, hint_text_delay ); if ( $(this).attr( 'id' ) == 'review' ) { $('[id="review"] [id="conditions"]').slideDown( 200 ); }; }, function() { clearTimeout( infopage_timer ); $(this).find('.text').hide( 200 ); if ( $(this).attr( 'id' ) == 'review' ) { $('[id="review"] [id="conditions"]').slideUp( 200 ); }; }); // Show review conditions $('[id="infopage"] [id="review_accept"]').click( function (){ if ( $('[id="infopage"] [id="conditions"]').html().length == '' ) { $.get( '/vilk%C3%A5r/firmaomtale', function( conditions_html ){ $('[id="infopage"] [id="conditions"]').html( conditions_html ); $('[id="infopage"] [id="conditions"]').css( 'margin-top', '25px' ); }); } else { $('[id="infopage"] [id="conditions"]').html( '' ); } }); $('[id="review"]').click( function() { if ( $('[id="review"] [id="conditions"]').html().length != '' ) { $('[id="review"] [id="conditions"]').html( '' ); $('[id="review"] [id="conditions"]').css( 'margin-top', '0' ); } }); // Tiptool $('[class="tooltip"]').mousemove( function( e ) { var title = $(this).attr('data-title'); var message = $(this).attr('data-message'); var x = e.pageX + 24; var y = e.pageY; if ( x > ( menupositionx - ( $("#tooltipbox").width() + 10 ) ) ) { x = x - ( $("#tooltipbox").width() + 45 ); } $("#tooltipbox").css( { left: x, top: y } ); $("#tooltipboxtitle").html( title ); $("#tooltipboxmessage").html( message ); $("#tooltipbox").show(); }); $('[class="tooltip"]').mouseout( function(e) { $("#tooltipbox").hide(); }); // Set review stars var review_starrate = 0; $('[id="review"] [class="star"]').hover( function (){ var review_starid = $(this).attr('id').substr( 5 ); $('[id="review"] [class="star"]').each( function(){ var id = $(this).attr('id').substr( 5 ); if ( review_starid >= id ) { // $('[id="review"] [id="star_'+ id +'"]').attr( 'src', '/bilder/star_on.png' ); $('[id="review"] [id="star_'+ id +'"]').attr( 'src', '/bilder/star_on'+ id +'.png' ); } else { $('[id="review"] [id="star_'+ id +'"]').attr( 'src', '/bilder/star_off.png' ); } }); }, function() { var review_starid = $(this).attr('id').substr( 5 ); $('[id="review"] [class="star"]').each( function(){ var id = $(this).attr('id').substr( 5 ); if ( review_starrate >= id ) { // $('[id="review"] [id="star_'+ id +'"]').attr( 'src', '/bilder/star_on.png' ); $('[id="review"] [id="star_'+ id +'"]').attr( 'src', '/bilder/star_on'+ id +'.png' ); } else { $('[id="review"] [id="star_'+ id +'"]').attr( 'src', '/bilder/star_off.png' ); } }); }); $('[id="review"] [class="star"]').click( function(){ review_starrate = $(this).attr('id').substr( 5 ); $('[id="review"] input[name="score"]').val( review_starrate ); }); // Format queryurl ( also miniserach) $('[id="searchform"], [id="searchform-mini"]').submit( function( evt ){ var id = evt.target.id; var q = $('[id="'+ id +'"] [name="q"]').val(); q = q.replace( /^\s+|\s+$/g, '' ); if ( q ) { $("body").css( 'cursor', 'wait' ); q = q.replace( /[ \+]/g, '_' ); q = q.replace( /[\\\/]/g, '' ); q = q.toLowerCase(); q = escape( utf8_encode( q ) ); $('[id="'+ id +'"] [name="q"]').prop('disabled', true); if ( municipality.length > 0 ) { evt.preventDefault(); top.window.location.href = '/'+ escape( utf8_encode( municipality.replace( / /g, '_' ) ) ) +'/'+ q + '.html'; } } else { $('[id="'+ id +'"] [name="q"]').val( q ); } }); }); /// FUNCTIONS /// function setCookie( c_name, value, exdays ){ var exdate=new Date(); exdate.setDate( exdate.getDate() + exdays ); var c_value = escape( value ) + ( ( exdays==null ) ? "" : "; expires=" + exdate.toUTCString() ); document.cookie = c_name + "=" + c_value; } function getCookie( c_name ){ var i,x,y,ARRcookies = document.cookie.split( ";" ); for( i=0; i 3 && document.e.parkzipcode.value.length == 4 ) { var s = document.e.parkaddress.value +", "+ document.e.parkzipcode.value +" "+ document.e.parkplace.value +" , Norway"; geocoder = new google.maps.Geocoder(); geocoder.geocode ( {'address':s}, function(results, status) { if(status == google.maps.GeocoderStatus.OK) { var p=results[0].geometry.location; document.e.lat.value=p.lat(); document.e.lng.value=p.lng(); map.setCenter(p); mapClick(p); } else { } } ); } } function lookupcoordsfromplace( place ) { if ( place.length >= 2 ) { var s = place +" , Norway"; geocoder = new google.maps.Geocoder(); geocoder.geocode ( {'address':s}, function(results, status) { if(status == google.maps.GeocoderStatus.OK) { var p=results[0].geometry.location; document.e.lat.value=p.lat(); document.e.lng.value=p.lng(); map.setCenter(p); mapClick(p); } else { } } ); } } function responseinfo( message, type ){ if ( type === undefined) { $('[id="responseinfo"]').css( 'background-color', '#3598DB' ); } else if ( type == 'warning' ) { $('[id="responseinfo"]').css( 'background-color', '#FF3333' ); } $('[id="responseinfo"]').html( message ); $('[id="responseinfo"]').slideDown( 300 ); setTimeout(function(){ $('[id="responseinfo"]').slideUp( 300 ); }, 2000 + ( message.length * 45 ) ); } function utf8_encode( string ) { for (var n=0, u=""; n < string.length; n++) { var c=string.charCodeAt(n); if (c < 128) { u += String.fromCharCode(c); } else if((c > 127) && (c < 2048)) { u += String.fromCharCode((c >> 6) | 192); u += String.fromCharCode((c & 63) | 128); } else { u += String.fromCharCode((c >> 12) | 224); u += String.fromCharCode(((c >> 6) & 63) | 128); u += String.fromCharCode((c & 63) | 128); } } return u; } function hex2rgb( hexStr, type ){ // note: hexStr should be #rrggbb var hex = parseInt(hexStr.substring(1), 16); var r = (hex & 0xff0000) >> 16; var g = (hex & 0x00ff00) >> 8; var b = hex & 0x0000ff; // return as array or string if ( type === undefined ) { return [r, g, b]; } else { return r +', '+ g +', '+ b; } }