var lastQ;
var lastTab = 0;

function showRecord(arg) { 
//arg = db/tbl/fld/arg
	lastQ = arg;
	if ($('recmenu')) {
		lastTab = $('recmenu').currenttab;
	}
	$('content').update("<div class='loader'><img src='resources/indicator.gif' alt='loading' width='16' height='16' /><br />loading...<br /><br /><br /><br /></div>");
	var url="ajax.php";
	myRand=parseInt(Math.random()*99999999);
	url=url+"?"+"fakecache="+myRand;
	new Ajax.Updater("content", url, { method: 'get', evalScripts: true, parameters: {args: arg, lastt: lastTab} });
	//var menutit = $('lftcl').firstChild;
	//menutit.innerHTML = "<a href='"+window.location.href+"'>"+menutit.innerHTML+"</a>";
	}
	
function recfield(id,fld,val) {
	if (fld=='public') $(fld+'_'+id).setAttribute('src','icm/resources/public.gif');
	var url ='change.php';
	myRand=parseInt(Math.random()*99999999);
	var vars = "ID="+id+"&fld="+fld+"&val="+val+"&fakecache="+myRand;
		new Ajax.Request(url, {method: 'post', postBody: vars,
		 onSuccess: function(transport) {
		 	var thisResp = transport.responseText.split(':');
		 	if (thisResp[1]==="1") {
		 		newsrc = 'icm/resources/public.gif';
		 		newtit = ' nascondi '
		 	} else {
		 		newsrc = 'icm/resources/not_public.gif';
		 		newtit = ' pubblica '
		 	}
		 	$(fld+'_'+id).setAttribute('src',newsrc);
		 	$(fld+'_'+id).setAttribute('title',newtit);
		}
	});
}

function showImageBrowser() {
	imWindow = window.open("imagebrowser.php?d=images/prodotti/hires","imWindow","width=284,height=800,location=0,resizable=0,scrollbars=1");
}

function nl2br (str, is_xhtml) {
	var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
	return (str + '').replace(/([^>rn]?)(rn|nr|r|n)/g, '$1' + breakTag + '$2');
}	
function loadFBWall() {
	new Ajax.Request('proxy.php', {
		method: 'get',
		requestHeaders: {Accept: 'application/json'},
		onSuccess: function(transport) {
			alert( transport.responseText);
			var json = transport.responseText.evalJSON();
			var title = "<strong><a href='http://www.facebook.com/pages/Prodotti-Riciclati/" + json['data'][0]['from']['id'] + "' target='_blank'>" + json['data'][0]['from']['name'] + "</a></strong><br />";
			var message = json.data[0]['message'];
			if ( message == "undefined" ) {
				message = "<a href='"+json.data[0]['link']+"'>"+json.data[0]['name']+"</a>";
			}
			$('wall').update(title + message + "<br />");
		}
	});
}

