function apriPrivacy(){
	apriModale();
	$.get(
		'privacy.html',
		null,
		function(response_data){
			$('#finestraModale .messaggio').html(response_data);
			$('#finestraModale .messaggio').fadeIn();
		}
	);
}

function apriModale(){
//	$('select').hide(); // nascondo select per problema ie6			
/*	$('#modalBoxOverlay').show();
	var offset =$('#finestraModale').outerHeight()/2;	
	if(typeof document.body.style.maxHeight == "undefined") {
		// IE6
		var viewportheight = document.documentElement.clientHeight //altezza area visibile
		var scrOfY = document.documentElement.scrollTop; //scroll verticale
		var topIe6 =scrOfY+(viewportheight/2)-offset;		
		$('#finestraModale').css({'top':topIe6+'px'}).fadeIn();
	}else{
		// tutti gli altri
		$('#finestraModale').css({'top':'50%', 'margin-top':'-'+offset+'px'}).fadeIn();
	};
	*/
	$('#finestraModale .messaggio').html('<img src="img/spinner.gif" />');
	$.blockUI({message: $('#finestraModale'), css : {height: '300px', 'cursor': 'auto', 'width': '400px'}});
};
function chiudiModale(){
/*	$('select').show(); 
	$('#modalBoxOverlay').hide();
	$('#finestraModale').hide();
	$('.messaggio').hide();*/
	$.unblockUI();
};

function showTroubleTickets(){
	$.get(
		'ajax/troubleticket_manager.php?action=show&id_richiesta='+$.query.get('id'),
		null,
		function(response_data){
			if(response_data['success']==true){
				$('#troubletickets p').html(response_data['response']);
			}
		},
		'json'
	);
}

function showAttachments(){
	$.get(
		'ajax/allegati_manager.php?action=show&id_richiesta='+$.query.get('id'),
		null,
		function(response_data){
			if(response_data['success']==true){
				$('#attachments p').html(response_data['response']);
			}
		},
		'json'
	);
}

function showDownloads(){
	$.get(
		'ajax/downloads_manager.php?action=show&id_richiesta='+$.query.get('id'),
		null,
		function(response_data){
			if(response_data['success']==true){
				$('#downloads').html(response_data['response']);
			}
		},
		'json'
	);
}
function removeAttachments(){
	var data = $('#form_remove_attachments').serialize();
	$.post(
		'ajax/allegati_manager.php?action=remove&id_richiesta='+$.query.get('id'),
		data,
		function(response_data){
			if(response_data['success']==true){
				showAttachments();
			}
		},
		'json'
	);
}
function removeDownloads(){
	var data = $('#form_remove_downloads').serialize();
	$.post(
		'ajax/downloads_manager.php?action=remove&id_richiesta='+$.query.get('id'),
		data,
		function(response_data){
			if(response_data['success']==true){
				showDownloads();
			}else{
				$.blockUI({
					message: response_data['response'],
		            timeout: 3000
				});
			}
		},
		'json'
	);
}
function changeState(new_state){
	$.get(
		'ajax/richieste_manager.php?state='+new_state+'&id_richiesta='+$.query.get('id'),
		null,
		function(response_data){
			if(response_data['success']==false){
				alert(response_data['response']);
			}
			if(response_data['success']==true){
				alert(response_data['response']);
				location.href='home_utente.php';
			}
		},
		'json'
	);
}

function ajaxLogin(){
	apriModale();
	$.get(
		'/ajax/login_manager.php',
		null,
		function(response_data){
			$('#finestraModale .messaggio').html(response_data['response']).show();
		},
		'json'
	);
}

function submitAjaxForm(form_id, url, method, callback){
	var callback_func = function(response_data){
		if(response_data['success']==true){
			$('#finestraModale .messaggio').html(response_data['response']);
		}
	}
	
	if(typeof callback == 'function'){
		callback_func = callback;
	}
	
	var data = $(form_id).serialize();
	$('#finestraModale .messaggio').html('<img src="img/spinner.gif" />');
	$.post(
		url,
		data,
		callback_func,
		'json'
	);
}

function updateComuni(el, obj_id){
	var id = el.options[el.selectedIndex].value;
	$.get(
		'ajax/registrati_manager.php',
		'provincia_id='+id,
		function(response_data){
			$(obj_id).html(response_data);
		},
		'html'
	);
}

var popup = function(o) {

//	o.url = (typeof o.url == 'undefined') ? return : o.url;
	o.width = (typeof o.width == 'undefined') ? screen.width/2 : o.width;
	o.height = (typeof o.height == 'undefined') ? screen.height/2 : o.height;
	if((o.width<=1)&&(o.width>0)){o.width*=screen.width}
	if((o.height<=1)&&(o.height>0)){o.height*=screen.height}
	o.xpos = (typeof o.xpos == 'undefined') ? (screen.width/2)-(o.width/2) : o.xpos;
	o.ypos = (typeof o.ypos == 'undefined') ? (screen.height/2)-(o.height/2) : o.ypos;
	o.xoffset = (typeof o.xoffset == 'undefined') ? 0 : o.xoffset;
	o.yoffset = (typeof o.yoffset == 'undefined') ? 0 : o.yoffset;
	o.name = (typeof o.name == 'undefined') ? 'propup' : o.name;
	o.scrollbars = (typeof o.scrollbars == 'undefined') ? 'no' : o.scrollbars;
	o.resizable = (typeof o.resizable == 'undefined') ? 'no' : o.resizable;
	o.status = (typeof o.status == 'undefined') ? 'no' : o.status;
	o.locat = (typeof o.locat == 'undefined') ? 'no' : o.locat;
	o.toolbar = (typeof o.toolbar == 'undefined') ? 'no' : o.toolbar;

	if(o.xpos == "left"){o.xpos=0;}
	if(o.xpos == "right"){o.xpos = screen.width-o.width;}
	
	if(o.ypos == "top"){o.ypos=0;}
	if(o.ypos == "bottom"){o.ypos = screen.height-o.height;}
	
	o.xpos += o.xoffset;
	o.ypos += o.yoffset;

	var scrollbarstext = 'scrollbars = '+o.scrollbars+",";
	var resizabletext = 'resizable = '+o.resizable+",";
	var statustext = 'status = '+o.status+",";
	var locationtext = 'location = '+o.locat+",";
	var toolbartext = 'toolbar = '+o.toolbar+",";

	features = scrollbarstext+resizabletext+statustext;
	features = features + locationtext+toolbartext;
	features = features + 'width = '+o.width+',height = '+o.height;
	features = features + ',top = ' + o.ypos;
	features = features + ',left = ' + o.xpos;
		
	var win = null;
	win = window.open(o.url, o.name, features);
}

$(document).ready(function(){ 
    $(document).pngFix();
});

function ajaxRecuperoPassword(){
	apriModale();
	$.get(
		'/ajax/recupero_password.php',
		null,
		function(response_data){
			$('#finestraModale .messaggio').html(response_data['response']).show();
		},
		'json'
	);
}
