// JavaScript Document
function initDoc() {
	$("#coming_soon").attr("href","#");
	$("#coming_soon").hover(
		function() { Tip('COMING SOON...');},
		function() { UnTip();}
	);	
}

function addServiceToolTip() {
	var aService = $("a","#content_primary").get();
	for (var i=0;i<aService.length;i++) {
		$(aService[i]).hover(
			function() {
				if ($('#nav_language a').attr("title").indexOf("English") != -1) {
					Tip('<strong>' + this.innerHTML + '</strong><br/>Cliquez pour voir les avocats dans ce domaine');
				} else {
					Tip('<strong>' + this.innerHTML + '</strong><br/>Click to view lawyers listing in that area of expertise');
				}
				$("#lawyers_listing").attr("title", this.innerHTML);
			},
			function() {
				UnTip();
			}
		);
	}	
}

function addGoToCV() {
	var aLawyers = $("#services #aside_content ul li");
	var aLawLink, lawyerId;
	var arrIds = new Array();
	for (var i=0;i<aLawyers.length;i++) {
		aLawLink = $("a",aLawyers[i]).get();		
		lawyerId = aLawyers[i].id.substr(6,aLawyers[i].id.length);
		for (var y=0;y<aLawLink.length;y++) {
			arrIds.push(lawyerId);
			$(aLawLink[y]).bind("click", {avocatId:lawyerId}, function(e) {
				GoToCV(e.data.avocatId);
			});
			if ($.browser.msie) {
				$(aLawLink[y]).attr("href","#");
			}
		}
	}
	return(arrIds.pop());
}

function getLastAvocatId(fromPage) {
	var aLawyers;
	aLawyers = $("li","#aside_content").get();

	var aLawLink, lawyerId;
	var arrIds = new Array();
	for (var i=0;i<aLawyers.length;i++) {
		aLawLink = $("a",aLawyers[i]).get();
		lawyerId = aLawyers[i].id.substr(6,aLawyers[i].id.length);
		for (var y=0;y<aLawLink.length;y++) {
			arrIds.push(lawyerId);
		}
	}
	arrIds.sort(function(a,b){return a - b})
	return(arrIds.pop());	
}

function SwitchLanguage(langue) {
	if (langue > 0) {
		var str = document.location.href;
		switch(langue) {
			case 1:
				str = str.replace('eng','fra');
				break;
			case 2:
				str = str.replace('fra','eng');
				break;
		}
	}
	document.location.href = str;
}

function addExperts() {
  $.ajax({
		 type: "GET",
		 url: "../../data/expertises.xml",
		 dataType: "xml",
		 success: function(xml) {
			 $("domaine", xml).each(function(){
				var id_domaine = $(this).attr('id');
				var objAvocats = $(this).find("avocat");
				$("#domaine" + id_domaine).removeAttr("href");
				$("#domaine" + id_domaine).bind("click", {xmlAvocats:objAvocats} ,function(e) {
					var strIds = "";
					var objIds = new Object;
					for(var i=0;i<e.data.xmlAvocats.length;i++) {
						strIds += $(e.data.xmlAvocats[i]).attr("id") + ",";
					}
					strIds = strIds.substr(0,strIds.length-1);
					objIds.ids = strIds;
					ShowLawyer(objIds);
				});
			 });
		 }
	 }); 
}

function addShowCV() {
	$("#aside_content li").each(function() {
		var avocat_id = $(this).attr("id").substr(6,$(this).attr("id").length-1);
		$("a", $(this)).bind("click", {avocatId:avocat_id}, function(e) {
			ShowCV(e.data.avocatId);
		});
	});	
}

function GetCurrentYear() {
	var yr;
	Today = new Date();
	yr = Today.getFullYear();
	return yr;
}

function ShowLawyer(objIds) {
	var obj;
	var arrID = objIds.ids.split(",");
	for (var i=1; i <= getLastAvocatId(); i++) {
		obj = document.getElementById('avocat' + i);
		if (obj != null) {
			obj.style.display = 'none';
		}
	}
	
	for (i=0; i < arrID.length; i++) {
		$("#avocat" + arrID[i]).show("slow");
	}
}

function ShowCV(avocatId) {
	var objCV;
	var objList;
	
	for (var i=1; i <= getLastAvocatId(1); i++) {
		objCV  = document.getElementById('cv' + i);
		objList = document.getElementById('avocat' + i);		

		if ((objCV != null) && (objList != null)) {
			if (avocatId == i) {
				objCV.style.display = 'block';
				objList.className = 'cvSelected';				
			} else {
				objCV.style.display = 'none';
				objList.className = '';				
			}
		}
	}	
}

function GoToCV(avocatId) {
	window.location.href = 'avocats.htm?id=' + avocatId;
}

