var thisPointer;
var bannerFunctions =
{
    activeFrame: 0,
    bannerContentsWidth: 960,
    bannerTransitionTime: 1000,
    bannerTimeoutLength: 7000,
    frameLength: null,
    frameRotateTimer: null,
    frameTimeoutLength: 7000,
    goToFrameTimer: null,

    frameRotate: function ()
    {
        if (bannerFunctions.activeFrame >= bannerFunctions.frameLength - 1)
        {
            bannerFunctions.goToFrame(0);
        }
        else
        {
            bannerFunctions.goToFrame(bannerFunctions.activeFrame + 1);
        }
    },
    goToFrame: function (frameNumber, direction)
    {
        clearTimeout(bannerFunctions.frameRotateTimer);
        $('.promo_frame').stop(true, true);
        var showDirection = 'right';
        var hideDirection = 'left';
        if( direction == 'back') {
	        var showDirection = 'left';
	        var hideDirection = 'right';
        }
                
        bannerFunctions.frameRotateTimer = setTimeout('bannerFunctions.frameRotate()', bannerFunctions.bannerTimeoutLength);
        $('.promo_bookmarks').removeClass('promo_bookmarks_active');
        $('.promo_frame').eq(bannerFunctions.activeFrame).hide('slide', {direction: hideDirection}, 500, function() {
        	$(this).clearQueue();
        }).removeClass('promo_frame_active');
        bannerFunctions.activeFrame = frameNumber;
        $('.promo_frame').eq(bannerFunctions.activeFrame).show('slide', {direction: showDirection}, 500, function() {
			$(this).clearQueue();        	
        }).addClass('promo_frame_active');
        $('.promo_bookmarks').eq(frameNumber).addClass('promo_bookmarks_active');
    }
};
var productFunctions =
{
    displayConfigurations: function(data)
    {
        var configWrapper = $('<div id="product_configure_wrapper">');
        $(configWrapper).append($('<div id="product_configure_header">').html('Please Select a Configuration'));
        $(data.configurations).each(function() {
            var configItem = $('<div class="product_configure_row">');
            var configImage = $('<div class="product_configure_img">').append('<img width="90" height="90" alt="' + this.product_name + '" title="' + this.product_name + '" src="http://vault.trilithic.com/instruments/images/products/90/' + this.product_image_name + '" />');
            var configInfo = '<div class="product_configure_info">' + '	<div class="product_configure_name">' + this.product_name + '</div>' + '	<div class="product_configure_subtitle">' + this.product_subtitle + '<br />P/N: ' + this.product_number + '</div>' + '	<a class="input_button input_button_mini product_request_button" name="' + this.product_id + '">Request a Quote</a>' + '</div>';
            $(configItem).append(configImage).append(configInfo);
            $(configWrapper).append(configItem);
        });
        generalFunctions.displayNotice(configWrapper, '610', null, '460', 'Select a Configuration');
    },
    displayOptions: function(data, productId)
	{
        quoteFunctions.configureData = data;
        var customWrapper = '<div id="product_configure_wrapper">';

        // Add Configured Product ID to quoteFunctions.configureData IF it is != to the base product id
        quoteFunctions.configureData.baseproduct.configureproductid = (quoteFunctions.configureData.baseproduct.baseproductid == productId) ? 0 : productId;
             
        switch (quoteFunctions.configureData.baseproduct.baseproductid) {
            // Customize your 9581 SST R3, R4 or TPX
        case '8238':
        case '8239':
        case '8240':
        	generalFunctions.trackEvent('Configurations', 'SST Series', 'Started');

            //Define maximum TMP-8 Options
            var customOptionsMaxTMP8;
            switch (quoteFunctions.configureData.baseproduct.baseproductid) {
            case '8238':
            case '8239':
                customOptionsMaxTMP8 = 2;
                break;
            case '8240':
                customOptionsMaxTMP8 = 8;
                break;
            }

            // Place options in correct groups
            var customOptionsArray = {
                'options': [],
                'tpm8': [],
                'interfaces': []
            };
            $(quoteFunctions.configureData.options).each(function() {
                var thisOption = this;
                switch (thisOption.product_id) {
                case '402':
                case '8284':
                    customOptionsArray.options.push(thisOption);
                    break;
                case '390':
                    customOptionsArray.tpm8.push(thisOption);
                    break;
                case '408':
                case '294':
                case '404':
                    customOptionsArray.interfaces.push(thisOption);
                    break;
                }
            });
            
            customWrapper += '	<form id="form_product_configure" action="/Request/review.html" method="post">';
            if ($(customOptionsArray.options).length) {
                //Optional Features Header
                customWrapper += '		<div id="product_configure_header">' + '			<div class="product_configure_header">Optional Features</div>' + '		</div>';

                //Optional Features Checkboxes
                $(customOptionsArray.options).each(function() {
                    customWrapper += '		<div class="product_configure_row result_row">' + '			<div class="product_configure_functions">' + '				<input class="product_configure_productId" type="hidden" value="' + this.product_id + '" />' + '				<input class="product_configure_selected" type="checkbox" value="' + this.product_id + '" ' + (this.pre_select == 1 ? 'checked="checked"' : '') + ' /> ' + '			</div>' + '			<div class="product_configure_subtitle">' + this.product_name + '</div>' + '		</div>';
                });
                customWrapper += '		<hr />';
            }
            if ($(customOptionsArray.tpm8).length) {
                //TPM-8 Header
                customWrapper += '		<div id="product_configure_header">' + '			<div class="product_configure_header">Number of Test Point Managers (0 - ' + customOptionsMaxTMP8 + ')</div>' + '		</div>' + '		<div class="product_configure_row result_row">' + '			<div class="product_configure_functions">&nbsp;</div>' + '			<div class="product_configure_subtitle">' + '				Quantity: <input id="product_configure_quantity" class="input_text" type="text" size="2" /> ' + '			</div>' + '		</div>' + '		<hr />';

            }
            if ($(customOptionsArray.interfaces).length) {
                //Interface Header
                customWrapper += '		<div id="product_configure_header">Communication Interface</div>';
                //Interface Radio Buttons
                $(customOptionsArray.interfaces).each(function() {
                    customWrapper += '		<div class="product_configure_row result_row">' + '			<div class="product_configure_functions">' + '				<input class="product_configure_productId" type="hidden" value="' + this.product_id + '" />' + '				<input class="product_configure_selected" type="radio" name="' + quoteFunctions.configureData.baseproduct.paseproductid + '" value="' + this.product_id + '" ' + (this.pre_select == 1 ? 'checked="checked"' : '') + ' /> ' + '			</div>' + '			<div class="product_configure_subtitle">' + this.product_name + '</div>' + '		</div>';
                });
                customWrapper += '		<hr />';
            }

            customWrapper += '		<input id="product_configure_submit" class="input_button" type="submit" value="Add to Basket" />' + '	</form>' + '</div>';
            break;

            // Load unique configuration screen for field upgrade product IDs
        case '437':
        case '439':
        case '511':
        case '512':
        case '513':
        case '514':
        case '515':
        case '516':
        case '8344':
        case '8354':
        
	        generalFunctions.trackEvent('Configurations', 'Field Upgrades', 'Started');
	        	
            customWrapper += '	<form id="form_product_configure" action="#" method="post">' + '		<div id="product_configure_header">' + '			<div class="product_configure_functions">&nbsp;</div>' + '			<div class="product_configure_name">How many units will be upgraded?</div>' + '		</div>' + '		<div class="product_configure_row result_row">' + '			<div class="product_configure_functions">&nbsp;</div>' + '			<div class="product_configure_name">' + '			Quantity: <input id="product_configure_quantity" class="quote_input" type="text" size="4" value="25">' + '			</div>' + '		</div>' + '		<hr>' + '		<div id="product_configure_header">' + '			<div class="product_configure_functions">&nbsp;</div>' + '			<div class="product_configure_name">What is the location of this upgrade?</div>' + '		</div>' + '		<div id="product_configure_map">' + '			<img src="/_img/configure_zone_map.png" width="460" height="292" alt="Zone Surcharge Map" usemap="#configure_map" id="configure_map_image"/>' + '		</div>';

            $(quoteFunctions.configureData.options).each(function() {
                customWrapper += '		<div class="product_configure_row result_row">' + '			<div class="product_configure_functions">' + '				<input class="product_configure_productId" type="hidden" value="' + this.product_id + '" />' + '				<input class="product_configure_selected" type="radio" name="' + quoteFunctions.configureData.baseproduct.baseproductid + '" value="' + this.product_id + '" ' + (this.pre_select == 1 ? 'checked="checked"' : '') + ' /> ' + '			</div>' + '			<div class="product_configure_name">' + this.product_name + '</div>' + '		</div>';
            });

            customWrapper += '		<hr>' + '		<input id="product_configure_submit" class="quote_button" type="submit" value="Add to Basket" />' + '	</form>' + '</div>';
            break;

            //Default to 860 Options
        default:
        
	        generalFunctions.trackEvent('Configurations', '860', 'Started');
        	            
            customWrapper += '<form id="form_product_configure" action="#" method="post">' + '<p>Please select the options you would like to configure your field analyzer.</p>' + '<div id="product_configure_header">Option Name</div>';

            $(quoteFunctions.configureData.options).each(function() {
                customWrapper += '		<div class="product_configure_row result_row">' + '			<div class="product_configure_functions">' + '				<input class="product_configure_productId" type="hidden" value="' + this.product_id + '" />' + '				<input class="product_configure_selected" type="checkbox" name="' + quoteFunctions.configureData.baseproduct.baseproductid + '" value="' + this.product_id + '" ' + (this.pre_select == 1 ? 'checked="checked"' : '') + ' /> ' + '			</div>' + '			<div class="product_configure_subtitle">' + this.product_name + '</div>' + '		</div>';
            });
            customWrapper += '		<input id="product_configure_submit" class="input_button" type="submit" value="Add to Basket" />' + '	</form>' + '</div>';
            break;
        }
        generalFunctions.displayNotice(customWrapper, 450, null, null, 'Configure Your Product');
       
        // Product Configuration Submit
        $('#form_product_configure').bind('submit', function(e) {
            e.preventDefault();
            
            //Track configuration submits
            switch (quoteFunctions.configureData.baseproduct.baseproductid) {
	            // 9581 SST R3, R4 or TPX
		        case '8238':
		        case '8239':
		        case '8240':
	        	generalFunctions.trackEvent('Configurations', 'SST Series', 'Submitted');
	        	break;
	        	// Field upgrades
	        	case '437':
		        case '439':
		        case '511':
		        case '512':
		        case '513':
		        case '514':
		        case '515':
		        case '516':
		        case '8344':
		        case '8354':
		        generalFunctions.trackEvent('Configurations', 'Field Upgrades', 'Submitted');
		    	//860
		    	default:
		        generalFunctions.trackEvent('Configurations', '860', 'Submitted');
		    	break;        	
        	}

            var aSelectedOptions = [];
            var upgradeQuantity;
            $(':checked', this).each(function() {
                aSelectedOptions.push($(this).val());
            });
            if ($('#product_configure_quantity').val()) {
                upgradeQuantity = $('#product_configure_quantity').val();
            }
            $.getJSON('/_inc/_ajx/ajxQuoteActions.php', {
                action: 'product_configure_submit',
                jaProductOptions: JSON.stringify(aSelectedOptions),
                jProductID: quoteFunctions.configureData.baseproduct.baseproductid,
                jProductQuantity: upgradeQuantity
            }, function(data) {
                switch (data.outcome) {
                case '0':
            	//Track configuration errors
	            switch (quoteFunctions.configureData.baseproduct.baseproductid) {
		            // 9581 SST R3, R4 or TPX
			        case '8238':
			        case '8239':
			        case '8240':
		        	generalFunctions.trackEvent('Configurations', 'SST Series', 'Error');
		        	break;
		        	// Field upgrades
		        	case '437':
			        case '439':
			        case '511':
			        case '512':
			        case '513':
			        case '514':
			        case '515':
			        case '516':
			        case '8344':
			        case '8354':
			        generalFunctions.trackEvent('Configurations', 'Field Upgrades', 'Error');
			    	//860
			    	default:
			        generalFunctions.trackEvent('Configurations', '860', 'Error');
			    	break;        	
	        	}
                var configureError = $('<ul id="product_configure_error_list">');
                if ($.isArray(data.message)) {
                    for (var i = 0; i < data.message.length; i++) {
                        configureError.append($('<li>').append(data.message[i]));
                    }
                }
                else {
                    configureError.append($('<li>').append(data.message));
                }
                if ($('#product_configure_error').length) {
                    $('#product_configure_error').html(configureError);
                }
                else {
                    $('#alert').prepend($('<div id="product_configure_error">').html(configureError));
                }
                if (data.required) {
                    $(data.required).each(function() {
                        $('input.product_configure_selected[value=' + this + ']').attr('checked', 'true');
                    });
                }
                break;
                case '1':
                //Track configuration successes
	            switch (quoteFunctions.configureData.baseproduct.baseproductid) {
		            // 9581 SST R3, R4 or TPX
			        case '8238':
			        case '8239':
			        case '8240':
		        	generalFunctions.trackEvent('Configurations', 'SST Series', 'Success');
		        	break;
		        	// Field upgrades
		        	case '437':
			        case '439':
			        case '511':
			        case '512':
			        case '513':
			        case '514':
			        case '515':
			        case '516':
			        case '8344':
			        case '8354':
			        generalFunctions.trackEvent('Configurations', 'Field Upgrades', 'Success');
			    	//860
			    	default:
			        generalFunctions.trackEvent('Configurations', '860', 'Success');
			    	break;        	
	        	}
	        	quoteFunctions.configureData.baseproduct.baseproductid = null;
                generalFunctions.hideNotice();
                window.location = "/Request/review.html";
                }
            });
        });
    }
}    

    var quoteFunctions =
    {
        configureData: null,
        formatCurrency: function(num) {
            num = parseFloat(num);
            num = isNaN(num) || num === '' || num === null ? 0 : num.toFixed(2);
            num += '';
            x = num.split('.');
            x1 = x[0];
            x2 = x.length > 1 ? '.' + x[1] : '';
            var rgx = /(\d+)(\d{3})/;
            while (rgx.test(x1)) {
                x1 = x1.replace(rgx, '$1' + ',' + '$2');
            }
            return x1 + x2;
        }
    }

    $(document).ready(function() {
        ////////////////////////////////////
        // Homepage Banner
        ////////////////////////////////////
        bannerFunctions.frameLength = $('.promo_frame').length;
        
        //Banner click tracking
        $('.promo_frame').click(function(e){
        	e.preventDefault();
        	generalFunctions.trackEvent('Banner', 'INST Home', $(this).attr('id'));
        	window.location = $(this).find('a').attr('href');
		});
        
        var bannerBookmarks = $('#promo_bookmarks_wrapper');
		
        // Initialize banner bookmarks
        for (i = 1; i <= bannerFunctions.frameLength; i++)
        {
            bannerBookmarks.append($('<div class="promo_bookmarks' + (i==1?' promo_bookmarks_active':'') + '">'));
        }

        // Banner bookmark listener
        $('.promo_bookmarks').live('click', function ()
        {
            var thisBookmark = $(this).index('.promo_bookmarks');
            bannerFunctions.goToFrame(thisBookmark);
        });

        bannerFunctions.frameRotateTimer = setTimeout('bannerFunctions.frameRotate()', bannerFunctions.bannerTimeoutLength);
        
        ////////////////////////////////////
        // Slider
        ////////////////////////////////////
        /* No mas slider!
        var handleWidth = parseInt($('#featured_slider_handle').css('width'));
        var sliderWidth = $('.featured_product').outerWidth(true) * $('.featured_product').length;
        var wrapperWidth = $('#featured').width();
        $('#featured_slider').css('width', sliderWidth + 'px');

        $('#featured_slider_handle').draggable( {
            containment: 'parent',
            drag: function(event, ui) {
                var handlePosition = parseInt($('#featured_slider_handle').css('left'));
                var handlePercent = handlePosition / (wrapperWidth - handleWidth);
                $('#featured_slider').css('right', (sliderWidth - wrapperWidth) * handlePercent + 'px');
            }
        });
		*/
        ////////////////////////////////////
        // Product Page
        ////////////////////////////////////
        $('#product_tab_wrapper').tabs();

        //Show Documents when category is clicked
        $('.product_documents_type').click(function() {
            $(this).next('.product_documents_file_list').toggle('blind', 250);
        });
		
		//Show Instruments vs. Telco Reps
    	$('#showtelcoreps').click(function() {
    	    $('.locator_rep_inst_domestic').hide();
    	    $('.locator_rep_inst_int').hide();
    	    $('.locator_rep_telco_domestic').show();
    	});
    	
    	$('#showbroadbanddomesticreps').click(function() {
    	    $('.locator_rep_telco_domestic').hide();
    	    $('.locator_rep_inst_int').hide();
    	    $('.locator_rep_inst_domestic').show();
    	});
    	
    	$('#showbroadbandintreps').click(function() {
    	    $('.locator_rep_telco_domestic').hide();
    	    $('.locator_rep_inst_domestic').hide();
    	    $('.locator_rep_inst_int').show();
    	});
    	
        //Set the number of documents to display for each type
        var productDocumentsDisplayed = 2;

        $('.product_documents').each(function() {
            var productDocuments = $(this).find('.product_documents_file');

            //Hide any documents greater than the quantity defined by productDocumentsDisplayed
            productDocuments.each(function() {
                if ($(productDocuments).index(this) > productDocumentsDisplayed - 1) {
                    $(this).hide();
                }
            });

            //Create a "More" link if more documents are available
            if (productDocuments.length > productDocumentsDisplayed) {
                productDocuments.last().after($('<li class="product_documents_more product_documents_file">').html('<a href="#more">' + (productDocuments.length - productDocumentsDisplayed) + ' More available</a>'));
            }
        });
        
        //Display more documents
        $('.product_documents_more').click(function(e) {
        	var theseDocs = $(this).parents('ul').clone();
        	theseDocs.find('.product_documents_more').remove();
        	theseDocs.find('li').show();
        	generalFunctions.displayNotice(theseDocs, '480', null, '360', 'More Documents');
		});
 
        //Request a Quote
        $('.product_request_button').live('click', function(e) {
            e.preventDefault();
            var productId = $(this).attr('name');
            $.getJSON('/_inc/_ajx/ajxQuoteActions.php', {
                action: 'product_add',
                jProductID: productId
            }, function(data) {
                if (data.configurations) {
                	productFunctions.displayConfigurations(data);
                }
                else if (data.options) {
                    	productFunctions.displayOptions(data, productId);
                }
                else if (data.outcome == '0') {
                    generalFunctions.displayNotice(data.message);
                }
                else if (data.outcome == '1') {
                    window.location = "/Request/review.html";
                }
            });
        });

        //Initialize Product Videos
        var thisVid = $('#product_video').attr('name');
        if (thisVid != '') {
            swfobject.embedSWF("http://www.youtube.com/e/" + thisVid + "?enablejsapi=1&playerapiid=product_video", "product_video", "300", "251", "8", null, null, generalFunctions.videoParams, generalFunctions.videoAtts);
        }

        ////////////////////////////////////
        // Quote Summary
        ////////////////////////////////////
        $('#form_summary_contact_new').hide().find('input, select, textarea').removeClass('required');
        $('#form_summary_contact_update').hide().find('input, select, textarea').removeClass('required');
        $('#form_summary_submit').hide();

        //Change product quantity
        $('.input_quantity').change(function(e) {
            e.preventDefault();
            var thisProductID = $(this).parents('.summary_product_quantity').siblings('.summary_product_functions').find('.summary_product_id').val();
            $.getJSON('/_inc/_ajx/ajxQuoteActions.php', {
                action: 'product_update',
                jProductID: thisProductID,
                jQuantity: $(this).val()
            }, function(data) {
                //Do something?
            });
        });

        //Validate email address against database
        $('#form_summary_login').submit(function(e) {
            e.preventDefault();
            if (generalFunctions.validateForm(this)) {
                $.getJSON('/_inc/_ajx/ajxQuoteActions.php', {
                    action: 'validate',
                    jEmailAddress: $('#summary_login').val()
                }, function(data) {
                    switch (data.outcome) {
                    case '0':
                        generalFunctions.displayNotice(data.message, '480', 10);
                        generalFunctions.trackEvent('Quote Submit', 'Email Entry', data.message);
                        break;
                    case '1':
                    	generalFunctions.trackEvent('Quote Submit', 'Email Entry', 'Success');

                    	//We're doing this now so we can check if the fields that need updating are "Required"
                    	//Then we can determine whether to load the Update or Success form
                    	var reqFields = [];
                    	var updateBool = 0;
                    	if(data.update){
                    		var updateForm = $('#form_summary_contact_update');
	                    	//Gather up required fields for an update page.
                    		$(updateForm).find('.input_required_wrapper').find('input, select, text area').each(function(){
                    			thisPointer = this;
                    			reqFields.push($(thisPointer).attr('name'));
                    		});
                    		//Check if any of the returned values are in our "Required" array
                    		for(i=0; i < data.update.length; i++){
	                			if($.inArray(data.update[i], reqFields) != -1){
	                				updateBool = 1;
	                			}
                			}
                    	}
                    
                    	//Create new contact
                        if (data.contactid <= 0) {
                        	$('#summary_contact_id').val(null);
                            $('#form_summary_login').hide('blind', 250, function(){
                            	$(this).find('input, select, textarea').removeClass('required');
                            	$('#form_summary_contact_new').show('blind', 250).find('.input_required_wrapper').find('input, select, textarea').addClass('required');
                            	$('#summary_email').val($('#summary_login').val());
                            });
                        //Contact requires updates
                        } else if (data.update && updateBool == 1){
                        	var updateForm = $('#form_summary_contact_update');
                        	$('#form_summary_login').hide('blind', 250, function(){
                            	$('#summary_contact_id').val(data.contactid);
                            	//Remove required field and hide the login form
                            	$(this).find('input, select, textarea').removeClass('required');
                            	$('#form_summary_contact_update').find('input, select, textarea, label').attr('disabled','disabled').hide();
                            	//Enable and show required fields on update form
                            	for(i=0; i < data.update.length; i++){
                            		var thisInput = $(updateForm).find('.input_required_wrapper').find('[name = ' + data.update[i] + ']');
                            		if(thisInput){
	                            		thisInput.parent('.input_required_wrapper').show();
	                            		thisInput.parent('.input_required_wrapper').prev('label').show();
	                            		thisInput.addClass('required').removeAttr('disabled').show();
	                            		thisInput.siblings('label').show();
                            		}
                            	}
                            	//Display the Email input
                            	var thisEmail = $(updateForm).find('.input_required_wrapper').find('[name = Email]');
                            	thisEmail.val($('#summary_login').val()).show();
                            	thisEmail.parent('.input_required_wrapper').prev('label').show();
                            	//Show the previously disabled submit button;
                            	$(updateForm).find('.input_button').removeAttr('disabled').show();
                            	$(updateForm).show('blind', 250)
                            });
                        //Successful login
                        } else if (data.contactid > 0) {
                            $('#summary_contact_id').val(data.contactid);
                            $('#summary_submit_email').html($('#summary_login').val());
                            $('#form_summary_login').hide('blind', 250, function(){
	                            $(this).find('input, select, textarea').removeClass('required');
	                            $('#form_summary_submit').show('blind', 250);
                            });
                        }
                        break;
                        default:
                        generalFunctions.displayNotice('There has been an error.  Please try again later.', '480', 10);
			        	generalFunctions.trackEvent('Quote Submit', 'Email Entry', 'No Response');
                    }
                });
            }
        });
        
        $('#summary_relog').click(function(e) {
        	e.preventDefault();
            $('#form_summary_submit').hide('blind', 250, function(){
            	$('#form_summary_login').show('blind', 250).find('input, select, textarea').addClass('required');
            });
            $('#summary_contact_id').val(null);
        });
        
        $('#summary_contact_back').click(function(e) {
        	e.preventDefault();
            $('#form_summary_contact_new').hide('blind', 250, function(){
            	$(this).find('.input_required_wrapper').find('input, select, textarea').removeClass('required');
            	$('#form_summary_login').show('blind', 250).find('input, select, textarea').addClass('required');
            });
            $('#summary_contact_id').val(null);
        });
        
        $('#summary_update_back').click(function(e) {
        	e.preventDefault();
            $('#form_summary_contact_update').hide('blind', 250, function(){
            	$(this).find('.input_required_wrapper').find('input, select, textarea').removeClass('required');
            	$('#form_summary_login').show('blind', 250).find('input, select, textarea').addClass('required');
            });
            $('#summary_contact_id').val(null);
        });

        //Insert/Update new contact
        $('#form_summary_contact_new, #form_summary_contact_update').submit(function(e) {
            e.preventDefault();
            thisPointer = this;
            if (generalFunctions.validateForm(this)) {
                $.getJSON('/_inc/_ajx/ajxQuoteActions.php', {
                    action: 'contact_info',
                    jContactID: $('#summary_contact_id').val() ? $('#summary_contact_id').val() : 0,
                    jContactInfo: JSON.stringify($(thisPointer).serializeArray()),
                    jEmailAddress: $(thisPointer).find('input[name="Email"]').val()
                }, function(data) {
                    switch (data.outcome) {
                    case '0':
                        generalFunctions.displayNotice(data.message, '480', 10);
                        generalFunctions.trackEvent('Quote Submit', 'New Contact', data.message);
                        break;
                    case '1':
                        $('#summary_contact_id').val(data.contactid);
                        $('#summary_submit_email').html($('#summary_login').val());
                        $(thisPointer).hide('blind', 250, function(){
                        	$('#form_summary_submit').show('blind', 250).find('.summary_head').html('Welcome to Trilithic.');
                        });
                        generalFunctions.trackEvent('Quote Submit', 'New Contact', 'Success');
                        break;
                    default:
                        generalFunctions.trackEvent('Quote Submit', 'New Contact', 'No Response');
                        break;
                    }
                });
            }
        });

        $('#form_summary_submit').on('submit', function(e) {
            e.preventDefault();
            $('.input_error').html('');
            if (generalFunctions.validateForm(this)) {
                $.getJSON('/_inc/_ajx/ajxQuoteActions.php', {
                    action: 'send_quote',
                    jComments: ($('#summary_comments').val() == 'Enter additional comments here...' ? '' : $('#summary_comments').val()),
                    jEmailAddress: $('#summary_email').val(),
                    jContactID: $('#summary_contact_id').val()
                }, function(data) {
                    switch (data.outcome) {
                    case '0':
                        generalFunctions.displayNotice(data.message, null, 10);
                        generalFunctions.trackEvent('Quote Submit', 'Submit', data.message);
                        break;
                    case '1':
                        generalFunctions.displayNotice('<h3>Your request for quote has been submitted.</h3><p>A copy of your request for a quote has been sent to your email address.  A Trilithic representative will contact you to discuss your quote.</p><p>You will be redirected to the Trilithic Broadband Instruments homepage shortly.</p>', 480, 10);
                        setTimeout(function() {
                            window.location = "http://instruments.trilithic.com";
                        }, 10000);
                        generalFunctions.trackEvent('Quote Submit', 'Submit', 'Success');
                        break;
                    default:
                        generalFunctions.trackEvent('Quote Submit', 'Submit', 'No Response');
                        break;
                    }
                });
            }
        });

        // Remove product from quote
        $('.summary_product_remove').click(function(e) {
            e.preventDefault();
            var thisProductWrapper = $(this).parents('.summary_product');
            $.getJSON('/_inc/_ajx/ajxQuoteActions.php', {
                action: 'product_delete',
                jProductID: $(this).siblings('.summary_product_id').val()
            }, function(data) {
                if (data.outcome == '1') {
                    thisProductWrapper.hide('blind', 250, function() {
                        if (data.items.length === 0) {
                            location.reload();
                        }
                        else {
                            thisProductWrapper.remove();
                        }
                    });
                }
            });
        });
    });

