$(function() {
  initPage();
})

function initPage() {
  try {
    $('#qTop').inputFocus('S\u00d8G');
  } catch (e) {
  }
}

/* STH: 2009-08-06: 
   inputFocus(sDefaultText)
   These behavious are added to elements which has the attribute "value":
   onFocus:
     - A class "focus" is added
     - If the value attribute has the value specified by parameter sDefaultText this value is cleaned
   onBlur:
     - The class "focus" is removed
     - If the element has the class "required" the default value will be restored
*/
$.fn.inputFocus = function(sDefaultText, bSpaceOK) {
  try {
    var $this = $(this);
    bSpaceOK = (typeof bSpaceOK != 'undefined') ? bSpaceOK : false;
    if (typeof $this.attr('value') != 'undefined' && (sDefaultText.indexOf(' ') == -1 || bSpaceOK)) {
      $this.attr('title', sDefaultText);
      $this.data('defaultvalue', sDefaultText);
      $this.focus(function() {
        $this.addClass('focus');
        if ($this.val() == sDefaultText) {
          $this.val('');
        }
      }).blur(function() {
        $this.removeClass('focus');
        $this.removeClass('notvalid');
        if ($.trim($this.val()) == '' && $this.hasClass('required')) {
          $this.val(sDefaultText);
        }
      })
    }
  } catch (e) {
    alert('Error "' + e.message + '" during call:\n\ninputFocus("' + sDefaultText + '")');
  }
}

function isValidEmail(sEmail) {
  var pattern = "^[a-zA-Z0-9._+&*# -]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$"
  var regex = new RegExp(pattern, 'ig');
  return regex.test(sEmail);
}


var bAlert = true;
function alert(s) {
  if (bAlert) {
    bAlert = window.confirm(s);
  }
}
