function setTopLink_allActive(){
	dojo.byId("menuTop_1").className="red";
	dojo.byId("menuTop_2").className="red";
	dojo.byId("menuTop_3").className="red";
	dojo.byId("menuTop_4").className="red";
	dojo.byId("menuTop_5").className="red";
}

function ajaxGetHome(){
	closeCollaneTree();
	dojo.byId("menuTop_1").className="hilite";
	dojo.byId("menuTop_2").className="red";
	dojo.byId("menuTop_3").className="red";
	dojo.byId("menuTop_4").className="red";
	dojo.byId("menuTop_5").className="red";
	var xhrArgs = {
		url:"/ajaxGetHomeDiv/",
		handleAs:"text",
		load:function(response){
			dojo.byId("mainContent").innerHTML=response;
		},
		error:function(error){
			dojo.byId("mainContent").innerHTML="Errore di comunicazione con il server ("+error+")";
		}
	}
	var deferred = dojo.xhrGet(xhrArgs);
}

function ajaxGetChiSiamo(){
	closeCollaneTree();
	dojo.byId("menuTop_1").className="red";
	dojo.byId("menuTop_2").className="hilite";
	dojo.byId("menuTop_3").className="red";
	dojo.byId("menuTop_4").className="red";
	dojo.byId("menuTop_5").className="red";
	var xhrArgs = {
		url:"/ajaxGetChiSiamoDiv/",
		handleAs:"text",
		load:function(response){
			dojo.byId("mainContent").innerHTML=response;
		},
		error:function(error){
			dojo.byId("mainContent").innerHTML="Errore di comunicazione con il server ("+error+")";
		}
	}
	var deferred = dojo.xhrGet(xhrArgs);
}

function ajaxGetContatti(){
	closeCollaneTree();
	dojo.byId("menuTop_1").className="red";
	dojo.byId("menuTop_2").className="red";
	dojo.byId("menuTop_3").className="hilite";
	dojo.byId("menuTop_4").className="red";
	dojo.byId("menuTop_5").className="red";
	var xhrArgs = {
		url:"/ajaxGetContattiDiv/",
		handleAs:"text",
		load:function(response){
			dojo.byId("mainContent").innerHTML=response;
		},
		error:function(error){
			dojo.byId("mainContent").innerHTML="Errore di comunicazione con il server ("+error+")";
		}
	}
	var deferred = dojo.xhrGet(xhrArgs);
}

function ajaxGetInfoAcquisti(){
	closeCollaneTree();
	dojo.byId("menuTop_1").className="red";
	dojo.byId("menuTop_2").className="red";
	dojo.byId("menuTop_3").className="red";
	dojo.byId("menuTop_4").className="hilite";
	dojo.byId("menuTop_5").className="red";
	var xhrArgs = {
		url:"/ajaxGetInfoAcquisti/",
		handleAs:"text",
		load:function(response){
			dojo.byId("mainContent").innerHTML=response;
		},
		error:function(error){
			dojo.byId("mainContent").innerHTML="Errore di comunicazione con il server ("+error+")";
		}
	}
	var deferred = dojo.xhrGet(xhrArgs);
}

function toggleCollaneTree(){
	collaneTree=document.getElementById("tree");
	if (collaneTree.style.display=='none'){
		openCollaneTree();
	} else {
		closeCollaneTree();
	}
}

function closeCollaneTree(){
	collaneTree=document.getElementById("tree");
	collaneTree.style.display="none";
	document.getElementById("treeTitle").style.backgroundColor="#6699cc"
}

function openCollaneTree(){
	collaneTree=document.getElementById("tree");
	collaneTree.style.display="block";
	document.getElementById("treeTitle").style.backgroundColor="#336699"
}

function ajaxGetVolumi(itemId,grouping,pageNum){
	//setTopLink_allActive();
	var xhrArgs = {
		url:"/ajaxGetVolumiHP_div/",
		handleAs:"text",
		content: {"itemId":itemId,"grouping":grouping,"p":pageNum},
		load:function(response){
			dojo.byId("mainContent").innerHTML=response;
		},
		error:function(error){
			dojo.byId("mainContent").innerHTML="Errore di comunicazione con il server ("+error+")";
		}
	}
	var deferred = dojo.xhrGet(xhrArgs);
}

function ajaxGetLibrary(){
	//setTopLink_allActive();
	closeCollaneTree();
	var xhrArgs = {
		url:"/ajaxGetLibrary_div/",
		handleAs:"text",
		load:function(response){
			dojo.byId("mainContent").innerHTML=response;
		},
		error:function(error){
			dojo.byId("mainContent").innerHTML="Errore di comunicazione con il server ("+error+")";
		}
	}
	var deferred = dojo.xhrGet(xhrArgs);
}

function ajaxGetSearchResults(searchTerm,pageNum){
	closeCollaneTree();
	var xhrArgs = {
		url:"/ajaxGetSearchResultsDiv/",
		handleAs:"text",
		content: {"searchTerm":searchTerm,"p":pageNum},
		load:function(response){
			dojo.byId("mainContent").innerHTML=response;
		},
		error:function(error){
			dojo.byId("mainContent").innerHTML="Errore di comunicazione con il server ("+error+")";
		}
	}
	var deferred = dojo.xhrGet(xhrArgs);
}

function ajaxGetSearchResultsLibrary(searchTerm,pageNum){
	var xhrArgs = {
		url:"/ajaxGetSearchResultsLibraryDiv/",
		handleAs:"text",
		content: {"searchTermLibrary":searchTerm,"p":pageNum},
		load:function(response){
			dojo.byId("searchResultsLibrary").innerHTML=response;
		},
		error:function(error){
			dojo.byId("mainContent").innerHTML="Errore di comunicazione con il server ("+error+")";
		}
	}
	var deferred = dojo.xhrGet(xhrArgs);
}

function submitSearch(){
	searchTerm=dojo.byId("searchTerm").value;
	if (searchTerm !=''){
		ajaxGetSearchResults(searchTerm,1)
	}
}

function submitSearchLibrary(){
	searchTerm=dojo.byId("searchTermLibrary").value;
	if (searchTerm !=''){
		ajaxGetSearchResultsLibrary(searchTerm,1)
	}
}

function ajaxGetAuthors(let, pageNum){
	//setTopLink_allActive();
	closeCollaneTree();
	if (let==''){
		let='a';
	}
	var xhrArgs = {
		url:"/ajaxGetAuthorsDiv/",
		handleAs:"text",
		content: {"let":let,"p":pageNum},
		load:function(response){
			dojo.byId("mainContent").innerHTML=response;
		},
		error:function(error){
			dojo.byId("authorsList").innerHTML="Errore di comunicazione con il server ("+error+")";
		}
	}
	var deferred = dojo.xhrGet(xhrArgs);
}

function ajaxGetVolumiAutoreDiv (autoreAnagraficaPk, pageNum){
	closeCollaneTree();
	var xhrArgs = {
		url:"/ajaxGetVolumiAutoreDiv/",
		handleAs:"text",
		content: {"autoreAnagraficaPk":autoreAnagraficaPk,"p":pageNum},
		load:function(response){
			dojo.byId("mainContent").innerHTML=response;
		},
		error:function(error){
			dojo.byId("mainContent").innerHTML="Errore di comunicazione con il server ("+error+")";
		}
	}
	var deferred = dojo.xhrGet(xhrArgs);
}

function ajaxGetVolume(isbn13){
	var xhrArgs = {
		url:"/ajaxGetVolume_div/",
		handleAs:"text",
		content: {"isbn13":isbn13},
		load:function(response){
			dojo.byId("mainContent").innerHTML=response;

			var ShareThis = SHARETHIS.addEntry(
				{'title' : dojo.byId("btnShareThis").title,
				 'summary' :'',
				 'url' : 'http://www.vitaepensiero.it/volumi/'+isbn13+'/'
				}, {button:false}
			);
			//Tie customized button to ShareThis button functionality.
			var ShareThisBtn = document.getElementById("btnShareThis"); //Replace 'btnShareThis' with your button ID
			ShareThis.attachButton(ShareThisBtn);
			
		},
		error:function(error){
			dojo.byId("mainContent").innerHTML="Errore di comunicazione con il server ("+error+")";
		}
	}
	var deferred = dojo.xhrGet(xhrArgs);
}

function addVolumeToCart(isbn13){
	var xhrArgs = {
		url:"/ajaxAddVolumeToCart/",
		handleAs:"text",
		content: {"isbn13":isbn13},
		load:function(response){
			dojo.byId("CartResponse").innerHTML="Questo volume &#232; stato aggiunto al carrello";
			dojo.byId("CartResponse").style.display='block';
		},
		error:function(error){
			dojo.byId("mainContent").innerHTML="Errore di comunicazione con il server ("+error+")";
			dojo.byId("CartResponse").style.display='none';
		}
	}
	var deferred = dojo.xhrPost(xhrArgs);
}
	
