/**
* Fonction anuuler le blanc ? gauche et ? droite
*/
function trim(string){
	  return string.replace(/(^\s*)|(\s*$)/g,'');
}

/**
* Ouverture fenetre popup
*/
function ouvrirPopup(action) {
    var win = window.open(action,'LirePdf','left=10,height=500,width=1000,menubar=yes,toolbar=no,directories=no,status=no,scrollbars=yes,resizable=no');
    win.focus() ;
}

/**
* Mot de passe oubli?
*/

function motPasseOublie_2(action){
    var form = document.forms["form_login2"] ;
	var login = trim(form.login.value) ;
	var password = trim(form.password.value) ;
	bok = true ;
	if(login==""){
		document.getElementById("hrefclose").href="javascript:close_login_2();" ;
		document.getElementById('msgDetailsError').innerHTML ="Veuillez renseigner votre identifiant" ;
		bok = false ;
		$.blockUI({ message: $('#popupError'), css: { width: 'auto' } });
	}
	if(bok){
		form.action= action ;
		form.submit() ;
	}
}

function motPasseOublie(action){
    var form = document.forms["form_login"] ;
	var login = trim(form.login.value) ;
	var password = trim(form.password.value) ;
	bok = true ;
	if(login==""){
		hrefclose = document.getElementById("hrefclose");
		if(!hrefclose){
			hrefclose = document.getElementById("close1");
		}
		hrefclose.href="javascript:close_login();" ;
		document.getElementById('msgDetailsError').innerHTML ="Veuillez renseigner votre identifiant" ;
		bok = false ;
		$.blockUI({ message: $('#popupError'), css: { width: 'auto' } });
	}
	if(bok){
		form.action= action ;
		form.submit() ;
	}
}

function close_login(){
	var form = document.forms["form_login"] ;
	closeDialog();
	form.login.focus();
}

function close_password(){
	var form = document.forms["form_login"] ;
	closeDialog();
	form.password.focus();
}

function close_login_2(){
	var form = document.forms["form_login2"] ;
	closeDialog();
	form.login.focus();
}

function close_password_2(){
	var form = document.forms["form_login2"] ;
	closeDialog();
	form.password.focus();
}


function dologinSend(form){
	var login = trim(form.login.value) ;
	var password = trim(form.password.value) ;
	bok = true ;
	if(login==""){
		document.getElementById("hrefclose").href="javascript:close_login();" ;
		document.getElementById('msgDetailsError').innerHTML ="Veuillez renseigner votre identifiant" ;
		bok = false ;
		$.blockUI({ message: $('#popupError'), css: { width: 'auto' } });
	}
	if(password=="" && bok){
		document.getElementById("hrefclose").href="javascript:close_password();" ;
		document.getElementById('msgDetailsError').innerHTML ="Veuillez renseigner votre mot de passe" ;
		bok = false ;
		$.blockUI({ message: $('#popupError'), css: { width: 'auto' } });
	}
	return bok;
}

function dologin(){
	var form = document.forms["form_login"] ;
	return dologinSend(form);
}

function dologin2(){
	var form = document.forms["form_login2"] ;
	return dologinSend(form);
}
/**
* Fermeture popup
*/
function closeDialog(){
	$.unblockUI(); 
}

/* inactiver les liens actifs */ 

function parseAndApplyLink ( hashMapTag ) {
	for ( var i = 0; i < hashMapTag.length; i++){   // parse la collection de tags passee en arg.
		     // recupere pour chaque tag le className 
		  	if( hashMapTag[i] != null ) { 
		     		hashMapTag[i].href = 'javascript:void(0)';	      	
		     		hashMapTag[i].style.cursor='default';
		     		hashMapTag[i].onmouseover = function() { this.style.background = '#ffffff';this.style.textDecoration='underline';}; 
		     		hashMapTag[i].onmouseout = function() { this.style.background = '#ffffff';};
		    } 
  	}

}


function parseAndApplySelect ( hashMapTag ) {
	for ( var i = 0; i < hashMapTag.length; i++){   // parse la collection de tags passee en arg.
		     // recupere pour chaque tag le className 
		  	if( hashMapTag[i] != null ) { 
		     		hashMapTag[i].onchange = 'javascript:void(0)';   	
		    } 
  	}

}

function inactiveLink(targetDocument){		
		
	hmTags = targetDocument.getElementsByTagName("a");
 	if (hmTags != null && hmTags.length > 0 ){
 		parseAndApplyLink (hmTags);
 	}
 	
	hmTags = targetDocument.getElementsByTagName("select");
 	if (hmTags != null && hmTags.length > 0 ){
 		parseAndApplySelect (hmTags);
 	}
}
/**
V�rification d'une date au format JJ/MM/AAAA si valide
*/
function checkIfDate(strValue) {
	try{
		strValue = strValue.split("/")[1]+"/"+strValue.split("/")[0]+"/"+strValue.split("/")[2];
		var objRegExp = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
		if(strValue.match(objRegExp)){
			return true;
		}
	}
	catch(ex){}
	return false;    
}
/**
Redirection de page vers une page pr�c�dente tout en veroullant la fonction du bouton "pr�cedente" du navigateur
*/
function redirectTo(base) {
	var comeFrom = document.referrer;
	if(trim(comeFrom) != "") {
		document.location.href = comeFrom;
	}
	else {
		document.location.href = base;
	}
}
function redirectTo_2(base) {
	document.location.href = base;
}