var expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
 
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
 if (document.cookie.substring(i, j) == arg)//cookie exists
  return getCookieVal (j);
  i = document.cookie.indexOf(" ", i) + 1;//cookie doesn't exist
  if (i == 0) break;
 }
return null;
}

function SetCookie (name, value) {

 if(document.getElementById("rememberLocation").checked==1){
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;//required extra param
	var path = (argc > 3) ? argv[3] : null;//extra param
	var domain = (argc > 4) ? argv[4] : null;//extra param
	var secure = (argc > 5) ? argv[5] : false;//extra param
	if(value!="0"){//if not choose location option
		//create cookie
		document.cookie = name + "=" + escape(value) +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
	}
 }
 if(value!="0"){
	if(value=="edina"||value=="minnetonka"||value=="paul"){//add check for other locations here
		window.location.href = "http://www.breadsmithmn.com";
	}else{
		window.location.href ="locations/"+value+".html";
	}
 }
}

function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
 
var favorite = GetCookie('location');//on page load, get cookie if it exists

if (favorite != null) {
switch (favorite) {
case 'edina' :  url = 'http://www.breadsmithmn.com'; //add other locations here
   break;
case 'mesa' :  url = 'http://www.breadsmith.com/locations/mesa.html';
  break;
case 'highlandpark' : url = 'http://www.breadsmith.com/locations/highlandpark.html';
  break;
case 'lombard' : url = 'http://www.breadsmith.com/locations/lombard.html';
  break;
case 'palosheight' :  url = 'http://www.breadsmith.com/locations/palosheights.html';
  break;
case 'skokie' : url = 'http://www.breadsmith.com/locations/skokie.html';
  break;
case 'stcharles' : url = 'http://www.breadsmith.com/locations/stcharles.html';
  break;
case 'indianapolis' : url = 'http://www.breadsmith.com/locations/indianapolis.html';
  break;
case 'southbend' :  url = 'http://www.breadsmith.com/locations/southbend.html';
  break;
case 'potomac' :  url = 'http://www.breadsmith.com/locations/potomac.html';
  break;
case 'birmingham' :  url = 'http://www.breadsmith.com/locations/birmingham.html';
  break;
case 'bloomfieldhills' : url = 'http://www.breadsmith.com/locations/bloomfieldhills.html';
  break;
case 'grossepointe' : url = 'http://www.breadsmith.com/locations/grossepointe.html';
  break;
case 'livonia' : url = 'http://www.breadsmith.com/locations/livonia.html';
  break;
case 'okemos' :  url = 'http://www.breadsmith.com/locations/okemos.html';
  break;
case 'minnetonka' : url = 'http://www.breadsmithmn.com';
  break;
case 'paul' : url = 'http://www.breadsmithmn.com';
  break;
case 'springfield' : url = 'http://www.breadsmith.com/locations/springfield.html';
  break;
case 'stlouis' :  url = 'http://www.breadsmith.com/locations/stlouis.html';
  break;
case 'cranford' : url = 'http://www.breadsmith.com/locations/cranford.html';
  break;
case 'fargo' : url = 'http://www.breadsmith.com/locations/fargo.html';
  break;
case 'fairlawn' :  url = 'http://www.breadsmith.com/locations/fairlawn.html';
  break;
case 'lakewood' : url = 'http://www.breadsmith.com/locations/lakewood.html';
  break;
case 'fortmill' : url = 'http://www.breadsmith.com/locations/fortmill.html';
  break;
case 'siouxfalls' : url = 'http://www.breadsmith.com/locations/siouxfalls.html';
  break;
case 'siouxfallswest' : url = 'http://www.breadsmith.com/locations/siouxfallswest.html';
  break;
case 'mcallen' :  url = 'http://www.breadsmith.com/locations/mcallen.html';
  break;
case 'appleton' : url = 'http://www.breadsmith.com/locations/appleton.html';
  break;
case 'appletoneast' : url = 'http://www.breadsmith.com/locations/appletoneast.html';
  break;
case 'greenbay' : url = ' 	http://www.breadsmith.com/locations/greenbay.html';
  break;
case 'greenfield' : url = 'http://www.breadsmith.com/locations/greenfield.html';
  break;
case 'milwaukee' :  url = 'http://www.breadsmith.com/locations/milwaukee.html';
 break;
case 'milwaukeepublicmarket' :  url = 'http://www.breadsmith.com/locations/milwaukeepublicmarket.html';
 break;
case 'wauwatosa' : url = 'http://www.breadsmith.com/locations/wauwatosa.html';
  break;
case 'whitefishbay' : url = 'http://www.breadsmith.com/locations/whitefishbay.html';
  break;
}
window.location.href = url;

}

