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)
    return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}

function SetCookie (name, value) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
   ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
   ((path == null) ? "" : ("; path=" + path)) +
   ((domain == null) ? "" : ("; domain=" + domain)) +
   ((secure == true) ? "; secure" : "");
}

function show_count() {
  var expdate = new Date();
  var num;
  expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 31));
  if(!(num = GetCookie("kennycount")))
  num = 0;
  num++;
  SetCookie ("kennycount", num, expdate);
  if (num == 1) document.write("Since this is the first time you have been here, please take a moment to look around.");
  else document.write("You have been here " + num + " times.");
}

function auto_show_name() {
  if(GetCookie("kennymarchant") != null)
    switch (GetCookie('kennymarchant')) {
	case "Bedford": 	document.getElementById("banner").style.backgroundImage = 'url(images/bedford.jpg)';
		break;
	case "Carrollton":	document.getElementById("banner").style.backgroundImage = 'url(images/carrollton.jpg)';
		break;
	case "CedarHill":	document.getElementById("banner").style.backgroundImage = 'url(images/banner_image.jpg)';
		break;
	case "Colleyville":	document.getElementById("banner").style.backgroundImage = 'url(images/colleyville.jpg)';
		break;
	case "Coppell":		document.getElementById("banner").style.backgroundImage = 'url(images/coppell.jpg)';
		break;
	case "Duncanville":	document.getElementById("banner").style.backgroundImage = 'url(images/duncanville.jpg)';
		break;
	case "Euless":		document.getElementById("banner").style.backgroundImage = 'url(images/banner_image.jpg)';
		break;
	case "FarmersBranch":	document.getElementById("banner").style.backgroundImage = 'url(images/farmersbranch.jpg)';
		break;
	case "GrandPrairie":	document.getElementById("banner").style.backgroundImage = 'url(images/grandprairie.jpg)';
		break;
	case "Grapevine":	document.getElementById("banner").style.backgroundImage = 'url(images/cowboysgolf.jpg)';
		break;
	case "Hurst":		document.getElementById("banner").style.backgroundImage = 'url(images/bedford.jpg)';
		break;
	case "Irving":		document.getElementById("banner").style.backgroundImage = 'url(images/irving.jpg)';
		break;
	case "Lewisville":	document.getElementById("banner").style.backgroundImage = 'url(images/lewisville.jpg)';
		break;
	case "Southlake":	document.getElementById("banner").style.backgroundImage = 'url(images/southlake.jpg)';
		break;
		default: break;
    }
  else {
  	document.getElementById("banner").style.backgroundImage = 'url(images/banner_image.jpg)';
	window.open('selectcity.html',"Select_City","menubar=no,location=no,resizable=no,scrollbars=no,status=no,width=320,height=240");
  }
}

function set_name(form) {
  var expdate = new Date ();
  expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 31));
  var username = form.nameinput.value
  if (username != "") {
    if (confirm("Are you sure you want this saved as your city?")) {
      SetCookie ("kennymarchant", username, expdate);
	  opener.location=('index.shtml')
      window.close();
    }
  } else { SetCookie ("kennymarchant", username, expdate); window.close(); }
}
