$(document).ready(function(){
	try 
	{
		$('.galleriafoto .jcarousel-skin-ie7 ').jcarousel();
		$('.galleriafoto ul li a').lightBox();
	}
	catch (e) {}
	$('.header').pngFix();
	$('#headerBottom').pngFix();	
$("#message").hide();	
	
});
var Lait = {
	
	WordpressAutoLogin : function (susername, spassword, autoredirect, returl) {
		if (autoredirect)
		{
			$.get("/wordpress/culturalazio_login.php", { username: susername, password: spassword }, function () {
				if (returl != '')
				{
					document.location.href = returl;
				}
				else 
					document.location.href = "/wordpress/wp-admin/";
			} );
		}
		else
		{
			$.get("/wordpress/culturalazio_login.php", { username: susername, password: spassword }, function () {
			} );
		}
	},
	
	WordpressAutoLogout : function () {
		$.get("/wordpress/culturalazio_logout.php");
	},
	
	DoSubscribe : function(){
		var txtName				= $("#txtName").val() ;
		var txtLastName			= $("#txtLastName").val() ;
		var txtEmail			= $("#txtMail").val() ;
		var txtLogin			= $("#txtUserName").val() ;
		var txtPassword			= $("#txtPassword").val() ;
		var txtConfirmPassword	= $("#txtPasswordConfirm").val() ;
		var txtDateOfBirth		= $("#txtDateOfBirth").val() ;
		
		var uri					= "/site/registrazione.aspx" ;
		
		var bSuccess = "false";
		
		$("#frmRegistrazione input").each(function(i){
			if( ($(this).attr("id") != "txtName") && ($(this).attr("id") != "txtLastName") && ($(this).attr("id") != "txtDateOfBirth") )
			{
				if($(this).val() == "" ) 
				{
					$(this).parent().find("span").attr("style","visibility:visible;") ;
					bSuccess = false;
				}
				else 
				{
					$(this).parent().find("span").attr("style","visibility:hidden;") ;
				}
			}
			
		}) ;
		
		$("#frmRegistrazione input").each(function(i){
			if( ($(this).attr("id") != "txtName") && ($(this).attr("id") != "txtLastName") && ($(this).attr("id") != "txtDateOfBirth") )
			{
				if($(this).val() != "" ) 
				{
					bSuccess = "true";
					
				}
				else 
				{
					bSuccess = "false";
					//alert("campi vuoti") ;
				}
			}
		}) ;
		
		if(($("#txtPassword").val() != $("#txtPasswordConfirm").val()) || ($("#txtPassword").val() == ""  || $("#txtPasswordConfirm").val() == "") )
		{
			$("#txtPasswordConfirm").parent().find("span").attr("style","visibility:visible;") ;
			bSuccess = "false" ;
			//alert("con") ;
		}
		else
		{
			bSuccess = "true" ;
			//alert("no"); 
		}
		
		var email = document.getElementById('txtMail');
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(email.value)) 
		{
			
			$(email).parent().find("span").attr("style","visibility:visible;") ;
			email.focus ;
			bSuccess = false ;
			//alert("mail") ;
		}
		
		
		var dateb = document.getElementById('txtDateOfBirth');
		var filterDate = /(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d/;
		
		if (!filterDate.test(dateb.value) && dateb.value != "" ) 
		{
			$(dateb).parent().find("span").attr("style","visibility:visible;") ;
			bSuccess = false ;
		}
		else
		{
			
			//alert("") ;
		
			$(dateb).parent().find("span").attr("style","visibility:hidden;") ;
		}
		//alert(bSuccess) ;
			
		if(bSuccess == "true")
		{
			try{
			$.ajax({
						type: 'POST',
						url: uri,
						data: {name: txtName, lastname: txtLastName, email: txtEmail, 
								login: txtLogin, password: txtPassword, birthDate: txtDateOfBirth},
						dataType: 'xml',
						error: function(request, type) {
							alert(type);
						},
						success: function(responseXml) {
						var bResult = $("ContentHTML",responseXml).text() ;
						//alert(bResult) ;
						
						if (bResult == "true")
							{
								$("#frmRegistrazione").fadeOut(function(){
									$("#message").fadeIn();
								}) ;	
							}
							else
							{
								alert("Utente o E-Mail esistente.") ;
								
							}
						}
					}); 
				}
				catch(e){alert(e) ;}
		}
	
	}
}

