PreviewShoppingCartModule = function()
{
    var processorUrl = null;
    var moduleId = null;
    var sandbox = null;
    var self = this;
    var myContextX = null;
    var myContextY = null;
    var mainWidgetContainer = null;
    var previewShoppingCart = null;
    var myOverlay = null;
    var overlayCloseButton = null;
    var overlayGoToCartButton = null;
    var overlayArrowSliderUp = null;
    var overlayArrowSliderDown = null;
    var orderedProductIds = null;
    var contentSliderMask = null;
    var contentSliderUp = null;
    var contentSliderDown = null;
    var contentOrderedProducts = null;
    var contentGoToCartButton = null;
    var eachBoxHeight = null;
    
    this.init = function(moduleId_p, data_p, sandbox_p)
    {
        //processorUrl = "../model/FiftyHeader_MDL.php";
        processorUrl = location.protocol + "//" + location.hostname + "/model/FiftyHeader_MDL.php";
        moduleId = moduleId_p;
        sandbox = sandbox_p;
        myContextX = data_p['myContextX'];
        myContextY = data_p['myContextY'];
        mainWidgetContainer = document.getElementById('mainWidgetContainer');//div uses as container for the YUI overlay
        eachBoxHeight = 80;
        getInitialPreviewShoppingCartView();
    };

    this.setContentOrderedProducts = function(html,orderedProductIdArrayLength)
    {
        sandbox.removeClass(contentOrderedProducts,'loading');
        contentOrderedProducts.innerHTML = '';
        contentOrderedProducts.innerHTML = html;
        sandbox.removeClass(contentGoToCartButton,'display-none');
        var data = {
            orderedProductIdArrayLength: orderedProductIdArrayLength
        };
        setSliderArrows();
        sandbox.notify('ordered-products-ready-set-content');
    };
    
    this.setContentEmptyCart = function(html)
    {
        sandbox.removeClass(contentOrderedProducts,'loading');
        contentOrderedProducts.innerHTML = html;
        sandbox.addClass(contentGoToCartButton, 'display-none');
        sandbox.notify('empty-cart-ready-set-content');
    };
    
  
    var getOrderedProductIds_success = function(o)
    {
        var data = null;
        try {
            data = sandbox.jsonParse(o.responseText);    
        }
        catch(x) {
            alert("Failure on: getOrderedProductIds_success. " + x);
        }
        orderedProductIds = data;
        var myData = {
            orderedProductIds: orderedProductIds
        };
        sandbox.notify('ordered-products-ready-preview-shopping-cart', myData);
    };
    
    var getOrderedProductIds_failure = function()
    {
        alert('Failure on: getOrderedProductIds');
    };
    
    this.getOrderedProductIds = function()
    {
        var method = 'POST';
        var url = processorUrl;
        var scope = self;
        var success = getOrderedProductIds_success;
        var failure = getOrderedProductIds_failure;
        var postData = "action=getOrderedProductIds";
        var handleEvent = {
            method:method,
            url:url,
            scope:scope,
            success:success,
            failure:failure,
            postData:postData
        };
        sandbox.ajaxRequest(handleEvent);        
    };

    var setSliderArrows = function()
    {
        //Note: 2010 Sep 15
        //The function was changed completely. This is the new code
        var userViewPortHeight = (Math.floor(sandbox.getViewportHeight()/eachBoxHeight)*eachBoxHeight);//user's height
        var orderedProductIdArrayLength = orderedProductIds.length;//number of ordered products
        var myHeight = 0;
        var j = 0;
        var setSliders = false;
        for(i=0; i<orderedProductIdArrayLength; i++)
        {
            j = i+1;
            myHeight = (j*eachBoxHeight)+(eachBoxHeight*2);
            if(myHeight > userViewPortHeight)
            {
                setSliders = true;
                showSliderArrows();
                addListenerToSliders();
                sandbox.setStyle(contentOrderedProducts, 'max-height', (i*eachBoxHeight)+"px");//content-ordered-product max-height
                i = orderedProductIdArrayLength;//finish the main loop (for i=0...)
            }
                
        }
        if(setSliders == false)
        {
            hideSliderArrows();    
        }
    };
    
    var showSliderArrows = function()
    {
        sandbox.removeClass(contentSliderUp,'display-none');//remove class to view the arrows
        sandbox.removeClass(contentSliderDown,'display-none');//remove class to view the arrows
    };

    var hideSliderArrows = function()
    {
        var upArrowHasThisClass = sandbox.hasClass(contentSliderUp,'display-none');
        if(upArrowHasThisClass == false)
        {
            sandbox.addClass(contentSliderUp,'display-none');
        }
        var downArrowHasThisClass = sandbox.hasClass(contentSliderDown,'display-none');
        if(downArrowHasThisClass == false)
        {
            sandbox.addClass(contentSliderDown,'display-none');
        }
    };    
    
    var addListenerToSliders = function()
    {
        sandbox.addListener(overlayArrowSliderUp,'click',slideUp,self,true);
        sandbox.addListener(overlayArrowSliderDown,'click',slideDown,self,true);
    };

    var removeListenerToSliders = function()
    {
        sandbox.removeListener(overlayArrowSliderUp,'click');
        sandbox.removeListener(overlayArrowSliderDown,'click');
    };
    
    var slideUp = function()
    {
        removeListenerToSliders();
        var firstElement = sandbox.selectorQuery(".firstElement ", contentOrderedProducts, true);
        var firstElementPositionY = sandbox.getY(firstElement);
        var elementTop = sandbox.getY(contentSliderUp);
        
        if(firstElementPositionY <= elementTop)
        {
            var myContainerPositionY = sandbox.getY(contentSliderMask);
            var mySliderPositionX = sandbox.getX(contentOrderedProducts);
            var mySliderPositionY = sandbox.getY(contentOrderedProducts);
            var toYou = mySliderPositionY+eachBoxHeight;
            var attributes = {
                //points: {to:[mySliderPositionX, toYou]}
                points: {
                            from:[mySliderPositionX, mySliderPositionY],
                            to:[mySliderPositionX, toYou]
                        }
            };
            var duration = 0.5;
            var method = YAHOO.util.Easing.easeOut;
            var myAnim = sandbox.motion(contentOrderedProducts, attributes, duration, method);
            myAnim.onComplete.subscribe(addListenerToSliders);
            myAnim.animate();              
        }
        else
        {
            addListenerToSliders();
        }
    };
    
    var slideDown = function()
    {
        removeListenerToSliders();
        var lastElement = sandbox.selectorQuery('.lastElement', contentOrderedProducts, true);
        var lastElementPositionY = sandbox.getY(lastElement);
        var elementTop = sandbox.getY(contentSliderDown);
        
        if(lastElementPositionY >= elementTop)
        {
            var myContainerPositionY = sandbox.getY(contentSliderMask);
            var mySliderPositionX = sandbox.getX(contentOrderedProducts);
            var mySliderPositionY = sandbox.getY(contentOrderedProducts);
            var toYou = mySliderPositionY-eachBoxHeight;
            var attributes = {
                //points: {to:[mySliderPositionX, toYou]}
                points: {
                            from:[mySliderPositionX, mySliderPositionY],
                            to:[mySliderPositionX, toYou]
                        }
            };
            var duration = 0.5;
            var method = YAHOO.util.Easing.easeOut;
            var myAnim = sandbox.motion(contentOrderedProducts, attributes, duration, method);
            myAnim.onComplete.subscribe(addListenerToSliders);
            myAnim.animate();              
        }
        else
        {
            addListenerToSliders();
        }
    };

    var closeButton_Click = function()
    {
        options = {path: "/"};
        sandbox.deleteCookie("preview-cart",options);
        myOverlay.hide();
    };
    
    var goToCartButton_Click = function()
    {
        options = {path: "/"};
        sandbox.deleteCookie("preview-cart",options);
        location.href="http://"+location.hostname+"/cart_action.php";
    };
    
    var createPreviewShoppingCartOverlay = function()
    {
        previewShoppingCart = document.getElementById('previewShoppingCart');//the id of the YUI overlay
        contentSliderMask = document.getElementById('sliderMask');
        contentOrderedProducts = document.getElementById('content-ordered-products');
        contentGoToCartButton = document.getElementById('content_goToCart_button');
        overlayCloseButton = document.getElementById('close_button');
        contentSliderUp = document.getElementById('content-slider-up');
        contentSliderDown = document.getElementById('content-slider-down');
        overlayGoToCartButton = document.getElementById('goToCart_button');
        overlayArrowSliderUp = document.getElementById('arrowSliderUp');
        overlayArrowSliderDown = document.getElementById('arrowSliderDown');
        sandbox.addListener(overlayCloseButton, 'click', closeButton_Click, self, true);
        sandbox.addListener(overlayGoToCartButton, 'click', goToCartButton_Click, self, true);
        myOverlay = new YAHOO.widget.Overlay(previewShoppingCart, {
                                                                    width:"150px",
                                                                    /*Commented this values to avoid absolute positioning when window is resized*/
                                                                    //x:myContextX,
                                                                    //y:myContextY,
                                                                    visible: false,                                                                    
                                                                    effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25}
                                                                });
        myOverlay.render();
        myOverlay.show();
        self.getOrderedProductIds();
    };
    
    var getInitialPreviewShoppingCartView_success = function(o)
    {
        var html = o.responseText;
        mainWidgetContainer.innerHTML = html;
        sandbox.onContentReady('previewShoppingCart', createPreviewShoppingCartOverlay, self, true);//previewShoppingCart is the id of the html element(div) that is the wrapper of the overlay
    };
    
    var getInitialPreviewShoppingCartView_failure = function()
    {
        alert('Error on: getInitialPreviewShoppingCartView function');
    };
    
    var getInitialPreviewShoppingCartView = function()
    {
        var method = 'POST';
        var url = processorUrl;
        var scope = self;
        var success = getInitialPreviewShoppingCartView_success;
        var failure = getInitialPreviewShoppingCartView_failure;
        var postData = "action=getInitialPreviewShoppingCartView";
        var handleEvent = {
            method:method,
            url:url,
            scope:scope,
            success:success,
            failure:failure,
            postData:postData
        };
        sandbox.ajaxRequest(handleEvent);
    };
};

OrderedProductModule = function()
{
    var processorUrl = null;
    var self = null;
    var sliderMaskObject = null;
    var contentOrderedProductsObject = null;
    
    this.init = function(moduleId_p, data_p, sandbox_p)
    {
        //processorUrl = "../model/FiftyHeader_MDL.php";
        processorUrl = location.protocol + "//" + location.hostname + "/model/FiftyHeader_MDL.php";
        self = this;
        moduleId = moduleId_p;
        sandbox = sandbox_p;
        var orderedProductId = data_p['orderedProductId'];
        contentOrderedProductsObject = data_p['contentOrderedProductsObject'];
        sliderMaskObject = data_p['sliderMaskObject'];
        var removeLinkObject = document.getElementById('remove_link_'+orderedProductId);
        if(removeLinkObject)
        {
            sandbox.addListener(removeLinkObject,"click",removeOrderedProduct,data_p,self);    
        }
    };
    
    var renderOrderedProductContainer = function()
    {
        var mySliderPosition = sandbox.getXY(sliderMaskObject);
        sandbox.setXY(contentOrderedProductsObject,mySliderPosition);
    };
    
    var removeOrderedProductFromView = function(orderedProductId)
    {
        var orderedProductIdContainerObject = document.getElementById('ordered_product_'+orderedProductId);
        sandbox.removeChild(contentOrderedProductsObject,orderedProductIdContainerObject);
        renderOrderedProductContainer();
        sandbox.notify('ordered-product-removed-from-preview-shopping-cart');
    };
    
    var removeOrderedProduct_success = function(o)
    {
        var orderedProductId = o.argument.orderedProductId;
        removeOrderedProductFromView(orderedProductId);
    };
    
    var removeOrderedProduct_failure = function()
    {
        alert('Error on: removeOrderedProduct function');  
    };
    
    var removeOrderedProduct = function(ev,data_p)
    {
        var orderedProductId = data_p['orderedProductId'];
        var method = 'POST';
        var url = processorUrl;
        var scope = self;
        var success = removeOrderedProduct_success;
        var failure = removeOrderedProduct_failure;
        var postData = "action=removeOrderedProduct&orderedProductId="+orderedProductId;
        var args = {
            orderedProductId:orderedProductId
        };
        var handleEvent = {
            method:method,
            url:url,
            scope:scope,
            success:success,
            failure:failure,
            postData:postData,
            argument:args
        };
        sandbox.ajaxRequest(handleEvent);
    };
};

LivePersonChatModule = function()
{
    var processorUrl = null;
    var moduleId = null;
    var sandbox = null;
    var self = this;
    var needValidate = false;
    var defaultVal2 = "Type your question here and click below...";
    var chatTextArea = null;
    var startChatButton = null;
    var formName = null;
    var myOverlay = null;
    var openedModule = null;
    var closedModule = null;
    var closeChatBox = null;
    var chatBoxMinimized=null;


    this.init = function(moduleId_p, data_p, sandbox_p)
    {
        //processorUrl = "../model/FiftyHeader_MDL.php";
        //processorUrl = location.protocol + "//" + location.hostname + "/model/FiftyHeader_MDL.php";
        processorUrl = "/model/FiftyHeader_MDL.php";
        moduleId = moduleId_p;
        sandbox = sandbox_p;
        createLivePersonChat();
    };
    var createLivePersonChat = function()
    {
        var method = 'POST';
        var url = processorUrl;
        var scope = self;
        var success = createLivePersonChat_success;
        var failure = createLivePersonChat_failure;
        var postData = "action=getLivePersonChat";
        var handleEvent = {
            method:method,
            url:url,
            scope:scope,
            success:success,
            failure:failure,
            postData:postData
        };
        sandbox.ajaxRequest(handleEvent);
    };
    var createLivePersonChat_success = function(o)
    {
        var chatboxContainer = document.getElementById('chat-box-container');//div uses as container for the YUI overlay
        var html = o.responseText;
        chatboxContainer.innerHTML = html;
        sandbox.onContentReady('chat-box', showLivePersonChat, self, true);//previewShoppingCart is the id of the html element(div) that is the wrapper of the overlay
    };

    var createLivePersonChat_failure = function()
    {
        //alert('Error on: showLivePersonChat function');
    };
    var showLivePersonChat = function()
    {
            chatTextArea = document.getElementById("lp_msgfield");
            startChatButton = document.getElementById("startChatButton");
            formName = document.getElementById("_lpChatBox");
            chatBoxMinimized = document.getElementById("chat-box-minimized");
            closeChatBox = document.getElementById("close-chat-box");
            sandbox.addListener(chatTextArea,"focus",textAreaOnFocus,self,true);
            sandbox.addListener(chatTextArea,"blur",textAreaOnBlur,self,true);
            sandbox.addListener(startChatButton,"click",submitChatBoxForm,self,true);
            sandbox.addListener(closeChatBox,"click",hideChatBox,self,true);
            sandbox.addListener(chatBoxMinimized,"click",showChatBox,self,true);

            var chatBox = document.getElementById("chat-box");
            var data={"visible":"false"};
            myOverlay = sandbox.newOverlayInstance(chatBox,data);
            var chatboxContainer = document.getElementById('chat-box-container');
            loadCorrectModule();
            myOverlay.render(chatboxContainer);
            myOverlay.show();
            //setTimeout(function(){myOverlay.show()},2000);
    };

    var openChatWindow = function(cbForm,windowName)
    {
        var res = true;
        var msg = document.getElementById("lp_msgfield");
        if(needValidate)
        {
            var validateMessage = "Before you start your chat, type in the following fields:\r\n ";
            if(msg.value.length==0 || msg.value==defaultVal2 )
            {
                validateMessage += "Your Question\r\n";
                res=false;
            }
            if(res==false){
                alert(validateMessage);
            }
        }

        var formurl = cbForm.action;
        if(formurl.indexOf('?')==-1)
        {
            formurl += '?';
        }

        var elemCol = cbForm.elements;

        for(var ie=0; ie<elemCol.length; ie++)
        {
            var et = elemCol[ie].type;
            if(et=="text" || et=="hidden" || et=="radio" || et=="textarea")
            {
                formurl += elemCol[ie].name + "=" + escape(elemCol[ie].value) + "&" ;
            }
        }

        if(res==true)
        {
            window.open(formurl, windowName,'width=475,height=400,resizable=yes');
        }

        return res;
    }


    var textAreaOnFocus = function()
    {

//        var  chatTextArea1 = document.getElementById("lp_msgfield");
        if (chatTextArea.value==defaultVal2)
            chatTextArea.value='';
                //        chatTextArea.value = chatTextArea.innerHTML;
                //        if(chatTextArea.value==defaultVal2)
                //            {
                //                chatTextArea.innerHTML='';
                //                chatTextArea.value = chatTextArea.innerHTML;
                //            }
    }
    var textAreaOnBlur = function()
    {
        if (chatTextArea.value=='')
            chatTextArea.value=defaultVal2;

                //        chatTextArea.innerHTML=chatTextArea.value;
                //        if(chatTextArea.value=='')
                //        {
                //            chatTextArea.innerHTML=defaultVal2;
                //            chatTextArea.value= chatTextArea.innerHTML;
                //        }
            
    }
    var submitChatBoxForm = function()
    {
         openChatWindow(formName,'chat39684833');// this way is ok
    };
    var loadCorrectModule = function()
    {
        openedModule = sandbox.newModuleInstance("opened-chat-box");
        closedModule = sandbox.newModuleInstance("closed-chat-box");
        var cookieValue = sandbox.readCookie("chatBox");
        /*Note: Marco, 2011-04-28
         only if the value is maximixed i will be maximixed
         if the value is minimized or NULL it will be minimized
         now we dont delete the cookie when the value of the cookie change
        */
        if (cookieValue=="maximized")
            showChatBox();
        else
            hideChatBox();
    };
    var showChatBox = function()
    {
        openedModule.render();
        openedModule.show();
        closedModule.render();
        closedModule.hide();
        options = {path: "/"};
        //sandbox.deleteCookie("chatBox",options);
        sandbox.setCookie("chatBox","maximized",options);
        var element = document.getElementById("chat-box");
        sandbox.replaceClass(element,"chatBox-minimized","chatBox-maximized");
    }
    var hideChatBox = function()
    {
        openedModule.render();
        openedModule.hide();
        closedModule.render();
        closedModule.show();
        options = {path: "/"};
        sandbox.setCookie("chatBox","minimized",options);
        var element = document.getElementById("chat-box");
        sandbox.replaceClass(element,"chatBox-maximized","chatBox-minimized");
    };
};

/*************************************Start PageTaggerModule********************/
PageTaggerModule = function()
{
    var processorUrl = null;
    var moduleId = null;
	var sandbox = null;
    var data = null;
    var self = this;
	var ffvisitor = null;

    this.init = function(moduleId_p,data_p,sandbox_p)
    {
		processorUrl = "";
		moduleId = moduleId_p;
		sandbox = sandbox_p;
        data = data_p;
		//this.tagFirstTimeVisitor();
		//Create createFFVisitor create cookie with json: first-visitor, last-visit-date
		createFFVisitor();
    }
	var createFFVisitor = function()
	{
		var value = sandbox.readCookie("visitorFF");
		var expiresDate = getExpiresDate();
        var jsonCookie = null;
		if(value == null)//creates the cookie for the first time
		{
			var now = new Date();
			jsonCookie = '{"first_visitor":true,"last_visit_date":"'+now+'","expires_date":"'+new Date(expiresDate)+'"}';
			try {
				ffvisitor = sandbox.jsonParse(jsonCookie);// saves the json object on this global variable.
			}
			catch (e) {
				alert(e);
			}
            var jsonCookieBase64Encoded = sandbox.base64_encode(jsonCookie);
			createVisitorCookie(jsonCookieBase64Encoded, expiresDate);
		}
		else//reads the cookie if exist
		{
			jsonCookie = sandbox.readCookie("visitorFF");
			try {
                var jsonCookieBase64Decoded = sandbox.base64_decode(jsonCookie);
				ffvisitor = sandbox.jsonParse(jsonCookieBase64Decoded);
			}
			catch (e) {
				alert(e);
			}
		}
	}
	this.tagFirstTimeVisitor = function()
	{
		if(ffvisitor != null)
		{
			if(isNowMajorThanLastVisit(ffvisitor.last_visit_date))
			{
                var now = new Date();
                var expiresDate = getExpiresDate();//set expires day now + 90 days
				ffvisitor.first_visitor = false;
				ffvisitor.last_visit_date = now;
				ffvisitor.expires_date = new Date(expiresDate);
				var jsonCookie = sandbox.stringify(ffvisitor);
                var jsonCookieBase64Encoded = sandbox.base64_encode(jsonCookie);
				updateVisitorCookie(jsonCookieBase64Encoded, expiresDate);
			}
		}
	}
	var createVisitorCookie = function(jsonCookie, expiresDate)
	{
		var optionsConfigure = {"path":"/","domain":location.hostname,"expires":new Date(expiresDate)};
		sandbox.setCookie("visitorFF", jsonCookie, optionsConfigure);
	}
	var updateVisitorCookie = function(jsonCookie, expiresDate)
	{
		var value = sandbox.readCookie("visitorFF");
		if(value != null)
		{
			var optionsConfigure = {"path":"/","domain":location.hostname,"expires":new Date(expiresDate)};
			sandbox.setCookie("visitorFF", jsonCookie, optionsConfigure);
		}
	}
	var getExpiresDate = function()
    {
        var now = new Date();
        now.setDate(now.getDate()+90);//90 days  alert(now);
		return now;
    };
	var isNowMajorThanLastVisit = function(lastVisit)
	{
		var result = false;
		var myDate=new Date(lastVisit);
		var today = new Date();
		today.setMinutes(today.getMinutes()-15);// we are going to delete 15 minutes to compare with the lastvisit
		if (today>=myDate)
		{  
            result = true;
		}
		return result;
	}
};
/*************************************End PageTaggerModule********************/


HeaderLinksModule = function()
{
	var self = this;
	var moduleId = null;
	var sandbox = null;
	var data = null;
	var processorUrl = null;
    var trackMyOrderForm = null;
    var trackMyOrderLink = null;
    
    this.init = function(moduleId_p,data_p,sandbox_p)
    {
		processorUrl = "";
		moduleId = moduleId_p;
		sandbox = sandbox_p;
        data = data_p;
        trackMyOrderForm = document.getElementById("trackMyOrderForm");
        trackMyOrderLink = document.getElementById("trackMyOrderLink");
        if(trackMyOrderLink)
        {
            sandbox.addListener(trackMyOrderLink,'click',submitTrackMyOrderForm,self,true);
        }
    };
    
    var submitTrackMyOrderForm = function()
    {
        if(trackMyOrderForm)
        {
            trackMyOrderForm.submit();
        }
    };
};

/******************************************* SIGN UP FORM FOR EMAILDIRECT.COM IN THE FOOTER ***********************************************/
FooterSignupFormModule = function()
{
    var self = this;
    var moduleId = null;
    var sandbox = null;
    var data = null;
    var processorUrl = null;
    var firstName = null;
    var firstNameHidden = null;
    var email = null;
    var emailHidden = null;
    var telephone = null;
    var telephoneHidden = null;
    var eventDate = null;
    var eventDateHidden = null;
    var eventDateCalendar = null;
    var submit_button = null;
    var signUpCalendar = null;
    var signUpDialog = null;
    var strandsUserId = null;
    
    this.init = function(moduleId_p,data_p,sandbox_p)
    {
        processorUrl = "/model/FiftyHeader_MDL.php";
        moduleId = moduleId_p;
        sandbox = sandbox_p;
        data = data_p;
        firstName = sandbox.get('ed_first_name');
        firstNameHidden = sandbox.get('ed_first_name_hidden');
        email = sandbox.get('ed_email');
        emailHidden = sandbox.get('ed_email_hidden');
        telephone = sandbox.get('ed_telephone');
        telephoneHidden = sandbox.get('ed_telephone_hidden');
        eventDate = sandbox.get('ed_event_date');
        eventDateHidden = sandbox.get('ed_event_date_hidden');
        eventDateCalendar_button = sandbox.get('event-date-calendar');
        submit_button = sandbox.get('ed_signup_button');
        strandsUserId = sandbox.get('ed_strands_user_id');
        
        var dialogConfig = {
			width: "192px",
			height:"248px",
			visible:false,
			context:[eventDateCalendar_button, "tl", "tr",["beforeShow", "windowResize"]],
			draggable:false,
			close:true
		};
        
        signUpDialog = sandbox.Dialog('signupCalendarContainer',dialogConfig);
        signUpDialog.setHeader('Select a Date');
        signUpDialog.render();
        
       var calendarNavConfig = {
				strings : {
					month: "Choose Month",
					year: "Enter Year",
					submit: "OK",
					cancel: "Cancel",
					invalidYear: "Please enter a valid year"
				},
				monthFormat: YAHOO.widget.Calendar.LONG,
				initialFocus: "year"
		};
        
        var calendarConfig = {
            navigator:calendarNavConfig,			
			iframe : false        	// Turn iframe off, since container has iframe support.
		};
        
        signUpCalendar = sandbox.Calendar("signUpCalendar",calendarConfig);
        signUpCalendar.render();
        
        signUpCalendar.selectEvent.subscribe(function() {
			if (signUpCalendar.getSelectedDates().length > 0) 
			{
	
                var selDate = signUpCalendar.getSelectedDates()[0];
                var day = selDate.getDate();
                var month = selDate.getMonth()+1;
                var year = selDate.getFullYear();
                var theDate = month+"/"+day+"/"+year;
                eventDate.value = theDate;
                eventDateHidden.value = theDate;
			} 
			signUpDialog.hide();
		});
        
        // Hide Calendar if we click anywhere in the document other than the calendar
        sandbox.EventOn(document, "click", function(e) {
			
			var el = sandbox.getTarget(e);
			var dialogEl = signUpDialog.element;
			
            if (el != dialogEl && !sandbox.isAncestor(dialogEl, el) && el != eventDateCalendar_button && !sandbox.isAncestor(eventDateCalendar_button, el))
			{
				signUpDialog.hide();
			}
		});
        
        if(firstName)
        {
            sandbox.addListener(firstName,'focus',setBlankFirstName,self,true);
            sandbox.addListener(firstName,'blur',setValueFirstName,self,true);
            sandbox.addListener(firstName,'keypress',checkOnlyLetters,self,true);
        }
        if(email)
        {
            sandbox.addListener(email,'focus',setBlankEmail,self,true);
            sandbox.addListener(email,'blur',setValueEmail,self,true);
        }
        if(telephone)
        {
            sandbox.addListener(telephone,'focus',setBlankTelephone,self,true);
            sandbox.addListener(telephone,'blur',setValueTelephone,self,true);
            sandbox.addListener(telephone,'keypress',phoneNumberChars,self,true);
        }
      
        if(eventDateCalendar_button)
        {
            sandbox.addListener(eventDateCalendar_button,'click',signUpDialog.show,signUpDialog,true);
        }
        if(submit_button)
        {
            sandbox.addListener(submit_button,'click',submitSignUp,self,true);
        }
    };
    
    var setBlankFirstName = function()
    {
        if(firstNameHidden.value == "")
        {
            firstName.value = "";
        }
    };
    
    var setValueFirstName = function()
    {
        if(firstName.value == "")
        {
            firstName.value = "First Name";
            firstNameHidden.value = "";
        }
        else
        {
            firstNameHidden.value = firstName.value;
        }
    };
    
    var checkOnlyLetters = function(e)
    {
        sandbox.hasOnlyLetters(e);
    }
    
    var setBlankEmail = function()
    {
        if(emailHidden.value == "")
        {
            email.value = "";
        }
    };
    
    var setValueEmail = function()
    {
        if(email.value == "")
        {
            email.value = "Email";
            emailHidden.value = "";
        }
        else
        {
            emailHidden.value = email.value;
        }
    };
    
    var setBlankTelephone = function()
    {
        if(telephoneHidden.value == "")
        {
            telephone.value = "";
        }
    };
    
    var setValueTelephone = function()
    {
        if(telephone.value == "")
        {
            telephone.value = "Telephone";
            telephoneHidden.value = "";
        }
        else
        {
            telephoneHidden.value = telephone.value;
        }
    };
    
    var phoneNumberChars = function(e)
    {
        sandbox.phoneNumberChars(e);
    };
    
    var submitSignUp = function()
    {
        submit_button.disabled = true;
        var theFirstName = firstNameHidden.value;
        var theEmail = emailHidden.value
        var theTelephone = telephoneHidden.value
        var theEventDate = eventDateHidden.value;
        //Note: 2011Sep26 - Added strands user id
        var theStrandsUserId = strandsUserId.value;
        
        var error = validateInformation(theFirstName,theEmail,theTelephone,theEventDate);
        
        if(error == "")
        {
            var method = 'POST';
            var url = processorUrl;
            var scope = self;
            var success = submitSignUp_success;
            var failure = submitSignUp_failure;
            var postData = "action=submitSignUp&firstName="+theFirstName+"&email="+theEmail+"&telephone="+theTelephone+"&eventDate="+theEventDate+"&strandsUserId="+theStrandsUserId;
            var handleEvent = {
                method:method,
                url:url,
                scope:scope,
                success:success,
                failure:failure,
                postData:postData
            };
            sandbox.ajaxRequest(handleEvent);
        }
        else
        {
            alert("Error:\n\t"+error);
            submit_button.disabled = false;
        }
    };
    
    var submitSignUp_success = function(o)
    {
        if(o.responseText == "")
        {
            alert("Your information has been sent.");
            clearSignUpForm();
        }
        else
        {
            alert(o.responseText);
        }
        submit_button.disabled = false;
    }
    
    var submitSignUp_failure = function()
    {
        alert("Error in submitSignUp function - FiftyHeaderModules.js");
        submit_button.disabled = false;
    }
    
    var clearSignUpForm = function()
    {
        firstName.value = "First Name";
        firstNameHidden.value = "";
        email.value = "Email";
        emailHidden.value = "";
        telephone.value = "Telephone";
        telephoneHidden.value = "";
        eventDate.value = "Event Date";
        eventDateHidden.value = "";
    }

    var validateInformation = function(theFirstName,theEmail,theTelephone,theEventDate)
    {
        error = "";
        if(trim(theFirstName) == "")
        {
            error += "- You must enter your First Name.\n\t";
        }
        if(trim(theEmail) == "")
        {
            error += "- You must enter an email address.\n\t";
        }           
        if(trim(theTelephone) == "")
        {
            error += "- You must enter a telephone number.\n\t";
        }
        if(trim(theEventDate) == "")
        {
            error += "- You must choose the date of your event.\n\t";
        }
        if(error == "")
        {
            if(!sandbox.isValidEmail(theEmail))
            {
                error += "- Please enter a valid email.\n\t";
            }
            if(!sandbox.isValidTelephoneNumber(theTelephone))
            {
                error += "- Please enter a valid Telephone Number.\n\t";
            }
            if(!sandbox.isValidDate(theEventDate,"MDY"))
            {
                error += "- Please enter a valid event date.\n\t";
            }
        }
        
        return error;
    };
    
    var trim = function(s)
    {
        var l=0;
        var r=s.length -1;
        while(l < s.length && s[l] == ' ')
        {
            l++;
        }
        while(r > l && s[r] == ' ')
        {
            r-=1;
        }
        return s.substring(l, r+1);
    };
}
