/**
 * Customer Email Book Javascript
 * 
 * @category	Millesima
 * @package		Millesima_Customer
 * @author		Emmanuel FAURE <efaure@millesima.com>
 * @Mantis		MIL-251
 */
function addEmail(url){	
	value = document.getElementById('new_email').value;
	
	//result = Validation.get('IsEmpty').test(value) || /^([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*@([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*\.(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]){2,})$/i.test(value);
	result = /^[\w\-_\.]{1,}[@][\w\-\.]{1,}[.]([\w]{2,4})$/.test(value);
	
	if(result){
		hideJ2tOverlay();
		showLoading();
		// Used for customer/account/edit
		var myAjax = new Ajax.Request(
	    	url, 
	    	{
	            asynchronous: true,
	            method: 'post',
	            postBody: $('form-validate').serialize(),
	            parameters : $('form-validate').serialize(true),		    
			    onException: function (xhr, e)
		        {
		           //alert('Exception : ' + e);
		        },
		        onSuccess: function(xhr){            
		            //alert(xhr.responseText);
		            //alert ('//succes//'+xhr.status + ' : ' + transport.statusText);  
		            
		        },
		        onComplete: function (xhr)
		        {     
		            //alert(xhr.responseText);
		            hideJ2tOverlaySmoothForced();  
		            $('j2t_ajax_progress').hide();    
		            $('ajaxresponse').replace(xhr.responseText);
		            return true;
		        }
	    	} 
	    );
	}
}



function updateEmail(url,idEmail,value){
	//result = Validation.get('IsEmpty').test(value) || /^([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*@([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*\.(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]){2,})$/i.test(value);
	
	result = /^[\w\-_\.]{1,}[@][\w\-\.]{1,}[.]([\w]{2,4})$/.test(value);
	if(result){
		hideJ2tOverlay();
		showLoading();
		// Used for customer/account/edit
		var myAjax = new Ajax.Request(
		    url,
		    {
		        asynchronous: true,
		        method: 'post',
		        parameters:{
		         	'emailform[id]':idEmail,
					'emailform[value]':value,
		        },
			    onException: function (xhr, e)
			    {
			       //alert('Exception : ' + e);
			    },
			    onSuccess: function(xhr){
			        //alert(xhr.responseText);
			        //alert ('//succes//'+xhr.status + ' : ' + transport.statusText);
			    },
			    onComplete: function (xhr){
			     	//alert(xhr.responseText);
			    	//alert ('//->//'+xhr.status + ' : ' + xhr.statusText+" - "+ xhr.responseText);
			        hideJ2tOverlaySmoothForced();  
			        $('j2t_ajax_progress').hide();    
			        $('ajaxresponse').replace(xhr.responseText);
			        return true;
			    }
		    } 
		); 
	}
}



function subscribeNewsletter(url,bool){
	hideJ2tOverlay();
	showLoading();
	// Used for customer/account/edit
	var myAjax = new Ajax.Request(
	    url,
	    {
	        asynchronous: true,
	        method: 'post',
	        parameters:{
	         	'subscribe':bool,
			},
		    onException: function (xhr, e)
		    {
		       //alert('Exception : ' + e);
		    },
		    onSuccess: function(xhr){
		        //alert(xhr.responseText);		    	
		        //alert ('//succes//'+xhr.status + ' : ' + transport.statusText);
		    },
		    onComplete: function (xhr){
		    	//alert ('//<<<//'+xhr.status + ' : ' + xhr.statusText+" - "+ xhr.responseText);
		     	//alert(xhr.responseText);
		    	hideJ2tOverlaySmoothForced();  
		        $('j2t_ajax_progress').hide();    
		        $('ajaxresponse').replace(xhr.responseText);
		        return true;
		    }
	    } 
	);       
}


function otherEmail(url,idEmail){
	hideJ2tOverlay();
	showLoading();
	// Used for customer/account/edit
	var myAjax = new Ajax.Request(
	    url,
	    {
	        asynchronous: true,
	        method: 'post',
	        parameters:{
	         	'emailform[id]':idEmail,
			},
		    onException: function (xhr, e)
		    {
		       //alert('Exception : ' + e);
		    },
		    onSuccess: function(xhr){
		        //alert(xhr.responseText);
		    	
		        //alert ('//succes//'+xhr.status + ' : ' + transport.statusText);
		    },
		    onComplete: function (xhr){
		    	//alert ('//<<<//'+xhr.status + ' : ' + xhr.statusText+" - "+ xhr.responseText);
		     	//alert(xhr.responseText);
		        hideJ2tOverlaySmoothForced();  
		        $('j2t_ajax_progress').hide();    
		        $('ajaxresponse').replace(xhr.responseText);
		        return true;
		    }
	    } 
	);       
}

