// JavaScript Document
function evo_changeCSSclass(obj,style)
{
	obj.className = style;
}

function courriel(nom,site)
{
	window.location.href = "mailto:" + nom + "@" + site;
}

function evo_popup(fichier, name,largeur, hauteur, scroller, resizable, menus)
{
 	window.open(fichier,name,"toolbar="+menus+",scrollbars="+scroller+",directories=no,status=no,menubar="+menus+",resizable="+resizable+",left=50,right=0,top=50,width="+largeur+",height="+hauteur);
	screen.focus;
}

function evo_updateINPUTvalue(input,action)
{	
	var myInput = eval(input.value);
		
	if((action == 'hi') && myInput < 9999){		
		myInput = myInput + 1;
		}
	else if((action =='low') && (myInput > 0)){
		myInput = myInput - 1;
		}
	input.value = myInput;
}

function showElement(my_id) { 
	document.getElementById(my_id).style.display = "block";
}

function hideElement(my_id) { 
	document.getElementById(my_id).style.display = "none";
}

function confirmDelete(url,message)
{
	if (confirm(message)) { 
		window.location.href= url;
	}
}

function valid_form(formname, url)
{ 	
	this.formname = formname;
	
	document.forms[this.formname].action = url;
	document.forms[this.formname].submit();
}

function save_form(obj_form, url, obj_field)
{ 	
	var txtMessage;

	if ((obj_field.value=='') || (obj_field.value==null)) 
		txtMessage = "";
	else 
		txtMessage = obj_field.value;
	
	while ( (txtMessage == '') || (txtMessage == null))  { 
	   txtMessage = prompt('Entrez un nom pour votre liste d\'achat', txtMessage);
	} 
	url = url+"&cmdnm="+txtMessage ;

	valid_form(obj_form, url);
}

function save_form_popup(formname, url, obj_field)
{ 	
	var txtMessage;

	if ((obj_field.value=='') || (obj_field.value==null)) 
		txtMessage = "";
	else 
		txtMessage = obj_field.value;
	
	url = url+"&cmdnm="+txtMessage ;
	
	window.opener.document.forms[formname].action = url;
	window.opener.document.forms[formname].submit();
	window.close();	
}

function add_product(url, prod_id, qte, price) {

	window.location.href = url + "&pid=" +  prod_id + "&qty=" + qte + "&price=" + price ;

}


function checkUncheckAll(theElement)
{
	var theForm = theElement.form, z = 0;
	for(z=0; z<theForm.length;z++)
	{
		if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall')
		{
			theForm[z].checked = theElement.checked;
		}
	}
}

function formatcurrency(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	var s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

function isMoneyFormat(str,eur) {
   isMoneyFormatAmount = 0.00;
   isMoneyFormatString = "0.00";

   if(!str && str!=0) return false;

   str = "" + str; // force string
   for (var i=0; i<str.length;i++) {
      var ch = str.charAt(i);
      if (!isNum(ch) && ch!='.' && ch != ',' && ch !='-') return isMoneyFormatString ;
   }

   var sign = 1;
   var signChar = '';
   isMoneyFormatAmount = 0.00;
   isMoneyFormatString = "0.00";

   if (str.length > 1) {
      signChar = str.substring(0,1);
      if (signChar == '-' || signChar == '+' ) {
         if (signChar == '-') sign = -1;         
         str = str.substring(1);
      }
      else signChar = '';
   }
   var decimalPoint = '.';
   var thDelim = ',';
   if (eur) { 
      decimalPoint = ','
      thDelim = '.';
   }
   test1 = str.split(decimalPoint);
   if (test1.length == 2) { // Decimals found
      if (test1[1].length > 2) test1[1] = Math.round(String("0"+decimalPoint+test1[1])*100); // more than 2 decimals
      if (isNum(test1[1])) {
         if (test1[1] < 9 && test1[1].charAt(0) > 0) test1[1] = new String(test1[1]+"0");
      }
      else test1[1] = "00"; 
   }
   else test1[1] = "00"; // force decimals
   if (test1[0] == '') test1[0] = 0;
   if (test1[0] && test1[0].indexOf(thDelim) != -1) {
      test2 = test1[0].split(thDelim);  
      if (test2.length >= 2) { // thousands found
         var thError = false;
         for (var i=0;i<test2.length;i++) {
            if (test2[i].length < 3 && i != 0) { thError = true; break; } // all thousands exept the first.
            if (!isNum(test2[i])) { thError = true; break; } // all numbers
         }
         if (thError) test1[0] = "0.00";
         test1[0] = test2.join('')
      }
   }
   isMoneyFormatAmount = (parseInt(test1[0]) + parseFloat('.'+test1[1]))*sign;
   isMoneyFormatString = new String(""+signChar+""+parseInt(test1[0])) +'.'+test1[1];

   return isMoneyFormatString;
} 

function isNum(str) {
  if(!str) return false;
  for(var i=0; i<str.length; i++){
    var ch=str.charAt(i);
    if ("0123456789".indexOf(ch) ==-1) return false;
  }
  return true;
} 

function switch_menu(obj_menu, obj_sousmenu_actif){
	menu_elements = obj_menu.childNodes;
	for(var i=0; i<menu_elements.length; i++){
		if(menu_elements[i].nodeName == 'LI'){
			if(!menu_elements[i].attributes['class']){
				attribute_class = document.createAttribute('class');
				menu_elements[i].setAttributeNode(attribute_class);
			}
			menu_elements[i].attributes['class'].value = (menu_elements[i].attributes['class'].value).replace('actif','');
			
			menu_elements_A = menu_elements[i].firstChild;
			if(!menu_elements_A.attributes['href']){
				attribute_href = document.createAttribute('href');
				menu_elements_A.setAttributeNode(attribute_href);
			}
			if(menu_elements_A.attributes['href2']){
				menu_elements_A.attributes['href'].value = menu_elements_A.attributes['href2'].value;
			}
			
			menu_level2 = menu_elements[i].childNodes;
			for(var ii=0; ii<menu_level2.length; ii++){
				if(menu_level2[ii].nodeName == 'UL'){
					if(menu_level2[ii].attributes['id'].value == obj_sousmenu_actif.id){
						menu_elements[i].attributes['class'].value += ' actif';
						menu_elements_A.removeAttribute('href');
					}
				}
			}
		}
		
		
	}
	
	menus_level2 = obj_menu.getElementsByTagName('ul');
	for(i=0; i<menus_level2.length; i++){
		if(menus_level2[i] != obj_sousmenu_actif){
			menus_level2[i].style.display = 'none';
		}else{
			menus_level2[i].style.display = 'block';
		}
	}
}

function showAds(zone_id){
	var m3_u = (location.protocol=='https:'?'https://www.avril.ca/openads/www/delivery/ajs.php':'http://www.avril.ca/openads/www/delivery/ajs.php');
	var m3_r = Math.floor(Math.random()*99999999999);
	if (!document.MAX_used) document.MAX_used = ',';
	document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
	document.write ("?zoneid="+zone_id);
	document.write ('&amp;cb=' + m3_r);
	if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
	document.write ("&amp;loc=" + escape(window.location));
	if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
	if (document.context) document.write ("&context=" + escape(document.context));
	if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
	document.write ("'><\/scr"+"ipt>");
}