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];}
}
function mOvr(src,clrOver)
	{ if (!src.contains(event.fromElement)) { src.style.cursor = 'hand'; src.bgColor = clrOver; }
}
function mOut(src,clrIn)
	{ if (!src.contains(event.toElement)) { src.style.cursor = 'default'; src.bgColor = clrIn; }
}
function centrePopup(theURL,winName,width,height,features) {
    var cTop = (screen.availHeight/2) - (height/2);
    var cLeft = (screen.availWidth/2) - (width/2);
    window.open(theURL,winName,'width='+width+',height='+height+',top='+cTop+',left='+cLeft+features);
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function doCalc(isSplit,id) {
	var total,d,splitprice;
	total = 0;
	d = 'document.productslist';
	// Check to see if this item has a split and calc total
	if (isSplit == 1) {
		splitamt = parseInt(eval(d+'.split_' + id).value); //min you need to buy
		minsplit = parseInt(eval(d+'.min_' + id).value); //what you are buying
		// Only check min split if a number is in the splitbox
		if (minsplit > 0) {
			// Check to see if we have the min amount of items
			if (minsplit >= splitamt) {
				splitprice = eval(d+'.minsellprice_' + id).value;
				total = total + (parseInt(minsplit) * parseFloat(splitprice))
			} else {
				alert("You must purchase a minimun of " + splitamt + " items");
				return false;
			}
		}
	}
	
	// All items should have a box amt
	boxamt = parseInt(eval(d+'.box_' + id).value);
	if (boxamt > 0) {
		boxprice = eval(d+'.boxsellprice_' + id).value;
		total = total + (parseInt(boxamt) * parseFloat(boxprice))
	}
	
	// Round and fix string to look like a price
	total = Math.round(total*100)/100
	total = total.toString();
	var decimal = total.indexOf(".")
	if (decimal == -1)
		total = total + ".00";
	else if (decimal == 1 && (total.length-(decimal+1) < 2))
		total = total + "0";
	else if (decimal == 2 && (total.length-(decimal+1) < 2))
		total = total + "0";
	else if (decimal == 3 && (total.length-(decimal+1) < 2))
		total = total + "0";
	else if (decimal == 4 && (total.length-(decimal+1) < 2))
		total = total + "0";
	eval(d+'.grandtotal_' + id).value = total
}

function setBuy(buyid) {
	hasBought = false;
	d = 'document.productslist';
	if(typeof(eval(d+'.min_' + buyid)) != 'undefined') {
		minsplit = (eval(d+'.min_' + buyid).value); 
		splitamt = (eval(d+'.split_' + buyid).value);
		
		//alert("min: " + minsplit);
		//a	lert("split: " + splitamt);
		
		
		// IVV only numeric values are accepted	
		
		if (!IsNumeric(minsplit) )
		{
			alert("Please insert a valid minimum quantity of items to buy");
			return false;
			hasBought = false;
		}	


		if (parseInt(minsplit) > 0) {
			// Check to see if we have the min amount of items			
			if (parseInt(minsplit) >= parseInt(splitamt)) 
			{
				hasBought = true;
			} 
			else 
			{
				alert("You must purchase a minimum of " + splitamt + " items");
				return false;
			}
		}
	}
	boxamt = eval(d+'.box_' + buyid).value
	//alert("boxamt: " + boxamt)
	if (boxamt > 0)
		hasBought = true;

	// IVV only numeric values are accepted
	if (boxamt != '' && !IsNumeric(boxamt))
	{
		alert("Please insert quantity of items to buy");
		return false;
		hasBought = false;
	}	
	
		
	if (hasBought == true) {
		document.productslist.buyID.value = buyid;
		return true;
		//productslist.submit();
	} else {
		alert("Please insert quantity of items to buy")
		return false;
	}
}

function togglePopup(PopupID){
	var oPopup = document.getElementById(PopupID);
	
	if(oPopup != 'none'){
		document.getElementById(PopupID).style.display = 'none';
		return true;
	}
}


//IVV added new function
function IsNumeric(sText)

{
   var ValidChars = "0123456789";
   var IsNumber = true;
   var Char;


	for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
            IsNumber = false;
         }
      }
      

	//alert ("so here we are " + sText + " "  + IsNumber);


   return IsNumber;
   
   }