SF.FORMCUSTOM = {
    
    // tracking: 
    // {
    //     timestamp: function() { d = new Date(); return d.getTime(); }(),
    //     storeName: 'Student Flights',
    //     tax: '0.00'
    // },
    
    TYPE: 
    {
        name: 'product-enquiry'    
    },

    addMarketingSuccess: function() {
        var random;
        random = this.tracking.sku + SF.DATETIME.todaysDate().replace(/\//gmi,'') + this.tracking.timestamp

        //* YAHOO MARKETING
        var strDestination = this.getDestination();
        var strSku = this.getSku();
        var priceDigits = '0.00';
        var timestamp = function() {
            d = new Date();
            return d.getTime();
        }();
        
        var priceDigitsCheck = $('#prodPrice').val().match(/[0-9,]+/gm);
        if (priceDigitsCheck != null) {
            priceDigits = priceDigitsCheck[0] + '.00';
        }

        if (typeof(window.ysm_customData) != 'object') window.ysm_customData = new Object();
        window.ysm_customData.conversion = SF.format('transId=PRDeve{1}{2}{3},currency=AUD,amount={4}', strDestination, strSku, timestamp, priceDigits)

        ysm_accountid = '195CHAMUE2CDPPQHITP9CE0ID2G'

        var yahooScript = document.createElement('script');
        yahooScript.type = 'text/javascript';
        yahooScript.src = '//srv2.wa.marketingsolutions.yahoo.com/script/ScriptServlet?aid=' + ysm_accountid;
        $('body').append(yahooScript);

        //* CALL GOOGLE AJAX TRACKPAGE EVENT
        SF.registerGAPageView({path: this.TYPE.name, item: '/' + strSku });

        //* DGM TRACKING 
        var dgm1 = '<img height="1" width="3" src="http://www.s2d6.com/x/?x=a&amp;h=16628&amp;o={1}" alt="" class="hide" />';
        var dgm2 = '<img height="1" width="3" src="http://www.s2d6.com/x/?x=r&amp;h=16628&amp;o={1}&amp;g=357679833273&amp;s={2}&amp;q=1" class="hide" />';

        //* AD.DOUBLECLICK
        var doubleClick = '<img height="1" width="3" src="https://ad.doubleclick.net/activity;src=986775;type=fligh123;cat=sfsal002;qty=1;cost={1};ord={2}?" alt="" class="hide" />';

        // //* GOOGLE E-COMMERCE TRACKING
        //   _gaq.push(['_addTrans',
        //     random,           // order ID - required
        //     this.tracking.storeName,  // affiliation or store name
        //     this.tracking.total,          // total - required
        //     this.tracking.tax,           // tax
        //     '0',              // shipping
        //     'n/a',       // city
        //     'n/a',     // state or province
        //     'n/a'             // country
        //   ]);

        //    // add item might be called for every item in the shopping cart
        //    // where your ecommerce engine loops through each item in the cart and
        //    // prints out _addItem for each
        //   _gaq.push(['_addItem',
        //     random,           // order ID - required
        //     this.tracking.sku,           // SKU/code
        //     this.tracking.product,        // product name
        //     'Product',   // category or variation
        //     this.tracking.total,          // unit price - required
        //     '1'               // quantity - required
        //   ]);

        //   _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers
        // //* END GOOGLE E-COMMERCE TRACKING


        //* GOOGLE AD CONVERSION
        var google_conversion_id = 1035570271;
        var google_conversion_language = 'en_AU';
        var google_conversion_format = '3';
        var google_conversion_color = 'ffffff';
        var google_conversion_label = 'vXhECLWlmwEQ35jm7QM';
        var google_conversion_value = priceDigits;

        var googleAdImage = '<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1035570271/?label=vXhECLWlmwEQ35jm7QM&amp;guid=ON&amp;script=0"/>' +
                            '<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1005941684/?label=wgqyCJzT9gEQtOfV3wM&amp;guid=ON&amp;script=0"/>' +
                            '<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/998531215/?label=QDN9COmZiQIQj8GR3AM&amp;guid=ON&amp;script=0"/>' +
                            '<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1002905825/?label=sTUqCP_SlgIQ4cGc3gM&amp;guid=ON&amp;script=0"/>' +
                            '<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/999516777/?label=za6pCOfx7wEQ6dTN3AM&amp;guid=ON&amp;script=0"/>' +
                            '<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/997474498/?label=4Fq2CMaB9gEQwoHR2wM&amp;guid=ON&amp;script=0"/>' +
                            '<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1040398195/?label=VJwOCN_FuwEQ8-6M8AM&amp;guid=ON&amp;script=0"/>' +
                            '<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1045875622/?label=xU-UCIqq-AEQppfb8gM&amp;guid=ON&amp;script=0"/>' +
                            '<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1035570271/?label=2M0gCKnxnAEQ35jm7QM&amp;guid=ON&amp;script=0"/>' +
                            '<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1018237290/?label=htnQCO6g0wEQ6qLE5QM&amp;guid=ON&amp;script=0"/>' +
                            '<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1018237290/?label=EsCUCP6e0wEQ6qLE5QM&amp;guid=ON&amp;script=0"/>' +
                            '<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1018237290/?label=7egCCPaf0wEQ6qLE5QM&amp;guid=ON&amp;script=0"/>';


        $('body').prepend(SF.format(dgm1, timestamp))
                .prepend(SF.format(dgm2, timestamp, priceDigits))
                .prepend(SF.format(doubleClick, priceDigits, timestamp))
                .append(googleAdImage);

    },

    setupForm: function() 
    {
        SF.ENQUIRY.$form.find('.ef-submit').attr('disabled', false);  

        //* CHECK IF MODAL WINDOW PRODUCT ENQUIRY
        if(window.location.href.indexOf('.html') >-1)
        {
            var packageName = SF.getUrlVars('','packageName'), 
            packagePrice = SF.getUrlVars('','packagePrice'), 
            page = SF.getUrlVars('','pageUrl'), 
            packageSku = SF.getUrlVars('','sku');
            pageUrl = SF.getUrlVars('','pageUrl');
            
            SF.PRODUCTENQ.$form.find('input[name="pageUrl"]').val(pageUrl);
            SF.PRODUCTENQ.$wrapper.find('span.productName').text(packageName);
            SF.PRODUCTENQ.$wrapper.find('span.price').text(packagePrice);
            SF.PRODUCTENQ.$form.find('#prodSku').val(packageSku);
            SF.PRODUCTENQ.$form.find('#prodName').val($.trim(packageName));
            SF.PRODUCTENQ.$form.find('#prodPrice').val(packagePrice);
            
            // Remove text 'from' is product is $0 (zeroPriceChecked)
            if(packagePrice == 'enquire now for price'){
                $('.from').hide();
            }

            // this.tracking.product = $.trim(packageName);
            // this.tracking.sku = packageSku;
            // this.tracking.total = packagePrice.match(/\d+/gm)[0] + '.00';
        }
        // else
        // {
        //     try
        //     {
        //         this.tracking.product = $.trim(SF.PRODUCTENQ.$wrapper.find('span.productName').text());
        //         this.tracking.sku = SF.PRODUCTENQ.$form.find('#prodSku').val();
        //         this.tracking.total = SF.PRODUCTENQ.$form.find('#prodPrice').val().match(/\d+/gm)[0] + '.00';
        //     }
        //     catch(e){}
        // }
        
        // Truncate
        try
        {
            var strLittleTitleLength = $('#productEnquireForm .productName').html().length;
            var strBigTitleLength = $('#main-panel .title-with-bar h1').html().length
                    
            if (strLittleTitleLength > 45)
            {
                SF.truncateText($('#productEnquireForm .productName'),{len:45, ignoreStopChar: true})    
            }
                    
            if (strBigTitleLength > 68)
            {
                SF.truncateText($('#main-panel .title-with-bar h1'),{len:68, ignoreStopChar: true})               
            };
        }
        catch(e){}

        
        
        var $departureDate = $('#departureDate');
        var $returnDate = $('#returnDate');
        
        $departureDate.val('dd/mm/yyyy');
        $returnDate.val('dd/mm/yyyy');
        
        $departureDate.datepicker({
            minDate: new Date(),
            dateFormat: 'dd/mm/yy',
            showOn: 'both',
            buttonImage: '/images/sf-mini-cali.png',
            buttonImageOnly: true
        }).change(function()
        {
            $returnDate.datepicker('option', 'minDate', $(this).datepicker('getDate'))
        });
        
        $returnDate.datepicker({
            minDate: new Date(),
            dateFormat: 'dd/mm/yy',
            showOn: 'both',
            buttonImage: '/images/sf-mini-cali.png',
            buttonImageOnly: true 
        });
    },
    
    getProductImages: function(amount)
    
    {
        amount = amount + 1;
        var strDes = this.getDestination();

        var defaultPath = '/global-images/Product_Images/sfau/product-images/'
        
        try
        {
            for (var i=1; i < amount; i++)
            {
                currImage = new Image();
                
                $(currImage).attr({src: SF.format('{1}{2}-{3}{4}',defaultPath,strDes,i,'.jpg'), width: 178});
                            
                $(currImage).bind('load', function(){
                    $('#right-side-panel').append(this)
                })
                .error(function(){
                })              
                
            };
            
        } catch(e){}
		
    }
	
};


/*___ PRODUCT ENQUIRY FOR MATES PRICE PROMOTION - JANUARY 2011 ___*/
(function()
{
    if(window.location.pathname.match(/^\/product\//) == null)
    {
        return;
    }

    // Alter form to be a product enquiry form on init signal
    FCL.SIGNALS.listen('SF.ENQUIRY', 'init', function()
    {
        var skus, sku, price, matesPrice, $h1, h1Text, $enquiryFormPrice, enquiryFormPriceText;
        skus = [1176276, 1202667, 1202668, 1202669, 1202670, 1202671, 1202672, 1202673, 1202674, 1202675, 1202676];
        sku = parseInt($('head meta[name="product.sku"]').attr('content'), 10);

        if($.inArray(sku, skus) === -1)
        {
            return;
        }

        price = $('head meta[name="product.price"]').attr('content');
        matesPrice = $('head meta[name="product.wasPrice"]').attr('content');
        $h1 = $('#main-panel').find('h1');

        // Adjust h1
        h1Text = $h1.text().substring(0, $h1.text().indexOf('from $'));
        h1Text = '{1} - <span class="yourMate">you <span class="price">{2}*</span> your mate <span class="price">{3}*</span></span>'.fclFormat(
            h1Text,
            price,
            matesPrice
        );
        $h1.html(h1Text);

        // Adjust price in Enquiry form
        $enquiryFormPrice = $('#titleRowProduct span.right');
        enquiryFormPriceText = '<span class="from">you</span> <span class="price">{1}*</span> <span class="from">your mate</span> <span class="price">{2}*</span>'.fclFormat(
            price,
            matesPrice
        );
        $('#titleRowProduct span.title').remove();
        $('#titleRowProduct').css('padding-left', 0);
        $enquiryFormPrice.html(enquiryFormPriceText);

        // Change template to be product enquiry mates price
        $('#productEnquiry').find('input[name="template"]').val('ausf/product-enquiry-mates-price.html');

        $(function()
        {
            // Change "Enquire Now" link to go to enquiry form on product page
            $('#modalGenEnq, a.headerEnquire').unbind('click');
            $('#modalGenEnq, a.headerEnquire').bind('click', function(e)
            {
                e.preventDefault();
                SF.scrollTo($('#productEnquireForm'));
            });
        });
    });
})();

SF.PRODUCTENQ = $.extend(true, SF.ENQUIRY, SF.FORMCUSTOM);
SF.PRODUCTENQ.init();
