//
// OVERLAY COPIES
//
var strShowLoc_FindDoms  = "Locations";
var strShowLoc_FindStore = "Please provide your address below and we'll find a Domino's location in your area. " + 
						   "After that you're just a couple of clicks away from delicious.";

var strShowLoc_Coupons   = "Coupons";
var strShowLoc_CoupDesc  = "Please provide your address below so we can show you coupons from the Domino's location in your area.";

var strShowLoc_Menu      = "Menu";
var StrShowLoc_MenuDesc  = "Please provide your address below so we can show you the menu from the Domino's location in your area. You can also <a href='/home/main_servlet?storeid=9999&COMMAND_MENU'>view a smaller menu offered at all locations.</a>";

var strShowLoc_Order     = "Order";
var strShowLoc_OrderDesc = "Please provide your address below and we'll find a Domino's location in your area. " + 
						   "After that you're just a couple of clicks away from delicious.";

var strChangeLoc_FindDoms     = "Find a Domino's";
var strChangeLoc_FindDomsDesc = "Please provide your address below and we'll find a Domino's location in your area. " + 
                                "After that you're just a couple of clicks away from delicious.";
    
var strPhoneNumberLength = 'Please enter your 10 digit cell phone number.';
var strCellNumberNumeric = 'Cell phone number must be numeric.';

var strNoAddressInfo = "Please enter your city, state or zip code.";
var strNoCampusInfo = "Please enter your state, campus, and building.";

var strBlank_StreetAddress = "Street Address";
var strBlank_CityStateZip  = "City, State, or Zip";
    
<!-- mp_trans_disable_start -->

String.prototype.trim = function() {
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
};

// NON-FLASH DIGIAL CLOCK
var clock;
setClock();

function setClock() {
	var weekday 	= new Array(7)
	weekday[0] 		= "SUN";
	weekday[1] 		= "MON";
	weekday[2] 		= "TUE";
	weekday[3] 		= "WED";
	weekday[4] 		= "THU";
	weekday[5] 		= "FRI";
	weekday[6] 		= "SAT";
	
	time=new Date(); // time object
	var minutes 	= time.getMinutes()
	var hours 		= time.getHours()
	
	if (hours<12) {
		ampm = "AM";
	} else {
		ampm = "PM";
	}
	while(hours >12) {
		hours = hours - 12;
	}
	if(minutes<10) {
		minutes = "0" + minutes;
	}
	
	clock = weekday[time.getDay()] + " " + hours + ":" + minutes + " "+ ampm;
}

// FUNCTION TO TOGGLE LABEL VALUES IN FORM FIELDS
jQuery.fn.toggleVal = function(focusClass) {
	this.each(function() {
		$(this).focus(function() {
			// clear value if current value is the default
			if($(this).val() == this.defaultValue) { $(this).val(""); }
			
			// if focusClass is set, add the class
			if(focusClass) { $(this).addClass(focusClass); }
		}).blur(function() {
			// restore to the default value if current value is empty
			if($(this).val() == "") { $(this).val(this.defaultValue); }
			
			// if focusClass is set, remove class
			if(focusClass) { $(this).removeClass(focusClass); }
		});
	});
}

//
// ORDER INTERFACE FUNCTIONS
//

function getAddressInfo() {

	var addr = "";
	
	var strOLOUser     = getCookie("oloUserName");
	var strDCEUser     = getCookie("dceUserName");
	var strOLORemember = getCookie("oloRememberMe");

    var strStreetName;
    var strCity; 
    var strRegion; 
    var zipCookie;

    var strUnit;
    var strBldg; 

    var addressType = getCookie("DomFindStoreCMAddrType");
	
    if (strOLOUser == null && strDCEUser == null && strOLORemember == null) {
	    
        if (!addressType || addressType.length == 0 || addressType == 'undefined' || addressType == 'null') {
            addressType = "";
        }

        if (addressType == "Campus") {
        
            strUnit = getCookie("DomFindStoreCMUnit");
            if (!strUnit || strUnit.length == 0 || strUnit == 'undefined' || strUnit == 'null') {
                strUnit = "";
            }
            addr += "&streetname=" + escape(strUnit);
            strRegion = getCookie("DomFindStoreCMState");   
            if (!strRegion || strRegion.length == 0 || strRegion == 'undefined' || strRegion == 'null') {
                strRegion = "";
            }
            addr += "&region=" + escape(strRegion);
            strBldg = getCookie("DomFindStoreCMBldg");   
            if (!strBldg || strBldg.length == 0 || strBldg == 'undefined' || strBldg == 'null') {
                strBldg = "";
            }
            addr += "&businessName=" + escape(strBldg);
        } else {
            strStreetName = getCookie("DomFindStoreAddr");
            strUnitNumber = getCookie("DomFindStoreUnit");
            strCity       = getCookie("DomFindStoreCity");	
            strRegion     = getCookie("DomFindStoreState");
            strPostalCode = getCookie("DomFindStoreZip");

            if (strStreetName != null && strStreetName != 'undefined') {
                addr += "&streetname=" + escape(strStreetName);
            }

            if (strUnitNumber != null && strUnitNumber != 'undefined') {
                addr += "&unitnumber=" + escape(strUnitNumber);
            }

            if (strCity != null && strCity != 'undefined') { 
                addr += "&city=" + escape(strCity);
            }

            if (strRegion != null && strRegion != 'undefined') {
                addr += "&region=" + escape(strRegion);
            }

            if (strPostalCode != null && strPostalCode != 'undefined') {
                addr += "&postalcode=" + escape(strPostalCode);
            }
        }
        
	}
	
	if (addressType != null && addressType != 'undefined' && addressType != '') {
        	addr += "&addressType=" + escape(addressType);
	}
	return addr;
}

function clickedonme(oloRoot, category, flavor, size, specialty, product, orderdesc, nonOLOStore, strPhoneNumber) {
	
	if (nonOLOStore == "1") {
		showOrderFromStore(strPhoneNumber);	
	} else {
		var baseURL="/olo/faces/servlet/init_servlet?target=new_order";
		var args  = "&category=" + escape(category);
	
		args += "&flavorcode=" + escape(flavor);
		args += "&sizecode=" + escape(size);
		args += "&specialtycode=" + escape(specialty);
		args += "&productcode=" + escape(product);
		args += "&orderdescription=" + escape(orderdesc);
		args += "&sourceid=STM";
		
		args += getAddressInfo();
		
		location.href=(oloRoot + baseURL + args); 
	}
}

function submitOrderToOLO(oloBaseURL, orderXML) {
	var context = "/olo/faces/servlet/init_servlet?target=new_order";
	
	var address = getAddressInfo();
	
	var orderXMLEnc = "&orderxml=" + escape(orderXML);
	
	location.href = oloBaseURL + context + address + orderXMLEnc;
}

function populateSauceOverlay(strOverLayId, category, flavor, orderdesc, nonOLOStore, strPhoneNumber) {  
    var objCategoryHid = document.getElementById('overlay' + strOverLayId + 'Category');
    var objFlavorHid = document.getElementById('overlay' + strOverLayId + 'FlavorCode');
    var objDescriptionHid = document.getElementById('overlay' + strOverLayId + 'Description');
    var objNonOLOStoreHid = document.getElementById('overlay' + strOverLayId + 'NonOLOStore');
    var objPhoneNumberHid = document.getElementById('overlay' + strOverLayId + 'PhoneNumber');
    var objToppingCntHid = document.getElementById('overlay' + strOverLayId + 'ToppingCount');
    var intToppingCnt = 0;

    if (objCategoryHid != null) {
        objCategoryHid.value = category;
    }
    if (objFlavorHid != null) {
        objFlavorHid.value = flavor;
    }
    if (objDescriptionHid != null) {
        objDescriptionHid.value = orderdesc;
    }
    if (objNonOLOStoreHid != null) {
        objNonOLOStoreHid.value = nonOLOStore;
    }
    if (objPhoneNumberHid != null) {
        objPhoneNumberHid.value = strPhoneNumber;
    }


    if (objToppingCntHid != null && !isNaN(objToppingCntHid.value)) {
        intToppingCnt = parseInt(objToppingCntHid.value);
        
        for (var i = 1; i <= intToppingCnt; i++) {
            objToppingInput = document.getElementById('overlay' + strOverLayId + 'Topping' + i);
            
            if (objToppingInput != null) {
                objToppingInput.value = "0";
            }
        }
    }


    return;
}

function closeSauceOverlay(strOLORoot, strOverLayId, strPopupId) {
    var objCategoryHid = document.getElementById('overlay' + strOverLayId + 'Category');
    var objFlavorHid = document.getElementById('overlay' + strOverLayId + 'FlavorCode');
    var objDescriptionHid = document.getElementById('overlay' + strOverLayId + 'Description');
    var objNonOLOStoreHid = document.getElementById('overlay' + strOverLayId + 'NonOLOStore');
    var objPhoneNumberHid = document.getElementById('overlay' + strOverLayId + 'PhoneNumber');
    var objToppingCntHid = document.getElementById('overlay' + strOverLayId + 'ToppingCount');
    var objToppingInput;
    var strOrderXML = "";
    var args = "";
    var baseURL="/olo/faces/servlet/init_servlet?target=new_order";
    var intToppingCnt = 0;

    if (objCategoryHid != null && objFlavorHid != null
        && objDescriptionHid != null && objNonOLOStoreHid != null
        && objPhoneNumberHid != null && objToppingCntHid != null) {

        if (objNonOLOStoreHid.value == "1") {
            closePopup(strPopupId);
            showOrderFromStore(objPhoneNumberHid.value);	
        } else {

            strOrderXML = '<?xml version="1.0" encoding="ISO-8859-1"?>';
            strOrderXML += '<Order><SourceID>STM</SourceID>';
            strOrderXML += '<OrderDescription>' + objDescriptionHid.value + '</OrderDescription>';
            strOrderXML += '<OrderItem  flavorCode="' + objFlavorHid.value + '" specialtyCode="" category="' + objCategoryHid.value + '">';
            strOrderXML += '<ItemQuantity>1</ItemQuantity>';
            strOrderXML += '<ItemModifiers>';

            if (!isNaN(objToppingCntHid.value)) {
                intToppingCnt = parseInt(objToppingCntHid.value);
            }

            for (var i = 1; i <= intToppingCnt; i++) {
                objToppingInput = document.getElementById('overlay' + strOverLayId + 'Topping' + i);

                if (objToppingInput != null) {
                    if (!isNaN(objToppingInput.value) && parseInt(objToppingInput.value) > 0) {

                        strOrderXML += '<ItemModifier code="' + objToppingInput.name + '">';
                        strOrderXML += '<ItemModifierName><![CDATA[' + encodeURIComponent(objToppingInput.getAttribute("desc")) + ']]></ItemModifierName><ItemModifierQuantity>' + objToppingInput.value + '</ItemModifierQuantity><ItemModifierPart>W</ItemModifierPart>';
                        strOrderXML += '</ItemModifier>';

                    }
                }
            }

            strOrderXML += '</ItemModifiers>';
            strOrderXML += '</OrderItem></Order>';

            args = "&orderxml=" + escape(strOrderXML);
            args += getAddressInfo();

            closePopup(strPopupId);

            location.href=(strOLORoot + baseURL + args); 
        }
    } else {
        closePopup(strPopupId);
    }

    return;
}

function clickedCoupon(oloRoot, storeId, couponCode, description, sourceId) {

	var baseURL="/olo/faces/servlet/init_servlet?target=new_order";
	var args = "&couponcode=" + escape(couponCode);
	
	args += "&orderdescription=" + escape('A coupon for ' + description);
	
	if (sourceId != null && sourceId != "") {
		args += "&sourceid=" + escape(sourceId);
	}
	//args += "&addresstype=Address-US";

	args += getAddressInfo();
	 
	location.href=(oloRoot + baseURL + args); 
}

//
// OVERLAYS
//

//Active Popup
var activePopup; 

function getPageDimensions()
{
	var body = document.getElementsByTagName("body")[0];
	var bodyOffsetWidth=0;
	var bodyOffsetHeight=0;
	var bodyScrollWidth=0;
	var bodyScrollHeight=0;
	var pageDimensions = [0,0];
	
	if(typeof document.documentElement !="undefined" && typeof document.documentElement.scrollWidth != "undefined")
	{
		pageDimensions[0] = document.documentElement.scrollWidth;
		pageDimensions[1] = document.documentElement.scrollHeight;
	}
	
	bodyOffsetWidth=body.offsetWidth;
	bodyOffsetHeight=body.offsetHeight;
	bodyScrollWidth=body.scrollWidth;
	bodyScrollHeight=body.scrollHeight;
	
	if(bodyOffsetWidth > pageDimensions[0])
	{
		pageDimensions[0] = bodyOffsetWidth;
	}
	
	if(bodyOffsetHeight > pageDimensions[1])
	{
		pageDimensions[1] = bodyOffsetHeight;
	}
	
	if(bodyScrollWidth > pageDimensions[0])
	{
		pageDimensions[0] = bodyScrollWidth;
	}
	
	if(bodyScrollHeight > pageDimensions[1])
	{
		pageDimensions[1] = bodyScrollHeight;
	}
	return pageDimensions;
}
    
function getViewportSize(){
	var size=[0,0];
	if(typeof window.innerWidth != 'undefined')
	{
		size=[
			window.innerWidth,
			window.innerHeight
		];
	}
	else if (typeof document.documentElement!='undefined' && typeof document.documentElement.clientWidth!='undefined' && typeof document.documentElement.clientWidth!=0){
		
		size=[
			document.documentElement.clientWidth,
			document.documentElement.clientHeight
		];
	}
	else
	{
		size=[
			document.getElementsByTagName('body')[0].clientWidth,
			document.getElementsByTagName('body')[0].clientHeight
		];
	}
	return size;	
} 
    
function makeDim(){
	var body = document.getElementsByTagName("body")[0];
	var pageDimensions=getPageDimensions();
	var viewportSize=getViewportSize();
	
	if(viewportSize[1]>pageDimensions[1])
	{
		pageDimensions[1]=viewportSize[1];
	}
	var dropSheet=document.createElement("div");
	dropSheet.setAttribute("id", "dropSheet");
	dropSheet.style.position = "absolute";
	dropSheet.style.left = "0";
	dropSheet.style.top = "0";
	if (document.all) {
		dropSheet.style.width = parseInt(pageDimensions[0]) +"px";
	} else {
		dropSheet.style.width = pageDimensions[0] +"px";
	}
	dropSheet.style.height = pageDimensions[1]+"px";
	dropSheet.style.zIndex = 1000;
	body.appendChild(dropSheet);		
}


function getScrollY() {
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return scrOfY;
}

function showPopup(popupId) {
	makeDim();
    var viewportSize = getViewportSize();
    var browserWidth = viewportSize[0];
    var browserHeight = viewportSize[1];
    document.getElementById(popupId).style.visibility = "visible";
    
    leftPos = parseInt((browserWidth/2) - 200);
    document.getElementById(popupId).style.left = leftPos + "px";
	topPos = parseInt((browserHeight/2) - 200) + parseInt(getScrollY());
	document.getElementById(popupId).style.top = topPos + "px";
	document.getElementById(popupId).style.zIndex = 1010;
    

	if (document.getElementById("iframe-" + popupId) && navigator.userAgent.toLowerCase().indexOf("msie 6") != -1) {
		document.getElementById("iframe-" + popupId).style.visibility = "visible";
		document.getElementById("iframe-" + popupId).style.top = topPos + 5 + "px";
		document.getElementById("iframe-" + popupId).style.left = leftPos + 1 + "px";
		document.getElementById("iframe-" + popupId).style.zIndex = 1000;
	}


    //Set active popup
    activePopup = popupId;
}
function recalculate() {
    if (document.getElementById("dropSheet")) {
        //Resize existing div
        var pageDimensions=getPageDimensions();
        var viewportSize=getViewportSize();
        
        if(viewportSize[1]>pageDimensions[1])
        {
            pageDimensions[1]=viewportSize[1];
        }
                                                        
        var dropSheet=document.getElementById("dropSheet");
        dropSheet.style.width = pageDimensions[0]+"px";
        dropSheet.style.height = pageDimensions[1]+"px";

        var browserWidth = document.body.clientWidth;
        var browserHeight = document.body.clientHeight;
        leftPos = parseInt((browserWidth/2) - 200);
        
        if (document.getElementById(activePopup)) {
	        document.getElementById(activePopup).style.left = leftPos + "px";
	        topPos = parseInt((browserHeight/2) - 200) + parseInt(getScrollY());
	        //document.getElementById(activePopup).style.top = topPos + "px";
	        document.getElementById(activePopup).style.zIndex = 1010;
        }
    }
}

//Call the recalculate function when window is resized
window.onresize = function() {
	recalculate();
}

  
function closePopup(popupId) {
	var body = document.getElementsByTagName("body")[0];
	var dropSheet = document.getElementById("dropSheet");
	if (body && dropSheet) {
		body.removeChild(dropSheet);
	}
	
	document.getElementById(popupId).style.visibility = "hidden";
	
    if (document.getElementById("iframe-" + popupId)) {
		document.getElementById("iframe-" + popupId).style.visibility = "hidden";
	}
}

function showLocations(strType, strServerName, strServletAction, oloServer) {
    
    var strStoreId = "";
    var strStoreValues = "";
    var arrStoreValues;
    var streetCookie = "";
    var cityCookie = "";
    var stateCookie = "";
    var zipCookie = "";
    var strOLOUser = "";
    var strDCEUser = "";
    var strOLORemember = "";
    var landingPageIdx = -1;
    var landingPage = "";

    document.getElementById("servlet-action").name = strServletAction;
    document.getElementById('page-mode').value = getPageMode(strType);
    
    // Re-initialize these values as they may have been set by an earlier
    // opening and closing of the location popup.
    document.getElementById('landingpage').value = "";
    document.getElementById('log-in').onclick = function onclick(event) {
    	document.getElementById('log-in').href = oloServer + "/olo/faces/login/login.jsp";
    };

    if (document.getElementById('order-popup-footer')) {
    	document.getElementById('order-popup-footer').style.display = "none";
    }
    if (document.getElementById('non-order-popup-footer')) {
    	document.getElementById('non-order-popup-footer').style.display = "block";
    }
    
    if (strType != null && strType.toUpperCase() == "FIND") {
        
        document.getElementById('location-header').innerHTML = strShowLoc_FindDoms;
        document.getElementById('location-content').innerHTML = strShowLoc_FindStore;
        document.getElementById('location-content-campus').innerHTML = strShowLoc_FindStore;
        			
		populatePopUpFields(strServerName);            
        showPopup('location-popup');
        focusPopup();
        
    } else if (strType != null && (strType.toUpperCase() == "COUPON" || strType.toUpperCase() == "MENU")) {
        
        if (strType.toUpperCase() == "COUPON") {
            document.getElementById('location-header').innerHTML = strShowLoc_Coupons;
            document.getElementById('location-content').innerHTML = strShowLoc_CoupDesc;
            document.getElementById('location-content-campus').innerHTML = strShowLoc_CoupDesc;
        } else {
            document.getElementById('location-header').innerHTML = strShowLoc_Menu;
            document.getElementById('location-content').innerHTML = StrShowLoc_MenuDesc;
            document.getElementById('location-content-campus').innerHTML = StrShowLoc_MenuDesc;
		}

        strStoreId = getCookie("DomFindStoreId");

        if (strStoreId && strStoreId != "" && strStoreId != "0") {
        
        	checkFormValues();
        
            document.getElementById('new-location-form').submit();
        
        } else {
        
			populatePopUpFields(strServerName);            
            showPopup('location-popup');
            focusPopup();
        }
    
    } else if (strType != null && strType.toUpperCase().indexOf("ORDER") == 0) {
    	landingPageIdx = strType.indexOf(":");
    	if (landingPageIdx >= 0 && landingPageIdx + 1 < strType.length) {
    		landingPage = strType.substring(landingPageIdx + 1);
    		document.getElementById("landingpage").value = encodeURIComponent(landingPage);
    	    document.getElementById('log-in').onclick = function onclick(event) {
    	    	document.getElementById('log-in').href = oloServer + "/olo/faces/servlet/init_servlet?target=login&lp=" + encodeURIComponent(landingPage);
    	    }
    	}
    	
        document.getElementById('location-header').innerHTML = strShowLoc_Order;
        document.getElementById('location-content').innerHTML = strShowLoc_OrderDesc;
        document.getElementById('location-content-campus').innerHTML = strShowLoc_OrderDesc;

		strOLOUser     = getCookie("oloUserName");
		strDCEUser     = getCookie("dceUserName");
		strOLORemember = getCookie("oloRememberMe");
		
		strStoreId = getCookie("DomFindStoreId");
				
        populatePopUpFields(strServerName);            
		
        if (strOLOUser || strDCEUser || strOLORemember || (strStoreId && strStoreId != "" && strStoreId != "0")) {
			
			checkFormValues();
			
			document.getElementById('new-location-form').submit();
			
		} else {

            if (document.getElementById('order-popup-footer')) {
                document.getElementById('order-popup-footer').style.display = "block";
            }
            if (document.getElementById('non-order-popup-footer')) {
                document.getElementById('non-order-popup-footer').style.display = "none";
            }
            showPopup('location-popup');
            focusPopup();
		}        
    }
    
}
    
function populatePopUpFields(strServerName, strStreetAddress, strCityStateZip, strFormNum) {
    
    var addressTypeCookie = getCookie("DomFindStoreCMAddrType");
    var streetCookie;
    var unitNumberCookie;
    var cityCookie; 
    var stateCookie; 
    var zipCookie;

    var unitCookie;
    var unitValueCookie; 
    var stateValueCookie; 
    var bldgCookie; 
    var bldgValueCookie;

    if (strFormNum == null || typeof(strFormNum) == undefined) {
        strFormNum = "";
    }

    if (strStreetAddress == null || typeof(strStreetAddress) == undefined) {
        strStreetAddress = "";
    }
    if (strCityStateZip == null || typeof(strCityStateZip) == undefined) {
        strCityStateZip = "";
    }

	if (!addressTypeCookie || addressTypeCookie.length == 0 || addressTypeCookie == 'undefined' || addressTypeCookie == 'null') {
        addressTypeCookie = "";
    }

    if (addressTypeCookie == "Campus") {
        unitCookie = getCookie("DomFindStoreCMUnit");
        if (!unitCookie || unitCookie.length == 0 || unitCookie == 'undefined' || unitCookie == 'null') {
            unitCookie = "";
        }
        unitValueCookie = getCookie("DomFindStoreCMUnitValue");  
        if (!unitValueCookie || unitValueCookie.length == 0 || unitValueCookie == 'undefined' || unitValueCookie == 'null') {
            unitValueCookie = "";
        }
        stateCookie = getCookie("DomFindStoreCMState");   
        if (!stateCookie || stateCookie.length == 0 || stateCookie == 'undefined' || stateCookie == 'null') {
            stateCookie = "";
        }
        stateValueCookie = getCookie("DomFindStoreCMStateValue"); 
        if (!stateValueCookie || stateValueCookie.length == 0 || stateValueCookie == 'undefined' || stateValueCookie == 'null') {
            stateValueCookie = "";
        }
        bldgCookie = getCookie("DomFindStoreCMBldg");   
        if (!bldgCookie || bldgCookie.length == 0 || bldgCookie == 'undefined' || bldgCookie == 'null') {
            bldgCookie = "";
        }
        bldgValueCookie = getCookie("DomFindStoreCMBldgValue"); 
        if (!bldgValueCookie || bldgValueCookie.length == 0 || bldgValueCookie == 'undefined' || bldgValueCookie == 'null') {
            bldgValueCookie = "";
        }

		toggleDiv('std_addr_tab', false, strFormNum);
        clearStandardAddressFields(strFormNum);
        toggleDiv('campus_tab', true, strFormNum);
        prepopulateDropdowns(strServerName, 'Campus', stateValueCookie, stateCookie, unitValueCookie, unitCookie,
                              bldgValueCookie, bldgCookie, strFormNum);

        if (strFormNum != "") {
            focusPopup(strFormNum);
        }

    } else {
        
        toggleDiv('campus_tab', false, strFormNum);
        clearEnhancedAddressFields('Campus', strFormNum);
		toggleDiv('std_addr_tab', true, strFormNum);

        if (strCityStateZip != "") {
            if (document.getElementById('street-address' + strFormNum) != null) {
                if (strStreetAddress && strStreetAddress.length > 0 
                    && strStreetAddress != 'undefined' && strStreetAddress != 'null') {
                    document.getElementById('street-address' + strFormNum).value = strStreetAddress;
                } else {
                    document.getElementById('street-address' + strFormNum).value = "";
                }
            }
    
            if (document.getElementById('city-state-zip' + strFormNum) != null) {
                document.getElementById('city-state-zip' + strFormNum).value = strCityStateZip;
            }
        } else {

            streetCookie = getCookie("DomFindStoreAddr");
            unitNumberCookie = getCookie("DomFindStoreUnit");
            cityCookie = getCookie("DomFindStoreCity");  
            stateCookie = getCookie("DomFindStoreState"); 
            zipCookie = getCookie("DomFindStoreZip"); 
    
            if (streetCookie && streetCookie.length > 0 && streetCookie != 'undefined' && streetCookie != 'null') {
                document.getElementById('street-address' + strFormNum).value = streetCookie;
            } else {
                document.getElementById('street-address' + strFormNum).value = "";
            }

            if (unitNumberCookie && unitNumberCookie.length > 0 && unitNumberCookie != 'undefined' && unitNumberCookie != 'null') {
                document.getElementById('street-address' + strFormNum).value =
                	document.getElementById('street-address' + strFormNum).value + ' ' + unitNumberCookie;
            }

            if ((cityCookie && cityCookie.length > 0) 
                   || (stateCookie && stateCookie.length > 0) 
                   || (zipCookie && zipCookie.length > 0)) {	
    
                var cityStateZip = "";
    
                if (cityCookie != 'undefined' && cityCookie) {
                    cityStateZip = cityCookie;
                }
    
                if (stateCookie != 'undefined' && stateCookie) {
                    if (cityStateZip != "") {
                        cityStateZip += ", ";
                    }        	
                    cityStateZip = (cityStateZip + " " + stateCookie).trim();
                }
    
                if (zipCookie != 'undefined' && zipCookie) {
                    cityStateZip = (cityStateZip + " " + zipCookie).trim();
                }
    
                document.getElementById('city-state-zip' + strFormNum).value = cityStateZip;
    
            } else {
                document.getElementById('city-state-zip' + strFormNum).value = "";
            }

        }
        if (strFormNum != "") {
            focusPopup(strFormNum);
        }
    } 
    
}


/***************************************************************************
 * submitAddressForm()                                                     *
 *                                                                         *
 * input: strFormName - the name of the form                               *
 *        strFormNum - the form number, defaults to blank                  *
 *                                                                         *
 * output: none                                                            *
 *                                                                         *
 * description: calls validation code, clears or sets campus info, submits *
 *                                                                         *
 ***************************************************************************/
function submitAddressForm(strFormName, strFormNum) {
    var objAddressType;
    var strValidation = "";
    
    if (strFormNum == null || typeof(strFormNum) == undefined) {
        strFormNum = "";
    }

    objAddressType = document.getElementById('addresstype' + strFormNum);

    strValidation = validateAddressForm(strFormNum);
    if (strValidation != "") {
        alert(strValidation);
        return;
    }

    if (objAddressType != null && objAddressType.value == "") {
        checkFormValues();
	}  

    document.getElementById(strFormName).submit();

    //Clear objects
    objAddressType = null;
			
    return;
} //submitAddressForm()
    
    
function trimQuotes(str) { 
	return str.replace(/^\"*|\"*$/g,""); 
}

function trim(str) { 
	return str.replace(/^\\s*|\\s*$/g,""); 
}
   
function focusPopup(strFormNum) {
    var objField;
    var campus_div;
    var strAddrType = "";

    if (strFormNum == null || typeof(strFormNum) == undefined) {
        strFormNum = "";
    }
    campus_div = document.getElementById('campus_tab' + strFormNum);

    if (campus_div && campus_div.style.display != "none") {
        objField = document.getElementById('cp_state' + strFormNum);
    } else {
        objField = document.getElementById('street-address' + strFormNum);
    }

    if (objField) {
        if (objField.select) {
            objField.select();
        }    		
        if (objField.focus) {
            objField.focus();
        }
    }

}

function showOrderFromStore(strPhoneNumber) {
    showPopup('order-from-this-store');

    if (strPhoneNumber != null && strPhoneNumber.length > 0) {
        document.getElementById('phone-number').innerHTML = strPhoneNumber;
    }
}


function showStoreClosed(blnTakeFutureOrder) {
    showPopup('store-closed');

    if (blnTakeFutureOrder) {
        document.getElementById('store-closed-future').style.visibility = "visible";
    } else {
        document.getElementById('store-closed-future').style.visibility = "hidden";
    }
}

function getCookie(name) 
{
    var strValue = null;
    var arrCookies;
    var arrCookie = "";
    
    if (document.cookie) {
    	arrCookies = document.cookie.split("; ");
    	
    	for (var i = 0; i < arrCookies.length; i++) {

            if (arrCookies[i]) {
                arrCookie = arrCookies[i].split("=")
                if (arrCookie != null && arrCookie[0] == name) {
                    strValue = trimQuotes(unescape(arrCookie[1]));
                }
            }

        }
    }

    if (strValue == null || strValue == 'undefined') {
        strValue = null;
    }

    return strValue;
}
  
function checkFormValues(strFormNum)
{
    if (strFormNum == null || typeof(strFormNum) == undefined) {
        strFormNum = "";
    }
    if (document.getElementById('street-address' + strFormNum).value == strBlank_StreetAddress) {
    	document.getElementById('street-address' + strFormNum).value = "";
    }
    
    if (document.getElementById('city-state-zip' + strFormNum).value == strBlank_CityStateZip) {
    	document.getElementById('city-state-zip' + strFormNum).value = "";
    }

	return true;
}
   
function defaultFormValues(strFormNum)
{
    if (strFormNum == null || typeof(strFormNum) == undefined) {
        strFormNum = "";
    }
    if (document.getElementById('street-address' + strFormNum).value == "") {
    	document.getElementById('street-address' + strFormNum).value = "";
    }
    
    if (document.getElementById('city-state-zip' + strFormNum).value == "") {
    	document.getElementById('city-state-zip' + strFormNum).value = "";
    }

	return true;
}
 
function submitenter(myfield, e, fnc) {
	var keycode;
	
	if (window.event) {
		keycode = window.event.keyCode;
	} else if (e) {
		keycode = e.which;
	}
	
	if (keycode == 13) {
		fnc();
		return true;
	
	} else {
	   return false;
	}		
}

function submitSorry() {
	submitAddressForm('sorry-submit-form', '2');
}

function submitFindStore() {
	submitAddressForm('findstore-index', '2');
}

function validateAddressForm(strFormNum) {
    var msg = "";
    var city;
    var state;
	var campus;
    var building;
    var addressType;
    var std_div;
    var campus_div;
    var strReturn = "";
    
    if (strFormNum == null || typeof(strFormNum) == undefined) {
        strFormNum = "";
    }

    addressType = document.getElementById('addresstype' + strFormNum);
    std_div = document.getElementById('std_addr_tab' + strFormNum);
    campus_div = document.getElementById('campus_tab' + strFormNum);

    city = document.getElementById('city-state-zip' + strFormNum).value;

    state = document.getElementById('cp_state' + strFormNum);
    campus = document.getElementById('cp_campus' + strFormNum);
    building = document.getElementById('cp_bldg' + strFormNum);

    if (std_div && std_div.style.display != "none") {

	    msg = strNoAddressInfo;
	
	    if (city != null) { 
            city = city.trim();
            if (city == strBlank_CityStateZip) {
                city = "";
            }
	    } else {
	        city = "";
		}
		
	    if ( city.length == 0 ) {
	            strReturn = msg;
	    }    	
	} else if (campus_div && campus_div.style.display != "none") {
		msg = strNoCampusInfo;
	    
	    if (state != null && campus != null && building) {
	    	
	    	if (state.value == "" || campus.value == "" 
	    	|| building.value == "") {
	    		strReturn = msg;
	    	}	    	
	    }			
	}
    return strReturn;
}

	
function submitpopup() {
    submitAddressForm('new-location-form');
    return;
}

function getPageMode(strType) {

	var pageType = "";

	if (strType.toUpperCase() == "COUPON") {
		pageType = "C";
    }
    
    if (strType.toUpperCase() == "MENU") {
    	pageType = "M";
    }	
    
    if (strType.toUpperCase() == "ORDER") {
    	pageType = "O";
    }	
    
    return pageType;
}

function initFsScreen(blnError, strAddr, strCity) {
	var addr = null;
	var city = null;
	var state = null;
	var zip = null;
		
	if (blnError) {
		var addr = getCookie("DomFindStoreAddr");
		var city = getCookie("DomFindStoreCity");
		var state = getCookie("DomFindStoreState");
		var zip = getCookie("DomFindStoreZip");
	} else {
		var addr = stAddr;
		var city = cityStateZip;
		var state = null;
		var zip = null;
	}
    var csv = "";
    if (city) csv = city;
    if (state && city) csv = csv + ", " + state;
    if (state && !city) csv = state;
    if (zip) csv = csv + " " + zip;
            

	if (addr) document.getElementById('street-address2').value = addr.trim();
	
	if (csv) {
		document.getElementById('city-state-zip2').value = csv.trim();
	}
	
    if (document.getElementById('street-address2').focus) {
        document.getElementById('street-address2').focus(); 
    }
    if (document.getElementById('street-address2').select) {
    	document.getElementById('street-address2').select();
    }
		
	return true;
}

function isNumeric(strString) {
   	var strValidChars = "0123456789";
   	var strChar;
   	var blnResult = true;

   	if (strString.length == 0) return false;

   	for (i = 0; i < strString.length && blnResult == true; i++) {
    	strChar = strString.charAt(i);
    	if (strValidChars.indexOf(strChar) == -1) {blnResult = false;}
   	}

   	return blnResult;
}

function checkPhone() {
	var formValid = true;

  	var phone1 = document.getElementById('areacode').value;
  	var phone2 = document.getElementById('prefix').value;
  	var phone3 = document.getElementById('number').value;

  	if (formValid && (phone1.length < 3 || phone2.length < 3 || phone3.length < 4)) {
		alert(strPhoneNumberLength);
		formValid = false;
  	}

  	if (formValid && (!isNumeric(phone1) || !isNumeric(phone2) || !isNumeric(phone3))) {
    	alert(strCellNumberNumeric);
    	formValid = false;
  	}

  	if (formValid) {
    	document.getElementById('learn_mo').submit();
  	}

  	return formValid;
}

function setStoreIdCookie(strStoreId, strDomain) {


	if (strStoreId != null && strStoreId != 'undefined' &&
	      strStoreId != '0' && strStoreId != '9999') {
	      
	      var domFindStoreId = getCookie("DomFindStoreId");
	      
	      if (domFindStoreId == null || domFindStoreId == 'undefined' 
	           || domFindStoreId.length == 0) {

			  setCookie("DomFindStoreId", strStoreId, strDomain);	           
	      }
	}
}

function checkLanguage() {

	var strDomLanguage = getCookie("DomLanguage");
	var strMotionPoint = getCookie("MPLinkClicked");
	
	if (strDomLanguage != null 
		&& strDomLanguage.toUpperCase() == 'ES' && strMotionPoint == null) {
		
		var spanishLink = document.getElementById("mp-switch");
		
		if (spanishLink != null && spanishLink != 'undefined') {
		
			if(document.dispatchEvent) { // W3C
				
				var oEvent = document.createEvent("MouseEvents");
				
				oEvent.initMouseEvent("click", true, true, window, 1, 1, 1, 1, 1, false, false, false, false, 0, spanishLink);
				
				spanishLink.dispatchEvent(oEvent);
			
			} else if(document.fireEvent) { // IE
				
				spanishLink.fireEvent("onclick");
			} 		
		}
	}
}

function setCookie(strName, strValue, strDomain, strExpire) {

	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	if (strName != null && strName != 'undefined' &&
	    strValue != null && strValue != 'undefined' &&
	    strDomain != null && strDomain != 'undefined' &&
	    strExpire != null && strExpire != 'undefined') {
	    
    	var expires_date = new Date( today.getTime() + (strExpire * 1000 * 60 * 60 * 24));
    
    	var cookieValue = strName + "=" + escape(strValue);
    	
    	if (strExpire != -1 && strExpire != 0) {
        	cookieValue += ";expires=" + expires_date;
        }
        
        if (strExpire == 0) {
            cookieValue += ";expires=0";
        }
        
        cookieValue += ";path=/;domain=" + strDomain;
        
        document.cookie = cookieValue;
	}
}

function setLanguageCookie(strLanguage, strDomain) {

	if ((strLanguage != null && strLanguage != 'undefined') &&
	    (strDomain != null && strDomain != 'undefined')) {
	
		if (strLanguage.toUpperCase() == 'ENGLISH') {
		
			setCookie("DomLanguage", "en", strDomain, 0);
			
		} else {
		
			setCookie("MPLinkClicked", "1", strDomain, -1);
			setCookie("DomLanguage", "es", strDomain, 365);
		}
	}
}

function openPopupWindow(strURL, strWindowName, strOptions) {
    window.open(strURL, strWindowName, strOptions); 
}


<!-- mp_trans_disable_end -->


