var settings = {
    messages            : 'messages',
    messages_hide_delay : 0.5,
    cart				: 'cart',
    popupmessage		: 'popupMessage',
    busy				: false,
    ajaxmessage			: ''
};

function init(e)
{
    // check if the messages element exists and is visible,
    // and if so, apply the highlight effect to it
    var messages = $(settings.messages);

    if (messages && messages.visible()) {
        new Effect.Highlight(messages);
    }
    new SearchSuggestor('search');
    
    if(typeof(useLimitText) != 'undefined') {
    	limitText(ltField,ltCountdown,ltChars)
    }
   	// hideBusyMessage();
}
Event.observe(window, 'load', init);

function message_write(message)
{
    var messages = $(settings.messages);
    if (!messages)
        return;

    if (message.length == 0) {
        messages.hide();
        return;
    }

    messages.update(message);
    messages.show();
    new Effect.Highlight(messages);
}
function cart_update(message)
{
    var cart = $(settings.cart);
    if (!cart)
        return;

    if (message.length == 0) {
        cart.hide();
        return;
    }

    cart.update(message);
    cart.show();
    new Effect.Highlight(cart);
}

function message_clear()
{
    setTimeout("message_write('')", settings.messages_hide_delay * 1000);
}
// Prototype powered popup script
// http://jehiah.cz/archive/prototype-powered-popup-script
var Popup = {
  open: function(options)
  {
    this.options = {
      url: '#',
      width: 600,
      height: 500,
      name:"_blank",
      location:"no",
      menubar:"no",
      toolbar:"no",
      status:"yes",
      scrollbars:"yes",
      resizable:"yes",
      left:"",
      top:"",
      normal:false
    }
    Object.extend(this.options, options || {});

    if (this.options.normal){
        this.options.menubar = "yes";
        this.options.status = "yes";
        this.options.toolbar = "yes";
        this.options.location = "yes";
    }

    this.options.width = this.options.width < screen.availWidth?this.options.width:screen.availWidth;
    this.options.height=this.options.height < screen.availHeight?this.options.height:screen.availHeight;
    var openoptions = 'width='+this.options.width+',height='+this.options.height+',location='+this.options.location+',menubar='+this.options.menubar+',toolbar='+this.options.toolbar+',scrollbars='+this.options.scrollbars+',resizable='+this.options.resizable+',status='+this.options.status
	if (this.options.top!="")openoptions+=",top="+this.options.top;
	else openoptions+=",top="+parseInt((parseInt(screen.height)/2) - (parseInt(this.options.height)/2));
	if (this.options.left!="")openoptions+=",left="+this.options.left;
	else openoptions+=",left="+parseInt((parseInt(screen.width)/2) - (parseInt(this.options.width)/2));
    window.open(this.options.url, this.options.name,openoptions );
    return false;
  }
}
function limitText(limitField, limitCount, limitNum) {
	// FROM http://www.mediacollege.com/internet/javascript/form/limit-characters.html
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}