if (typeof storis == 'undefined'){
	var storis = new function(){
		this.ajax					= null;
		this.topLevelCategoryURL	= "";
		this.globalBaseURI			= "";
		this.scriptBaseURI			= "";
		this.message				= "";
		this.sessionCart			= "";
		this.keepActiveTimeLimit	= ((19) * 60);
		this.cookiePath				= "";
		this.sessionMessage			= "";
		this.debugFlag				= "0";
		this.usePickupOption		= false;
		this.useMultiCurrency		= false;
		this.enableCntyLngMap		= false;
		this.is_country_avail		= false;
		this.image_exist			= null;
	};
};

storis.coreCode = new function(){
	this.BaseURI 			= storis.scriptBaseURI;
	this.js_files 			= new Object();						// contains all scripts that have been added dynamically to the document head.
	this.css_files			= new Object();
	this.googleAnalyticsId	= null
	this.usePickupOption 	= this.usePickupOption = "true";
	this.$head				= null;
	this.pickup_container	= null;
	
	/* 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() {
		$(document).ready(function() {
			$es.$head = ($es.$head)? $es.$head: $("head");
			$es.importExternalFiles();
			$es.createMessageElements();
			$es.displayAllErrors();
			$es.setFormFocus();
		});
	};
	
	this.import_js = function(jsFile){
		if ($es.js_files[jsFile] != null) return;/*check if script was already added.*/
		$(document.createElement('script')).prop({'type' : 'text/javascript', 'async' : true, 'src' : jsFile}).appendTo($es.$head);
		$es.js_files[jsFile] = jsFile;
	};
	this.import_css = function(css_file){
		if ($es.css_files[css_file] != null) return;/*check if css was already added.*/
		$(document.createElement('link')).prop({'rel':'stylesheet','type':'text/css','async':true,'href':css_file}).appendTo($es.$head);
		$es.css_files[css_file] = css_file;
	};
	
	//load our external JavaScript files used throughout the site...
	this.importExternalFiles = function(){
		/* Run capabilities test */
		if ($es.usePickupOption){$es.import_css($es.BaseURI+'css/app_css_dependences/datagridPickup.css')};
		if (storis.debugFlag){$es.import_css($es.BaseURI+'css/app_css_dependences/debugInformation.css')};
		$es.import_css($es.BaseURI+'app_resources/better-tooltip/theme/style.css');
		$es.import_css($es.BaseURI+'js/libs/jquery/css/base/minified/jquery-ui.min.css');
		$es.import_css($es.BaseURI+'js/libs/colorbox/css/colorbox.css');
		
		$es.import_js($es.BaseURI+'js/libs/jquery/js/jquery-ui.min.js');
		$es.import_js($es.BaseURI+'js/libs/colorbox/jquery.colorbox-min.js');
		
		$es.import_js($es.BaseURI+'js/estoris-navigation-state.js');
		$es.import_js($es.BaseURI+'js/menu.js');
		$es.import_js($es.BaseURI+'js/sms_vsSCLinkHandler.js');
		/*$es.import_js($es.BaseURI+'js/sms_SessionKeepAlive.js');*/
		$es.import_js($es.BaseURI+'js/ie6UpgradeMsg.js');
		$es.import_js($es.BaseURI+'js/cookie.js');
		
		$es.import_js($es.BaseURI+'app_resources/better-tooltip/js/jquery.betterTooltip.js');
		/*$es.import_js($es.BaseURI+'js/client-custom/client-custom.js');*/
		
		/*
		if(storis.enableCntyLngMap){$es.import_js($es.BaseURI+'app_resources/region-map/js/region-map.js')};*/
		if (storis.debugFlag){$es.import_js($es.BaseURI + 'js/debug.js');}
		/*$es.import_js($es.BaseURI+'js/googleAnalytics.js');*/

		
	};
	
	this.createMessageElements = function(){
		$es.reloadFlag = false;
		$es.closeLink.prop({
			href: 'javascript:void(0);',
			title: 'close'
		});
		$es.closeLink.html('close');
		$es.closeLink.click($es.hideCSSMsgBox);
		$es.disableBG.prop({id: 'DisableBG'}).click($es.hideCSSMsgBox);
		$es.hoverInfo.prop({id: 'hoverInfo'});
		$es.hoverInfoContent.prop({id: 'hoverInfoContent'});
		$es.titleBar.prop({id: 'titleBar'});
				
		$es.titleBarContent.append($es.closeLink);
		$es.titleBar.append($es.titleBarContent);
		$es.hoverInfo.append($es.hoverInfoContent);
		$es.hoverInfo.append($es.titleBar);
		$('body').append($es.hoverInfo);
		$('body').append($es.disableBG);
	};
	
	this.hideCSSMsgBox = function(){
		try{
			$($es.hoverInfoContent).html('');
			$($es.hoverInfo).css({
				'display' : 'none'
				});
			$($es.disableBG).hide();
			if ($es.reloadFlag){
				document.location.reload();
			}
			$es.reloadFlag = false;
			$es.setFormFocus();
			return true;
		}catch(e){
			return false;
		}
	}

	this.expandDiv = function(Msg, divWidth, divHeight){
			divWidth = (!$es.overrideWidth)? divWidth : $es.overrideWidth;
			divHeight = (!$es.overrideHeight)? divHeight : $es.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 	= $es.body.outerHeight();
				var windowScrollWidth 	= $es.body.outerWidth();
				winl = (windowWidth - divWidth) / 2; /* center div */
			    wint = 30
				
				$(window).scrollTop(0);
				
				var speed = 1000;
				if ($($es.hoverInfoContent).css('height') > (divHeight - 60)){
					speed = 400
				}
				
				$($es.disableBG).css({
					height: $(document).height(),
					opacity: .75
				}).show();
				$($es.hoverInfo).css({
						'left'		: winl, 
						'top'		: wint,
						'width'		: divWidth, 
						'display'	: 'block',
						'height'	: divHeight
				});
								
				$($es.hoverInfoContent).html(Msg)
				.css({
					'height': (divHeight - 60)
				}, speed);
				return $es.hoverInfo;
			}catch (e){}
				
			
			
	};
	
	this.showMessage = function(Msg, divWidth, divHeight){
		if(Msg != ""){
			var objInfoBox = $es.expandDiv(Msg, divWidth, divHeight);
			return objInfoBox;
		}
	};
	
	this.displayAllErrors = function(){
		var alertMsg = "";
		if (storis.sessionMessage != ""){
			alertMsg = storis.sessionMessage;
		}else if(storis.message != ""){
			alertMsg = storis.message;
		}
		if(alertMsg != ""){
			$es.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 _init_focus = this;
		var INIT_FOCUS = {
			set_focus: false,
			load: function(){
				_init_focus = this;
				_init_focus.on_page_load();
			},
			on_page_load: function(){
				_init_focus.attach_focus_events();
				$('form').filter(function(index){
					set_focus = ($('form').length > 1)? ((index % 2 == 1)? true : false) : true;
					if (set_focus){
						_init_focus.focus_first_input(this);
					};
				})
			},
			focus_first_input: function(obj){
				$('input[type="text"]:visible', $(obj)).each(function(index){
					set_focus = (this.name == "TEXTBOX1")? false : true;
					if (set_focus){
						$(this).focus();
					};
				})
			},
			attach_focus_events: function(){
				$('form').each(function(index){
					$('input[type="text"]:visible, input[type="password"]:visible, textarea:visible, select:visible', $(this)).each(function(index){
						_init_focus.on_focus(this);
						_init_focus.on_blur(this);
					})
				})
				return;
			},
			on_focus: function(obj){
				$(obj).focus(function(){
					$(this).addClass('selected').select();
				})
			},
			on_blur: function(obj){
				$(obj).blur(function(){
					$(this).removeClass('selected');
					if (this.type != "select-one"){
						if(this.value == ""){
							this.value = obj.defaultValue;
						};
					}
				})
			}
		};
		INIT_FOCUS.load();
	};
	
	this.winStatus = function(){
		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;
		});
	};

	/* hides text assigned the class toggle-hide-show when page loads */
	this.hideExtraText = function(){
		var p = $(document.createElement('p'));
		var a  = $(document.createElement('a'));
		$(a).text('show more...').prop('href', 'javascript:void(0);');
		$(p).addClass('more-link');
		$(p).append(a);
		$('.toggle-hide-show').before(p);
		$('.toggle-hide-show').css('display', 'none');
		$(a).bind({
			click: function() {
				$es.toggleExtraText();
			}
		});
		
		$es.toggleExtraText = function(){
			if ($('.toggle-hide-show').css('display') == 'none'){
				$('.toggle-hide-show').slideDown('slow', function() {
			    // Animation complete.
					$('.more-link a').text('show less...');
				});
			}else{
				$('.toggle-hide-show').slideUp('slow', function() {
			    // Animation complete.
					$('.more-link a').text('show more...');
				});
			}
		};
	};
	
	
	this.getZipForm = function(form_data){
		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 = $es.expandDiv(data, (500), (300));
				container.ready(function(){
					$('#shipping-lookup-form').submit(function() {
						$es.getZipForm($(this).serialize());
						storis.coreCode.reloadFlag = true;
						
					 	return false;
					});
				});
			}
			
		};
		ZIPLOOKUP.load();
	};
	
	this.debug = function(data){
		if (!$es.textarea){
			$es.textarea = $(document.createElement('textarea')).css({
				'width': '300px',
				'height': '400px',
				'position': 'absolute',
				'top': '20px',
				'left': '20px',
				'z-index': '500',
				'border': '1px solid #333'
			}).appendTo('body');
		}
		$($es.textarea).text($($es.textarea).text() + data + '\r');
	};
	
	this.prepDebugTabs = function(){
		try{
			$(document).ready(function() {
	    		$("#debugTabs").tabs();
		  });
	  	}catch(e){};
	};
};

var $es = storis.coreCode; $es.init();


function checkforNum(objElement){
	if (objElement.value != ""){
		var intNumber = parseInt(objElement.value);
		if (isNaN(intNumber)){
			objElement.value = "";
			objElement.focus();
		}else{
			objElement.value = intNumber
		}
	}
}

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(){
	storis.coreCode.getZipForm();
} 

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;
};

