
var SESSIONID;

//-------------------------------------------------------------------
function ajuste_affichage(choix) {
	changeObjectVisibility("to_div","hidden");
	changeObjectVisibility("cc_div","hidden");	
	changeObjectVisibility("bcc_div","hidden");		

	if (choix == 'to') {
		getCarnetAdresse(['cible__to', 'value__' + getVal('to'), 'SESSIONID__' + SESSIONID, 'NO_CACHE'], ['toselectdiv']);	
		changeObjectVisibility("to_div","visible");
	}

	if (choix == 'cc') {
		getCarnetAdresse(['cible__cc', 'value__' + getVal('cc'), 'SESSIONID__' + SESSIONID, 'NO_CACHE'], ['ccselectdiv']);
		changeObjectVisibility("cc_div","visible");
	}
	
	if (choix == 'bcc') {
		getCarnetAdresse(['cible__bcc', 'value__' + getVal('bcc'), 'SESSIONID__' + SESSIONID, 'NO_CACHE'], ['bccselectdiv']);	
		changeObjectVisibility("bcc_div","visible");
	}
};

//-------------------------------------------------------------------
function ajouter_adresse(valeur, destination) {
	var obj = document.getElementById(destination);
	obj.value = valeur;
	ajuste_affichage();
};

//-------------------------------------------------------------------
function afficher_ab() {
	var theform = document.getElementById("form_email");
	
	if (theform) {
		changeObjectVisibility("form_email","hidden");			
		changeObjectVisibility("to_div","hidden");
		changeObjectVisibility("cc_div","hidden");	
		changeObjectVisibility("bcc_div","hidden");		
	};

	changeObjectVisibility("ab_div_shadow","visible");				
	changeObjectVisibility("ab_div","visible");			
	
 	getAllFiches(['SESSIONID__' + SESSIONID, 'NO_CACHE'], ['abselectdiv']);		 
	document.getElementById("ad_edit_div").innerHTML = 'sélectionnez une fiche du carnet d\'adresse...';	 	
};

//-------------------------------------------------------------------
function masquer_ab() {

	var theform = document.getElementById("form_email");

	if (theform) {
		changeObjectVisibility("to_div","hidden");
		changeObjectVisibility("cc_div","hidden");	
		changeObjectVisibility("bcc_div","hidden");		
		changeObjectVisibility("form_email","visible");						
	};	

	changeObjectVisibility("ab_div_shadow","hidden");				
	changeObjectVisibility("ab_div","hidden");			
};

//-------------------------------------------------------------------
function afficher_fiche(id) {
	document.getElementById("ad_edit_div").innerHTML = 'chargement en cours...';
	getFiche(['value__' + id,'SESSIONID__' + SESSIONID, 'NO_CACHE'], ['ad_edit_div']);
};

//-------------------------------------------------------------------
function enregistrer_fiche() {
	saveFiche(['SESSIONID__' + SESSIONID, 'id_fiche__' + getVal('id_fiche'),
																									'nom__' + getVal('nom'),
																									'courriel__' + getVal('courriel'),
																									'site_web__' + getVal('site_web'),
																									'telephone__' + getVal('telephone'),
																									'telephone_travail__' + getVal('telephone_travail'),
																									'cellulaire__' + getVal('cellulaire'),
																									'pagette__' + getVal('pagette'),
																									'adresse_postale__' + getVal('adresse_postale'),
																									'notes__' + getVal('notes'), 'NO_CACHE'], ['abselectdiv'], 'POST');	
	document.getElementById("ad_edit_div").innerHTML = 'sélectionnez une fiche du carnet d\'adresse...';	 		
};

//-------------------------------------------------------------------
function ajouter_fiche(nom, courriel) {
	saveFiche(['SESSIONID__' + SESSIONID, 'id_fiche__0', 'nom__' + nom, 'courriel__' + courriel, 'NO_CACHE'], [], 'POST');	
	alert(nom + ' a été ajouté au carnet d\'adresses.');
};

//-------------------------------------------------------------------
function effacer_fiche() {
	if (confirm("Êtes-vous certain de vouloir effacer cette fiche?") == true) {
		deleteFiche(['SESSIONID__' + SESSIONID, 'id_fiche__' + getVal('id_fiche'), 'NO_CACHE'], ['abselectdiv'], 'POST');	
	} else {
		return false;
	};
};

//-------------------------------------------------------------------
function printSpecial(name) {
	var name

	if (document.getElementById != null) {
		var html = '<HTML>\n<HEAD>\n';
		
		if (document.getElementsByTagName != null) {
			var headTags = document.getElementsByTagName("head");
			if (headTags.length > 0)
				html += headTags[0].innerHTML;
		}
		
		html += '\n</HE' + 'AD>\n<BODY>\n';
		
		
		var printReadyElem = document.getElementById(name);
		
		if (printReadyElem != null)	{
			html += printReadyElem.innerHTML;
		}	else	{
			alert("Could not find the printReady section in the HTML");
			return;
		}
		
		html += '\n</BO' + 'DY>\n</HT' + 'ML>';
		
		var printWin = window.open("",name);
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
//		if (gAutoPrint)
		printWin.print();
	}	else {
		alert("Sorry, the print ready feature is only available in modern browsers.");
	}
}
