
var IS_IE = navigator.appVersion.indexOf("MSIE") != -1;
var IS_IE_5 = (document.all && document.getElementById) != top.undefined;
var IS_IE_6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.") != -1));
var IS_IE_7 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 7.") != -1));
var IS_NS_6 = (!document.all && document.getElementById);

// GLOBAL VARIABLES
var bgFaderOpacityCounter;
var bgFaderIntervalHandle;
var formFaderOpacityCounter;
var formFaderIntervalHandle;
var formHeightCounter;
var formHeightIntervalHandle;

function setDivOpacity(divId, opacity)
{
	if(IS_IE_5) document.getElementById(divId).filters.alpha.opacity = opacity;
	if(IS_NS_6) document.getElementById(divId).style.MozOpacity = opacity/100;
}


function showSiteLink()
{
	setDivOpacity('fadedBackground', 90);
	$('fadedBackground').toggleClassName('class_hidden');
	$('fadedBackground').toggleClassName('class_visible');
	$('siteLinkDiv').show();
}

function hideSiteLink()
{
	$('siteLinkDiv').hide();
	setDivOpacity('fadedBackground', 0);
	$('fadedBackground').toggleClassName('class_hidden');
	$('fadedBackground').toggleClassName('class_visible');
}

function showMentionsLegales()
{
	setDivOpacity('fadedBackground', 90);
	$('fadedBackground').toggleClassName('class_hidden');
	$('fadedBackground').toggleClassName('class_visible');
	$('mentionsLegalesDiv').show();
}

function hideMentionsLegales()
{
	$('mentionsLegalesDiv').hide();
	setDivOpacity('fadedBackground', 0);
	$('fadedBackground').toggleClassName('class_hidden');
	$('fadedBackground').toggleClassName('class_visible');
}

function demandeDeQuestionFormShow(bool, text, destEmail, subject)
{	
	if (text)
		$('demandeDeQuestionForm_champ_Question').value = text;
	
	if (destEmail)
		$('demandeDeQuestionForm_champ_destemail').value = destEmail;
		
	if (subject)
		$('demandeDeQuestionForm_champ_subject').value = subject;
		
	if (bool == true) {
		
		if (IS_IE_7) {
			$('bodyElement').up().setStyle({overflow : 'hidden'});
		}

		hideDropDownLists(true);
		bgFaderOpacityCounter = 0;
		bgFaderIntervalHandle = setInterval('fadeInDiv(true, "fadedBackground", 15, 90, "bgFaderOpacityCounter", "bgFaderIntervalHandle")', 100);
		
		formFaderOpacityCounter = -50;
		formFaderIntervalHandle = setInterval('fadeInDiv(true, "demandeDeQuestionFormDiv", 20, 100, "formFaderOpacityCounter", "formFaderIntervalHandle")', 50);
		
		setTimeout('document.getElementById("demandeDeQuestionForm_champ_nom").focus()', 1000);
		
		formHeightCounter = 0;
		formHeightIntervalHandle = setInterval("rollDiv('demandeDeQuestionFormDiv', 36, 3, 'formHeightCounter', 'formHeightIntervalHandle')", 50);
	}
	else {
		
		setTimeout('hideDropDownLists(false)', 800);
		bgFaderIntervalHandle = setInterval('fadeInDiv(false, "fadedBackground", 20, 0, "bgFaderOpacityCounter", "bgFaderIntervalHandle")', 100);

		formFaderIntervalHandle = setInterval('fadeInDiv(false, "demandeDeQuestionFormDiv", 20, 0, "formFaderOpacityCounter", "formFaderIntervalHandle")', 100);

		formHeightIntervalHandle = setInterval("rollDiv('demandeDeQuestionFormDiv', 0, -4, 'formHeightCounter', 'formHeightIntervalHandle')", 50);
		
		if (IS_IE_7) {
			$('bodyElement').up().setStyle({overflow : 'auto'});
		}
	
	}
}


function setDivOpacity(divId, opacity)
{
	if(IS_IE_5) document.getElementById(divId).filters.alpha.opacity = opacity;
	if(IS_NS_6) document.getElementById(divId).style.MozOpacity = opacity/100;
}


function setDivHeight(divId, height)
{
	document.getElementById(divId).style.height = height;
}


function fadeInDiv(isFadeIn, divId, opacitySteps, opacityThreshold, opacityCounterVarName, fadeIntervalHandleVarName)
{
	if (isFadeIn) {
		
		document.getElementById(divId).className = 'class_visible';
		
		if(eval(opacityCounterVarName) < opacityThreshold){
			eval(opacityCounterVarName + '+=' + opacitySteps);
			setDivOpacity(divId, eval(opacityCounterVarName));
		}
		// RESET OPAC VAR FOR NEXT USE.
		else {
			clearInterval(eval(fadeIntervalHandleVarName));
		}
	}
	else {
		if(eval(opacityCounterVarName) > opacityThreshold){
			eval(opacityCounterVarName + '-=' + opacitySteps);
			setDivOpacity(divId, eval(opacityCounterVarName));
		}
		// RESET OPAC VAR FOR NEXT USE.
		else {
			document.getElementById(divId).className = 'class_hidden';
			clearInterval(eval(fadeIntervalHandleVarName));
		}
	}
}


function rollDiv(divId, endHeight, step, divHeightCounterVarName, divHeightIntervalHandleVarName)
{
	eval(divHeightCounterVarName + '+=' + step);

	if ( (step > 0 && eval(divHeightCounterVarName) > endHeight) || (step < 0 && eval(divHeightCounterVarName) < endHeight)) {
		clearInterval(eval(divHeightIntervalHandleVarName));
		return;
	}
	
	setDivHeight(divId, eval(divHeightCounterVarName)+'em');
}


function hideDropDownLists(bool)
{
	if (IS_IE) {
		try {
			if (bool) {
//				$('rechercheDeBiensForm_champ_typeDeBien').hide();
//				$('biens_resultats_liste_tri').hide();
			}
			else {
//				$('rechercheDeBiensForm_champ_typeDeBien').show();
//				$('biens_resultats_liste_tri').show();
			}
		}
		catch (ex) {}
		
	}
}

function getUrlParameter(paramName)
{
    paramsString = self.location.search;
    pos = paramsString.indexOf(paramName);
    if (pos == -1)
        return null;

    // REMOVE THE PIECE BEFORE THE PARAM
    paramsString = paramsString.slice(pos);

    // REMOVE THE PIECE AFTER THE PARAM VALUE
    pos = paramsString.indexOf('&');
    if (pos != -1)
        paramsString = paramsString.slice(0, pos);

    // EXTRACT THE PARAM VALUE
    pos = paramsString.indexOf('=');
    paramsString = paramsString.slice(pos+1);

    // RETURN THE FINAL VALUE
    return paramsString;
}

function mainPageOnLoadHandler()
{
	// HANDLES 
	if (getUrlParameter('msgid') == 'MessageEnvoye') {
		alert("Votre message a bien été envoyé.\n\nMerci.");
		location.href = "?msgid=";
	}


	try {
		onLoadHandler();
	}
	catch (ex) {
	}
}


function demandeDeQuestionForm_checkFields()
{
	if ($('demandeDeQuestionForm_champ_antispam').value != "roche") {
		alert("Vous n'avez pas renseigné le champ anti-spam correctement.");
		return false;
	}

	return true;
}
