//*********** rollover code for product images and colors *******************//
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.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];}
}

//Popup Window Script
//By JavaScript Kit (http://javascriptkit.com)
//JavaScript tutorials and over 400+ free scripts

function openpopup(var1,var2,var3,var4){
var popurl=var1;
var popname=var2;
var popwidth=var3;
var popheight=var4;
winpops=window.open(popurl,popname,"width=" + popwidth + ",height=" + popheight + ",");
}

//************  email form check fields *******************//

function checkFields() {
		var missinginfo = "";
		var error_found	= true;
		var item;


		if (document.form.name.value == "") {
			missinginfo += "\n - Please enter your name";
		}

		if ((document.form.email.value == "") || (document.form.email.value.indexOf('@') == -1) || (document.form.email.value.indexOf('.') == -1)) {
			missinginfo += "\n - Please enter a proper email address";
		}

		if(document.form.comments.value == "") {
			missinginfo += "\n - Please enter your comments";
		}

		if (missinginfo != "") {
			alert(missinginfo);
			return false;
		}else{
			return true;
		}
	}

//************ currency conversion (numbers retrieved from Bank of Canada **********//

var CurrencyUS = 1.1290;
var CurrencyAUS = 0.8691;
var CurrencyEU = 1.4343;
var CurrencyGBP = 2.1462;

function calculateGBP(varPrice){
var GBPresult = varPrice * 1 / CurrencyGBP;
GBPresult = Math.round(GBPresult * 100)/100;
return GBPresult;
}


function calculateAUS(varPrice){
var AUSresult = varPrice * 1 / CurrencyAUS;
AUSresult = Math.round(AUSresult * 100)/100;
return AUSresult;
}

function calculateEU(varPrice){
var EUresult = varPrice * 1 / CurrencyEU;
EUresult = Math.round(EUresult * 100)/100;
return EUresult;
}

function calculateUS(varPrice){
var USresult = varPrice * 1 / CurrencyUS;
USresult = Math.round(USresult * 100)/100;
return USresult;
}

//*************** shopping cart form checking fields*********************//

function productType(var1,var2,var3)
{
  var the_box = var1; // value of the checkbox
  var product_code_box = var2; // value of the product code box
  var product_code = var3; // value of the product code upon the click

  // var the_switch = "";
  if (the_box.checked == false) {
    product_code_box.value = product_code;
    //alert (product_code_box.value);
  } else {
    product_code_box.value = product_code +'v';
    //alert (product_code_box.value);
  }
}

function productSize(var1)
{

  var vegan = 'qty' + var1 + 'c';
  var product_code_box = 'pcode' + var1;
  var container_size_box1 = 'container' + var1 + 'a';
  var container_size_box2 = 'container' + var1 + 'b';


  var veganChoice = window.document.forms[1].elements[vegan]; // create checkbox element
  var product_code = window.document.forms[1].elements[product_code_box]; // create product code box
  var Container1 = window.document.forms[1].elements[container_size_box1]; // create container size box
  var Container2 = window.document.forms[1].elements[container_size_box2];

		if (Container2.checked == true){

			product_code.value = Container2.value; // set the value of the product code to match selected size

		} else {

			product_code.value = Container1.value; // set the value of the product code to match selected size

		}

		if (veganChoice.checked == false) {

					product_code.value = product_code.value; // // set the value of the product code to remain the way that it is
//					alert ('vegan unchecked ' + product_code.value);

				} else {

					product_code.value = product_code.value +'v'; // set the value of the product code to be vegan
//					alert ('vegan checked ' + product_code.value);

		}


// alert('end of code');


}

function Uncheck(var1,var2,var3) // this makes sure the radio buttons show the correct selection
{

var Active_radio_button = 'container' + var1 + var2;
var InActive_radio_button = 'container' + var1 + var3;

// alert (Active_radio_button);

var radio_button1 = document.forms[1].elements[Active_radio_button]; // create the form object on the fly
var radio_button2 = document.forms[1].elements[InActive_radio_button]; // create the form object on the fly

radio_button1.checked = false; // set the radio button not selected to unselected
radio_button2.checked = true;  // set the radio button selected unselected

productSize(var1); // now determine what the product code should be

}