function setTitle(title) {
	document.title = title;
}

function selectFirstOption(ddl) {
	if(ddl.options.length > 0) {
		ddl.options[0].selected = true;
	}
	
	if(ddl.options.length > 1) {
		for(var i=1;i<ddl.options.length;i++){
			ddl.options[i].selected = true;
		}
	}
}

function popup(url, width, height) {
	if (url != "") {
		var top=(screen.height-height)/2;
		var left=(screen.width-width)/2;
		return (window.open(url,'_blank','top=' + top + ',left=' + left + ',scrollbars=yes,statusbar=no,resizable=yes,location=no,directories=no,menubar=no,toolbar=no,width=' + width + ',height=' + height));
	}
}

function demoPopup(url, width, height) {
	if (url != "") {
		var top=(screen.height-height)/2;
		var left=(screen.width-width)/2;
		window.open(url,'_blank','top=' + top + ',left=' + left + ',scrollbars=no,statusbar=no,resizable=no,location=no,directories=no,menubar=no,toolbar=no,width=' + width + ',height=' + height);
	}
}

function IsValidEMail(strEmail) {
	var regEmail = new RegExp("^[A-Za-z0-9\\._%-]+@[A-Za-z0-9\\._%-]+\\.[A-Za-z]{2,4}$");
	return regEmail.test(strEmail);
}

function EnsureMaxDecimal(strNum, maxDec) {
	var regMaxDec = new RegExp("^[0-9\\s]+[,]?[0-9]{0," + maxDec + "}$");
	return regMaxDec.test(strNum);
}

function addSpacesNumber(str) {
	var newStr = '';
	var compteur = 3;
	var tabStr = str.split('');
	if(str.indexOf(',') != -1) {
		return str;
	} else {
		var i;
		for(i=(str.length - 1); i >= 0; --i) {
			if(tabStr[i] != ' ') {
				newStr = tabStr[i] + newStr;
				--compteur;
					
				if(compteur == 0) {
					newStr = ' ' + newStr;
					compteur = 3;
				}
			}
		}
		return newStr;
	}
}

function convertDotToComa(str) {
	var newStr = '';
	var tabStr = str.split('');
	var i;
	for(i=0; i < str.length; ++i) {
		if(tabStr[i] != '.') {
			newStr = newStr + tabStr[i];
		} else {
			newStr = newStr + ',';
		}
	}
	return newStr;
}

function checkAjax() {
	if(XMLHttpRequest == null) {
		return false;
	} else {
		return true;
	}
}

function ajaxUpdate(htmlElementUpdateId, ajaxResponse) {
	if(ajaxResponse.value == "<EXCEPTION>") {
		//Une exception a eu lieu sur le serveur - tenter le postback
		return true;
	}
	
	var strFunctionWriteToAjaxPanel = 'writeTo_' + htmlElementUpdateId + '(ajaxResponse.value)';
	eval(strFunctionWriteToAjaxPanel);
	
	return false;
}

//Valide une date dd/mm/yyyy
function isDateOk(strDate) {
	var reg = new RegExp("^(0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/]((?:19|20)[0-9][0-9])$");
	if(reg.test(strDate)) {
		var arrayMatch = reg.exec(strDate);
		var day = parseInt(arrayMatch[1]);
		var month = parseInt(arrayMatch[2]);
		var year = parseInt(arrayMatch[3]);
		
		//31 jours dans un mois de 30
		if((day == 31) && ((month == 4) || (month == 6) || (month == 9) || (month == 11))) {
			return false;
		}
		
		//30-31 jours au mois de Fevrier
		if((day >= 30) && (month == 2)) {
			return false;
		}
		
		//29 jours en février seulement les années bissextiles
		if((month == 2) && (day == 29) && !(((year % 4) == 0) && ((year % 100 != 0) || (year % 400 == 0)))) {
			return false;
		}
		
		return true;
	} else {
		return false;
	}
}

function convertToJsDate(strDate) {
	var reg = new RegExp("^(0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/]((?:19|20)[0-9][0-9])$");
	var arrayMatch = reg.exec(strDate);
	var dateRes = new Date(parseInt(arrayMatch[3]), parseInt(arrayMatch[2]) - 1, parseInt(arrayMatch[1]) - 1);
	return dateRes;
}

function convertDateToStr(objDate) {
	var strDate = '';
	
	if(objDate.getDate() < 10) {
		strDate = '0' + objDate.getDate();
	} else {
		strDate += objDate.getDate();
	}
	strDate += '/';
	
	var month = objDate.getMonth() + 1;
	if( month < 10) {
		strDate += '0' + month;
	} else {
		strDate += month;
	}
	
	strDate += '/' + objDate.getFullYear();
	
	return strDate;
}

function getObject(objectName) {
	if (navigator.appName.indexOf ("Microsoft") !=-1) {
		return window[objectName]
	} else {
		return document[objectName]
	}
}