/**
 * ---
 * GuestLayout Class
 * ---
 */
function GuestLayout() {
    this.localeSetup();
    this.handledInputHints();
    this.setupTabs();
}

/**
 * Setup locale settings.
 */
GuestLayout.prototype.localeSetup = function() {
    Date.CultureInfo.amDesignator = 'am';
    Date.CultureInfo.pmDesignator = 'pm';
    
    //http://stackoverflow.com/questions/149055/how-can-i-format-numbers-as-money-in-javascript
    Number.prototype.toMoney = function(decimals, decimal_sep, thousands_sep) { 
       var n = this,
       c = isNaN(decimals) ? 2 : Math.abs(decimals), //if decimal is zero we must take it, it means user does not want to show any decimal
       d = decimal_sep || '.', //if no decimal separetor is passed we use the comma as default decimal separator (we MUST use a decimal separator)
       
       t = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep, //if you don't want ot use a thousands separator you can pass empty string as thousands_sep value
    
       sign = (n < 0) ? '-' : '',
    
       //extracting the absolute value of the integer part of the number and converting to string
       i = parseInt(n = Math.abs(n).toFixed(c), 10) + '',
    
       j = ((j = i.length) > 3) ? j % 3 : 0; 
       return sign + (j ? i.substr(0, j) + t : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ''); 
    };
};

/**
 * Handle input fields that use default text hints.
 */
GuestLayout.prototype.handledInputHints = function() {
    var input_handler = function(event_obj) {
        var input = jQuery(this);
        
        if(input.val().length)
            input.parent('form .holding').addClass('hasvalue');
        else
            input.parent('form .holding').removeClass('hasvalue');
    };
    
    jQuery('form .holding :first-child').live('keyup change focusout', input_handler)
        .live('keydown', function() {
            jQuery(this).parent('form .holding').addClass('hasvalue');
        });
    
    jQuery('form .holding :first-child').each(input_handler);
    setInterval(function() {
        jQuery('form .holding :first-child').each(input_handler);
    }, 1000);
    
    jQuery('form .holding .holder').live('click dblclick dragstart selectstart', function() {
        jQuery(this).siblings().focus();
        return false;
    });
};

/**
 * Setup page tabs.
 */
GuestLayout.prototype.setupTabs = function() {
    jQuery('.tabs').tabs();
}
