// MAIN.JS VERSION 1/28/2004 9:00am

 // NON-FUNCTION SCRIPTS

 dom = document.getElementById ? true:false;
 nn4 = document.layers ? true:false;
 ie4 = document.all ? true:false;
 openMenu=false;
 menuItem=false;

 // DETECT SERVER AND SET ROOTDIR
 //if(location.href.indexOf('/servlet/portal/serve/content/public/')!=-1)
 //{rootDir = "/servlet/portal/serve/content/public";} else {rootDir = "";}
var rootDir = "";

 // PRELOAD ACTIVE IMAGES
 img0active = new Image();
 img0active.src = rootDir+"/site_files/nav/images/save-active.gif";
 img1active = new Image();
 img1active.src = rootDir+"/site_files/nav/images/create-active.gif";
 img2active = new Image();
 img2active.src = rootDir+"/site_files/nav/images/browse-active.gif";
 img3active = new Image();
 img3active.src = rootDir+"/site_files/nav/images/learn-active.gif";

 //PRELOAD MENU BACKGROUNDS
 menu0bg = new Image();
 menu0bg.src = rootDir+"/site_files/nav/images/bg-save.gif";
 menu1bg = new Image();
 menu1bg.src = rootDir+"/site_files/nav/images/bg-create.gif";
 menu2bg = new Image();
 menu2bg.src = rootDir+"/site_files/nav/images/bg-browse.gif";
 menu3bg = new Image();
 menu3bg.src = rootDir+"/site_files/nav/images/bg-learn.gif";

 // FUNCTIONS

  // ONLOAD FUNCTION
  function ourPageLoad(){
   //confirmPortalPathContent();
   wtsession();

   // PRELOAD TOOLBAR ROLLOVER IMAGES
   MM_preloadImages(rootDir+'/site_files/toolbar/common_images/TOOLBAR-Store-On.gif',rootDir+'/site_files/toolbar/common_images/TOOLBAR-Rewards-On.gif',rootDir+'/site_files/toolbar/common_images/TOOLBAR-Website-On.gif',rootDir+'/site_files/toolbar/common_images/TOOLBAR-About-On.gif',rootDir+'/site_files/toolbar/common_images/TOOLBAR-Contact-On.gif',rootDir+'/site_files/toolbar/common_images/TOOLBAR-Search1-On.gif');

}


  // CHECK THE DOCUMENT.ALL METHOD IN NS6
  function toggleIt(xobj, onoff) {
   if (onoff) {
    if (onoff == "on"){turnOn = true;}
    else {turnOn = false;}
    if (dom) {
     if(turnOn){document.getElementById(xobj).style.display="";}
     else{document.getElementById(xobj).style.display="none";
    }
   }
   else if (ie4) {
    if (turnOn) {document.all[xobj].style.display = "";}
    else {document.all[xobj].style.display = "none";}
   }
   } else if (dom) {
    if (document.getElementById(xobj).style.display=="none"){document.getElementById(xobj).style.display = "";}
    else {document.getElementById(xobj).style.display = "none";}
   }
   else if (ie4) {
    if (document.all[xobj].style.display=="none"){document.all[xobj].style.display = "";}
    else {document.all[xobj].style.display = "none";}
   }
  }


  function styleChange(id, newClass) {
   if (document.getElementById||document.all) {
    if (document.getElementById) {identity=document.getElementById(id);}
    else if (document.all) {identity=document.all[id];}
    identity.className=newClass;
   }
  }


  function headswap (xobj) {
   lgwidth = 246;
   lgheight = 61;
   if (xobj==0) {
    document.img0.src = rootDir+"/site_files/nav/images/save-active.gif";
    document.img0.height = lgheight;
    document.img0.width = lgwidth;
    document.img0sub0.src = rootDir+"/site_files/nav/images/save_online_circular_act.gif";
    document.img0sub1.src = rootDir+"/site_files/nav/images/save_promotions_act.gif";
    document.img0sub2.src = rootDir+"/site_files/nav/images/save_rewards_central_act.gif";		
	document.img0sub3.src = rootDir+"/site_files/nav/images/save_online_coupons_act.gif";		
   }
   if (xobj==1) {
    document.img1.src = rootDir+"/site_files/nav/images/create-active.gif";
    document.img1.height = lgheight;
    document.img1.width = lgwidth;
    document.img1sub0.src = rootDir+"/site_files/nav/images/create_services_act.gif";
    document.img1sub1.src = rootDir+"/site_files/nav/images/create_your_party_guide_act.gif";
    document.img1sub2.src = rootDir+"/site_files/nav/images/create_cook_act.gif";
    document.img1sub3.src = rootDir+"/site_files/nav/images/create_bunches_of_fun_act.gif";
   }
   if (xobj==2) {
    document.img2.src = rootDir+"/site_files/nav/images/browse-active.gif";
    document.img2.height = lgheight;
    document.img2.width = lgwidth;
    document.img2sub0.src = rootDir+"/site_files/nav/images/browse_departments_act.gif";
	document.img2sub1.src = rootDir+"/site_files/nav/images/browse_own_brand_act.gif";
	document.img2sub2.src = rootDir+"/site_files/nav/images/browse_produce_act.gif";
    document.img2sub3.src = rootDir+"/site_files/nav/images/browse_wild_harvest_act.gif";
	document.img2sub4.src = rootDir+"/site_files/nav/images/browse_osco_pharmacy_act.gif";
   }
   if (xobj==3) {
    document.img3.src = rootDir+"/site_files/nav/images/learn-active.gif";
    document.img3.height = lgheight;
    document.img3.width = lgwidth;
    document.img3sub0.src = rootDir+"/site_files/nav/images/learn_ducklings_act.gif";
    document.img3sub1.src = rootDir+"/site_files/nav/images/learn_shaws_wellbeing_act.gif";
    document.img3sub2.src = rootDir+"/site_files/nav/images/learn_community_act.gif";
    document.img3sub3.src = rootDir+"/site_files/nav/images/learn_environment_act.gif";
    document.bottombar.src = rootDir+"/site_files/nav/images/spacer.gif";
    document.bottombar.height = 1;
   }
   styleChange(xobj+"bg", "bg"+xobj);
   return false;
}


  function menufy(xobj) {
   for (q=0;q<4;q++) {
    menu = q+"menu";
    toggleIt(menu, "off");
   }
   toggleIt(xobj, "on");
   if (xobj=="3menu") {toggleIt("bottombar", "off");} else {toggleIt("bottombar", "on");}
  }

  function itemify(iobj) {
   styleChange(iobj, "active");
  }


  function MM_preloadImages() { //v3.0
   var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
  }

  function MM_swapImgRestore() { //v3.0
   var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  }

  function MM_findObj(n, d) { //v4.01
   var p,i,x;
   if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length)
   {d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
   if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
   for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
   if(!x && d.getElementById) x=d.getElementById(n); return x;
  }

  function MM_swapImage() { //v3.0
   var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
  }


  function MM_openBrWindow(theURL,winName,features) { //v2.0
   window.open(theURL,winName,features);
  }


  function checkEmail (frmnum) {
   if (document.forms[frmnum].txtEmail.value != document.forms[frmnum].txtConfirmEmail.value) {
    alert('The two email addresses you have entered do not match');
    document.forms[frmnum].txtConfirmEmail.value = "";
    return false;
   } else {
    return true;
   }
  }


  //OUTBOUND LINKS
  function outbound(url,description,messagetype,windowtype){
   if(!url || !description){alert("This link is not configured properly. Please notify shaws.webmaster@supervalu.com");return;}
   if(!messagetype){var messagetype=1;}
   var messageparttwo = "";
   var ourmessage = "";
   if(description=='for our vendors'){description = 'svHarbor';messagetype=1};
   if(messagetype==1){messageparttwo="The " + description + " site is not a Shaw\'s Supermarket site. Your use of the " + description + " web site is governed by its own terms and conditions and privacy policy, if any, and Shaw\'s is not responsible for this web site or any personal information collected by it.";}
   if(messagetype==2){messageparttwo="This is also a Shaw\'s Supermarkets site, but has different terms, conditions and policies than www.shaws.com. Please review the policies for " + description + " upon visiting the site.";}
   
   ourmessage="You have requested to leave www.shaws.com, and enter the " + description + " web site.\n\n" + messageparttwo + "\n\nClick OK to go to "+description +" web site.\n\nClick Cancel to stay on the Shaw\'s web site.";
   var go = confirm(ourmessage);
   if(go){
	   if(windowtype=='new') {
	  	window.open(url)
	   }else {
		location.href=url;
		}	
	}		
}

 function inbound(url,description,messagetype,windowtype){
   if(!url || !description){alert("This link is not configured properly. Please notify shaws.webmaster@supervalu.com");return;}
   if(!messagetype){var messagetype=1;}
   var messageparttwo = "";
   var ourmessage = "";
   if(description=='for our vendors'){description = 'svHarbor';messagetype=1};
   
   
   if(messagetype==3){messageparttwo="The Upromise site  is not a Shaw\'s Supermarket site. Your use of the Upromise web site is governed by its own terms and conditions and privacy policy, if any, and Shaw\'s is not responsible for this web site or any personal information collected by it.";}
   ourmessage="You have requested to leave www.shaws.com, and enter the Upromise web site.\n\n" + messageparttwo + "\n\nClick OK to go to Upromiseweb web site.\n\nClick Cancel to stay on the Shaw\'s web site.";
   var go = confirm(ourmessage);
   if(go){
	   if(windowtype=='new') {
	  	window.open(url)
	   }else {
		location.href=url;
		}	
	}		
}

//ADOBE AIR
 function outbound1(url,description,messagetype,windowtype){
   if(!url || !description){alert("This link is not configured properly. Please notify shaws.webmaster@supervalu.com");return;}
   if(!messagetype){var messagetype=1;}
   var messageparttwo = "";
   var ourmessage = "";
   if(description=='Adobe air '){description = 'Adobe air';messagetype=1};
   if(messagetype==1){messageparttwo="The " + description + " site is not a Shaw\'s Supermarket site. Your use of the " + description + " web site is governed by its own terms and conditions and privacy policy, if any, and Shaw\'s is not responsible for this web site or any personal information collected by it.";}
   if(messagetype==2){messageparttwo="This is also a Shaw\'s Supermarkets site, but has different terms, conditions and policies than www.shaws.com. Please review the policies for " + description + " upon visiting the site.";}
   ourmessage="Enter the " + description + " web site.\n\n" + messageparttwo + "\n\nClick OK to go to "+description +" web site.\n\nClick Cancel to stay on the Shaw\'s web site.";
   var go = confirm(ourmessage);
   if(go){
	   if(windowtype=='new') {
	  	window.open(url)
	   }else {
		location.href=url;
		}	
	}		
}

//SAVE MORE
 function outbound2(url,description,messagetype,windowtype){
   if(!url || !description){alert("This link is not configured properly. Please notify shaws.webmaster@supervalu.com");return;}
   if(!messagetype){var messagetype=1;}
   var messageparttwo = "";
   var ourmessage = "";
   if(description=='Save more '){description = 'Save more';messagetype=1};
   if(messagetype==1){messageparttwo="The " + description + " site is not a Shaw\'s Supermarket site. Your use of the " + description + " web site is governed by its own terms and conditions and privacy policy, if any, and Shaw\'s is not responsible for this web site or any personal information collected by it.";}
   if(messagetype==2){messageparttwo="This is also a Shaw\'s Supermarkets site, but has different terms, conditions and policies than www.shaws.com. Please review the policies for " + description + " upon visiting the site.";}
   ourmessage="Enter the " + description + " web site.\n\n" + messageparttwo + "\n\nClick OK to go to "+description +" web site.\n\nClick Cancel to stay on the Shaw\'s web site.";
   var go = confirm(ourmessage);
   if(go){
	   if(windowtype=='new') {
	  	window.open(url)
	   }else {
		location.href=url;
		}	
	}		
}



  function outbound2(url,description,messagetype,windowtype){

   if(!url || !description){alert("This link is not configured properly. Please notify shaws.webmaster@supervalu.com");return;}
   if(!messagetype){var messagetype=1;}
   var messageparttwo = "";
   var ourmessage = "";
  if(description=='for our vendors'){description = 'svHarbor';messagetype=1};
   if(messagetype==1){messageparttwo="The " + description + " site is not a Shaw\'s Supermarket site. Your use of the " + description + " web site is governed by its own terms and conditions and privacy policy, if any, and Shaw\'s is not responsible for this web site or any personal information collected by it.";}
   if(messagetype==2){messageparttwo="This is also a Shaw\'s Supermarkets site, but has different terms, conditions and policies than www.shaws.com. Please review the policies for " + description + " upon visiting the site.";}
   ourmessage="You have requested to leave www.shaws.com, and enter the " + description + " web site.\n\n" + messageparttwo + "\n\nClick OK to go to the "+description +" web site.\n\nClick Cancel to stay on the Shaw\'s web site.";
   var go = confirm(ourmessage);
   if(go){
	   if(windowtype=='new') {
	  	window.open(url)
	   }else {
		location.href=url;
		}	
	}
	else{
//			 window.alert('this is -1 page ' + history.go(-1));
//	 window.alert('Hi');	
   window.alert('location.href ' + location.href);	
   window.alert('window.location.pathname ' + location.pathname);	 
   window.alert('window.location.hostname ' + location.hostname);	  //this returns sol1.shaws.com 
   window.alert('window.location.host ' + location.host);	 
//	 window.alert(location.href());		 
/*	 window.alert('window.location.pathname ' + location.pathname());		 
   window.alert('window.location.hostname ' + location.hostname());	
	 window.alert('window.location.host ' + location.host());	
	 */
	 

	 //window.alert('this is -1 page ' + history.go(-1);
	 //window.alert('this is -2 page ' + history.go(-2);	
//	 window.alert('this is -3 page ' + history.go(-3);													 													 
		//window.close();
		location.href='http://'+location.hostname;		
	}
}



  function getstoreinfo(storenum){

   location.href='/pages/toolbar/storeLocator.php?storeNum='+storenum;			
  }


  // session id 
  function wtsession(){
   if(getCookie("WTID")){
    return;
   } else {
    var cval1 = Math.round(Math.random()*999999);
    var today = new Date();
    var hh = today.getHours();
    var mm = today.getMinutes();
    var ss = today.getSeconds();
    var cval = cval1.toString() + "-" + hh.toString() + mm.toString() + ss.toString();
    var expiry = new Date(today.getYear()+1900, today.getMonth(), today.getDate()+30);
    expiry = expiry.toGMTString();
    setCookie("WTID", cval, expiry, "/", ".shaws.com");
   }
  }	


  function setCookie(name, value, expires, path, domain, secure) {
   document.cookie = name + "=" + escape(value) +
  ((expires == null) ? "" : "; expires=" + expires) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}

  function getCookie(name){
   var cname = name + "=";
   var dc = document.cookie;
   if (dc.length > 0) {
    begin = dc.indexOf(cname);
    if (begin != -1) {
     begin += cname.length;
     end = dc.indexOf(";", begin);
     if (end == -1) end = dc.length;
      return unescape(dc.substring(begin, end));
     }
    }
   return false;
  }


  // POINT TO PORTAL 1/28/2004
function confirmPortalPathContent() {
   baseHref="/servlet/portal/serve/content/public/";
   protocal="://";
   protocalStr=location.href.substring(0,location.href.indexOf(protocal)+protocal.length);
   locStr=location.href;
   locStr=locStr.substring(location.href.indexOf(protocal)+protocal.length, locStr.length);
   if (locStr.indexOf("/") != -1) {
    locStr=locStr.substring(0,locStr.indexOf("/"));
   }
   locStr=protocalStr+locStr;
   if ( location.href.indexOf(baseHref) == -1 ) {
    for (i=0;i<document.links.length;i++){
     linkVal=document.links[i].href;
     if (linkVal.indexOf("?norewrite")!=-1 || linkVal.indexOf("&norewrite")!=-1) {
     } else if (linkVal.indexOf(locStr)!=-1) {
      document.links[i].href=locStr+baseHref+linkVal.substring(locStr.length+1,linkVal.length);
     }
    }
   }
  }