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

/* ADD BOOKMARK */

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

/***** QUICKNAV ONCHANGE SELECT *****/

  function getLocation(page) { if (page != "") { self.location=page; } }

/* POPUP WINDOW FUNCTION */

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

  function launchwin(winURL)
  {
    winWidth = 780;
	winHeight = 350;
	winFeatures = 'menubar=1,location=1,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=1,directories=1';
	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 launchPop(winURL)
  {
    winWidth = 510;
	winHeight = 190;
	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 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)
  {
   return ""
  }

  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
  }

function fullscreen(url)
{
	w = screen.availWidth-10;
	h = screen.availHeight-20;
	features = "width="+w+",height="+h;
	features += ",left=0,top=0,screenX=0,screenY=0";
	features += ",menubar=1,toolbar=1,location=1,directories=1,status=1,scrollbars=1,resizable=1";
	window.open(url, "", features);
}

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

/* DIAPORAMA */
var nimages = 12;
var placeholders = 3;
var mesImages = new Array();
var position = 0;

for (i =0; i <nimages; i++)
{
               mesImages[i] = new Image(219,147);
               mesImages[i].src = "../images/showcase_"+ ajouteZero(i) +".jpg";
}


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

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

function diapoSuivante(position)
{
          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.realname.value != "") &&
        (document.FormMail.email.value != "") &&
        (document.FormMail.message.value != "") &&
        (document.FormMail.Telephone_bureau.value != "") &&
		(document.FormMail.realname.value != " ") &&
        (document.FormMail.email.value != " ") &&
        (document.FormMail.message.value != " ") &&
        (document.FormMail.Telephone_bureau.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;
    }
   }

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

	function getParams(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 popLargeEmbed(videoLink)
{
	document.write('		<object id="MediaPlayer1" width=1280 height=900');
	document.write('			classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"');
	document.write('			codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"');
	document.write('	        standby="Loading Microsoft® Windows® Media Player components..." ');
	document.write('       		type="application/x-oleobject" align="middle">');
	document.write('		    <param name="FileName" value="' + videoLink +'">');
	document.write('		    <param name="ShowStatusBar" value="true">');
	document.write('		    <param name="showControls" value="true">');
	document.write('		    <param name="animationatStart" value="true">');
	document.write('		    <param name="transparentatStart" value="true">');
	document.write('		    <param name="autoStart" value="true">');
	document.write('		    <embed type="application/x-mplayer2" pluginspage = "http://www.microsoft.com/Windows/MediaPlayer/"');
	document.write('				src="' + videoLink +'" align="middle"');
	document.write('				width=1280');
	document.write('				height=768');
	document.write('				showstatusbar=true>');
	document.write('		    </embed> ');
	document.write('		  </object>');
}

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

// EXPANDING TEXT BLOCKS

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


