// JavaScript Document
//Load map of where the course is taking place
function loadMap()
{
  if (GBrowserIsCompatible())
  {
    var map = new GMap2(document.getElementById("map"));
    map.setUIToDefault();
    map.setCenter(new GLatLng(55.9526626426108,-3.19645023137709), 15);
    function createMarker(point) {  
      var marker = new GMarker(point);  
      GEvent.addListener(marker, "click", function() {    
        marker.openInfoWindowHtml("<p>Christianity Explored<br>@ Costa Coffee<br>Hanover Street<br>Edinburgh</p>");  });  
        return marker;
    }
    var point = new GLatLng(55.9526626426108,-3.19645023137709)
    map.addOverlay(createMarker(point));
  }
}


// Hide signup form
function showHideForm (value) {
  if (value == "hide") {
  document.getElementById("signupform").style.display = "none";
  }
  else {
  document.getElementById("signupform").style.display = "block";
  }
}


//AJAX signup form
function signup(){
	var ajaxRequest;  // The variable that makes Ajax possible!
	var ajaxDisplay = document.getElementById('signup');
	
	// display a loading image so the user knows something is happening
	ajaxDisplay.innerHTML = '<br /><br /><p align="center">Submitting Signup....</p>';
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			//var ajaxDisplay = document.getElementById('txtFilterOutput');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	// get variables from the form
	var name = document.getElementById('name').value;
	var email = document.getElementById('email').value;
	var phone = document.getElementById('phone').value;
	var question = document.getElementById('question').value;
	// generate the query string to pass parameters to the filter page
	var queryString = "?name=" + name + "&phone=" + phone +"&email=" + email + "&question=" + question + "&random=" +new Date().getTime();
	// send the data to the filter page
  ajaxRequest.open("GET", "signup.php" + queryString, true);
	ajaxRequest.send(null); 
	showHideForm ('hide')
	return false;
}

