
function MailCore(){
	this.mailConf=new MailConfiguration();
	this.label="";
}
	
MailCore.prototype.getLabelForm= function(_value){
	switch (parseInt(_value)){
		case this.mailConf.van:
			this.label="furgoni_";
		    break;
		 
		case this.mailConf.bus:
			this.label="pulmini_";
		    break;
		   
		case this.mailConf.car:
			this.label="auto_";
		    break;
	}
	
	return this.label;
}

MailCore.prototype.setMailValue=function (_label){
		
	this.mailConf.form.startStationValue=$(idSel+_label+this.mailConf.form.startStation).attr("value");	
	this.mailConf.form.endStationValue=$(idSel+_label+this.mailConf.form.endStation).attr("value");
	this.mailConf.form.startDateValue=$(idSel+_label+this.mailConf.form.startDate).attr("value");
	this.mailConf.form.endDateValue=$(idSel+_label+this.mailConf.form.endDate).attr("value");
	this.mailConf.form.startHourValue=$(idSel+_label+this.mailConf.form.startHour).attr("value");	
	this.mailConf.form.endHourValue=$(idSel+_label+this.mailConf.form.endHour).attr("value");
	this.mailConf.form.startMinuteValue=$(idSel+_label+this.mailConf.form.startMinute).attr("value");
	this.mailConf.form.endMinuteValue=$(idSel+_label+this.mailConf.form.endMinute).attr("value");
	this.mailConf.form.surnameValue=$(idSel+_label+this.mailConf.form.surname).attr("value");
	this.mailConf.form.nameValue=$(idSel+_label+this.mailConf.form.name).attr("value");
	this.mailConf.form.emailValue=$(idSel+_label+this.mailConf.form.email).attr("value");
	this.mailConf.form.phoneValue=$(idSel+_label+this.mailConf.form.phone).attr("value");
	this.mailConf.form.typeValue=$(idSel+_label+this.mailConf.form.type).attr("value");
	this.mailConf.form.vehiclePreferenceValue=$(idSel+_label+this.mailConf.form.vehiclePreference).attr("value");
	this.mailConf.form.privacyValue=$(idSel+_label+this.mailConf.form.privacy).attr("checked");
}



MailCore.prototype.toString=function (){
	jAlert("Form"+this.label+" - type: "+this.mailConf.form.typeValue+" - "+this.mailConf.form.startStationValue+" - "+this.mailConf.form.endStationValue+" - "+this.mailConf.form.startDateValue
			+" - "+this.mailConf.form.endDateValue+" - "+this.mailConf.form.startHourValue+" - "+this.mailConf.form.endHourValue+" - "+this.mailConf.form.startMinuteValue+" - "+
			this.mailConf.form.endMinuteValue+" - "+this.mailConf.form.nameValue+" - "+this.mailConf.form.surnameValue+" - "+
			this.mailConf.form.emailValue+" - "+this.mailConf.form.phoneValue+" - "+this.mailConf.form.vehiclePreferenceValue+" - "+this.mailConf.form.privacyValue,"toString");
	
}

MailCore.prototype.beanToJson=function(_form){
	//var jsonObj={"params":[_form.startStation:_form.startStationValue,_form.endStation:_form.endStationValue,_form.startDate:_form.startDateValue, _form.endDate:_form.endDateValue,_form.startHour:_form.startHourValue,_form.endHour:_form.endHourValue,_form.startMinute:_form.startMinuteValue,_form.endMinute:_form.endMinuteValue,_form.name:_form.nameValue,_form.surname:_form.surnameValue,_form.email:_form.emailValue, _form.phone:_form.phoneValue]};
	this.toString();
	var myJSONObject = {"bindings": [
	                                 {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
	                                 {"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
	                                 {"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
	                             ]
	                         };
	
	return jsonObj;
}




MailCore.prototype.validate= function(){
	
	var result;
	
	if(this.fieldRequired(this.mailConf.form.startStationValue,"Stazione di ritiro")&&
	   this.fieldRequired(this.mailConf.form.endStationValue,"Stazione di consegna")&&
	   this.isValidDate(this.mailConf.form.startDateValue,"Data di ritiro")&&
	   this.isNumeric(this.mailConf.form.startHourValue,"")&&
	   this.isNumeric(this.mailConf.form.startMinuteValue,"")&&
	   this.isValidDate(this.mailConf.form.endDateValue,"Data di consegna")&&
	   this.isNumeric(this.mailConf.form.endHourValue,"")&&	   
	   this.isNumeric(this.mailConf.form.endMinuteValue,"")&&
	   this.fieldRequired(this.mailConf.form.nameValue,"Nome")&&
	   this.fieldRequired(this.mailConf.form.surnameValue,"Cognome")&&	   
	   this.isValidMail(this.mailConf.form.emailValue,"email")&&
	   this.fieldRequired(this.mailConf.form.vehiclePreferenceValue,"Preferenza veicolo")&&
	   this.acceptCondition(this.mailConf.form.privacyValue)){
	    	 result=true;
	}else{
			result=false;
	}
	
	return result;

}



MailCore.prototype.isNumeric= function(_value,_label){
	var exit=true;
	
	var RegExp=/^\d+$/;
	
	if ( (RegExp.test(_value)) && (_value != "") ) {
	    //alert("Corretto");
	} else {
		jAlert("I dati inseriti non sono corretti: "+ _value, 'Notifica');
		exit=false;
	}	
	return exit;
}


MailCore.prototype.fieldRequired= function(_value,_label){
	var exit=true;
	if (_value==""){
		exit=false;
		jAlert("Il campo "+_label+" è obbligatorio!", 'Notifica');
	}
	return exit;
}

MailCore.prototype.isValidMail= function(_value,_label){
	var exit=true;
	var RegExp=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
	
	if ( (RegExp.test(_value)) && (_value != "") ) {
	  	} else {
		jAlert("Il campo "+_label+" non è corretto!", 'Notifica');
		exit=false;
	}	
	return exit;
}

MailCore.prototype.isValidDate= function(_value,_label){
	//
	var exit=true;
	var RegExp=/^(\d{1,2})-(\d{1,2})-(\d{4})/;
	
	if ((RegExp.test(_value)) && (_value != "") ) {
	  //  alert("Corretto");
	} else {
		jAlert("Il campo "+_label+" non è nel formato desiderato!",'Notifica');
		exit=false;
	}	
	return exit;
}




MailCore.prototype.acceptCondition= function(_value){
	var exit=true;
	
	if (_value=="" || !_value){
		exit=false;
		jAlert("Per procedere è necessario accettare<br> le Condizioni Legali", 'Notifica');
	}
	return exit;
}




