function http_fill_div(url, vars, div_container){
	//$(div_container).html("<div class='loading'>loading</div>");
	$.ajax({
	   type: "POST",
	   url: url,
	   data: vars,
	   success: function(msg){
	     $(div_container).html(msg);
	   }
	});
}

function req_login(username, password){
	$.get("login.php", { username:username, password:password, action:"validate_login"}, function(response){
		switch(response){
			case "USERPRO_AUTHENTICATED":
				location.href = "http://www.anniluce.info/areapro"; 
			break;
			case "USER_AUTHENTICATED":
				location.reload(); 
			break;
			case "USER_NOT_APPROVED":
				alert("mail di conferma");
			break;
			default:
				//gestione degli errori da implementare
				alert(response);
		}
	}, "text");
}


function req_login_oldsite(username, password){
	$.post("oldsite/accesso_agenti.php", { utente:username, pad:password}, function(response){
		http_fill_div('oldsite_frame.php', null, '#content');
	});
}

function open_collection(id_collection, pagina){
	http_fill_div('/incl_collection.php', {collection: id_collection, pagina: pagina}, '#structure');
}

function open_detail(id_articolo, pagina, id_collezione){
	http_fill_div('/incl_detail.php', {id_articolo: id_articolo, pagina: pagina, id_collezione: id_collezione}, '#structure');
}

function req_logout(){
	$.get("login.php", { action:"logout"}, function(response){
		if(response=='USER_DEAUTHENTICATED'){
			location.reload(); 
		} else {
			//gestione degli errori da implementare
		}
	}, "text");
}

function reset_login(){
	$("#username").val("");
	$("#password").val("");
}

function registra_nuovo_utente(){
		$.getScript("libs/registr_form.js");
}

function auth_dati_personali(){
    if ($('#autorizzazione').is(':checked')) {
        $('#prosegui').attr('disabled', false);
    } else {
        $('#prosegui').attr('disabled', true);
    } 
}

function check_captcha(){
	code = $("#code").val();
	$.get("captcha/securimage_check.php", { captcha_code: code}, function(response){
		if(response!='OK'){
			$("#code").val("");
			$("#code").focus();
			$("#captcha_error").show();
		} else {
			$("#captcha_error").hide();
		}
	}, "text");	
}

function conferma_password(){
	if($("#pwd").val()!=$("#pwd2").val()){
		$("#pwd").val("");
		$("#pwd2").val("");
		$("#pwd").focus();
		$("#pwd_conferma").show();
	} else {
		$("#pwd_conferma").hide();
	}
}

function check_unique_username(newname){
	$.get("registrazione.php?action=username_check", { username: newname}, function(response){
		if(response=='USER_EXIST'){
			$("#username").focus();
			$("#username_error").show();
		} else {
			$("#username_error").hide();
		}
	}, "text");
}

function reinvia_approvazione(email){
	var url = "registrazione.php?action=mail_resended&email="+email;
	http_fill_div(url, null, "#login_messaggi");
}

function user_page(user){
	var url = "login.php?action=user_page&user="+user;
	http_fill_div(url, null, "#content")
}

function jfck(text_area){ //da testare, nn sembra funzionare!
	var fckpath = document.location.pathname+"ckeditor/";
	$.fck.path = fckpath;
	$.fck.waitFor = 1;
	$(text_area).fck();
}

function update_list(page, act_name, dest_div, page_num){
	http_fill_div(page, {action: act_name, page:page_num}, dest_div);
}

function section(sezione){
	http_fill_div("/navigazione.php", {section: sezione}, "#content");
}

function az_section(page){
	http_fill_div(page+".php", null, "#content_azienda");
}
function is_empty(id_input){
	var vresult = false;
	if($(id_input).val() == ""){
		vresult = true;
	}
	return vresult;
}
