/*
* File: 		ajax.js
* Author: 		Matt Skelton
* Company: 		Broda Seating LTD.
* Date:		December 18, 2008	: Created
*			December 22, 2008 	: Updated
* Description:	This file contains mutliple functions/methods that assist in Ajax implementations of the seatingisbelieving.com website.
* License:		You are free to use any code within this file as you see fit, as long as you include the header of this file. Cheers!
*/

loadTestimonialData = function(currentPage)
{
	getGetTestimonials(currentPage);
	
	getPagination(currentPage);
	
	// The following AJAX call breaks Firefox!?
	// Look into it.
	//getRandomImage();
	
	return false;
}

/*
* Finds distributors for a region & updates the searchResults div
*/
function getGetTestimonials(currentPage)
{
	var loader 			= document.getElementById("loader");
	loader.innerHTML 	= "<img src=\"../system/application/images/icons/ajax_loaders/ajax_loader_purple.gif\" />";
	
	var xmlHttp = getTransport();
	
	if (xmlHttp == null)
	{
		return;
	}

	var url = "testimonial/ajaxGetTesimonials";
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.send("currentPage=" + currentPage);
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4)
		{			
			document.getElementById("testimonialContainer").innerHTML = xmlHttp.responseText;	
			loader.innerHTML = "";
		}
	}
	
	return false;
}

getPagination = function(currentPage)
{
	var xmlHttp = getTransport();
	
	if (xmlHttp == null)
	{
		return;
	}

	var url = "testimonial/ajaxGetPagination";
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.send("currentPage=" + currentPage);
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4)
		{			
			var container 			= document.getElementById("pagination");	
			container.innerHTML 	= xmlHttp.responseText;
		}
	}
	
	return false;
}

getRandomImage = function()
{
	var xmlHttp = getTransport();
	
	if (xmlHttp == null)
	{
		return;
	}

	var url = "/testimonial/ajaxGetRandomImage";
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.send();
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4)
		{	
			document.getElementById("testimonialSideBarImage").innerHTML = xmlHttp.responseText;	
		}
	}
	
	return false;
}