// ajax per la lista dei rivenditori	
function getRivenditori(page){	
		var regione=document.getElementById('regione').value;
		var prov=document.getElementById('provincia').value;
		var citta=document.getElementById('citta').value;
		page=(page)?page:'';
		document.getElementById('rivenditori_container').innerHTML=getLoadingImage();
		AyaxRequest("ajax_request.php", "POST", "filetocall=rivenditori&regione="+regione+"&provincia="+ prov+"&citta="+citta+"&page=" + page, getRivenditori_HTML);
	}
	function getRivenditori_HTML(){
		document.getElementById('rivenditori_container').innerHTML=this.req.responseText;
	}
	// -------------------------

function getLoadingImage(what){
	if(what=='open'){
		return ('<div style="position: absolute; top: 40%; left: 0%; height: 25%; width: 100%; text-align: center; line-height: 0;"><img src="img/loading.gif" alt="" align="absmiddle" id="loading3" /></div>');
	}else{
		return '<div align="center"><img src="img/loading.gif" alt="" align="absmiddle"/></div>';
	}
	}
function getSelect(what,value){
	if(what=='provincia'){
		AyaxRequest('ajax_request.php', 'POST', 'filetocall=query_comuni&what='+what+'&value='+value, SelectProvincia_html);
	}
	if(what=='citta'){
		AyaxRequest('ajax_request.php', 'POST', 'filetocall=query_comuni&what='+what+'&value='+value, SelectCitta_html);
	}
	if(what=='cap'){
		AyaxRequest('ajax_request.php', 'POST', 'filetocall=query_comuni&what='+what+'&value='+value, SelectCAP_html);
	}
}

function SelectProvincia_html(){
	document.getElementById('provincia_container').innerHTML=this.req.responseText;
	document.getElementById('citta').value='';
	document.getElementById('citta').disabled=true;
}
function SelectCitta_html(){
	document.getElementById('citta_container').innerHTML=this.req.responseText;
}
function SelectCAP_html(){
	document.getElementById('cap').disabled=false;
	document.getElementById('cap').value=this.req.responseText;
}

function getSelect_dyn(what,value){
	if(what=='provincia'){
		AyaxRequest('ajax_request.php', 'POST', 'filetocall=query_comuni&what='+what+'&value='+value+'&dyn=yes', SelectProvinciadyn_html);
	}
	if(what=='citta'){
		AyaxRequest('ajax_request.php', 'POST', 'filetocall=query_comuni&what='+what+'&value='+value+'&dyn=yes', SelectCittadyn_html);
	}
	if(what=='cap'){
		AyaxRequest('ajax_request.php', 'POST', 'filetocall=query_comuni&what='+what+'&value='+value+'&dyn=yes', SelectCAPdyn_html);
	}
}

function SelectProvinciadyn_html(){
	document.getElementById('provincia_container_dyn').innerHTML=this.req.responseText;
	document.getElementById('citta_dyn').value='';
	document.getElementById('citta_dyn').disabled=true;
	document.getElementById('cap_dyn').value='';
	document.getElementById('cap_dyn').disabled=true;
}
function SelectCittadyn_html(){
	document.getElementById('citta_container_dyn').innerHTML=this.req.responseText;
	document.getElementById('cap_dyn').value='';
	document.getElementById('cap_dyn').disabled=true;
}
function SelectCAPdyn_html(){
	document.getElementById('cap_dyn').disabled=false;
	document.getElementById('cap_dyn').value=this.req.responseText;
}

function getCategoriaDetail(id){	
		document.getElementById('catalogo_container').innerHTML=getLoadingImage();
		AyaxRequest('ajax_request.php', 'POST', 'filetocall=catalogo&id_categoria='+id, setCatalogo_html);
	}
function setCatalogo_html(){
		//alert(this.req.responseText);
		document.getElementById('catalogo_container').innerHTML=this.req.responseText;
	}
	// -------------------------
function getProdotti(page,id){	
		document.getElementById('catalogo_prodotti_container').innerHTML=getLoadingImage();
		AyaxRequest('ajax_request.php', 'POST', 'filetocall=catalogo_prodotti&id_categoria='+id+'&page=' + page, setProdotti_html);
	}
function setProdotti_html(){
		document.getElementById('catalogo_prodotti_container').innerHTML=this.req.responseText;
	}
	// -------------------------
function AnteprimaCaricature(id){
	AyaxRequest('ajax_request.php', 'POST', 'filetocall=caricature&id='+id, setCaricature_HTML);
}
function setCaricature_HTML(){
	document.getElementById('caricature_container').innerHTML=this.req.responseText;
}
