// setup ids and images 

var bromleyurl=window.location.href;
//alert('bromley url  '+bromleyurl);
var blen=bromleyurl.length;

var checkin = bromleyurl.substr(bromleyurl.indexOf("index.html")).toLowerCase();
var longurl = bromleyurl.substr(bromleyurl.indexOf("?")).toLowerCase();

if(longurl)
{
	
	//alert('bromley blen  '+blen);
	inq=bromleyurl.indexOf("?");
	var bromsub = bromleyurl.substr(inq,blen).toLowerCase();
	//alert('bromley bromsub 23  '+bromsub);
	bromlen=bromsub.length;
	BL=parseInt(blen)-parseInt(bromlen);
	//alert('bromley  26 BL  '+BL);
	
	var bromsuburl = bromleyurl.split(bromsub);
	var bromurl = bromleyurl.substr(bromleyurl.indexOf("http://"),BL).toLowerCase();
	//alert('bromley bromsub 27  '+bromsuburl);
	//alert('bromley bromurl  '+bromurl);
	
	bromsuburl=bromurl;
}
else if(checkin)
{
	blen=parseInt(blen)-10;
	//alert('bromley blen  '+blen);
	//var bromsub = bromleyurl.substr(bromleyurl.indexOf("http"),blen).toLowerCase();
	var bromsuburl = bromleyurl.split("index.html");
	//alert('bromley bromsub 22  '+bromsuburl);
}
else
{
		//alert('bromley bromsub 26  '+bromsuburl);
		var bromsuburl = bromleyurl;
}
//alert('bromley bromsub 43  '+bromsuburl);
  
  
  
   
rollovers = new Rollovers([
	["butBuzz", "http://bromley.dev.textor.com/images/butBuzzOvr.jpg"],
	["butConnect", "http://bromley.dev.textor.com/images/butConnectOvr.jpg"],
	["butActive", "http://bromley.dev.textor.com/images/butActiveOvr.jpg"],
	["butPrime", "http://bromley.dev.textor.com/images/butPrimetimeOvr.jpg"]
	]);



function Rollovers_swap(id){ // id to swap in an image, null to swap out
	if (id != null)
	{	
		var image = document.images[id]
		if (image == null) return
	
		var newimage = this.images[id]
		if (newimage == null) return
		
		this.temp_img = image
		this.temp_src = image.src
		
		image.src = newimage.src
	}
	else
	{
		if ((this.temp_img != null) && (this.temp_src != null))
			this.temp_img.src = this.temp_src
			
		this.temp_img = null
		this.temp_src = null
	}
}
	
function Rollovers(image_list){
	this.images = new Object()		// Storage for swap-in images
	this.load = Rollovers_Install
	this.swap = Rollovers_swap	
	// Storage for the current swap-out image
	this.temp_img = null
	this.temp_src = null
	for (var i=0; i < image_list.length; i++) {
		var id = image_list[i][0]
		var src = image_list[i][1]
		
		var image = new Image()
		image.src = src
		this.images[id] = image
	}
}

function Rollovers_Install() {	// Should be called after page is loaded
	var _this = this
	var swap_out = function(){_this.swap(null);}

	var set = function (id){
		var image = document.images[id]
		if (image == null) return
		image.onmouseover = function(){_this.swap(id);}
		image.onmouseout = swap_out
	}
	
	for(var id in this.images) set(id);
}


function clearform (formfield)
{
	//alert('formfield'+formfield.value);
	if(formfield && formfield.value=='Type here')
	{
		formfield.value="";
	}
}
	
	
	
function makeRequest(response) {
	//alert(' Entering makeRequest '+response);
		
	http_request = false;
	//alert('bromley bromsub 126 '+bromsuburl);
	
	var url = bromsuburl+"/cgi-bin/bromley/poll.pl?response=" + response;
	//alert('bromley url  '+url);

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
			// See note below about this line
		}
	}
	else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				//catch error here
			}
		}
	}

	if (!http_request) {
		return false;
	}
	//alert(' Entering http_request ');
	
	http_request.onreadystatechange = function() { showResults(http_request); };
	http_request.open('GET', url, true);
	http_request.send(null);
}

function showResults(http_request)
{
	document.getElementById('poll').innerHTML = http_request.responseText;
}
	
function pollsubmit()
	{
		//alert('entering poll submit ');
		for (i=0;i<document.pollform.response.length;i++)
			{
				//alert('checking which option submit  response '+document.pollform.response.length);
				if (document.pollform.response[i].checked)
				{
					//alert('entering submit '+document.pollform.response[i]);
					user_input = document.pollform.response[i].value;
				}
			}
		//alert(' makeRequest '+user_input);
		
		makeRequest(user_input);
		return false; 
	}	
	
	
function homescript(sname)
	{
		//alert(sname);
		var getn="document.getElementById('"+sname+"');";
		var len=getn.length;
		
		if(sname=='centres')
			{
				var selinc=document.getElementById('centres').selectedIndex;
				window.location.href=document.getElementById('centres').options[selinc].value;
			}
		else if(sname=='activities')
			{
				var selina=document.getElementById('activities').selectedIndex;
				window.location.href=document.getElementById('activities').options[selina].value;
			}
		return true;
	}