var isIE=document.all?1:0;


function changeClassNameOnMouseOver(obj,className) {
	obj.previousClassName = obj.className;
	obj.className = className;

	return true;
}


function restoreClassNameOnMouseOut(obj) {
	try {
		obj.className = obj.previousClassName;
	}
	catch(e) {
	}

	return true;
}




function getObj(id) {
	// on cherche dans document.all

	if (isIE && eval("typeof(document.all[id])")!="undefined") {
		return document.all[id];
	}
	else
	{
		if (document.getElementById(id)!=null)
			return document.getElementById(id);
	}
	
	// sinon on cherche dans les formulaires
	for(var i=0; i<document.forms.length; i++) {
		if (eval("document.forms[i].id") == id)
			return document.forms[i];
	}

	// sinon on cherche dans les frames
	if (isIE) {
		for(var i=0; i<document.frames.length; i++) {
		if (eval("document.frames[i].id") == id)
			return document.frames[i];
		}
	}

	// sinon on cherche dans les images
	for(var i=0; i<document.images.length; i++) {
		if (eval("document.images[i].id") == id)
			return document.images[i];
	}

	// sinon on cherche dans les liens
	for(var i=0; i<document.anchors.length; i++) {
		if (eval("document.anchors[i].id") == id)
			return document.anchors[i];
	}

	// pas trouvé !!
	return null;
}

function ResizeScrollDivs()
{
	var h = document.body.clientHeight - document.body.topMargin - 0;
	if (!isNaN(document.body.bottomMargin))
		h = h - document.body.bottomMargin;
	h = h - getObj("tblContext").scrollHeight;
	if (h <= 0) h = 1;
	if (getObj("divContent") != null && typeof(getObj("divContent").style) != 'undefined')
	{
		getObj("divContent").style.height = h;
	}
	if (getObj("fileContent") != null && typeof(getObj("fileContent").style) != 'undefined')
	{
		getObj("fileContent").style.height = h;
	}

	ResizeDivContentScrollDivs(h);
}					

function ResizeDivContentScrollDivs(h)
{
	var divContent = getObj("divContent");
	var header = getObj("divContentHeader");
	var content = getObj("divContentContent");
	var footer = getObj("divContentFooter");
	
	if (content == null) return;

	if (header != null)
		h = h - header.scrollHeight;
		
	if (footer != null)
		h = h - footer.scrollHeight;

	// Empirique...
	h = h  - 20;
	if (h <= 0) h = 1;		
	content.style.height = h;
}


function SetFrameURL()
{
	if (typeof(document.all.divContent.frameSrc) != 'undefined')
	{
		document.all.divContent.src = document.all.divContent.frameSrc;
	}

	if (typeof(document.all.fileContent) != 'undefined' && typeof(document.all.fileContent.frameSrc) != 'undefined')
	{
		document.all.fileContent.src = document.all.fileContent.frameSrc;
	}
}

var divContentW, divContentH;
var divInited = false;

var ovx, ovy;
function SaveOverflow()
{
	if (typeof(divContent)=="undefined") return;
	ovx = divContent.style.overflowX;
	ovy = divContent.style.overflowY;
	divContent.style.overflowX = "hidden";
	divContent.style.overflowY = "hidden";
}

function LoadOverflow()
{
	if (typeof(divContent)=="undefined") return;
	divContent.style.overflowX = ovx;
	divContent.style.overflowY = ovy;
}

function getKeyCode(e)
{
	if (e && e.which) return e.which; // NS
	if (window.event && window.event.keyCode) return window.event.keyCode; // IE
	return null;
}


function pressOnEnter(e /*event*/, elem, btnId)
{
	if (getKeyCode(e) != 13) return true;
	
	//if (!document.all) {return false;} // NS: non supporte car elements avec Id non geres

	// Si btnId=null, alors on souhaite desactiver la touche ENTER
	if (btnId == null) return false;
	
	var i, col, f;
	
	if (elem == null)
	{
		if (getKeyCode(e) != 13) return;
		
		col = document.all;

		for (i = 0 ; i < col.length ; i++)
		{
			if (pressOnEnter(e, col.item(i), btnId)) return true;
		}
		
		return false;
	}
	else
	{
		if ((""+elem.id).indexOf(btnId) >= 0)
		{
			window.event.returnValue = false;
			elem.click();
			return true;
		}

		col = elem.children;
		
		for (i = 0 ; i < col.length ; i++)
		{
			if (pressOnEnter(e, col.item(i), btnId)) return true;
		}
		
		return false;
	}
}

function SetInitialFocus()
{
	try{
		FocusItem_SetInitialFocus();
	} catch(e) {}
}

function doRecursiveEndOfSession(loopCount)
{
	if (loopCount == null) loopCount=0;
	if (loopCount > 10) return;
	
	// La variable existe et vaut true pour la fenêtre parente.
	if (typeof(bIsTopWindow) == 'boolean' && bIsTopWindow)
	{
		doEndOfSession(loopCount+1);
	}
	else
	{
		window.close();
		window.opener.doRecursiveEndOfSession();
	}
}

function doEndOfSession()
{
	window.location.replace(window.location.href);
}

// Ne marche que si la fenetre modale a été appelée depuis la fenêtre principale.
function checkModalEndOfSession(retValue)
{
	if (typeof(retValue) == "string" && retValue == "EndOfSession") 
	{
		doEndOfSession();
		return true;
	}
	return false;
}


function mailTo(EMail,subject) {
var chaine_mail = "mailto:" + EMail + "?subject= " + subject;
location.target="_blanck";
location.href = chaine_mail;
}

//***********************************************
// Affiche la div contenant
// le carnet d'entretien du batiment selectionné
// [function]
// function displayDivCeBatiment()
//************************************************
function displayDivCeBatiment(_batId)
{
	var arr = _batId.split('#');

	// on passe en rouge le batiment en cours de visualisation
	var maCollec = window.document.getElementsByTagName("a");
	for (var i = 0; i <= maCollec.length - 1; i++)
	{
		var arrCollec = maCollec[i].id.split('#');
		if (arrCollec[0] == "hrefBatiment")
		{
			if (arrCollec[1] == arr[1])
			{
				if (maCollec[i].style.color == "red") maCollec[i].style.color = "";
				else maCollec[i].style.color = "red";
			}
			else maCollec[i].style.color = "";
		}
	}
		
	window.document.getElementById("ceCourant").innerHTML = window.document.getElementById(_batId).innerHTML;
}

function displayContent(_id)
{
	var newId = _id.replace("Titre","Content");
	var maCollec = window.document.getElementsByTagName("div");
	for (var i = 0; i <= maCollec.length - 1; i++)
	{
		var arr = maCollec[i].id.split('#');
		if (arr[0].indexOf("Content") > 0)
		{
			if (newId == maCollec[i].id)
			{
				if (maCollec[i].style.display == "inline")
					maCollec[i].style.display = "none";
				else maCollec[i].style.display = "inline";
			}
			else maCollec[i].style.display = "none";
		}
	}
}

function displayDetailContratAssurance(_id)
{
	var maCollec = window.document.getElementsByTagName("div");
	for (var i = 0; i <= maCollec.length - 1; i++)
	{
		var arr = maCollec[i].id.split('#');
		if (arr[0] == "garantie" || arr[0] == "sinistre")
		{
			if (_id == maCollec[i].id)
			{
				if (maCollec[i].style.display == "inline")
					maCollec[i].style.display = "none";
				else maCollec[i].style.display = "inline";
			}
			else maCollec[i].style.display = "none";
		}
	}
}

function centerLayer(obj)
{
	centerLayerInObject(obj,window);
}

function centerLayerInObject(_msg,_obj)
{
	if (typeof(_msg)=="undefined" || _msg==null)
		return;

	_msg.style.visibility = "hidden";
    	_msg.style.display = "block";
	var x = Math.round((_obj.clientWidth - _msg.offsetWidth) / 2 + _obj.scrollLeft);
	var y = Math.round((_obj.clientHeight - _msg.offsetHeight) / 2 + _obj.scrollTop);

	_msg.style.posLeft = x;
	_msg.style.posTop = y;
 
    _msg.style.visibility = "visible";
    _msg.style.display = "none";
}
