function reloadCartTab(text, idDiv)
{
	var spanTab = dojo13.query('span.tabLabel:(span:last-of-type))',dojo13.byId(idDiv).parentNode.parentNode);
	var elt = spanTab[spanTab.length-1];
	
	elt.innerHTML = text;
}


function recursiveHunt(lookfor, model, buildme, item)
{
	var id = model.getIdentity(item);
	buildme.push(id);
	if(id == lookfor)
	{
		//console.log("++ FOUND item ", item, " buildme now = ", buildme);
		selectedItem = item;
		
		result = new Array();
		result['item'] = item;
		result['path'] = buildme;
		return result;
	}
		
	for(var idx in item.children)
	{
		if(!isNaN(idx))
		{
			// start a new branch of buildme, starting with what we have so far
			var buildmebranch = buildme.slice(0);
			//console.log("Branching into ", model.store.getValue(item.children[idx], 'name'), ", buildmebranch=", buildmebranch);
			var r = recursiveHunt(lookfor, model, buildmebranch, item.children[idx]);
			if(r){
				return r;
			}
		}
	}
	// Return undefined, indicating no match was found
	return undefined;
}

function selectTreeNodeById(tree, lookfor)
{
	var buildme = new Array();
    var result = recursiveHunt(lookfor, tree.model, buildme, tree.model.root);
    //console.log("*** FINISHED: result ", result, " buildme ", buildme);
    //console.dir(result);
	
	var path = result['path'];
	
    if(path && path.length > 0)
	{
		tree.attr('path', path);
		return result['item'];
	}
	return undefined;
}


//function to return CSS class name to display icon
function getIconTreeEsiaListe(/*dojo.data.Item*/ item, /*Boolean*/ opened)
{		
	var css='';
    if(!item || item.root || this.mayHaveChildren(item))
	{
		//css = (opened) ? "dijitFolderOpened" : "dijitFolderClosed";	
		css="dijitIconListe";
	}
	else
	{
		 css="dijitLeaf";
		 
		 if(dojo13.indexOf(item.type, 'organization') >=0)
		 {
		 	css="dijitIconOrganization";
		 }
		 
		 if(dojo13.indexOf(item.type, 'user') >=0)
		 {
		 	css="dijitIconUser";
		 }
		 
		  if(dojo13.indexOf(item.type, 'contact') >=0)
		 {
		 	css="dijitIconContact";
		 }
		 
		 if(dojo13.indexOf(item.type, 'office') >=0)
		 {
		 	if(item.main==1) css="dijitIconMainOffice";
		 	else css="dijitIconOffice";
		 }	
		 
		 if(dojo13.indexOf(item.type, 'liste') >=0)
		 {
		 	css="dijitIconListe";
		 }			 			 
	}		
	return css;		
}


function supernoisy()
{
	var pwCharSet = new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","m","n","p","q","r","s","t","u","v","w","x","y","z");
	var checky = 8;
	var alphaPattern = /[0-9a-zA-Z]/
	var theStr = "";

	for(i=0;i < checky;i++){
		theChar = pwCharSet[(Math.floor(Math.random() * 100) % pwCharSet.length)];

		if(theChar.match(alphaPattern)){
			if((Math.floor(Math.random() * 10) % 2) == 0){
				theChar = theChar.toUpperCase();
			}
		}
		theStr += theChar;
	}

	return theStr;
}

function getPassword(idForm)
{
	var str = supernoisy();
	document.forms[idForm].elements["user_password"].value=str;
	document.forms[idForm].elements["user_password2"].value=str;
	document.forms[idForm].elements["user_password3"].value=str;
}

function getLogin(idForm)
{
	var str = supernoisy();
	var lname=document.forms[idForm].elements["user_lastname"].value;
	var lfirstname=document.forms[idForm].elements["user_firstname"].value;		
	var strreturn='';
		
	if(lname.length>3 && lfirstname.length>=1){
		strreturn=lfirstname.substr(0, 1)+lname.substr(0, 5);
	}else{
		strreturn=supernoisy();
	}
		
	document.forms[idForm].elements["user_login"].value=strreturn.toLowerCase();	
}


function validFormPassword(idForm)
{
	if (document.forms[idForm].elements["user_password"].value != document.forms[idForm].elements["user_password2"].value) {
		alert("Les 2 mots de passe ne sont pas identiques !");
		document.forms[idForm].elements["user_password"].focus();
		throw new Error('');
	}
}


function display(htmlNode,val){
	if(val) htmlNode.style.display='';
	else htmlNode.style.display='none';
}


function switchDisplay(eltId, val)
{	
	display(document.getElementById(eltId), val);		
}



function verifForm_mail(champ_mail,mess){

    champ_mail = this.form.elements[champ_mail];
    if(champ_mail){
        valeur = this.trim(champ_mail.value);
        champ_mail.value = valeur;

        if(champ_mail.value.length!=0){

            var e = champ_mail.value;

            if (document.images){
                //re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
                re_two = /^[a-zA-Z0-9_\-\.]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;

                if (!e.match(re_two))
                    this.addError(champ_mail,"Le format de de l'adresse de courriel n'est pas valide !");
            }
        }
    }
}
function verifForm_displayError(showAll){
		
		if(showAll==null) showAll=true;
						
		for(var i=0; i<this.array_err.length; i++){
			
			//nouveau noeud div
			var nouveauB = document.createElement("div");		
			
			//noeud text du div
			var texte_nouveauB = document.createTextNode(this.array_err[i]);
			nouveauB.appendChild(texte_nouveauB);
	
			//nouveau noeud attribut NAME du div
			nouveauB.setAttribute('name', 'div_'+this.array_el[i].name);

 			//style nouveau div
			nouveauB.className = nouveauB.className+" requiredError";

 			/*nouveauB.style.padding=this.errorStylePadding;*/
			
			this.array_el[0].focus();
					
 			//insertion du noeud ds le document
 			var parent_node=this.array_el[i].parentNode;
 			parent_node.insertBefore(nouveauB,this.array_el[i]);
 			
			document.documentElement.scrollTop=document.documentElement.scrollTop-60;
 			if(!showAll) return false;
		}		
	}
	
	
function initSelectFilter(idDijit, value, param)
{
	dj=dijit13.byId(idDijit); 
	
	if(value!= "")
	{
		dj.attr('disabled',false);
		dj.query[param] = value;
	}
	else
	{
		dj.attr('disabled',true);
		dj.query[param] = null;
	}
	
	dj.reset();
}


/*
 * disabledDijit(nodeName)
 * nodeName = Dom element
 * fonction permettant d'activer ou de désactiver les composants Dijit pour la validation des formulaires
 */
function disabledDijit(nodeName, selector)
{
	if(selector == undefined) selector = '.';

	dojo13.query(selector+nodeName).forEach(function(n, index, arr){
		dojo13.query('input', n).forEach(function(node, index, arr){
			var w = dijit13.byId(node.id);
			if(w)
			{
				if(n.style.display == 'none')
					w.attr('disabled',true);
				else
					w.attr('disabled',false);
			}
		});
	});
}



function openCWindowMod(mod, strparam)
{
	if(mod == 'bexternes')
	{
		var url = 'http://www.emploi-formation.net/';
		window.open(url);
	}
	else
	{
		var url_='?module='+mod+'&action=Index';
		if(strparam) url_+="&"+strparam;
		var obj_=document.getElementById("menuButton_"+mod);
		var cwindow_=WindowSystem.getWindowByModuleName(mod);
		openCwindow(cwindow_, url_, obj_);		
	} 
}
