﻿dialogHtml = undefined;
		$(document).ready(function() {
			$("#infoForSizing a").click(function() {
				var dialog_box = $($(this).attr("rel"));
				var title = $(this).attr("title");
				dialogHtml = dialog_box.html();
				ShowDialog(dialog_box, title, 600, 1000);
				return false;
			});
		});
		
		function ShowDialog(dialog_box, dialogTitle, winHeight, winWidth) 
		{
			dialog_box.dialog({
				modal: true,
				overlay: {
					opacity: 0.5,
					background: "#333"
				},
				height: winHeight,
				width: winWidth,
				title: dialogTitle, 
				open: function(ev, ui) {
					$(this).html(dialogHtml).show();
					BindDialogClickableEvents($(this).find(".clickable"));
				}
			});
			if(!dialog_box.dialog("isOpen"))
				dialog_box.dialog("open");
		}
		
		function BindDialogClickableEvents(elems) {
			elems.each(function() {
				$(this).bind("click", function() {
					$(this).addClass("active").siblings().removeClass("active");
					if($(this).hasClass("active")) {
						$($(this).attr("rel")).show().siblings("div").hide();
					}
				});
				if($(this).hasClass("active")) $(this).trigger("click");
			});
		}
		
		
		
	function HelmetPrompter(prompted, formName)
	{
	    if(!prompted)
        {
            $("#HelmetPrompt").dialog(
            {
                bgiframe: true,
                resizable: false,
                height:140,
                modal: true,
                overlay: 
                {
	                backgroundColor: '#000',
	                opacity: 0.5
                },
	            buttons: 
	            {
	                'Yes': function() 
	                {
	                    $(this).dialog('close');
	                    
	                    $("#AddToCartPrompt").dialog(
                        {
                            bgiframe: true,
                            resizable: false,
                            height:140,
                            modal: true,
                            overlay: 
                            {
                                backgroundColor: '#000',
                                opacity: 0.5
                            },
                            buttons: 
                            {
                                'Yes': function() 
                                {			
	                                dialog_box = $("#AddToCartPrompt");
	                                var title = $("#AddToCartPrompt").attr("title");
	                                dialogHtml = dialog_box.html();
	                                ShowDialog(dialog_box, title, 600, 1200);
                        			
                        			$(formName).submit();
                        			
	                                $(this).dialog('close');
                                },
                                Cancel: function() 
                                {
	                                $(this).dialog('close');
                                }
                            }
                        })
	                
	                    dialog_box = $("#sizingHelp");
	                    var title = $("#sizingHelp").attr("title");
	                    dialogHtml = dialog_box.html();
                        ShowDialog(dialog_box, title, 600, 1200);
	                },
	                'No': function() 
	                {
		                $(this).dialog('close');
		                $(formName).submit();
	                }
	            }
	        })
		    prompted = true;
		}
		else
		{
		    $(formName).submit();
		}
		
		return prompted;
	}