//AJAX for the venue info
function getVenueInfo(link, venueID) {
	//hold the right side td as a variable for easy access;
	var right_side = document.getElementById("right_side");

	//set the link that was clicked to current
	clearClasses();
	link.className = "current";

	if(!xmlHttp){
		var xmlHttp;
		try {
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		}
		catch (e) {
			// Internet Explorer
			try {
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					//alert("Your browser does not support AJAX!");
					return true;
				}
			}
		}
	}
	
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			//print out the response
			right_side.innerHTML = xmlHttp.responseText;
			
		} else if(xmlHttp.readyState==1){
			right_side.innerHTML="<h3>loading venue info</h3>";
		}
	}
    
	xmlHttp.open("GET","get_venue_info2.php?venueID="+venueID,true);
    xmlHttp.send(null);
	return false;
}


//AJAX for the venue by sports
function getVenueBySport(link, typeID) {

	//close the sub menu that is currently open or return true to fire the href
	if(!closeSubs(document.getElementById('sub'))){
		return true;
	}

	//set the link that was clicked to current
	clearClasses();
	link.className = "current";

	if(!xmlHttp){
		var xmlHttp;
		try {
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		}
		catch (e) {
			// Internet Explorer
			try {
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					//alert("Your browser does not support AJAX!");
					return true;
				}
			}
		}
	}
	
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			//print out the response
			link.parentNode.innerHTML += xmlHttp.responseText;
			//alert(xmlHttp.responseText);
			
		} else if(xmlHttp.readyState==1){
			
		}
	}
    
	xmlHttp.open("GET","get_venues_by_sport.php?typeID="+typeID,true);
    xmlHttp.send(null);
	return false;
}

//ajax searchable venues by keyword
function searchVenuesByKeyword(){
	if(!xmlHttp){
		var xmlHttp;
		try {
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		}
		catch (e) {
			// Internet Explorer
			try {
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					alert("Your browser does not support AJAX!");
					return true;
				}
			}
		}
	}
	
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			venue_names.innerHTML = "";
			venue_names.innerHTML = xmlHttp.responseText;

			//var response = window.open('','responsed');
			//response.document.write(xmlHttp.responseText);
			
		} else if(xmlHttp.readyState==1){
			venue_names.innerHTML = "<li>searching the database for matching venues, please wait</li>";
		}
	}
    
	var keyword = document.getElementById('keyword_search').value;
	var venue_names = document.getElementById('venue_names');

	if(keyword==""){
		alert("You must enter a search term");
		return true;
	}

	xmlHttp.open("GET","get_venues_by_search.php?keyword="+keyword,true);
    xmlHttp.send(null);
	return false;
}

//ajax searchable venues by venueType
function searchVenuesByType(myForm){
	if(!xmlHttp){
		var xmlHttp;
		try {
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		}
		catch (e) {
			// Internet Explorer
			try {
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					//alert("Your browser does not support AJAX!");
					return true;
				}
			}
		}
	}
	
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			venue_names.innerHTML = xmlHttp.responseText;
			
		} else if(xmlHttp.readyState==1){
			venue_names.innerHTML = "<li>searching the database for matching venues, please wait</li>";
		}
	}
    
	//get all the checked box
	var inputs = myForm.elements; //or document.forms[0].elements;
	var checked = []; //will contain all checked checkboxes
	for (var i = 0; i < inputs.length; i++) {
	  if (inputs[i].type == "checkbox") {
		if (inputs[i].checked) {
		  checked.push(inputs[i].value);
		}
	  }
	}

	var venue_names = document.getElementById('venue_names');

	xmlHttp.open("GET","get_venues_by_search.php?categories="+checked,true);
    xmlHttp.send(null);
	return false;
}



//clears the class name for the venue list so everything doesn't turn yellow
function clearClasses(){
	var list = document.getElementById("venue_names");
	var names = list.getElementsByTagName("a");

	for(i=0; i<names.length; i++){
		if(names[i].className == "current"){
			names[i].className = "";
		}
	}
}

//removes the currently open submenu for venues by sport
function closeSubs(element){
	if (element.parentNode && element.parentNode.removeChild) {
		element.parentNode.removeChild(element);
		return true;
	} else {
		return false;
	}
}