// Toggle the store (filter) open + closed
function toggle(id){
	if (document.all){
		if(document.all[id].style.display == 'none'){
			document.all[id].style.display = '';
		} else {
			document.all[id].style.display = 'none';
		}
	return false;
	} else if (document.getElementById){
		if(document.getElementById(id).style.display == 'none'){
			document.getElementById(id).style.display = 'block';
		} else {
			document.getElementById(id).style.display = 'none';
		}
	return false;
	}
}


var xmlHttp
var xmlHttp2
var loadingImage="<img src='loading.gif' /> Requesting content..."

function showUser() { 
	// Get the current values of the two select boxes; city and distance (position values, not text values)
	var pre_str = document.getElementById("city")
	var pre_dis = document.getElementById("distance")
	
	//get the index value of the selected items, these will be converted by php later
	//these should be global vars
	str = pre_str.selectedIndex;
	dis = pre_dis.selectedIndex;	
/*	
	switch (str) {
		case "Bakersfield":
		break;
		case "Fresno":
		break;
		case "Los Angeles":
		break;	
		case "Sacramento":
		break;
		case "San Diego":
		break;
		case "San Francisco":
		pan_lat = 37.774200;
		pan_lon = -122.417068;
		break;
		case "San Jose":
		pan_lat = 37.340382;
		pan_lon = -121.892181;
		break;
		case "Santa Barbara":
		break;
	}
*/
	
	xmlHttp=GetXmlHttpObject()
	
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	//var url="getuser.php"
	
	/*
	if (dis) {
		var dist=dis;
	}
	else {
		var dist=2; // 2 is the default radius of 10
	}
	*/
	
	// why?
	// why not
	var dist=dis;
	
	// send the request with the city and distance (index values still)
	var url="getStoreRadius.php"
	url=url+"?q="+str
	url=url+"&dis="+dist
	url=url+"&sid="+Math.random() //session id
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	
	// pause to make sure xml file has been constructed
	setTimeout("loadPoints(str,dis);",1500); 
}

function loadFeed(str) { 
	
	//toggle('livefeed');
	
	xmlHttp2=GetXmlHttpObject2()
	
	if (xmlHttp2==null) {
		alert ("Browser does not support HTTP Request")
		return
	} 
		
	document.getElementById("livefeed").innerHTML=loadingImage
	
	var url="getFeed.php"
	url=url+"?q="+str
	//url=url+"&sid="+Math.random() //session id
	xmlHttp2.onreadystatechange=stateChanged2 
	xmlHttp2.open("GET",url,true)
	xmlHttp2.send(null)
}

function stateChanged2() { 
	if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete") { 
		document.getElementById("livefeed").innerHTML=xmlHttp2.responseText 
	} 
}
function stateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		//document.getElementById("ajaxme").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 GetXmlHttpObject2() {
	var xmlHttp2=null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp2=new XMLHttpRequest();
	}
	catch (e) {
		//Internet Explorer
		try {
			xmlHttp2=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
return xmlHttp2;
}

 
