var xmlHttp;
function orgin(O)
{
  O = O.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+O+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
	return "";
  else
    return results[1];
}


function showSpecial(str)
{ 
var spinWheel = '<div style="position:relative; left:250px; padding-bottom:10px;"><img src="/images/spin-wheel-WS.gif" border="0"/></div>';
document.getElementById("price-frame").innerHTML = spinWheel; 

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/shopping/webspecials/ScrollPostCity.aspx";
url=url+"?q="+str;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged() 
{
if (xmlHttp.readyState==4)
{ 
document.getElementById("price-frame").innerHTML=xmlHttp.responseText
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function showUniqueCities()
{
		var selectObject = document.getElementById("_webSpecialCityList");
		var uniqueList = "";
		for (var i = 0; i < selectObject.options.length; i++) 
		{
			var curOption = selectObject.options[i].value;
			if(uniqueList.indexOf(curOption) < 0)
			{
				uniqueList = uniqueList + "|" + curOption + "|";
			}
			else{				
				selectObject.remove(i);
				i--;
			}	
		}		
		showUpdateInformation();		
}

function showUpdateInformation()
{
	document.getElementById("_lastUpdatedDateInfo").innerHTML=document.getElementById("_lastUpdatedDate").innerHTML;
}


function CheckCityExists(cityName)
{
		cityName = cityName.replace("%20", " ");
		var selectObject = document.getElementById("_webSpecialCityList");
		var uniqueList = "";
		for (var i = 0; i < selectObject.options.length; i++) 
		{
			var curOption = selectObject.options[i].value;			
			if(curOption == cityName)
			{				
				return true;				
			}			
		}		
		return false;
}

function showEm()
{	
	showUniqueCities();		
	var O_city = orgin('q');
	if (O_city !="" && CheckCityExists(O_city))
	{ 	
		showSpecial(O_city);
	}		
}