RTW.ENQUIRY_PROCESSOR =
{
    /**
     * Analyse the url in order to determine which method to call
     */
    init: function()
    {
        var _this = this;
		// Setting default processor to product enquiry
        var action = (window.location.pathname.match(/^\/forms\/([a-z\-]+)/))?window.location.pathname.match(/^\/forms\/([a-z\-]+)/)[1]:"productEnquiry";
        var cookieName = '';
		console.log(action);
        switch(action)
        {
            case 'general-enquiry-processor':
                this.cookieName = 'general-enquiry-processor';
                this.processGeneralEnquiry();
                break;

            case 'product-enquiry-processor':
                this.cookieName = 'product-enquiry-processor';
                this.processProductEnquiry();
                break;

            case 'itinerary-enquiry-processor':
                this.cookieName = 'itinerary-enquiry-processor';
                this.processItineraryEnquiry();
                break;

            case 'cruise-guide-processor':
                this.cookieName = 'cruise-guide-processor';
                this.processCruiseGuideRequest();
                break;

			case 'productEnquiry':
                this.cookieName = 'productEnquiry';
                this.productEnquiryProcess();
                break;

        }
    },

    /**
     * Process a general enquiry
     */
    processGeneralEnquiry: function()
    {
        var map = this.processUrlVars(
        {
            store: 'store',
            consultant: 'consultant',
            cruise_details: 'freeText',
            departure: 'departureDate',
            returndate:'returnDate',
            passengers: 'numberPassengers',
            name:'fullName',
            email: 'email',
            phone: 'phone',
            postcode: 'postCode',
            updates: 'emailNewsletter',
            keywords: 'keywords'
        });

        var formVars = $.extend(map,
        {
            brand: 'RTWUK',
            subject: '{enquiryType} Enquiry: {fullName} ({email})',
            enquiryType: 'General Enquiry',
            template: 'auca/wwwshop/ct-generalEnquiry.html',
            bounceBackTemplate: 'auca/wwwshop/bb-generalEnquiry.html',
            mailToTemplate: 'auca/wwwshop/mt-generalEnquiry'
        });

        this.processForm(formVars);
    },

    
	/**
	 * LG: use this for RTW product enquiry processing
	 * productEnquiryProcess
	 */
    productEnquiryProcess: function()
    {
        var map = this.processUrlVars(
        {
            firstName:	'firstName',
            lastName:	'lastName',
            email:		'email',
            phone: 		'phone',
            postCode: 	'postCode',
            departureDate: 	'phone',
            returnDate: 	'postCode',
            url_address: 'pageUrl',
            other_comments: 'freeText',
            keywords: 'keywords'
        });

        var formVars = $.extend(map,
        {
            brand: 'RTWUK',
            subject: '{enquiryType} Enquiry: {lastName} ({email})',
            //enquiryType: 'General',
            template: 'auca/wwwshop/ct-productEnquiry.html',
            bounceBackTemplate: 'auca/wwwshop/bb-productEnquiry.html',
            mailToTemplate: 'auca/wwwshop/mt-productEnquiry'
        });

        this.processForm(formVars);
    },
	 	
	/**
     * Process a product enquiry
     */
    processProductEnquiry: function()
    {
        var map = this.processUrlVars(
        {
            cruisename: 'cruiseName',
            cruisedest: 'destination',
            cruiselength: 'cruiseLength',
            ship: 'cruiseShip',
            sailingdate: 'sailingDate',
            cabin:'cabin',
            price: 'price',
            name:'fullName',
            email: 'email',
            telephone: 'phone',
            postcode: 'postCode',
            url_address: 'pageUrl',
            store: 'store',
            other_comments: 'freeText',
            updates: 'emailNewsletter',
            keywords: 'keywords'
        });

        var formVars = $.extend(map,
        {
            brand: 'RTWUK',
            subject: '{enquiryType} Enquiry: {fullName} ({email})',
            enquiryType: 'Product Enquiry',
            template: 'auca/wwwshop/ct-productEnquiry.html',
            bounceBackTemplate: 'auca/wwwshop/bb-productEnquiry.html',
            mailToTemplate: 'auca/wwwshop/mt-productEnquiry'
        });

        this.processForm(formVars);
    },

    /**
     * Process a itinerary enquiry
     */
    processItineraryEnquiry: function()
    {
        var map = this.processUrlVars(
        {
            email: 'email',
            name:'fullName',
            phone: 'phone',
            postcode: 'postCode',
            city: 'city',
            people: 'people',
            cabin: 'cabin',
            comments: 'freeText',
            updates: 'emailNewsletter',
            cruise_name: 'cruiseName',
            destination: 'destination',
            __length: 'duration',
            ship: 'cruiseShip',
            date: 'departureDate',
            keywords: 'keywords'
        });

        var formVars = $.extend(map,
        {
            brand: 'RTWUK',
            subject: '{enquiryType} Enquiry: {fullName} ({email})',
            enquiryType: 'Itinerary Enquiry',
            template: 'auca/wwwshop/ct-itineraryEnquiry.html',
            bounceBackTemplate: 'auca/wwwshop/bb-itineraryEnquiry.html',
            mailToTemplate: 'auca/wwwshop/mt-itineraryEnquiry'
        });

        this.processForm(formVars);
    },

    /**
     * process a cruise guide request
     */
    processCruiseGuideRequest: function()
    {
        var queryString = decodeURIComponent(window.location.href).replace(/\s/gm, ' ').match(/(\?.*)/)[1].replace(/\+/gm, ' ');

        var map = this.processUrlVars(
        {
            store: 'store',
            title:'title',
            firstname: 'firstName',
            lastname: 'lastName',
            address: 'address',
            suburb: 'suburb',
            state: 'state',
            postcode: 'postCode',
            phone: 'phone',
            email: 'email',
            dob: 'dob',
            additional_brochures: 'additionalBrochures',
            subscribe: 'emailNewsletter',
            keywords: 'keywords'
        }, queryString);

        var formVars = $.extend(map,
        {
            brand: 'RTWUK',
            subject: '{enquiryType} Enquiry: {firstName} {lastName} ({email})',
            enquiryType: 'Cruise Guide Request',
            template: 'auca/wwwshop/ct-cruiseGuideRequest.html',
            bounceBackTemplate: 'auca/wwwshop/bb-cruiseGuideRequest.html',
            mailToTemplate: 'auca/wwwshop/mt-cruiseGuideRequest'
        });

        this.processForm(formVars);
    },

    /**
     * Ensure emailNewsletter is in the correct format, perform GIMP request, then redirect to thank you page on the
     * old Cruiseabout with the query string appended.
     * @param {jQuery} $form
     */
    finishProcessing: function($form)
    {
        var $emailNewsletter = $form.find('input[name="emailNewsletter"]');
        var gimpUrl = '';

        // Ensure "emailNewsletter" has the correct value
        if($emailNewsletter.val() == 'undefined') { $emailNewsletter.val('No'); }
        if($emailNewsletter.val() == 'true') { $emailNewsletter.val('Yes'); }
        $emailNewsletter.val(function(i, val){ return FCL.UTIL._titleCaps(val);});
        
        if(this.cookieProcessing(RTW.ENQUIRY_PROCESSOR.cookieName)==false)
        {
            
            gimpUrl = FCL.GIMP.getUrl($form);
            $.get(gimpUrl, {}, function()
            {
                FCL.UTIL.log('RTW.ENQUIRY_PROCESSOR.finishProcessing');
                FCL.UTIL.log(gimpUrl);
                
                    window.location.href = 'http://www.cruiseabout.com.au/thankyou.html{1}'.fclFormat(window.location.search);                
            });
        }
    }
};
/*
FCL.UTIL.getJS('/js/fcl/fcl.enquiry_processor.js', function()
{
    RTW.ENQUIRY_PROCESSOR = $.extend(FCL.ENQUIRY_PROCESSOR, RTW.ENQUIRY_PROCESSOR);
    RTW.ENQUIRY_PROCESSOR.init();    
});
*/
