;(function($) {


if (/1\.(0|1|2)\.(0|1|2)/.test($.fn.jquery) || /^1.1/.test($.fn.jquery)) {
    alert('blockUI requires jQuery v1.2.3 or later!  You are using v' + $.fn.jquery);
    return;
}

$.fn.blockIris = function(message) {
	var msg = null;
	if(message!=null) {
		msg = message;
	}
	$(this).block({
		message: msg, 
		css: { 
				backgroundColor: '#000',
			 	color: '#FFF',
			 	opacity: '.5',
			 	border: '0px solid #000',
			 	padding: '15px',
		        height:         '20%', 
		        width:          '20%', 
		        top:            '100%', 
		        left:           '100%', 			 	
			 	showOverlay: true,
			 	textAlign:	'center',
			 	'font-size': '11pt'
		 	},
		overlayCSS: {
		 	backgroundColor: '#E1E1E1',
		 	opacity: '.5'
		 	},
	    centerX: true, // <-- only effects element blocking (page block controlled via css above) 
	    centerY: true
	});	 
}

$.fn.goHref = function(href,callback,blockTarget) {
	var target = $(this);
	callback = callback || function(){};

	if(blockTarget!=null) {
		var positionBefore = $("#"+blockTarget).size() > 0 ? $("#"+blockTarget).get(0).style.position: "";
		$("#"+blockTarget).block({
			message: 'Chargement...', 
			css: { 
					backgroundColor: '#000',
				 	color: '#FFF',
				 	opacity: '.5',
				 	border: 'none',
				 	padding: '5px',
			 		'-webkit-border-radius': '10px',
			 		'-moz-border-radius': '10px' 
			 	},
			overlayCSS: { backgroundColor: '#EBEBEB' }
		});	 
	}

	$.ajax({
		type: "POST",
		url: href,
		dataType : "html",
		data: {}, // necessaire pour passer les proxys sous FF
		success : function(html) {
			target.html(html);
			callback();
			if(blockTarget!=null) {
				$("#"+blockTarget).unblock();
				if ($("#"+blockTarget).size() > 0) {
					$("#"+blockTarget).get(0).style.position = positionBefore;
				}
			}
		},
		error : function( httprequest, textStatus, errorThrown){
			if(blockTarget!=null) {
				$("#"+blockTarget).unblock();
				if ($("#"+blockTarget).size() > 0) {
					$("#"+blockTarget).get(0).style.position = positionBefore;
				}
			}
		}
	});
};

$.goHref2 = function(href,blockTarget, nbSent) {
	var target = $(this);
	if (nbSent > 2) {
		alert('Attention, le quota d\'envoi de SMS maximal a été atteint pour la session.')
	}
	else {
		if(blockTarget!=null) {
			$("#"+blockTarget).block({
				message: 'Envoi du SMS...', 
				css: { 
						backgroundColor: '#000',
					 	color: '#FFF',
					 	opacity: '.5',
					 	border: 'none',
					 	padding: '5px',
				 		'-webkit-border-radius': '10px',
				 		'-moz-border-radius': '10px' 
				 	},
				overlayCSS: { backgroundColor: '#EBEBEB' }
			});	 
		}
	
		$.ajax({
			type: "POST",
			url: href,
			dataType : "html",
			data: {}, // necessaire pour passer les proxys sous FF
			success : function(html) {
				nbSent = nbSent + 1;
				if(blockTarget!=null) {
					$("#"+blockTarget).unblock();
				}
			},
			error : function( httprequest, textStatus, errorThrown){
				if(blockTarget!=null) {
					$("#"+blockTarget).block({
						message: 'Erreur lors de l\'envoi du SMS...', 
						css: { 
								backgroundColor: '#000',
							 	color: '#FFF',
							 	opacity: '.5',
							 	border: 'none',
							 	padding: '5px',
						 		'-webkit-border-radius': '10px',
						 		'-moz-border-radius': '10px' 
						 	},
						overlayCSS: { backgroundColor: '#EBEBEB' }
					}).unblock();	 
				}
			}
		});
	}
	return nbSent;

};

$.fn.goHrefAddSalleFavorite = function(href, codsal, callback, blockTarget, messageAjoute, messageDelete) {
	var target = $(this);
	callback = callback || function(){};

	if(blockTarget!=null) {
		$("#"+blockTarget).block({
			message: 'Chargement...', 
			css: { 
					backgroundColor: '#000',
				 	color: '#FFF',
				 	opacity: '.5',
				 	border: 'none',
				 	padding: '5px',
			 		'-webkit-border-radius': '10px',
			 		'-moz-border-radius': '10px' 
			 	},
			overlayCSS: { backgroundColor: '#EBEBEB' }
		});	 
	}

	$.ajax({
		type: "POST",
		url: href,
		dataType : "html",
		data: {}, // necessaire pour passer les proxys sous FF
		success : function(html) {
			if( jQuery("#action_"+codsal).attr("value") == "ajoute" ) {
				jQuery("#picto_"+codsal+" img").attr("src", "/static/uploads/fnacv2/images/pictos/pictoDeleteCinemaFavoris.png");
				jQuery("#action_"+codsal).attr("value", "delete");
				alert(messageAjoute);
			} else {
				jQuery("#picto_"+codsal+" img").attr("src", "/static/uploads/fnacv2/images/pictos/pictoAddCinemaFavoris.png");
				jQuery("#action_"+codsal).attr("value", "ajoute");
				alert(messageDelete);
			}
			if( callback ) { callback(); }
			if(blockTarget!=null) {
				$("#"+blockTarget).unblock();
			}
		},
		error : function( httprequest, textStatus, errorThrown){
			if(blockTarget!=null) {
				$("#"+blockTarget).unblock();
			}
		}
	});
};

})(jQuery);

