var isNav = navigator.appName.indexOf("Netscape") !=-1;
var isN6 = ((isNav) && (document.getElementById));
var isMac = navigator.appVersion.indexOf("Macintosh") !=-1;
var isIE = document.all;
var isIEPC = ((isIE) && (!(isMac)))
var Egale = '=';


Array.prototype.indexOf = function()
{
	switch (arguments.length)
	{
		// recherche CS AS
		case 1 :
			if (arguments.length==1)
				for(var i=0;i<this.length;i++)
					if(this[i]==arguments[0])
						return i;
			break;
		case 2 : 
			switch (arguments[1])
			{
				//si = 1 => CS AS
				case 1 :
					for(var i=0;i<this.length;i++)
						if(this[i]==arguments[0])
							return i;
					break;
				//si = 2 => CI AS
				case 2 :
					for(var i=0;i<this.length;i++)
					{
						if(this[i].toLowerCase()==arguments[0].toLowerCase())
							return i;
					}
					
					break;
				//si = 3 => CI AI
				case 3 :
					var val_tab = "";
					var argument = arguments[0].toLowerCase();
					myregexp = new RegExp("[eéèëe]","gi");
					argument = argument.replace(myregexp,"[eéèëe]");
					
					myregexp = new RegExp("[iîï]","gi");
					argument = argument.replace(myregexp,"[iîï]");
					
					myregexp = new RegExp("[aà]","gi");
					argument = argument.replace(myregexp,"[aà]");
						
					myregexp = new RegExp("[uù]","gi");
					argument = argument.replace(myregexp,"[uù]");
						
					myregexp = new RegExp("( |\-)","gi");
					argument = argument.replace(myregexp,"( |\-)");
					
					for(var i=0;i<this.length;i++)
					{
						val_tab = this[i].toLowerCase();
						
						myregexp = new RegExp("[eéèëe]","gi");
						val_tab = val_tab.replace(myregexp,"[eéèëe]");
						
						myregexp = new RegExp("[iîï]","gi");
						val_tab = val_tab.replace(myregexp,"[iîï]");
						
						myregexp = new RegExp("[aà]","gi");
						val_tab = val_tab.replace(myregexp,"[aà]");
							
						myregexp = new RegExp("[uù]","gi");
						val_tab = val_tab.replace(myregexp,"[uù]");
							
						myregexp = new RegExp("( |\-)","gi");
						val_tab = val_tab.replace(myregexp,"( |\-)");
						
						if(val_tab==argument)
							return i;
					}
					break;
			}
			
			break;
	}
	

	/*if (arguments.length==1)
		for(var i=0;i<this.length;i++)
			if(this[i]==arguments[0])
				return i;*/

	return -1;
}






function OuvreFenetre(URL,NomControle,Largeur,Hauteur,AffScrollBars)
{
	if (AffScrollBars!="no") AffScrollBars='yes';
	Top = screen.height/2-Hauteur/2 
	Gauche = screen.width/2-Largeur/2
	var popup = window.open(URL, NomControle, "toolbar=no,status=no,menubar=no,scrollbars=" + AffScrollBars + ",resizable=no,directories=no,location=no,width=" + Largeur + ",height=" + Hauteur +",top=" + Top + ",left=" + Gauche)
}


function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function Desactive_Bouton(theform,btn,texte_replace)
{
	if (document.all || document.getElementById)
	{
		document.getElementById(btn).disabled = true;
		
		if (document.all)
		{
			if (eval(theform.id + ".bo_form_soumis"))
				{eval(theform.id + ".bo_form_soumis.value='true';");}
		}
		else
		{
			if (document.getElementById('bo_form_soumis'))
			{
				document.getElementById('bo_form_soumis').value='true';
			}
		}
		theform.submit();
	}
}




function HiLite(imgN,PathImage2,Extension)
{
		eval("document [imgN].src = \"/images/" + PathImage2 + imgN + "_" + Extension + ".gif\"");
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function


function check_email(langue)
{
	var strMessage;
	switch (langue)
	{
	case "fr":
		strMessage="Il n'y a pas d'adresse de courriel dans votre annonce pour postuler!\nDésirez vous continuer ?";
		break;
	case "en":
		strMessage="There is no e-mail address in your job posting!\nAre you sure you want to continue ? ";
		break;
	default:
		strMessage="Il n'y a pas d'adresse de courriel dans votre annonce pour postuler!\nDésirez vous continuer ?";
	break;
	} 

	var reg = /[\w.-]+@[\w.-]{2,}[.][a-zA-Z]{2,4}/gi;
	
	var description_fr = LeForm.Tasks_FR.value;
	var description_en = LeForm.Tasks_EN.value;
	
	var tab_fr = description_fr.match(reg);
	var tab_en = description_en.match(reg);
	
	if (((tab_fr==null)&&(langue=='fr')) || ((tab_en==null)&&(langue=='en')) || ((description_fr!='')&&(tab_fr==null)&&(langue=='en')) || ((description_en!='')&&(tab_en==null)&&(langue=='fr')))
	{
		if (confirm(strMessage))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
		return true;
}


function PositionnerControleById(Layer,x,y)
{
	PositionnerControle(document.getElementById(Layer),x,y);
}

function PositionnerControle(ctrl,x,y)
{
	eval("ctrl.style.left='" + x + "px'");
	eval("ctrl.style.top='" + y + "px'");
}

function CreateDiv(cssClass,UniqueID)
{
    if (!document.getElementById(UniqueID))
    {
        var div = document.createElement('div');
        if (cssClass != "") div.className = cssClass;
        if (UniqueID != "") div.id = UniqueID;
        document.body.appendChild(div);
        div.style.position='absolute';
	    div.style.top='-1000px';
	    div.style.left='-1000px';
    }
    else
        div = document.getElementById(UniqueID);
    return div
}

function efface(text_defaut,ctrl)
{
	
	if (text_defaut.value==ctrl.value)
	{
		ctrl.value='';
		ctrl.focus();
	}
}

function ChangeClass(Ctrl,strClass)
{
	if (Ctrl.className != "SubMenu_Open") {	Ctrl.className = strClass;}
}

function popup_menu(td_parent,ctrl)
{

	var objTD = eval("document.getElementById('" + td_parent + "')")
	if (objTD.className != "SubMenu_Open")
	{
		var _x = findPosX(objTD);
		var _y = findPosY(objTD);
		var _h = eval(objTD.offsetHeight);
		
		PositionnerControleById(ctrl,_x,_y+_h);
		
		ChangeClass(objTD,"SubMenu_Open");
	}
	else
	{
		objTD.className = "iOut";
		PositionnerControleById(ctrl,-500,-500);
	}
}


function RTB_ClearMSWord(editor)
{
	editor = editor.contentWindow ? editor.contentWindow : editor;
	
	editor.focus();
	

	//on vire tous les CSS
	var body = editor.document.body //? editor.document.body ;
	var TagsArray = body.all ? body.all : body.getElementsByTagName("*");
	
	for (var index = 0; index < TagsArray.length; index++)
	{
		tag = TagsArray[index];
		tag.removeAttribute("className","",0);
		tag.removeAttribute("class","",0);
		tag.removeAttribute("style","",0);
	}

	// Regex based cleaning
	var html = editor.document.body.innerHTML;
	
	//gestion des tags ms-word
	html = html.replace(/<o:p>&nbsp;<\/o:p>/gi, "");
	html = html.replace(/<st1:.*?>/gi, "");
	
	//gestion des tags mozilla
	html = html.replace(/\<!--.+--\>/gi, "");
	


	html = html.replace(/<(\/)?((LINK)|(DIV)|(SPAN)|(O:P)|(FONT))( (([^>])+)>|>)/gi, "");

	//gestion des paragraphes
	html = html.replace(/<P>(&nbsp;)*<\/P>/gi, "");
		
	//gestion des entêtes
	html = html.replace(/<H(1|2|3|4|5|6)( (([^>])+)>|>)/gi, "<p><b>");
	html = html.replace(/<\/H(1|2|3|4|5|6)( (([^>])+)>|>)/gi, "</b></p>");
	
	//gestion des tags IE
	html = html.replace(/<(\/)?(STRONG)( (([^>])+)>|>)/gi, "<$1B>");
	html = html.replace(/<(\/)?(EM)( (([^>])+)>|>)/gi, "<$1I>");
	
	//gestion des bullets
	html = html.replace(/<p>(·|Ø|§|-)(&nbsp;)*(([^>])+)<\/p>/gi, "<ul><li>$3</li></ul>");	
	html = html.replace(/<\/ul>\s*<ul>/gi, "");	
	
	
	//gestion des italiques inutiles
	html = html.replace(/<U>(&nbsp;)*<\/U>/gi, "");
	
	//gestion des paragraphes inutiles créés 
	//lors des remplacements des headers ou autres
	html = html.replace(/<P>(<[^>]*>)*(&nbsp;)*(<[^>]*>)*<\/P>/gi,"");
	
	editor.document.body.innerHTML = html;
										
}

function Mozilla_OnPaste_Handler(e,editor)
{
	var oEvent = (window.event) ? window.event : e;
	var nKeyCode = oEvent.keyCode ? oEvent.keyCode : oEvent.which ? oEvent.which : void 0;
	var sChar = String.fromCharCode(nKeyCode).toLowerCase();
	var bCtrlPressed = (oEvent.ctrlKey) ? oEvent.ctrlKey : oEvent.modifiers & 2 > 0;
	
	if (bCtrlPressed && sChar=="v")
	{
		eval("setTimeout(\"RTB_ClearMSWord(document.getElementById('" +  editor.id + "'));\",50);");
	}
	
}

// déclenche la capture du Control-V
function Set_RTB_CleanMS_Word(editor)
{
	if (document.all)
		editor.contentWindow.document.body.onpaste = function() {eval("setTimeout(\"RTB_ClearMSWord(document.getElementById('" +  editor.id + "'));\",50);");};
	else
		editor.contentWindow.addEventListener('keypress', function(e) {	Mozilla_OnPaste_Handler(e,editor);}, true);
}


// fonction pour le keypress
/*
var msg = 'That functionality is restricted.';
var asciiBack       = 8;
var asciiTab        = 9;
var asciiSHIFT      = 16;
var asciiCTRL       = 17;
var asciiALT        = 18;
var asciiHome       = 36;
var asciiLeftArrow  = 37;
var asciiRightArrow = 39;
var asciiMS         = 92;
var asciiView       = 93;

var asciiF1         = 112;
var asciiF2         = 113;
var asciiF3         = 114;
var asciiF4         = 115;
var asciiF5         = 116;
var asciiF6         = 117;
var asciiF11        = 122;
var asciiF12        = 123;



function onKeyPress(evt) {
    window.status = '';
    //get the event object
    var oEvent = (window.event) ? window.event : evt;
    
    //hmmm in mozilla this is jacked, so i have to record these seperate
    //what key was pressed
    var nKeyCode =  oEvent.keyCode ? oEvent.keyCode : oEvent.which ? oEvent.which : void 0;
    var bIsFunctionKey = false;

    //hmmm in mozilla the keycode would contain a function key ONLY IF the charcode IS 0    
    //else key code and charcode read funny, the charcode for 't' 
    //returns 116, which is the same as the ascii for F5
    //SOOO,... to check if a the keycode is truly a function key, 
    //ONLY check when the charcode is null OR 0, IE returns null, mozilla returns 0 
    if(oEvent.charCode == null || oEvent.charCode == 0){ 
        bIsFunctionKey = (nKeyCode >= asciiF2 && nKeyCode <= asciiF12) || (nKeyCode == asciiALT || nKeyCode == asciiMS || nKeyCode == asciiView || nKeyCode == asciiHome || nKeyCode == asciiBack)
    }
    
    //convert the key to a character, makes for more readable code  
    var sChar = String.fromCharCode(nKeyCode).toUpperCase();

    //get the active tag that has the focus on the page, and its tag type
    var oTarget = (oEvent.target) ? oEvent.target : oEvent.srcElement;
    var sTag = oTarget.tagName.toLowerCase();
    var sTagType = oTarget.getAttribute("type");
    
    var bAltPressed = (oEvent.altKey) ? oEvent.altKey : oEvent.modifiers & 1 > 0;
    var bShiftPressed = (oEvent.shiftKey) ? oEvent.shiftKey : oEvent.modifiers & 4 > 0;
    var bCtrlPressed = (oEvent.ctrlKey) ? oEvent.ctrlKey : oEvent.modifiers & 2 > 0;
    //var bMetaPressed = (oEvent.metaKey) ? oEvent.metaKey : oEvent.modifiers & 8 > 0;

    var bRet = true; //assume true as that will be the case most times
       //alert (nKeyCode + ' ' + sChar + ' ' + sTag + ' ' + sTagType + ' ' + bShiftPressed + ' ' + bCtrlPressed + ' ' + bAltPressed);

    if(sTagType != null){sTagType = sTagType.toLowerCase();}

    //allow these keys inside a text box
    if  (sTag == "textarea" || (sTag == "input" && (sTagType == "text" || sTagType == "password")) && (nKeyCode == asciiBack || nKeyCode == asciiSHIFT || nKeyCode == asciiHome || bShiftPressed || (bCtrlPressed && (nKeyCode == asciiLeftArrow || nKeyCode == asciiRightArrow)))) {
		return true;
    }else if(bAltPressed && (nKeyCode == asciiLeftArrow || nKeyCode == asciiRightArrow)){ // block alt + left or right arrow
        bRet = false;
    }else if(bCtrlPressed && (sChar == 'A' || sChar == 'C' || sChar == 'V' || sChar == 'X')){ alert("go");// ALLOW cut, copy and paste, and SELECT ALL
        bRet = true;
    }else if(bShiftPressed && nKeyCode == asciiTab){//allow shift + tab
        bRet = true;
    }else if(bIsFunctionKey){ // Capture and stop these keys
        bRet = false;
    }else if(bCtrlPressed || bShiftPressed || bAltPressed){ //block ALL other sequences, includes CTRL+O, CTRL+P, CTRL+N, etc....
        bRet = false;
    }
    
    if(!bRet){
        try{
            oEvent.returnValue = false;
            oEvent.cancelBubble = true;

            if(document.all){ //IE
                oEvent.keyCode = 0;
            }else{ //NS
                oEvent.preventDefault();
                oEvent.stopPropagation();
            }
            window.status = msg; 
        }catch(ex){
            //alert(ex);
        }
    }
    return bRet;
}
*/



