// used to get the site real estate (sre) queryParam 
  function getRealEstate() 
  { 
      var sre = null;
      var url = window.location.href;
      var queryParams = url.toQueryParams();
    
      if (queryParams != null)
          sre = queryParams.sre;
        
      if (sre == null)
          sre = "";
    
    return sre;
  }

  // creates a cookie
  function createCookie(name,value,days) 
  {
      if (days) 
      {
		      var date = new Date();
				  date.setTime(date.getTime()+(days*24*60*60*1000));
				  var expires = "; expires="+date.toGMTString();
		  }
		  else var expires = "";
	    document.cookie = name+"="+value+expires+"; path=/";
  }
			
  // Gets and returns a cookie by name.	
  function getCookie(name) 
  {
      var nameEQ = name + "=";
		  var ca = document.cookie.split(';');
		  for(var i=0;i < ca.length;i++) 
      { 
		      var c = ca[i];
				  while (c.charAt(0)==' ') c = c.substring(1,c.length);
				  if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		  }
				
      return null;
	}

	// Deletes a cookie by name.
  function eraseCookie(name) 
  {
	    createCookie(name,"",-1);
	}		
			
  //String randomizer function to create a random string to insure no two users get the same Session ID.
	function randomString() 
  {
	    var chars = "!0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz-";
			var string_length = 56;
			var s = '';
			for (var i=0; i<string_length; i++) 
      {
			    var rnum = Math.floor(Math.random() * chars.length);
					s += chars.substring(rnum,rnum+1);
			}
				
      return s;
	}
	
// used for endeca
function blurSearch(){
	if (document.endeca_search_form_one.SearchString.value==''){
		document.endeca_search_form_one.SearchString.value='Search';
	}
}
function focusSearch(){
	if (document.endeca_search_form_one.SearchString.value=='Search'){
		document.endeca_search_form_one.SearchString.value='';
	}
}


// used for saks bag overlay

var receiveReqNumItems;
var numItemsReturned;
var SaksBagImg;

function getNumberofItems(){
	receiveReqNumItems=getXmlHttpRequestObjectItems();
	loadNumItems();
}

function getObjItems(imgId){
	if(document.getElementById){
		return document.getElementById(imgId);
	}else if(document.getElementsByName){
		return document.getElementsByName(imgId);
	}else if(document.getElementsByTagName){
		return document.getElementsByTagName(imgId);
	}else if (document.all){
	   return document.all[imgId];
	}else{
		return false;
	}
}

function getXmlHttpRequestObjectItems() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest(); //Not IE
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP"); //IE
	} else {
		//alert("Your browser doesn't support AJAX.");
	}
}

//popup effects, fade in and expand
var sPath = window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
ie5  = (document.all && document.getElementById && (navigator.userAgent.indexOf("Opera") < 0));
ns6 = (!document.all && document.getElementById || (navigator.userAgent.indexOf("Opera") >= 0));
opac = 0;
if (sPage.indexOf("Entry")> -1){MyLeft=0}else{MyLeft=0}

var docTitle = document.title;
if (docTitle.indexOf("Payment method") > -1) {
	myTop=141;
} else if (docTitle.indexOf("Search Sale") > -1) {
	myTop=141;
} else if (docTitle.indexOf("elite_mastercard_apply") > -1) {
	myTop=410;
} else {
	myTop=141;
}

//popup slide in code. include name of layer and its height+1 pixle in the call
var myHeight=1;
var layerOpened = false;
function slideIn(wchLayer,lyrHght,lyrTop,lyrLeft){
/*	if (lyrLeft != null){
		document.getElementById(wchLayer).style.left = lyrLeft;
	}else{
		document.getElementById(wchLayer).style.left = MyLeft;
	}
	if (lyrTop != null){
		document.getElementById(wchLayer).style.top = lyrTop;
	}*/
	if (isIE) {HidePullDown();}
	myOpen(wchLayer,lyrHght);
}

function myOpen(wchLayer,lyrHght){
 	if(!layerOpened){
 		Effect.BlindDown(wchLayer, { duration: 1.5, afterFinish: blindDownLayerFinished  });
 	}
}

function slideOut(wchLayer){
	Effect.BlindUp(wchLayer, { duration: 1, afterFinish: blindUpLayerFinished  });
}

var blindDownLayerFinished = function(){
	layerOpened = true;
}

var blindUpLayerFinished = function(){
	layerOpened = false;
	if (isIE) {ShowPullDown();}
}

//end of slide in

//popup fade in. include name of layer
function fadeIn(wchLayer) {
	if (isIE) {HidePullDown();}
	if(opac != 100){
		opac+=4;
		if (ie5) document.getElementById(wchLayer).filters.alpha.opacity = opac;
		if (ie5) document.all[wchLayer].style.left = MyLeft;
		if (ie5) document.all[wchLayer].style.top = myTop;
		if (ns6) document.getElementById(wchLayer).style.MozOpacity = opac/100;
		if (ns6) document.getElementById(wchLayer).style.left = MyLeft;
		if (ns6) document.getElementById(wchLayer).style.top = myTop;
		setTimeout("fadeIn('"+wchLayer+"')", 25);
	}else{return;}
}

//find x for atribute driven banner (fix a safari issue called from btm nav)
function testMyX(obj){
obj=document.getElementById(obj);
var newY = findPos(obj);
document.getElementById('Layer1').style.left = newY[0];
}
//to place pop-up next to link that called it (mostly used for check-out)
function setLyr(obj,lyr)
{
	var newY = findPos(obj);
	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	if((sPage.indexOf("Entry")> -1) || (sPage.indexOf("wac2_bc")> -1) || (sPage.indexOf("incubator_bc")> -1)){HomePage = true;}else{HomePage = false;}
	if (!HomePage) newY[1] -= 300;
	var x = new getObj(lyr);
	x.style.top = newY[1] + 'px';
}
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];
}

function getObj(name)
{
 if (document.getElementById)
 {
	   this.obj = document.getElementById(name);
	   this.style = document.getElementById(name).style;
 }
 else if (document.all)
 {
	   this.obj = document.all[name];
	   this.style = document.all[name].style;
 }
 else if (document.layers)
 {
	   if (document.layers[name])
	   {
	   	this.obj = document.layers[name];
	   	this.style = document.layers[name];
	   }
	   else
	   {
	    this.obj = document.layers.testP.layers[name];
	    this.style = document.layers.testP.layers[name];
	   }
 }
}

function popupwin(url, width, height, name){
if(name==null||name==""){
	window.open(url,"saksPopup","width=" + width + ",height=" + height + ",toolbar=no,location=no,scrollbars=yes,resizable=yes,menubar=no,status=no");
}else{
	window.open(url,name,"width=" + width + ",height=" + height + ",toolbar=no,location=no,scrollbars=yes,resizable=yes,menubar=no,status=no");
}
}

function popupwinName(url, name, width, height){
	window.open(url,name,"width=" + width + ",height=" + height + ",toolbar=no,location=no,scrollbars=yes,resizable=yes,menubar=no,status=no");
}

function popupWinFixed(url, width, height){
 window.open(url,"saksPopup","width=" + width + ",height=" + height + ",toolbar=no,location=no,scrollbars=no,resizable=no,menubar=no,status=no");
}

function popupWinFixed2(url, width, height, name){
	if(name==null||name==""){
 		window.open(url,"saksPopup","width=" + width + ",height=" + height + ",toolbar=no,location=no,scrollbars=no,resizable=no,menubar=no,status=no");
 	} else {
 		window.open(url,name,"width=" + width + ",height=" + height + ",toolbar=no,location=no,scrollbars=no,resizable=no,menubar=no,status=no"); 
 	}
}

function chooseAndGo(myDropdown){
	if(myDropdown.options[myDropdown.selectedIndex].value){
		location.href = myDropdown.options[myDropdown.selectedIndex].value;
	}
	else{
		myDropdown.selectedIndex = 0;
	}
}


