// Copyright LQC 2005
// Auteur: Laurent Quivogne
var session_timeout = 120;

function sessionAlert( no ){
	switch( no ){
	case 1:
		var nowDate = new Date();
		alert( msg__navigation_sessionalert1 );
		var delay = (new Date() - nowDate);
		if( delay < 2 * 60000 ){
			window.setTimeout( "sessionAlert( 2 )", delay );
		}
		break;
	case 2:
		alert( msg__navigation_sessionalert2 );
		break;
	}
}
function initSessionAlert(){
	window.setTimeout( "sessionAlert( 1 )", (session_timeout - 3) * 60000 );
}

function storeScrollValues(){
	var scrollX, scrollY;

	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrollX = window.pageXOffset;
		scrollY = window.pageYOffset;
	} else if( document.body
		&& ( document.body.scrollLeft
			|| document.body.scrollTop ) ) {
		//DOM compliant
		scrollX = document.body.scrollLeft;
		scrollY = document.body.scrollTop;
	} else if( document.documentElement 
		&& ( document.documentElement.scrollLeft 
			|| document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrollX = document.documentElement.scrollLeft;
		scrollY = document.documentElement.scrollTop;
	} else {
		scrollX = 0;
		scrollY = 0;
	}
	setCookie( "ScrollPage", document.location.pathname );
	setCookie( "scrollX", scrollX );
	setCookie( "scrollY", scrollY );
}

function resetScrollValues(){
	setCookie( "ScrollPage", '' );
}

function restoreScrollValues(){
	if( document.location.pathname == readCookie( "ScrollPage" ) ){
		window.scrollTo( 
			parseInt( readCookie( "scrollX" ), 10 ),
			parseInt( readCookie( "scrollY" ), 10 ) );
		setCookie( "ScrollPage", "" );
	}
}

function selectHierarchyWindow( fieldId, itemId, list, tableList ){
	var win;
	var W = 400;
	var H = 400;
	var X = ((screen.availWidth-W)/2);
	var Y= ((screen.availHeight-H)/2);
	win = window.open( 'selectHierarchyWindow.php?FIELDID=' + fieldId +
		"&ITEMID=" + itemId +
		"&LIST=" + list +
		"&TABLE=" + tableList,
		'selectHierarchyWindow', 
		'width=' + W + ',height=' + H + ',scrollbars=yes,status=yes,resizable=yes' );
	win.moveTo(X,Y);
	win.focus();
}

function selectHierarchyWindowWithRoot( fieldId, list, tableList, rootId, otherParam ){
	var win;
	var W = 400;
	var H = 400;
	var itemId = '';
	if ( document.getElementById(fieldId).value ) {
		itemId = document.getElementById(fieldId).value;
	}
	var X = ((screen.availWidth-W)/2);
	var Y= ((screen.availHeight-H)/2);
	win = window.open( 'selectHierarchyWindow.php?FIELDID=' + fieldId +
	"&ITEMID=" + itemId +
	"&ROOTID=" + rootId +
	"&LIST=" + list +
	"&TABLE=" + tableList +
	"&"+otherParam,
	'selectHierarchyWindowWithRoot', 
	'width=' + W + ',height=' + H + ',scrollbars=yes,status=yes,resizable=yes' );
	win.moveTo(X,Y);
	win.focus();
}


function resetSelectField( fieldId ){
	document.getElementById( fieldId ).value = "";
	document.getElementById( "selectLabel_" + fieldId ).innerHTML = "";
}

function setSelectField( fieldId, itemId, value ){
	window.opener.document.getElementById( fieldId ).value = itemId;
	window.opener.document.getElementById( "selectLabel_" + fieldId ).innerHTML = value;
}

// fonction qui permet de mettre à jour la variable document.domain, afin que des pages
// de sites différents puissent communiquer
// Dans cette version, la fonction, pour un nom de domaine réel, www.lqconseil.com:34,
// execute: document.domain = lqconseil.com
function setJavascriptDocumentDomain(){
	var str = window.location.hostname;
	var res = str.match( /[^.]+[.][^.]+$/ );
	if( res != null ){
		document.domain = res;
	}
}
