function IsNumeric(field){
  var result = /^\d*$/.test(field.value);
  if(!result){ alert("Please enter a numerical value for the quantity field"); field.value = "";field.focus();}
  return result;
}

/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: David Leppek :: https://www.azcode.com/Mod10

Basically, the alorithum takes each digit, from right to left and muliplies each second
digit by two. If the multiple is two-digits long (i.e.: 6 * 2 = 12) the two digits of
the multiple are then added together for a new number (1 + 2 = 3). You then add up the 
string of numbers, both unaltered and new values and get a total sum. This sum is then
divided by 10 and the remainder should be zero if it is a valid credit card. Hense the
name Mod 10 or Modulus 10. */
function Mod10(ccNumb) {  // v2.0
var valid = "0123456789"  // Valid digits in a credit card number
var len = ccNumb.length;  // The length of the submitted cc number
var iCCN = parseInt(ccNumb);  // integer of ccNumb
var sCCN = ccNumb.toString();  // string of ccNumb
sCCN = sCCN.replace (/^\s+|\s+$/g,'');  // strip spaces
var iTotal = 0;  // integer total set at zero
var bNum = true;  // by default assume it is a number
var bResult = false;  // by default assume it is NOT a valid cc
var temp;  // temp variable for parsing string
var calc;  // used for calculation of each digit

// Determine if the ccNumb is in fact all numbers
for (var j=0; j<len; j++) {
  temp = "" + sCCN.substring(j, j+1);
  if (valid.indexOf(temp) == "-1"){bNum = false;}
}

// if it is NOT a number, you can either alert to the fact, or just pass a failure
if(!bNum){
  /*alert("Not a Number");*/bResult = false;
}

// Determine if it is the proper length 
if((len == 0)&&(bResult)){  // nothing, field is blank AND passed above # check
  bResult = false;
} else{  // ccNumb is a number and the proper length - let's see if it is a valid card number
  if(len >= 15){  // 15 or 16 for Amex or V/MC
    for(var i=len;i>0;i--){  // LOOP throught the digits of the card
      calc = parseInt(iCCN) % 10;  // right most digit
      calc = parseInt(calc);  // assure it is an integer
      iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit
      i--;  // decrement the count - move to the next digit in the card
      iCCN = iCCN / 10;                               // subtracts right most digit from ccNumb
      calc = parseInt(iCCN) % 10 ;    // NEXT right most digit
      calc = calc *2;                                 // multiply the digit by two
      // Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
      // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
      switch(calc){
        case 10: calc = 1; break;       //5*2=10 & 1+0 = 1
        case 12: calc = 3; break;       //6*2=12 & 1+2 = 3
        case 14: calc = 5; break;       //7*2=14 & 1+4 = 5
        case 16: calc = 7; break;       //8*2=16 & 1+6 = 7
        case 18: calc = 9; break;       //9*2=18 & 1+8 = 9
        default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers
      }                                               
    iCCN = iCCN / 10;  // subtracts right most digit from ccNum
    iTotal += calc;  // running total of the card number as we loop
  }  // END OF LOOP
  if ((iTotal%10)==0){  // check to see if the sum Mod 10 is zero
    bResult = true;  // This IS (or could be) a valid credit card number.
  } else {
    bResult = false;  // This could NOT be a valid credit card number
    }
  }
}
// change alert to on-page display or other indication as needed.
//if(bResult) {
//  alert("This IS a valid Credit Card Number!");
//}
if(!bResult){
  alert("This is not a valid Credit Card Number, Please re-enter.");
  document.forms.order.ccno.value = "";document.forms.order.ccno.focus();
}
  return bResult; // Return the results
}

function checkLuhn(input)
  {
    var sum = 0;
    var numdigits = input.length;
    var parity = numdigits % 2;
    for(var i=0; i < numdigits; i++) {
      var digit = parseInt(input[i])
      if(i % 2 == parity) digit *= 2;
      if(digit > 9) digit -= 9;
      sum += digit;
    }
    return (sum % 10) == 0;
  }

function toggleLayer(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
}

////////////////////////////////////////////////////////////////////////////
///image switching functions////////////////////////////////////////////////

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

////////////////////////////////////////////////////////////////////////////
///image preloading/////////////////////////////////////////////////////////

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		nav_home_on = newImage("../images/nav_home_on.gif");
		nav_story_on = newImage("../images/nav_story_on.gif");
		nav_hm_story_on = newImage("../images/nav_hm_story_on.gif");
		nav_hm_wines_on = newImage("../images/nav_hm_wines_on.gif");
		nav_hm_peggy_on = newImage("../images/nav_hm_peggy_on.gif");
		nav_hm_causes_on = newImage("../images/nav_hm_causes_on.gif");
		nav_hm_latest_on = newImage("../images/nav_hm_latest_on.gif");
		nav_hm_contact_on = newImage("../images/nav_hm_contact_on.gif");
		nav_L2_wines_main1_on = newImage("../images/nav_L2_wines_main1_on.gif");
		nav_L2_wines_main2_on = newImage("../images/nav_L2_wines_main2_on.gif");
		nav_L2_wines_main3_on = newImage("../images/nav_L2_wines_main3_on.gif");
		nav_L2_causes_main_on = newImage("../images/nav_L2_causes_main_on.gif");
		nav_L2_latest_main_on = newImage("../images/nav_L2_latest_main_on.gif");
		nav_L2_story_main_on = newImage("../images/nav_L2_story_main_on.gif");
		preloadFlag = true;
	}
}

////////////////////////////////////////////////////////////////////////////
//function for css nn fix///////////////////////////////////////////////////

function WM_netscapeCssFix() {

  if (document.WM.WM_netscapeCssFix.initWindowWidth != window.innerWidth || document.WM.WM_netscapeCssFix.initWindowHeight != window.innerHeight) {
    document.location = document.location;
  }
}

function WM_netscapeCssFixCheckIn() {
  // This function checks to make sure the version of Netscape 
  // in use contains the bug; if so, it records the window's 
  // width and height and sets all resize events to be handled 
  // by the WM_netscapeCssFix() function.
  if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4)) {
    if (typeof document.WM == 'undefined'){
      document.WM = new Object;
    }
    if (typeof document.WM.WM_scaleFont == 'undefined') {
      document.WM.WM_netscapeCssFix = new Object;
      document.WM.WM_netscapeCssFix.initWindowWidth = window.innerWidth;
      document.WM.WM_netscapeCssFix.initWindowHeight = window.innerHeight;
    }
    window.onresize = WM_netscapeCssFix;
  }
}

WM_netscapeCssFixCheckIn()

var newwin;
function launchwin(winurl,winname,winfeatures)
{
       //This launches a new window and then
       //focuses it if window.focus() is supported.
       newwin = window.open(winurl,winname,winfeatures);
       if(javascript_version > 1.0)
       {
               //delay a bit here because IE4 encounters errors
               //when trying to focus a recently opened window
               setTimeout('newwin.focus();',250);
       }
}


//end of file///////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////