dojo.addOnLoad(function(){
  if(!dojo.isSafari) {
  dojo.query('div.dojodata').forEach(function(node) {
   var s = node.innerHTML.indexOf("{");
   var l = node.innerHTML.lastIndexOf("}");
   node.innerHTML = node.innerHTML.substr(s, l - s + 1);   
   });
    if(dojo.isIE <= 6){
       var ie6ad = document.getElementById('ie6Alert');   
    if(ie6ad) ie6ad.style.display = 'block';
    } 
  }
  else{
      var agent = navigator.userAgent.toLowerCase();
    if(agent.indexOf("ipad") != -1 || agent.indexOf("iphone") != -1) {
                var qvcss = document.createElement('style');
                    qvcss.type = 'text/css';
                var qvstyles = 'div.bigQuickViewButton {display: none !important;}';
                qvcss.appendChild(document.createTextNode(qvstyles));

                document.getElementsByTagName("head")[0].appendChild(qvcss);

                //nav seems to work fine on iPad without dedicated css
                //dojo.body().innerHTML += '<link rel="stylesheet" type="text/css" href="/static/css/navigator_bar_ipad.css"/>';
    }
  } 
});

dojo.require("dojo.cookie");

//dojo parser
//dojo.require("dojo.parser");

//global page layout
//dojo.require("dijit.layout.ContentPane");
//dojo.require("dijit.layout.BorderContainer");

//custom widgets and classes
//dojo.require("core.framework.event_manager.event_manager");

//global pointers to custom widgets
var pointerFarm = new Array();

var accountPtr = null;
var breadcrumbPtr = null;
var loginPtr = null;
var miniCartPtr = null;
var navigationPtr = null;
var subNavigationPtr = null;
var exclusiveCarouselPtr = null;
var alsoViewedPtr = null;

var eventManager = null;

//pointer to event logger
var eventLoggerPtr = null;

//constants
var CART_QUICKVIEW = 0;
var CART_PRODPAGE = 1;
var CART_MULTI = 2;
var CART_QUICKERVIEW = 3;

//fix for quick-scroll in cartridges
var scrollLock = false;

//document.domain = "disneystore.com"; //uncomment for release

//renders "grey out" for popups, updated with 2011 modals
function modalBackground(visable, options){
		var options = options || {}; 
  		var zindex = options.zindex || 50;
  		var opacity = options.opacity || 70;
  		var opaque = (opacity / 100);
 		var bgcolor = options.bgcolor || '#000000';
  		var grayScreen=document.getElementById('objModalBG');
		var click = options.click || "";
 		if (!grayScreen) {
   			 // The modal background has not been created so create it here
    			var tbody = document.getElementsByTagName("body")[0];
    			var tnode = document.createElement('div');           // Create the layer.
       			tnode.style.position='absolute';                 // Position 
        		tnode.style.top='0px';                           // In the top
        		tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        		tnode.style.display='none';                      // Start out Hidden
				tnode.style.left = '0';						
        		tnode.id='objModalBG';                   		// Name it so we can find it later
    			tbody.appendChild(tnode);                            // Add it to the web page
    			grayScreen=document.getElementById('objModalBG');  // Get the object.
  		}
  		if (visable) {
    		// Calculate the page width and height 
    		if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
							
       		var pageWidth = document.body.scrollWidth+'px';
        	var pageHeight = document.body.scrollHeight+'px';
			//alert(pageWidth + " " + pageHeight);
    		} else if( document.body.offsetWidth ) {
      			var pageWidth = document.body.offsetWidth+'px';
      			var pageHeight = document.body.offsetHeight+'px';
    		} else {
       			var pageWidth='100%';
       			var pageHeight='100%';
				
    		} 
			if(dojo.isSafari){
				var agent = navigator.userAgent.toLowerCase();
				if ((!dojo.isMac)&&(!(agent.indexOf("ipad") != -1 || agent.indexOf("iphone") != -1))){
					var pageWidth='100%';
	       			var pageHeight='100%';
					document.getElementById("objModalBG").style.position = "fixed";
				}
			}  
			
    		//set the modal background to cover the entire page and make it visible.
   			grayScreen.style.opacity=opaque;                      
    		grayScreen.style.MozOpacity=opaque;                   
    		grayScreen.style.filter='alpha(opacity='+opacity+')'; 
    		grayScreen.style.zIndex=zindex;        
    		grayScreen.style.backgroundColor=bgcolor;  
    		grayScreen.style.width= pageWidth;
    		grayScreen.style.height= pageHeight;
    		grayScreen.style.display='block';                          
  		} else {
     		grayScreen.style.display='none';
  		}
		if ((click != undefined)&&(click!="")){
			grayScreen.onclick = function()
    {
       closeModal(click);
    }
		}
}

//Display the email reminder pop up window with the email text field and the login button visable
function displayReminder(element){
	var reminderLink = document.getElementById("emailPopUpWindow");
	var reminderForm = document.getElementById("storeLocatorReminderPopupWindow");
	var reminderConf = document.getElementById("reminderConfirmationPopUpWindow");
	var submitFormBttn = document.getElementById("storeLocatorOkButton");
	var emailSubmitBttn = document.getElementById("emailSubmitBtn");
	var emailAddress = document.getElementById("storeLocatorEmailAddress");
	reminderLink.style.display = "block";
	reminderForm.style.display = "block";
	reminderConf.style.display = "none";
	submitFormBttn.disabled = true;
}

//Closes the email reminder pop up window
function hideReminder(){
	var reminderLink = document.getElementById("emailPopUpWindow");
	reminderLink.style.display = "none";
}

//Display the email confirmation pop up window with a change link and OK button
function displayConfirmation(){
	var submitFormBttn = document.getElementById("storeLocatorOkButton");
	var emailAddress = document.getElementById("storeLocatorEmailAddress");
	var reminderForm = document.getElementById("storeLocatorReminderPopupWindow");
	var reminderConf = document.getElementById("reminderConfirmationPopUpWindow");
	var confirmEmail = document.getElementById("storeLocatorConfirmEmailAddress");
	reminderForm.style.display = "none";
	reminderConf.style.display = "block";
	//Set the email address the user entered
	confirmEmail.innerHTML = emailAddress.value;
	submitFormBttn.disabled = false;
	submitFormBttn.focus(); 
}
function getCookieAttribute(cookieName, cookieAttributeName){
	value = dojo.cookie(cookieName);
	if(value == null){
		return "";
	}
	cookieAttributes = dojo.cookie(cookieName).split(",,,");
	for(i = 0; i < cookieAttributes.length; i++){
		if(cookieAttributes[i].split("~")[0] == cookieAttributeName){
			return cookieAttributes[i].split("~")[1];
		}
	}
	return "";
}

function setCookieAttribute(cookieName, cookieAttributeName, value){
	exists = false;
	cookieValue = "";
	attr = dojo.cookie(cookieName);
	if(attr != null){
		cookieAttributes = attr.split(",,,");
		
		for(i = 0; i < cookieAttributes.length; i++){
			if(cookieAttributes[i].split("~")[0] == cookieAttributeName){
				cookieValue = cookieValue + cookieAttributeName + "~" + value;
				exists = true;
			}
			else{
				cookieValue = cookieValue + cookieAttributes[i];
			}
			if((i+1) < cookieAttributes.length){
				cookieValue = cookieValue + ",,,";
			}
		}
	}
	
	if(!exists){
		cookieValue = cookieValue + ",,," + cookieAttributeName + "~" + value;
	}
	
	// setCookie(cookieName, cookieValue, false, '/', false, false);
	dojo.cookie(cookieName,cookieValue,{path : "/"});	
}

function deleteCookieAttribute(cookieName,cookieAttributeName){
	cookieValue = "";
	attr = dojo.cookie(cookieName);
	if(attr != null){
		cookieAttributes = attr.split(",,,");
		
		for(i = 0; i < cookieAttributes.length; i++){
			if(cookieAttributes[i].split("~")[0] != cookieAttributeName){
				cookieValue = cookieValue + cookieAttributes[i];
			}if((i+1) < cookieAttributes.length){
				cookieValue = cookieValue + ",,,";
			}
		}
	}
	
	// setCookie(cookieName, cookieValue, false, '/', false, false);
	dojo.cookie(cookieName,cookieValue,{path : "/"});
	
}

function prepare_entered_keyword_header(searchform,kwrequired)
{
	var requiredTrans = {
		'en-us':'Please enter a keyword or item number.',
		'en-gb':'Please enter a keyword or item number.',
		'fr-fr':'Veuillez saisir vos mots clés.',
		'de-de':'Bitte gib einen Suchbegriff ein oder eine Artikelnummer.'
	};
	var searchEmptyError = requiredTrans[dojo.locale];


	searchform = document.Search;
	prepare_entered_keyword(searchform,kwrequired)

	if (searchform.Searchstr.value == "" ||
		searchform.Searchstr.value == "Search DisneyStore.com") {
		alert (searchEmptyError);
		return false;
	}

	searchform.Ntt.value = searchform.Searchstr.value;
	searchform.D.value = searchform.Searchstr.value;
	searchform.Dr.value = searchform.Nr.value;
	return true;
}

function prepare_entered_keyword(searchform,kwrequired) {
	var kw = new String(searchform.Searchstr.value);

	kw = kw.replace(/(\s+)/g," "); // consolidate white space
	kw = kw.replace(/^ /,""); // remove leading white space
	kw = kw.replace(/ $/,""); // remove trailing white space
	kw = kw.replace(/"/g,""); // remove double quotes "
	if (dojo.locale != 'fr-fr') {
		kw = kw.replace(/'/g,""); // remove single quotes
	}
	kw = kw.replace(/^#/,""); // remove leading number sign (for item numbers)

	if (kw.length > 0) searchform.Searchstr.value = kw;
	return true;
}

function clearIfDefault(obj) {
	var parentForm = obj.form;
	var y = 0;
	while(parentForm.elements[y] != obj) { y++; }
	var defValue = parentForm.elements[y+1].value;
	if (obj.value == defValue) obj.value = "";
}
function setIfBlank(obj) {
	var parentForm = obj.form;
	var z = 0;
	while(parentForm.elements[z] != obj) { z++; }
	var defValue = parentForm.elements[z+1].value;
	if (obj.value == "") obj.value = defValue;
}
function validateSearchForm(theForm) {
	for (var w=0; w < theForm.elements.length; w++) {
		if (theForm.elements[w].type == "text" && theForm.elements[w+1].type == "hidden") clearIfDefault(theForm.elements[w]);
	}
	return true;
}

/**
 * SWFObject v1.4.4: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 * temporarily removed: we no longer rely on the flash configurator so it's not necessary to load this globally
 */

/* legacy cyo support */
function toggleContainer() {
	dojo.byId('flashConfig').style.display = 'none';
}

//Modal functions, no longer dijit.dialog, now self-contained for 2011

function escapeModal(divID, activate){
	if (activate == true){
	document.onkeydown = function(evt){
		evt = evt || window.event;
		if (evt.keyCode == 27) closeModal(divID);
	}
}
	else document.onkeydown = "";
}

function closeModal(divID){
	if (document.getElementById(divID).className == "modalExt")
		dojo.query("#" + divID).orphan();
	else 
		dojo.query("#" + divID).style({ visibility:"hidden" });
	modalBackground(false);
	escapeModal(divID, false);
}

function dojoModalAjax(url, divid, title){
	dojoModalAjax(url, divid, title, null);
}

function dojoModalAjax(url, divid, title, callback) {
	dojo.xhrGet({
	    url: url,
	    handleAs:"text",
	    load: function(data){	        							
			if (document.getElementById(divid)!=undefined) {
				dojo.query("#" + divid).orphan();
			}
			dojo.create("div", {id: divid, className: "modalExt", innerHTML: data}, dojo.body());
	        dojoModalInt(divid, title);	  
	        if(callback != null){
	        	callback();
	        }
	    }
	});
}

function dojoModalExt(divID, boxTitle, targetLink, iframeWidth, iframeHeight){
	if ((boxTitle == "undefined")||(boxTitle == undefined)) boxTitle = "";
	var itpl = "<div class='modalHeader'><div class='modalTitle'>" + boxTitle + "</div><div class='modalClose' onClick = 'closeModal(\"" + divID+ "\");'></div></div>";
	itpl += "<iframe id='modalExt' class='modalIframe' frameborder='0' style='width: " + iframeWidth + "px; height: " + iframeHeight + "px; border: 1px solid lightgrey;' ></iframe>";
	var modalWidth = parseInt(iframeWidth)+20;	
	var x = 0, y = 0; // default values
	var top = 0;
	if (window.pageYOffset>0) top = window.pageYOffset;
	else if (document.documentElement.scrollTop>0) top = document.documentElement.scrollTop;
	else top = 0;
	
		if((top + parseInt(iframeHeight) + 70) >= document.documentElement.scrollHeight){
			x = (document.documentElement.scrollHeight - iframeHeight - 70);
		}
		else x = (top)+ 20;
		if (window.innerWidth != undefined)	y = (window.innerWidth - iframeWidth) / 2;
		else y = (document.documentElement.clientWidth - iframeWidth) / 2;

	dojo.create("div", {id: divID, className: "modalExt", innerHTML: itpl, style: {
     width: modalWidth + "px",
	 top: x + "px",
     left: y + "px"
 }}, dojo.body());	
	dojo.attr('modalExt', 'src',targetLink);
	modalBackground(true, {bgcolor: "#666", opacity: "50", zindex: "998", click: divID});	
	escapeModal(divID, true);				
}

function dojoModalInt(divID, boxTitle){
	if ((boxTitle == "undefined")||(boxTitle == undefined)) boxTitle = "";
	if (!(document.getElementById(divID).className == "modalInt")){
		dojo.query("#" + divID).addClass("modalInt");
		var txt = "<div class='modalHeader'><div class='modalTitle'>" + boxTitle + "</div><div class='modalClose' onClick = 'closeModal(\"" + divID+ "\");'></div></div>";
		dojo.query("#" + divID).addContent(txt, "first");
	}
	var modalWidth = dojo.query("#" + divID).style("width");
	var x = 0, y = 0; // default values
	var top = 0;
	if (window.pageYOffset>0) top = window.pageYOffset;
	else if (document.documentElement.scrollTop>0) top = document.documentElement.scrollTop;
	else top = 0;
	
	 x = (top)+ 20;
		if (window.innerWidth != undefined)	y = (window.innerWidth - modalWidth) / 2;
		else y = (document.documentElement.clientWidth - modalWidth) / 2;	
	dojo.query("#" + divID).style({
     top: x + "px",
     left: y + "px",
	 display: "block",
	 visibility: "visible"
 });
 	dojo.body().appendChild(document.getElementById(divID));
	modalBackground(true, {bgcolor: "#666", opacity: "50", zindex: "998", click: divID});	
	escapeModal(divID, true);		
}

function doGenericDialog(content){
	content = "<div class='genericModalContent'>"+content+"</div>";
	var divID = "genericDialogDiv";
		if (document.getElementById(divID)!=undefined) {
			dojo.query("#" + divID).orphan();
				}
		dojo.create("div", {id: divID, innerHTML: content, style: {width: "400px"}}, dojo.body());
		dojoModalInt(divID);
}

/* from dojox/atom/io/model.js */
function unEscapeHtml(str) {
	str = str.replace(/&amp;/gm,"&").replace(/&lt;/gm,"<").replace(/&gt;/gm,">").replace(/&quot;/gm,"\"");
	str = str.replace(/&#39;/gm,"'");
	return str;
}

function launchCYO(url){
	var hexcase=0;function hex_md5(a){return rstr2hex(rstr_md5(str2rstr_utf8(a)))}function hex_hmac_md5(a,b){return rstr2hex(rstr_hmac_md5(str2rstr_utf8(a),str2rstr_utf8(b)))}function md5_vm_test(){return hex_md5("abc").toLowerCase()=="900150983cd24fb0d6963f7d28e17f72"}function rstr_md5(a){return binl2rstr(binl_md5(rstr2binl(a),a.length*8))}function rstr_hmac_md5(c,f){var e=rstr2binl(c);if(e.length>16){e=binl_md5(e,c.length*8)}var a=Array(16),d=Array(16);for(var b=0;b<16;b++){a[b]=e[b]^909522486;d[b]=e[b]^1549556828}var g=binl_md5(a.concat(rstr2binl(f)),512+f.length*8);return binl2rstr(binl_md5(d.concat(g),512+128))}function rstr2hex(c){try{hexcase}catch(g){hexcase=0}var f=hexcase?"0123456789ABCDEF":"0123456789abcdef";var b="";var a;for(var d=0;d<c.length;d++){a=c.charCodeAt(d);b+=f.charAt((a>>>4)&15)+f.charAt(a&15)}return b}function str2rstr_utf8(c){var b="";var d=-1;var a,e;while(++d<c.length){a=c.charCodeAt(d);e=d+1<c.length?c.charCodeAt(d+1):0;if(55296<=a&&a<=56319&&56320<=e&&e<=57343){a=65536+((a&1023)<<10)+(e&1023);d++}if(a<=127){b+=String.fromCharCode(a)}else{if(a<=2047){b+=String.fromCharCode(192|((a>>>6)&31),128|(a&63))}else{if(a<=65535){b+=String.fromCharCode(224|((a>>>12)&15),128|((a>>>6)&63),128|(a&63))}else{if(a<=2097151){b+=String.fromCharCode(240|((a>>>18)&7),128|((a>>>12)&63),128|((a>>>6)&63),128|(a&63))}}}}}return b}function rstr2binl(b){var a=Array(b.length>>2);for(var c=0;c<a.length;c++){a[c]=0}for(var c=0;c<b.length*8;c+=8){a[c>>5]|=(b.charCodeAt(c/8)&255)<<(c%32)}return a}function binl2rstr(b){var a="";for(var c=0;c<b.length*32;c+=8){a+=String.fromCharCode((b[c>>5]>>>(c%32))&255)}return a}function binl_md5(p,k){p[k>>5]|=128<<((k)%32);p[(((k+64)>>>9)<<4)+14]=k;var o=1732584193;var n=-271733879;var m=-1732584194;var l=271733878;
	for(var g=0;g<p.length;g+=16){var j=o;var h=n;var f=m;var e=l;o=md5_ff(o,n,m,l,p[g+0],7,-680876936);l=md5_ff(l,o,n,m,p[g+1],12,-389564586);m=md5_ff(m,l,o,n,p[g+2],17,606105819);n=md5_ff(n,m,l,o,p[g+3],22,-1044525330);o=md5_ff(o,n,m,l,p[g+4],7,-176418897);l=md5_ff(l,o,n,m,p[g+5],12,1200080426);m=md5_ff(m,l,o,n,p[g+6],17,-1473231341);n=md5_ff(n,m,l,o,p[g+7],22,-45705983);o=md5_ff(o,n,m,l,p[g+8],7,1770035416);l=md5_ff(l,o,n,m,p[g+9],12,-1958414417);m=md5_ff(m,l,o,n,p[g+10],17,-42063);n=md5_ff(n,m,l,o,p[g+11],22,-1990404162);o=md5_ff(o,n,m,l,p[g+12],7,1804603682);l=md5_ff(l,o,n,m,p[g+13],12,-40341101);m=md5_ff(m,l,o,n,p[g+14],17,-1502002290);n=md5_ff(n,m,l,o,p[g+15],22,1236535329);o=md5_gg(o,n,m,l,p[g+1],5,-165796510);l=md5_gg(l,o,n,m,p[g+6],9,-1069501632);m=md5_gg(m,l,o,n,p[g+11],14,643717713);n=md5_gg(n,m,l,o,p[g+0],20,-373897302);o=md5_gg(o,n,m,l,p[g+5],5,-701558691);l=md5_gg(l,o,n,m,p[g+10],9,38016083);m=md5_gg(m,l,o,n,p[g+15],14,-660478335);n=md5_gg(n,m,l,o,p[g+4],20,-405537848);o=md5_gg(o,n,m,l,p[g+9],5,568446438);l=md5_gg(l,o,n,m,p[g+14],9,-1019803690);m=md5_gg(m,l,o,n,p[g+3],14,-187363961);n=md5_gg(n,m,l,o,p[g+8],20,1163531501);o=md5_gg(o,n,m,l,p[g+13],5,-1444681467);l=md5_gg(l,o,n,m,p[g+2],9,-51403784);m=md5_gg(m,l,o,n,p[g+7],14,1735328473);n=md5_gg(n,m,l,o,p[g+12],20,-1926607734);o=md5_hh(o,n,m,l,p[g+5],4,-378558);l=md5_hh(l,o,n,m,p[g+8],11,-2022574463);m=md5_hh(m,l,o,n,p[g+11],16,1839030562);n=md5_hh(n,m,l,o,p[g+14],23,-35309556);o=md5_hh(o,n,m,l,p[g+1],4,-1530992060);l=md5_hh(l,o,n,m,p[g+4],11,1272893353);m=md5_hh(m,l,o,n,p[g+7],16,-155497632);n=md5_hh(n,m,l,o,p[g+10],23,-1094730640);o=md5_hh(o,n,m,l,p[g+13],4,681279174);l=md5_hh(l,o,n,m,p[g+0],11,-358537222);m=md5_hh(m,l,o,n,p[g+3],16,-722521979);
	n=md5_hh(n,m,l,o,p[g+6],23,76029189);o=md5_hh(o,n,m,l,p[g+9],4,-640364487);l=md5_hh(l,o,n,m,p[g+12],11,-421815835);m=md5_hh(m,l,o,n,p[g+15],16,530742520);n=md5_hh(n,m,l,o,p[g+2],23,-995338651);o=md5_ii(o,n,m,l,p[g+0],6,-198630844);l=md5_ii(l,o,n,m,p[g+7],10,1126891415);m=md5_ii(m,l,o,n,p[g+14],15,-1416354905);
	n=md5_ii(n,m,l,o,p[g+5],21,-57434055);o=md5_ii(o,n,m,l,p[g+12],6,1700485571);l=md5_ii(l,o,n,m,p[g+3],10,-1894986606);m=md5_ii(m,l,o,n,p[g+10],15,-1051523);n=md5_ii(n,m,l,o,p[g+1],21,-2054922799);o=md5_ii(o,n,m,l,p[g+8],6,1873313359);l=md5_ii(l,o,n,m,p[g+15],10,-30611744);m=md5_ii(m,l,o,n,p[g+6],15,-1560198380);n=md5_ii(n,m,l,o,p[g+13],21,1309151649);o=md5_ii(o,n,m,l,p[g+4],6,-145523070);l=md5_ii(l,o,n,m,p[g+11],10,-1120210379);m=md5_ii(m,l,o,n,p[g+2],15,718787259);n=md5_ii(n,m,l,o,p[g+9],21,-343485551);o=safe_add(o,j);n=safe_add(n,h);m=safe_add(m,f);l=safe_add(l,e)}return Array(o,n,m,l)}function md5_cmn(h,e,d,c,g,f){return safe_add(bit_rol(safe_add(safe_add(e,h),safe_add(c,f)),g),d)}function md5_ff(g,f,k,j,e,i,h){return md5_cmn((f&k)|((~f)&j),g,f,e,i,h)}function md5_gg(g,f,k,j,e,i,h){return md5_cmn((f&j)|(k&(~j)),g,f,e,i,h)}function md5_hh(g,f,k,j,e,i,h){return md5_cmn(f^k^j,g,f,e,i,h)}function md5_ii(g,f,k,j,e,i,h){return md5_cmn(k^(f|(~j)),g,f,e,i,h)}function safe_add(a,d){var c=(a&65535)+(d&65535);var b=(a>>16)+(d>>16)+(c>>16);return(b<<16)|(c&65535)}function bit_rol(a,b){return(a<<b)|(a>>>(32-b))};	
	
	window.location = "/"+ storesWebPath + "DSIPageDisplayView?storeId=10051&catalogId=10002&langId=-1&N=36513+109&URL=" + encodeURIComponent(url) + "&basePageZone=DisneyZazzlePageZone&productId=" + hex_md5(url);
}

//Takes an SEO URL and replaces the category with the NValues
//ex: http://Host/junk/mp/123123/00/ --> http://Host/junk/mp/123123/11/
function replaceHrefCategoryWithNValue(linkHref, nValue){ 
	if(nValue == null || nValue == "" || nValue == "-1"){  
		return linkHref;                
	}       
	else if(linkHref.match(/^\/.*(\/mp\/[0-9]*\/)[0-9]*\//)){
		return linkHref.replace(/(\/mp\/[0-9]*\/)[0-9]*\//,"$1" + nValue + "/");
	}  
	else{ 
		return linkHref +"?N=" + nValue;
	}
}   

function getCrossSellNValue(productNValue, validNValues, defaultNValue){
	var nValue = "";
	var urlNValues = globalNValueRef.split('+');
	
	for(i = 0; i < urlNValues.length; i++){
		if(urlNValues[i] == productNValue){
			if(nValue != ""){
				nValue += "+";
			}
			nValue += defaultNValue;
		}else if(validNValues.indexOf("," + urlNValues[i] + ",") > -1){
			if(nValue != ""){
				nValue += "+";
			}
			nValue += urlNValues[i];
		}
	}
	
	if(nValue == ""){
		return defaultNValue;
	}else if(productNValue == ""){
		return defaultNValue + "+" + nValue;
	}	else{
		return nValue;
	}
}

//set a quasi-GUID cookie used by Quest Foglight to track unique sessions
function fx_S4() { return (((1+Math.random())*0x10000)|0).toString(16).substring(1); }
if (legacy_getCookie("DSIFXID") == null) {
	var fx_Now = new Date();
	var fx_Ts = (fx_Now.getHours()+100)+""+fx_Now.getMinutes()+""+fx_Now.getSeconds()+""+(fx_Now.getMilliseconds()+1000);
	var fx_Cookie = (fx_S4()+fx_S4()+"-"+fx_S4()+"-"+fx_S4()+"-"+fx_S4()+"-"+fx_S4()+fx_S4()+fx_S4()+"-"+fx_Ts).toUpperCase();
	var fx_Domain = "";
try {
	fx_Domain = document.location.host.replace(/^(.*)\.([^\.]+)\.fr$/,".$2"+".fr");
} catch (e) {
	fx_Domain = ".disneystore.fr";
};
	legacy_setCookie("DSIFXID",fx_Cookie,null,"/",fx_Domain,null);
}

function legacy_setCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
}

function legacy_getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) end = cookie.length;
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

function calcStars(rating){
	var strStars = "";
	if (rating < 1) strStars = "zero_star_rating";
	else if (rating <= 1.2) strStars = "one_star_rating";
	else if (rating <= 1.7) strStars = "one_five_star_rating";
	else if (rating <= 2.2) strStars = "two_star_rating";
	else if (rating <= 2.7) strStars = "two_five_star_rating";
	else if (rating <= 3.2) strStars = "three_star_rating";
	else if (rating <= 3.7) strStars = "three_five_star_rating";
	else if (rating <= 4.2) strStars = "four_star_rating";
	else if (rating <= 4.7) strStars = "four_five_star_rating";
	else if (rating <= 5) strStars = "five_star_rating";
	else strStars = "zero_star_rating";
	return strStars;
}

function validLogin(){
	var fieldTrans = {
		'en-us':'This field is required.',
		'en-gb':'This field is required.',
		'fr-fr':'Ce champ est obligatoire.',
		'de-de':'Dieses Feld ist erforderlich.'
	};
	var fieldRequired = fieldTrans[dojo.locale];


	valid=true; 
	loginError = document.getElementById('logonIdLabel'); 
	passError = document.getElementById('logonPasswordLabel');
    loginError.style.display = 'none'; 
	passError.style.display = 'none';
	if (document.getElementById('memberName').value == '') { 
		loginError.style.display = 'block'; 
		loginError.innerHTML = fieldRequired; 
		valid = false;
		}
	if (document.getElementById('loginPassword').value == '') {
		passError.style.display = 'block'; 
		passError.innerHTML = fieldRequired; 
		valid = false;
		}
	if(valid==true) document.logonForm.submit();
	}

//Highlights the appropriate tab in the primary / secondary navigator bar (temp disable per defect 9623)
/* dojo.addOnLoad(function(){
	var selectedIndex = "";
	if (dojo.byId("navHighlightInfo_tabIndex") != null) {
		selectedIndex = dojo.byId("navHighlightInfo_tabIndex").innerHTML;
	}
	var primary = false;
	if (dojo.byId("navHighlightInfo_primary") != null) {
		if (dojo.byId("navHighlightInfo_primary").innerHTML == 'true') {
			primary = true;
		}
	}
	var selectedFlyoutLabel = "";
	if (dojo.byId("navHighlightInfo_flyoutLabel") != null) {
		selectedFlyoutLabel = dojo.byId("navHighlightInfo_flyoutLabel").innerHTML;
	}
	var maxMainNavIndex = "";
	if (dojo.byId("maxMainNavIndex") != null) {
		maxMainNavIndex = dojo.byId("maxMainNavIndex").innerHTML;
	}
	
	if (primary) {
		var mainNavMenuItemOverElement = dojo.byId("mainNavMenuItemOver" + selectedIndex);
		if (mainNavMenuItemOverElement!=null) {
			if (selectedIndex == "0") {
				mainNavMenuItemOverElement.className = mainNavMenuItemOverElement.className + "mainNavHighlightedLeftFirst";
			} else if (selectedIndex == maxMainNavIndex) {
				mainNavMenuItemOverElement.className = mainNavMenuItemOverElement.className + "mainNavHighlightedRightLast";
			} else {
				mainNavMenuItemOverElement.className = mainNavMenuItemOverElement.className + "mainNavHighlighted";
			}
		}
	} else {
		var subNavMenuItemOverElement = dojo.byId("subNavMenuItemOver" + selectedIndex);
		if (subNavMenuItemOverElement != null) {
			subNavMenuItemOverElement.className = subNavMenuItemOverElement.className + " secondaryNavHighlighterLeftBg";
		}
	}
	
	// highlight the appropriate link in the primary/secondary flyout
	if (primary) {
		var flyoutElement = dojo.byId("item"+selectedIndex);
		if (flyoutElement!=null) {
			var liLists = dojo.query('li', flyoutElement)
			for (var i=0; i < liLists.length; i++) {
				var liElement = liLists[i];
				var aLists = dojo.query('a', liElement);
				if (aLists.length > 0) {
					var aElement = aLists[0];
					var flyoutLabel = aElement.innerHTML;
					if (flyoutLabel != null) {
						flyoutLabel = dojo.trim(flyoutLabel);	
						if (flyoutLabel == selectedFlyoutLabel) {
							// FOUND MATCH
							liElement.className = liElement.className + " mnselected";
						}
					}
				}
			}
		}
	} else {
		// TODO: put logics here to highligth secondary nav flyout
		// currently no new requirement for this yet
	}

});
*/

/**
 * Start content from error.js
 **/

// this method will return the URL parameter value given a parameter name
function getParamValue(paramName){
  //alert ("paramName="+paramName);
  var paramValue = "";
  var strURL = window.location.href;
  //alert ("strURL="+strURL);
  if ( strURL.indexOf("&") > -1 ){
    var initialQueryString = strURL.substr(strURL.indexOf("&"));
    var queryString = initialQueryString.split("&");
    for (var i=0; i<queryString.length; i++) {
      if (queryString[i].indexOf(paramName + "=") > -1) {
        var paramArray = queryString[i].split("=");
        paramValue = paramArray[1];
        break;
      }
    }
  }
  //alert ("paramValue="+paramValue);
  return paramValue;
}

// the following two methods are used to hide the mini-cart from view upon user actions
var doHideMiniCart = true;
function hideMiniCart() {
    	if (doHideMiniCart) {
		if (eval(document.getElementById("cartBox"))) {
			document.getElementById("cartBox").style.display="none";
		}
	}
	doHideMiniCart = true;
}
function setHideMiniCart(hideMiniCartBoolean) {
	doHideMiniCart = hideMiniCartBoolean;
}

// the following two methods are used to hide the store finder view upon user actions
var doHideStoreFinder = true;
function hideStoreFinder() {
    	if (doHideStoreFinder) {
		if (eval(document.getElementById("storeFinderBox"))) {
			document.getElementById("storeFinderBox").style.display="none";
		}
	}
	doHideStoreFinder = true;
}
function setHideStoreFinder(hideStoreFinderBoolean) {
	doHideStoreFinder = hideStoreFinderBoolean;
}


function isMonth(month, months){
	for (i = 0; i < months.length; i ++){
		//alert(month.toUpperCase()+" "+months[i].toUpperCase());
		if (month.toUpperCase().indexOf(months[i].toUpperCase()) > -1) return true;
	}
}

function isValidDate(value){
	isValidDateString = true;
	has30Days = ["Apr","Jun","Sep","Nov"];
	has29Days = ["Feb"];
	month = value[0];
	day = value[1];
	year = value[2];
	if (year.length < 4) isValidDateString=false;
	isLeapYear = parseInt(year)%4==0;
	if (isMonth(month, has30Days) && day > 30) isValidDateString=false;
	if (isMonth(month, has29Days) && day > 29) isValidDateString=false;
	if (isMonth(month, has29Days) && !isLeapYear && day > 28) isValidDateString=false;
	return isValidDateString;
}

// validation start...
var vMsg="";
var vFormattedMsg="";
var VT_IS_NOT_NULL=1;
var VT_IS_NUMERIC=2;
var VT_IS_EMAIL=3;
var VT_IS_PHONE_NUMBER=4;
var VT_IS_US_POSTALCODE=5;
var VT_IS_CANADIAN_POSTCODE=6;
var VT_IS_EQUAL=7;
var VT_IS_DIFFERENT=8;
var VT_IS_TRUE=9;
var VT_IS_FALSE=10;
var VT_IS_CREDITCARDNUMBER=11;
var VT_IS_OVER_18=12;
var VT_IS_BAD_WORD=13;
var VT_IS_NOT_EMAIL=14;
var VT_IS_GR_PASSWORD=15;
var VT_IS_PAST_DATE=16;
var VT_IS_GR_BIRTHDATE=17;

var invalidFieldCount=0;
var invalidFields=new Array();

function initValidation(){
	vMessages = new Array();
	vMessageCount = 0;
	vMsg="";
	vFormattedMsg="";
	invalidFieldCount=0;
	invalidFields=new Array();
}

function isInvalidField(captionId){
	for(i=0; i<=invalidFields.length; i++){
		if (invalidFields[i]==captionId){
			return true;
		}
	}
	return false;
}

function assertFormfield(vType, errMsg, formfield, label) {
	//alert("label: " + label.id);
	if (formfield == null) {
		// generic error
		alert("Generic error");
		return false;
	} else {
		var assertion=assertCondition(vType, formfield.value, errMsg);
		if(label!=null) {
			if (!assertion) {
				showErrMsgInLabel(label, errMsg);
			} else {
				clearErrMsgInLabel(label);
			}
		}
	}
	return assertion;
}

function assertArray(vType, errMsg, anArray, label, errElement) {
	//alert("label: " + label.id);
	if (anArray == null) {
		// generic error
		alert("Generic error");
		return false;
	} else {
		var assertion=assertCondition(vType, anArray, errMsg);
		if(label!=null) {
			if (!assertion) {
				showErrMsgInLabel(label, errMsg);
			} else {
				clearErrMsgInLabel(label);
			}
		}
	}
	return assertion;
}

function assert(vType, value, errMsg, captionId){
	//alert(captionId);
	captionObj=document.getElementById(captionId);
	assertion=assertCondition(vType, value, errMsg);
	if(captionObj!=null){
		if (!assertion || isInvalidField(captionId)){
			captionObj.style.color='red';
			invalidFieldCount++;
			invalidFields[invalidFieldCount]=captionId;
			
		}
		else{
			captionObj.style.color="";
		}
	}
	return assertion;
}

function assertInputContainer(vType, value, errMsg, captionId, errorDivId){
	//alert(captionId);
	captionObj=document.getElementById(captionId);
	assertion=assertCondition(vType, value, errMsg);
	if(captionObj!=null){
		if (!assertion || isInvalidField(captionId)){
			captionObj.className = "errorInputContainer";
			invalidFieldCount++;
			invalidFields[invalidFieldCount]=captionId;
			
			errorDivObj=document.getElementById(errorDivId);
			if (errorDivObj != null) {
				errorDivObj.style.display="block";
				var labelElements = errorDivObj.getElementsByTagName("label");
				if (labelElements != null && labelElements.length > 0) {
					var labelElement = labelElements[0];
					labelElement.innerHTML=errMsg;
				}
			}
		}
		else{
			captionObj.className = "inputContainer";
			errorDivObj=document.getElementById(errorDivId);
			if (errorDivObj != null) {
				errorDivObj.style.display="none";
			}
		}
	}
	return assertion;
}

function assertCondition(vType, value, errMsg){
  	if (vType==VT_IS_NOT_NULL){
  		return appMsgIfError(!isEmptyString(value), errMsg);
  	}
  	if (vType==VT_IS_NUMERIC){
  		return appMsgIfError((value!=null && /^[0-9]+$/.test(value)), errMsg);
  	}
  	if (vType==VT_IS_EMAIL){
  		return appMsgIfError((value!=null && /^[a-zA-Z0-9]+([\.\-_]*[a-zA-Z0-9]+)*[\.\-_]*@[a-zA-Z0-9]+([\.\-_]*[a-zA-Z0-9]+)*(\.[a-zA-Z0-9]{2,3})+$/.test(value)), errMsg);
  	}
  	if (vType==VT_IS_PHONE_NUMBER){
  		return appMsgIfError(!isEmptyString(value), errMsg);
  	}
  	if (vType==VT_IS_US_POSTALCODE){
  		//appMsgIfError((value==null||!/^[0-9]{10}$/.test(value)), errMsg);
  		return appMsgIfError(!isEmptyString(value), errMsg);
  	}
  	if (vType==VT_IS_CANADIAN_POSTCODE){
  		return appMsgIfError(!isEmptyString(value), errMsg);
  	}
  	if (vType==VT_IS_EQUAL){
  		val1=value[0];
  		val2=value[1];
  		return appMsgIfError( !isEmptyString(val1)&&!isEmptyString(val2) && val1==val2, errMsg);
  	}
  	if (vType==VT_IS_DIFFERENT){
  		val1=value[0];
  		val2=value[1];
  		return appMsgIfError( !((isEmptyString(val1)&&emptyString(val2))||val1==val2), errMsg);
  	}

  	if (vType==VT_IS_TRUE){
  		return appMsgIfError( value!=null&&value, errMsg);
  	}

  	if (vType==VT_IS_FALSE){
  		return appMsgIfError( value!=null&&!value, errMsg);
  	}
  	if (vType==VT_IS_CREDITCARDNUMBER){
  		return appMsgIfError((value!=null&&/^[0-9\*]+$/.test(value)), errMsg);
  	}
  	if (vType==VT_IS_OVER_18){
  		return appMsgIfError(isOver18(value), errMsg);
  	}
  	if (vType==VT_IS_BAD_WORD) {
  		return appMsgIfError( value!=null && value != "****", errMsg);
  	}
  	if (vType==VT_IS_NOT_EMAIL){
  		return appMsgIfError((value!=null && value.indexOf("@")==-1), errMsg);
  	}

  	if (vType==VT_IS_GR_PASSWORD){
  		return appMsgIfError((value!=null && value.length>3 && value.length<26 && value.indexOf(" ")==-1 && isGoodChars(value)), errMsg);
  	}
  	if (vType==VT_IS_PAST_DATE){
  		return appMsgIfError(isPastDate(value), errMsg);
  	}
  	if (vType==VT_IS_GR_BIRTHDATE){
  		return appMsgIfError(isPastDate(value) && isLater(value, ['January',1,1850]), errMsg);
  	}

}

function isGoodChars(val){
	if (val!=null){
		var badChars="@";
		for(i=0;i<badChars.length;i++){
			if (val.indexOf(badChars.charAt(i))>-1) 
				return false;
		}		
	}
	return true;
}
function isEmptyString(value){
	return value==null||value.replace(/ /g, "")=="";
}

function isOver18(value){
	ofAge = false;
	month = value[0];
	day = value[1];
	year = value[2];
	try{
		if (isValidDate(value)){
			dateString = day + " " + month + " " + year;
			var currDate = new Date();
			var birthDate = Date.parse(dateString);
			years = (currDate.getTime() - birthDate)/31556926000;
		
			if (years > regMinimumAge){
			ofAge = true;
			} else {
				setCookie("u18", "1", false, '/', false, false);
				ofAge = fale;
			}
		}
	} catch (error) { 
		//alert("caught exception:"+error);
		ofAge = false 
	}
	
	return ofAge;
		
}

function isPastDate(value){
	ofAge = false;
	month = value[0];
	day = value[1];
	year = value[2];
	try{
		if (isValidDate(value)){
			dateString = day + " " + month + " " + year;
			var currDate = new Date();
			var birthDate = Date.parse(dateString);
			return currDate.getTime() > birthDate;
		}
	} catch (error) { 
		alert("caught exception:"+error);
		ofAge = false 
	}
	
	return ofAge;
		
}

function isLater(testDate, refDate){
	ofAge = false;
	try{
		if (isValidDate(testDate) && isValidDate(refDate)){
			date1=Date.parse(testDate[0]+" "+testDate[1]+" "+testDate[2]);
			date2=Date.parse(refDate[0]+" "+refDate[1]+" "+refDate[2]);
			return date1>date2;
		}
		else{
			alert("Date formating error!");
		}
	} catch (error) { 
		alert("caught exception:"+error);
		ofAge = false 
	}
	
	return ofAge;
		
}

function getMmmFromMm(Mm) {
	if (Mm>=1 && Mm <= 12) {
		var months=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
		return months[Mm-1];
	} else {
		return "";
	}
}

function duplicateMessage(errMsg){
	for (i = 0; i < vMessages.length; i++){
		if (vMessages[i] == errMsg) return true;
	}
	return false;
}

function appMsgIfError(condition, errMsg){
	if (!condition){
		if (!duplicateMessage(errMsg)){
			vMessages[vMessageCount] = errMsg;
			vMessageCount++;
		}
		return false;
	}
	else{
		return true;
	}
}

function isvalid(){
	return vMessages.length == 0;
}

function getErrorMessage(){
	return vMsg;
}
function getFormattedErrorMessage(){
	for (i = 0; i < vMessages.length; i++){
	 vFormattedMsg += vMessages[i] + "<br />\n";
	}
	return vFormattedMsg;
}

function displayOptionsErrorMessage(divName){
	displayOptionsErrorMessageDetail(divName,getFormattedErrorMessage());
}

function displayOptionsErrorMessageDetail(divName, errorMsg){
	msgArea = document.getElementById(divName);
	msgArea.innerHTML="<p class=\"error\">"+errorMsg+"</div>";
	msgArea.visibility="visible";
}

function displayErrorMessage(divName){
	displayErrorMessageDetail(divName, getFormattedErrorMessage());
}

function displayErrorMessageDetail(divName, errorMsg){
	msgArea = document.getElementById(divName);
	msgArea.innerHTML="<div id=\"errorMsgBox\" class=\"errorMessageText\">"+errorMsg+"</div>";
	msgArea.style.visibility="visible";
	msgArea.style.display="block";
}
/*
function displayErrorMessage(divName){
	msgArea = document.getElementById(divName);
	msgArea.innerHTML="<div id=\"errorMsgBox\" class=\"errorMessageText\">"+getFormattedErrorMessage()+"</div>";
	msgArea.style.visibility="visible";
	msgArea.style.display = "block";
}
*/
function removeErrorMessage(divName) {
//	alert("removing error msg for: "+divName);
	msgArea = document.getElementById(divName);
	if (msgArea != null) {
		msgArea.style.display = "none";
	}	
}

function clearErrorMessage(divName){
	msgArea = document.getElementById(divName);
	if (msgArea != null) {
		msgArea.innerHTML = "";
		msgArea.style.visibility="hidden";
		msgArea.style.display = "none";
	}	
}

function emptyString(stringVar){
	if (stringVar==null || stringVar=='') return true;
	for (var index=0; index < stringVar.length; index++){
        	if (stringVar.charAt(index) != ' ') {return false;}
     	}
     	return false;
}

// changes input field to strip out all characters other than ones in filteredValues
function onlyNumeric (input, filteredValues) {
	s = input.value;
	var i;
	var returnString = "";
	for (i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if (filteredValues.indexOf(c) != -1) returnString += c;
	}	
	input.value = returnString;
}

// validation end

// display errors that are a result of an Ajax action
function showErrorMessage(errMsg, divName){
	if (errMsg!=null && errMsg!=""){
		initValidation();
		appMsgIfError(false, errMsg);
	   	if(!isvalid()){
	   		if (document.getElementById(divName)!=null){
				displayErrorMessage(divName);
	   		}
	   		else{
	   			alert(errMsg);
	   		}		
	   	}
	}
}

// Appends 'error' css classname to the element.
// This ensures no pending spaces at the end of the clasName value
function addErrorStyleToElement(elementName) {
	if (elementName != null) {
		var newClassName = stripErrorClass(elementName.className);
		if (newClassName.length > 0) {
			newClassName = newClassName + " ";
		}
		newClassName = newClassName + "error";
		elementName.className = newClassName;
	}
}

function removeErrorStyleFromElement(elementName) {
	if (elementName != null) {
		elementName.className = stripErrorClass(elementName.className);
	}
}

function showErrMsgInLabel(label, errMsg) {
	if (label != null) {
		label.innerHTML=errMsg;
		label.style.display='block';
	}
}

function clearErrMsgInLabel(label) {
	if (label != null) {
		label.innerHTML = "";
		label.style.display = 'none';
	}
}

function stripErrorClass(strClassName) {
	var nClassName = "";
	var classNames = strClassName.split(" ");
	for (i = 0; i < classNames.length; i++) {
		if (classNames[i] != '') {
			if (classNames[i].match(/^error$/) == null) {
				if (nClassName.length > 0) {
					nClassName = nClassName + " ";
				}
				nClassName = nClassName + classNames[i];
			}
		}
	}
	return nClassName;
}

// Checks rather the radioObject is checked or not.  Returns true at least 1 radio is checked.  Returns false, none is checked. 
function isRadioChecked(aRadioObject) {
	var checked = false
	
	if (aRadioObject != null) {
		if (aRadioObject.length != null) {
			// more than 1 radio button
			for (var i=0; i < aRadioObject.length; i++) {
				if (aRadioObject[i].checked) {
					checked = true;
					break;
				}
			}
		} else {
			if (aRadioObject.checked) {
				checked = true;
			}
		}
	}

	return checked;
}

/* Returns the checked radio value.  Returns empty string if no radio button is selected.
 * 
 */
function getRadioCheckedValue(aRadioObject) {
	var value="";
	
	if (aRadioObject.length != null) {
		// more than 1 radio button
		for (var i=0; i < aRadioObject.length; i++) {
			if (aRadioObject[i].checked) {
				value = aRadioObject[i].value;
				break;
			}
		}
	} else {
		if (aRadioObject.checked) {
			value = aRadioObject.value;
		}
	}

	return value;
}

dojo.addOnLoad(function(){
	if(typeof(isSurveyEnabled) != "undefined" && isSurveyEnabled) {
		var foreseeInclude = dojo.doc.createElement('script');
		foreseeInclude.type = 'text/javascript';
		foreseeInclude.src = '/static/js/foresee/foresee-trigger.js';
		dojo.body().appendChild(foreseeInclude);
	}
});

/**
 * End content from error.js
 **/

// return current epoch time in milliseconds
function getTime(){
	var cookieTime = getCookieAttribute("DSISession", "DSILASTACCESS");
	if( cookieTime != "" ){		
		// return time stored in session cookie
		return parseInt(cookieTime);
	}else{
		// use browser time 
		var d = new Date();
		return d.getTime();	
	}
}

function showMobilewebLink(uri) {
	//TODO::insert approprite anchor tag into static html footer controlled by production
	var markup = '<div style="width: 100%; text-align: center; padding-bottom: 20px;" class="mobileBar"><a href="' + uri + '"><img src="/static/media/image_db/buttons/mobileversion.png" /></a></div>';

	var agent = navigator.userAgent.toLowerCase();
	if(agent.indexOf("iphone") != -1 || agent.indexOf("Android") != -1) {
	dojo.query(".superfooter").forEach(function(node, index, arr){
      node.innerHTML = markup + node.innerHTML;
  	});
  	}		
}

