var urlCrit = "mxajax/core/cf/insights-criteria.cfc";

function getCritOptions(params, destination) {
		document.getElementById("showCritInd").style.display = 'inline';
	    new mxAjax.Data({
	        executeOnLoad:true,
	        paramArgs: new mxAjax.Param(urlCrit,{param:params, cffunction:"showCriteria"}),
	        postFunction: handleData
	    });
	   
	    function handleData(response) {
	        var myHTMLOutput = JSON.parse(response);
	        document.getElementById(destination).innerHTML = myHTMLOutput;
			document.getElementById("showCritInd").style.display = 'none';
	    }
	}

var urlTags = "mxajax/core/cf/insights-tags.cfc";

	function sendData(params, destination) {
	    new mxAjax.Data({
	        executeOnLoad:true,
	        paramArgs: new mxAjax.Param(urlTags,{param:params, cffunction:"addTag"}),
	        postFunction: handleData
	    });
	   
	    function handleData(response) {
	        var myHTMLOutput = JSON.parse(response);
	        document.getElementById(destination).innerHTML = myHTMLOutput;
	    }
	}	
	
	function showAddForm(params, destination) {
	    new mxAjax.Data({
	        executeOnLoad:true,
	        paramArgs: new mxAjax.Param(urlTags,{param:params, cffunction:"showAddForm"}),
	        postFunction: handleData
	    });
	   
	    function handleData(response) {
	        var myHTMLOutput = JSON.parse(response);
	        document.getElementById(destination).innerHTML = myHTMLOutput;
	    }
	}
	
	function cancelForm(params, destination) {
	    new mxAjax.Data({
	        executeOnLoad:true,
	        paramArgs: new mxAjax.Param(urlTags,{param:params, cffunction:"cancelTagAdd"}),
	        postFunction: handleData
	    });
	   
	    function handleData(response) {
	        var myHTMLOutput = JSON.parse(response);
	        document.getElementById(destination).innerHTML = myHTMLOutput;
	    }
	}

var urlNotes = "mxajax/core/cf/insights-notes.cfc";

	function sendDataNote(params, destination) {
	    new mxAjax.Data({
	        executeOnLoad:true,
	        paramArgs: new mxAjax.Param(urlNotes,{param:params, cffunction:"addNote"}),
	        postFunction: handleData
	    });
	   
	    function handleData(response) {
	        var myHTMLOutput = JSON.parse(response);
	        document.getElementById(destination).innerHTML = myHTMLOutput;
	    }
	}	
	
	function showAddFormNote(params, destination) {
	    new mxAjax.Data({
	        executeOnLoad:true,
	        paramArgs: new mxAjax.Param(urlNotes,{param:params, cffunction:"showNoteAddForm"}),
	        postFunction: handleData
	    });
	   
	    function handleData(response) {
	        var myHTMLOutput = JSON.parse(response);
	        document.getElementById(destination).innerHTML = myHTMLOutput;
	    }
	}
	
	function cancelFormNote(params, destination) {
	    new mxAjax.Data({
	        executeOnLoad:true,
	        paramArgs: new mxAjax.Param(urlNotes,{param:params, cffunction:"cancelTagNote"}),
	        postFunction: handleData
	    });
	   
	    function handleData(response) {
	        var myHTMLOutput = JSON.parse(response);
	        document.getElementById(destination).innerHTML = myHTMLOutput;
	    }
	}			

	function deleteComment(params, destination, cancelParams, cancelDestination, expandComments) {
	
	
		if (window.confirm("Are you sure?")) {
		    new mxAjax.Data({
		        executeOnLoad:true,
		        paramArgs: new mxAjax.Param(urlNotes,{param:params, cffunction:"deleteComment"}),
		        postFunction: handleData
		    });
	   
		}
		else {
		}
	
	    function handleData(response) {
	        var myHTMLOutput = JSON.parse(response);
			cancelFormNote(cancelParams, cancelDestination);
	        // document.getElementById(destination).style.display = 'none';
			// shotNoteList(expandComments);
	    }
	
	}
	
	
var urlRefs = "mxajax/core/cf/refTrendToInsight.cfc";

	function showAddFormTrends(params, destination) {
	    new mxAjax.Data({
	        executeOnLoad:true,
	        paramArgs: new mxAjax.Param(urlRefs,{param:params, cffunction:"searchTrend"}),
	        postFunction: handleData
	    });
	   
	    function handleData(response) {
	        var myHTMLOutput = JSON.parse(response);
	        document.getElementById(destination).innerHTML = myHTMLOutput;
	    }
	}
	
	function showAddFormTrendsCancel(destination) {
	    document.getElementById(destination).innerHTML = '';
	}	
	
	function sendDataTrends(params, destination) {
		document.getElementById("showIndicator").style.visibility = 'visible';
	    new mxAjax.Data({
	        executeOnLoad:true,
	        paramArgs: new mxAjax.Param(urlRefs,{param:params, cffunction:"searchTrendsTable"}),
	        postFunction: handleData
	    });
	   
	    function handleData(response) {
	        var myHTMLOutput = JSON.parse(response);
	        document.getElementById(destination).innerHTML = myHTMLOutput;
			document.getElementById("showIndicator").style.visibility = 'hidden';
	    }
	}		

	function refreshTrendsList(params, destination) {
	    new mxAjax.Data({
	        executeOnLoad:true,
	        paramArgs: new mxAjax.Param(urlRefs,{param:params, cffunction:"refreshTrends"}),
	        postFunction: handleData
	    });
	   
	    function handleData(response) {
	        var myHTMLOutput = JSON.parse(response);
	        document.getElementById(destination).innerHTML = myHTMLOutput;
	    }
	}	
	
	function sendRefData(params, destination, refreshList) {
	    new mxAjax.Data({
	        executeOnLoad:true,
	        paramArgs: new mxAjax.Param(urlRefs,{param:params, cffunction:"refInsight"}),
	        postFunction: handleData
	    });
		
		refreshTrendsList(params, refreshList);
	   
	    function handleData(response) {
	        var myHTMLOutput = JSON.parse(response);
	        document.getElementById(destination).innerHTML = myHTMLOutput;
			
	    }
	}			
	
	function handleEnterRefs(field, event, params, destination) 
	{
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
		var i;
			for (i = 0; i < field.form.elements.length; i++)
			if (field == field.form.elements[i])
				break;
				i = (i + 1) % field.form.elements.length;
			sendDataTrends(params, destination);
			return false;
		} 
		else
			return true;
		}	
		

	function changeBox(cbox) {
		box = eval(cbox);
		box.checked = !box.checked;
		}	
		
		
	function shotNoteList(destination) {
	
	            var e = document.getElementById(destination);
	            
				if (e.style.display == 'none') 
				{
		            e.style.display = 'inline';
				}
				else
				{
		            e.style.display = 'none';
				}		
	
	}
	
	
			var creatorsURL = "mxajax/core/cf/insights-creators.cfc";
			
            var targetCreate = "";
	        function showCreators(indicator, sourceTarget, params, target, sourceID)
	        {
            	document.getElementById(sourceTarget).innerHTML = '';

	            $$("#myList div").each(function(value, index) {
	                  value.innerHTML = '';
	            });
	            sourceTab = sourceID;
	            targetTab = target;
	            
	            var e = document.getElementById(targetTab);
	            var i = document.getElementById(indicator);
	            
				if (e.style.visibility == 'hidden') 
				{
		            i.style.display = 'inline';
		            new mxAjax.Data({
		                executeOnLoad:true,
		                paramArgs: new mxAjax.Param(creatorsURL,{param:params, cffunction:"showCreators"}),
		                postFunction: handleData
		            });
		            e.style.visibility = 'visible';
				}
				else
				{
					document.getElementById(targetTab).innerHTML == '';
					e.style.visibility = 'hidden';
		            document.getElementById(sourceID).innerHTML = 'Assess'; 
				}
		            function handleData(response) {
		                var myHTMLOutput = JSON.parse(response);
		                document.getElementById(targetTab).innerHTML = myHTMLOutput;
		           		document.getElementById(sourceID).innerHTML = 'Assess'; 
			            i.style.display = 'none';
		            }	            

	            
	            
	        }	
			
			
			var toolsURL = "mxajax/core/cf/insights-tools.cfc";
			
            var targetCreate = "";
	        function showTools(indicator, sourceTarget, params, target, sourceID)
	        {
            	document.getElementById(sourceTarget).innerHTML = '';

	            $$("#myList div").each(function(value, index) {
	                  value.innerHTML = '';
	            });
	            sourceTab = sourceID;
	            targetTab = target;
	            
	            var e = document.getElementById(targetTab);
	            var i = document.getElementById(indicator);
	            
				if (e.style.visibility == 'hidden') 
				{
		            i.style.display = 'inline';
		            new mxAjax.Data({
		                executeOnLoad:true,
		                paramArgs: new mxAjax.Param(toolsURL,{param:params, cffunction:"showCreators"}),
		                postFunction: handleData
		            });
		            e.style.visibility = 'visible';
				}
				else
				{
					document.getElementById(targetTab).innerHTML == '';
					e.style.visibility = 'hidden';
		            document.getElementById(sourceID).innerHTML = 'Tools'; 
				}
		            function handleData(response) {
		                var myHTMLOutput = JSON.parse(response);
		                document.getElementById(targetTab).innerHTML = myHTMLOutput;
		           		document.getElementById(sourceID).innerHTML = 'Tools'; 
			            i.style.display = 'none';
		            }	            

	            
	            
	        }			
