var cacheObj = new Object();

/*---\\\ LIST FUNCTIONS ///---*/
	function list_request(){ 
		http( "GET" , "db_ddbiz.cfc?method=getList" , list_response ); //notice the third argument = list_response. This is the callback function below.
	}	
	function list_response(obj){ //callback functions always take one argument. This is the result passed back from the server.
		document.getElementById("tbl_directoryList").innerHTML = obj;
	}
/*---\\\ LIST FUNCTIONS ///---*/


/*---\\\ DETAILS FUNCTIONS ///---*/
	function details_request(cid){
		//structKeyExists() is a UDF at the bottom of this page ;)
		if( structKeyExists(cacheObj,cid) )		//populate from cache if already retrieved
			details_response(cacheObj[cid]);
		else{									//otherwise make an http() call
			var httpParam = new Object();
				httpParam.cid = cid;
			http( "POST" , "db_ddbiz.cfc?method=getDetails" , details_response , httpParam );
		}
	}	
	
	function details_response(obj){
//		cacheObj[obj.CID] = obj;  //you can uncomment this line to Cache server results. *NOTE: you should also uncomment line 51 below to Clear cache after updating.
		
		//POPULATE THE UPPER FORM
		var form = document.userForm;
			form.CID.value = obj.cid;
			form.coName.value = obj.coname;
			form.coPhone.value = obj.cophone;
			form.coAddress.value = obj.coaddress;
			form.coWebsite.value = obj.cowebsite;
			form.coNotes.value = obj.conotes;
	}
/*---\\\ DETAILS FUNCTIONS ///---*/




/*---\\\ SUBMIT FUNCTIONS ///---*/
	function submit_request(form){ 
		http( "POST" , "db_ddbiz.cfc?method=putDetails" , submit_response , form ); //here we are posting the entire form.
	}
	function submit_response(obj){
		if(eval(obj)){
//			delete cacheObj[obj];
			list_request();
			alert('Success');
		}else{
			details_request(document.userForm.CID.value);
			alert('There was a problem with your form');
		}
		
	}




/*---\\\ EMULATE CF FUNCTIONS ///---*/
	function structKeyExists(obj,key){
		for(x in obj){
			if(x == key)
			return true;
		}
	return false;	
	}
	
	function isDefined(argsVar){
		return (eval('typeof('+argsVar+') != "undefined"'))
	}
/*---\\\ EMULATE CF FUNCTIONS ///---*/