//    _____        ____.  _____  ____  ___   _________            .__        __   
//   /  _  \      |    | /  _  \ \   \/  /  /   _____/ ___________|__|______/  |_ 
//  /  /_\  \     |    |/  /_\  \ \     /   \_____  \_/ ___\_  __ \  \____ \   __\
// /    |    \/\__|    /    |    \/     \   /        \  \___|  | \/  |  |_> >  |  
// \____|__  /\________\____|__  /___/\  \ /_______  /\___  >__|  |__|   __/|__|  
//         \/(c) A Haswell 2008\/      \_/         \/     \/         |__|         

var xmlHttp // Set a new variable for xmlHttp

var redir // Set a new variable for redir (the area on the page to alter with the request)

// +----------------------------------
// | FUNCTION getValue()
// | ---------------------------------
// | Nothing to do with the ajax stuff, but will be
// | necessary for sending the correct info through
// +----------------------------------

function getValue() {
	var x=document.getElementById("users")
	alert(x.options[x.selectedIndex].text)
}

// +----------------------------------
// | FUNCTION getLink(str,request,area)
// | ---------------------------------
// | str = the string to be used in the URL containing the $_GET variables
// | request = the URL to send the request to
// | area = the id of the area in the HTML to replace
// | ---------------------------------
// | Uses an xml request to asyncronously update a section of
// | the page the function is been ran from.
// +----------------------------------

function getLink(str,request,area) { 

	redir=area // The variable 'redir' is the section of the HTML code to be replaced
	
	// Replace the area with a loader image so the user knows something is happening...
	document.getElementById(redir).innerHTML='<div align="center" style="padding:20px"><img src="skins/SelectLighting2009/media/sideMenuLoader.gif" /></div>'
	
	xmlHttp=GetXmlHttpObject() // Get the xml request as defined in FUNCTION GetXmlHttpObject()
	
	// +-------------------------------
	// | If the browser can't use AJAX, tell the user...
	// +-------------------------------
	
	if (xmlHttp==null) {
 		alert ("Browser does not support HTTP Request")
 		return
	}
	
	// +-------------------------------
	// | Define the URL including the variables necessary...
	// +-------------------------------

	var url=request // The main URL
	url=url+"?"+str // The $_GET variables
	url=url+"&sid="+Math.random() // A random sid code to prevent the page from caching...
	
	// +-------------------------------
	// | Do the clever xml request stuff...
	// +-------------------------------
	
	xmlHttp.onreadystatechange=showLink // Change the HTML page when the request comes back
	xmlHttp.open("GET",url,true) // Open the request to the specified URL... (true tells it to check asynchronously)
	xmlHttp.send(null) // ...and send it.

}

// +----------------------------------
// | FUNCTION showLink()
// | ---------------------------------
// | Replaces the information defined by 'redir' with the info that
// | comes back from the request
// +----------------------------------

function showLink() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		document.getElementById(redir).innerHTML=xmlHttp.responseText // 'redir' is the area to replace
	} 
}

// +----------------------------------
// | FUNCTION GetXmlHttpObject()
// | ---------------------------------
// | Creates a browser friendly xml request...
// +----------------------------------

function GetXmlHttpObject() {
	var xmlHttp=null;
	try { // For Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	} catch (e) { //For Internet Explorer (boo!)
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
 	}
	return xmlHttp;
}