/* Programmation Javascript par Vincent */
window.onload = initialiser;

function initialiser() {
	genererMenuActif();
	genererSousMenusIE();
	genererLiensExternes();
}


function genererMenuActif() {
	if ( document.getElementById ) {
		uri = window.location.href;
		
		if ( uri.indexOf("/agent/") != -1 )
			identifiant = "mn_agent";
		else if (  ( (uri.indexOf("/acheter.html") != -1) || (uri.indexOf("/buy.html") != -1) ) && ( (uri.indexOf("/conseils") == -1) && (uri.indexOf("/advice") == -1) )  )
			identifiant = "mn_acheter";
		else if (  ( (uri.indexOf("/vendre.html") != -1) || (uri.indexOf("/sell.html") != -1) ) && ( (uri.indexOf("/conseils") == -1) && (uri.indexOf("/advice") == -1)  ) )
			identifiant = "mn_vendre";
		else if ( (uri.indexOf("/nouvelles/") != -1) || (uri.indexOf("/news/") != -1) )
			identifiant = "mn_nouvelles";
		else if ( (uri.indexOf("/outils/") != -1) || (uri.indexOf("/tools/") != -1) )
			identifiant = "mn_outils";
		else if ( uri.indexOf("/faq.html") != -1 )
			identifiant = "mn_faq";
		else if ( (uri.indexOf("/apropos.aspx") != -1) || (uri.indexOf("/about.aspx") != -1) )
			identifiant = "mn_apropos";
		else
			identifiant = 0;
			
		if ( identifiant )
			document.getElementById(identifiant).className = "actif";
	}
}


function genererSousMenusIE() {
	if ( document.getElementById && document.all ) {
		oMenu = document.getElementById("menu");
		classeSurvol = "survol";
		
		for ( compteurUL = 0; compteurUL < oMenu.childNodes.length; compteurUL++ ) {
			oUL = oMenu.childNodes[compteurUL];
			if ( oUL.nodeName == "UL" ) {
				for ( compteurLI = 0; compteurLI < oUL.childNodes.length; compteurLI++ ) {
					oLI = oUL.childNodes[compteurLI];
					if ( oLI.nodeName == "LI" ) {
						oLI.onmouseover = function () { this.className = classeSurvol + " " + this.className; }
						oLI.onmouseout = function () { this.className = (this.className).replace(classeSurvol + " ", ""); }
					}
				}
			}
		}
	}
}



function genererLiensExternes() {
	if ( document.getElementsByTagName ) {
		for ( compteur = 0; compteur < document.getElementsByTagName("A").length; compteur++ ) {
			eAncre = document.getElementsByTagName("A")[compteur];
			if ( eAncre.className.indexOf("externe") != -1 ) {
				if ( eAncre.href.indexOf("collegeimmobilier.com") != -1 ) {
					eAncre.onclick = function () { window.open(this.href, "CollegeImmobilier", "top=0,left=0,width=" + screen.availWidth + ",height=" + screen.availWidth + ",menubar=1,location=1,toolbar=1,resizable=yes"); return false; }
				} else {
					eAncre.onclick = function () { window.open(this.href); return false; }
				}
			} else if ( eAncre.href.indexOf("http://services.centris.ca/sectionPublic/recherche") != -1 ) {
				largeur = 570;
				hauteur = 470;
				posX = Math.ceil( ( screen.availWidth / 2 ) - ( largeur / 2 ) );
				posY = Math.ceil( ( screen.availHeight / 2 ) - ( hauteur / 2 ) );
				eAncre.onclick = function () {
									uneFenetre = window.open(this.href, "Trouver", "left=" + posX + ",top=" + posY + ",width=" + largeur + ",height=" + hauteur + ",menubar=no,location=no,toolbar=no,resizable=yes,scrollbars=no");
									uneFenetre.focus();
									return false;
									}
			}
		}
	}
}


function classerRangees(eTable) {
	if ( document.getElementById ) {
		compteurTR = 0;
		for ( compteur = 0; compteur < eTable.childNodes.length; compteur++ ) {
			eTR = eTable.childNodes[compteur];
			if ( eTR.nodeName == "TR" ) {
				if ( compteurTR % 2 == 0 )
					eTR.className = "pair " + eTR.className;
				compteurTR++;
			}
		}
	}
}

function clearBox(box) {
	box.value = "";
}


/* Construction du systeme de recherche pour SearchMaker Pro */
function executerRecherche() {
	uri = window.location.href;
	
	if ( uri.indexOf('?s=') > -1 ) {
		dernierePos = uri.length;
		if ( uri.lastIndexOf("&x=") != -1 )
			dernierePos = uri.lastIndexOf("&x=");
			
		valeurForm = uri.substring( uri.indexOf('?s=') + 3, dernierePos );
		valeurForm = valeurForm.replace(/\+/gi, " ");
		
		// Conversion des accents
		valeurForm = valeurForm.replace(/%C3%89/g, "É");
		valeurForm = valeurForm.replace(/%C3%A9/g, "é");
		valeurForm = valeurForm.replace(/%C3%88/g, "È");
		valeurForm = valeurForm.replace(/%C3%A8/g, "è");
		valeurForm = valeurForm.replace(/%C3%8A/g, "Ê");
		valeurForm = valeurForm.replace(/%C3%AA/g, "ê");
		valeurForm = valeurForm.replace(/%C3%8B/g, "Ë");
		valeurForm = valeurForm.replace(/%C3%AB/g, "ë");
		valeurForm = valeurForm.replace(/%C3%80/g, "À");
		valeurForm = valeurForm.replace(/%C3%A0/g, "à");
		valeurForm = valeurForm.replace(/%C3%82/g, "Â");
		valeurForm = valeurForm.replace(/%C3%A2/g, "â");
		valeurForm = valeurForm.replace(/%C3%94/g, "Ô");
		valeurForm = valeurForm.replace(/%C3%B4/g, "ô");
		valeurForm = valeurForm.replace(/%C3%87/g, "Ç");
		valeurForm = valeurForm.replace(/%C3%A7/g, "ç");
		valeurForm = valeurForm.replace(/%C3%8E/g, "Î");
		valeurForm = valeurForm.replace(/%C3%AE/g, "î");
		valeurForm = valeurForm.replace(/%C3%8F/g, "Ï");
		valeurForm = valeurForm.replace(/%C3%AF/g, "ï");
		
		valeurForm = unescape(valeurForm);
		
		document.write('<form name="formSearch">');
		document.write('<input type="hidden" name="txtSearch" value="' + valeurForm + '">');
		document.write('</form>');
		SMPStartSearch();
	}
}

/* - - - - - - - - - - - - - - - - - - - - - - - - */
/* Ouvre la fonction financiere dans une nouvelle  */
/* fenetre                                         */
/* - - - - - - - - - - - - - - - - - - - - - - - - */
function ouvrirFonctionFinaciere( eAncre) {
	
	var iLargeur = 800;
	var iHauteur = 800;
	var iPosX = Math.round( ( screen.availWidth / 2 ) - ( iLargeur / 2 ) );
	var iPosY = Math.round( ( screen.availHeight / 2 ) - ( iHauteur / 2 ) );
	
	var oFenetre = window.open( eAncre.href, "FonctionsFinancieres", "left=" + iPosX + ",top=" + iPosY + ",width=" + iLargeur + ",height=" + iHauteur + ",menubar=no,locationbar=no,statusbar=no,scrollbars=yes" );
	oFenetre.focus();
}