/**
 * @author Francesco
 */

function Register() {}

Register.prototype = new AjaxModule();
Register.prototype.constructor = Register;

Register.prototype.server_page = "../include_user/php/subscribe.php";

Register.prototype.fields = [];
Register.prototype.fields.push({id:"profilo", pattern:/^[a-z]{5,11}$/, empty:false, message:"Profilo non valido."});
Register.prototype.fields.push({id:"ragione", pattern:/^.{3,255}$/, empty:false, message:"Ragione sociale non valida\n(min. 3 caratteri)."});
Register.prototype.fields.push({id:"nome", pattern:/^[\w\W\d\s]{2,255}$/, empty:false, message:"Nome non valido\n(min. 2 caratteri)."});
Register.prototype.fields.push({id:"cognome", pattern:/^[\w\W\d\s]{2,255}$/, empty:false, message:"Cognome non valido\n(min. 2 caratteri)."});
Register.prototype.fields.push({id:"codfisc", pattern:/^[a-zA-Z0-9]{16}$/, empty:true, message:"Codice Fiscale non valido (spazi non ammessi)."});
Register.prototype.fields.push({id:"piva", pattern:/^[0-9]{11}$/, empty:false, message:"Partita IVA non valida."});
Register.prototype.fields.push({id:"indirizzo", pattern:/^[\.\w\W\d\s]{5,255}$/, empty:false, message:"Indirizzo non valido\n(min. 5 caratteri alfanumerici)."});
Register.prototype.fields.push({id:"cap", pattern:/^[0-9]{5}$/, empty:false, message:"Cap non valido (5 numeri)."});
Register.prototype.fields.push({id:"telefono", pattern:/^[0-9]{3,20}$/, empty:false, message:"Telefono non valido (solo numeri)."});
Register.prototype.fields.push({id:"fax", pattern:/^[0-9]{3,20}$/, empty:false, message:"Fax non valido (solo numeri)."});
Register.prototype.fields.push({id:"email", pattern:/^([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})){1}$/, empty:false, message:"Indirizzo e-mail non valido."});
Register.prototype.fields.push({id:"username", pattern:/^[\w\W\d\s_-]{3,255}$/, empty:false, message:"Username non valido\n(min. 3 caratteri)."});
Register.prototype.fields.push({id:"userpass", pattern:/^.{5,255}$/, empty:false, message:"Password non valida\n(min. 5 caratteri)."});

Register.prototype.submit = function()
{
	this.clearParams();

	for (var i = 0; i < Register.prototype.fields.length; i++)
	{
		var check = new String(document.getElementById(Register.prototype.fields[i].id).value);
		if ((check.length > 0 && !check.match(Register.prototype.fields[i].pattern)) ||
			(check.length <= 0 && !Register.prototype.fields[i].empty))
		{
			alert(Register.prototype.fields[i].message);
			document.getElementById(Register.prototype.fields[i].id).focus();
			document.getElementById(Register.prototype.fields[i].id).style.borderColor = "red";
			return;
		}
		else
		{
			this.params[Register.prototype.fields[i].id] = check;
			document.getElementById(Register.prototype.fields[i].id).style.borderColor = "green";
		}
	}

	try
	{
		var comune = parseInt(document.getElementById("sonvalue_6").value);
		this.params["comune"] = comune;
	} catch (e) { this.params["comune"] = 0; }

	this.setTarget(document.getElementById("php_response_loading"));
	this.setLoadingTarget(document.getElementById("php_response_loading"));
	this.makeRequest(Register.prototype.server_page);
}

var regobj = new Register();
