i = 0;
j = 0;
FormCount = 0;

//Swap images for mouseovers
	function MM_preloadImages() { //v3.0
		var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}

	function MM_swapImgRestore() { //v3.0
		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_findObj(n, d) { //v4.01
		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 && d.getElementById) x=d.getElementById(n); return x;
	}

	function MM_swapImage() { //v3.0
		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];}
	}

//Global Variables
	var DomainPrefix = "http://www.kunoki.com/images/";

/* ADD BOOKMARK */
	function addbookmark(bookmarkurl)
	{
		if (bookmarkurl = -1) { bookmarkurl="http://www.kunoki.com/" }
		bookmarktitle="123 Déménagez"
		if (document.all) window.external.AddFavorite(bookmarkurl,bookmarktitle)
	}

/***** QUICKNAV ONCHANGE SELECT *****/
	function quicknav(pageURL) {
		if (pageURL == "")
		{
			return false;
		}
		else
		{
			document.location.href = pageURL;
		}
	}

/* POPUP WINDOWS */
	var popWin = null		// use this when referring to pop-up window
	var winCount = 0
	var winName = "popWin"

	function FullPop(winURL)
	{
	window.open(winURL, '', 'fullscreen=yes, scrollbars=1');
	}

	function SlidePop(winURL)
	{
		winWidth = 740;
		winHeight = 535;
		winFeatures = 'menubar=0,location=0,resizable=0,scrollbars=0,statusbar=0,titlebar=0,toolbar=0,directories=0';
		winLeft = 20;
		winTop = 20;
		var d_winLeft = 20	// default, pixels from screen left to window left
		var d_winTop = 20	 // default, pixels from screen top to window top
		winName = "popWin" + winCount++ //unique name for each pop-up window
		closePopWin()			 // close any previously opened pop-up window
		winFeatures += getLocation(winWidth, winHeight, d_winLeft, d_winTop)
		popWin = window.open(winURL, winName, "width=" + winWidth + ",height=" + winHeight + winFeatures)
	}


	function LargePop(winURL)
	{
		winWidth = 785;
		winHeight = 415;
		winFeatures = 'menubar=0,location=0,resizable=1,scrollbars=1,statusbar=0,titlebar=0,toolbar=0,directories=0';
		winLeft = 20;
		winTop = 20;
		var d_winLeft = 20	// default, pixels from screen left to window left
		var d_winTop = 20	 // default, pixels from screen top to window top
		winName = "popWin" + winCount++ //unique name for each pop-up window
		closePopWin()			 // close any previously opened pop-up window
		winFeatures += getLocation(winWidth, winHeight, d_winLeft, d_winTop)
		popWin = window.open(winURL, winName, "width=" + winWidth + ",height=" + winHeight + winFeatures)
	}

	function MedPop(winURL)
	{
		winWidth = 600;
		winHeight = 350;
		winFeatures = 'menubar=0,location=0,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=0,directories=0';
		winLeft = 20;
		winTop = 20;
		var d_winLeft = 20	// default, pixels from screen left to window left
		var d_winTop = 20	 // default, pixels from screen top to window top
		winName = "popWin" + winCount++ //unique name for each pop-up window
		closePopWin()			 // close any previously opened pop-up window
		winFeatures += getLocation(winWidth, winHeight, d_winLeft, d_winTop)
		popWin = window.open(winURL, winName, "width=" + winWidth + ",height=" + winHeight + winFeatures)
	}

	function SmallPop(winURL)
	{
		winWidth = 435;
		winHeight = 330;
		winFeatures = 'menubar=0,location=0,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=0,directories=0';
		winLeft = 20;
		winTop = 20;
		var d_winLeft = 20	// default, pixels from screen left to window left
		var d_winTop = 20	 // default, pixels from screen top to window top
		winName = "popWin" + winCount++ //unique name for each pop-up window
		closePopWin()			 // close any previously opened pop-up window
		winFeatures += getLocation(winWidth, winHeight, d_winLeft, d_winTop)
		popWin = window.open(winURL, winName, "width=" + winWidth + ",height=" + winHeight + winFeatures)
	}

	function VidPop(winURL)
	{
		// window.open(winURL, '', 'fullscreen=yes, scrollbars=1');
		winWidth = 755;
	winHeight = 550;
	winFeatures = 'menubar=0,location=0,resizable=0,scrollbars=1,status=0,titlebar=0,toolbar=0,directories=0';
	winLeft = 20;
	winTop = 20;
		var d_winLeft = 20	// default, pixels from screen left to window left
		var d_winTop = 20	 // default, pixels from screen top to window top
		winName = "popWin" + winCount++ //unique name for each pop-up window
		closePopWin()			 // close any previously opened pop-up window
		winFeatures += getLocation(winWidth, winHeight, d_winLeft, d_winTop)
		popWin = window.open(winURL, winName, "width=" + winWidth + ",height=" + winHeight + winFeatures)
	}

	function closePopWin()
	{		// close pop-up window if it is open
		if (navigator.appName != "Microsoft Internet Explorer" || parseInt(navigator.appVersion) >=4) // do not close if early IE
		if (popWin != null) if(!popWin.closed) popWin.close()
	}

	function getLocation(winWidth, winHeight, winLeft, winTop)
	{
		var winLocation = ""
		if (winLeft < 0)
		 winLeft = screen.width - winWidth + winLeft
		if (winTop < 0)
		 winTop = screen.height - winHeight + winTop
		if (winTop == "cen")
		 winTop = (screen.height - winHeight)/2 - 20
		if (winLeft == "cen")
		 winLeft = (screen.width - winWidth)/2
		if (winLeft>0 & winTop>0)
		 winLocation =	",screenX=" + winLeft + ",left=" + winLeft + ",screenY=" + winTop + ",top=" + winTop
		else
		winLocation = ""
		return winLocation
	}

/* numbering functions */
	function ajouteZero(s) // adds zeros to digits under 10
	{
		return((s<10)?"0":"") + s
	}

/* Switch language */
	function SwitchLang(lang)
	{
		var urlloc = location.href;
		var loc = urlloc.toLowerCase();
		var locpath = location.pathname
		var curLang = locpath.substring(0,4);
		// alert(curLang);
		if ((curLang == '/fr') || (curLang == '/en'))
		{
			var curPath = locpath.substring(4);
			if (lang)
			{
				var newLang = '/' + lang + '/';
				var newloc = newLang + curPath;
				location.href=newloc;
			}
		}
		else;
		{
			location.href= "/smile";
		}
	}


/* DIAPORAMA */
	function dynAfficheImage(i)
	{
		document.pic.src = mesImages[i].src;
	}

	function diaporama()
	{
		position	= (position + 1) % nimages;
		dynAfficheImage(position);
		setTimeout("diaporama()",4000);
	}

	function diapoSuivante()
	{
		position = (position+1)%nimages;
		dynAfficheImage(position);
	}

	function diapoPrecedente()
	{
		position = (position -1 + nimages)%nimages;
		dynAfficheImage(position);
	}

/* PRINT WINDOW */
	function printWindow(){
		bV = parseInt(navigator.appVersion)
		if (bV >= 4) window.print()
	}

/* VALIDATE EMAIL ADRESSES IN FORMS */
	 function ValidFormMail()
	 {
		if ((document.FormMail.prenom.value != "") &&
				(document.FormMail.nom.value != "") &&
				(document.FormMail.email.value != "") &&
		(document.FormMail.prenom.value != " ") &&
				(document.FormMail.nom.value != " ") &&
				(document.FormMail.email.value != " ")
			 )
		{
			if ((document.FormMail.email.value.indexOf('.',0) == -1) ||
					(document.FormMail.email.value.indexOf('@',0) == -1)
				 )
			{
				alert("Format de courrier électronique non-valide.\nInvalid Email format");
				return false;
			}
			else
			{
				return true;
			}
		}
		else
		{
			sMsg = "Veuillez remplir les champs obligatoires avant de soumettre.\n";
		//	+ "Please fill all required fields before submitting";
			alert(sMsg);
			return false;
		}
	 }

	function RealName()
	{
		if ((document.FormMail.prenom.value != "") &&
				(document.FormMail.nom.value != "") &&
				(document.FormMail.prenom.value != " ") &&
				(document.FormMail.nom.value != " ")
			 )
		{
			var realname = document.FormMail.prenom.value + ' ' + document.FormMail.nom.value;
			document.FormMail.realname.value = realname;
		}
	}

/* ADJUST DATE DROPDOWNS */
	function dropDownSelect(select_name,option_name)
	{
		select_dropdown = eval ( 'document.FormMail.' + select_name );
		for (var i = 0; i<select_dropdown.length; i++)
		{
			if (select_dropdown.options[i].value == option_name)
			{
				select_dropdown.selectedIndex = i;
			}
		}
	}

	function ajouteZero(s) // adds zeros to digits under 10
	{
		return((s<10)?"0":"") + s
	}

	function AdjustDate()
	{
		var aMonthName = new Array ("Jan","Fev","Mar","Avr","Mai","Juin","Juil","Août","Sept","Oct","Nov","Dec");
		var aujourdhui =	new Date();
		var iJourNombre = ajouteZero(aujourdhui.getDate());
		var sMois	= aMonthName[aujourdhui.getMonth()];
		var sMois2	= aMonthName[aujourdhui.getMonth()+1];
		var iAnnee	= aujourdhui.getYear();

		dropDownSelect('start_year',iAnnee);
		dropDownSelect('start_month',sMois);
		dropDownSelect('start_day',iJourNombre);
		dropDownSelect('end_year',iAnnee);
		dropDownSelect('end_month',sMois2);
		dropDownSelect('end_day',iJourNombre);
	}

	function ClearDate()
	{
		dropDownSelect('start_year','');
		dropDownSelect('start_month','');
		dropDownSelect('start_day','');
		dropDownSelect('end_year','');
		dropDownSelect('end_month','');
		dropDownSelect('end_day','');
	}

	function ConcatDate()
	{
		sOrigDate = document.FormSoum1.start_year.value + document.FormSoum1.start_month.value + document.FormSoum1.start_day.value;
		document.FormSoum1.O_DATE.value = sOrigDate;
		sDestDate = document.FormSoum1.end_year.value + document.FormSoum1.end_month.value + document.FormSoum1.end_day.value;
		document.FormSoum1.D_DATE.value = sDestDate;
	}

/* GET PARAMS FOR MUTLIPLE STEP FORM DATA GATHERING */

// forces alphanumeric
	function f(o){
		// o.value=o.value.toUpperCase().replace(/([^0-9A-Z\.])/g,"");
		o.value=o.value.toUpperCase().replace(/([^0-9A-Z\' '._-])/g,"");
	}

	function g(o){
		if(/[^0-9A-Z]/.test(o.value)){
			// o.value=o.value.toUpperCase().replace(/([^0-9A-Z\.])/g,"");
		o.value=o.value.toUpperCase().replace(/([^0-9A-Z\' '._-])/g,"");
		}
	}

	function showElements(theForm) {
		 str = "Form Elements of form " + theForm.name + ": \n "
		 for (var FormCount = 0; FormCount < theForm.length; FormCount++)
		 {
			 str += theForm.elements[FormCount].name + "&nbsp;: " + theForm.elements[FormCount].value + "\n"
		 }
		 alert(str)
	}

// form output in a string
	function getFormParams(theForm)
	{
		sMsg = '';
		var sUrl = document.location.search;
		if (sUrl)
		{
			iUrlCount = 0;
			var iLastCharPos = sUrl.indexOf("&submit");
			var sFullString = sUrl.substring("?",iLastCharPos);
			var sGetString = sFullString.substring(1,iLastCharPos);
			var aUrl = sGetString.split("&");
			var iUrlLength = aUrl.length;
			for (iUrlCount =0; iUrlCount < iUrlLength; iUrlCount++)
			{
				var sParamAndValue = aUrl[iUrlCount];
				var sSep = sParamAndValue.indexOf("=");
				var sFieldName = sParamAndValue.substring(0,sSep);
				var sFieldValue = sParamAndValue.substring(sSep+1);

				sMsg += "\n sFieldName: " + sFieldName;
				sMsg += "\n sFieldValue: " + sFieldValue;

				for (j = 0; j < theForm.length; j++)
				{
					Item = theForm.elements[j];
					ItemType = (Item.type);
					if (ItemType == 'hidden')
					{

						ItemName = (Item.name);
						if (ItemName == sFieldName)
						{
							sMsg += "\n ItemName: " + ItemName;
							theForm.elements[j].value = sFieldValue;
						}
					}
				}
			}
			// alert(sMsg);
		}
	}

// Extranet LoadPage
	function loadpage()
	{
		var page = "/extranet/" + document.frm.pwd.value + "/";
		if ((document.frm.pwd.value != " ") && (document.frm.pwd.value != ""))
		{
			document.location.href = page;
		}
	}

// Expanding Table Rows
	content = new Array ();

	content [0] = new Array (
	false,
	new Array('sub_0_1')
	);
	content [1] = new Array (
	false,
	new Array('sub_1_1')
	);
	content [2] = new Array (
	false,
	new Array('sub_2_1')
	);
	content [3] = new Array (
	false,
	new Array('sub_3_1')
	);
	content [4] = new Array (
	false,
	new Array('sub_4_1')
	);
	content [5] = new Array (
	false,
	new Array('sub_5_1')
	);
	content [6] = new Array (
	false,
	new Array('sub_6_1')
	);

	isOPERA = (navigator.userAgent.indexOf('Opera') >= 0)? true : false;
	isIE		= (document.all && !isOPERA)? true : false;
	isDOM	 = (document.getElementById && !isIE && !isOPERA)? true : false;

	function processTree(id){
		if (content [id][0]){
			for (i = 0; i < content [id][1].length; i++)
				hide (content [id][1][i]);

			content [id][0] = false;
		}else{
			for (i = 0; i < content [id][1].length; i++)
				show (content [id][1][i], 'table-row');
			content [id][0] = true;
		}
		return false;
	}

	function show(id,displayValue){
		if (isDOM)
			document.getElementById(id).style.display = (displayValue)? displayValue : "block";
		else if (isIE)
			document.all[id].style.display = "block";
	}

	function hide(id){
		if (isDOM)
			document.getElementById(id).style.display = "none";
		else if (isIE)
			document.all[id].style.display = "none";
	}

	if(isDOM||isIE){
		document.writeln('<style type="text/css">');
		document.writeln('.SubItemRow \{ display:none; \}');
		document.writeln('</style>');
	}

	function notReady(){
		alert("Sorry, the information you just requested is not yet ready. Please check back later.");
	}
