/**
 * Flight Centre New Zealand master object
 *
 * @author          Ryan Blunden
 * @modifiedby      $LastChangedBy$
 * @copyright       Copyright Flight Centre Ltd. All rights reserved.
 * @version         $Revision$
 * @lastmodified    $Date$
 * @requires        FCL, FCL.UTIL, FCL.FORMS
 */

;FCNZ =
{
	megaMenuPreloadImages:
	[
	    '/cms_images/megamenu/images/mega-home.png',
        '/cms_images/megamenu/images/mega-hotels.png',
        '/cms_images/megamenu/images/mega-flights.png',
        '/cms_images/megamenu/images/mega-holidays.png',
        '/cms_images/megamenu/images/mega-specials.png',
        '/cms_images/megamenu/images/mega-booking.png',
        '/cms_images/megamenu/images/mega-travelextras.png',
        '/cms_images/megamenu/images/mega-specialist-consultants.png',
        '/cms_images/megamenu/images/mega-contactus.png',
        '/cms_images/megamenu/images/mega-about.png'
    ],

    preloadedImages : new Array(),

    preload: function() {
    	for (i in this.megaMenuPreloadImages) {
    		this.preloadedImages[i] = new Image();
    		this.preloadedImages[i].src = this.megaMenuPreloadImages[i];
    	}
    },

	getEnvHost: function()
    {
        var host = window.location.host.substring(0, window.location.host.indexOf('.'));
        var env = '';

        switch(host)
        {
            case 'int':
                env = 'development';
                break;

            case 'stage':
                env = 'staging';
                break;

            case 'newstage':
                env = 'staging';
                break;

            case 'www':
                env = 'production';
                break;

            default:
                env = 'production';
                break;
        }

        return env;
    },

    filterInputText: function(str)
    {
        try
        {
            return str.match(/[a-zA-Z0-9\(\)\',.!/:%@&?+_=\-\$\* ]+/gm).join('');
        }
        catch(e)
        {
            return '';
        }
    },

	getMailerUrl: function(mailerSettings)
    {
        var mailer = $.extend(FCNZ.SETTINGS.MAILER, mailerSettings);
        var mailerUrl = FCNZ.SETTINGS.MAILER.baseUrl;

        $.each(mailer, function(key, val)
        {
            if(val != '' && key != 'baseUrl')
            {
                mailerUrl += key + '=' + FCNZ.filterInputText(val) + '&';
            }
        });

        return mailerUrl.substring(0, mailerUrl.length-1);
    },

    init: function()
    {
		this.preload();
		var _this = this;

		$(document).ready(function()
		{
			_this.legacyCode();
		});
    },

	/**
	 * #Legacy code
	 * This function maps legacy FCL.UTIL function calls to their
	 */
	legacyCode: function()
	{
		FCL.UTIL.filterProductlineElementsList = FCNZ.UTIL.filterProductlineElementsList;
		FCL.UTIL.filterProductlineElementsSequence = FCNZ.UTIL.filterProductlineElementsSequence;
		FCL.UTIL.log = FCNZ.UTIL.log;
	}

};
FCNZ.init();
