
    function add_load_event(func) {
        var oldonload = window.onload;
        if (typeof window.onload != 'function') {
                window.onload = func;
        } else {
                window.onload = function() {
                        oldonload();
                        func();
                }
        }
    }

    function get_query_var(url, variable) {
      var query = url.split("?")[1];
      var vars = query.split("&");
      for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
          return pair[1];
        }
      }
    }

    function prepare_links() {
      if (!document.getElementsByTagName) return false;
      var links = document.getElementsByTagName('a');
      for (var i = 0; i < links.length; i++) {
        var url = links[i].href;
        if (links[i].className == 'popup-image') {
          links[i].onclick = function() {
            popimage(this.href, get_query_var(this.href, 'width'), get_query_var(this.href, 'height'));
            return false;
          }
        }
        else if (is_external(url)) {
          links[i].onclick = poplink;
        }
      }
    }

    function is_external(url) {
      return url.indexOf('http://') == 0 && url.indexOf('photographycorner.com') == -1;
    }

    add_load_event(prepare_links);

    var new_window;
    function popimage(url, width, height) {
      new_window = self.open(url, '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=' + width + ',height=' + height + ',left = 100,top = 100');
      new_window.focus();
    }

    function poplink(e) {
      //if (!e) var e = window.event; // IE
      //var a = e.target ? e.target : e.srcElement;
      return !window.open(this.href);
    }

    function onsearch() {
     if (document.forms['search'].which[1].checked) {
       document.forms['search_vb'].query.value = document.forms['search'].elements[0].value;
       document.forms['search_vb'].submit();
       return false;
     }
     document.forms['search'].submit();
     return true;
    }

