var cookieStr=getCookie('attPersistantLocalization');
//window.alert("att cookie: "+cookieStr);
// goToCityState cookie if "yes" overrides the personlaizaiton cookie
// and causes the city/state page to appear
//this cookie is set to "yes" if the user clicks "change" on one of the marketing pages.
var goToCityState=getCookie('goToCityState');
var xmlDoc = "";
stateAbbrev=new Array();
stateAbbrev['Alabama']="AL";
stateAbbrev['Florida']="FL";
stateAbbrev['Georgia']="GA";
stateAbbrev['Kentucky']="KY";
stateAbbrev['Louisiana']="LA";
stateAbbrev['Mississippi']="MS";
stateAbbrev['North Carolina']="NC";
stateAbbrev['South Carolina']="SC";
stateAbbrev['Tennessee']="TN";
//cookie stuff
var expires = "";
var path ="/";

if (currURL.indexOf('iocteamsite.bls.com') > -1) {
var BSdomain = ".bls.com";
} else if (currURL.indexOf('localhost') > -1) {
var BSdomain = "";
} 
else if (currURL.indexOf('ourbellsouth.com') > -1) {
var BSdomain = ".ourbellsouth.com";
}
else if (currURL.indexOf('90.106.3.109') > -1) {
var BSdomain = "90.106.3.109";
} else {
var BSdomain = ".bellsouth.com";
}
var secure = "";
var cookiestuff = ((expires) ? "; expires=" + expires.toGMTString() : "") +
  ((path) ? "; path=" + path : "") +
  ((BSdomain) ? "; domain=" + BSdomain : "") +
  ((secure) ? "; secure" : "");
if (cookieStr!=null)
{
    if ((goToCityState==null) || (goToCityState=="") || (goToCityState=="no")) 
    {
	var cltState="";
	var cltCity="";
	var cltNode="";
	//window.alert("clt cookie: "+cookieStr);
	re=/state=(.+?)(\||$)/;
	if (re.test(cookieStr))
	{
	    cltState=RegExp.$1;
	    if ((cltState!=null)&&(cltState!=""))
	    {
		if ((stateAbbrev[cltState]!=null)&&(stateAbbrev[cltState]!=""))
		{
		   cltState=stateAbbrev[cltState];
		}
		else
		{
		    cltState="";
		}
	    } 
	}//test        
	if ((cltState!=null)&&(cltState!=""))
	{
	   re=/city=(.+?)(\||$)/;        
	   if (re.test(cookieStr))
	   {
		cltCity=RegExp.$1; 
	   }       
	    //name kludges
	   //window.alert("cltState: "+cltState+"  cltCity: "+cltCity);
	   //get nodenumber
	   loadXmlDocument("/consumer/xml/" + cltState + ".xml", getCLTData);
	} //city test
    }//goToCityState
    else
    {
	//goToCityState==yes citystate cookie was wiped out when we set thias cookie and refreshed page in city_state var in popProducts.js
	//set to "no" for future visits
	setChangeLocale('no');
    }
}//cookies    	
function getCLTData()
{
    var hit=false;
    citiesList = xmlDoc.getElementsByTagName("city");
    for (var x=0;x<citiesList.length;x++)
    {
	var tCity = citiesList[x].getElementsByTagName("cityname")[0].firstChild.nodeValue;
	//window.alert(tCity+":"+cltCity);
	if (tCity==cltCity)
	{
	    hit=true;
	    cltNode=citiesList[x].getElementsByTagName("nodenumber")[0].firstChild.nodeValue;
	    setCityState(cltNode, cltState, cltCity)
	    //window.alert(tCity+":"+cltState+":"+cltNode);
	    break;
	}
    }
    if (!hit)
    {
	    cltNode=citiesList.length-1;
	    setCityState(cltNode, cltState, 'Other')
	    //window.alert("Other:"+cltState+":"+cltNode);
    }
}
function setCityState(citystate_node, citystate_state, citystate_city)
{
    var cltCityState_string = "";
    cltCityState_string = cltCityState_string + "xxx" + citystate_node + "xxx" + citystate_state + "xxx" + citystate_city;
    document.cookie = "citystate=" + escape(cltCityState_string) + cookiestuff;
}
function setChangeLocale(tType)
{
    //type is 'yes' or 'no'
    document.cookie = "goToCityState=" + escape(tType) + cookiestuff;
}
