// JavaScript Document

function openQuebec511(x, y, lang, zoom){
	/************************************************************************
	* Changement le 2012-01-07 par Fred Laplante
	* Le site de Québec 511 utilise dorénavant les maps à partir de GoogleMaps, 
	* donc l'url a changer pour accéder à la carte.
	*************************************************************************/
	//var url = "http://www.etat-reseau.mtq.gouv.qc.ca/Default.aspx?coordX="+x+"&coordY="+y+"&lang="+lang+"&zoom="+zoom;
	var url = "http://carte.quebec511.gouv.qc.ca/fr/Default.aspx?idreg=3";
	var newwin = window.open(url,'newwin','toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=no,copyhistory=no,scrollbars=no,width=955,height=600,top='+findTopPosition(675)+',left='+findLeftPosition(1000));
	newwin.focus();
	return;
}
function openNewsForPrint(idNews){
	var url = "/printNews.php?idNews=" + idNews;
	var newwin = window.open(url,'PrintNews','toolbar=no,location=no,directories=no,status=no,menubar=yes,resizable=no,copyhistory=no,scrollbars=no,width=500,height=400,top='+findTopPosition(675)+',left='+findLeftPosition(1000));
	newwin.focus();
	return;
}
function openMsgCommForPrint(idMsg){
	var url = "/printMsgComm.php?idMsg=" + idMsg;
	var newwin = window.open(url,'PrintMsgComm','toolbar=no,location=no,directories=no,status=no,menubar=yes,resizable=no,copyhistory=no,scrollbars=no,width=500,height=400,top='+findTopPosition(675)+',left='+findLeftPosition(1000));
	newwin.focus();
	return;
}
function findTopPosition(windowHeight){return (window.screen.height/2 - windowHeight/2);}

function findLeftPosition(windowWidth){return (window.screen.width/2 - windowWidth/2);}


function pageChange(page, param) {
	var page = (page == null) ? "" : page;
	var param = (param == null) ? "" : "?"+param;
	switch(page.toUpperCase()){
		case 'HOME' : 
      document.location.href = '/index.php'+ param;
      break;
		default :
			gotoPage(page, param);
			break;
	}
}
function gotoPage(page, param){
	document.location.href = page + param;
}

function show(objId){
	$(objId).style.display = '';
}
function hide(objId){
	$(objId).style.display = 'none';
}
function showObj(obj){
	obj.style.display = '';
}
function hideObj(obj){
	obj.style.display = 'none';
}
function lockInput(objId){
	$(objId).readOnly = true;
	$(objId).className = 'readonly';	
}
function unlockInput(objId){
	$(objId).readOnly = false;
	$(objId).className = ''; //S'arranger pour remettre la valeur initial pour la class
}


/***********************************************************************
* keyEnter : Pour les champs qui accepte tout les caractères
*            ENTER = tabulation (change de case à l'index suivant)
* @param : index de l'élément
***********************************************************************/
function keyEnterID(id) {
	var key = window.event.keyCode;
	if (key == 13 && $(id)){
		$(id).select();
		window.event.keyCode = 0;
	}
}

/*************************************************************************
* keyUPPER : Pour les champs qui accepte tout les caractères en UPPERCASE
*            ENTER = tabulation (change de case à l'index suivant)
* @param : index de l'élément
*************************************************************************/
function keyUPPER(index) {
	var key = window.event.keyCode;
	if (key == 13 && document.forms[0].elements(index+1)){
		document.forms[0].elements(index+1).focus()
		window.event.keyCode = 0;
	}
	else if (key >= 97 && key <= 122){
		window.event.keyCode = key - 32;
	}else{
		window.event.keyCode = key;
	}
}

/***********************************************************************
* keyNum : pour les champs numérique à virgule. ex: montant "100.99"
*          Accepte seulement les chiffres et le point.
*          Virgule = Point    (chr(44) = chr(46))
*          ENTER = tabulation (change de case à l'index suivant)
* @param : index de l'élément
***********************************************************************/
function keyNum(index) {
	var key = window.event.keyCode;
	if (key == 13 && document.forms[0].elements(index+1)){
		document.forms[0].elements(index+1).focus();
		window.event.keyCode = 0;
	}
		else if (key == 45){ 						// "-" = "-" pour les négatifs
		window.event.keyCode = 45;
	}
	else if (key < 48 || key > 57){		//Pas chiffre de 0 à 9 = Null
		window.event.keyCode = 0;
	}		
}

/***********************************************************************
* keyNumID : pour les champs numérique à virgule. ex: montant "100.99"
*            Accepte seulement les chiffres et le point.
*            Virgule = Point    (chr(44) = chr(46))
*            ENTER = tabulation (change de case à l'index suivant)
* @param : index de l'élément
***********************************************************************/
function keyNumID(id)	{
	var key = window.event.keyCode;
	if (key == 13 && $(id)){
		$(id).select();
		window.event.keyCode = 0;
	}
	else if (key == 45){ 						// "-" = "-" pour les négatifs
		window.event.keyCode = 45;
	}
	else if (key < 48 || key > 57){		//Pas chiffre de 0 à 9 = Null
		window.event.keyCode = 0;
	}		
}

/***********************************************************************
* denyKey : Pour les champs qui n'accepte aucun caractère
*           ENTER = tabulation (change de case à l'index suivant)
* @param : index de l'élément
***********************************************************************/
function denyKey(index) {
		key = window.event.keyCode;
		if (key == 13 && document.forms[0].elements(index+1)){
			document.forms[0].elements(index+1).focus()
		}
		window.event.keyCode = 0;
	}
	
/***********************************************************************
* denyLetters : Pour les champs qui accepte seulement des chiffres
*               ENTER = tabulation (change de case à l'index suivant)
* @param : index de l'élément
***********************************************************************/
function denyLetters(index) {
	key = window.event.keyCode;
	if (key == 13 && document.forms[0].elements(index+1)){
		document.forms[0].elements(index+1).focus()
		window.event.keyCode = 0;
	}
	else if (key < 48 || key > 57){
		window.event.keyCode = 0;
	}
}

/***********************************************************************
* limitNbChar : Limite le nombre de caractères entrés dans un champs Text
*               et affiche le nombre de caractères restants.
* @param : obj - l'objet à contrôler
* @param : maxChar - le nombre maximal de caractères
* @param : displayID - l'ID de l'objet qui va contenir l'affichage
***********************************************************************/
function limitNbChar(obj, maxChar, displayID){
	if(obj.value.length >= maxChar){
		event.keyCode = 0;
	}else{
		$(displayID).innerHTML = (maxChar - obj.value.length-1);
	}
}

/***********************************************************************
* highlightElement : Met en évidence l'élément en paramètre et défini une
*							méthode onblur pour qu'il reprenne sa classe d'origine lors
*             de la perte du focus. La méthode onblur s'annule elle même
*							lors de son exécution.
* Auteur : Frédéric Laplante
* Date : 30 avril 2007
* @param : elem - l'élément à mettre en évidence
***********************************************************************/
function highlightElement(elem){
	//On vérifie si une fonction blur existe déjà pour l'élément
//	if(elem.onblur != null){
//		origBlur = elem.onblur;
//		//origBlur = origBlur.replace("anonymous","");
//	}
	//Définir dans le CSS principal une classe .focus pour les éléments à mettre en évidence
	var origClass = elem.className;
	elem.onblur = function() {
		//alert("className : "+ this.className +"\norigClass : "+ origClass);
		if(this.value != ''){
			this.className = origClass;
			this.onblur = null;
		}
	}
	elem.className += " focus";
	elem.select();	
	elem.focus();	
}

function formatDuree(HH, MM, SS){
	if(isNaN(HH)) HH = 0;
	if(isNaN(MM)) MM = 0;
	if(isNaN(SS)) SS = 0;
	if(MM > 59){
		HH = HH + parseInt(MM / 60);
		MM = MM % 60;
	}
	if(SS > 59){
		MM = MM + parseInt(SS / 60);
		SS = SS % 60;
	}
	return new Array(HH,MM,SS);
}
