if (typeof storis == 'undefined'){
	var storis = new function(){
		this.ajax = null;
		this.topLevelCategoryURL = ""
		this.globalBaseURI = "";
		this.scriptBaseURI = "";
		this.message = "";
		this.sessionCart = "";
		this.keepActiveTimeLimit = ((20-1) * 60);
		this.cookiePath = "";
		this.sessionMessage = "";
		this.debugFlag = "0";
		
	};
};

storis.coreCode = new function(){
	this.BaseURI 			= storis.scriptBaseURI;
	this.km_scripts 		= new Object();
	
	/* create elements for floating div message box */
	this.disableBG 			= $(document.createElement('div'));
	this.hoverInfo 			= $(document.createElement('div'));
	this.hoverInfoContent 	= $(document.createElement('div'));
	this.titleBarContent 	= $(document.createElement('div'));
	this.titleBar 			= $(document.createElement('div'));
	this.closeLink 			= $(document.createElement('a'));
	this.body				= $('body');
	this.reloadFlag 		= false;										// flag to signal page needs to be reloaded after message box is closed. a value of true will reload the page.
	this.overrideWidth 		= null;											// overides default width of the message box.
	this.overrideHeight 	= null;										
	
	this.init = function() {
		var self = storis.coreCode;											// assign self to corecode so we can easily reference other items in the corecode class...
		self.importJavaScriptFiles();										// imports external js files used on every page...
		self.addEventSimple(window, 'load', self.createMessageElements);
		self.addEventSimple(window, 'load', self.displayAllErrors);
		self.addEventSimple(window, 'load', self.setFormFocus);
		self.addEventSimple(window, 'load', self.winStatus);
		if(storis.debugFlag == "1"){										// set up our debug scripts if in debug mode.
			self.addEventSimple(window, 'load', self.prepDebugTabs);
		}
	};
	
	/*	Easy way of including or removing external js scripts without needing to edit every page. */
	this.km_myclass_import = function(jsFile){
		var self = storis.coreCode;
		if (self.km_scripts[jsFile] != null) return;
		var scriptElt = document.createElement('script');
		scriptElt.type = 'text/javascript';
		scriptElt.src = jsFile;
		document.getElementsByTagName('head')[0].appendChild(scriptElt);
		self.km_scripts[jsFile] = jsFile;
	};
	
	//load our external JavaScript files used throughout the site...
	this.importJavaScriptFiles = function(){
		var self = storis.coreCode;
		/* note: these files could be loaded anywhere as long as they come after sms_coreCode.asp and sms_coreCode.js.
		the reason being they use functions in sms_coreCode.js which inturn uses variables assigned in sms_coreCode.asp.
		Loading them before these to files would cause javascript errors. */
		self.km_myclass_import(self.BaseURI + 'js/sms_sideNavigation.js');		// expands parent directory of active web category in the side navigation.
		self.km_myclass_import(self.BaseURI + 'js/sms_vsSCLinkHandler.js');		// core script used to control links like check zip, view cart, gift certificate. etc...
		self.km_myclass_import(self.BaseURI + 'js/ie6UpgradeMsg.js');			// displays IE upgrade for IE 6 and below.
		self.km_myclass_import(self.BaseURI + 'js/cookie.js');					// checks if cookies are enabled.
		self.km_myclass_import(self.BaseURI + 'js/debug.js');					// used for debugging javasript. can be commented on production site.
		self.km_myclass_import(self.BaseURI + 'js/sms_SessionKeepAlive.js');	// maintains session state by calling a server side page through AJAX.
	};
	
	this.createMessageElements = function(){
		var self = storis.coreCode;
		self.reloadFlag = false;
		self.closeLink.attr({
			href: 'javascript:void(0);',
			title: 'close'
		});
		self.closeLink.html('close');
		self.closeLink.click(self.hideCSSMsgBox);
		self.disableBG.attr({id: 'DisableBG'});
		self.hoverInfo.attr({id: 'hoverInfo'});
		self.hoverInfoContent.attr({id: 'hoverInfoContent'});
		self.titleBar.attr({id: 'titleBar'});
				
		self.titleBarContent.append(self.closeLink);
		self.titleBar.append(self.titleBarContent);
		self.hoverInfo.append(self.hoverInfoContent);
		self.hoverInfo.append(self.titleBar);
		$('body').append(self.hoverInfo);
		$('body').append(self.disableBG);
	};
	
	this.hideCSSMsgBox = function(){
		var self = storis.coreCode;
		try{
			self.hoverInfoContent.innerHTML = "";
			if (self.reloadFlag){
				document.location.reload();
			}else{
				self.hoverInfo.fadeOut();
				self.disableBG.css({
					'display': 'none'
				});
			}
			self.reloadFlag = false;
			self.setFormFocus();
			return true;
		}catch(e){
			return false;
		}
	}

	this.expandDiv = function(Msg, divWidth, divHeight){
			var self = storis.coreCode;
			divWidth = (!self.overrideWidth)? divWidth : self.overrideWidth;
			divHeight = (!self.overrideHeight)? divHeight : self.overrideHeight;
			try{
			    var winl;
				var wint;
				var noPx = document.childNodes ? 'px' : 0;
				var windowWidth 		= (document.documentElement.clientWidth || document.body.clientWidth);
			    var windowHeight 		= (document.documentElement.clientHeight || document.body.clientHeight);
				var windowScrollHeight 	= self.body.outerHeight();
				var windowScrollWidth 	= self.body.outerWidth();
				winl = (windowWidth - divWidth) / 2;	// figures out what our left position of the message box should begin so it appears centered.
			    wint = 30 								//(divHeight==0)?(30):((window.screen.height - divHeight) / 2);
				self.disableBG.css({
					height: windowScrollHeight,
					display: 'block'
				});
				
				self.hoverInfo.css({
					'left': winl, 
					'top': wint,
					'width': divWidth, 
					'height': divHeight,
					'display': 'block'
				});
				
				self.hoverInfoContent.html(Msg);
				self.hoverInfoContent.css({
					'height': (divHeight - 60) // set height of content container to 70% of the main message box.
				});
				location.hash = '#';
				return self.hoverInfo;
			}catch (e){}
	};
	
	this.showMessage = function(Msg, divWidth, divHeight){
		var self = storis.coreCode;
		if(Msg != ""){
			var objInfoBox = self.expandDiv(Msg, divWidth, divHeight)
			return objInfoBox;
		}
	};
	
	this.displayAllErrors = function(){
		var self = storis.coreCode;
		var alertMsg = "";
		if (storis.sessionMessage != ""){
			alertMsg = storis.sessionMessage;
		}else if(storis.message != ""){
			alertMsg = storis.message;
		}
		if(alertMsg != ""){
			self.showMessage(alertMsg, 500, 200);
		}
	};
	
	this.addEventSimple = function(obj,evt,fn) {
		if (obj.addEventListener){
			obj.addEventListener(evt,fn,false);
		}else if (obj.attachEvent){
			obj.attachEvent('on'+evt,fn);
		}
	};

	this.removeEventSimple = function(obj,evt,fn) {
		if (obj.removeEventListener){
			obj.removeEventListener(evt,fn,false);
		}else if (obj.detachEvent){
			obj.detachEvent('on'+evt,fn);
		}
	};
	
	this.addClass = function(target, classValue){
		var pattern = new RegExp("(^| )" + classValue + "( |$)");
		if (!pattern.test(target.className)){
			if (target.className == ""){
				target.className = classValue;
			}else{
				target.className += " " + classValue;
			}
		}
		return true;
	}

	this.removeClass = function(target, classValue){
		var removedClass = target.className;
		var pattern = new RegExp("(^| )" + classValue + "( |$)");
		removedClass = removedClass.replace(pattern, "$1");
		removedClass = removedClass.replace(/ $/, "");
		target.className = removedClass;
		return true;
	}
	
	this.setFormFocus = function() {
		var W3CDOM = document.createElement && document.getElementsByTagName;
		if (!W3CDOM) return;
		var forms = document.forms;
		var focusSet = false;
		for (var i=0;i<forms.length;i++) {
			for(var j=0;j<forms[i].elements.length;j++){
				if ((forms.length==1)&&(forms[i].elements[j].type=="text")){
					forms[i].elements[j].focus();
					focusSet = true;
					break;
				}else if((i>0)&&(forms[i].elements[j].type=="text")){
					forms[i].elements[j].focus();
					focusSet = true;
					break;
				}
			}
			if(focusSet){
				break;
			}
		}
	};
	
	this.winStatus = function(){
		var self = storis.coreCode;
		var windowStatusOver = '';
		var windowStatusOut = 'hello';
		$('a').mouseover(function(){
			if (this.title != ''){
				windowStatusOver = $(this).title;
			}else{
				windowStatusOver = $(this).text();
			}
			window.status = windowStatusOver;
		});
		$('a').mouseout(function() {
			window.status = windowStatusOut;
		});
	};

	
	this.prepDebugTabs = function(){
		var self = storis.coreCode;
		try{
			$(document).ready(function() {
	    	$("#debugTabs").tabs();
		  });
	  	}catch(e){};
	};
	
	// 11-09-2010 - dcw / added to address functional issue in firefox / begin....
	this.getZipForm = function(form_data){
		var self = storis.coreCode;
		var ZIPLOOKUP = {
			delay: 5000,
			running: false,
			url: "faq/shipZipAlt.asp",
			load: function(){				
				if (this.running) { // Don't call if already running!
					return;
				};
				this.running = true;
				var _zipLookup = this;
				$.ajax({
					type: "POST",
					url: _zipLookup.url,
					data: form_data,
					dataType: 'html',
					success: function(data){
						_zipLookup.display(data);
					}
				});
			},
			display: function(data) {	// Process the data
				var container = self.expandDiv(data, (500), (300));
				container.ready(function(){
					$('#shipping-lookup-form').submit(function() {
						self.getZipForm($(this).serialize());
						storis.coreCode.reloadFlag = true;
					 	return false;
					});
				});
			}
			
		};
		ZIPLOOKUP.load();
	}
	// 11-09-2010 - dcw / end....
	
	this.debug = function(data){
		var self = storis.coreCode;
		var textarea = $(document.createElement('textarea'));
		$(textarea).text(data).css({
			'width': '300px',
			'height': '500px',
			'position': 'absolute',
			'top': '20px',
			'left': '20px',
			'z-index': '500'
		});
		$(textarea).appendTo('body');
	}
};

$(storis.coreCode.init());


function checkforNum(objElement){
	if (objElement.value != ""){
		var intNumber = parseInt(objElement.value);
		if (isNaN(intNumber)){
			objElement.value = "";
			objElement.focus();
		}else{
			objElement.value = intNumber
		}
	}
}


//var reloadFlag = false;
/****************************************************************
// css / javascript alert box...
var DisableBG = document.createElement('DIV');
var hoverInfo = document.createElement('DIV');
var hoverInfoContent = document.createElement('DIV');
var titleBarContent = document.createElement('DIV');
var titleBar = document.createElement('DIV');
var closeLink = document.createElement('A');
*/


/*
function createMessageDivs(){
	closeLink.innerHTML = "close"
	closeLink.href="javascript:void(0);"
	addEventSimple(closeLink,'click', HideCSSMsgBox);
	DisableBG.id = "DisableBG"
	hoverInfo.id = "hoverInfo"
	hoverInfoContent.id = "hoverInfoContent"
	titleBar.id = "titleBar"
	titleBarContent.appendChild(closeLink)
	titleBar.appendChild(titleBarContent)
	hoverInfo.appendChild(hoverInfoContent)
	hoverInfo.appendChild(titleBar)
	document.body.appendChild(hoverInfo);
	document.body.appendChild(DisableBG);
}

function HideCSSMsgBox(){
	try{
		hoverInfoContent.innerHTML = "";
		if (reloadFlag){
			document.location.reload();
		}else{
			$('#hoverInfo').fadeOut();
			DisableBG.style.display = "none";
		}
		reloadFlag = false;
		storis.coreCode.setFormFocus();
		return true;
	}catch(e){
		return false;
	}
}


// used for expandable windows...
this.overrideWidth = null;
this.overrideHeight = null;
this.expandDiv = function(Msg, divWidth, divHeight){
	// dcw / begin - added to allow dimensions of the alert window to be overwriten on the fly...
	this.divWidth = (!this.overrideWidth)? divWidth : this.overrideWidth;
	this.divHeight = (!this.overrideHeight)? divHeight : this.overrideHeight;
	// dcw / end...
	try{
	    var winl;
		var wint;
		var noPx = document.childNodes ? 'px' : 0;
		var windowWidth = document.documentElement.clientWidth || document.body.clientWidth;
	    var windowHeight = document.documentElement.clientHeight || document.body.clientHeight;
		var windowScrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
		var windowScrollWidth = document.documentElement.scrollWidth || document.body.scrollWidth;
		winl = (windowWidth - this.divWidth) / 2;
	    wint = 30 
		// grey out the background and set the height of the grey area to match that of page scroll.
		DisableBG.style.height = windowScrollHeight + noPx;
		DisableBG.style.display="block";

		// Insert message into our message container...
		hoverInfoContent.innerHTML = "";
		hoverInfoContent.style.height = (this.divHeight-60) + noPx;
		hoverInfoContent.innerHTML = Msg;
		
		// display and position our message box...
		hoverInfo.style.left = winl + noPx;
		hoverInfo.style.top = wint + noPx;
		hoverInfo.style.width = this.divWidth + noPx;
		hoverInfo.style.height = (this.divHeight) + noPx;
		
		// add check to verify info is not show to prevent having to repaint the screen if it's already visible...
		if ((hoverInfo.style.display=="")||(hoverInfo.style.display=="none")){
			hoverInfo.style.display="block";
		}
		location.hash = '#';
	}catch (e){}
}
*/
function setOpacity(e,opacity){
	var o=e.style;
	o.opacity=(opacity/100); //Opera
	o.MozOpacity=(opacity/100); //Mozilla+Firefox
	o.KhtmlOpacity=(opacity/100); //Konqueror
	o.filter="alpha(opacity="+opacity+")"; //IE
}


function showMessage(Msg, divWidth, divHeight){
	storis.coreCode.showMessage(Msg, divWidth, divHeight)
}
/*****************************************************************/
	
/** Used to assign and remove events to page elements troughout the site **/
function addEventSimple(obj,evt,fn) {
	if (obj.addEventListener)
		obj.addEventListener(evt,fn,false);
	else if (obj.attachEvent)
	obj.attachEvent('on'+evt,fn);
}

function removeEventSimple(obj,evt,fn) {
	if (obj.removeEventListener)
		obj.removeEventListener(evt,fn,false);
	else if (obj.detachEvent)
	obj.detachEvent('on'+evt,fn);
}

/** PUSH AND SHIFT FOR IE5 **/
function Array_push() {
	var A_p = 0
	for (A_p = 0; A_p < arguments.length; A_p++) {
		this[this.length] = arguments[A_p]
	}
	return this.length
}

if (typeof Array.prototype.push == "undefined") {
	Array.prototype.push = Array_push
}

function Array_shift() {
	var A_s = 0
	var response = this[0]
	for (A_s = 0; A_s < this.length-1; A_s++) {
		this[A_s] = this[A_s + 1]
	}
	this.length--
	return response
}

if (typeof Array.prototype.shift == "undefined") {
	Array.prototype.shift = Array_shift
}


function winStatus(msg){
	return storis.coreCode.winStatus(msg)
}


var d=document;
// function used to open a new child window
var SelectionWindow = null;
function openWindow(url, width, height) {
	var winWidth = (width);
	var winHieght = (height);
	var winl = (screen.width - winWidth) / 2;
	var wint = (screen.height - winHieght) / 2;
    winStats='toolbar=no,location=no,directories=no,menubar=no,'
    winStats+='scrollbars=yes,width='+winWidth+',height='+winHieght
	if (navigator.appName.indexOf("Microsoft")>=0) {
         	winStats+=',left='+winl+',top='+wint
		}else{
      		winStats+=',screenX='+winl+',screenY='+wint
	}
	
	if (!SelectionWindow || SelectionWindow.closed){
		SelectionWindow = window.open(url,"",winStats);
	}else{
		SelectionWindow.focus();
	}

	if (SelectionWindow.opener == null){
		SelectionWindow.opener = self
	} 
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft + "|" + curtop];
}

// used to fill expandable window...
function ajaxFunction(pageName, ElementName){
	var xmlHttp;
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}catch (e){// Internet Explorer
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e){
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
    
	xmlHttp.onreadystatechange=function(){		
		switch(xmlHttp.readyState){
		case 1:
		  break;
		case 4:			
			document.getElementById(ElementName).innerHTML=xmlHttp.responseText;
		  break;
		default:	 
		}
	}
	xmlHttp.open("GET",pageName,true);
    xmlHttp.send(null);
}

// set functions that need to run after page loads here...
function loadInitScripts(){
	prepMultiCurrencyMenu();
}

function switchElementState(){
	var multiCurrencySelections = document.getElementById("multiCurrencySelections")
	multiCurrencySelections.style.display=(multiCurrencySelections.style.display!="block")? "block" : "none"
}

function prepMultiCurrencyMenu(){
	try{
		var multiCurrency = document.getElementById("multiCurrency")
		var multiCurrencySelections = document.getElementById("multiCurrencySelections")
		addEventSimple(multiCurrency,'click',switchElementState);
	}catch(e){}
} 


//***************************************************************************************/
// functions to handle zip code for tax calculation logic...
function getZipForm(addQS){
	storis.coreCode.getZipForm();
	/*
	var windowWidth = 500;
    var windowHeight = 300;
	if(addQS != ""){
		addQS = "&" + addQS;
	}
	var myShipZipURL = "faq/shipZipAlt.asp?BackLink=" + location.href + addQS;
	if (!myZipContainer){
		var myZipContainer = document.createElement('DIV');
	}
	myZipContainer.id = "myZipContainer";
	storis.coreCode.hoverInfoContent.innerHTML = "";
	
	var preLoaderImg = document.createElement('IMG');
	preLoaderImg.src = storis.scriptBaseURI + "images/ajax-loader.gif";
	preLoaderImg.className = "ajaxLoader"
	myZipContainer.appendChild(preLoaderImg);
	
  	storis.coreCode.hoverInfoContent.append(myZipContainer);
	ajaxFunction(myShipZipURL, "myZipContainer");
	storis.coreCode.showMessage(myZipContainer, windowWidth, windowHeight);
	*/
} 

function submitZip(objForm){
	var myZipCode = objForm.zip.value
	var myHidVal = objForm.HidVal.value
	var myBackLink = objForm.BackLink.value
	storis.coreCode.reloadFlag = true;
	getZipForm("zip=" + myZipCode + "&HidVal=" + myHidVal)
	return false;
}

//***************************************************************************************/
// functions to handle pickup logic...
function ajaxPickupCall(pageName, ElementName, closeDiv){
	var xmlHttp;
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}catch (e){// Internet Explorer
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e){
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function(){		
		switch(xmlHttp.readyState){
		case 1:
		  break;
		case 4:			
		  	if (closeDiv){
				storis.coreCode.hideCSSMsgBox();
			}else{
				document.getElementById(ElementName).innerHTML=xmlHttp.responseText;
			}
		  break;
		default:	 
		}
	}
	xmlHttp.open("GET",pageName,true);
    xmlHttp.send(null);
}

function showPickup(addQS, closeDiv){
	var windowWidth = 700;
    var windowHeight = 550;
	if(addQS){
		addQS = addQS + "&";
	}
	var myPickupURL = storis.scriptBaseURI + "GetPickupLocationsAJAX.asp?" + addQS + "BackLink=" + location.href;
	if (!myPickupContainer){
		var myPickupContainer = document.createElement('DIV');
	}
	myPickupContainer.id = "myPickupContainer";
	var preLoaderImg = document.createElement('IMG');
	preLoaderImg.src = storis.scriptBaseURI + "images/ajax-loader.gif";
	preLoaderImg.className = "ajaxLoader"
	myPickupContainer.appendChild(preLoaderImg);
  	storis.coreCode.hoverInfoContent.append(myPickupContainer);
	ajaxPickupCall(myPickupURL, "myPickupContainer", closeDiv);
	storis.coreCode.showMessage(myPickupContainer, (windowWidth), (windowHeight));
} 

function submitPickup(objForm){
	var myBackLink = objForm.BackLink.value
	var myPickupLoc = objForm.PickupLoc.value
	var myPickupFlag = objForm.PickupFlag.value
	storis.coreCode.reloadFlag = true;
	showPickup("PickupLoc=" + myPickupLoc + "&PickupFlag=" + myPickupFlag, true)
	return false;
}

function setPickupInfo(element, myValue){
	var objForm = element.form;
	element.value = myValue;
	submitPickup(objForm);
}
//***************************************************************************************/

function setFormFocus() {
	var W3CDOM = document.createElement && document.getElementsByTagName;
	if (!W3CDOM) return;
	var forms = document.forms;
	var focusSet = false;
	for (var i=0;i<forms.length;i++) {
		for(var j=0;j<forms[i].elements.length;j++){
			if ((forms.length==1)&&(forms[i].elements[j].type=="text")){
				forms[i].elements[j].focus();
				focusSet = true;
				break;
			}else if((i>0)&&(forms[i].elements[j].type=="text")){
				forms[i].elements[j].focus();
				focusSet = true;
				break;
			}
		}
		if(focusSet){
			break;
		}
	}
}

function openWinPickup(url) {
	winStats='toolbar=no,location=no,directories=no,menubar=no,'
    winStats+='scrollbars=no,width=600,height=600'
    if (navigator.appName.indexOf("Microsoft")>=0) {
    	winStats+=',left=70,top=20'
	}else{
    	winStats+=',screenX=70,screenY=20'
    }
    floater=window.open(url,"",winStats)
};

// trims spaces from begining and end of string...
String.prototype.trim = function() {
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
};


Array.prototype.clear = function(){
	this.length = 0;
};


//addEventSimple(document,'keypress',getKey)
storis.coreCode.addEventSimple(window,'load',loadInitScripts);
