
//  ====================================================================================================
//  Error Reporting (remove for deployment)
//  ====================================================================================================

//    window.onerror = function(desc, page, line, chr) {
//        alert('JavaScript error occurred! \n'
//            + '\nError description: \t' + desc
//            + '\nPage address:      \t' + page
//            + '\nLine number:       \t' + line
//            );
//        //window.location = "default.aspx";    
//    }

//  ====================================================================================================
//  Global Variables
//  ====================================================================================================

    var InitialProjectQuoteHeight = 0;
    var InitialProjectDetailsHeight = 0;
    var ctrlClick = false;

//  ====================================================================================================
//  Quote Complete Function
//  ====================================================================================================

    function QuoteComplete() {
        // display the processing screen for slower connections...
       
			$("#complete").css("display","block")
        
			$(".quoter-dropdown").css("display","none");
     
		// submit the form manually and move into myaccount
    
		//document.forms[0].action = 'http://localhost/myaccount2008/saveshortrunquote.aspx';
        document.forms[0].action = 'https://www.discmakers.com/myaccount/saveshortrunquote.aspx';
        document.forms[0].submit();
    }

//  ====================================================================================================
//  Update Panel Functions
//  ====================================================================================================

    // Raised before processing of an asynchronous postback starts and the postback request is sent to the server.         
    function beginRequest(sender, args) {
        var updateTrigger = args.get_postBackElement();
        // if any of the project inputs are being changed or if any of the product controls are being clicked, display the loading screen
        if (updateTrigger.id.indexOf("lbProdOption_") != -1 ||
            updateTrigger.id.indexOf("txtQuantity") != -1 ||
            updateTrigger.id.indexOf("ddShippingCountry") != -1 ||
            updateTrigger.id.indexOf("ddShippingOptions") != -1 ||
            updateTrigger.id.indexOf("ddProductionType") != -1) 
        {
            DisplayLoadingScreen();
        }   // if
    }

    // Raised after the response from the server to an asynchronous postback is received but before any content on the page is updated.
     function pageLoading(sender, args) {
        var updatingPanels = args.get_panelsUpdating();
        if (updatingPanels.length > 0) {
            for (idx = 0; idx < updatingPanels.length; idx++) {
                switch(updatingPanels[0].id)
                {
                    case "ctl00_BodyContent_upOptions":
                        break;
                    case "ctl00_BodyContent_upProject":
                        break;
                    default:
                }   // switch
            }   // for
        }   // if
    }   // pageLoading(sender, args)                      
                         
    // Raised after an asynchronous postback is finished and control has been returned to the browser.                            
    function endRequest(sender, args) {
    }

    // Raised after all content on the page is refreshed as the result of either a synchronous or an asynchronous postback, and after initial page load.
    function pageLoaded(sender, args) {
        var updatedPanels = args.get_panelsUpdated();
        if (updatedPanels.length > 0) {
            for (idx = 0; idx < updatedPanels.length; idx++) {
                // an update panel has been updated...detemrine which one
                switch(updatedPanels[idx].id)
                {
                    case "ctl00_BodyContent_upOptions":
                        CheckForXmlData();
                        BindOptionsPanel();
                        HideAjaxScreen();
                        CheckForRaisedModals();
                        HideLoadingScreen();
                        BindProjectTextbox();
                        break;
                    case "ctl00_BodyContent_upProject":
                        BindProjectPanel();
                        CheckForRaisedModals();
                        HideLoadingScreen();
                        BindProjectTextbox();
                        break;
                }   // switch
            }   // for
        } else {
            // initial page load
            InitialPageBind(); 
        }  // else
	// change the headers of the poster hubbles to display the price
        $("#hubble_PTR200-PRINT-100").find(".avlHubble-title").html("<div>Posters - $59<div>");
        $("#hubble_PTR200-PRINT-300").find(".avlHubble-title").html("<div>Posters - $99<div>");
    }   //    pageLoaded(sender, args)        

//  ====================================================================================================
//  Onload Events (page load event bindings)
//  ====================================================================================================

    // bind all elements on the page
    function InitialPageBind() {

        // Preload all images not loaded for initial render...
        $.avlImgLoader(
            "/Plugins/avlHubble/images/bottom-middle.png",
            "/Plugins/avlHubble/images/corners.png",
            "/Plugins/avlHubble/images/head-left.png",
            "/Plugins/avlHubble/images/head-right.png",
            "/Plugins/avlHubble/images/mid-arrows.png",
            "/Plugins/avlHubble/images/mid-left.png",
            "/Plugins/avlHubble/images/mid-right.png",
            "/Plugins/avlHubble/images/top-middle.png"
        )
        
        // Bind all elements in the options update panel
        BindOptionsPanel();
        
        // Initialize values in the project panel
        InitProjectPanel();
        
        // Bind all elements in the project update panel
        BindProjectPanel();
        
        // bind keypress event to stop tabs...
        BlockTabKeypress();
        
        // bind keypress event to stop tabs...
        BlockCtrlClick();
        
        // bind the key press event to the project name text box (Chrome fix for enter key)
        BindProjectTextbox();
        
        // make sure that the user has cookies turned on in their browser...
        CheckForCookies();
        
    }   // BindPage()


    // check to make sure cookies are enabled...
    function CheckForCookies() 
    {
        if (document.cookie == "")
        {
            $("#no-cookies").css("display","block");
            
            if (isIE6()) {
		        $("select").not(".hidden-dropdown").each(function() {
			        $(this)
				        .after("<span class='replacement'></span>").next()
				        .addClass($(this).attr('class'))
				        .attr('id', $(this).attr('id'))
				        .html($(this).find("option:selected").text())
				        .width($(this).width()-4)
				        .height($(this).height()-4)
				        .prev().addClass("hidden-dropdown").css("display","none");
		        });
            }   // if

        } else {
            $("#no-cookies").css("display","none");
            
            if (isIE6()) {
		        // remove all replacement drop downs from the html
		        $(".replacement").each(function() {
			        $(this).remove();
		        });
		        // convert all drop downs back to normal
		        $(".hidden-dropdown").each(function() {
			        $(this).removeClass("hidden-dropdown").css({
			            display:"block"
			        });
		        });
            }   // if
        }
    }   // CheckForCookies()

	function isIE6()
	{
	    return $.browser.msie && /msie 6\.0/i.test(navigator.userAgent);
	}   // isIE6()


    // initialize values in the project panel
    function InitProjectPanel() 
    {
    }   // InitProjectPanel()


    // bind all elements in the options panel
    function BindOptionsPanel() 
    {
        // Apply the slider functionality...
	    $("#avlSlider").avlSlider();

        // Apply the hubble functionality...
        $(".hubble").avlHubble();
        
    }   // BindOptionsPanel()


    // bind keypress event to stop tabs...
    function BlockTabKeypress() 
    {
        $(document).keydown(function(event) {
            if (event.keyCode == '9') {
                event.preventDefault();
                event.stopPropagation();
            }   // if
        });
    }   // BlockTabKeypress()


    // bind ctrl + click on the option links (Firefox hack)
    function BlockCtrlClick() 
    {
        $(document).keydown(function(event) {
            if (event.ctrlKey) {
                ctrlClick = true;
            }   // if
        });
        $(document).keyup(function(event) {
            ctrlClick = false;
        });
    }   // BlockCtrlClick()


    // bind the key press event to the project name text box
    function BindProjectTextbox() 
    {
        $(".quote-name").keydown(function(event) {
            if (event.keyCode == '13') {
                event.preventDefault();
                event.stopPropagation();
            }   // if
        });
    }   // BindProjectTextbox()


    // bind all elements in the project panel
    function BindProjectPanel() 
    {
        var detailsHeight = $("#project-details").height();
        var quoteHeight = $("#options-container").height() + 20;
		var showDelayTimer = null;
        
        // on;y expand if there is a vertical scroll bar!
        if ( $("#inner-project-details").height() > detailsHeight )
        {
            // make sure that the contents of the quote do not overflow when animation begins
            $("#options-container").css("overflow","hidden");
        }   // if
    }   // BindProjectPanel()


    // Display the loading screen, w/ animated gif, over the project quote section when returning from an async call
    function DisplayLoadingScreen()
    {
        $(".loading-image").css({ display: "block" });
        $(".loading-overlay")
            .css({ display: "block", opacity: 0.0 })
            .animate({ opacity: 1 }, 200, function() { });
    }   // DisplayLoadingScreen()


    // Hide the loading screen, w/ animated gif, over the project quote section when returning from an async call
    function HideLoadingScreen()
    {
        $(".loading-image").css({ display: "block" });
        $(".loading-overlay").css({ display: "block", opacity: 1.0 });
        
        $(".loading-overlay").animate({ opacity: 0.0 }, 200, function() {
            $(this).css({ display: "none" });;
            $(".loading-image").css({ display: "none" });;
         });
    }   // HideLoadingScreen()


    // Display the ajax screen over the page to prevent users from clicking on anything until the async postback is complete
    function DisplayAjaxScreen()
    {
		var overlayHeight, overlayWidth;
		// get the width of the viewport
	    overlayWidth = $(document.body).outerWidth(true)
	    // get the height of the viewport
		if(window.innerHeight || window.innerWidth){ overlayHeight = window.innerHeight; }
		else { overlayHeight = document.documentElement.clientHeight; }
        
        // show the ajax screen
		$("#ajax-screen").css({
			position: "absolute",
			zIndex:"9999",
			left: "0",
			top: "0",
			height:overlayHeight + "px",
			width:overlayWidth + "px",
			backgroundColor: "#000",
			opacity: 0.0,
			display: "block"
		});
    }   // DisplayAjaxScreen()

    // Hide the ajax screen
    function HideAjaxScreen()
    {
        // hide the ajax screen
		$("#ajax-screen").css({
			display: "none"
		});
    }   // HideAjaxScreen()


    // Display a modal window if there were any errors...
    function CheckForRaisedModals()
    {
        var modalErrorID = $(".qty-error-holder").html();
        
        if (modalErrorID.length > 0)
        {
            $.openModal({target:"#" + modalErrorID});
        }   // if
    }   // CheckForRaisedModals()


    // Validate the user has entered a name for their quote
    function ValidateName()
    {
        var quoteName = jQuery.trim($(".quote-name").val()); 
        if (quoteName.length > 0)
        {
            if ($(".price-label").text() == "$0.00")
            {
                $.openModal({target:"#no-price"});
                return false;
            } else {
                return true;
            }   // else
        }   // if
        else
        {
            $.openModal({target:"#quote-name"});
            return false;
        }   // else
    }   // ValidateName()


    // check to see if the xml data has been populated...
    function CheckForXmlData() 
    {
        if ($(".xml-data").val().length > 0) {
            // call the quote complete fucntion
            QuoteComplete();
        }   // if
        
    }   // CheckForXmlData()


//===============================================================================================================
// Link for Subscription
//===============================================================================================================

    function openFooterLink()
    {
       // alert($("#subsemail").val());
        if($("#subsemail").val().length > 0)
        {
            window.open('http://www.discmakers.com/EmailSubscriptionManager/SubscriptionManager.aspx?email='+ $("#subsemail").val() +'&ListToSubscribe=21','suubscribe');
        }
    }
