/*
    QuotePopup.js - Mike Cook - 2/3/11
    
    QuotePopup handles loading a popup from an element's click action.  Any element
    that has the 'popup_quote' class will automatically have a click function added
    to its existing click event.

    The only requirement of use is that this js file is included in the page and
    the POPUP_HTML_URL, POPUP_CSS_URL, POPUP_SAVE_URL properties are set correctly.
    The form HTML and CSS are loaded in dynamically and placed on the page.

    Function List (See function for description):
        init()
        prepareForm()
        getContent()
        clearForm()
        setFieldRestrictions()
        getScreenDimensions()
        createHelperFunctions()
        bindPopupButtonAction()
        bindButtonActions()
        bindTrackableActions(p_elements, p_attribute)
        saveForm()
        closeForm()
        displayOverlay()
        positionForm()
        bindQuoteCheckboxAction()
        errorCheckForm(p_short_form)
        showPanel(p_index, p_fade, p_callback)
        setCookieValue(p_name, p_value, p_increment)
        getCookieValue(p_name)
        getCookie(p_string)
*/
var QuotePopup = {
    // "Constants"
    POPUP_HTML_URL: '/wp-content/quote_popup/quote_popup.html', // URL to get HTML for popup form
    POPUP_CSS_URL : '/wp-content/quote_popup/quote_popup.css', // URL to get the CSS for the form
    POPUP_SAVE_URL: '/wp-content/actions/popup_form.php', // URL to save to

    // HTML for popup to display
    popupHTML: null,

    // Window dimensions
    windowWidth: null,
    windowHeight: null,

    // Document height
    documentHeight: null,

    // Text for panel button
    // NOTE: Not a fan of this, but don't want to rework styling
    buttonText: ["Submit", "Request Quote"],

    // Flag for if they request a quote
    requestQuote: false,

    // Flag indicated if data was submitted during this viewing
    requestSubmitted: false,

    //// Initialize the static object
    init: function() {
        // Load the content
        QuotePopup.getContent();
    },

    //// Prepare the form elements and actions once it has loaded
    prepareForm: function() {
        // Clear the form
        QuotePopup.clearForm();

        // Get the screen dimensions
        QuotePopup.getScreenDimensions();

        // Create the helper functions
        QuotePopup.createHelperFunctions();

        // Bind the popup action
        QuotePopup.bindPopupButtonAction();

        // Bind the save and close buttons
        QuotePopup.bindButtonActions();

        // Set the field restrictions
        QuotePopup.setFieldRestrictions();

        // Bind the request a quote checkbox
        QuotePopup.bindQuoteButtonAction();

        // Finally, bind the trackable actions for movies (if present), using the title 
        // as the unique id.
        QuotePopup.bindTrackableActions(jQuery(".movie"), "title");

		// Also, bind the trackable actions for movie headers (if present), using the title 
        // as the unique id.
		QuotePopup.bindTrackableActions(jQuery(".section_link"), "rel");
    },

    //// Gets the HTML  and CSS to inject into the page
    getContent: function() {
        // Add the CSS to the head
		if (document.createStyleSheet) { /* IE */
			document.createStyleSheet(QuotePopup.POPUP_CSS_URL);
		} else {
        	jQuery("head").append(jQuery("<link rel='stylesheet' href='" + QuotePopup.POPUP_CSS_URL + "' type='text/css' media='screen' />"));
		}

        // Get the HTML if we don't have it
        if (QuotePopup.popupHTML === null) {
            jQuery.ajax({
                url: QuotePopup.POPUP_HTML_URL,
                type: "GET",
                dataType: "html",
                complete: function(p_response) {
                    // Set the html locally
                    QuotePopup.popupHTML = p_response.responseText;

                    // Attach to page
                    jQuery("body").append(QuotePopup.popupHTML);

                    // Prepare the form
                    QuotePopup.prepareForm();
                }
            });
        }
    },

    //// Clear out the fields
    clearForm: function() {
        // Show the quote button
        jQuery("#popup_quote_contact_quote").css({ display: 'block' });

        // Clear the inputs
        jQuery("#popup_quote_container *:text").val('');

        // Clear the selects
        jQuery("#popup_quote_container select").children("option:first").attr("selected", "selected");

        // Clear the checkboxes
        jQuery("#popup_quote_container *:checkbox").attr("checked", "");

        // Check the keep me informed checkbox
        jQuery("#popup_quote_promo_piece").attr("checked", "checked");

        // Remove any open error classes
        jQuery(".required").removeClass("error");

        // Hide the demo button and show the submit button
        jQuery("#popup_quote_contact_quote").css({ display: 'inline' });
        jQuery("#popup_quote_contact_send").css({ display: 'none' });
        jQuery("#popup_quote_demo").css({ display: 'none' });

        // Hide the demo copy on the submittion page
        jQuery("#popup_quote_demo_copy").css({ display: 'none' });

        // Revert the close button to blue
        jQuery("#contact_form_close").removeClass("popup_quote_grey_button");

        // Revert the submittion state
        QuotePopup.requestSubmitted = false;

		// Revert the quote state
		QuotePopup.requestQuote = false;

        // Rotate back to the first panel
        QuotePopup.showPanel(0, false);
    },

    //// Set restrictions on certain fields
    setFieldRestrictions: function() {
        // Loop through the restricted elements
        jQuery(".required").each(function() {
            // Get the width of the required field, strip out the 'px' and convert to an int
            jQuery(this).parent().css({ width: '250px' });

            // Add the asterisk next to required fields
            jQuery(this).parent().append('<label class="required_field">*</label>');
        });

        // Set phone restriction
        jQuery("#popup_quote_phone_number").customOnly(/[^0-9- xX]/);

        // Set vehicle restriction
        jQuery("#popup_quote_number_of_vehicles").customOnly(/[^0-9]/);
    },

    //// Get and store the screen dimensions
    getScreenDimensions: function() {
        // Window dimensions
        QuotePopup.windowWidth = jQuery(window).width();
        QuotePopup.windowHeight = jQuery(window).height();

        // Document height
        QuotePopup.documentHeight = jQuery(document).height();
    },

    //// Extend jQuery with helper functions
    createHelperFunctions: function() {
        // Check if we have extensions already in place
        if (typeof jQuery.isEmpty === "undefined") {
            // Extend jQuery with some helper functions
	        jQuery.extend(jQuery.fn, {
                //// Check if a field is empty
		        // p_message: Include optional text
		        // p_options: Optional arguments
		        isEmpty: function(p_message, p_options) {
			        var empty = false;
			
			        // Check if options was passed in as the first parameter
			        if (typeof p_message == "object") {
			            p_options = p_message;
			        }
			
			        // Set default for p_options
		            var options = typeof p_options == "undefined" ? { placement: 'right', persistent: true, isSelected: false } : p_options;
			
			        // Set default for p_message
			        p_message = typeof p_message == "undefined" || typeof p_message == "object" ? "Required Field" : p_message;
			
			        jQuery(this).each(function() {
				        // Select
				        if(this.tagName == "SELECT") {
					        if(jQuery(this).children("option").length > 0) {
						        if(typeof options.isSelected != "undefined" && options.isSelected == true && jQuery(this).val().length == 0) {
							        jQuery(this).addClass("error");
							        empty = true;
						        } else {
							        jQuery(this).removeClass("error");
						        }
					        } else {
						        jQuery(this).addClass("error");
						        empty = true;
					        }	
				        } 
				        // Text
				        else {
					        if(jQuery(this).val().length > 0) {
						        jQuery(this).removeClass("error");
					        } else {
						        jQuery(this).addClass("error");
						        empty = true;
					        }
				        }
			        });
			
			        return empty;
		        },
		
		        //// Check if a field is empty
		        // p_message: Include optional text
		        isEmail: function(p_message, p_options) {
			        var email = true;
			
			        // Check if options was passed in as the first parameter
			        if (typeof p_message == "object") {
			            p_options = p_message;
			        }
			
			        // Set default for p_options
		            var options = typeof p_options == "undefined" ? { placement: 'right', persistent: true } : p_options;
			
			        // Set default for p_message
			        p_message = typeof p_message == "undefined" || typeof p_message == "object" ? "Invalid Email Address" : p_message;
			
			        jQuery(this).each(function() {
				        var reg = /^([A-Za-z0-9_\-\.\+])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{1,4})$/;
				
				        if(reg.test(jQuery(this).val()) == false) {
					        jQuery(this).addClass("error");
					        email = false;
				        } else {
					        jQuery(this).removeClass("error");
				        }
			        });
			
			        return email;
		        },

                //// Set the field to only accept the passed in regular expression
		        // p_expression: Regular expression to user
		        // p_case: Optional setting of case
		        customOnly: function(p_expression, p_case) {
		            // Set default for p_case
		            p_case = typeof p_case == "undefined" ? "" : p_case;
		
		            jQuery(this).each(function() {
				        var element = this;
				
				        jQuery(this).bind("keyup", function() {
					        reg = p_expression;
					
					        if(reg.test(jQuery(element).val())) {
						        jQuery(element).val(jQuery(element).val().replace(reg, ''));
					        }
					
					        if (p_case == "upper") {
					            jQuery(element).val(jQuery(element).val().toUpperCase());
					        } else if (p_case == "lower") {
					            jQuery(element).val(jQuery(element).val().toLowerCase());
					        }
				        });
			        });
		        }
            });
        }

        // Check if we .cookie exists
        if (typeof jQuery.cookie === "undefined") {
            //// Handles assigning and deleting cookies
            // p_name: Cookie name
            // p_value: Cookie value
            // p_options (Optional): Options for interacting with the cookie
            //     expires: Either an integer specifying the expiration date from now on in days or a Date object.
            //              If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
            //              If set to null or omitted, the cookie will be a session cookie and will not be retained when the the browser exits.
    	    //     path: The value of the path atribute of the cookie (default: path of page that created the cookie).
            //	   domain: The value of the domain attribute of the cookie (default: domain of page that created the cookie).
            //     secure: If true, the secure attribute of the cookie will be set and the cookie transmission will require a secure protocol (like HTTPS).
            jQuery.cookie = function(p_name, p_value, p_options) {
                // Check if the value is an object or a regular value
                if (typeof p_value === "object") {
                    // Vars for create string version of the object
		            var value_string = "{";
		            var first = true;
		                        
                    // Loop through the object properties
		            for (var property in p_value) {
                        // If this is not the first property, add a comma to seperate properties
			            if (!first) {
                            // Add comma
				            value_string = value_string + ",";
			            } else {
                            // Mark that we hit the first item this iteration
				            first = false;
			            }
			
                        // Add the property to the object string
			            value_string = value_string + "\"" + property + "\":" + (typeof p_value[property] == "string" ? "\"" + p_value[property] + "\"" : p_value[property]);
		            }
		                        
                    // Close out the object string
		            value_string = value_string + "}";
		                        
                    // Call the function again to store the string as the cookie
		            jQuery.cookie(p_name, value_string, p_options);
                } else if (typeof p_value !== 'undefined') {
                    // Set default for p_options
                    p_options = p_options || {};

                    // Check if there was no value passed
                    if (p_value === null) {
                        // Set the value to nothing and set the cookie to expire immediately
                        p_value = '';
                        p_options.expires = -1;
                    }

                    // Expires string var
                    var expires = '';

                    // Check if expires is true and if it is a number or a date
                    if (p_options.expires && (typeof p_options.expires == 'number' || p_options.expires.toUTCString)) {
                        // Date object
                        var date;

                        // If expires is a number convert it to a date
                        if (typeof p_options.expires == 'number') {
                            // Create a new date and add the time from expires
                            date = new Date();
                            date.setTime(date.getTime() + (p_options.expires * 24 * 60 * 60 * 1000));
                        } else {
                            // Otherwise just set it as the date
                            date = p_options.expires;
                        }

                        // Build the string from the date
                        expires = '; expires=' + date.toUTCString();
                    }

                    // Set defaults for the various options in a string format
                    var path = p_options.path ? '; path=' + (p_options.path) : '';
                    var domain = p_options.domain ? '; domain=' + (p_options.domain) : '';
                    var secure = p_options.secure ? '; secure' : '';

                    // Assign the cookie
                    document.cookie = [p_name, '=', encodeURIComponent(p_value), expires, path, domain, secure].join('');
                } else {
                    // Set a null value var since no value was passed
                    var cookie_value = null;

                    // Check that we have a cookie object
                    if (document.cookie && document.cookie !== '') {
                        // Split the cookies out
                        var cookies = document.cookie.split(';');

                        // Loop through the cookies
                        for (var i = 0; i < cookies.length; i++) {
                            // Trim the cookie
                            var cookie = jQuery.trim(cookies[i]);

                            // Check if it matches the cookie name
                            if (cookie.substring(0, p_name.length + 1) == (p_name + '=')) {
                                // Get the value of the cookie and exit
                                cookie_value = decodeURIComponent(cookie.substring(name.length + 1));
                                break;
                            }
                        }
                    }

                    // Return the value
                    return cookie_value;
                }
            };
        }
    },

    //// Check for popup buttons and bind the action to them
    bindPopupButtonAction: function() {
        jQuery(".popup_quote").click(QuotePopup.showForm);  
    },
    
    //// Initial display of form
    showForm: function() {
		// Track the click event
		_gaq.push(['_trackEvent', 'Popup Form', 'Viewed', 'Popup Form']);

    	// Display the overlay
        QuotePopup.displayOverlay();

        // Position the popup form on the page
        QuotePopup.positionForm();

        // Move to the top of the screen, show the overlay and fade in the form
        jQuery("html, body").animate({scrollTop:0}, "fast");
        jQuery("#popup_quote_overlay").css({ display: "block" });
        jQuery("#popup_quote_container").fadeIn(250);

        // Hide an open video if there are on the demo page
        jQuery("#vimeo_video").css({ display: 'none' });
    },

    //// Bind the forms save and close button actions
    bindButtonActions: function() {
        // Bind the save button
        jQuery("#popup_quote_contact_send").click(QuotePopup.saveForm);

        // Bind the close button
        jQuery("#popup_quote_close_form").click(QuotePopup.closeForm);
    },

    //// Binds click actions and stores them in a cookie for sending to post
    // p_elements: Elements to track
    // p_attribute: Attribute to use as unique id (spaces converted to double underscores)
    bindTrackableActions: function(p_elements, p_attribute) {
        // Set default to p_increment
        p_increment = typeof p_increment === "undefined" ? true : p_increment;

        // Loop through the elements
        for (var i = 0; i < p_elements.length; i++) {
            // Bind the click event for the element
            jQuery(p_elements[i]).click(function() {
                // Increment the cookie value
                QuotePopup.setCookieValue(this[p_attribute], 1, true);
            });
        }
    },

    //// Save the form
    // p_no_error_check (Optional): Bypass error check and send incomplete data
    saveForm: function(p_no_error_check) {
        // Set default for error check if it is undefined or the clicked object
        p_no_error_check = typeof p_no_error_check === "undefined" ? false : p_no_error_check;
		p_no_error_check = typeof p_no_error_check === "object" ? false : p_no_error_check;

        // Get the status on whether we are long or short form by checking the request quote checkbox
        var short_form = QuotePopup.requestQuote ? false : true;

        // Error check the form
        if (!QuotePopup.errorCheckForm(short_form) && !p_no_error_check) {
            // Exit out
            return;
        }

        // Create parameter object with values, adding the cookie values at the end
        var parameters = {
            popup_quote_email_address: jQuery("#popup_quote_email_address").val(),
            popup_quote_role_in_process: jQuery("#popup_quote_role_in_process").val(),
            popup_quote_request_quote: QuotePopup.requestQuote,
            popup_quote_promo_piece: jQuery("#popup_quote_promo_piece").attr("checked"),
            popup_quote_full_name: jQuery("#popup_quote_full_name").val(),
            popup_quote_company_name: jQuery("#popup_quote_company_name").val(),
            popup_quote_phone_number: jQuery("#popup_quote_phone_number").val(),
            popup_quote_number_of_vehicles: jQuery("#popup_quote_number_of_vehicles").val(),
            popup_quote_time_frame: jQuery("#popup_quote_time_frame").val(),
            popup_quote_quote_install: jQuery("#popup_quote_quote_install").attr("checked"),
            popup_quote_fieldlogix_plan: jQuery("#popup_quote_fieldlogix_plan").val(),
            popup_quote_purchase_phase: jQuery("#popup_quote_purchase_phase").val(),
            popup_quote_live_demo:  jQuery("#popup_quote_live_demo").attr("checked"),
            popup_quote_comments: jQuery("#popup_quote_comments").val(),
            popup_quote_trackable: JSON.stringify(QuotePopup.getCookie())
        };

        // Save the data
        jQuery.ajax({
            url: QuotePopup.POPUP_SAVE_URL,
            data: parameters,
            type: "POST",
            dataType: 'json'
        });

        // Update flag to show we submitted
        QuotePopup.requestSubmitted = true;
                        
        // Load the blank third panel
        QuotePopup.showPanel(2);

        // Hide the save button and contact quote button
        jQuery("#popup_quote_contact_send, #popup_quote_contact_quote").css({ display: 'none' });

        // If we aren't on the demo page, show the demo button
        if (jQuery("#vimeo_video").length === 0) {
            // Show the demo video button
            jQuery("#popup_quote_demo").css({ display: 'inline' });

            // Add copy for demo
            jQuery("#popup_quote_demo_copy").css({ display: 'block' });

            // Change the close button to gray
            jQuery("#contact_form_close").addClass("popup_quote_grey_button");
        }
        
        // Check if we are tracking a request for information or a request for a quote
        if (p_no_error_check) {
        	// Request information
        	_gaq.push(['_trackPageview', '/popup-form/additional-info.php']);
        } else {
        	// Request a quote
        	_gaq.push(['_trackPageview', '/popup-form/quote.php']);
        }
    },
    
    //// Close the popup form
    closeForm: function() {
        // Hide the popup and overlay
        jQuery("#popup_quote_container, #popup_quote_overlay").css({ display: 'none' });

        // If they didn't already submit, and there is an email in the field, just send it anyways
        if (!QuotePopup.requestSubmitted && !jQuery("#popup_quote_email_address").isEmpty()) {
            QuotePopup.saveForm(true);
        }

        // Clear the fields
        QuotePopup.clearForm();

        // Show the video if there are on the demo page
        jQuery("#vimeo_video").css({ display: 'block' }); 
    },
    
    //// Display or resize the overlay
    displayOverlay: function() {
        // Display the overlay
        jQuery("#popup_quote_overlay").css({ height: QuotePopup.documentHeight + 'px' });    
    },

    //// Position the form in the middle of the viewport
    positionForm: function() {
        // Position the form in the middle of the screen
        jQuery("#popup_quote_container").css({ left: (QuotePopup.windowWidth / 2) - (jQuery("#popup_quote_container").width() / 2) + 'px' });
        jQuery("#popup_quote_container").css({ top: (QuotePopup.windowHeight / 2) - (jQuery("#popup_quote_container").height() / 2) + 'px' });
    },
    
    //// Bind the quote button action
    bindQuoteButtonAction: function() {
        jQuery("#popup_quote_contact_quote").click(function() {
            // Error check first pane
            if (!QuotePopup.errorCheckForm(true)) {                           
                // Exit if there were errors
                return;
            }

            // Update the flag to show they want a quote
            QuotePopup.requestQuote = true;

            // Hide this button since the other button takes over
            jQuery(this).css({ display: 'none' });

            // If there are no errors, show the next panel and recalc the overlay
            QuotePopup.showPanel(1, function() {
                // Recalculate dimensions 
                QuotePopup.getScreenDimensions();

                // Adjust overlay
                QuotePopup.displayOverlay();
            });
            
            // Hide the quote button and show the send button
            jQuery("#popup_quote_contact_quote").css({ display: 'none' });
        	jQuery("#popup_quote_contact_send").css({ display: 'inline' });
        });
    },
    
    //// Check the form for errors
    // p_short_form (Optional): Flag for just checking the first panel
    errorCheckForm: function(p_short_form) {
        // Set default for p_short_form
        p_short_form = typeof p_short_form === "undefined" ? false : p_short_form;

        // Check fields on first pane
        if (!jQuery("#popup_quote_email_address").isEmail()) {
            // Not a valid email so exit
            return false;
        } else if (jQuery("#popup_quote_role_in_process").val() === "") {
            // They didn't select a role, so add the error class and exit
            jQuery("#popup_quote_role_in_process").addClass("error");
            return false;
        } else {
            // Looks good, so remove the error class from the select just in case it was set
            jQuery("#popup_quote_role_in_process").removeClass("error");
        }

        // If we are just checking the first pane, we can safely return here
        if (p_short_form) {
            return true;
        }

        // Check the rest of the fields
        if (jQuery("#popup_quote_full_name, #popup_quote_phone_number, #popup_quote_number_of_vehicles, #research_phase").isEmpty()) {
            // Required fields blank
            return false;
        }

        // We are solid
        return true;
    },

    
    //// Show a panel and hide others
    // p_index: Index of panel to display
    // p_fade (Optional): Flag to fade in panel or just show it
    // p_callback (Optional): Function to call after fade
    showPanel: function(p_index, p_fade, p_callback) {
        // Check if p_callback was sent as second paramater
        if (typeof p_fade === "function") {
            // Set the callback as the fade
            p_callback = p_fade;

            // Set p_fade to default
            p_fade = true;
        } else {
            // Set default for callback and fade
            p_callback = typeof p_callback === "undefined" ? null : p_callback;
            p_fade = typeof p_fade === "undefined" ? true : p_fade;
        }

        // Loop through the panels
        for (var i = 0; i < jQuery(".panel").length; i++) {
            // Shorthand panel
            var panel = jQuery(".panel")[i];

            // Flag if we have a description for this panel
            var description = i < jQuery(".popup_quote_panel_description").length ? jQuery(".popup_quote_panel_description")[i] : null;

            // Check whether we are hiding or showing this panel
            if (i === p_index) {
                // Check if we are fading or not
                if (p_fade) {
                    // Fade in panel
                    jQuery(panel).fadeIn(1000);
                } else {
                    // Just show the panel
                    jQuery(panel).css({ display: 'block' });
                }

                // If we have a description, show it
                if (description !== null) {
                    jQuery(description).css({ display: 'inline' });
                }

                // Perform the callback
                if (p_callback !== null) {
                    p_callback.call(this);
                }
            } else {
                // Hide the panel
                jQuery(panel).css({ display: 'none' });

                // If we have a description, hide it
                if (description !== null) {
                    jQuery(description).css({ display: 'none' });
                }
            }
        }

        // Update button with text for the buttonText array
        jQuery("#popup_quote_contact_send").val(QuotePopup.buttonText[p_index]);
    },

    //// Assign a property, or update one, as a cookie for tracked actions
    // p_name: Cookie name
    // p_value: Cookie value
    // p_increment (Optional): Flag for whether we are incrementing a existing property by p_value
    //                         or just doing a straight assignment                                           
    setCookieValue: function(p_name, p_value, p_increment) {
        // Set default for p_increment
        p_increment = p_increment || false;
                    
        // Get the cookie
        var cookie = QuotePopup.getCookie();

        // Convert the name if it is has spaces
        p_name = p_name.indexOf(' ') !== -1 ? p_name.replace(' ', '_') : p_name;

        // Remove bad characters
        p_name = p_name.replace('?', '').replace('.', ' ').replace('!', '').toLowerCase();

        // Check if we are incrementing or not
        if (p_increment) {
            // Increment the property, or create it at zero if it doesn't exists
            cookie[p_name] = (typeof cookie[p_name] !== "undefined" ? parseInt(cookie[p_name]) : 0) + p_value;
        } else {
            // Set the property
            cookie[p_name] = p_value;
        }
                    
        // Update the cookie
        jQuery.cookie("fieldtechnologies_quote", cookie, { expires: 730, path: "/", secure: false });                       
    },

    //// Get the value of a cookie property for tracked actions
    // p_name: Cookie name
    getCookieValue: function(p_name) {
        // Get the cookie
        var cookie = QuotePopup.getCookie();

        // Convert the name if it is has spaces
        p_name = p_name.indexOf(' ') !== -1 ? p_name.replace(' ', '_') : p_name;

        // Remove bad characters
        p_name = p_name.replace('?', '').replace('.', ' ').replace('!', '').toLowerCase();

        // Get the property (or null if it is unset)
        var value = typeof cookie[p_name] == "undefined" ? null : cookie[p_name];

        // Return the converted property or string value
        if (value == 0) { value = false; };
        if (value == 1) { value = true; };

        // Return the value
        return value;
    },

    //// Return the entire cookie as an object
    // p_string(Optional): Flag to return as string
    getCookie: function(p_string) {
        // Set default for p_string
        p_string = typeof p_string === "undefined" ? false : p_string;

        // Get the cookie string or null
        cookie_string = jQuery.cookie("fieldtechnologies_quote") || null;

        // Check if we are returning a string
        if (p_string) {
            // Return the quote, or if not set null
            return cookie_string;
        }

        // Get the cookie
        var cookie = cookie_string === null ? {} : eval('(' + cookie_string + ')');

        // Return the cookie object
        return cookie;
    }
};

jQuery(document).ready(function() {
    // Initialize the QuotePopup object
    QuotePopup.init();
});
