/*
*************************************************************
*															*
*	gr_ajax.js												*
*	all javascript functions for GemRecords Website 2007	*
*	Author Nick Kirkland									*
*	Date July 2007											*
*	Copyright Reload and Gem Records Ltd 2007				*
*	No permission given for use by any other party			*
*															*
*************************************************************
*/

/**************** common javascript functions ********************/

/*Create xmlhttpRequest Object for Asycronous Stuff*/

function getHTTPObject()
{
	var xmlhttp;
	
	if (window.XMLHttpRequest)
    {
      xmlhttp=new XMLHttpRequest();
    }
	else if (window.ActiveXObject)
    {
    		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
		else
		{
				xmlhttp = false;
		}
	return xmlhttp
}




/**************** artistsandbands.html javascript functions ********************/

/*Function db_getartists*/

/*get an artist by id and populate content div with response*/
function db_getartists(artist_id) {

/*set location to be populated*/
var location;
	location = document.getElementById('content');
/*create http object*/
var httpRead = getHTTPObject();
var now = new Date();
var isReady = false;

/*invoke HTTP Request*/
 httpRead.open("GET", "./db_scripts/db_getartists.php?artist_id=" + artist_id + "&ms=" + now.getTime(), true);
	

/*check for change of state*/
 httpRead.onreadystatechange = function () {
		 if (httpRead.readyState == 4) 
		 {
			 /*response fully loaded - set responseString = returned html*/
			 isReady = true;
			 responseString = httpRead.responseText;
			 /*call function to populate location div - Params (true,location object,response)*/
			 displayOutput(isReady,location,responseString);
		 }
		 else
		 {
			/*response not fully loaded - call displayOutput function isReady as false*/
			isReady = false;
			/*call function to show status of loading in location div - Params(false,location object)*/
			displayOutput(isReady,location);
		 }
		 /*Function displayOutput - shows returned response of notifies user data is still loading*/	
		 function displayOutput(isReady,location,responseString) {
		 if(isReady)
		 {
			 	 /*response is fully loaded - polulate location*/
				 location.innerHTML = responseString;
				 /*reset variables*/
				 responseString = "";
				 isReady = false;
		 }
		 else
		 {
			 /*response is not fully loaded - display loading UI*/
			 location.innerHTML = "<div class = \"loadingContent\">loading...<br /><img src =\"img/ajax-loader.gif\" /></div>";
		 }
	 
	}
 };
/*close RPC*/
 httpRead.send(null);
}


/*Function db_getartistlinks*/

/*get all artists' links and populate subnav div with response*/
function db_getartistlinks() {

/*set location to be populated*/
var location;
	location = document.getElementById('subnav');
/*create http object*/
var httpRead = getHTTPObject();
var now = new Date();
var isReady = false;

/*invoke HTTP Request*/
 httpRead.open("GET", "./db_scripts/db_getartistlinks.php?ms=" + now.getTime(), true);
	

/*check for change of state*/
 httpRead.onreadystatechange = function () {
		 if (httpRead.readyState == 4) 
		 {
			 /*response fully loaded - set responseString = returned html*/
			 isReady = true;
			 responseString = httpRead.responseText;
			 /*call function to populate location div - Params (true,location object,response)*/
			 displayOutput(isReady,location,responseString);
		 }
		 else
		 {
			/*response not fully loaded - call displayOutput function isReady as false*/
			isReady = false;
			/*call function to show status of loading in location div - Params(false,location object)*/
			displayOutput(isReady,location);
		 }
		 /*Function displayOutput - shows returned response of notifies user data is still loading*/	
		 function displayOutput(isReady,location,responseString) {
		 if(isReady)
		 {
			 	 /*response is fully loaded - polulate location*/
				 location.innerHTML = responseString;
				 /*reset variables*/
				 responseString = "";
				 isReady = false;
		 }
		 else
		 {
			 /*response is not fully loaded - display loading UI*/
			 location.innerHTML = "<div class = \"loadingLinks\">loading...<br /><img src =\"img/ajax-loader.gif\" /></div>";
		 }
	 
	}
 };
/*close RPC*/
 httpRead.send(null);
}




/**************** services.html javascript functions ********************/

/*Function db_getproject*/

/*get a project by id and populate content div with response*/
function db_getproject(project_id) {

/*set location to be populated*/
var location;
	location = document.getElementById('content');
/*create http object*/
var httpRead = getHTTPObject();
var now = new Date();
var isReady = false;

/*invoke HTTP Request*/
 httpRead.open("GET", "./db_scripts/db_getproject.php?project_id=" + project_id + "&ms=" + now.getTime(), true);
	

/*check for change of state*/
 httpRead.onreadystatechange = function () {
		 if (httpRead.readyState == 4) 
		 {
			 /*response fully loaded - set responseString = returned html*/
			 isReady = true;
			 responseString = httpRead.responseText;
			 /*call function to populate location div - Params (true,location object,response)*/
			 displayOutput(isReady,location,responseString);
		 }
		 else
		 {
			/*response not fully loaded - call displayOutput function isReady as false*/
			isReady = false;
			/*call function to show status of loading in location div - Params(false,location object)*/
			displayOutput(isReady,location);
		 }
		 /*Function displayOutput - shows returned response of notifies user data is still loading*/	
		 function displayOutput(isReady,location,responseString) {
		 if(isReady)
		 {
			 	 /*response is fully loaded - polulate location*/
				 location.innerHTML = responseString;
				 /*reset variables*/
				 responseString = "";
				 isReady = false;
		 }
		 else
		 {
			 /*response is not fully loaded - display loading UI*/
			 location.innerHTML = "<div class = \"loadingContent\">loading...<br /><img src =\"img/ajax-loader.gif\" /></div>";
		 }
	 
	}
 };
/*close RPC*/
 httpRead.send(null);
}


/*Function db_getartistlinks*/

/*get all artists' links and populate subnav div with response*/
function db_getartistlinks() {

/*set location to be populated*/
var location;
	location = document.getElementById('subnav');
/*create http object*/
var httpRead = getHTTPObject();
var now = new Date();
var isReady = false;

/*invoke HTTP Request*/
 httpRead.open("GET", "./db_scripts/db_getartistlinks.php?ms=" + now.getTime(), true);
	

/*check for change of state*/
 httpRead.onreadystatechange = function () {
		 if (httpRead.readyState == 4) 
		 {
			 /*response fully loaded - set responseString = returned html*/
			 isReady = true;
			 responseString = httpRead.responseText;
			 /*call function to populate location div - Params (true,location object,response)*/
			 displayOutput(isReady,location,responseString);
		 }
		 else
		 {
			/*response not fully loaded - call displayOutput function isReady as false*/
			isReady = false;
			/*call function to show status of loading in location div - Params(false,location object)*/
			displayOutput(isReady,location);
		 }
		 /*Function displayOutput - shows returned response of notifies user data is still loading*/	
		 function displayOutput(isReady,location,responseString) {
		 if(isReady)
		 {
			 	 /*response is fully loaded - polulate location*/
				 location.innerHTML = responseString;
				 /*reset variables*/
				 responseString = "";
				 isReady = false;
		 }
		 else
		 {
			 /*response is not fully loaded - display loading UI*/
			 location.innerHTML = "<div class = \"loadingLinks\">loading...<br /><img src =\"img/ajax-loader.gif\" /></div>";
		 }
	 
	}
 };
/*close RPC*/
 httpRead.send(null);
}



/*Function db_getprojectlinks*/

/*get all projects' links and populate subnav div with response*/
function db_getprojectlinks() {

/*set location to be populated*/
var location;
	location = document.getElementById('subnav');
/*create http object*/
var httpRead = getHTTPObject();
var now = new Date();
var isReady = false;

/*invoke HTTP Request*/
 httpRead.open("GET", "./db_scripts/db_getprojectlinks.php?ms=" + now.getTime(), true);
	

/*check for change of state*/
 httpRead.onreadystatechange = function () {
		 if (httpRead.readyState == 4) 
		 {
			 /*response fully loaded - set responseString = returned html*/
			 isReady = true;
			 responseString = httpRead.responseText;
			 /*call function to populate location div - Params (true,location object,response)*/
			 displayOutput(isReady,location,responseString);
		 }
		 else
		 {
			/*response not fully loaded - call displayOutput function isReady as false*/
			isReady = false;
			/*call function to show status of loading in location div - Params(false,location object)*/
			displayOutput(isReady,location);
		 }
		 /*Function displayOutput - shows returned response of notifies user data is still loading*/	
		 function displayOutput(isReady,location,responseString) {
		 if(isReady)
		 {
			 	 /*response is fully loaded - polulate location*/
				 location.innerHTML = responseString;
				 /*reset variables*/
				 responseString = "";
				 isReady = false;
		 }
		 else
		 {
			 /*response is not fully loaded - display loading UI*/
			 location.innerHTML = "<div class = \"loadingLinks\">loading...<br /><img src =\"img/ajax-loader.gif\" /></div>";
		 }
	 
	}
 };
/*close RPC*/
 httpRead.send(null);
}


  