/*
 * Author: Charles Lauzon
 * Name:   Functions.js
 * Date:   04 Aout, 2009
 */
 
/********************************************************************
 * 																	*
 *	                FUNCTION POUR PLUSIEURS PAGES                   *
 *																	*
 ********************************************************************/
//assignBlink will transform lblError (System Error) in blinking red
function assignBlink(el){
	el.runtimeStyle.visibility = "visible";
	setInterval(function(){
		el.runtimeStyle.visibility = (el.currentStyle.visibility == "visible") ? "hidden": "visible";
	}, 500);
}
//CheckNumberOnly will check if we press a number button
function txtCheckNumberOnly(e){
	var kc; 						//Key Code
	var key;						//Key Press
	var strCheck = '0123456789'; 	//String de Verification
	//Prendre le keyCode de la key appuyer
	if(e.keyCode){ kc = e.keyCode; }
	else if(e.which){ kc = e.which; }
	//Get String Code from the keyCode
	key = String.fromCharCode(kc);
	//Check si on Efface ou Tab ou Del ou Gauche ou Droite
	if(kc == 8 || kc == 9 || kc == 46 || kc == 37 || kc == 39){
		return true;
	}else{ //Check If a Valid Key
		if(strCheck.indexOf(key) == -1){ return false; }
		else{ return true; }
	}
}
//CheckNumberOnly will check if we press a number button or . (dot)
function txtCheckNumberOnlyWithDecimal(e){
	var kc; 					 	//Key Code
	var key;					 	//Key Press
	var strCheck = '0123456789.'; 	//String de Verification
	//Prendre le keyCode de la key appuyer
	if(e.keyCode){ kc = e.keyCode; }
	else if(e.which){ kc = e.which; }
	//Get String Code from the keyCode
	key = String.fromCharCode(kc);
	//Check si on Efface ou Tab ou Del ou Gauche ou Droite
	if(kc == 8 || kc == 9 || kc == 46 || kc == 37 || kc == 39){
		return true;
	}else{ //Check If a Valid Key
		if(strCheck.indexOf(key) == -1){ return false; }
		else{ return true; }
	}
}
//AutoConvertMoney onBlur will put space each 3 digits
function txtAutoConvertMoney_onBlur(obj){
	var Prix = obj.value;
	var Nombres = new Array();
	var x = 0;
	//Remplacer les Espaces par Rien
	for(i=0; i < Prix.length; i++){
		if(Prix.charAt(i) == " "){	
			Prix = Prix.replace(" ", ""); 
		}
	}
	//Separe chaque chiffre
	for(i=0; i < Prix.length; i++){
		Nombres[i] = Prix.charAt(i);
	}
	//Mettre a 0 le Prix
	Prix = "";
	//Reconstruire le Prix avec des espaces
	for(i=Nombres.length - 1; i >= 0; i--){
		if(x % 3 == 0 && x != 0){
			Prix = " " + Prix;
		}
		Prix = Nombres[i] + Prix;
		x++;
	}
	obj.value = Prix;
}
//Trim will remove all Space in the string
function strTrim(str){
	var strTrim = "";
	for(i=0; i < str.length; i++){
		if(str.charAt(i) != " "){
			strTrim += str.charAt(i)
		}
	}
	return strTrim;
}
//Trim will remove all Space in the string
function trim(myString){
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'');
} 
//CheckLimit will check if we can put more caractere
function txtaCheckLimit(obj, Limit){
	if(obj.value.length > Limit){
		return false;
	}
}
//CheckLimit onBlur will check if we have the right number of caractere
function txtaCheckLimit_onBlur(obj, Limit){
	if(obj.value.length > Limit){
		obj.value = obj.value.substr(0, Limit);	
	}
}
//ClearAll onFocus will clear all the text
function txtClearAll_onFocus(obj, isDefault){
	if(obj.value == isDefault){
		obj.value = "";	
	}
}
//Check each word length not over 60 characteres
function check_length_each_word(value){
	var arrWords = new Array();
	arrWords = value.split(" ");
	for(var i = 0; i < arrWords.length; i++){
		if(arrWords[i].length > 60){
			return false;
		}
	}
	return true;
}
//Invalid Data Send Back form MySql
function invalid_data(Erreurs){
	var arrErreurs;
	arrErreurs = Erreurs.split(",");
	//Put in Red Invalid Data
	for(var i = 0; i < arrErreurs.length; i++){
		document.getElementById("lbl"+arrErreurs[i]).style.color = "#FF0000";
	}
}
