$(document).ready(function(){

	//alert(isWWW(""));
	$("#AddEmail").click(function(){
		
		
		$("#Mailing_lll #Mname").val(trim2($("#Mailing_lll #Mname").val()));	
		$("#Mailing_lll #Memail").val(trim2($("#Mailing_lll #Memail").val()));

		
		$(this).removeClass("input_error");
		
		$("input").focus(function(){
			$(this).removeClass("input_error");
		});
		
		
		var ComSubmit2=true;
		

		if($("#Mailing_lll #Mname").val() == "")
		{
			//$("#Mailing_lll #Mname").addClass("input_error");
			//ComSubmit2 = false;
		}
		////////////////////////////////// 
		if($("#Mailing_lll #Memail").val() == "")
		{
			$("#Mailing_lll #Memail").addClass("input_error");
			ComSubmit2 = false;
		}
		else if(!isEmail2($("#Mailing_lll #Memail").val()))
		{
			$("#Mailing_lll #Memail").addClass("input_error");
			ComSubmit2 = false;
		}
		////////////////////////////////////////////////
		
		//return ComSubmit2;
		
		if(ComSubmit2 == true)
		{
			$("#ajax_loader_email").show();
			$.ajax({
				url: 'redirect.php',
				type: 'POST',
				data: { random: Math.random(),
						Com :  "AddEmail",
						name :  $("#Mname").val(),
						email :  $("#Memail").val()
					  },
				success: function(data) 
				{ 
					//alert("success");
					$("#ajax_loader_email").hide();
					$("#dialog").click();
					$(".dialog_massage").html($("#Memail").val()+"<br />شكرا لإشتراكك في قائمتنا البردية");
				}
			});
			
		}
		return false;
	});


});



function trim2(x){
		return x.replace(/^\s*/,'');
	}
function isEmail2(str){
		var regex = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
		return regex.test(str);
	}
function isNumber2(str){
		var regex = /\d+/;
		return regex.test(str);
	}
function isWWW2(str){
		var regex = /[a-zA-Z0-9._-]{6,20}/;
		return regex.test(str);
	}
function isWL2(str){
		var regex = /[a-zA-Z0-9]{6,20}/;
		return regex.test(str);
	}
