var mli_optin_sending = 0;

var mli_optin_register = function (IDForm)
		{
//alert(IDForm);
		if (mli_optin_sending==1) return;
		var SendData = new WPLY.DataAjax;
		if ((IDForm.name.value=="") || (IDForm.email.value=="")) return;
		
		if (IDForm.ButtonNL) IDForm.ButtonNL.style.display="none";
		if (document.getElementById("mlimember-thankyou-"+IDForm.idop.value)) document.getElementById("mlimember-thankyou-"+IDForm.idop.value).innerHTML="<img src=\""+WPLY_host+"/source/addon/mailinglist/images/loading.gif\" border=\"0\" />";
		
		if ((typeof(mli_optin_sendingtype) != "undefined") && (mli_optin_sendingtype=="js"))
				{
				mli_optin_sending=1;	
				SendData.callback = function (res)
					{
						
						mli_optin_sending=0;
						//alert(mli_optin_success);
						if (mli_optin_success==1)
							{
								set_thm=1;
								if (typeof(mli_optin_thp)!="undefined") {if (mli_optin_thp!="") {location.href=mli_optin_thp; return;}}
								if ((set_thm==1) && (typeof(mli_optin_thm)!="undefined"))
									if (document.getElementById("mlimember-thankyou-"+IDForm.idop.value)) document.getElementById("mlimember-thankyou-"+IDForm.idop.value).innerHTML=mli_optin_thm;
								if (typeof(mli_optin_eup)!="undefined") if (mli_optin_eup!="")  location.href=mli_optin_eup;
							}
						else
							{
								//alert(mli_optin_fieldrequest);
								if (IDForm.ButtonNL) IDForm.ButtonNL.style.display="block";
								if (document.getElementById("mlimember-thankyou-"+IDForm.idop.value)) document.getElementById("mlimember-thankyou-"+IDForm.idop.value).innerHTML="";
								if (mli_optin_fieldrequest!="") 
									fr = mli_optin_fieldrequest.split(",");
								
								for(var i = 0; i < IDForm.elements.length; i++){
									IDForm.elements[i].style.background="#f2f3f3";		
									  }	
								var b=mli_optin_fieldrequest+"";
								var c=b.split(",");
								
								for (i=0;i<c.length;i++)
									{
									if (c[i]!="") $("#wml-input-"+c[i]).css({background:"red"});
									
									if (c[i]=="privacy") alert("Esprimere il consenso alla Privacy!");
									
									}
							}
					}
				SendData.PostFormLoadJS(IDForm,"PROC=MLI_Register_User&OM=JS");
				return;	
				}
		
		
		
		else
		{
		
			SendData.callback = function (res) {
				var json = new WPLY.JSON();
				var a=json.decode(res); 
				var uco = "";
				if (typeof(IDForm.uco)=="undefined") uco ="";
					else uco = IDForm.uco.value;
	
				mli_optin_sending=0;
				if (a.success==false) 
					{
					if (IDForm.ButtonNL) IDForm.ButtonNL.style.display="block";
					if (document.getElementById("mlimember-thankyou-"+IDForm.idop.value)) document.getElementById("mlimember-thankyou-"+IDForm.idop.value).innerHTML="";
					for(var i = 0; i < IDForm.elements.length; i++){
						IDForm.elements[i].style.background="#f2f3f3";		
						  }
					var b=a.fieldrequest+"";
					var c=b.split(",");
					//IDForm."name".style.background="red";
					
					//$("#wml-input-email_"+uco).css({background:"red"});
					for (i=0;i<c.length;i++)
						{
						if (c[i]!="") 
							{
								if (uco=="") $("#wml-input-"+c[i]).css({background:"red"});
									else $("#wml-input-"+c[i]+"_"+uco).css({background:"red"});
							}
						if (c[i]=="privacy") alert("Esprimere il consenso alla Privacy!");
						
						}
					}
				else //Succedd true
					{
					
	
						if ((a.thp!="") && (typeof(a.thp)!="undefined")) {location.href=a.thp; return;}
							else if (document.getElementById("mlimember-thankyou-"+IDForm.idop.value)) document.getElementById("mlimember-thankyou-"+IDForm.idop.value).innerHTML=a.thm;
					if ((a.eup!="") && (typeof(a.eup)!="undefined"))  location.href=a.eup;
					}
			}
			mli_optin_sending=1;
			SendData.PostForm(IDForm,"PROC=MLI_Register_User");
		}
}	


