
function SubmitForm(divpadre, formName, load, fields, thanks, secure, var1)
{
	var d = new Date()
	var param = d.getTime();
	var Secure = jQuery('#'+secure);
	var DivPadre = jQuery('#'+divpadre);	
	var Form = jQuery('#'+formName);
	var Load = jQuery('#'+load);
	var Field = jQuery('#'+fields);
	var Thanks = jQuery('#'+thanks);
	var Var1 = jQuery('#'+var1);	
	
	jQuery(Secure).val(param); // -> <input type="hidden" name="secure" id="secure" value="">
	
	toConsole('parametro Sicurezza: '+param);
	toConsole('div richiesto: #'+divpadre);	
	toConsole('div richiesto: #'+secure);	
	toConsole('div richiesto: #'+formName);	
	toConsole('div richiesto: #'+load);	
	toConsole('div richiesto: #'+fields);					
	toConsole('div richiesto: #'+thanks);	
	
	//inizio validazione
	var error_found = 0;			
	
	if(error_found==0)
	{

		var options = { 
		
			beforeSubmit: function()
			{
				toConsole('invio in corso ...');
				jQuery(Field).fadeOut();
				jQuery(Var1).fadeOut();								
				jQuery(Load).fadeIn();				

			},
			resetForm: true,
			error: function()
			{
				toConsole('Errore di invio');
				jQuery(Load).fadeOut();
				jQuery(Thanks).html('<p>Attenzion! Errore di invio!</p>');
				return false;
			},
		    success: function() 
		    { 			    			
		    	toConsole('email inviata');   
				jQuery(Thanks).fadeIn();
				jQuery(Load).fadeOut();								
		    	
		    	return false; 	     
		    } 
		    
		}; 	
		
		jQuery(Form).ajaxForm(options); 
	    jQuery(Form).ajaxSubmit(options);
		    
	}	
	return false;

}


function FormatInput(){
	// css via js per ovviare al probl di visualizzazione su ie6
	jQuery('input').css('border', '1px solid #bbb').css('font-size','13px');
	jQuery('input').css('padding', '3px');
	jQuery('input').css('margin','0px 3px 0px 3px');	
    jQuery('input:button').css('padding', '3px').css('cursor','pointer').css('background-color','#dfdfdf');	
    jQuery('input:reset').css('padding', '3px').css('cursor','pointer').css('background-color','#dfdfdf');
    jQuery('input:submit').css('padding', '3px').css('cursor','pointer').css('background-color','#dfdfdf');
    jQuery('input:checkbox').css('border', '0px').css('margin','0px 3px 0px 3px');
    jQuery('textarea').css('border', '1px solid #bbb');
    jQuery('select').css('border', '1px solid #bbb');
   	jQuery('.b1').css('background-color', '#ccc').css('border', '1px solid #777');
}


function showDialog(div, _ID){
	if(_ID != ''){
		jQuery(div).html("<div class='Generaloading'></p>").load('index.php?l=it&option=content&id='+_ID+'&noheader=1&nofooter=1').dialog("open"); 
	}else{
		jQuery(div).dialog("open"); 		
	}
	
	
	return false;
}

/*****************************************************************************************/
function mainHeight()
{
try
{
// inizio dichiarazione variabili
	var main = $j('#main');
	var head = $j('#head');
	var colonnaSx = $j('#colonnaSx');
	var container = $j('#container');
	var colonnaDx = $j('#colonnaDx');
	var footer = $j('#footer');

	var colonnaSx_height;
	var container_height;
	var colonnaDx_height;
	var column_height;
	var total_height;
// fine dichiarazione variabili

// inizio assegnazione valori di default
	if(colonnaSx) colonnaSx_height = colonnaSx.height(); else colonnaSx_height = 0;
	if(container) container_height = container.height(); else container_height = 0;
	if(colonnaDx) colonnaDx_height = colonnaDx.height(); else colonnaDx_height = 0;
// fine assegnazione valori di default
//	inizio calcolo altezza maggiore
	column_height = Math.max((colonnaSx_height), container_height, colonnaDx_height);
//	inizio calcolo altezza maggiore
    
	the_height = column_height;
	return the_height;
}
catch(e) {toDebug(e.toString());}
}

function positionMainElements(columnHeight, animate)
{
try
{
	var headHeight = $('#head').height();
	var footerHeight = $('#footer').height();
	var default_height = mainHeight();
	var final_height;
	var in_animation;
	if(animate) in_animation = animate; else animation = false;
//	Se passo come parametro un valore da aggiungere all'altezza delle colonne ...
	if(columnHeight) final_height = default_height + columnHeight;
//	.. .altrimenti
	else final_height = default_height;
	
	totalHeight = headHeight + final_height + footerHeight;	
	
//	Aumento dimensioni con animazione
	if(in_animation)
	{
		$('#colonnaSx').animate({'height':final_height},1000);
		$('#container').animate({'height':final_height},1000);
		$('#colonnaDx').animate({'height':final_height},1000);
		$('#footer').animate({'top':headHeight + final_height},1000);
		$('#main').animate({'height':totalHeight},1000);
		
	}
//	Aumento dimensioni senza animazione
	else
	{
		$('#colonnaSx').css({'top':headHeight+'px'});
		$('#colonnaSx').height(final_height);
		
		$('#container').css({'top':headHeight+'px'});
		$('#container').height(final_height);
		
		$('#colonnaDx').css({'top':headHeight+'px'});
		$('#colonnaDx').height(final_height);
		
		$('#footer').css({'top':headHeight + final_height +'px'});
		$('#main').height(totalHeight);
        setContentHeight();
	}
}
catch(e) {toDebug(e.toString());}
}

function setContentHeight()
{
try
{
    var best_height = Math.max($('#content').parent().height(),$('#offerte').height()+40);
    if(best_height > $('#offerte').height())
        $('#offerte').height(best_height);
    else
        $('#content').parent().height(best_height);
}
catch(e) {toDebug(e.toString());}
}
/*****************************************************************************************/
function loadContent(url)
{
try
{
    $.ajax({
        url: url+'#content',
        success: function(data, textStatus) 
        {
            $('#content').html(data);
        }
    });
}
catch(e) {toDebug(e.toString());}
}


function tableFormat()
{
try
{
    var table = $('#contenuto table');
    table.each(function()
    {
        $('tr:even',$(this)).css('background-color','#e4eef4');
        $('tr:even td',$(this)).css('border-color','#ffffff');
    });
}
catch(e) {toDebug(e.toString());}
}


function playHiddenBox()
{
try
{
    var box = $('#hidden-box');
    var contents = $('#hidden-contents');
    var linguette = $('#linguette');
    var initial_right = -156;
    
    if(!box.is('.visible')) box.css('right',-linguette.width());
    else box.css('right',initial_right);
    
    /* mostro il box visibile */
    contents.children().each(function()
    {
        if($(this).is('.visible')) $(this).show();
        else $(this).hide();
    });
    
    /* aggancio evento alle linguette */
    linguette.children().each(function()
    {
        $(this).css('cursor','pointer');
        
        /* dichiaro il box di riferimento della linguetta */
        var box_to_show = '#'+$(this).attr('ref');
        
        /* aggancio il click */
        $(this).bind('click',function()
        {

            /* ciclo fra gli elementi da analizzare */
            contents.children().each(function()
            {
                /* se l'elemento non è quello interessato dalla linguetta */
                if(!$(this).is(box_to_show)) 
                {
                    $(this).removeClass('visible');
                    $(this).slideUp();
                }
                /* se l'elemento è quello interessato dalla linguetta */
                else 
                {
                    /* 
                    scontrollo se l'elemento è già visibile e se lo è toggle del box
                    altrimenti toggle del box e aggiunta di classe
                    */
                    if($(this).is('.visible')) 
                    {
                        toggleBoxPosition(box, linguette, initial_right);
                    }
                    else 
                    {
                        if(!box.is('.visible')) toggleBoxPosition(box, linguette, initial_right);
                        $(this).addClass('visible');
                    }
                    $(this).slideDown();
                }
            });
        });
    });
}
catch(e) {toDebug(e.toString());}
}

/* questa sposta il box dietro o di fianco al main a seconda della sua posiziona */
function toggleBoxPosition(box, linguette, initial_right)
{
try
{
    if(parseInt(box.css('right')) < -linguette.width())
    {
        box.animate({'right': -linguette.width()}, 700);
        box.removeClass('visible');
    }
    else
    {
        box.animate({'right': initial_right}, 700);
        box.addClass('visible');
    }
}
catch(e) {toDebug(e.toString());}
}



