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.montrealaxion.com/";

/* ADD BOOKMARK */
function addbookmark(bookmarkurl)
{
	if (bookmarkurl = -1) { bookmarkurl="http://www.mistralcg.com/extranet/danoids" }
	bookmarktitle="DAN-oid TRIVIA micro-site"
	if (document.all) window.external.AddFavorite(bookmarkurl,bookmarktitle)
}

/***** QUICKNAV ONCHANGE SELECT *****/
	function changeLocation(page)
	{
		if (page != "")
		{
			self.location=page;
		}
	}

/* 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 LargePop(winURL)
  {
    winWidth = 800;
	winHeight = 600;
	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 = 550;
	winHeight = 400;
	winFeatures = 'menubar=0,location=0,resizable=1,scrollbars=0,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 = 350;
	winHeight = 200;
	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
}

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

/* VALIDATE EMAIL ADRESSES IN FORMS */

function ValidFormMail()
{
/*
	sMsg = "The DAN Challenge is now over. Congratulations to our winners!";
	alert(sMsg);
	changeLocation('winners.html');
	return false;
*/
	if ((document.FormMail.realname.value != "") &&
		(document.FormMail.email.value != "") &&
		(document.FormMail.firstname.value != "") &&
		(document.FormMail.lastname.value != "") &&
		(document.FormMail.realname.value != " ") &&
		(document.FormMail.email.value != " ") &&
		(document.FormMail.firstname.value != " ") &&
		(document.FormMail.lastname.value != " ")
		)
	{
		if ((document.FormMail.email.value.indexOf('.',0) == -1) ||
			(document.FormMail.email.value.indexOf('@',0) == -1)
		)
		{
			alert("Invalid Email format");
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		sMsg = "Please fill all required fields before submitting";
		alert(sMsg);
		return false;
	}
}

/* DOB to age */
function myAge(inbyr,inbmo,inbday)
{
	byr=parseInt(inbyr);
	bmo=(parseInt(inbmo)-1);
	bday=parseInt(inbday);
	var age;
	var now = new Date();
	tday=now.getDate();
	tmo=(now.getMonth());
	tyr=(now.getFullYear());
	if((tmo > bmo)||(tmo==bmo & tday>=bday))
	{
		age=byr;
	}
	else
	{
		age=byr+1;
	}
	document.write(tyr-age);
}

/* ADJUST DATE DROPDOWNS */

	function dropDownSelect(select_name,option_name)
	{
		select_dropdown = eval ( 'document.FormSoum1.' + select_name );

		for (var i = 0; i<select_dropdown.length; i++)
		{
			if (select_dropdown.options[i].text == option_name)
			{
				select_dropdown.selectedIndex = i;
			}
		}
	}

	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)
}

// gets for location bar parameter=string and puts the values in the name=parameter form elements value=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);
	}
}

function getParams(sExtract)
{
	var sFieldValue = '';
	var sFieldName = '';
	var sParamAndValue  = '';
	var sSep  = '';
	var sUrl = document.location.search;
	if (sUrl)
	{
		iUrlCount = 0;
		var iLastCharPos = sUrl.length+1;
		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++)
		{
			sParamAndValue = aUrl[iUrlCount];
			sSep = sParamAndValue.indexOf("=");
			sFieldName = sParamAndValue.substring(0,sSep);
			sFieldValue = sParamAndValue.substring(sSep+1);
			if (sFieldName == sExtract)
			{
				return sFieldValue;
			}
		}
	}
}

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

/* For debugging */
function AfficheMsg(Msg)
{
  document.write(Msg);
}

/* Screen Resolution */
function getMaxCoords() {
	var x, y = 0;
	var width  = 600;
	var height = 800;
	if (screen) {
      if (screen.availLeft) {
         x = screen.availLeft;
         y = screen.availTop;
      }
       // width  = screen.availWidth - 6;
	   // height = screen.availHeight - 29;
       width  = screen.availWidth;
	   height = screen.availHeight;
   }
	var reference = width + " X " + height;
	return reference;
}

/* SWITCH LANGUAGE */
function SwitchLang(lang)
{
	var urlloc = location.href;
	var loc = urlloc.toLowerCase();
	var locpath = location.pathname  // location.hash + location.search;
	var curLang = locpath.substring(0,4);
	if ((curLang != '/cgi') && (curLang != '/scr'))
	{
		var curPath = locpath.substring(4);
		alert(curPath);
		if (lang)
		{
			var newLang = '/' + lang + '/';
			var newloc = newLang + curPath;
			location.href=newloc;
		}
	}
}

/* DHTML DELAY */
function switchDiv(strDivName,bolVisible)
{
	//identify the element based on browser type
	if (isNS4)
	{
		objElement = document.layers[strDivName];
	}
	else if (isIE4)
	{
		objElement = document.all[strDivName];
	}
	else if (isIE5 || isNS6)
	{
		objElement = document.getElementById(strDivName);
	}
	if(isNS4)
	{
		if(!bolVisible)
		{
			objElement.visibility ="hidden"
		}
		else
		{
			objElement.visibility ="visible"
		}
	}
	else
	{
		if(!bolVisible)
		{
			objElement.style.visibility = "hidden";
		}
		else
		{
			objElement.style.visibility = "visible";
		}
	}
}

/* DHTML SWAP */

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.");
}




