String.prototype.trim = function () {
   return this.toString ().replace ( /^\s\s*/, '' ).replace ( /\s\s*$/, '' );
}

// First parameter should be the ID of the input element.  The second (optional) parameter should be the text to populate the default form with.  If no default text is set, the label text is searched.
var formDefault = function ( input, text ) {
    try {
       var field = document.getElementById ( input );
    
       if ( field != null ) {
          if ( text === undefined ) { // If no text is passed for the default state, we can assume the label value.
             var text   = '';
             var labels = field.parentNode.getElementsByTagName ( 'label' );
    
             for ( var i = 0; i < labels.length; i++ ) {
                if ( labels[i].htmlFor ) {
                   var textNode = labels[i].childNodes[0];
    
                   if ( textNode != null ) {
                      text = textNode.nodeValue;
                   }
    
                   break;
                }
             }
          }
    
          field.onclick = function () {
             if ( field.value === text ) {
                field.value = '';
             }
          }
    
          field.onblur = function () {
             if ( field.value.trim () === '' ) {
                field.value = text;
             }
          }
    
          field.onblur (); // Set the default text on load.
       }
   } catch(e) {
   
   }
}

window.onload = function () {
   document.body.className += ' rich'; // Add a class to the body so we know JS is available.
   formDefault ( 'search' );
}

function doPopup(url){
    $('#popup').load(url, {}, showPopup);
}

function flashPopup(url){
    $('#popup').load(url, {}, showPopup);
}
        
// new functions 
function hidePopup(speed, cb){
    $('#popup-wrapper').hide(cb); return;
    $('#popup-wrapper').fadeOut(speed || 'slow', cb);
}
function showPopup(speed, cb){
    $('#popup-wrapper').show(cb); return;
    $('#popup-wrapper').fadeIn(speed || 'slow', cb);
    $('#popup-container').bgiframe({width:500,height:500});
}
