var culture;
var	monthName;

var	fixedX = -1;			// x position (-1 if to appear below control)
var	fixedY = -1;		// y position (-1 if to appear below control)
var startAt = 0;		// 0 - sunday ; 1 - monday
var showWeekNumber = 1;	// 0 - don't show; 1 - show
var showToday = 1;		// 0 - don't show; 1 - show
var imgDirValidation; // Directory used for images

var gotoString = "Go To Current Month";
var todayString = "Today is";
var weekString = "Wk";
var scrollLeftMessage = "Click to scroll to previous month. Hold mouse button to scroll automatically.";
var scrollRightMessage = "Click to scroll to next month. Hold mouse button to scroll automatically.";
var selectMonthMessage = "Click to select a month.";
var selectYearMessage = "Click to select a year.";
var selectDateMessage = "Select [date] as date."; // do not replace [date], it will be replaced by date.
var sCloseCalendar = "Close the calendar";

var	crossobj, crossMonthObj, crossYearObj, monthSelected, yearSelected, dateSelected, omonthSelected, oyearSelected, odateSelected, monthConstructed, yearConstructed, intervalID1, intervalID2, timeoutID1, timeoutID2, ctlToPlaceValue, ctlNow, dateFormat, nStartingYear;

var	bPageLoaded=false;
var	ie=document.all;
var	dom=document.getElementById;

var	ns4=document.layers;
var	today =	new	Date();
var	dateNow	 = today.getDate();
var	monthNow = today.getMonth();
var	yearNow	 = today.getFullYear();
var	imgsrc = new Array("drop1.gif","drop2.gif","left1.gif","left2.gif","right1.gif","right2.gif");
var	img	= new Array();

var bShow = false;


/******************************************************************************************/
// Validation Function

function MyValidation()
{
  var i;
  
  if (typeof(Page_Validators)!= "undefined")
  {
    for (i=0; i < Page_Validators.length; i++)
	  {
		  if (Page_Validators[i].controltovalidate && document.getElementById(Page_Validators[i].controltovalidate) && document.getElementById(Page_Validators[i].controltovalidate).getAttribute("isKce") == "true")
		  {
		    handleBlur(document.getElementById(Page_Validators[i].controltovalidate));
		  }
	  }
	}
}

function SendEmail(sControlId)
{
	if (document.getElementById(sControlId).value != "")
	{
		location.href='mailto:' + document.getElementById(sControlId).value;
	}
}

function GoToURL(sControlId)
{
	if (document.getElementById(sControlId).value != "")
	{
		window.open(document.getElementById(sControlId).value);
	}
}

// End of Validation Function
/******************************************************************************************/



/******************************************************************************************/
// Utilities functions

/* hides <select> and <applet> objects (for IE only) */
function hideElement( elmID, overDiv )
{
  if( ie )
  {
    for( i = 0; i < document.getElementsByTagName( elmID ).length; i++ )
    {
      obj = document.getElementsByTagName( elmID )[i];
      if( !obj || !obj.offsetParent )
      {
        continue;
      }
  
      // Find the element's offsetTop and offsetLeft relative to the BODY tag.
      objLeft   = obj.offsetLeft;
      objTop    = obj.offsetTop;
      objParent = obj.offsetParent;
      
      while( objParent.tagName.toUpperCase() != "BODY" )
      {
        objLeft  += objParent.offsetLeft;
        objTop   += objParent.offsetTop;
        objParent = objParent.offsetParent;
      }
  
      objHeight = obj.offsetHeight;
      objWidth = obj.offsetWidth;
  
      if(( overDiv.offsetLeft + overDiv.offsetWidth ) <= objLeft ) { }
      else if(( overDiv.offsetTop + overDiv.offsetHeight ) <= objTop ) { }
      else if( overDiv.offsetTop >= ( objTop + objHeight )) { }
      else if( overDiv.offsetLeft >= ( objLeft + objWidth )) { }
      else
      {
				// Hide only the object that is not already hidden
				if (obj.style.visibility != "hidden")
				{
					obj.setAttribute("isHiddenBykce", "true");
        obj.style.visibility = "hidden";
      }
    }
  }
}
}
  
/*
* unhides <select> and <applet> objects (for IE only)
*/
function showElement( elmID )
{
  if( ie )
  {
    for( i = 0; i < document.getElementsByTagName( elmID ).length; i++ )
    {
      obj = document.getElementsByTagName( elmID )[i];
      
      if( !obj || !obj.offsetParent )
      {
        continue;
      }
    
			// This verfication is to show just the objects hidden by hideElement method
			if (obj.getAttribute("isHiddenBykce"))
			{
				obj.removeAttribute("isHiddenBykce");
				obj.style.visibility = "visible";
			}
    }
  }
}

function swapImage(srcImg, destImg)
{
	document.getElementById(srcImg).setAttribute("src",imgDirValidation + destImg);
}

function padZero(num) {
	return (num	< 10)? '0' + num : num ;
}

/*
Created by Sharon Paine of Dynamic Web Coding
www.dyn-web.com
*/

// avoid error of passing event object in older browsers
if (!window.document.layers && !window.document.all) 
{
	event = "nope";
}

function doTooltip(voObject,evt,txt) {
// enclose tip in nested tables for uniform 'tooltip' effect
// customize here

// check for object (i.e., layers or all) 
// for Netscape 4+
/*if (window.document.layers) {
	window.document.tooltip.document.write(tip)
	window.document.tooltip.document.close()
	window.document.tooltip.left = evt.pageX + 8
	window.document.tooltip.top = evt.pageY + 8
	window.document.tooltip.visibility = "show"
}*/
// for IE 4+	
if (window.document.all) {
  //var pos = getBoundingClientRect();
 	
 	window.document.all(voObject.id + "_tooltipmsg").innerHTML = txt;
 	//window.document.all(id + "_tooltip").style.left = pos.left;
 	//window.document.all(id + "_tooltip").style.top = pos.top + 23;
 	window.document.all(voObject.id + "_tooltip").style.display = "inline";
 }
}

function hideTip(voObject) {
  var oToolTip = document.getElementById(voObject.id + "_tooltip");
  if (oToolTip)
  {
    oToolTip.style.display = "none";
  }
}

// End of Utilities functions
/******************************************************************************************/



/******************************************************************************************/
// Calendar

var sCurrentLanguage;
var HolidaysCounter = 0;
var Holidays = new Array();

// The calendar will be writen in this div
document.write("<span id='spanCalendar'></span>");

// The popup message will be writen in this span
document.write("<span id='spanPopupMessage'></span>");

/* Event registration */
//IE
if(ie)
{
	window.attachEvent("onload", init);
	document.attachEvent("onkeypress", hidecal1);
	document.attachEvent("onclick", hidecal2);
}
//DOM
else
{
	window.addEventListener("load", init, false);
	document.addEventListener("keypress", hidecal1, false);
	document.addEventListener("click", hidecal2, false);
}

// Hide the calendar when presing on ESC
function hidecal1 (e) 
{ 
	if (!e)
	{
		e = event;
	}
	if (e.keyCode==27) 
	{
		hideCalendar();
	}
}

// Hide the calendar when clicking on the X
function hidecal2 (e) 
{
	var oSrcElement;

	if(ie)
	{
		oSrcElement = e.srcElement;
	}
	else
	{
		oSrcElement = e.target;
	}

	if (oSrcElement != null && oSrcElement.id !=null && oSrcElement.id == "imgCloseCalendar")
	{
	  hideCalendar();
	}
	else if (!bShow)
	{
		hideCalendar();
	}
	bShow = false;
}

function init()	
{
	if (!ns4)
	{
		if(!bPageLoaded)
		{
			initCalendar();
		}

		bPageLoaded=true;
	}
}
	
function initCalendar(language)
{
	var sCalendar;
	var sHtml;

	if(calendarDefined())
	{
		initLanguage(language);
	
		if (dom)
		{
			for	(i=0;i<imgsrc.length;i++)
			{
				img[i] = new Image();
				img[i].src = imgDirValidation + imgsrc[i];
			}
			
			sCalendar = "<iframe id='oCalendarIFrame' style='display:none;left:0px;position:absolute;top:0px;z-index:11000' src='" + imgDirValidation + "dummy.htm" + "' frameBorder='0' scrolling='no'></iframe>";
					
			sCalendar += "<div onclick='bShow=true' id='calendar' style='z-index:11001;position:absolute;visibility:hidden;'><table width="+((showWeekNumber==1)?250:220)+" class='CalendarMainTable'><tr><td class='CalendarHeader'><table width='"+((showWeekNumber==1)?248:218)+"'><tr><td class='CalendarHeaderCell'><span id='caption'></span></td><td class='CalendarHeaderCell' align=right><img src='"+imgDirValidation+"close.gif' border='0' title='" + sCloseCalendar + "' alt='" + sCloseCalendar + "' id='imgCloseCalendar'></td></tr></table></td></tr><tr><td class='CalendarContent'><span id='CalendarContentHtml'></span></td></tr>";
			
			if (showToday==1)
			{
					sCalendar += "<tr><td class='CalendarFooter'><span id='lblToday'></span></td></tr>";
			}
		
			sCalendar += "</table></div><div id='selectMonth' style='z-index:11002;position:absolute;visibility:hidden;'></div><div id='selectYear' style='z-index:11002;position:absolute;visibility:hidden;'></div>";
		}

		document.getElementById("spanCalendar").innerHTML = sCalendar;
							
		crossobj=(dom)?document.getElementById("calendar").style : ie? document.all.calendar : document.calendar
							
		hideCalendar();

		crossMonthObj=(dom)?document.getElementById("selectMonth").style : ie? document.all.selectMonth	: document.selectMonth

		crossYearObj=(dom)?document.getElementById("selectYear").style : ie? document.all.selectYear : document.selectYear

		monthConstructed=false;
		yearConstructed=false;

		if (showToday==1)
		{
			var tmpMonthName;
			
			if (monthName[monthNow].indexOf("&") == -1)
			{
				tmpMonthName = monthName[monthNow].substring(0,3);
			}
			else
			{
				tmpMonthName = monthName[monthNow].substring(0, monthName[monthNow].indexOf(";") + 2);
			}
			
			document.getElementById("lblToday").innerHTML =	" <span onmousemove='window.status=\"" + gotoString + "\"' onmouseout='window.status=\"\"' title='" + gotoString + "' class='CalendarFooterLink' onclick='javascript:monthSelected=monthNow;yearSelected=yearNow;constructCalendar();'>" + todayString + " " + dayName[(today.getDay()-startAt==-1)?6:(today.getDay()-startAt)] + ", " + dateNow + " " + tmpMonthName	+ "	" +	yearNow	+ "</span>";
			document.getElementById("imgCloseCalendar").src = imgDirValidation+"close.gif";
		}

		sHtml="<span id='spanLeft' class='CalendarHeaderButton' onmouseover='swapImage(\"changeLeft\",\"left2.gif\");this.className=\"CalendarHeaderButtonHover\";window.status=\""+scrollLeftMessage+"\"' onclick='javascript:decMonth()' onmouseout='clearInterval(intervalID1);swapImage(\"changeLeft\",\"left1.gif\");this.className=\"CalendarHeaderButton\";window.status=\"\"' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartDecMonth()\",500)'	onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'>&nbsp<img id='changeLeft' src='"+imgDirValidation+"left1.gif' border=0>&nbsp</span>&nbsp;";
		sHtml+="<span id='spanRight' class='CalendarHeaderButton'	onmouseover='swapImage(\"changeRight\",\"right2.gif\");this.className=\"CalendarHeaderButtonHover\";window.status=\""+scrollRightMessage+"\"' onmouseout='clearInterval(intervalID1);swapImage(\"changeRight\",\"right1.gif\");this.className=\"CalendarHeaderButton\";window.status=\"\"' onclick='incMonth()' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartIncMonth()\",500)'	onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'>&nbsp<img id='changeRight' src='"+imgDirValidation+"right1.gif' border=0>&nbsp</span>&nbsp";
		sHtml+="<span id='spanMonth' class='CalendarHeaderButton'	onmouseover='swapImage(\"changeMonth\",\"drop2.gif\");this.className=\"CalendarHeaderButtonHover\";window.status=\""+selectMonthMessage+"\"' onmouseout='swapImage(\"changeMonth\",\"drop1.gif\");this.className=\"CalendarHeaderButton\";window.status=\"\"' onclick='popUpMonth()'></span>&nbsp;";
		sHtml+="<span id='spanYear' class='CalendarHeaderButton' onmouseover='swapImage(\"changeYear\",\"drop2.gif\");this.className=\"CalendarHeaderButtonHover\";window.status=\""+selectYearMessage+"\"'	onmouseout='swapImage(\"changeYear\",\"drop1.gif\");this.className=\"CalendarHeaderButton\";window.status=\"\"'	onclick='popUpYear()'></span>&nbsp;";
		
		document.getElementById("caption").innerHTML  =	sHtml;
	}
}

function initLanguage(language)
{
	if (language != null && language == "fr")
	{
		monthName =	new	Array("Janvier","F&eacute;vrier","Mars","Avril","Mai","Juin","Juillet","Ao&ucirc;t","Septembre","Octobre","Novembre","D&eacute;cembre")
		gotoString = "Aller au mois pr&eacute;sent"
		todayString = "Aujourd'hui "
		weekString = "Sem."
		scrollLeftMessage = "Cliquer pour aller au mois pr&eacute;cedent."
		scrollRightMessage = "Cliquer pour aller au prochain mois."
		selectMonthMessage = "Cliquer pour choisir un mois."
		selectYearMessage = "Cliquer pour choisir une ann&eacute;e."
		selectDateMessage = "Choisir [date] comme date." // do not replace [date], it will be replaced by date.
		sCloseCalendar = "Fermer le calendrier"
				
		if (startAt==0)
		{
			dayName = new Array	("Dim","Lun","Mar","Mer","Jeu","Ven","Sam")
		}
		else
		{
			dayName = new Array	("Lun","Mar","Mer","Jeu","Ven","Sam","Dim")
		}
	}
	else
	{
		monthName =	new	Array("January","February","March","April","May","June","July","August","September","October","November","December");

		if (startAt==0)
		{
			dayName = new Array	("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
		}
		else
		{
			dayName = new Array	("Mon","Tue","Wed","Thu","Fri","Sat","Sun");
		}
	}
}

function hideCalendar()	
{
	var oCalendarIFrame;
	if(calendarDefined() && crossobj)
	{
		crossobj.visibility="hidden"
		if (crossMonthObj != null){crossMonthObj.visibility="hidden";}
		if (crossYearObj !=	null){crossYearObj.visibility="hidden";}
		
		oCalendarIFrame = document.getElementById("oCalendarIFrame");
		
		oCalendarIFrame.style.position = "absolute";
		oCalendarIFrame.style.display = "none";

	  showElement( 'SELECT' );
		showElement( 'APPLET' );
	}
}

function constructDate(d,m,y)
{
	var	sTmp;		
	sTmp = dateFormat;
	sTmp = sTmp.replace	("dd","<e>");
	sTmp = sTmp.replace	("d","<d>");
	sTmp = sTmp.replace	("<e>",padZero(d));
	sTmp = sTmp.replace	("<d>",d);
	sTmp = sTmp.replace	("mmm","<o>");
	sTmp = sTmp.replace	("mm","<n>");
	sTmp = sTmp.replace	("m","<m>");
	sTmp = sTmp.replace	("<m>",m+1);
	sTmp = sTmp.replace	("<n>",padZero(m+1));
	sTmp = sTmp.replace	("<o>",monthName[m]);
	return sTmp.replace ("yyyy",y);
}

function closeCalendar() 
{
	hideCalendar();
	ctlToPlaceValue.value =	constructDate(dateSelected,monthSelected,yearSelected);
	if (ctlToPlaceValue.SetValidators != null)
	{
		ctlToPlaceValue.SetValidators();
	}
}

/*** Month Pulldown	***/

function StartDecMonth()
{
	intervalID1=setInterval("decMonth()",80);
}

function StartIncMonth()
{
	intervalID1=setInterval("incMonth()",80);
}

function incMonth () 
{
	monthSelected++;
	if (monthSelected>11) 
	{
		monthSelected=0;
		yearSelected++;
	}
	constructCalendar();
	setCalendarIFrame();
}

function decMonth () 
{
	monthSelected--;
	if (monthSelected<0) 
	{
		monthSelected=11;
		yearSelected--;
	}
	constructCalendar();
	setCalendarIFrame();
}

function constructMonth() 
{
	var sHTML;
	popDownYear();
	if (!monthConstructed) 
	{
		sHTML =	"";
		for	(i=0; i<12;	i++) 
		{
			sName =	monthName[i];
			if (i==monthSelected)
			{
				sName =	"<B>" +	sName +	"</B>";
			}
			sHTML += "<tr><td id='m" + i + "' onmouseover='this.className=\"CalendarMonthDropDownSelected\"' onmouseout='this.className=\"\"' style='cursor:pointer' onclick='monthConstructed=false;monthSelected=" + i + ";constructCalendar();popDownMonth();event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>";
		}

		document.getElementById("selectMonth").innerHTML = "<table class='CalendarMonthDropDown' cellspacing=0 onmouseover='clearTimeout(timeoutID1)'	onmouseout='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"popDownMonth()\",100);event.cancelBubble=true'>" +	sHTML +	"</table>";

		monthConstructed=true;
	}
}

function popUpMonth() 
{
	constructMonth();
	crossMonthObj.visibility = (dom||ie)? "visible"	: "show";
	crossMonthObj.left = parseInt(crossobj.left) + 50;
	crossMonthObj.top =	parseInt(crossobj.top) + 26;

	hideElement( 'SELECT', document.getElementById("selectMonth") );
	hideElement( 'APPLET', document.getElementById("selectMonth") );			
}

function popDownMonth()	
{
	crossMonthObj.visibility= "hidden";
	setCalendarIFrame();
}

/*** Year Pulldown ***/

function incYear() 
{
	for	(i=0; i<7; i++)
	{
		newYear	= (i+nStartingYear)+1;
		if (newYear==yearSelected)
		{ txtYear =	"&nbsp;<B>"	+ newYear +	"</B>&nbsp;"; }
		else
		{ txtYear =	"&nbsp;" + newYear + "&nbsp;"; }
		document.getElementById("y"+i).innerHTML = txtYear;
	}
	nStartingYear ++;
	bShow=true;
}

function decYear() 
{
	for	(i=0; i<7; i++)
	{
		newYear	= (i+nStartingYear)-1;
		if (newYear==yearSelected)
		{ txtYear =	"&nbsp;<B>"	+ newYear +	"</B>&nbsp;"; }
		else
		{ txtYear =	"&nbsp;" + newYear + "&nbsp;"; }
		document.getElementById("y"+i).innerHTML = txtYear;
	}
	nStartingYear --;
	bShow=true;
}

function selectYear(nYear)
{
	yearSelected=parseInt(nYear+nStartingYear);
	yearConstructed=false;
	constructCalendar();
	popDownYear();
}

function constructYear() 
{
	var sHTML = "";
	popDownMonth();
	if (!yearConstructed) 
	{
		sHTML =	"<tr><td align='center'	onmouseover='this.className=\"CalendarYearDropDownSelected\"' onmouseout='clearInterval(intervalID1);this.className=\"\"' style='cursor:pointer'	onmousedown='clearInterval(intervalID1);intervalID1=setInterval(\"decYear()\",30)' onmouseup='clearInterval(intervalID1)'>-</td></tr>";

		j =	0;
		nStartingYear =	yearSelected-3;
		for	(i=(yearSelected-3); i<=(yearSelected+3); i++) 
		{
			sName =	i;
			if (i==yearSelected)
			{
				sName =	"<B>" +	sName +	"</B>";
			}

			sHTML += "<tr><td id='y" + j + "' onmouseover='this.className=\"CalendarYearDropDownSelected\"' onmouseout='this.className=\"\"' style='cursor:pointer' onclick='selectYear("+j+");event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>";
			j ++;
		}

		sHTML += "<tr><td align='center' onmouseover='this.className=\"CalendarYearDropDownSelected\"' onmouseout='clearInterval(intervalID2);this.className=\"\"' style='cursor:pointer' onmousedown='clearInterval(intervalID2);intervalID2=setInterval(\"incYear()\",30)'	onmouseup='clearInterval(intervalID2)'>+</td></tr>";

		document.getElementById("selectYear").innerHTML	= "<table class='CalendarYearDropDown' onmouseover='clearTimeout(timeoutID2)' onmouseout='clearTimeout(timeoutID2);timeoutID2=setTimeout(\"popDownYear()\",100)' cellspacing=0>"	+ sHTML	+ "</table>";

		yearConstructed	= true;
	}
}

function popDownYear() 
{
	clearInterval(intervalID1);
	clearTimeout(timeoutID1);
	clearInterval(intervalID2);
	clearTimeout(timeoutID2);
	crossYearObj.visibility= "hidden";
	setCalendarIFrame();
}

function popUpYear() 
{
	var	leftOffset;

	constructYear();
	crossYearObj.visibility	= (dom||ie)? "visible" : "show";
	leftOffset = parseInt(crossobj.left) + document.getElementById("spanYear").offsetLeft;
	if (ie)
	{
		leftOffset += 6;
	}
	crossYearObj.left =	leftOffset;
	crossYearObj.top = parseInt(crossobj.top) +	26;
}

function WeekNbr(n) 
{
  // Algorithm used:
  // From Klaus Tondering's Calendar document (The Authority/Guru)
  // hhtp://www.tondering.dk/claus/calendar.html
  // a = (14-month) / 12
  // y = year + 4800 - a
  // m = month + 12a - 3
  // J = day + (153m + 2) / 5 + 365y + y / 4 - y / 100 + y / 400 - 32045
  // d4 = (J + 31741 - (J mod 7)) mod 146097 mod 36524 mod 1461
  // L = d4 / 1460
  // d1 = ((d4 - L) mod 365) + L
  // WeekNumber = d1 / 7 + 1

  year = n.getFullYear();
  month = n.getMonth() + 1;
  if (startAt == 0) {
      day = n.getDate() + 1;
  }
  else {
      day = n.getDate();
  }

  a = Math.floor((14-month) / 12);
  y = year + 4800 - a;
  m = month + 12 * a - 3;
  b = Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400);
  J = day + Math.floor((153 * m + 2) / 5) + 365 * y + b - 32045;
  d4 = (((J + 31741 - (J % 7)) % 146097) % 36524) % 1461;
  L = Math.floor(d4 / 1460);
  d1 = ((d4 - L) % 365) + L;
  week = Math.floor(d1/7) + 1;

  return week;
}

function constructCalendar ()
{
	var aNumDays = Array (31,0,31,30,31,30,31,31,30,31,30,31)

	var dateMessage
	var	startDate =	new	Date (yearSelected,monthSelected,1)
	var endDate
	
	var sClass;

	if (monthSelected==1)
	{
		endDate	= new Date (yearSelected,monthSelected+1,1);
		endDate	= new Date (endDate	- (24*60*60*1000));
		numDaysInMonth = endDate.getDate()
	}
	else
	{
		numDaysInMonth = aNumDays[monthSelected];
	}

	datePointer	= 0
	dayPointer = startDate.getDay() - startAt
	
	if (dayPointer<0)
	{
		dayPointer = 6
	}

	sHTML =	"<table class='CalendarContentGrid'><tr>"

	if (showWeekNumber==1)
	{
		sHTML += "<td width=27><b>" + weekString + "</b></td><td width=1 rowspan=7 class='CalendarVerticalLine'><img src='"+imgDirValidation+"divider.gif' width=1></td>"
	}

	for	(i=0; i<7; i++)	{
		sHTML += "<td width='27' align='right'><B>"+ dayName[i]+"</B></td>"
	}
	sHTML +="</tr><tr>"
	
	if (showWeekNumber==1)
	{
		sHTML += "<td align=right>" + WeekNbr(startDate) + "&nbsp;</td>"
	}

	for	( var i=1; i<=dayPointer;i++ )
	{
		sHTML += "<td>&nbsp;</td>"
	}

	for	( datePointer=1; datePointer<=numDaysInMonth; datePointer++ )
	{
		dayPointer++;
		sHTML += "<td align=right>"
		
		if ((datePointer==odateSelected) &&	(monthSelected==omonthSelected)	&& (yearSelected==oyearSelected))
		{ 
			if ((datePointer==dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow))
			{
				sClass = "CalendarDaySelectedToday";
			}
			else if	((dayPointer % 7 == (startAt * -1)+1) || (dayPointer % 7 == (startAt * -1)))
			{
				sClass = "CalendarDaySelectedWeekEnd";
			}
			else
			{
				sClass = "CalendarDaySelected";
			}
		}
		else if ((datePointer==dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow))
		{
			sClass = "CalendarDayToday";
		}
		else if	((dayPointer % 7 == (startAt * -1)+1) || (dayPointer % 7 == (startAt * -1)))
		{
			sClass = "CalendarDayWeekEnd";
		}
		else
		{
			sClass = "CalendarDay";
		}

		sHint = ""
		/*for (k=0;k<HolidaysCounter;k++)
		{
			if ((parseInt(Holidays[k].d)==datePointer)&&(parseInt(Holidays[k].m)==(monthSelected+1)))
			{
				if ((parseInt(Holidays[k].y)==0)||((parseInt(Holidays[k].y)==yearSelected)&&(parseInt(Holidays[k].y)!=0)))
				{
					sStyle+="background-color:#FFDDDD;"
					sHint+=sHint==""?Holidays[k].desc:"\n"+Holidays[k].desc
				}
			}
		}*/

		var regexp= /\"/g
		sHint=sHint.replace(regexp,"&quot;")


		dateMessage = "onmousemove='window.status=\""+selectDateMessage.replace("[date]",constructDate(datePointer,monthSelected,yearSelected))+"\"' onmouseout='window.status=\"\"' "

		sHTML += "<span "+dateMessage+" title=\"" + sHint + "\" class='" + sClass + "' onclick='javascript:dateSelected="+datePointer + ";javascript:closeCalendar();'>&nbsp;" + datePointer + "&nbsp;</span>"

		sHTML += ""
		if ((dayPointer+startAt) % 7 == startAt) { 
			sHTML += "</tr><tr>" 
			if ((showWeekNumber==1)&&(datePointer<numDaysInMonth))
			{
				sHTML += "<td align=right>" + (WeekNbr(new Date(yearSelected,monthSelected,datePointer+1))) + "&nbsp;</td>"
			}
		}
	}

	document.getElementById("CalendarContentHtml").innerHTML   = sHTML
	document.getElementById("spanMonth").innerHTML = "&nbsp;" +	monthName[monthSelected] + "&nbsp;<IMG id='changeMonth' SRC='"+imgDirValidation+"drop1.gif' BORDER=0>"
	document.getElementById("spanYear").innerHTML =	"&nbsp;" + yearSelected	+ "&nbsp;<IMG id='changeYear' SRC='"+imgDirValidation+"drop1.gif' BORDER=0>"
}

function popUpCalendar(ctl,	ctl2, format, language) 
{
	var	leftpos=0;
	var	toppos=0;
	var oDivCalendarPosition;
	
	if (language != sCurrentLanguage)
	{
		initCalendar(language);
		sCurrentLanguage = language;
	}
			
	if (bPageLoaded)
	{
		if ( crossobj.visibility ==	"hidden" ) {
			ctlToPlaceValue	= ctl2
			dateFormat=format;

			formatChar = " "
			aFormat	= dateFormat.split(formatChar)
			if (aFormat.length<3)
			{
				formatChar = "/"
				aFormat	= dateFormat.split(formatChar)
				if (aFormat.length<3)
				{
					formatChar = "."
					aFormat	= dateFormat.split(formatChar)
					if (aFormat.length<3)
					{
						formatChar = "-"
						aFormat	= dateFormat.split(formatChar)
						if (aFormat.length<3)
						{
							// invalid date	format
							formatChar=""
						}
					}
				}
			}

			tokensChanged =	0
			if ( formatChar	!= "" )
			{
				// use user's date
				aData =	ctl2.value.split(formatChar)

				for	(i=0;i<3;i++)
				{
					if ((aFormat[i]=="d") || (aFormat[i]=="dd"))
					{
						dateSelected = parseInt(aData[i], 10)
						tokensChanged ++
					}
					else if	((aFormat[i]=="m") || (aFormat[i]=="mm"))
					{
						monthSelected =	parseInt(aData[i], 10) - 1
						tokensChanged ++
					}
					else if	(aFormat[i]=="yyyy")
					{
						yearSelected = parseInt(aData[i], 10)
						tokensChanged ++
					}
					else if	(aFormat[i]=="mmm")
					{
						for	(j=0; j<12;	j++)
						{
							if (aData[i]==monthName[j])
							{
								monthSelected=j
								tokensChanged ++
							}
						}
					}
				}
			}

			if ((tokensChanged!=3)||isNaN(dateSelected)||isNaN(monthSelected)||isNaN(yearSelected))
			{
				dateSelected = dateNow
				monthSelected =	monthNow
				yearSelected = yearNow
			}

			odateSelected=dateSelected
			omonthSelected=monthSelected
			oyearSelected=yearSelected

			aTag = ctl
			do {
				aTag = aTag.offsetParent;
				if (aTag)
				{
				leftpos	+= aTag.offsetLeft;
				toppos += aTag.offsetTop;
				}
			} while(aTag && aTag.tagName!="BODY");

			crossobj.left =	fixedX==-1 ? ctl.offsetLeft	+ leftpos :	fixedX
			crossobj.top = fixedY==-1 ?	ctl.offsetTop +	toppos + ctl.offsetHeight +	2 :	fixedY
			
			constructCalendar (1, monthSelected, yearSelected);
			crossobj.visibility=(dom||ie)? "visible" : "show"
			
			oDivCalendarPosition = getPosition( document.getElementById("calendar") );
			
			if ((removePx(crossobj.top) + oDivCalendarPosition.height) - getScrollingDistanceVertical() >= getScreenHeight())
			{
				// The calendar position is too low, reposition it on top of the button if possible
				toppos = removePx(crossobj.top) - oDivCalendarPosition.height - ctl.offsetHeight - 2;
				if (toppos >= 0)
				{
					crossobj.top = toppos;
				}
			}
			
			if ((removePx(crossobj.left) + oDivCalendarPosition.width) - getScrollingDistanceHorizontal() >= getScreenWidth())
			{
				// The calendar position is too far on the right, reposition it on left of the button if possible
				leftpos = removePx(crossobj.left) - oDivCalendarPosition.width;
				if (leftpos >= 0)
				{
					crossobj.left = leftpos;
				}
			}
			
			setCalendarIFrame();
		
			hideElement( 'SELECT', document.getElementById("calendar") );
			hideElement( 'APPLET', document.getElementById("calendar") );			

			bShow = true;
		}
		else
		{
			hideCalendar()
			if (ctlNow!=ctl) {popUpCalendar(ctl, ctl2, format, language)}
		}
		ctlNow = ctl
	}
}

function setCalendarIFrame()
{
	var oCalendarIFrame;
	var oDivCalendarPosition;
	
	oCalendarIFrame = document.getElementById("oCalendarIFrame");	
	oDivCalendarPosition = getPosition( document.getElementById("calendar"));
			
	oCalendarIFrame.style.left = crossobj.left;
	oCalendarIFrame.style.top = crossobj.top;
	
	oCalendarIFrame.style.height = oDivCalendarPosition.height;
	oCalendarIFrame.style.width = oDivCalendarPosition.width;
	
	oCalendarIFrame.style.position = "absolute";
	oCalendarIFrame.style.display = "block";
}

// End of Calendar
/******************************************************************************************/




/******************************************************************************************/
// Validations

var consCultureFrCa = "fr-CA";
var consCultureFrFr = "fr-FR";
var consCultureEnCa = "en-CA";
var consCultureEnUs = "en-US";
var consCultureEnGb = "en-GB";
var consCultureEsEs = "es-ES";
var consCultureEsMx = "es-MX";
var consCultureItIt = "it-IT";
var consCultureDeDe = "de-DE";
       
function handleBlur(voObject)
{
  doInit(voObject);
  doOnBlur(voObject);
}

function handleFocus(voObject)
{
  doInit(voObject);
  doOnFocus(voObject);
}

function onBlurMethod(voObject)
{
	doOnBlur(voObject);
}

function SetValidators(voObject)
{
  if (voObject.getAttribute("Required") == "True")
  {
    document.getElementById(voObject.getAttribute("parentId") + "_oReqValidator").isvalid = true;
  }
  document.getElementById(voObject.getAttribute("parentId") + "_oRegExValidator").isvalid = true;
  doOnBlur(voObject);
}

function doInit(voObject)
{
  var id = new String();
 
  id = voObject.id;

	voObject.setAttribute("parentId", id.substring(0, voObject.id.lastIndexOf("_")));
}

function doOnFocus(voObject)
{
	if (voObject.getAttribute("ToolTipMsg") != null || voObject.getAttribute("ToolTipValidationMessage") == "True")
	{
		voObject.setAttribute("ValidationMessage", getValidationMessage(voObject));
		
		if (voObject.getAttribute("ValidationMessage") != "")
		{
			doTooltip(voObject,event, voObject.getAttribute("ValidationMessage"));
			if (voObject.getAttribute("ToolTipDelay") == "True")
				voObject.setAttribute("TimeoutId", setTimeout(hideTip(voObject), voObject.getAttribute("ToolTipDelayTime")));
		}
		else if (voObject.getAttribute("ToolTipMsg") != null)
		{
			doTooltip(voObject,event, voObject.getAttribute("ToolTipMsg"));
			if (voObject.getAttribute("ToolTipDelay") == "True")
				voObject.setAttribute("TimeoutId", setTimeout(hideTip(voObject), voObject.getAttribute("ToolTipDelayTime")));
		}
	}
}

function doOnBlur(voObject)
{
	if (voObject.value != null && voObject.value.length > 0)
	{
		chooseFormating(voObject);
	}
	else
	{
		if (voObject.getAttribute("Required") == "False" && voObject.getAttribute("ExtOptional") == "False" && voObject.getAttribute("ValidationType") == "phoneExt")
		{
			if (document.getElementById(voObject.id + "ReqExtValidator") != null)
			{
				document.getElementById(voObject.id + "ReqExtValidator").enabled = false;
				document.getElementById(voObject.id + "ReqExtValidator").disabled = true;
			}	
		}
		
		if (voObject.getAttribute("Required") == "False" && voObject.id.indexOf("txtExt") != -1)
		{
			if (document.getElementById(voObject.id.replace("txtExt","oReqValidator")) != null)
			{
				document.getElementById(voObject.id.replace("txtExt","oReqValidator")).disabled = true;
				document.getElementById(voObject.id.replace("txtExt","oReqValidator")).enabled = false;
			}
			onBlurMethod(document.getElementById(voObject.id.replace("txtExt","txt")));
		}
	}
	
	if (document.getElementById(voObject.id + "_tooltip") != null)
	{
		if (document.getElementById(voObject.id + "_tooltip").style.display == "inline")
		{
			clearTimeout(voObject.TimeoutId);
			hideTip(voObject);
		}
	}
	
	return SetOnBlurStyle(voObject);
}

function SetOnBlurStyle(voObject)
{
  var id = new String();

  var bReqValid = true;
	var bRegExValid = true;
	var bRangeValid = true;
	var bCompareValid = true;
	var bDefaultReqValid = true;
	var sReqValidName = "_oReqValidator";
	var sRegExValidName = "_oRegExValidator";
	var sRangeValidName = "_RangeValidator";
	var sCompareValidName = "_CompareValidator";
	var sDefaultReqValidName = "_ReqValidator";
	
	id = voObject.id;
	
	if (id.indexOf("txtExt") != -1)
	{
	  sReqValidName = "_txtReqExtValidator";
	  sRegExValidName = "_oRegExtValidator";
	}
	
  if (document.getElementById(voObject.getAttribute("parentId") + sReqValidName) != null)
	{
	 if (!document.getElementById(voObject.getAttribute("parentId") + sReqValidName).isvalid && !document.getElementById(voObject.getAttribute("parentId") + sReqValidName).disabled && document.getElementById(voObject.getAttribute("parentId") + sReqValidName).controltovalidate == voObject.id)
	  {
		  bReqValid = false;
	  }
	}
  	
	if (document.getElementById(voObject.getAttribute("parentId") + sRegExValidName) != null)
	{
	  if (!document.getElementById(voObject.getAttribute("parentId") + sRegExValidName).isvalid && !document.getElementById(voObject.getAttribute("parentId") + sRegExValidName).disabled && document.getElementById(voObject.getAttribute("parentId") + sRegExValidName).controltovalidate == voObject.id)
	  {
  	  bRegExValid = false;
	  }
	}
	
	if (document.getElementById(voObject.getAttribute("parentId") + sRangeValidName) != null)
	{
	  if (!document.getElementById(voObject.getAttribute("parentId") + sRangeValidName).disabled && document.getElementById(voObject.getAttribute("parentId") + sRangeValidName).controltovalidate == voObject.id)
	  {
			ValidatorValidate(document.getElementById(voObject.getAttribute("parentId") + sRangeValidName));
			if (!document.getElementById(voObject.getAttribute("parentId") + sRangeValidName).isvalid)
			{
  			bRangeValid = false;
  		}
	  }
	}
	
	if (document.getElementById(voObject.getAttribute("parentId") + sCompareValidName) != null)
	{			
	  if (!document.getElementById(voObject.getAttribute("parentId") + sCompareValidName).disabled && document.getElementById(voObject.getAttribute("parentId") + sCompareValidName).controltovalidate == voObject.id)
	  {
			ValidatorValidate(document.getElementById(voObject.getAttribute("parentId") + sCompareValidName));
			if (!document.getElementById(voObject.getAttribute("parentId") + sCompareValidName).isvalid)
			{
  			bCompareValid = false;
  		}
	  }
	}
	
	if (document.getElementById(voObject.id + sDefaultReqValidName) != null)
	{
	  if (!document.getElementById(voObject.id + sDefaultReqValidName).isvalid && !document.getElementById(voObject.id + sDefaultReqValidName).disabled && document.getElementById(voObject.id + sDefaultReqValidName).controltovalidate == voObject.id)
	  {
  	  bDefaultReqValid = false;
	  }
	}
	if (!bReqValid)
	{
		ApplyInvalidValueStyle(voObject, getRequiredMessage(voObject));
		return false;
	}
	else if (!bRegExValid || !bRangeValid || !bCompareValid || !bDefaultReqValid)
	{
		ApplyInvalidValueStyle(voObject, getValidationMessage(voObject));
		return false;
	}
	else
	{
	  if(!voObject.readOnly)
	  {
			ApplyValidValueStyle(voObject);	  
		  return true;
		}
		else{
		  return true;
		}
	}
}

function FormatColorName(sColor)
{
	if (sColor.substr(0, 2) == "ff")
		return sColor.substr(2);
	else
		return sColor;
}

function ApplyInvalidValueStyle(voObject, vsMessage)
{
	voObject.className = voObject.getAttribute("ErrorCssClass");

	if (vsMessage)
	{
		popMessage(voObject, vsMessage);
	}
}

function ApplyValidValueStyle(voObject)
{
	voObject.className = voObject.getAttribute("CssClass");
	hideMessage(voObject);
}

function getValidationMessage(voObject)
{
	return voObject.getAttribute("ValidationMessage");
}

function getRequiredMessage(voObject)
{
	return voObject.getAttribute("RequiredMessage");
}

function chooseFormating(voObject)
{
	switch(voObject.getAttribute("ValidationType"))
  {
    case "Phone"            :
        voObject.value = MaskPhone(voObject,voObject.value);
        break;
    case "PhoneExt"            :
        voObject.value = MaskPhone(voObject,voObject.value);
        break;
    case "ZipPostal"            :
        voObject.value = MaskZipPostal(voObject,voObject.value);
        break;
    case "Currency"            :
        voObject.value = MaskCurrency(voObject,voObject.value);
        break;
    case "Numeric"            :
        voObject.value = MaskNumeric(voObject,voObject.value);
        break;
    case "DateType"            :
        voObject.value = MaskDateType(voObject,voObject.value);
        break;
    case "Email"            :
        voObject.value = MaskEmail(voObject,voObject.value);
        break;
    case "Url"            :
			  voObject.value = MaskURL(voObject,voObject.value);
			  break;
	  case "RegEx" :
			  voObject.value = MaskRegEx(voObject,voObject.value);
        break;
    case "Time" :
				voObject.value = MaskTime(voObject, voObject.value);
   }
}

function MaskRegEx(voObject,sValue)
{
	var RegEx = new RegExp(voObject.getAttribute("ValidationRegEx"));
	
	if (!RegEx.test(sValue))
	{
		ApplyInvalidValueStyle(voObject);
	}
	
	return sValue;
}

function MaskPhone(voObject,sValue)
{
  if (voObject.getAttribute("Country") == "CA" || voObject.getAttribute("Country") == "US")
	{
		var sValueTmp = GetNumbersOnly(voObject,sValue);
		if (sValueTmp.length == 7  && voObject.getAttribute("AreaCodeOptional") == "True")
		{
			sValue = AddDashToPhone(voObject,sValueTmp);
			ActivateExtReqValidator(voObject);
		}
		else if (sValueTmp.length == 10)
		{
			sValueTmp = AddDashToPhone(voObject,sValueTmp);
			sValue = AddParenthesistoPhone(voObject,sValueTmp);
			ActivateExtReqValidator(voObject);
		}
		else
		{
			ApplyInvalidValueStyle(voObject);
		}
	}
	else
	{
		var sValueTmp = GetNumbersOnly(voObject,sValue);
		if (sValueTmp.length == 10)
		{
			sValueTmp = AddDashToPhone(voObject,sValueTmp);
			sValue = AddParenthesistoPhone(voObject,sValueTmp);
		}
	  ActivateExtReqValidator(voObject);
	}
	return sValue;
}

function ActivateExtReqValidator(voObject)
{
  if (voObject.getAttribute("Required") == "False" && voObject.getAttribute("ExtOptional") == "False" && voObject.getAttribute("ValidationType") == "phoneExt")
	{
    document.getElementById(voObject.id + "ReqExtValidator").enabled = true;
    document.getElementById(voObject.id + "ReqExtValidator").disabled = false;
  }
}

function MaskZipPostal(voObject,sValue)
{
	var sValueTmp = sValue;
	
	if (voObject.getAttribute("Country") == "CA")
	{
		var RegExCa = /^[A-Z]\d[A-Z]\d[A-Z]\d$/;
	
		sValueTmp = sValueTmp.toUpperCase();
		sValueTmp = ReplaceAll(sValueTmp, " ", "");
		
		if (!RegExCa.test(sValueTmp))
			ApplyInvalidValueStyle(voObject);
		else
			sValue = sValueTmp.substring(0, 3) + " " + sValueTmp.substring(3, sValueTmp.length)
	}
	else if (voObject.getAttribute("Country") == "US")
	{
		var RegExUs = /^\d{5}(\d{4})?$/;
		
		sValueTmp = ReplaceAll(sValue, "-", "");
		
		if (!RegExUs.test(sValueTmp))
		{
			ApplyInvalidValueStyle(voObject);
	}
		else if (sValueTmp.length == 9)
		{
		  sValue = sValueTmp.substring(0, 5) + "-" + sValueTmp.substring(5, sValueTmp.length);
		}  
	}
	
	return sValue;
}

function MaskCurrency(voObject,sValue)
{
	var bIsNegative = false;
	
	var sCulture = voObject.getAttribute("Culture");
		
	sValueTmp = sValue;
		
	sValueTmp = ReplaceAll(sValue, ",", ".");
	
	if (sValueTmp.indexOf("-") == 0)
	{
		bIsNegative = true;
		sValueTmp = sValueTmp.substr(1);
	}
	
	if (voObject.getAttribute("Country") == "CA" && sValueTmp.indexOf("$") == sValueTmp.length - 1)
	{
		sValueTmp = sValueTmp.substring(0, sValueTmp.indexOf("$") - 1);
	}
	else if (voObject.getAttribute("Country") == "US" && sValueTmp.indexOf("$") == 0)
	{
		sValueTmp = sValueTmp.substring(1);
	}
		
	if (CheckNumericCurrencyValue(voObject,sValueTmp))
	{
		sValue = AdjustDecimal(voObject,sValueTmp);
		// a modifier selon le pays
		if (voObject.getAttribute("Country") == "CA")
			sValue += " $";
		else if (voObject.getAttribute("Country") == "US")
			sValue = "$" + sValue;
	}
	else
		ApplyInvalidValueStyle(voObject);
		
	if (bIsNegative)
	{
		sValue = "-" + sValue;
	}
	
	if (sCulture == consCultureFrCa || sCulture == consCultureFrFr || sCulture == consCultureEsEs || sCulture == consCultureItIt || sCulture == consCultureDeDe)
	  return ReplaceAll(sValue, ".", ",");
	else
	  return sValue;
}

function MaskNumeric(voObject,sValue)
{
	sValueTmp = sValue;
	sValueTmp = ReplaceAll(sValue, ",", ".");
	
	var sCulture = voObject.getAttribute("Culture");
		
	if (CheckNumericCurrencyValue(voObject,sValueTmp))
	{
	  sValue = AdjustDecimal(voObject,sValueTmp);
	  if (voObject.getAttribute("Required") == "False" && voObject.id.indexOf("txtExt") != -1)
	  {
			if (document.getElementById(voObject.id.replace("txtExt","oReqValidator")) != null )
			{
				document.getElementById(voObject.id.replace("txtExt","oReqValidator")).disabled = false;
			}
			if (document.getElementById(voObject.id.replace("txtExt","oReqValidator")) != null )
			{
				document.getElementById(voObject.id.replace("txtExt","oReqValidator")).enabled = true;
	    }
	  }
	}
	else
		ApplyInvalidValueStyle(voObject);
	
	if (sCulture == consCultureFrCa || sCulture == consCultureFrFr || sCulture == consCultureEsEs || sCulture == consCultureItIt || sCulture == consCultureDeDe)
	  return ReplaceAll(sValue, ".", ",");
	else
	  return sValue;
}

function GetTxtNameFromTxtExt(voObject)
{
  return voObject.id.substr(0, voObject.id.length - 3);
}

function MaskDateType(voObject,sValue)
{
	var RegExDateDDMMYYYY = /^(((0[1-9]|[12][0-9]|30)[/](0[469]|11))|((0[1-9]|[12][0-9]|3[01])[/](0[13578]|1[02]))|((0[1-9]|[12][0-9])[/][0][2]))[/]\d{4}$/;
	var RegExDateMMDDYYYY = /^(((0[469]|11)[/](0[1-9]|[12][0-9]|30))|((0[13578]|1[02])[/](0[1-9]|[12][0-9]|3[01]))|([0][2][/](0[1-9]|[12][0-9])))[/]\d{4}$/;
	var RegExDateInt = /^\d{4}[/](((0[469]|11)[/](0[1-9]|[12][0-9]|30))|((0[13578]|1[02])[/](0[1-9]|[12][0-9]|3[01]))|([0][2][/](0[1-9]|[12][0-9])))$/;
	var RegExDateIntNoDash = /^\d{4}(((0[469]|11)(0[1-9]|[12][0-9]|30))|((0[13578]|1[02])(0[1-9]|[12][0-9]|3[01]))|([0][2](0[1-9]|[12][0-9])))$/;
			
	var	sValueTmp = sValue;
	
	var sCulture = voObject.getAttribute("Culture");
	
	sValueTmp = ReplaceAll(sValue, "-", "/");
			
	if ((sCulture == consCultureFrFr || sCulture == consCultureEnCa || sCulture == consCultureEnGb || sCulture == consCultureEsEs || sCulture == consCultureEsMx || sCulture == consCultureItIt || sCulture == consCultureDeDe) && RegExDateDDMMYYYY.test(sValueTmp))
	{
		return sValueTmp;
	}
	else if (sCulture == consCultureEnUs && RegExDateMMDDYYYY.test(sValueTmp))
	{
		return sValueTmp;
	}
	else if (sCulture == consCultureFrCa && RegExDateInt.test(sValueTmp))
	{
		return sValueTmp;
	}
	else if (sCulture == consCultureFrCa && RegExDateDDMMYYYY.test(sValueTmp))
	{
		return FormatFrToInt(voObject,sValueTmp);
	}
	else if (RegExDateInt.test(sValueTmp) || RegExDateIntNoDash.test(sValueTmp))
	{
		return FormatIntDate(voObject,sValueTmp);
	}
	else
	{
		ApplyInvalidValueStyle(voObject);
		return sValue;
	}
}

function MaskTime(voObject, sValue)
{
	if (sValue != "")
	{
		if (parseInt(sValue) < 10 && sValue.length < 2)
		{
			return "0" + sValue;
		}
		else
		{
			return sValue;
		}
	}
	else
	{
		return sValue;
	}
}

function FormatFrToInt(voObject,sDateValue)
{
  var sYear, sMonth, sDay;
  
  sDateValue = ReplaceAll(sDateValue, "/", "");
			
	sYear = sDateValue.substr(4,4);
	sMonth = sDateValue.substr(2,2);
	sDay = sDateValue.substr(0,2);
	
	return sYear + "/" + sMonth + "/" + sDay;
}

function FormatIntDate(voObject,sDateValue)
{
  var sYear, sMonth, sDay;
  
	var sCulture = voObject.getAttribute("Culture");
  
  sDateValue = ReplaceAll(sDateValue, "/", "");
			
	sYear = sDateValue.substr(0,4);
	sMonth = sDateValue.substr(4,2);
	sDay = sDateValue.substr(6,2);
	
	if (sCulture == consCultureFrFr || sCulture == consCultureEnCa || sCulture == consCultureEnGb || sCulture == consCultureEsEs || sCulture == consCultureEsMx || sCulture == consCultureItIt || sCulture == consCultureDeDe)
	{
		return sDay + "/" + sMonth + "/" + sYear;
	}
	else if (sCulture == consCultureEnUs)
	{
		return sMonth + "/" + sDay + "/" + sYear;
	}
	else if (sCulture == consCultureFrCa)
	{
		return sYear + "/" + sMonth + "/" + sDay;
	}
	else
	{
		return sYear + "/" + sMonth + "/" + sDay;
	}
}

function MaskEmail(voObject,sValue)
{	
	var sRegExValidName = "_oRegExValidator";
	var RegExEmail = /^([\w\d\-\.]+)@{1}(([\w\d\-]{1,67})|([\w\d\-]+\.[\w\d\-]{1,67}))\.(([a-zA-Z\d]{2,4})(\.[a-zA-Z\d]{2})?)(;(([\w\d\-\.]+)@{1}(([\w\d\-]{1,67})|([\w\d\-]+\.[\w\d\-]{1,67}))\.(([a-zA-Z\d]{2,4})(\.[a-zA-Z\d]{2})?)))*$/;
	
	sValue = ReplaceAll(sValue, " ", "");
	
	if (!RegExEmail.test(sValue))
	{
		ApplyInvalidValueStyle(voObject);
	}
	else
	{
		// Set the validator to valid, prevend the validator to be invalid when a space is trimed in the field
		document.getElementById(voObject.getAttribute("parentId") + sRegExValidName).isvalid = true;
	}
		
	return sValue;
}

function MaskURL(voObject,sValue)
{
	var RegExHttp = /(http|https):\/\/([\w-]+\.)+[\w-]+([\w- ./?%&=]*)?/;
	var RegExLastChar = /([A-Za-z]|\d)|[/]/
	var sValueTmp = sValue
	
	if (!RegExHttp.test(sValueTmp) || !RegExLastChar.test(sValueTmp.charAt(sValueTmp.length - 1)))
	{
		sValueTmp = "http://" + sValueTmp;
		if (!RegExHttp.test(sValueTmp) || !RegExLastChar.test(sValueTmp.charAt(sValueTmp.length - 1)))
		{
			ApplyInvalidValueStyle(voObject);
		}
		else
		{
			sValue = sValueTmp
		}
	}	
	return sValue;
}

function GetNumbersOnly(voObject,sValue)
{
	var sFormattedValue = "";
	
	for (var i = 0; i < sValue.length; i++)
	{
		if (sValue.charCodeAt(i) >= 48 && sValue.charCodeAt(i) <= 57)
		{
			sFormattedValue += sValue.charAt(i)
		}
	}
	return sFormattedValue;
}

function FillWithZeros(voObject,sValue, iLength)
{
	while (sValue.length < iLength)
	{
		sValue += "0";
	}
	return sValue;
}

function AddDashToPhone(voObject,sValue)
{
	var sFirstPart = sValue.substring(0, sValue.length - 4);
	var sLastPart = sValue.substring(sValue.length - 4, sValue.length);
		
	return sFirstPart + "-" + sLastPart;
}

function AddParenthesistoPhone(voObject,sValue)
{
	var sFirstPart = sValue.substring(0, 3);
	var sLastPart = sValue.substring(3, sValue.length);
	
	return "(" + sFirstPart + ") " + sLastPart;
}

function ReplaceAll(sValue, sOldString, sNewString)
{
	while (sValue.indexOf(sOldString) != -1)
		sValue = sValue.replace(sOldString, sNewString);
		
	return sValue;
}

function CheckNumericCurrencyValue(voObject,sValue)
{
	var iNbSeparateur = 0;
	var bOk = true
	
	for (var i = 0; i < sValue.length; i++)
	{
		if ((sValue.charCodeAt(i) < 48 || sValue.charCodeAt(i) > 57) && sValue.charCodeAt(i) != 46 && sValue.charCodeAt(i) != 45)
		{
			bOk = false;
		}
		else if (sValue.charCodeAt(i) == 45 && i != 0)
		{
			bOk = false;
		}
		else if (sValue.charCodeAt(i) == 46)
		{
			iNbSeparateur++;
			
			if (iNbSeparateur > 1)
			{
				bOk = false;
			}
		}
	}
	return bOk;
}

function AdjustDecimal(voObject,sValue)
{
	var DecimalLength;
	var bIsNegative = false;
	
	var iDecimalPrecision = voObject.getAttribute("DecimalPrecision");
	var iDecimalLength;
	
	if (sValue.indexOf("-") == 0)
	{
		bIsNegative = true;
		sValue = sValue.substr(1);
	}
	
	if (sValue.indexOf(".") == 0)
		sValue = "0" + sValue;


	if (iDecimalPrecision > 0 && sValue.indexOf(".") == -1 && voObject.getAttribute("FillDecimal") == "True")
	{
		if (!voObject.getAttribute("maxlength") || parseInt(sValue.length) + parseInt(iDecimalPrecision) < voObject.getAttribute("maxlength"))
		{
		sValue += ".";
		for (var i=0; i < iDecimalPrecision; i++)
		{
			sValue += "0";
		}
	}
	}
	else if (iDecimalPrecision > 0 && sValue.indexOf(".") != -1)
	{
		voObject.setAttribute("DecimalLength", (sValue.length - 1) - sValue.indexOf("."));
		iDecimalLength = voObject.getAttribute("DecimalLength");
				
		if (iDecimalLength < iDecimalPrecision && voObject.getAttribute("FillDecimal") == "True")
		{
			for (var j=iDecimalLength; j < iDecimalPrecision; j++)
			{
				sValue += "0";
			}
		}
		else if (iDecimalLength > iDecimalPrecision)
		{
		  
			sValue = sValue.substring(0, sValue.indexOf(".") + parseInt(iDecimalPrecision) + 1);
		}
	}
	else if (sValue.indexOf(".") != -1)
	{
		sValue = sValue.substring(0, sValue.indexOf("."));
	}
	
	if (bIsNegative)
	{
		sValue = "-" + sValue;
	}
		
	return sValue
}

function calendarDefined()
{
	var oControls = document.getElementsByTagName("INPUT");
	for (var i = 0; i < oControls.length; i++)
	{
		if (oControls[i].getAttribute("isKce") == "true" && oControls[i].getAttribute("isCalendar") == "true")
		{
			return true;
		}
	}
	return false;	
}


// End of Validations
/******************************************************************************************/

/******************************************************************************************/
// Validation Popup Message

function initPopupMessage()
{
	var sPopupMessage = "";
	if (!document.getElementById("oPopupMessageIFrame"))
	{
		if (pageContainValidationTextBox())
		{
		
			if (dom)
			{
				if (typeof document.body.style.maxHeight == "undefined") //This condition return True in IE6 and less
				{
					// This is a trick for IE6 and less to pop the div on top of window control ex: DropDown. This iframe is not required in modern browsers.
					sPopupMessage = "<iframe id='oPopupMessageIFrame' style='display:none;left:0px;position:absolute;top:0px' src='" + imgDirValidation + "dummy.htm" + "' frameBorder='0' scrolling='no'></iframe>";	
				}
			  sPopupMessage += "<div id='oPopupMessageDiv' class='ErrorMessageDiv' style='display:none;width:auto;height:auto;left:0px;right:0px;position:absolute;zIndex:100;background-position:top right;background-repeat:no-repeat;'>";
				sPopupMessage += "<div class='ErrorMessageTable'><div class='ErrorMessageTd'></div></div>";
				sPopupMessage += "</div>";
			}
			
			document.getElementById("spanPopupMessage").innerHTML = sPopupMessage;
		}
	}
}

function popMessage(voTextBox, vsMessage)
{
	var oSourceDiv;
	var oSourceIFrame;
	var oDiv;
	var oIFrame;
	
	if (isVisible(voTextBox))
	{
	  initPopupMessage();
  	
	  oDiv = document.getElementById("oPopupMessageDiv" + voTextBox.id);
	  oIFrame = document.getElementById("oPopupMessageIFrame" + voTextBox.id);
  	
	  if (!oDiv)
	  {
		  oSourceDiv = document.getElementById("oPopupMessageDiv");
		  oSourceIFrame = document.getElementById("oPopupMessageIFrame");
  		
		  oDiv = oSourceDiv.cloneNode(true);
		  oDiv.id += voTextBox.id;
		  document.body.appendChild(oDiv);
  		
		  // IE6 only
		  if (oSourceIFrame)
		  {
			  oIFrame = oSourceIFrame.cloneNode(true);
			  oIFrame.id += voTextBox.id;
			  document.body.appendChild(oIFrame);
		  }
	  }	
  	
	  popMessageDiv(voTextBox, oDiv, oIFrame, vsMessage);
	}
}

function popMessageDiv(voTextBox, voDiv, voIFrame, vsMessage)
{
	var setDivDistanceX;
	var setDivDistanceY = 4;
	
	var textBoxHeight = voTextBox.offsetHeight;
	
	setDivDistanceX = Math.floor(voTextBox.offsetWidth / 3);
	
	// Put the message in the popup div
	if (vsMessage && vsMessage != "")
	{
		voDiv.childNodes[0].childNodes[0].innerHTML = vsMessage;
	}
	
	initCssClass(voDiv, voIFrame);
			
	getPos(voTextBox);
	setPos(voTextBox, voDiv, setDivDistanceX, setDivDistanceY, textBoxHeight);
	
	// IE6 only
	if (voIFrame)
	{
		setCssIFrame(voIFrame, voDiv);
	}
}

function hideMessage(voTextBox)
{
	var oDiv;
	var oIFrame;
	
	oDiv = document.getElementById("oPopupMessageDiv" + voTextBox.id);
	oIFrame = document.getElementById("oPopupMessageIFrame" + voTextBox.id);
	
	if (oDiv)
	{
		hideMessageDiv(voTextBox, oDiv, oIFrame);
	}
}

function hideMessageDiv(voTextBox, voDiv, voIFrame)
{
	initCssClass(voDiv, voIFrame);
}

function setCssIFrame(voIFrame, voDiv)
{
		voIFrame.style.width = voDiv.offsetWidth;
    voIFrame.style.height = voDiv.offsetHeight - 5;
    voIFrame.style.top = removePx(voDiv.style.top) + 5;
    voIFrame.style.left = removePx(voDiv.style.left) + 5;
    voIFrame.style.zIndex = voDiv.style.zIndex - 1;
    voIFrame.style.position = "absolute";
    voIFrame.style.display = "block";
    voIFrame.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
}

function getPos(elementFrom){
	if (document.getBoxObjectFor) {
		//**** FIREFOX ****	
		var boxObject = document.getBoxObjectFor(elementFrom);
		elementFrom.x = boxObject.x;
		elementFrom.y = boxObject.y;
	}
	else
	{
		//**** IE ****
		var clientRect = elementFrom.getBoundingClientRect();
		elementFrom.x = clientRect.left;
		elementFrom.y = clientRect.top;
	}
}

function setPos(elementFrom, divTo, divPosX, divPosY, textBoxHeight)
{ 
  setInitCssClassVisible(divTo);
  
	divHeight = getDivHeight(divTo.childNodes[0].childNodes[0]);
	divWidth = getDivWidth(divTo.childNodes[0].childNodes[0]);
	setInitCssClass(divTo, divHeight, divWidth);
	
	if (document.getBoxObjectFor){
		//**** FIREFOX ****	
		if((elementFrom.x + divPosX + getDivWidth(divTo)) >= getScreenWidth()){
			// Element colle a droite du browser
			divTo.style.left = (elementFrom.x - divPosX) + "px";
			divTo.style.top = (elementFrom.y + divPosY + textBoxHeight - 4) + "px";
			divTo.style.backgroundImage="url(" + imgDirValidation + "cTR.gif)";
			divTo.style.backgroundPosition="top right";
		}else{
			// Element colle a gauche du browser
			divTo.style.left = (elementFrom.x + divPosX) + "px";// - 105;
			divTo.style.top = (elementFrom.y + divPosY + textBoxHeight - 4) + "px";
			divTo.style.backgroundImage="url(" + imgDirValidation + "cTL.gif)";
			divTo.style.backgroundPosition="top left";
		}
	}
	else 
	{
		//**** IE ****
		if((elementFrom.x + divPosX + getDivWidth(divTo)) >= getScreenWidth()){
			// Element colle a droite du browser
			divTo.style.pixelLeft = elementFrom.x - divPosX;
			divTo.style.pixelTop = elementFrom.y + divPosY + textBoxHeight + getScrollingDistanceVertical() - 4;
			divTo.style.backgroundImage="url(" + imgDirValidation + "cTR.gif)";
			divTo.style.backgroundPosition="top right";
		}else{
			// Element colle a gauche du browser
			divTo.style.pixelLeft = elementFrom.x + divPosX;// - 105;
			divTo.style.pixelTop = elementFrom.y + divPosY + textBoxHeight + getScrollingDistanceVertical() - 4;
			divTo.style.backgroundImage="url(" + imgDirValidation + "cTL.gif)";
			divTo.style.backgroundPosition="top left";
		}
	}
}

function getScrollingDistanceVertical()
{
	if (document.body && document.body.scrollTop && document.body.scrollTop > 0)
	{
		// Page don't use doctype and has scroll
		return (parseInt(document.body.scrollTop));
	}
	else if(document.documentElement && document.documentElement.scrollTop && document.documentElement.scrollTop > 0)
	{
		// Page use doctype and has scroll
		return (parseInt(document.documentElement.scrollTop));
	}
	else
	{
		// Page don't scroll
		return 0;
	}
}

function getScrollingDistanceHorizontal()
{
	if (document.body && document.body.scrollLeft && document.body.scrollLeft > 0)
	{
		// Page don't use doctype and has scroll
		return (parseInt(document.body.scrollLeft));
	}
	else if(document.documentElement && document.documentElement.scrollLeft && document.documentElement.scrollLeft > 0)
	{
		// Page use doctype and has scroll
		return (parseInt(document.documentElement.scrollLeft));
	}
	else
	{
		// Page don't scroll
		return 0;
	}
}

function isVisible(obj)
{    
  if (obj == document) return true;  
  if (!obj) return false;    
  if (!obj.parentNode) return false;    
  if (obj.style) 
  {        
    if (obj.style.display == 'none') return false;
    if (obj.style.visibility == 'hidden') return false;
  }     
  
  //Try the computed style in a standard way    
  if (window.getComputedStyle) 
  {        
    var style = window.getComputedStyle(obj, "");
    if (style.display == 'none') return false;
    if (style.visibility == 'hidden') return false;
  }     
  
  //Or get the computed style using IE's silly proprietary way    
  var style = obj.currentStyle;
  if (style) 
  {        
    if (style['display'] == 'none') return false;
    if (style['visibility'] == 'hidden') return false;
  }     
  
  return isVisible(obj.parentNode);
}

function getScreenHeight()
{
	return (parseInt(truebody().offsetHeight));
}

function getScreenWidth()
{
	return (parseInt(truebody().offsetWidth));
}

function getDivHeight(divFrom)
{
	return (parseInt(divFrom.offsetHeight));
}

function getDivWidth(divFrom)
{
  return (parseInt(divFrom.offsetWidth));
}

function truebody()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function setInitCssClass(divFrom,divHeight,divWidth)
{
	divFrom.style.position = "absolute"
	divFrom.style.zIndex = 10000;
	divFrom.style.height = divHeight + "px";
	divFrom.style.width = divWidth + "px";
}

function setInitCssClassVisible(divFrom)
{
	divFrom.style.display = "inline";
}

function initCssClass(divFrom, oIFrame)
{
	divFrom.style.display = "none";
	
	divFrom.style.zIndex = 100;
	divFrom.style.backgroundPosition = "top right";
	divFrom.style.backgroundRepeat = "no-repeat";

	// IE6 only	
	if (oIFrame)
	{
		oIFrame.style.display = "none";
		oIFrame.style.left = "0px";
		oIFrame.style.top = "0px";
		oIFrame.style.bottom = "0px";
		oIFrame.style.right = "0px";
		oIFrame.style.zIndex = 100;
	}
}

// Return an object with properties: x, y, width, height
function getPosition(el)
{
	var oDimension = new Object();
	if(el.getBoundingClientRect)
	{
		oDimension.x = el.getBoundingClientRect().left + Math.max(document.body.scrollLeft, document.documentElement.scrollLeft);
		oDimension.y = el.getBoundingClientRect().top + Math.max(document.body.scrollTop, document.documentElement.scrollTop);
		oDimension.width = el.getBoundingClientRect().right - el.getBoundingClientRect().left;
		oDimension.height =  el.getBoundingClientRect().bottom - el.getBoundingClientRect().top;
	}
	else if(document.getBoxObjectFor)
	{
    oDimension.x = document.getBoxObjectFor(el).x;
	  oDimension.y =  document.getBoxObjectFor(el).y;
	  oDimension.width = document.getBoxObjectFor(el).width;
	  oDimension.height = document.getBoxObjectFor(el).height;
	}

	return oDimension;
}

function removePx(vsString)
{
	return parseInt(vsString.substr(0,vsString.length - 2)); // remove "px"
}

function setFocusToNextElement(voIdControlFrom)
{
	var evt = window.event;
	var oControlFrom = document.getElementById(voIdControlFrom);
	var oControlToFocus;
	
	if (evt.keyCode == 0 && evt.shiftKey)
	{
		oControlToFocus = findPreviousElement(oControlFrom)
	}
	else
	{
		oControlToFocus = findNextElement(oControlFrom)	
	}
	

	if (oControlToFocus)
	{
		try
		{
			oControlToFocus.focus();
			oControlToFocus.select();
		}
		catch (e)
		{
			// The control is possibly not visible so focus cannot be set
		}
	}
}

// Return the next element to focus on
function findNextElement (field) 
{ 
  var form = document.forms[0];
  for (var i = 0; i < form.elements.length; i++) 
    if (field == form.elements[i]) 
      break; 
  i = ++i % form.elements.length; 
  return form.elements[i];
}

// Return the previous element to focus on
function findPreviousElement (field) 
{ 
  var form = document.forms[0];
  for (var i = 0; i < form.elements.length; i++) 
    if (field == form.elements[i]) 
      break; 
  i = ++i % form.elements.length; 
  return form.elements[i - 1]; 
} 

// End of Validation Popup Message
/******************************************************************************************/

/************************************* Utilities ******************************************/

function pageContainValidationTextBox()
{
	var oControls = document.getElementsByTagName("INPUT");
	for (var i = 0; i < oControls.length; i++)
	{
		if (oControls[i].getAttribute("isKce") == "true")
		{
			return true;
		}
	}
	return false;
}

// This function is used to make a drop down autopostback with validation.
function DropChange(eventTarget, eventArgument) 
{
	if (typeof(Page_ClientValidate) == 'function')
	{
		Page_ClientValidate();
		if (Page_IsValid)
		{
			__doPostBack(eventTarget,eventArgument);
			return Page_IsValid;
		}
	}
	else
	{
	__doPostBack(eventTarget,eventArgument);
	return true;
	}
}

/******************************************************************************************/