var xmlhttp = createXmlHttpRequestObject();
var cacheurl = new Array();
var cachepage = new Array();
var cacheparam = new Array();
var cacheid = new Array();
 
function createXmlHttpRequestObject() {
	// will store the reference to the XMLHttpRequest object
	var xmlHttp;

	// this should work for all browsers except IE6 and older
	try {
		// try to create XMLHttpRequest object
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		// assume IE6 or older
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
				"MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0",
				"MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP");
		// try every prog id until one works
		for ( var i = 0; i < XmlHttpVersions.length && !xmlHttp; i++) {
			try {
				// try to create XMLHttpRequest object
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			} catch (e) {
			}
		}
	}
	// return the created object or display an error message
	if (!xmlHttp)
		alert("Error creating the XMLHttpRequest object.");
	else
		return xmlHttp;
}

// loads a simple string into an area
function loadString(string, id) {
	//document.getElementById(id).innerHTML = string;
	$('#'+id+'').html(string);
}


function getResponseText(url, id, page, stage, fb, rnd) {

	if (id != "" && id != undefined)
	{
		cacheurl.push(url);
		cacheid.push(id);
		cacheparam.push("page="+page + "&stage="+stage+"&fb="+fb+"&rnd="+rnd);
	}

	if ((xmlhttp.readyState == 0 || xmlhttp.readyState == 4) && cacheurl.length > 0)
	{
		
		url = cacheurl.shift();
		id = cacheid.shift();
		var parameter = cacheparam.shift();

		xmlhttp.open("POST",url,true);
		xmlhttp.id = id;
		xmlhttp.onreadystatechange = handleResponseText;
		xmlhttp.setRequestHeader("Pragma", "no-cache");
		xmlhttp.setRequestHeader("Cache-Control", "must-revalidate");
		xmlhttp.setRequestHeader("If-Modified-Since", document.lastModified);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		xmlhttp.send(parameter);
	}
	
}

function handleResponseText(e){
 	if (xmlhttp.readyState == 4) {
		try {
			
			var xmlResponse = xmlhttp.responseText;
			loadString(xmlResponse, xmlhttp.id);
			setTimeout("getResponseText();",100);
		} catch (e) {
			alert("Error reading the response: " + e.toString());
		}
	}
}


function checkRegValuesita(reg) {

	var returnValue = false;
	if (reg == "reg") {

		if ($('#privacy').attr('checked')) {
			$("#privacycheck").css("display", "block");
			var privacycheck = checkValueita('privacy');
		} else {
			$("#privacycheck").css("display", "none");
		}


		var firstnamecheck = checkValueita('firstname');
		if (firstnamecheck == false)
		{
			$('#firstname').val("");
			firstnamecheck = checkValueita('firstname');
		}
		
		if ($.trim($('#firstname').val()) == "") 
			$("#firstnamecheck").css("visibility", "hidden");
		else
			$("#firstnamecheck").css("visibility", "visible");

		var lastnamecheck = checkValueita('lastname');
		if (lastnamecheck == false)
		{
			$('#lastname').val("");
			lastnamecheck = checkValueita('lastname');
		}

		if ($.trim($('#lastname').val()) == "") 
			$("#lastnamecheck").css("visibility", "hidden");
		else
			$("#lastnamecheck").css("visibility", "visible");
			
		mailtest = $('#mail').val();
		var mailvalue = mailtest.match(/^[a-zA-Z0-9]+([a-zA-Z0-9_-])*([.][a-zA-Z0-9_-]+)*[@][a-zA-Z0-9_-]+([.][a-zA-Z0-9_-]+)*[.][a-zA-Z]{2,4}$/);	
		if (mailvalue == false)
		{
			$('#mail').val("");
		}
			
		var telcheck = checkValueita('teleita');
		if (telcheck == false)
		{
			$('#tele1').val(""); 
			$('#tele2').val("");
			telcheck = checkValueita('teleita');
		}
		
		if ($.trim($('#tele1').val()) == "" && $.trim($('#tele2').val()) == "") 
			$("#telecheck").css("visibility", "hidden");
		else
			$("#telecheck").css("visibility", "visible");
		
		
		var byear = $('#birthyear').val();
		var bday = $('#birthday').val();
		var bmonth = $('#birthmonth').val();
		var currentdate = new Date();
		var cyear = currentdate.getFullYear();
		
		var birthcheck = checkValueita('birthday');
		if (bday = '1' && bmonth == '01' && byear == cyear) 
			$("#birthcheck").css("visibility", "hidden");
		else
			$("#birthcheck").css("visibility", "visible");


		if ($.trim($('#fiscale').val()) == "") 
			$("#fischeck").css("visibility", "hidden");
		else
			$("#fischeck").css("visibility", "visible");
			
		var cittacheck = checkValueita('citta');
		if (cittacheck == false)
		{
			$('#citta').val("");
			$('#cittanr').val("");
			cittacheck = checkValueita('citta');
		}
		
		if ($.trim($('#citta').val()) == "" && $.trim($('#cittanr').val()) == "") 
			$("#cittacheck").css("visibility", "hidden");
		else
			$("#cittacheck").css("visibility", "visible");
			
		var capcomprocheck = checkValueita('capcomunepro');
		if (capcomprocheck == false)
		{
			$('#cap').val("");
			$('#comune').val("");
			$('#provincia').val("");
			capcomprocheck = checkValueita('capcomunepro');
		}
		
		if ($.trim($('#cap').val()) == "" && $.trim($('#comune').val()) == "" && $.trim($('#provincia').val()) == "") 
			$("#capcomprocheck").css("visibility", "hidden");
		else
			$("#capcomprocheck").css("visibility", "visible");		
			

		if ($.trim($('#nick').val()) == "") 
			$("#usercheck").css("visibility", "hidden");
		else
			$("#usercheck").css("visibility", "visible");
		
		if ($.trim($('#mail').val()) == "") 
			$("#mailcheck").css("visibility", "hidden");
		else
			$("#mailcheck").css("visibility", "visible");
	
		if ($.trim($('#pw').val()) == "") 
			$("#passcheck").css("visibility", "hidden");
		else
			$("#passcheck").css("visibility", "visible");
	
		if ($.trim($('#pwconf').val()) == "") 
			$("#pass2check").css("visibility", "hidden");
		else
			$("#pass2check").css("visibility", "visible");
			
			
			
		usertest = $('#nick').val();
		uservalue = usertest.match(/^[a-z\d_\d.]{4,16}$/i);
		if (uservalue == false)
		{
			$('#nick').val("");
		}
		
		pwtest = $('#pw').val();
		pwvalue = pwtest.match(/^[a-z\d_\d.\x20-\x7e]{4,16}$/i);
		if (pwvalue == false)
		{
			$('#pw').val("");
		}
				
		pw2test = $('#pwconf').val();
		pw2value = pw2test.match(/^[a-z\d_\d.\x20-\x7e]{4,16}$/i);
		if (pw2value == false)
		{
			$('#pwconf').val("");
		}
		
		
			
	} else {
		
		var usercheck = checkValueita('user');
		var emailcheck = checkValueita('mail');
		var passcheck = checkValueita('pass');
		var pass2check = checkValueita('pass2');
		var privacycheck = checkValueita('privacy');
		var capcomprocheck = checkValueita('capcomunepro');
		var cittacheck = checkValueita('citta');
		var fischeck = checkValueita('fiscale');
		var birthcheck = checkValueita('birthday');
		var telcheck = checkValueita('teleita');
		var lastnamecheck = checkValueita('lastname');
		var firstnamecheck = checkValueita('firstname');
	}

	if (reg =="sub") {
		/*$("#firstnamecheck").css("visibility", "visible");
		$("#lastnamecheck").css("visibility", "visible");
		$("#mailcheck").css("visibility", "visible");
		$("#telecheck").css("visibility", "visible");
		$("#birthcheck").css("visibility", "visible");
		$("#usercheck").css("visibility", "visible");
		$("#fischeck").css("visibility", "hidden");
		$("#cittacheck").css("visibility", "visible");
		$("#capcomprocheck").css("visibility", "visible");*/
		
		var usercheck = checkValueita('user');
		var emailcheck = checkValueita('mail');
		var passcheck = checkValueita('pass');
		var pass2check = checkValueita('pass2');
		var privacycheck = checkValueita('privacy');
		var capcomprocheck = checkValueita('capcomunepro');
		var cittacheck = checkValueita('citta');
		var fischeck = checkValueita('fiscale');
		var birthcheck = checkValueita('birthday');
		var telcheck = checkValueita('teleita');
		var lastnamecheck = checkValueita('lastname');
		var firstnamecheck = checkValueita('firstname');
	}
		

	if(emailcheck && usercheck && passcheck && pass2check && firstnamecheck && lastnamecheck && telcheck && cittacheck && capcomprocheck && fischeck && privacycheck && birthcheck) {
		returnValue = true;
	}
	var theobj = document.getElementById('fiscale');
	var fiscalcheck =true;
	if ($("#fiscale").val() != "")
		fiscalcheck = checkCF(theobj, true); 
	else {
		if (reg =="sub") {
			$("#fischeck").css("visibility", "visible");
			$("#fischeck").html("il campo &egrave; obbligatorio");
		}
		else
		{
			$("#fischeck").css("visibility", "hidden");
		}
	}

	if (fiscalcheck == false)
	{
		if (reg == "reg") 
		{
			$('#tele2').val("wrong code");
		}
		else
		{
			$("#fischeck").css("visibility", "visible");
			$("#fischeck").addClass("invalid");
			$("#fischeck").html("il campo non &egrave; corretto");
			returnValue = false;
		}
	} 
	if (reg == 'sub' && returnValue == false)
		alert("un campo non è corretto");
	
	return returnValue;
}

function checkitaPWValues(pw) {
	
	var returnValue = false;

	if (pw == "pw") {

		if ($.trim($('#oldpw').val()) == "") 
			$("#passoldcheck").css("visibility", "hidden");
		else
			$("#passoldcheck").css("visibility", "visible");
			
		if ($.trim($('#pw').val()) == "") 
			$("#passcheck").css("visibility", "hidden");
		else
			$("#passcheck").css("visibility", "visible");
	
		if ($.trim($('#pwconf').val()) == "") 
			$("#pass2check").css("visibility", "hidden");
		else
			$("#pass2check").css("visibility", "visible");
			
	} else {
		
		var passcheck = checkValueita('pass');
		var pass2check = checkValueita('pass2');
		var passoldcheck = checkValueita('pass3');
		
	}

	if(passcheck && pass2check && passoldcheck) {
		returnValue = true;
	} 

	return returnValue;
	
}

function arrHasDupes( A ) {                          // finds any duplicate array elements using the fewest possible comparison
	var i, j, n;
	n=A.length;
                                                     // to ensure the fewest possible comparisons
	for (i=0; i<n; i++) {                        // outer loop uses each item i at 0 through n
		for (j=i+1; j<n; j++) {              // inner loop only compares items j at i+1 to n
			if (A[i]==A[j]) return true;
	}	}
	return false;
}

function checkitaEmailValues() {

	var returnValue = false;
	var allempty = true;
	var dublicated = new Array();


	for (i=1;i<26;i++){
		
		returnValue = checkValueita('mails', $('#'+i+'_mail').val(), i+'_mailcheck');
		
		if ($.trim($('#'+i+'_mail').val()) != "" && allempty)
		{
			allempty = false;
			
		}

		if ($.trim($('#'+i+'_mail').val()) != "")
			dublicated.push($.trim($('#'+i+'_mail').val()));

		if (!returnValue)
		{
			break;
		}
	}

	if (arrHasDupes(dublicated))
	{
		$("#maildublicate").css("visibility", "visible");
		$("#maildublicate").addClass("invalid");
		$("#maildublicate").html("alcuni indirizzi email inseriti sono uguali tra loro");
		returnValue = false;
	} else {
		$("#maildublicate").css("visibility", "hidden");
	}
	
	
	if (allempty)
		returnValue = false;
	
	return returnValue;
}



function checkValueita(element, value, checkid) {
	
	var inhalt, ergebnis; 
	var returnvalue = false;
	switch(element) {
		case "mail":

			inhalt = $('#mail').val();
			ergebnis = inhalt.match(/^[a-zA-Z0-9]+([a-zA-Z0-9_-])*([.][a-zA-Z0-9_-]+)*[@][a-zA-Z0-9_-]+([.][a-zA-Z0-9_-]+)*[.][a-zA-Z]{2,4}$/);
			if(ergebnis) {
				$("#mailcheck").css("visibility", "hidden");
				$("#mailcheck").removeClass("invalid");
				$("#mailcheck").html("corretto");
				returnValue = true;
			} else if(!ergebnis && inhalt != "") {
				$("#mailcheck").css("visibility", "visible");
				$("#mailcheck").addClass("invalid");
				$("#mailcheck").html("il campo non &egrave; corretto");
				returnValue = false;
			} else {
				
				if (value == 'direct')
				{
					$("#mailcheck").css("visibility", "hidden");
				} else {
					$("#mailcheck").css("visibility", "visible");
					$("#mailcheck").addClass("invalid");
					$("#mailcheck").html("il campo &egrave; obbligatorio");
				}
				returnValue = false;
			}
			break;
		case "mails":
			ergebnis = value.match(/^[a-zA-Z0-9]+([a-zA-Z0-9_-])*([.][a-zA-Z0-9_-]+)*[@][a-zA-Z0-9_-]+([.][a-zA-Z0-9_-]+)*[.][a-zA-Z]{2,4}$/);
			if(ergebnis) {
				$("#"+checkid+"").css("visibility", "hidden");
				$("#"+checkid+"").removeClass("invalid");
				$("#"+checkid+"").html("corretto");
				returnValue = true;
			} else if(!ergebnis && inhalt != "") {
				$("#"+checkid+"").css("visibility", "visible");
				$("#"+checkid+"").addClass("invalid");
				$("#"+checkid+"").html("il campo non &egrave; corretto");
				returnValue = false;
			} else {
				$("#"+checkid+"").css("visibility", "visible");
				$("#"+checkid+"").addClass("invalid");
				$("#"+checkid+"").html("il campo &egrave; obbligatorio");
				returnValue = false;
			}
			if ($.trim(value) == "")
			{
				$("#"+checkid+"").css("visibility", "hidden");
				returnValue = true;
			}
			break;
		case "user":

			inhalt = $('#nick').val();
			ergebnis = inhalt.match(/^[a-z\d_\d.]{4,16}$/i);
			if(ergebnis) {
				$("#usercheck").css("visibility", "hidden");
				$("#usercheck").removeClass("invalid");
				$("#usercheck").html("corretto");
				returnValue = true;
			} else if(!ergebnis && inhalt != "") {
				$("#usercheck").css("visibility", "visible");
				$("#usercheck").addClass("invalid");
				$("#usercheck").html("Lunghezza minima 4 caratteri");
				returnValue = false;
			} else {
				if (value == 'direct')
				{
					$("#usercheck").css("visibility", "hidden");
				} else {
					$("#usercheck").css("visibility", "visible");
					$("#usercheck").addClass("invalid");
					$("#usercheck").html("il campo &egrave; obbligatorio");
				}
				returnValue = false;
			}
			break;
		case "pass":
			inhalt = $('#pw').val();
			ergebnis = inhalt.match(/^[a-z\d_\d.\x20-\x7e]{4,16}$/i);
			if(ergebnis) {
				$("#passcheck").css("visibility", "hidden");
				$("#passcheck").removeClass("invalid");
				$("#passcheck").html("corretto");
				returnValue = true;
			} else if(!ergebnis && inhalt != "") {
				$("#passcheck").css("visibility", "visible");
				$("#passcheck").addClass("invalid");
				$("#passcheck").html("il campo non &egrave; corretto (almeno 4 segni)");
				returnValue = false;
			} else {
				if (value == 'direct')
				{
					$("#passcheck").css("visibility", "hidden");
				} else {
					$("#passcheck").css("visibility", "visible");
					$("#passcheck").addClass("invalid");
					$("#passcheck").html("il campo &egrave; obbligatorio");
				}
				returnValue = false;
			}
			if ($.trim($('#pw').val()) == "") {
				if (value == 'direct')
				{
					$("#pass2check").css("visibility", "hidden");
				} else {
					$("#pass2check").css("visibility", "visible");
					$("#pass2check").addClass("invalid");
					$("#pass2check").html("il campo &egrave; obbligatorio");
				}
				returnValue = false;
			} 
			checkValueita('pass2');
			break;
		case "pass2":

			inhalt = $('#pwconf').val();
			var pass = $('#pw').val();
			ergebnis = inhalt.match(/^[a-z\d_\d.\x20-\x7e]{4,16}$/i);
			if(ergebnis && inhalt == pass ) {
				$("#pass2check").css("visibility", "hidden");
				$("#pass2check").removeClass("invalid");
				$("#pass2check").html("corretto");
				returnValue = true;
			} else if (ergebnis && inhalt != pass) {
				$("#pass2check").css("visibility", "visible");
				$("#pass2check").addClass("invalid");
				$("#pass2check").html("conferma password non valida");
				returnValue = false;
			} else if(!ergebnis && inhalt != "") {
				$("#pass2check").css("visibility", "visible");
				$("#pass2check").addClass("invalid");
				$("#pass2check").html("il campo non &egrave; corretto");
				returnValue = false;
			} else {
				$("#pass2check").css("visibility", "visible");
				$("#pass2check").addClass("invalid");
				$("#pass2check").html("il campo &egrave; obbligatorio");
				returnValue = false;
			}
			if ($.trim($('#pwconf').val()) == "") {
				if (value == 'direct')
				{
					$("#pass2check").css("visibility", "hidden");
				} else {
					$("#pass2check").css("visibility", "visible");
					$("#pass2check").addClass("invalid");
					$("#pass2check").html("il campo &egrave; obbligatorio");
				}
				returnValue = false;
			}
			
			break;
		case "pass3":
			inhalt = $('#oldpw').val();
			ergebnis = inhalt.match(/^[a-z\d_\d.\x20-\x7e]{4,16}$/i);
			if(ergebnis) {
				$("#passoldcheck").css("visibility", "hidden");
				$("#passoldcheck").removeClass("invalid");
				$("#passoldcheck").html("corretto");
				returnValue = true;
			} else if(!ergebnis && inhalt != "") {
				$("#passoldcheck").css("visibility", "visible");
				$("#passoldcheck").addClass("invalid");
				$("#passoldcheck").html("il campo non &egrave; corretto");
				returnValue = false;
			} else {
				if (value == 'direct')
				{
					$("#passoldcheck").css("visibility", "hidden");
				} else {
					$("#passoldcheck").css("visibility", "visible");
					$("#passoldcheck").addClass("invalid");
					$("#passoldcheck").html("il campo &egrave; obbligatorio");
				}
				returnValue = false;
			}
			if ($.trim($('#pw').val()) == "") {
				if (value == 'direct')
				{
					$("#passoldcheck").css("visibility", "hidden");
				} else {
					$("#passoldcheck").css("visibility", "visible");
					$("#passoldcheck").addClass("invalid");
					$("#passoldcheck").html("il campo &egrave; obbligatorio");
				}
				returnValue = false;
			} 
			break;
		case "firstname":
			inhalt = $('#firstname').val();
			ergebnis = inhalt.match(/^[a-z\d_\d. ]{1,32}$/i);
			if(ergebnis) {
				$("#firstnamecheck").removeClass("invalid");
				$("#firstnamecheck").html("corretto");
				$("#firstnamecheck").css("visibility", "hidden");
				returnValue = true;
			} else {
				$("#firstnamecheck").css("visibility", "visible");
				$("#firstnamecheck").addClass("invalid");
				$("#firstnamecheck").html("il campo non &egrave; corretto");
				returnValue = false;
			}
			if ($.trim($('#firstname').val()) == "") {
				if (value == 'direct')
				{
					$("#firstnamecheck").css("visibility", "hidden");
				} else {
					$("#firstnamecheck").css("visibility", "visible");
					$("#firstnamecheck").html("il campo &egrave; obbligatorio");
				}
				returnValue = false;
			}
			
			break;
		case "lastname":
			inhalt = $('#lastname').val();
			ergebnis = inhalt.match(/^[a-z\d_\d. \']{1,32}$/i);
			if(ergebnis) {
				$("#lastnamecheck").css("visibility", "hidden");
				$("#lastnamecheck").removeClass("invalid");
				$("#lastnamecheck").html("corretto");
				returnValue = true;
			} else {
				$("#lastnamecheck").css("visibility", "visible");
				$("#lastnamecheck").addClass("invalid");
				$("#lastnamecheck").html("il campo non &egrave; corretto");
				returnValue = false;
			}
			if ($.trim($('#lastname').val()) == "") {
				if (value == 'direct')
				{
					$("#lastnamecheck").css("visibility", "hidden");
				} else {
					$("#lastnamecheck").css("visibility", "visible");
					$("#lastnamecheck").html("il campo &egrave; obbligatorio");
				}
				
			}
			break;
		case "tel":
			inhalt = $('#tel').val();
			ergebnis = inhalt.match(/^(\d{0,5}\/?)?\d+$/i);
			if(ergebnis) {
				returnValue = true;
			} else {
				returnValue = false;
			}
			break;
		case "tele":
			inhalt = $('#tele').val();
			ergebnis = inhalt.match(/^[0-9][0-9 ]+$/i);
			if (ergebnis)
			{
				$("#telecheck").css("visibility", "hidden");
				$("#telecheck").removeClass("invalid");
				$("#telecheck").html("corretto");
				returnValue = true;
			} else {
				$("#telecheck").css("visibility", "visible");
				$("#telecheck").addClass("invalid");
				$("#telecheck").html("il campo non &egrave; corretto");
				returnValue = false;
			}
			if ($.trim($('#tele').val()) == "") {
				$("#telecheck").html("il campo &egrave; obbligatorio");
			}
			break;
		case "teleita":

			tele1 = $('#tele1').val();
			tele2 = $('#tele2').val();
			ergebnis = tele1.match(/^[0-9]{1,3}$/i);
			ergebnis2 = tele2.match(/^[0-9]{1,10}$/i);

			if (ergebnis && ergebnis2)
			{
				$("#telecheck").css("visibility", "hidden");
				$("#telecheck").removeClass("invalid");
				$("#telecheck").html("corretto");
				returnValue = true;
			} else {
				if ($.trim($('#tele1').val()) != "" && $.trim($('#tele2').val()) != "") {
					$("#telecheck").css("visibility", "visible");
					$("#telecheck").addClass("invalid");
					$("#telecheck").html("il campo non &egrave; corretto");
					returnValue = false;
				} else {
					if ($.trim($('#tele1').val()) == "")
					{
						if (value == 'direct')
						{
							$("#telecheck").css("visibility", "hidden");
						} else {
							$("#telecheck").css("visibility", "visible");
							$("#telecheck").addClass("invalid");
							$("#telecheck").html("il campo &egrave; obbligatorio");
						}
						returnValue = false;
					} else if ($.trim($('#tele2').val()) == "") 
					{
						if (value == 'direct')
						{
							$("#telecheck").css("visibility", "hidden");
						} else {
							$("#telecheck").css("visibility", "visible");
							$("#telecheck").addClass("invalid");
							$("#telecheck").html("il campo Numero di Cellulare &egrave; obbligatorio");
						}
						returnValue = false;
					}
					return false;
					
				}
			}
			if ($.trim($('#tele1').val()) == "" && $.trim($('#tele2').val()) == "") {
				if (value == 'direct')
				{
					$("#telecheck").css("visibility", "hidden");
				} else {
					$("#telecheck").css("visibility", "visible");
					$("#telecheck").addClass("invalid");
					$("#telecheck").html("il campo &egrave; obbligatorio");
				}
				returnValue = false;
			}
			break;
		case "citta":

			citta = $('#citta').val();
			cittanr = $('#cittanr').val();
			ergebnis = citta.match(/^[a-zA-Z0-9][a-zA-Z0-9 \']*$/i);
			ergebnis2 = cittanr.match(/^[a-zA-Z0-9][a-zA-Z0-9 \/\\-]*$/i);
			if (ergebnis && ergebnis2)
			{
				$("#cittacheck").css("visibility", "hidden");
				$("#cittacheck").removeClass("invalid");
				$("#cittacheck").html("corretto");
				returnValue = true;
			} else {
				if ($.trim($('#citta').val()) != "" && $.trim($('#cittanr').val()) != "") {
					$("#cittacheck").css("visibility", "visible");
					$("#cittacheck").addClass("invalid");
					$("#cittacheck").html("il campo non &egrave; corretto");
					returnValue = false;
				} else {
					if ($.trim($('#citta').val()) == "")
					{
						if (value == 'direct')
						{
							$("#cittacheck").css("visibility", "hidden");
						} else {
							$("#cittacheck").css("visibility", "visible");
							$("#cittacheck").addClass("invalid");
							$("#cittacheck").html("il campo Indirizzo &egrave; obbligatorio");
						}
						returnValue = false;
					} else if ($.trim($('#cittanr').val()) == "") 
					{
						if (value == 'direct')
						{
							$("#cittacheck").css("visibility", "hidden");
						} else {
							$("#cittacheck").css("visibility", "visible");
							$("#cittacheck").addClass("invalid");
							$("#cittacheck").html("il campo N. civico &egrave; obbligatorio");
						}
						returnValue = false;
					}
					return false;
					
				}
				
			}
			if ($.trim($('#citta').val()) == "" && $.trim($('#cittanr').val()) == "") {
				if (value == 'direct')
				{
					$("#cittacheck").css("visibility", "hidden");
				} else {
					$("#cittacheck").css("visibility", "visible");
					$("#cittacheck").addClass("invalid");
					$("#cittacheck").html("il campo N. civico &egrave; obbligatorio");
				}
				returnValue = false;
			}
			break;
		case "capcomunepro":
			cap = $('#cap').val();
			comune = $('#comune').val();
			provincia = $('#provincia').val();
			ergebnis = cap.match(/^\d{1,5}$/i);
			ergebnis2 = comune.match(/^[a-zA-Z0-9][a-zA-Z0-9 ]+$/i);
			ergebnis3 = provincia.match(/^[a-zA-Z]{2}$/i);
			if (ergebnis && ergebnis2 && ergebnis3)
			{	
				$("#capcomprocheck").css("visibility", "hidden");
				$("#capcomprocheck").removeClass("invalid");
				$("#capcomprocheck").html("corretto");
				returnValue = true;
			} else {
				
				if ($.trim($('#cap').val()) != "" && $.trim($('#comune').val()) != "" && $.trim($('#provincia').val()) != "") {
					$("#capcomprocheck").css("visibility", "visible");
					$("#capcomprocheck").addClass("invalid");
					$("#capcomprocheck").html("il campo non &egrave; corretto");
					returnValue = false;
				} else {
					if ($.trim($('#cap').val()) == "")
					{
						if (value == 'direct')
						{
							$("#capcomprocheck").css("visibility", "hidden");
						} else {
							$("#capcomprocheck").css("visibility", "visible");
							$("#capcomprocheck").addClass("invalid");
							$("#capcomprocheck").html("il campo CAP &egrave; obbligatorio");
						}
						returnValue = false;
					} else if ($.trim($('#comune').val()) == "") 
					{
						if (value == 'direct')
						{
							$("#capcomprocheck").css("visibility", "hidden");
						} else {
							$("#capcomprocheck").css("visibility", "visible");
							$("#capcomprocheck").addClass("invalid");
							$("#capcomprocheck").html("il campo Comune &egrave; obbligatorio");
						}
						returnValue = false;
					} else if ($.trim($('#provincia').val()) == "") 
					{
						if (value == 'direct')
						{
							$("#capcomprocheck").css("visibility", "hidden");
						} else {
							$("#capcomprocheck").css("visibility", "visible");
							$("#capcomprocheck").addClass("invalid");
							$("#capcomprocheck").html("il campo Provincia &egrave; obbligatorio");
						}
						returnValue = false;
					}
					return false;
					
				}
			}
			if ($.trim($('#cap').val()) == "" && $.trim($('#comune').val()) == "" && $.trim($('#provincia').val()) == "") {
				if (value == 'direct')
				{
					$("#capcomprocheck").css("visibility", "hidden");
				} else {
					$("#capcomprocheck").css("visibility", "visible");
					$("#capcomprocheck").addClass("invalid");
					$("#capcomprocheck").html("il campo &egrave; obbligatorio");
				}
				returnValue = false;
			}
			break;
		case "fiscale":
			inhalt = $('#fiscale').val();
			ergebnis = inhalt.match(/^[0-9a-zA-Z]{1,16}$/i);
			if (ergebnis)
			{
				$("#fischeck").css("visibility", "hidden");
				$("#fischeck").removeClass("invalid");
				$("#fischeck").html("corretto");
				returnValue = true;
			} else {
				$("#fischeck").css("visibility", "visible");
				$("#fischeck").addClass("invalid");
				$("#fischeck").html("il campo non &egrave; corretto");
				returnValue = false;
			}
			if ($.trim($('#fiscale').val()) == "") {
				$("#fischeck").html("il campo &egrave; obbligatorio");
			}
			break;
		case "privacy":
		
	
			if ($('#privacy').attr('checked'))
			{
				$("#privacycheck").css("display", "none");
				/*$("#privacycheck").removeClass("invalid");
				$("#privacycheck").html("accettato");*/
				returnValue = true;
			} else {
				
				$("#privacycheck").css("display", "block");
				$("#privacycheck").addClass("invalid");
				$("#privacycheck").html("Per proseguire &egrave; necessario accettare le condizioni d&rsquo;uso.");
				returnValue = false;
			}
			break;
		case "birthday":
			var valid = checkage(18);
			var byear = $('#birthyear').val();
			var bday = $('#birthday').val();
			var bmonth = $('#birthmonth').val();
			var currentdate = new Date();
			var cyear = currentdate.getFullYear();
			
			if (valid) {
				$("#birthcheck").css("visibility", "hidden");
				$("#birthcheck").removeClass("invalid");
				$("#birthcheck").html("accettato");
				returnValue = true;
			} else if (bday = '1' && bmonth == '01' && byear == cyear) {
				$("#birthcheck").css("visibility", "hidden");
				returnValue = false;
			} else {
				$("#birthcheck").css("visibility", "visible");
				$("#birthcheck").addClass("invalid");
				$("#birthcheck").html("Per partecipare all'estrazione dei premi devi essere maggiorenne.");
				returnValue = false;
			}
			
			break;
		case "cardnr":

			tele1 = $('#cardnr').val();
			tele2 = $('#cardnr2').val();
			ergebnis = tele1.match(/^[0-9]{4}$/i);
			ergebnis2 = tele2.match(/^[0-9]{4}$/i);
			if (ergebnis && ergebnis2)
			{
				$("#bgunicheck").css("visibility", "hidden");
				$("#bgunicheck").removeClass("invalid");
				$("#bgunicheck").html("corretto");
				returnValue = true;
			} else {
				
				if ($.trim($('#cardnr').val()) != "" && $.trim($('#cardnr2').val()) != "") {
					$("#bgunicheck").css("visibility", "visible");
					$("#bgunicheck").addClass("invalid");
					$("#bgunicheck").html("Ogni campo richiede 4 cifre");
					returnValue = false;
				} 
			}

			if ($.trim($('#cardnr').val()) == "")
			{
				$("#bgunicheck").css("visibility", "hidden");
			}
			break;
	}
	return returnValue;
}

function checkage(minage) {
	var bday = $('#birthday').val();
	var bmonth = $('#birthmonth').val()-1;
	var byear = $('#birthyear').val();
	var age = minage;

	var birthdate = new Date(byear, bmonth, bday);

	var currentdate = new Date();
	currentdate.setFullYear(currentdate.getFullYear() - age);
	if ((currentdate - birthdate) < 0)
		return false;
	else
		return true;
	
}

function checkItaEditProfileValues(edit) {
	var returnValue = false;;
	
	if (edit == "edit") {

	} else {

		var emailcheck = checkValueita('mail');

	}
	
	var firstnamecheck = checkValueita('firstname');
	var lastnamecheck = checkValueita('lastname');
	var telecheck = checkValueita('teleita');

	var cittacheck = checkValueita('citta');
	var capcomprocheck = checkValueita('capcomunepro');
	var fischeck = checkValueita('fiscale');
	var birthcheck = checkValueita('birthday');

	
	if(firstnamecheck && lastnamecheck && emailcheck && capcomprocheck && fischeck && telecheck && birthcheck && cittacheck) {
		returnValue = true;
	}


	var theobj = document.getElementById('fiscale');
	var fiscalcheck =true;
	if ($("#fiscale").val() != "")
		fiscalcheck = checkCF(theobj, true); 
	else {
		if (reg =="sub") {
			$("#fischeck").css("visibility", "visible");
			$("#fischeck").html("il campo &egrave; obbligatorio");
		}
		else
		{
			$("#fischeck").css("visibility", "hidden");
		}
	}

	if (fiscalcheck == false)
	{
			
		$("#fischeck").css("visibility", "visible");
		$("#fischeck").addClass("invalid");
		$("#fischeck").html("il campo non &egrave; corretto");
		returnValue = false;
	} 


	return returnValue;
}

function checkCF (theObj,obblig) {

            if (theObj == null)            return !obblig;

            var cfVal=theObj.value.toUpperCase();

            var cfLen=cfVal.length;

            var cfName="Codice fiscale";

            theObj.value=cfVal;        // metto tutto maiuscolo (nel campo form)

            

            if (cfVal==""&&!obblig)    return true;                    // vuoto

            

 

 

            if (cfVal==""||cfLen<2) {

                        theObj.focus();

                        if (obblig)                       alert("Attenzione, è necessario completare il campo '"+cfName+"'.");

                        else                              alert("Attenzione, il '"+cfName+"' inserito non è valido.");

                        return false;

            } else if (cfLen!=16) {

                        theObj.focus();

                        alert("Attenzione, il '"+cfName+"' inserito non è valido.\nLa lunghezza del campo deve essere di 16 caratteri.");

                        return false;

            }

 

            try {

                        if (cfVal.match(/[^A-Z0-9]/gi)) {

                                    theObj.focus();

                                    alert("Attenzione, il '"+cfName+"' inserito non è valido.\nSono ammesse solo lettere e cifre.");

                                    return false;

                        }

            } catch (e) { 

                        var alfaNumString="0123456789QWERTYUIOPASDFGHJKLZXCVBNM";

                        for (var i=0; i<cfLen; i++) {           // controllo singoli caratteri

                                    if (alfaNumString.indexOf (cfVal.charAt(i), 0)==-1) {

                                                theObj.focus();

                                                alert("Attenzione, il '"+cfName+"' inserito non è valido.\nSono ammesse solo lettere e cifre.");

                                                return false;

                                    }

                        }

            }

 

            try {

                        if (!cfVal.match(/^[A-Z]{6}[0-9LMNPQRSTUV]{2}[ABCDEHLMPRST][0-9LMNPQRSTUV]{2}[A-Z][0-9LMNPQRSTUV]{3}[A-Z]$/gi)) {

                                    theObj.focus();

                                    alert("Attenzione, il '"+cfName+"' inserito non è valido.");

                                    return false;

                        }

            } catch (e) { }

 

            var        alfa="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            var        alfanum="0123456789"+alfa;

            var corrPari=new Array(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25);

            var corrDisp=new Array(1,0,5,7,9,13,15,17,19,21,1,0,5,7,9,13,15,17,19,21,2,4,18,20,11,3,6,8,12,14,16,10,22,25,24,23);

            var tot=0;

            for(var i=0;i<=14;i+=2)                tot+=parseInt(corrDisp[parseInt(alfanum.indexOf(cfVal.charAt(i)),10)],10);

            for(i=1;i<=14;i+=2)                                 tot+=parseInt(corrPari[parseInt(alfanum.indexOf(cfVal.charAt(i)),10)],10);

 

            if (alfa.charAt(tot%26)!=cfVal.charAt(15))              {

                        theObj.focus();

                        alert("Attenzione, il '"+cfName+"' inserito non è valido.");

                        return false;

            }

            return true;        // ok

}



function checkDeEditProfileValues(edit) {
	var returnValue = false;;
	
	if (edit == "edit") {

	} else {

		var emailcheck = checkValue('mail');
	
	}
	
	var firstnamecheck = checkValue('firstname');
	var lastnamecheck = checkValue('lastname');
	var telcheck = checkValue('tel');
	var birthcheck = checkValue('birthday');	

	
	if(firstnamecheck && lastnamecheck && emailcheck && telcheck && birthcheck) {
		returnValue = true;
	}

	return returnValue;
}


function checkPWValues(pw) {
	
	var returnValue = false;;

	if (pw == "pw") {

		if ($.trim($('#oldpw').val()) == "") 
			$("#passoldcheck").css("visibility", "hidden");
		else
			$("#passoldcheck").css("visibility", "visible");
			
		if ($.trim($('#pw').val()) == "") 
			$("#passcheck").css("visibility", "hidden");
		else
			$("#passcheck").css("visibility", "visible");
	
		if ($.trim($('#pwconf').val()) == "") 
			$("#pass2check").css("visibility", "hidden");
		else
			$("#pass2check").css("visibility", "visible");
			
	} else {
		
		var passcheck = checkValue('pass');
		var pass2check = checkValue('pass2');
		var passoldcheck = checkValue('pass3');
		
	}

	if(passcheck && pass2check && passoldcheck) {
		returnValue = true;
	} 

	return returnValue;
	
}


function checkrPWValues(rpw) {
	
	var returnValue = false;;

	if (rpw == "rpw") {

		if ($.trim($('#nick').val()) == "") 
			$("#usercheck").css("visibility", "hidden");
		else
			$("#usercheck").css("visibility", "visible");
			
		if ($.trim($('#mail').val()) == "") 
			$("#mailcheck").css("visibility", "hidden");
		else
			$("#mailcheck").css("visibility", "visible");
	
	} else {
		
		var usercheck = checkValue('user');
		var mailcheck = checkValue('mail');
		
	}

	if(usercheck && mailcheck) {
		returnValue = true;
	} 

	return returnValue;
	
}

function checkritaPWValues(rpw) {
	
	var returnValue = false;;

	if (rpw == "rpw") {

		if ($.trim($('#nick').val()) == "") 
			$("#usercheck").css("visibility", "hidden");
		else
			$("#usercheck").css("visibility", "visible");
			
		if ($.trim($('#mail').val()) == "") 
			$("#mailcheck").css("visibility", "hidden");
		else
			$("#mailcheck").css("visibility", "visible");
	
	} else {
		
		var usercheck = checkValueita('user');
		var mailcheck = checkValueita('mail');
		
	}

	if(usercheck && mailcheck) {
		returnValue = true;
	} 

	return returnValue;
	
}



function checkRegValues(reg) {
	
	var returnValue = false;
	
	if (reg == "reg") {

		if ($('#privacy').attr('checked')) {
			$("#privacycheck").css("display", "block");
			var privacycheck = checkValueita('privacy');
		} else {
			$("#privacycheck").css("display", "none");
		}

		var firstnamecheck = checkValue('firstname');
		if ($.trim($('#firstname').val()) == "") 
			$("#firstnamecheck").css("visibility", "hidden");
		else
			$("#firstnamecheck").css("visibility", "visible");

		var lastnamecheck = checkValue('lastname');
		if ($.trim($('#lastname').val()) == "") 
			$("#lastnamecheck").css("visibility", "hidden");
		else
			$("#lastnamecheck").css("visibility", "visible");
			
		var telcheck = checkValue('tel');
		if ($.trim($('#tele').val()) == "") 
			$("#telecheck").css("visibility", "hidden");
		else
			$("#telecheck").css("visibility", "visible");
		
		
		var byear = $('#birthyear').val();
		var bday = $('#birthday').val();
		var bmonth = $('#birthmonth').val();
		var currentdate = new Date();
		var cyear = currentdate.getFullYear();
		var birthcheck = checkValue('birthday');

		
		if (bday = '1' && bmonth == '01' && byear == cyear) 
			$("#birthcheck").css("visibility", "hidden");
		else
			$("#birthcheck").css("visibility", "visible");
			
		if ($.trim($('#nick').val()) == "") 
			$("#usercheck").css("visibility", "hidden");
		else
			$("#usercheck").css("visibility", "visible");
		
		
		if ($.trim($('#mail').val()) == "") 
			$("#mailcheck").css("visibility", "hidden");
		else
			$("#mailcheck").css("visibility", "visible");
	
		if ($.trim($('#pw').val()) == "") 
			$("#passcheck").css("visibility", "hidden");
		else
			$("#passcheck").css("visibility", "visible");
	
		if ($.trim($('#pwconf').val()) == "") 
			$("#pass2check").css("visibility", "hidden");
		else
			$("#pass2check").css("visibility", "visible");
			
	} else {
		
		var usercheck = checkValue('user');
		var emailcheck = checkValue('mail');
		var passcheck = checkValue('pass');
		var pass2check = checkValue('pass2');
		var privacycheck = checkValue('privacy');
		var telcheck = checkValue('tel');
		var birthcheck = checkValue('birthday');
		var firstnamecheck = checkValue('firstname');
		var lastnamecheck = checkValue('lastname');
	}

		
	if (reg =="sub") {
		$("#firstnamecheck").css("visibility", "visible");
		$("#lastnamecheck").css("visibility", "visible");
		$("#mailcheck").css("visibility", "visible");
		
		if ($.trim($('#tele').val()) == "") 
			$("#telecheck").css("visibility", "hidden");
		else
			$("#telecheck").css("visibility", "visible");
			
		$("#birthcheck").css("visibility", "visible");
		$("#usercheck").css("visibility", "visible");
	}
	
	
	
	
	if(emailcheck && usercheck && passcheck && pass2check && privacycheck && firstnamecheck && lastnamecheck && telcheck && birthcheck) {
		returnValue = true;
	} 

	return returnValue;
	
}

function checkEmailValues() {

	var returnValue = false;
	var allempty = true;
	var dublicated = new Array();


	for (i=1;i<26;i++){
		
		returnValue = checkValue('mails', $('#'+i+'_mail').val(), i+'_mailcheck');
		
		if ($.trim($('#'+i+'_mail').val()) != "" && allempty)
		{
			allempty = false;
			
		}

		if ($.trim($('#'+i+'_mail').val()) != "")
			dublicated.push($.trim($('#'+i+'_mail').val()));

		if (!returnValue)
		{
			break;
		}
	}

	if (arrHasDupes(dublicated))
	{
		$("#maildublicate").css("visibility", "visible");
		$("#maildublicate").addClass("invalid");
		$("#maildublicate").html("doppelte E-Mail Adressen");
		returnValue = false;
	} else {
		$("#maildublicate").css("visibility", "hidden");
	}
	
	if (allempty)
		returnValue = false;
	
	return returnValue;
}

function checkContactValues(){
	
	var returnValue = false;
	
	var namecheck = checkValue('name');
	var emailcheck = checkValue('mailcontact');
	var messagecheck = checkValue('message');
	
	if(namecheck && emailcheck && messagecheck) {
		returnValue = true;
	} 

	return returnValue;
}


function checkValue(element, value, checkid) {
	var inhalt, ergebnis; 
	var returnvalue = false;
	switch(element) {
		case "mail":
			inhalt = $('#mail').val();
			ergebnis = inhalt.match(/^[a-zA-Z0-9]+([a-zA-Z0-9_-])*([.][a-zA-Z0-9_-]+)*[@][a-zA-Z0-9_-]+([.][a-zA-Z0-9_-]+)*[.][a-zA-Z]{2,4}$/);
			if(ergebnis) {
				$("#mailcheck").css("visibility", "visible");
				$("#mailcheck").removeClass("invalid");
				$("#mailcheck").html("valid");
				returnValue = true;
			} else if(!ergebnis && inhalt != "") {
				$("#mailcheck").css("visibility", "visible");
				$("#mailcheck").addClass("invalid");
				$("#mailcheck").html("E-Mail nicht valid");
				returnValue = false;
			} else {
				$("#mailcheck").css("visibility", "visible");
				$("#mailcheck").addClass("invalid");
				$("#mailcheck").html("invalid");
				returnValue = false;
			}
			break;
		case "mailcontact":
			inhalt = $('#mail').val();
			ergebnis = inhalt.match(/^[a-zA-Z0-9]+([a-zA-Z0-9_-])*([.][a-zA-Z0-9_-]+)*[@][a-zA-Z0-9_-]+([.][a-zA-Z0-9_-]+)*[.][a-zA-Z]{2,4}$/);
			if(ergebnis) {
				$("#mailcheck").css("visibility", "hidden");
				returnValue = true;
			} else if(!ergebnis && inhalt != "") {
				$("#mailcheck").css("visibility", "visible");
				$("#mailcheck").addClass("invalid");
				$("#mailcheck").html("E-Mail nicht valid");
				returnValue = false;
			} else {
				$("#mailcheck").css("visibility", "visible");
				$("#mailcheck").addClass("invalid");
				$("#mailcheck").html("invalid");
				returnValue = false;
			}
			break;
		case "mails":
			ergebnis = value.match(/^[a-zA-Z0-9]+([a-zA-Z0-9_-])*([.][a-zA-Z0-9_-]+)*[@][a-zA-Z0-9_-]+([.][a-zA-Z0-9_-]+)*[.][a-zA-Z]{2,4}$/);
			if(ergebnis) {
				$("#"+checkid+"").css("visibility", "visible");
				$("#"+checkid+"").removeClass("invalid");
				$("#"+checkid+"").html("valid");
				returnValue = true;
			} else if(!ergebnis && inhalt != "") {
				$("#"+checkid+"").css("visibility", "visible");
				$("#"+checkid+"").addClass("invalid");
				$("#"+checkid+"").html("E-Mail nicht valid");
				returnValue = false;
			} else {
				$("#"+checkid+"").css("visibility", "visible");
				$("#"+checkid+"").addClass("invalid");
				$("#"+checkid+"").html("invalid");
				returnValue = false;
			}
			if ($.trim(value) == "")
			{
				$("#"+checkid+"").css("visibility", "hidden");
				returnValue = true;
			}
			break;
		case "user":
			inhalt = $('#nick').val();
			ergebnis = inhalt.match(/^[a-z\d_\d.]{4,16}$/i);
			if(ergebnis) {
				$("#usercheck").css("visibility", "visible");
				$("#usercheck").removeClass("invalid");
				$("#usercheck").html("valid");
				returnValue = true;
			} else if(!ergebnis && inhalt != "") {
				$("#usercheck").css("visibility", "visible");
				$("#usercheck").addClass("invalid");
				$("#usercheck").html("ungültiger Username");
				returnValue = false;
			} else {
				$("#usercheck").css("visibility", "visible");
				$("#usercheck").addClass("invalid");
				$("#usercheck").html("invalid");
				returnValue = false;
			}
			break;
		case "pass":
			inhalt = $('#pw').val();
			ergebnis = inhalt.match(/^[a-z\d_\d.\x20-\x7e]{4,16}$/i);
			if(ergebnis) {
				$("#passcheck").css("visibility", "visible");
				$("#passcheck").removeClass("invalid");
				$("#passcheck").html("valid");
				returnValue = true;
			} else if(!ergebnis && inhalt != "") {
				$("#passcheck").css("visibility", "visible");
				$("#passcheck").addClass("invalid");
				$("#passcheck").html("Passwort ungültig");
				returnValue = false;
			} else {
				$("#passcheck").css("visibility", "visible");
				$("#passcheck").addClass("invalid");
				$("#passcheck").html("invalid");
				returnValue = false;
			}
			if ($.trim($('#pw').val()) == "") {
				$("#pass2check").css("visibility", "visible");
				$("#pass2check").addClass("invalid");
				$("#pass2check").html("invalid");
				returnValue = false;
			} 
			checkValue('pass2');
			break;
		case "pass3":
			inhalt = $('#oldpw').val();
			ergebnis = inhalt.match(/^[a-z\d_\d.\x20-\x7e]{4,16}$/i);
			if(ergebnis) {
				$("#passoldcheck").css("visibility", "visible");
				$("#passoldcheck").removeClass("invalid");
				$("#passoldcheck").html("valid");
				returnValue = true;
			} else if(!ergebnis && inhalt != "") {
				$("#passoldcheck").css("visibility", "visible");
				$("#passoldcheck").addClass("invalid");
				$("#passoldcheck").html("Passwort ungültig");
				returnValue = false;
			} else {
				$("#passoldcheck").css("visibility", "visible");
				$("#passoldcheck").addClass("invalid");
				$("#passoldcheck").html("invalid");
				returnValue = false;
			}
			if ($.trim($('#pw').val()) == "") {
				$("#passoldcheck").css("visibility", "visible");
				$("#passoldcheck").addClass("invalid");
				$("#passoldcheck").html("invalid");
				returnValue = false;
			} 
			break;
		case "pass2":
			inhalt = $('#pwconf').val();
			var pass = $('#pw').val();
			ergebnis = inhalt.match(/^[a-z\d_\d.\x20-\x7e]{4,16}$/i);
			if(ergebnis && inhalt == pass ) {
				$("#pass2check").css("visibility", "visible");
				$("#pass2check").removeClass("invalid");
				$("#pass2check").html("valid");
				returnValue = true;
			} else if (ergebnis && inhalt != pass) {
				$("#pass2check").css("visibility", "visible");
				$("#pass2check").addClass("invalid");
				$("#pass2check").html("Passwort stimmt nicht überein");
				returnValue = false;
			} else if(!ergebnis && inhalt != "") {
				$("#pass2check").css("visibility", "visible");
				$("#pass2check").addClass("invalid");
				$("#pass2check").html("invalid");
				returnValue = false;
			} else {
				$("#pass2check").css("visibility", "visible");
				$("#pass2check").addClass("invalid");
				$("#pass2check").html("invalid");
				returnValue = false;
			}
			if ($.trim($('#pwconf').val()) == "") {
				$("#pass2check").css("visibility", "visible");
				$("#pass2check").addClass("invalid");
				$("#pass2check").html("invalid");
				returnValue = false;
			}
			
			break;
		case "privacy":
			if ($('#privacy').attr('checked'))
			{
				$("#privacycheck").css("display", "none");
				/*$("#privacycheck").removeClass("invalid");
				$("#privacycheck").html("accettato");*/
				returnValue = true;
			} else {
				
				$("#privacycheck").css("display", "block");
				$("#privacycheck").addClass("invalid");
				$("#privacycheck").html("Du musst den Nutzungsbedingungen zustimmen.");
				returnValue = false;
			}
			break;
		case "firstname":
			inhalt = $('#firstname').val();
			ergebnis = inhalt.match(/^[a-z\d_\d. äüöÄÜÖß]{1,32}$/i);
			if(ergebnis) {
				$("#firstnamecheck").removeClass("invalid");
				$("#firstnamecheck").html("valid");
				$("#firstnamecheck").css("visibility", "visible");
				returnValue = true;
			} else {
				$("#firstnamecheck").css("visibility", "visible");
				$("#firstnamecheck").addClass("invalid");
				$("#firstnamecheck").html("invalid");
				returnValue = false;
			}
			break;
		case "lastname":

			inhalt = $('#lastname').val();
			ergebnis = inhalt.match(/^[a-z\d_\d. äüöÄÜÖß]{1,32}$/i);
			if(ergebnis) {
				$("#lastnamecheck").css("visibility", "visible");
				$("#lastnamecheck").removeClass("invalid");
				$("#lastnamecheck").html("valid");
				returnValue = true;
			} else if ($.trim($('#lastname').val()) == "") {
				$("#lastnamecheck").css("visibility", "hidden");
				returnValue = false;
			} else {
				$("#lastnamecheck").css("visibility", "visible");
				$("#lastnamecheck").addClass("invalid");
				$("#lastnamecheck").html("invalid");
				returnValue = false;
			}
			break;
		case "name":

			if ($.trim($('#name').val()) == "") 
			{
				$("#namecheck").css("visibility", "visible");
				$("#namecheck").addClass("invalid");
				$("#namecheck").html("Du musst einen Namen angeben!");
				returnValue = false;
			} else {
				$("#namecheck").css("visibility", "hidden");
				returnValue = true;
			}
			
			
			break;
		case "message":

			if ($.trim($('#message').attr('value')) == "") 
			{
				$("#messagecheck").css("visibility", "visible");
				$("#messagecheck").addClass("invalid");
				$("#messagecheck").html("Du musst eine Nachricht angeben!");
				returnValue = false;
			} else {
				$("#messagecheck").css("visibility", "hidden");
				returnValue = true;
			}
			
			
			break;
		case "tel":
	
			inhalt = $('#tele').val();
			ergebnis = inhalt.match(/^[0-9][0-9 ]+$/i);
			if (ergebnis)
			{
				$("#telecheck").css("visibility", "visible");
				$("#telecheck").removeClass("invalid");
				$("#telecheck").html("valid");
				returnValue = true;
			} else {
				$("#telecheck").css("visibility", "visible");
				$("#telecheck").addClass("invalid");
				$("#telecheck").html("invalid");
				returnValue = false;
			}
			if ($.trim($('#tele').val()) == "")
			{
				$("#telecheck").css("visibility", "hidden");
				returnValue = true;
			}
				
			
			break;
		case "birthday":
			var valid = checkage(16);
			var byear = $('#birthyear').val();
			var bday = $('#birthday').val();
			var bmonth = $('#birthmonth').val();
			var currentdate = new Date();
			var cyear = currentdate.getFullYear();
			
			if (valid) {
				$("#birthcheck").css("visibility", "visible");
				$("#birthcheck").removeClass("invalid");
				$("#birthcheck").html("valid");
				returnValue = true;
			} else {
				$("#birthcheck").css("visibility", "visible");
				$("#birthcheck").addClass("invalid");
				$("#birthcheck").html("Du musst mindestens 16 sein.");
				returnValue = false;
			}
			
			break;
		default:
			break;
	}
	return returnValue;
}



	

