$(document).ready(function(){
	$.fn.createDialog.defaults = {
		progress: false,
		center: true,
		opacity: 0.7,
		bg: '#90B6CC'
	}
	$("#nuvolette_click").createDialog({
		addr: '/core/nuvoletta.html',
		opacity: 0.9
	});
	
		
	$('div#site_container').ifixpng();

	$('#s1').cycle({ 
    	fx:    'fade',
    	speed:  2500,
    	pause:  1
    });
    $('#s2').cycle({ 
    	fx:    'fade',
    	speed:  1500,
    	pause:  1.5
    });
    $('#sConcept').cycle({ 
    	fx:    'fade',
    	speed:  1500,
    	pause:  1.5
    });
	
	$(".rectangleCorner").corner("bevel tl br 14px");
	$(".rectangleCornerSmall").corner("bevel tl br 14px");
	$("#site_menu ul li").click( function() {
		$("#site_menu ul li ul:visible").hide();
		$(".openMenu").show();
		$(this).children("ul").show();
	});
	$(".onmesecimage li").click( function() {
		$(".onmesecimage li").css("color","");
		$(this).css("color","#cc0000");
		$(".onmeimage img").css("display","none");
		keyimg = $(this).text();
		$("#openLightBoxImg"+keyimg).css("display","block");
	});
	
	$("#FAQ_SECTION li").click( function() {
		//$(this).children("ul").show("slow");
		//$(this).children("ul").slideToggle("slow");
		$("#FAQ_SECTION li ul:visible").hide("slow");
		$(this).children("ul:hidden").show("slow");
	});
	
	$("#objaddtocartsend").click( function() {
		$('#objaddtocart').submit();
	});
	
	$(".selectpayment").click( function() {
		$('#selectpayment').submit();
	});
	
	/*

	$('#sufu_codfiscale').keypress( function() {
		$('#sufu_codfiscale').toUpperCase();
	});
	$('#sufu_email').keypress( function() {
		$('#sufu_email').toUpperCase();
	});
*/
	
	/*var options = { 
        target:        '#output',   // target element(s) to be updated with server response 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse  // post-submit callback 
    };*/
    
    //$('#objaddtocart').ajaxForm(options); 
    //$('#signupformuser').ajaxForm(optionsReg);
    
    $("#signupformuser").validate({
		rules: {
			sufu_nome: "required",
			sufu_cognome: "required",
			sufu_codfiscale: {
				required: true,
				minLength: 16,
				maxLength: 16
			},
			sufu_email: {
				required: true,
				email: true
			},
			sufu_country: "required",
			sufu_password: {
				required: true,
				minLength: 6
			},
			sufu_password_confirm: {
				required: true,
				minlength: 6,
				equalTo: "#sufu_password"
			},
			sufu_citta: "required",
			sufu_provincia: "required",
			sufu_postacode: "required",
			sufu_street: "required",
			agree: "required"
		},
		messages: {
			sufu_nome: "Inserisci il tuo nome",
			sufu_cognome: "Inserisci il tuo cognome",
			sufu_codfiscale: {
				required: "Inserisci Codice Fiscale"
			},
			sufu_email: "Inserisci un indirizzo email valido",
			sufu_country: "Seleziona una nazione",
			sufu_password: {
				required: "Inserisci una password",
				minLength: jQuery.format("Inseire almeno {0} caratteri")
			},
			sufu_password_confirm: {
				required: "Ripeti la password",
				minLength: jQuery.format("Inseire almeno {0} caratteri"),
				equalTo: "Inserisci la password come sopra"
			},
			sufu_citta: "Inserisci la tua citt&agrave;",
			sufu_provincia: "Inserisci il tua provincia",
			sufu_postacode: "Inserisci il codice postale",
			sufu_street: "Inserisci la via",
			agree: "Autorizza:"
		}
	});
	
	$("#signuplogin").validate({
		rules: {
			sufu_email: {
				required: true
			},
			sufu_password: {
				required: true
			}
		},
		messages: {
			sufu_email: "Inserisci la tua email",
			sufu_password: "Inserisci la tua password"
		}
	});
});



// pre-submit callback 
function showRequest(formData, jqForm, options) { 
    
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
 	
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 
    if (confirm('About to submit: \n\n' + queryString)) {
    	return true;
    } else {
       	return false;
    }
 
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
     
} 
 
// post-submit callback 
function showResponse(responseText, statusText)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
 
    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + '\n\nThe output div should have already been updated with the responseText.'); 
}

function pagamento_registrazione() {
	location = "http://www.cartadazucchero.com/index.php?go=registrazioneutente";
}
function pagamento_login() {
	location = "http://www.cartadazucchero.com/index.php?go=login";
}