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

//Global Variables
var DomainPrefix = "http://www.123demenagez.com/static/fr/images/";

/* ACTIVE WEDGE MOUSEOVER */
  if (document.images)
  {
   wedge_on = new Image();
   wedge_off = new Image();
   wedge_on.src  = DomainPrefix + "bg-tabs-wedge-on.gif";
   wedge_off.src = DomainPrefix + "bg-tabs-wedge-off.gif";
  }

  function Hover(state)
  {
    if (document.images)
    {
      if (state == true)
	  {
	    document.wedge.src = wedge_on.src;
	  }
	  else
	  {
	    document.wedge.src = wedge_off.src;
	  }
    }
  }

function addbookmark(bookmarkurl)
{
	if (bookmarkurl = -1) { bookmarkurl="http://www.123demenagez.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 = 510;
	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
  }

/* 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_maison.value != "") &&
		(document.FormMail.realname.value != " ") &&
        (document.FormMail.email.value != " ") &&
        (document.FormMail.message.value != " ") &&
        (document.FormMail.Telephone_maison.value != " ")
       )
    {
      if ((document.FormMail.email.value.indexOf('.',0) == -1) ||
          (document.FormMail.email.value.indexOf('@',0) == -1)
         )
      {
        alert("Format du courrier électronique non-valide");
        return false;
      }
      else
      {
        return true;
      }
    }
    else
    {
      sMsg = "Veuillez remplir les champs\n"
           + "obligatoires avant de soumettre.";
      alert(sMsg);
      return false;
    }
   }

	function ValidAddress()
	{
		ConcatDate();
	    if ((document.FormSoum1.O_ADDR.value != "") &&
	        (document.FormSoum1.O_VILLE.value != "") &&
	        (document.FormSoum1.D_ADDR.value != "") &&
	        (document.FormSoum1.D_VILLE.value != "") &&
	        (document.FormSoum1.O_ADDR.value != " ") &&
	        (document.FormSoum1.O_VILLE.value != " ") &&
	        (document.FormSoum1.D_ADDR.value != " ") &&
	        (document.FormSoum1.D_VILLE.value != " ")
	       )
	    {
	      return true;
	    }
	    else
	    {
	      sMsg = "Veuillez remplir les champs\n"
	           + "obligatoires avant de soumettre.";
	      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 + " : " + 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);
		}
	}
	
	
/* CALCULETTE DE VOLUME */
mValue = 0;
iValue = 0;
function CalcVol(theForm,rVolume)
{
	var k = 0;
	var Total = 0;
	for (k = 0; k < theForm.length; k++)
	{
		var Item = (theForm.elements[k]);
		var ItemType = (Item.type.substring(0,1));
		var ItemCheck = (Item.checked);
		if (ItemCheck)
	    {
			ItemValue = eval(Item.value);
			if (ItemValue != 0)
			{
				ItemValue = eval(Item.value * rVolume);
			}
      		Total = (ItemValue + Total);
		}
	}
	mValue = Total;
	iValue = Total * 35.31;
	// theForm.result_m.value = mValue;
	theForm.result_i.value = iValue;
}

  function CalcClose(zeForm)
  {    // close pop-up window if it is open
  	var sCaller = window.opener.location;
	if (  (sCaller == 'http://www.123demenagez.com/static/fr/soumissionrapide/2.html') 
	   || (sCaller == 'http://www.123changingplaces.com/static/fr/soumissionrapide/2.html') 
	   )
	{
	  // sResult_m = window.zeForm.result_m.value;
  	  sResult_i = Math.round(window.Volume.result_i.value);
	  if (sResult_i && (sResult_i != -1))
	  { 
	    sConcatResult = sResult_i + " PI CU";
	  }
	  else
	  { 
	    sConcatResult = "";
	  }
	  window.opener.FormSoum2.VOL.value = sConcatResult;
	}
    window.close()
  }
  
  function ConvertVol()
  {
	var newVol = 0;
	if ((document.FormSoum2.VOL.value != "") && (document.FormSoum2.VOL.value != " "))
	{
	   	MyVol = document.FormSoum2.VOL.value;
		if (MyVol.indexOf(' PI CU')!=-1)
		{
			iChar = MyVol.indexOf(' PI CU');
			newVol = MyVol.substr(0,iChar) * 0.0283;
			document.FormSoum2.VOL.value = newVol + " M CU";

		}
		else if (MyVol.indexOf(' M CU')!=-1)
		{
			iChar = MyVol.indexOf(' M CU');
			newVol = MyVol.substr(0,iChar) * 35.315;
			document.FormSoum2.VOL.value = Math.round(newVol,2) + " PI CU";

		}
		else
		{
	  		document.FormSoum2.VOL.value = MyVol + " PI CU";
		}
	}
	else
	{
		alert("Vous devez d'abord entrer une valeur");
	}
  }

