/******************************
 * 
 *    mot de passe oublié
 * 
 ****************************/
function getPasswordForget()
{
	$.post(this.action,$(this).serialize(),responsePasswordForget,"json");
	return false;
}

function responsePasswordForget( data ){
	$('.error-msg').remove();
	
	var sMessage = '';
	
	if(data.success == true)
	{
		sMessage = '<p class="valid-msg">Un email contenant votre mot de passe vous a été envoyé.</p>';
		$('#form-forget-password').hide();
	}
	else
	{
		sMessage = '<ul class="error-msg">';
		
		for (var error in data.errors)
			sMessage += '<li>'+data.errors[error]+'</li>\r\n';
		
		sMessage += '</ul>';
	}
	
	$("#form-forget-password").before(sMessage);
	$('.popin').css('height','auto');
	
}

/******************************
 * 
 *         connexion
 * 
 ****************************/

function identification(){
	
	$('#submit-connexion').disable();//attr('disabled', 'disabled');
	
	$.post(this.action,$(this).serialize(),retourIdentification,"json");
	
	return false;
}

function retourIdentification( data ){
	
	var sMessage = '';
	
	if(data.success == true)
	{
		location.reload();
	}
	else
	{
		$('#submit-connexion').enable();//removeAttr('disabled');

		sMessage = '<ul class="error-msg">';
		
		for (var error in data.errors)
			sMessage += '<li>'+data.errors[error]+'</li>\r\n';
		
		sMessage += '</ul>';
		
		 //$('body').popin({ content: sMessage, width: 450, show: true, title: 'Identification' });
		 SAlert.alert(sMessage, 'Identification');
		
		//-- donner id aux popins
		//$(sMessage).appendTo(popin);
		
	}
}

/******************************
 * 
 *     		Bannière
 * 
 ****************************/

function buildPub(url,wrapper,width, height)
{
	var oWrapper = $('#' + wrapper);
	if (oWrapper.length == 0)
		return;
	if ( swfobject.getFlashPlayerVersion().major >= 6 ) {
		var flashvars = {};
		var params = {
			bgcolor: "#000000",
			wmode:"transparent",
			allowFullScreen: 'false'
		};
		var attributes = {};
		
		oWrapper.width(width).height(height);
		swfobject.embedSWF(url, wrapper, width, height, "9.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);
	}
}

function popinPubGauche()
{
	//$('body').popin({trigger: $('#crypto-link'), urlAjax: SDefines.URL_AJAX+'partial/panier/cryptogramme', title: 'Cryptogramme', width: 500});
	
	$('body').popin({id: 'pub', urlAjax: SDefines.URL_AJAX+'partial/home/popin_pub', title: 'Annonce', width: 500});
	$('#popin_pub').jqmShow();
}



$(
	function(){
		//-- mot de passe oublié
		$('body').popin({trigger: $('#pass-forget'), urlAjax: SDefines.URL_AJAX+'compte/passwordForget', title: 'Mot de passe oublié ?', width: 450, onLoad: function(){$('#form-forget-password').submit(getPasswordForget);} });
		
		//-- login
		$('#form-identification').submit(identification);
		
		//-- effets
		$('body').popin({trigger: $('#effect-mode-call'), urlAjax: SDefines.URL_AJAX+'effet/mode.html', title: 'L\'Effet Mode', width: 450 });
		$('body').popin({trigger: $('#effect-bon-plan-call'), urlAjax: SDefines.URL_AJAX+'effet/bon_plan.html', title: 'L\'Effet Bon Plan', width: 450 });
		$('body').popin({trigger: $('#effect-sur-mesure-call'), urlAjax: SDefines.URL_AJAX+'effet/sur_mesure.html', title: 'L\'Effet Sur Mesure', width: 450 });
		

		

		/*
		 * Menu principal
		 */
		$('#cssdropdown .withSubMenu').hover(
			function()
			{
				$('ul', $(this)).show();
			},
			
			function()
			{
				$('ul', $(this)).hide();
			}
		);
	}
	
);