$(function() { 				
    $('#close2').click(function() { 
        $.unblockUI(); 
        return false; 
    }); 
    
    $('#buttonclose2').click(function(){
    	$.unblockUI();
    	return false;
    });
    $('#imgclose2').click(function(){
    	$.unblockUI();
    	return false;
    }); 
}); 
function toggleDFCategory(item)
{
	//get the item
	var content_item = item.parentNode.nextSibling;
	if (content_item.nodeType == 3) content_item = content_item.nextSibling;
	
	var header_item = item.parentNode;

	var ts = content_item.className;
	var hs = header_item.className;
	var p = -1;
	if ((p=ts.indexOf("df_category_hidden"))>=0)
	{
		ts = ts.substring(0, p) + ts.substring(p+String("df_category_hidden").length);
		if (hs.indexOf("df_selected_category")<0) hs = hs + " df_selected_category";
	}
	else
	{
		ts = ts + " df_category_hidden";
		var q = hs.indexOf("df_selected_category");
		if (q>=0) hs = hs.substring(0, q) + hs.substring(q+String("df_selected_category").length);
	}
	//toggle the content
	content_item.className = ts;
	
	//toggle the header (if selected exists)
	header_item.className = hs;
	
	//toggle the expand/collapse icon
	item.className = item.className == "df_category_expand" ? "df_category_collapse" : "df_category_expand";
}

function _toggleDFCategory(item)
{
	//get the item
	var target_item = item.parentNode.nextSibling;
	if (target_item.nodeType == 3) target_item = target_item.nextSibling;
	
	//toggle the content
	target_item.className = target_item.className == "df_category_content df_category_hidden" ? "df_category_content" : "df_category_content df_category_hidden";
	
	//toggle the expand/collapse icon
	item.className = item.className == "df_category_expand" ? "df_category_collapse" : "df_category_expand";
}

/**
* Clique sur le lien je m'abonne
*/    
function creerDossier(nomForm){
	var form = document.forms[nomForm] ;
	var nomdossier = trim(form.nomdossier.value) ;
	bok = true ;
	if(nomdossier==""){
		document.getElementById('msgDetailsError').innerHTML ="Veuillez saisir un nom de dossier" ;
		bok = false ;
		$.blockUI({ message: $('#popupError'), css: { width: 'auto' } });
	}
	//alert(bok);
	return bok;
}

function modifierDossier(idDossier, nomDossier){
	var div = document.getElementById("modDossier");
	div.className = "affiche";
	var form = document.forms["formModDossier"] ;
	form.idDossier.value = idDossier ;
	//form.action = "editer" ;
	form.nomdossier.value = nomDossier;
	form.nomdossier.focus();
	//form.submit() ;
	
}

/**
* Suppression d'un dossier dans la page moncompte/favoris
*/
function prepareDeleteDossier(idDossier, nomDossier){
	document.getElementById('msgDetailsConfirm').innerHTML = "Confimez vous la suppression du dossier '" + nomDossier + "'?";
	document.getElementById('confirmationAction').href="javascript:deleteDossier('"+ idDossier +"')" ;
	$.blockUI({ message: $('#popupConfirmation'), css: { width: 'auto' } });
}
function deleteDossier(idDossier){
	var form = document.forms["formDossier"] ;
	form.idDossier.value = idDossier ;
	form.action = "delete" ;
	form.submit() ;
}

function prepareDeleteDocument(idDocument){
	document.getElementById('msgDetailsConfirm').innerHTML = "Confimez vous la suppression du document?" ;
	document.getElementById('confirmationAction').href="javascript:deleteDocument('"+ idDocument +"')" ;
	$.blockUI({ message: $('#popupConfirmation'), css: { width: 'auto' } });
}

function deleteDocument(idDocument){
	var form = document.forms["formDossier"] ;
	form.iddocument.value = idDocument ;
	form.action = "deleteDocument" ;
	form.submit() ;
}

/**
* Suppression d'un dossier dans la page moncompte
*/
function prepareDeleteDossierCompte(idDossier, nomDossier){
	document.getElementById('msgDetailsConfirm').innerHTML = "Confimer vous la suppression du dossier " + nomDossier ;
	document.getElementById('confirmationAction').href="javascript:deleteDossierCompte('"+ idDossier +"')" ;
	$.blockUI({ message: $('#popupConfirmation'), css: { width: 'auto' } });
}

function prepareDeleteDocumentCompte(idDocument){
	document.getElementById('msgDetailsConfirm').innerHTML = "Confimer vous la suppression du document" ;
	document.getElementById('confirmationAction').href="javascript:deleteDocumentCompte('"+ idDocument +"')" ;
	$.blockUI({ message: $('#popupConfirmation'), css: { width: 'auto' } });
}

function deleteDossierCompte(idDossier){
	var form = document.forms["formDossier"] ;
	form.idDossier.value = idDossier ;
	form.action = "deleteMC" ;
	form.submit() ;
}

function deleteDocumentCompte(idDocument){
	var form = document.forms["formDossier"] ;
	form.iddocument.value = idDocument ;
	form.action = "deleteDocumentMC" ;
	form.submit() ;
}

function modifierPassword(){
	$.blockUI({ message: $('#popupMPassword'), css: { width: 'auto' } });
}

function modifierEmail(){
	$.blockUI({ message: $('#popupMEmail'), css: { width: 'auto' } });
}

function modifierAdresse(base){
	$('#popupMAdresse').load(base+"/popup/popupmodifadresse",{},
		function(data, textStatus){
   			$.blockUI({ message: $('#popupMAdresse'), css: { width: 'auto' } }); 
   		}
   	);
}

function validModifPassword(){
    var form = document.forms["formPassword"] ;
	var password = trim(form.abonnePassword.value) ;
	bok = true ;
	if(password==""){
		document.getElementById('msgDetailsError').innerHTML ="Veuillez renseigner votre mot de passe" ;
		bok = false ;
		$.blockUI({ message: $('#popupError'), css: { width: 'auto' } });
	}
	if(password !="" && password.length <6 || password !="" && password.length >8)
	{
	document.getElementById('msgDetailsError').innerHTML ="Votre mot de passe doit comprendre entre 6 et 8 caract&egrave;res alphanum&eacute;riques." ;
		bok = false ;
		$.blockUI({ message: $('#popupError'), css: { width: 'auto' } });
	}
	if(bok){
		 var formDest = document.forms["formPasswordConfirm"] ;
		 formDest.abonnePassword.value = password;
		$.blockUI({ message: $('#popupMPasswordConfirm'), css: { width: 'auto' } });
	}
}

function confirmModifPassword() {
	var form = document.forms["formPasswordConfirm"] ;
	form.submit() ;
}


function validModifAdresse(){
    var form = document.forms["formAdresse"] ;
    var nom = trim(form.abonneNom.value) ;
    var adresse = trim(form.abonneAdresse.value) ;
	bok = true ;
	if(nom==""){
		document.getElementById('msgDetailsError').innerHTML ="Veuillez renseigner votre nom" ;
		bok = false ;
		$.blockUI({ message: $('#popupError'), css: { width: 'auto' } });
	}
	if(adresse==""){
		document.getElementById('msgDetailsError').innerHTML ="Veuillez renseigner votre adresse" ;
		bok = false ;
		$.blockUI({ message: $('#popupError'), css: { width: 'auto' } });
	}
	if(bok){
		form.submit() ;
	}
}

function validModifMail(){
    var form = document.forms["formMail"] ;
	var email = trim(form.abonneEmail.value) ;
	bok = true ;
	if(email==""){
		document.getElementById('msgDetailsError').innerHTML ="Veuillez renseigner votre e-mail" ;
		bok = false ;
		$.blockUI({ message: $('#popupError'), css: { width: 'auto' } });
	}
	else{
		if(!isEMailAddr(email)){
			document.getElementById('msgDetailsError').innerHTML ="Erreur d'adresse email" ;
			bok = false ;
			$.blockUI({ message: $('#popupError'), css: { width: 'auto' } });
		}	
	}
	if(bok){
		form.submit() ;
	}
}

function lienDocument(base,basedocument,docRef){
	document.location = base + docRef;
}
