$(document).ready(init);
function init()
{
$("input.stdinput,textarea.stdinput,input.login-form").focus(function() {$(this).addClass("stdinput-sel");}).blur(function() {$(this).removeClass("stdinput-sel");});

$('#sPayement-cd').click(function(){$('#bonifico-alert').slideDown();});

if( !(jQuery.browser.msie && (jQuery.browser.version < 7)) ){
 
$("#tabella").tablesorter({
		sortColumn: 'name',			
		sortClassAsc: 'headerSortUp',		
		sortClassDesc: 'headerSortDown',	
		headerClass: 'header',			
		widgets: ['zebra'],	
		stripRowsOnStartUp: true,		
		columnParser: [[3,'currency']],
		dateFormat: 'dd/mm/yyyy' 
});
}
$("#tabella tr").Abilita();
$(".select-all").funcAll();
$(".select-none").funcNone();
$("#optionbox").numeric(",");
$("#sCap").numeric();
$('.conferma').confirm_prompt("Sei sicuro? Questa operazione sarà irreversibile.");
}
$.fn.confirm_prompt = function(stringa) {
newlocation = $(this).get(0);	
this.click(function() {
	 if (confirm(stringa)) {
      window.location = newlocation;
    }else{
	return false;
	}});
}
$.fn.funcAll = function(){
	$(this).click(function() {
$("#tabella tr").find("input[@type='checkbox']").each(
				function()
				{
					this.checked = true;					
					Conta();
				});	});
	
}
$.fn.funcNone = function(){
	$(this).click(function() {
$("#tabella tr").find("input[@type='checkbox']").each(
				function()
				{
					
					this.checked = false;					
					Conta();
				});	});
	
}


$.fn.Abilita = function(){
Conta();
$(this).find("input[@type='checkbox']").hide();
this.mouseover(function() {
$(this).attr("id","over");
})

.mouseout(function() {
$(this).attr("id","");
})

.click(function(){
var Contenitore = $(this);
$(this).find("input[@type='checkbox']").each(
				function()
				{
					//Contenitore.id("selected");
					this.checked = !this.checked;					
					Conta();
				});




});
}
function Conta(){
var counter = 0
//var importo = 0
$("#tabella tr").find("input[@type='checkbox']").each(function()
				{
					//alert(this.checked);
					if (this.checked){					
					$(this).parent().parent().addClass("available-selected");
					counter++;					
				    somma = parseFloat($(this).parent().prev().prev().html());
				   // importo = importo +  somma;
									
					}else{
					$(this).parent().parent().removeClass("available-selected");
					}
				});				

if (counter == 0){
	var Messaggio = "Puoi selezionare una delle opzioni disponibili";
	counter = "";
}
if (counter == 1){
	var Messaggio = " Opzione selezionata";
}
if (counter > 1){
	var Messaggio = " Opzioni selezionate";
}
$(".optioncount").html(counter + Messaggio);
}