// Check for existing Cookies & Redirect, Otherwise Choose Location

// *** get COOKIE *********************
function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return "";
}		


// *** SET COOKIE *********************
function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
//alert(cookie_string);
  document.cookie = cookie_string;
}


// *** CHECK COOKIE *********************
function checkCookie()
{
	var current_page = window.location.href;
	//alert(current_page);
	if (current_page == "http://www.westmancom.com/index.php?id=381")
	{
		resetCookie();
	}
	else
	{
		var the_city=get_cookie('city');
		//alert (the_city);

		// returning user who already has a city set
		if (the_city!=null && the_city!="")
		{
			// alert('Welcome again '+the_city+'!');
			window.location = "http://" + the_city + ".westmancom.com/";
			//window.location = "file:///E:/Documents/Desktop/" + the_city + ".html";
		}	// end if
		else
		{
			// new user -> present city options
			showDiv('city_list');
		}	// end else
	}	// end else
}

// *** RESET COOKIE *************************
function resetCookie()
{
	// returning user who wants to change their city

	// erase any exisitng cookies 
	set_cookie('city',"",-1);

	// present city options
	showDiv('city_list');
}


// *** CHOOSE CITY *********************
function showDiv(id) 
{
	//safe function to show an element with a specified id
		  
	if (document.getElementById) 
	{ 	// DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
		//document.getElementById(id).style.height = 800;
		//document.getElementById(id).style.lineHeight = 1;
	}
	else 
	{
		if (document.layers) 
		{ 	// Netscape 4
			document.city.id.display = 'block';
			//document.city.id.height = 800;
			//document.city.id.lineHeight = 1;
		}
		else 
		{ 	// IE 4, 
			document.all.city_list.style.display = 'block';
			//document.all.city_list.style.height = 800;
			//document.all.city_list.style.lineHeight = 1;			
		}
	}
}
