/*
 * Resource : /javascript/highlightnew.js
 */

function highlightWord(node,word, niv) {	   	
	// On itère sur les fils
	var hi_cn;
	if (node.hasChildNodes && niv < 16) {		
		if (node.nodeType == 3) {traiteNoeud(node, word);}		
		else
			{
				niv++;
				for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {			
					highlightWord(node.childNodes[hi_cn],word,niv);
				}
		}
	}
}

function replaceAll (chaine, rech, remp)
{ var st = chaine;
  var size = rech.length;
  if (size > 0)
  	{
	  var idx = st.indexOf(rech);
	  	while (idx >= 0)
		  {   st = st.substring(0,idx) + remp + st.substr(idx+size);
	     		idx = st.indexOf(rech);
	  	  }
   	}
  return st;
}

function traiteNoeud(node, word){
// on traite le noeud lui-meme
		
	tempNodeVal = noaccent(node.nodeValue.toLowerCase());
	tempWordVal = word;
	//word.toLowerCase();
	if (tempNodeVal.indexOf(tempWordVal) != -1 ) {		
		pn = node.parentNode;
		if (pn.className != "searchwords") {				
			nv = node.nodeValue;
			ni = tempNodeVal.indexOf(tempWordVal);
			
			before = document.createTextNode(nv.substr(0,ni));
			docWordVal = nv.substr(ni,word.length);
			after = document.createTextNode(nv.substr(ni+word.length));
			hiwordtext = document.createTextNode(docWordVal);				
			hiword = document.createElement("span");				
			hiword.className = "searchwords";				
			hiword.appendChild(hiwordtext);
			pn.insertBefore(before,node);
			pn.insertBefore(hiword,node);
			pn.insertBefore(after,node);
			pn.removeChild(node);
		}
	}	
}

function noaccent(chaine)
{
var temp="";
temp = chaine.replace(/[àâä]/gi,"a");
temp = temp.replace(/[éèêë]/gi,"e");
temp = temp.replace(/[îï]/gi,"i");
temp = temp.replace(/[ôö]/gi,"o");
temp = temp.replace(/[ùûü]/gi,"u");
return temp.toLowerCase();
}


function highlightSearchTerms() {
	if (!document.createElement) return;
	var w=0;
	var i=0;
	var j=0;		
	var ref = location.href;	
	var queryip;
	var words;
	var lesResultats;
	var niv=0;
	if (ref.indexOf('?') == -1) return;
	
	var query = ref.substr(ref.indexOf('?')+1);	
	var querya = query.split('&');
	
	for (i=0;i<querya.length;i++) {
		 queryip = querya[i].split('=');		
		
	       if (queryip.length >= 1) {
	       	
        	if (queryip[0] == 'keywords' || queryip[0] == 'position' || queryip[0] == 'company' || queryip[0] == 'lastname' || queryip[0] == 'location'  || queryip[0] == 'country' || queryip[0] == 'education'  ) {                										
        			
        			if (queryip[1].indexOf("+") != -1 ) {words = unescape(queryip[1]).split("+");}
        			else if (queryip[1].indexOf(" ") != -1 ) {words = unescape(queryip[1]).split(" ");}	
        			else if (queryip[1].indexOf("%20") != -1 ) {queryip[1] = replaceAll(queryip[1],"%20","+"); words = unescape(queryip[1]).split("+");}	
        			else {words = unescape(queryip[1]).split("+");}
					
	                for (w=0;w<words.length;w++) {	                	
	                	words[w] = (words[w].indexOf("*") != -1 ? words[w].substr(0, words[w].indexOf("*")) : words[w]);	                	
	                	words[w] = (words[w].indexOf(",") != -1 ? words[w].substr(0, words[w].indexOf(",")) : words[w]);	                	
	                	words[w] = (words[w].indexOf(".") != -1 ? words[w].substr(0, words[w].indexOf(".")) : words[w]);	                	
	                	words[w] = noaccent(words[w]);
	                	if (words[w].length > 2 && words[w] != 'des' && words[w] != 'les') { 	                																																		
							for (j=0; ((j < 20) && ((lesResultats = document.getElementById('result'+j)) != null)) ;j++){																								
	                					highlightWord(lesResultats,words[w],niv);	                					
							}		
						}						
					}
              }
           }
	  }
	
}


function highlightSearchTermsSearchBar() {
	if (!document.createElement) return;
	var w=0;
	var i=0;
	var j=0;		
	var ref = location.href;	
	var queryip;
	var words;
	var lesResultats;
	var niv=0;
	if (ref.indexOf('?') == -1) return;
	var query = ref.substr(ref.indexOf('?')+1);	
	var querya = query.split('&');
	for (i=0;i<querya.length;i++) {
		 queryip = querya[i].split('=');		
		
	       if (queryip.length >= 1) {
	       	
        	if (queryip[0] == 'queryString' || queryip[0] == 'town' || queryip[0] == 'fullName' || queryip[0] == 'keywords' || queryip[0] == 'position' || queryip[0] == 'company' || queryip[0] == 'lastname' || queryip[0] == 'location'  || queryip[0] == 'country' || queryip[0] == 'education') {                										
        			
        			if (queryip[1].indexOf("+") != -1 ) {words = unescape(queryip[1]).split("+");}
        			else if (queryip[1].indexOf(" ") != -1 ) {words = unescape(queryip[1]).split(" ");}	
        			else if (queryip[1].indexOf("%20") != -1 ) {queryip[1] = replaceAll(queryip[1],"%20","+"); words = unescape(queryip[1]).split("+");}	
        			else {words = unescape(queryip[1]).split("+");}
					
	                for (w=0;w<words.length;w++) {
	                	words[w] = (words[w].indexOf("*") != -1 ? words[w].substr(0, words[w].indexOf("*")) : words[w]);	                	
	                	words[w] = (words[w].indexOf(",") != -1 ? words[w].substr(0, words[w].indexOf(",")) : words[w]);	                	
	                	words[w] = (words[w].indexOf(".") != -1 ? words[w].substr(0, words[w].indexOf(".")) : words[w]);	                	
	                	words[w] = noaccent(words[w]);
	                	if (words[w].length > 2 && words[w] != 'des' && words[w] != 'les') { 
	                		for (j=0; ((j < 20) && ((lesResultats = document.getElementById('resultMember'+j)) != null)) ;j++){																								
	                			highlightWord(lesResultats,words[w],niv);	                					
							}               																																		
							for (j=0; ((j < 20) && ((lesResultats = document.getElementById('resultBlog'+j)) != null)) ;j++){																								
	                			highlightWord(lesResultats,words[w],niv);	                					
							}
							for (j=0; ((j < 20) && ((lesResultats = document.getElementById('resultBlogTitle'+j)) != null)) ;j++){																								
	                			highlightWord(lesResultats,words[w],niv);	                					
							}
							for (j=0; ((j < 20) && ((lesResultats = document.getElementById('resultJobOffer'+j)) != null)) ;j++){																								
	                	    	highlightWord(lesResultats,words[w],niv);	                					
							}
							for (j=0; ((j < 20) && ((lesResultats = document.getElementById('resultHub'+j)) != null)) ;j++){																								
	                			highlightWord(lesResultats,words[w],niv);	                					
							}
							for (j=0; ((j < 20) && ((lesResultats = document.getElementById('resultEvent'+j)) != null)) ;j++){
	                			highlightWord(lesResultats,words[w],niv);	                					
							}
							for (j=0; ((j < 20) && ((lesResultats = document.getElementById('resultExpert'+j)) != null)) ;j++){																								
	                			highlightWord(lesResultats,words[w],niv);	                					
							}
							for (j=0; ((j < 20) && ((lesResultats = document.getElementById('resultTraining'+j)) != null)) ;j++){																								
	                			highlightWord(lesResultats,words[w],niv);	                					
							}
						}						
					}
              }
           }
	  }
	
}

function highlightSearchTerms1(keywords) {
	if (!document.createElement) return;
	var w=0;
	var j=0;		
	var words;
	var lesResultats;
	var niv=0;
        			if (keywords.indexOf("+") != -1 ) {words = unescape(keywords).split("+");}
        			else if (keywords.indexOf(" ") != -1 ) {words = unescape(keywords).split(" ");}	
        			else {words = unescape(keywords).split("+");}
	                for (w=0;w<words.length;w++) {	                	
	                	words[w] = (words[w].indexOf("*") != -1 ? words[w].substr(0, words[w].indexOf("*")) : words[w]);	                	
	                	words[w] = (words[w].indexOf(",") != -1 ? words[w].substr(0, words[w].indexOf(",")) : words[w]);	                	
	                	words[w] = (words[w].indexOf(".") != -1 ? words[w].substr(0, words[w].indexOf(".")) : words[w]);	                	
	                	words[w] = noaccent(words[w]);
						
	                	if (words[w].length > 2 && words[w] != 'des' && words[w] != 'les') { 	                																																		
							for (j=0; ((j < 20) && ((lesResultats = document.getElementById('result'+j)) != null)) ;j++){																								
	                					highlightWord(lesResultats,words[w],niv);				
							}		
						}						
					}
}


