/* fonction utilitaire de tracking dans la console firebug */
//function track(item) { if (typeof(console) != "undefined") { console.debug(item); } }
/* liaison de tous les fieldComment visibles avec les fieldCommentBox (si ceux-ci ont un contenu) */
function popupFields() {
	$(".fieldComment").filter(function(index) {
			if ($(this).css("display")=="none") return false;
			var boxText = $(".fieldCommentBox", $(this).parent()).text();
			if (boxText == null || boxText == "") return false;
			$(this).css("cursor", "help");
			return true;
		}).hover(
		function() {
			var box = $(".fieldCommentBox", $(this).parent());
			//track("box on front");
			box.css("z-index", "999");
			box.fadeIn(250);
		},
		function() { $(".fieldCommentBox", $(this).parent()).fadeOut(250); }
	);
}
/* cas particulier pour les commentaires dans les libellés des champs (fieldCommentInLabel) */
function popupCommentInLabel() {
	$(".fieldCommentInLabel").filter(function(index) {
			if ($(this).css("display")=="none") return false;
			var boxText = $(".fieldCommentBox", $(this).parent().parent()).text();
			if (boxText == null || boxText == "") return false;
			$(this).css("cursor", "help");
			return true;
		}).hover(
		function() {
			var box = $(".fieldCommentBox", $(this).parent().parent());
			//track("box on front");
			box.attr("z-index", "999");
			box.fadeIn(250);
		},
		function() { $(".fieldCommentBox", $(this).parent().parent()).fadeOut(250); }
	);
}
/* cas particulier pour les titres de zones dans les pages dossier crédit
car le CommentBox est 1 cran plus haut car un <div> ne doit pas être dans un <h3> */
function popupInformationsPartenaire() {
	$(".lblInformationsPartenaireComment").filter(function(index) {
			if ($(this).css("display")=="none") return false;
			var boxText = $(".lblInformationsPartenaireCommentBox").text();
			if (boxText == null || boxText == "") return false;
			$(this).css("cursor", "help");
			return true;			
		}).hover(
		function() {
			var box = $(".lblInformationsPartenaireCommentBox");
			box.attr("z-index", "1");
			box.fadeIn(500);
		},
		function() {$(".lblInformationsPartenaireCommentBox").fadeOut(1000);}
	);
}
function popupInformationsPersonnelles() {
	$(".lblInformationsPersonnellesComment").filter(function(index) {
			if ($(this).css("display")=="none") return false;
			var boxText = $(".lblInformationsPersonnellesCommentBox").text();
			if (boxText == null || boxText == "") return false;
			$(this).css("cursor", "help");
			return true;			
		}).hover(
		function() {
			var box = $(".lblInformationsPersonnellesCommentBox");
			box.attr("z-index", "1");
			box.fadeIn(500);
		},
		function() {$(".lblInformationsPersonnellesCommentBox").fadeOut(1000);}
	);
}
function popupPartenaireReduit() {
	$(".lblPartenaireReduitComment").filter(function(index) {
			if ($(this).css("display")=="none") return false;
			var boxText = $(".lblPartenaireReduitCommentBox").text();
			if (boxText == null || boxText == "") return false;
			$(this).css("cursor", "help");
			return true;			
		}).hover(
		function() {
			var box = $(".lblPartenaireReduitCommentBox");
			box.attr("z-index", "1");
			box.fadeIn(500);
		},
		function() {$(".lblPartenaireReduitCommentBox").fadeOut(1000);}
	);
}
/* lancement des fonctions de gestion de popup (au chargement complet de la page) */
$(popupFields);
$(popupCommentInLabel);
$(popupInformationsPartenaire);
$(popupInformationsPersonnelles);
$(popupPartenaireReduit);
/* gestion du masquage/affichage des optins en fonction de la saisie des autres champs */
$(function() {
		checkTelephone(null, true);
		checkGsm(null, true);
		$(".liTelephone input").keyup(checkTelephone);
		$(".liGSM input").keyup(checkGsm);
	}
);
function checkTelephone(event_, instantaneous_) {
	if ($(".liTelephone input").attr("value") == '') {
		if (instantaneous_) {
			$(".liOptinTelephoneSociete").css("display", "none");
			$(".liOptinTelephonePartenaires").css("display", "none");
		} else {
			$(".liOptinTelephoneSociete").slideUp(1000);
			$(".liOptinTelephonePartenaires").slideUp(1000);
		}
	} else {	
		if (instantaneous_) {
			$(".liOptinTelephoneSociete").css("display", "block");
			$(".liOptinTelephonePartenaires").css("display", "block");
		} else {
			$(".liOptinTelephoneSociete").slideDown(1000);
			$(".liOptinTelephonePartenaires").slideDown(1000);
		}
	}
}
function checkGsm(event_, instantaneous_) {
	if ($(".liGSM input").attr("value") == '') {
		if (instantaneous_) {
			$(".liOptinGsmSociete").css("display", "none");
			$(".liOptinGsmPartenaires").css("display", "none");
		} else {
			$(".liOptinGsmSociete").slideUp(1000);
			$(".liOptinGsmPartenaires").slideUp(1000);
		}
	} else {
		if (instantaneous_) {
			$(".liOptinGsmSociete").css("display", "block");
			$(".liOptinGsmPartenaires").css("display", "block");
		} else {
			$(".liOptinGsmSociete").slideDown(1000);
			$(".liOptinGsmPartenaires").slideDown(1000);
		}
	}
}


/* ajout d'un masque de saisie sur le numéro de compte bancaire */
function PageLoadedHandler(sender, args) {
	if (uiContext.Client.Pays == "BE") {
		$(".txtNumeroRegistreNationalPartenaire").mask("99 99 99 999 99");
	}
}
$(function() {
		if (uiContext.Client.Pays == "BE") {
			$(".txtNumeroCompteBanque").mask("999 9999999 99");
			$(".txtNumeroRegistreNational").mask("99 99 99 999 99");
		}
		/* pour le partenaire, on applique aussi le masque sur un retour de requête ajax car */
		/*le controle n'est pas forcément présent au chargement initial de la page */
		Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(PageLoadedHandler);
	}
);




