// JavaScript Document
function jsonToString(obj){
	
	var string = '{'
	
	//Loop through object and create a json formated string to pass to the server
	for(i in obj){
		string += ('"' + i + '":"' +obj[i] + '", ')
	}//end loop
	
	
	//Close the string 
	string += '"END":"END"}'
	
	
	//URL encode the string
	var encode = escape(string)
	
	//return the string as the result of the function
	return encode
}





function jsonToObject(string){
	
	try{
		//Get position of last curly brace
		var lastPos = string.indexOf('"}')
		
		//Strip the curly braces
		string = string.replace("{", "")
		string = string.replace("}", "")
		string = string.substring(0, lastPos)	
	
	
		//Split the data into an array
		var array = string.split(",")
		
		
		//Create an object that will hold the json data as an object
		var obj = new Object()
		
		for(i=0;i<array.length;i++){
			//Splie the string by the ":"
			var tmpArray = array[i].split(":")
			
			//Set the tmpArray values as the name and value pair of the object
			obj[tmpArray[0].toString()] = tmpArray[1].toString()
		
		}//end loop
		
		
	}//end try
	catch(e){
		alert("JavaScript Error:"+e)
	}//end catch
	
	//Return the object
	return obj
	
}//end function




function ajaxRequest(obj, callBackFunction){
	
	//Create the URL
	var url = '?ajax=true&json='+jsonToString(obj)

	//Call the ajax function
	ajax(url, callBackFunction)
	
}