function doSearch() {
  $('#search_button').blur();
  var search = $('#search').val();
  if (undefined == search || null == search || search.length == 0) {
    alert('Please enter some text to search');
    $('#search').focus();
  } else {
    $('#searchForm').submit();
  }
}

function setup(authenticated) {
  $('ul.dropdown ul li').hover(
    function() {
      // $(this).css('background-color', '#F0DD0E');
      $(this).css('border-top', '0px solid #FFFFFF');
    },
    function() {
      // $(this).css('background-color', '#FFFFFF');
      $(this).css('border-top', '0px solid #FFFFFF');
    }
  );
  
  $('#nav_home').hover(
    function(){  // over
      $(this).css('border-bottom', '1px solid #000000')
      if ($G.isIE()) {
        $(this).css('height', '27px')
        $(this).css('line-height', '27px')
      } else {
        $(this).css('height', '27px')        
      }
      if (!authenticated) {
        $(this).addClass('ui-corner-left');
      }
    }, 
    function(){  // out
      $(this).css('border-bottom', '0px solid #FFFFFF')
      if ($G.isIE()) {
        $(this).css('height', '28px')
      } else {
        $(this).css('height', '29px')        
      }
      if (!authenticated) {
        $(this).removeClass('ui-corner-left');
      }
    })
 	
  $(".nav_footer").mouseover(function () {
    $(this).css("background-color", "#FFFFFF");
  });

  /* Fixes for IE */
  if (false == jQuery.support.boxModel) {
  
    $(".auth_input").css("height", "15px");
    $(".search_input").css("height", "15px");
   
  }

  $('#nav_online_shop a').css('color','#58595B');
  
  if (!authenticated) {
  	$('#nav_links').css('width','69px');
  	$('#nav_online_shop').css('width','88px');
  }
  
  $('td .top_nav').each(function(){
    $(this).hover(
      function() {
        $(this).find('a').each( function() { $(this).css('color','#000000'); } );
      }, 
      function() {
        $(this).find('a').each( function() { $(this).css('color','#ffffff'); } );
      }
    );
  });
  
}

function adjustWidth() {
  $("ul.dropdown li[id^='nav_']").each(function() {
    var str = $(this).css("width");
    var width = new Number(str.replace('px', ''));
    $(this).css("width", (width - 6) + "px");
  });

  $(".img_white").each(function() {
    var str = $(this).attr("width");
    var width = new Number(str);
    $(this).attr("width", (width - 6));
  });
}

function adjustWidth2(id, adjWidth) {
  $(id).each(function(){
    try {
      var str = $(this).css('width');
      var width = new Number(str.replace('px', ''));
      $(this).css('width', (width + adjWidth) + 'px');
    } catch (e) { 
      // 
    }
  });
}

function adjustWidthStyle(id, className) {
  try {
    var width = new Number($('#'+id+'_width').val());
    $('#'+id).css('width', (width - 2) + 'px');
    $('#'+id).addClass(className); 
  } catch (e) { 
    // 
  }
}

function adjustWidthStyleRemove(id, className) {
  try {
    var str = $('#'+id).css('width');
    var width = new Number($('#'+id+'_width').val());
    $('#'+id).css('width', (width) + 'px');
    $('#'+id).removeClass(className); 
  } catch (e) { 
    alert(e); 
  }
}

function adjustHeight(id, adjHeight) {
  $(id).each(function(){
    var str = $(this).css('height');
    var height = new Number(str.replace('px', ''));
    $(this).css('height', (height + adjHeight) + 'px');
  });
}
 
$(function() {
  adjustWidth2('ul.dropdown li', 2);
  $("ul.dropdown li").hover(function() {
    if (!$G.isIE()) {
      adjustWidth2(this, -2);
    } else {
      $(this + ' li').css('width','100%');
    }
    $(this).addClass("hover");
    $('ul:first',this).show();
  }, function() {
    if (!$G.isIE()) {
      adjustWidth2(this, 2);
    } else {
      $(this + ' li').css('width','100%');
    }
    $(this).removeClass("hover");
    $('ul:first',this).hide();
  });
  $("ul.dropdown li ul li:has(ul)").find("a:first").append(" &raquo; ");
});

function blank() {
  //
}

function ImagePopper() {

  this.imageSrc = '';
  this.imageDisplayDelay = 1000;
  this.title = '';

  this.get = function(imageSrc, title) {
    this.imageSrc = imageSrc;
    this.title = title;
    this.getLoader();
    var t = setTimeout('imagePopper.setImage()', this.imageDisplayDelay);
  }
  
  this.setImage = function() {
    var image = $('<img />').attr('src', this.imageSrc);
    $('#imagePopper').html(image);
  }

  this.getLoader = function() {
    $.get('/image_loader.jsp', function(data){
	  $('#imagePopper').html($.trim(data));
      imagePopper.getDialog();
	});
  }

  this.getDialog = function() {
    $('#imagePopper').dialog({
      autoOpen: true,
	  bgiframe: true,
	  resizable: false,
	  draggable: false,
	  modal: true,
	  width: 425,
	  title: 'CODE: ' + imagePopper.title,
	  zIndex: 9999
	});
	$('#imagePopper').dialog('open');    
  }
}

function addDivToSubnav(auth) {
  $('.sub_menu').each(function() {
    $(this).html(getDivContent(this.id, auth)+$(this).html());
  });
  
  // fix mouse overs
  $('ul.sub_menu li.sub_menu_item').mouseover(function() {
    var pos = new Number(-1);
    if ($(this).attr('name') == 'second_level') {
      var pos = new Number($(this).attr('pos'));
    } 
    $(this).css('background-color', '#F0DD0E');
  	$(this).children('ul').each(function() {
  	  // find the position the parent <ul> and change the position of this child <ul>
  	  var linkText = '';
  	  $(this).find('a').each(function(){ linkText = $(this).html(); })
  	  if ($G.isIE()) {
  	    var newTop = (pos-1) * 17;
  	    var newTopValue = newTop + 'px';
  	    $(this).css('top', newTopValue);
  	    $(this).css('left', '168px');
  	  }
  	  $(this).show();
  	});
  });
  $('ul.sub_menu li.sub_menu_item').mouseout(function() { 
    $(this).css('background-color', '#FFFFFF');
  	$(this).children('ul').each(function() {
  	  $(this).hide();
  	});
  });
}

function getDivContent(id, auth) {
  var array = id.split('_');
  var div = '';
  if (array.length == 3) {
    var width = new Number(array[2]);
    if (!auth) {
    	if (array[1] == '10') {
    		width = width + 6;
    	}
    	if (array[1] == '11') {
    		width = width - 6;
    	}
    } else if (auth) {
      width = width - 6;
    }
    if (!$G.isIE()) {
      div = "<div style='position: absolute; z-index: 10; top: -1px; left: 1px;'><img class='img_white' src='/images/white.gif' alt='' width='"+width+"' height='1' /></div>";
    } else {
      div = "<div><img class='img_white' src='/images/white.gif' alt='' width='"+width+"' height='1' style='position: absolute; z-index: 1000; top: -1px; left: 1px;' /></div>";
    }
  }
  return div;
}
