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_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_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.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];}
}

//*********************************************************************************************
// Fonctions pour ajuster les prix sur la page d'achat
//*********************************************************************************************
// Ajuster les prix selon les critères sélectionnés
function SetPrices(nPrixProduit)
{
  // Quantités
	var nQteProduit = document.FAchat.IQteProduit.value;
	if((isNaN(nQteProduit)) || (nQteProduit == ""))
	{
		nQteProduit = 0;
	}
	
	// Pays et province/état
	var nPays = document.FAchat.SPays.value;
	var strProvince = document.FAchat.IProvince.value.toLowerCase();
	
	/*
	// Ajuster la devise et les prix selon le pays sélectionné
	if(nPays == "CA")
	{
		// Canada
		nPrixProduit = 1449.00;
		nPrix51991 = 70.00;
	}
	else
	{
	  // États-Unis
		nPrixProduit = 1300.00;
		nPrix51991 = 50.00;		
	}
	*/
	
	// Calcul des sous totaux
	var nTotalProduit = parseFloat(nPrixProduit * nQteProduit);
	var nTotal = nTotalProduit;
	
	/*
	// Calcul des taxes
	var nTPS = 0;
	var nTVQ = 0;
	// Les taxes sont calculées pour le Canada seulement
	if(nPays == "CA")
	{
  	nTPS = parseFloat(nTotal * 0.07);
  	nTotal = parseFloat(nTotal + nTPS);
		
		// La TVQ est seulement pour la province du Québec
		if((strProvince == "") || ((strProvince.indexOf("q") != -1) && (strProvince.indexOf("c") != -1)) || (strProvince.indexOf("pq") != -1))
		{
			nTVQ = parseFloat(nTotal * 0.075);
  		nTotal = parseFloat(nTotal + nTVQ);
		}
	}
	*/
	
	// Modifier dynamiquement les valeurs affichées à l'écran
	PrixProduit.innerHTML = format_number(nPrixProduit,2);
	TotalProduit.innerHTML = format_number(nTotalProduit,2);

	//SousTotal.innerHTML = format_number(nSousTotal,2);
	//TPS.innerHTML = format_number(nTPS,2);
	//TVQ.innerHTML = format_number(nTVQ,2);
	Total.innerHTML = format_number(nTotal,2);
	
	// Modifier les valeurs des inputs
	//document.FAchat.IQteProduit.value = nQteProduit;
	document.FAchat.IPrixProduit.value = format_number(nPrixProduit,2);
	document.FAchat.ITotalProduit.value = format_number(nTotalProduit,2);
	//document.FAchat.ISousTotal.value = format_number(nSousTotal,2);
	//document.FAchat.ITPS.value = format_number(nTPS,2);
	//document.FAchat.ITVQ.value = format_number(nTVQ,2);
	document.FAchat.ITotal.value = format_number(nTotal,2);
}

function format_number(pnumber,decimals)
{ 

   if (isNaN(pnumber)) { return 0}; 
   var snum = new String(pnumber); 
   var sec = snum.split('.'); 
   var whole = parseFloat(sec[0]); 
   var result = ''; 
   if(sec.length > 1)
   { 
      var dec = new String(sec[1]); 
      dec = String(parseFloat(sec[1])/Math.pow(10,(dec.length - decimals))); 
      dec = String(whole + Math.round(parseFloat(dec))/Math.pow(10,decimals)); 
      var dot = dec.indexOf('.'); 
      if(dot == -1){ 
      dec += '.'; 
      dot = dec.indexOf('.'); 
      } 
      while(dec.length <= dot + decimals) { dec += '0'; }
      result = dec; 
   }
   else
   { 
      var dot; 
      var dec = new String(whole); 
      dec += '.'; 
      dot = dec.indexOf('.'); 
      while(dec.length <= dot + decimals) { dec += '0'; } 
      result = dec; 
   }
   return result;
}

// Si le champ est vide, mettre 0
function checkVide()
{
	var current = window.event.srcElement;
	
	if(current.value == "")
		current.value = 0;
}

// Accepter seulement les chiffres
function integerOnly()
{
	if((window.event.keyCode < 48) || (window.event.keyCode > 57))
		event.returnValue = false;
}
//*********************************************************************************************


//*********************************************************************************************
// Fonctions pour switcher les images sur la page d'accueil
//*********************************************************************************************
// Inverser la grande et la petite image
function ChangeImage(nNoImage)
{
	oImg1 = document.getElementById("imggrand");
	oImg2 = document.getElementById("img"+nNoImage);

    if (oImg1 && oImg2) {
	    var srcImg1 = oImg1.src;
	    var srcImg2 = oImg2.src;
    	
	    var nImg1 = new Image();
	    var nImg2 = new Image();
    	
	    nImg1.src = srcImg2.replace("petit","grand");
	    nImg2.src = srcImg1.replace("grand","petit");
    	
	    oImg1.src = nImg1.src;
	    oImg2.src = nImg2.src;
	}
}
//*********************************************************************************************


//*********************************************************************************************
// Valider les champs du formulaire contactez-nous
//*********************************************************************************************
function ValideContact()
{
	if(document.FContact.Inom.value == "")
  {
    alert("You must enter your name.");
    document.FContact.Inom.focus();
  }
  else if(document.FContact.Iemail.value == "")
  {
    alert("You must enter your email address.");
    document.FContact.Iemail.focus();
  }  
  else if((document.FContact.Iemail.value.indexOf("@") == -1) || (document.FContact.Iemail.value.indexOf(".") == -1))
  {
    alert("Your email address is invalid.");
    document.FContact.Iemail.focus();
  }
  else if(document.FContact.IAddress.value == "")
  {
    alert("You must enter your address.");
    document.FContact.IAddress.focus();
  }
	else if(document.FContact.Icity.value == "")
  {
    alert("You must enter your city.");
    document.FContact.Icity.focus();
  }	
	else if(document.FContact.Imess.value == "")
  {
    alert("You must enter a message.");
    document.FContact.Imess.focus();
  }
	else
	{
		document.FContact.submit();
	}
}
//*********************************************************************************************


//*********************************************************************************************
// Fonction pour valider le formulaire de la page d'achat
//*********************************************************************************************
function ValideAchat()
{
	var bError = false;
	document.FAchat.BtnSubmit.disabled = true;
	var errMsg = "Fields in bold characters are required.";
	
	if(document.FAchat.IQteProduit.value == 0)
	{
    alert("The quantity must be over zero.");
    document.FAchat.IQteProduit.focus();
		bError = true;
	}
  else if(document.FAchat.IPrenom.value == "")
  {
    alert(errMsg);
		document.FAchat.IPrenom.focus();
		bError = true;
  }
  else if(document.FAchat.INom.value == "")
  {
    alert(errMsg);
		document.FAchat.INom.focus();
		bError = true;
  }
  else if(document.FAchat.IAdresse.value == "")
  {
    alert(errMsg);
    document.FAchat.IAdresse.focus();
		bError = true;
  }
  else if(document.FAchat.IVille.value == "")
  {
    alert(errMsg);
    document.FAchat.IVille.focus();
		bError = true;
  }
  else if(document.FAchat.IProvince.value == "")
  {
    alert(errMsg);
    document.FAchat.IProvince.focus();
		bError = true;
  }	
  else if(document.FAchat.IZip.value == "")
  {
    alert(errMsg);
    document.FAchat.IZip.focus();
		bError = true;
  }
  else if(document.FAchat.ITel1.value == "")
  {
    alert(errMsg);
    document.FAchat.ITel1.focus();
		bError = true;
  }
	else if(document.FAchat.ITel2.value == "")
  {
    alert(errMsg);
    document.FAchat.ITel2.focus();
		bError = true;
  }
	else if(document.FAchat.ITel3.value == "")
  {
    alert(errMsg);
    document.FAchat.ITel3.focus();
		bError = true;
  }
  else if(document.FAchat.IEmail.value == "")
  {
    alert(errMsg);
    document.FAchat.IEmail.focus();
		bError = true;
  }
  else if((document.FAchat.IEmail.value.indexOf("@") == -1) || (document.FAchat.IEmail.value.indexOf(".") == -1))
  {
    alert("Your email address is invalid.");
    document.FAchat.IEmail.focus();
		bError = true;
  }

	if(bError == true)
	{
		document.FAchat.BtnSubmit.disabled = false;
    return false;						
	}
}
//*********************************************************************************************


//*********************************************************************************************
// Fonction pour valider le formulaire de la page d'achat
//*********************************************************************************************
function ValidPurchase()
{
	var bError = false;
	document.FAchat.BtnSubmit.disabled = true;
	var errMsg = "Fields in bold characters are required.";
	
	if(document.FAchat.IPrenom.value == "")
  {
    alert(errMsg);
		document.FAchat.IPrenom.focus();
		bError = true;
  }
  else if(document.FAchat.INom.value == "")
  {
    alert(errMsg);
		document.FAchat.INom.focus();
		bError = true;
  }
  else if(document.FAchat.IAdresse.value == "")
  {
    alert(errMsg);
    document.FAchat.IAdresse.focus();
		bError = true;
  }
  else if(document.FAchat.IVille.value == "")
  {
    alert(errMsg);
    document.FAchat.IVille.focus();
		bError = true;
  }
  else if(document.FAchat.IProvince.value == "")
  {
    alert(errMsg);
    document.FAchat.IProvince.focus();
		bError = true;
  }	
  else if(document.FAchat.IZip.value == "")
  {
    alert(errMsg);
    document.FAchat.IZip.focus();
		bError = true;
  }
  else if(document.FAchat.ITel1.value == "")
  {
    alert(errMsg);
    document.FAchat.ITel1.focus();
		bError = true;
  }
	else if(document.FAchat.ITel2.value == "")
  {
    alert(errMsg);
    document.FAchat.ITel2.focus();
		bError = true;
  }
	else if(document.FAchat.ITel3.value == "")
  {
    alert(errMsg);
    document.FAchat.ITel3.focus();
		bError = true;
  }
  else if(document.FAchat.IEmail.value == "")
  {
    alert(errMsg);
    document.FAchat.IEmail.focus();
		bError = true;
  }
  else if((document.FAchat.IEmail.value.indexOf("@") == -1) || (document.FAchat.IEmail.value.indexOf(".") == -1))
  {
    alert("Your email address is invalid.");
    document.FAchat.IEmail.focus();
		bError = true;
  }

	if(bError == true)
	{
		document.FAchat.BtnSubmit.disabled = false;
    return false;						
	}
}
//*********************************************************************************************


//*********************************************************************************************
// Fonctions pour le panier d'achat
//*********************************************************************************************
function ChangeBrand()
{
	window.location.href = "atv-models.asp?nBrand="+document.FProduct.SMarque.value;
}

function DelPanier(nID,strLangue)
{
	if(strLangue == "fr")
		strConfirmDel = "Voulez-vous vraiment enlever ce produit de votre panier?";
	else
		strConfirmDel = "Are you sure you want to remove this product from your cart?";
		
  if(confirm(strConfirmDel))
    window.document.location.href = "atv-mycart.asp?strAction=del&nID="+nID;
}

function addextraitem()
{
    var vdesc = document.getElementById("iextradesc");
    var vprice = document.getElementById("iextraprice");
    
    if (vdesc && vprice) {
        var vdescvalue = vdesc.value;
        var vpricevalue = vprice.value;
        
        if (vdescvalue && vpricevalue && vdescvalue != "" && vpricevalue != "") {
            window.document.location.href = "atv-mycart.asp?strAction=addx&desc="+escape(vdescvalue)+"&price="+escape(vpricevalue);
        }
    }
}

function DelExtra(nID,strLangue)
{
	if(strLangue == "fr")
		strConfirmDel = "Voulez-vous vraiment enlever cet item de votre panier?";
	else
		strConfirmDel = "Are you sure you want to remove this item from your cart?";
		
  if(confirm(strConfirmDel))
    window.document.location.href = "atv-mycart.asp?strAction=delx&nID="+nID;
}

function IntegerOnly()
{
	if((window.event.keyCode < 48) || (window.event.keyCode > 57))
		event.returnValue = false;
}

function NoEmptyQty(i)
{
	if(i == 0)
	{
		if((document.FProduct.IQteProduit.value == 0) || (isNaN(document.FProduct.IQteProduit.value)))
			document.FProduct.IQteProduit.value = 0;
	}
	else
	{
		if((document.FProduct.IQteProduit[i].value == 0) || (isNaN(document.FProduct.IQteProduit[i].value)))
			document.FProduct.IQteProduit[i].value = 0;
	}
}
