		var myReq;

		function ajax( url, vars, callback ) {

			if (XMLHttpRequest){
				myReq = new XMLHttpRequest();
			}else{
				myReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");
			}
			
			myReq.open("POST", url, true);
			myReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	
			myReq.onreadystatechange = callback;
        	myReq.send(vars);
 	       
		}

		
		function handleData( )
		{
			
			if (myReq.readyState == 4 && myReq.status == 200) {
	
				if ( myReq.responseText ){

					//alert( "handleData: (" + myReq.responseText + ")" );
					
					// get chart div and replace its contents
					var div = document.getElementById('chart');

					div.innerHTML = myReq.responseText;
					
					// now run effect?
					//Effect.Appear('chart',{ delay:1.1, duration:3.0 });		
					//Effect.Fade('chart',{ delay:1.1, duration:3.0 });		
					
				}

			} else {

				//alert( 'handleData: ' + myReq.readyState);

			}

		}
		
		function handleNDXRClick( arg )
		{
						
			ajax( "./ndxr.php", "in=" + arg, handleData );
			
			// set the appropriate tab to be selected
			var item = document.getElementById('tabsB');
			// sub element ul, sub elements li, set id to current of selected tab
			
		}

		function handleClickWithPID( pid, arg )
		{
			ajax( "./ndxr.php?p=" + pid, "in=" + arg, handleData );
		}
		
		function rtrim(stringToTrim) {
			return stringToTrim.replace(/\s+$/,"");
		}

		
		function handleEmbedModalBoxTest() {
			
			Modalbox.show( getEmbedBox(), {title: this.title, width: 500} );
						
		}
		
		function handleEmbedModalBox( ) {

			Modalbox.show($('embed_overlay'), {title: this.title, width: 300});
			return true;
		}

		function handleEmbedModalBoxTestTwo() {
			
			var boxScript  = '<div class=\'embed_overlay\'>';
				boxScript += '<p>Are you sure to delete this item?</p>';
				boxScript += '<input type=\'button\' value=\'Yes, delete!\' onclick=\'Modalbox.hide()\' />';
				boxScript += ' or ';
				boxScript += '<input type=\'button\' value=\'No, leave it!\' onclick=\'Modalbox.hide()\' />';
				boxScript += '</div>';
			
			Modalbox.show( getEmbedBox, {title: this.title, width: 500} );
						
		}
		
		function getEmbedBox(){
			
			var portfolio_id = 6;
		
			var boxText  = '<br/><div class="embed_label">To embed the Colorado Bio Index into your site,';
				boxText += ' copy and paste the following code into your page:</div><br/><br/><blockquote>';

				boxText += '<code>';
				boxText += '&lt;a href="http://nova.metafy.com/cooking/ndxr.php?p=' + portfolio_id + '"&gt;';
				boxText += '&lt;img src="http://nova.metafy.com/cooking/ndxr_chart.php?p=' + portfolio_id + '"&gt;';
				boxText += '&lt;/a&gt;';
				 	
				boxText += '</code>'		
				boxText += '<br/><br/>'
				boxText += '<input type=\'button\' value=\'Done\' onclick=\'Modalbox.hide()\' />';
				boxText += '</blockquote>'
				boxText += '<br/><br/>'
				 			   
			return boxText;		
		}

