function remplace(text,find,repl){
  var found = text.indexOf(find);
  var retVal= "";
  var start = 0;
  while(found != -1){
    retVal +=text.substring(start,found) +repl;
    start = found+find.length;
    found =text.indexOf(find,start);
  }
  retVal +=text.substring(start,text.length);
  return retVal;
}

function ucfirst(str) {
   str = str.toLowerCase();
   return str.substr(0,1).toUpperCase()+str.substr(1)
}

function MM_findObj(n, d) { //v4.0
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && document.getElementById) x=document.getElementById(n); return x;
	}

function MM_swapImgRestore() { 
		var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}

function MM_swapImage() { 
		var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
		if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
		}
		
function MM_showHideLayers() { //v3.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
		if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
		obj.visibility=v; }
	}

function Openhw (path,nom,h,w){
		win = window.open(path,nom,"width="+w+",height="+h+",toolbar=yes,location=no,status=no,menubar=no,scrollbars=no,resizable=no");
}

function OpenhwNoToolbar (path,nom,h,w){
		win = window.open(path,nom,"width="+w+",height="+h+",toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no");
}

function OpenhwWithParam (path,nom,h,w,toolbar,menubar,scrollbars){
		win = window.open(path,nom,"width="+w+",height="+h+",toolbar="+ toolbar + ",location=no,status=no,menubar="+ menubar +",scrollbars="+ scrollbars +",resizable=no");
}

function Openhwscroll (path,nom,h,w){
		win = window.open(path,nom,"width="+w+",height="+h+",toolbar=yes,location=no,status=no,menubar=no,scrollbars=yes,resizable=no");
}

function AddEncodedParameter(pageUrl, parameterName, parameterValue)
{
	var parameterEncodedValue = new String();
	var character;
			
	if ((pageUrl) && (parameterValue) && (parameterName))
	{
		for (var index=0; index < parameterValue.length; index++) 
		{ 
			character = parameterValue.charAt(index); 
			if (character == '?' ) parameterEncodedValue += "%3F"; 
			else if (character == '&') parameterEncodedValue += "%26"; 
			else if (character == '/') parameterEncodedValue += "%2F"; 
			else parameterEncodedValue += character; 
		}
	
		return pageUrl + parameterName + '=' + parameterEncodedValue;
	}
	else
	{
		return '';
	}
}

function UpperCase(text)
{
	document.write(text.toUpperCase());
}

// Vérifier la pression sur la touche Entrée et soumet le formulaire
function checkEnterAndSubmit(e,myForm,submitUrl){ //e is event object passed from function invocation
	var characterCode;  //literal character code will be stored in this variable
	
	if(e && e.which){ //if "which" property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	}
	else{
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}
	
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		if (submitUrl != null && submitUrl != "")
		{
			// On change l'attribut "action" du 1er formulaire sur la page
			//alert(document.__aspnetForm);
			//alert(document.__aspnetForm.action);
			document.__aspnetForm.action = submitUrl;
			document.__aspnetForm.submit();
		}
	}
}

//------------------------------------------------------------------------------------------------//
// CONTACT US FUNCTIONS SECTION                                                                   //
//------------------------------------------------------------------------------------------------//
var subjectlist;

//-----------------------------------------------//
// This function add a subject to subjects list. //
//-----------------------------------------------//
function AddSubject(subject, subsubject)
{
	var index;
	var subjectfound = false;
	var currentsubject;
	
	if (!subjectlist)
	{
		// Initialize subject Array;
		 subjectlist = new Array();
	}

	// Search the subject in subjects Array
	for (index = 0; (index < subjectlist.length) && !subjectfound; index++)
	{
		currentsubject = subjectlist[index];
		
		// Test if subject and current subject are defined
		if (subject && currentsubject)
		{
			if (subject.code == currentsubject.code)
			{
				subjectfound = true;
			}
		}
	}

	if (!subjectfound)
	{
		// Add the subject to subjects Array
		subjectlist.push(subject);
		currentsubject = subject;
	}

	// Add the subsubject to the subject
	AddSubSubject(currentsubject, subsubject);
}

//---------------------------------------------//
// This function add a subsubject to a subject //
//---------------------------------------------//
function AddSubSubject(subject, subsubject)
{
	// Test if subject and subsubject are defined
	if (subject && subsubject)
	{
		if (!subject.subsubjects)
		{
			subject.subsubjects = new Array();
		}
		
		// Add subsubject
		subject.subsubjects.push(subsubject);
	}
}

//---------------------------------------------//
// This function fills a select with subjects. //
//---------------------------------------------//
function FillSubject(optionselect,optionhidden)
{
	var index;
	var optionitem;
	var subjectselect = GetElement("mail_subject_list", 0);
	//alert(subjectselect);
	var subjecthidden = GetElement("mail_subject", 0);
	//alert(subjecthidden);
	
	if (subjectselect && subjectlist)
	{
		// Reset subjects
		ResetSelect(subjectselect);
		
		for (index = 0; index < subjectlist.length; index++)
		{
			// Add option item
			optionitem = document.createElement("OPTION");
			optionitem.text = subjectlist[index].text;
			optionitem.value = subjectlist[index].code;
			subjectselect.options[subjectselect.options.length] = optionitem;
			
			if (subjecthidden)
			{
				// Select the current value
				optionitem.selected = (optionitem.value == subjecthidden.value);
			}
		}
		
		if (optionselect)
		{
			var mail_subject_list = GetElement("mail_subject_list", 0);
			
			mail_subject_list_index = mail_subject_list.selectedIndex;
			mail_subject_list.selectedIndex = optionselect;
		}
		
		if (optionhidden)
		{
			var mail_subject_list = GetElement("mail_subject_list", 0);
			MM_showHideLayers("mail_subject_list","","hide");
		}
	}
}

//------------------------------------------------//
// This function fills a select with subsubjects. //
//------------------------------------------------//
function FillSubSubject()
{
	var optionitem;
	var index;
	var subjectselect = GetElement("mail_subject_list", 0);
	var subsubjectselect = GetElement("mail_subsubject_list", 0);
	var subsubjecthidden = GetElement("mail_subsubject", 0);

	if (subjectselect && subsubjectselect)
	{
		// Reset subsubjects					
		ResetSelect(subsubjectselect);
		
		currentsubject = subjectlist[subjectselect.options.selectedIndex - 1];
		
		if (currentsubject && currentsubject.subsubjects)
		{		
			for (index = 0; index < currentsubject.subsubjects.length; index++)
			{
				// Add option item
				optionitem = document.createElement("OPTION");
				optionitem.text = currentsubject.subsubjects[index].text;
				optionitem.value = currentsubject.subsubjects[index].code;
				subsubjectselect.options[subsubjectselect.options.length] = optionitem;
				
				if (subsubjecthidden)
				{
					// Select the current value
					optionitem.selected = (optionitem.value == subsubjecthidden.value);
				}
			}
		}
	}
}

//------------------------------------------------//
// This function resets a select.                 //
//------------------------------------------------//
function ResetSelect(selectlist)
{
	// Remove options
	while (selectlist.options.length != 1)
	{
		selectlist.options[1] = null;
	}
}

//------------------------------------------------//
// This function gets a value from a list using   //
// its index and return the default value if      //
// index is out of range or list is null.         //
//------------------------------------------------//
function GetListValue(list, index, defaultvalue)
{
	if (list && list[index])
	{
		return list[index];
	}
	else
	{
		return defaultvalue;
	}
}	

//------------------------------------------------//
// This function sets mailto and subject values   //
// to hidden fields. It also rebuild subsubjects  //
// list.                                          //
//------------------------------------------------//
function OnSubjectListChange()
{
	var subjectselect = GetElement("mail_subject_list", 0);
	var subject = GetListValue(subjectlist, subjectselect.selectedIndex - 1, null);
	
	if (subject)
	{
		SaveElement('mail_subject', subject.text);
		SaveElement('mail_subject_code', subject.code);
		SaveElement('mail_to', subject.emailto);
	}
	else
	{
		SaveElement('mail_subject', '');
		SaveElement('mail_subject_code', '');
		SaveElement('mail_to', '');
	}
	
	if(GetElement("mail_subsubject_list", 0))
	{
		FillSubSubject();
	}
}

//------------------------------------------------//
// This function sets mailto and subject values   //
// to hidden fields. It also rebuild subsubjects  //
// list.                                          //
//------------------------------------------------//
function OnSubSubjectListChange()
{
	var subjectselect;
	var subsubjectselect;
	var subject;
	var subsubject;
	
	subjectselect = GetElement("mail_subject_list", 0);
	subsubjectselect = GetElement("mail_subsubject_list", 0);
	subject = GetListValue(subjectlist, subjectselect.selectedIndex - 1, null);
	
	if (subject)
	{
		subsubject = GetListValue(subject.subsubjects, subsubjectselect.selectedIndex - 1, null);
		
		if (subsubject)
		{
			SaveElement('mail_subsubject', subsubject.text);
			SaveElement('mail_subsubject_code', subsubject.code);
		}
		else
		{
			SaveElement('mail_subsubject', '');
			SaveElement('mail_subsubject_code', '');
		}
	}
}

function nomargin(){
	// permet de déterminer le navigateur en fonction de nos besoins
	var dom = net = iex = false;
	if (document.getElementById) dom = true; // IE5+ ou Netscape6+/Mozilla
	if (document.layers) net = true; // Netscape4 
	if (document.all) iex = true; // IE4+
	
	if (iex) {
	  var larg_utile = "document.body.offsetWidth";
	  var haut_utile = "document.body.offsetHeight";
	}
	else if (dom || net) {
	  var larg_utile = "window.innerWidth";
	  var haut_utile = "window.innerHeight";
	}
	else {}
	var nb_couleurs = screen.colorDepth;
	var larg_ecran = screen.width;
	var haut_ecran = screen.height;
	
	var iddiv = "TakeCareCenter";
	if(!document.getElementById("TakeCareCenter")){
		iddiv = "TakeCareCenter_Home";
	}
	if(eval(larg_utile)<960){
	    if(document.getElementById(iddiv)){
		   document.getElementById(iddiv).style.left = 0;
		   document.getElementById(iddiv).style.marginLeft = 0;
		}
	}else{
		if(document.getElementById(iddiv)){
		   document.getElementById(iddiv).style.left = "50%";
		   document.getElementById(iddiv).style.marginLeft = "-480px";
		}
	}
	if(eval(haut_utile)<600){
		if(document.getElementById(iddiv)){
		   document.getElementById(iddiv).style.top = 0;
		   document.getElementById(iddiv).style.marginTop= 0;
		}
	}else{
	    if(document.getElementById(iddiv)){
		   document.getElementById(iddiv).style.top = 0;
		   document.getElementById(iddiv).style.marginTop= 0;
		}
	}
}

window.onload= nomargin;
window.onresize= nomargin;
