<!--
// ColdFusion JavaScript functions for cfform client-side validation

var _CF_loaded=0;

function _CF_signalLoad()
{
	_CF_loaded = 1;
}


function _CF_onError(form_object, input_object, object_value, error_message)
{
	alert(error_message);
	return false;	
}


function _CF_hasValue(obj, obj_type)
{
	if (obj_type == "TEXT" || obj_type == "PASSWORD")
	{
		if (obj.value.length == 0) 
	  		return false;
		else 
	  		return true;
	}
	else if (obj_type == "SELECT")
	{
		for (i=0; i < obj.length; i++)
		{
			if (obj.options[i].selected)
				return true;
		}
	   	return false;	
	}
	else if (obj_type == "SINGLE_VALUE_RADIO" || obj_type == "SINGLE_VALUE_CHECKBOX")
	{
		if (obj.checked)
			return true;
		else
	   		return false;	
	}
	else if (obj_type == "RADIO" || obj_type == "CHECKBOX")
	{
		for (i=0; i < obj.length; i++)
		{
			if (obj[i].checked)
				return true;
		}
	   	return false;	
	}
}


function _CF_checkdate(object_value)
{
	if (object_value.length == 0)
		return true;

	isplit = object_value.indexOf('/');

	if (isplit == -1 || isplit == object_value.length)
		return false;

	sMonth = object_value.substring(0, isplit);

	if (sMonth.length == 0)
		return false;

	isplit = object_value.indexOf('/', isplit + 1);

	if (isplit == -1 || (isplit + 1 ) == object_value.length)
		return false;

	sDay = object_value.substring((sMonth.length + 1), isplit);

	if (sDay.length == 0)
		return false;

	sYear = object_value.substring(isplit + 1);

	if (!_CF_checkinteger(sMonth))
		return false;
	else if (!_CF_checkrange(sMonth, 1, 12))
		return false;
	else if (!_CF_checkinteger(sYear))
		return false;
	else if (!_CF_checkrange(sYear, 0, 9999))
		return false;
	else if (!_CF_checkinteger(sDay))
		return false;
	else if (!_CF_checkday(sYear, sMonth, sDay))
		return false;
	else
		return true;
}


function _CF_checkeurodate(object_value)
{
	if (object_value.length == 0)
		return true;

	isplit = object_value.indexOf('/');

	if (isplit == -1)
		isplit = object_value.indexOf('.');

	if (isplit == -1 || isplit == object_value.length)
		return false;

	sDay = object_value.substring(0, isplit);

	monthSplit = isplit + 1;

	isplit = object_value.indexOf('/', monthSplit);

	if (isplit == -1)
		isplit = object_value.indexOf('.', monthSplit);

	if (isplit == -1 ||  (isplit + 1 )  == object_value.length)
		return false;

	sMonth = object_value.substring((sDay.length + 1), isplit);

	sYear = object_value.substring(isplit + 1);

	if (!_CF_checkinteger(sMonth))
		return false;
	else
	if (!_CF_checkrange(sMonth, 1, 12))
		return false;
	else
	if (!_CF_checkinteger(sYear))
		return false;
	else
	if (!_CF_checkrange(sYear, 0, null))
		return false;
	else
	if (!_CF_checkinteger(sDay))
		return false;
	else
	if (!_CF_checkday(sYear, sMonth, sDay))
		return false;
	else
		return true;
}


function _CF_checkday(checkYear, checkMonth, checkDay)
{
	maxDay = 31;

	if (checkMonth == 4 || checkMonth == 6 ||
		checkMonth == 9 || checkMonth == 11)
		maxDay = 30;
	else if (checkMonth == 2)
	{
		if (checkYear % 4 > 0)
			maxDay =28;
		else if (checkYear % 100 == 0 && checkYear % 400 > 0)
			maxDay = 28;
		else
			maxDay = 29;
	}

	return _CF_checkrange(checkDay, 1, maxDay);
}


function _CF_checkinteger(object_value)
{
	if (object_value.length == 0)
		return true;

	var decimal_format = ".";
	var check_char = object_value.indexOf(decimal_format);

	if (check_char == -1)
		return _CF_checknumber(object_value);
	else
		return false;
}


function _CF_numberrange(object_value, min_value, max_value)
{
	if (min_value != null)
	{
		if (object_value < min_value)
			return false;
	}

	if (max_value != null)
	{
		if (object_value > max_value)
			return false;
	}

	return true;
}


function _CF_checknumber(object_value)
{
	if (object_value.length == 0)
		return true;

	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;

	check_char = start_format.indexOf(object_value.charAt(0));

	if (check_char == 1)
		decimal = true;
	else if (check_char < 1)
		return false;

	for (var i = 1; i < object_value.length; i++)
	{
		check_char = number_format.indexOf(object_value.charAt(i));
		if (check_char < 0)
			return false;
		else if (check_char == 1)
		{
			if (decimal)
				return false;
			else
				decimal = true;
		}
		else if (check_char == 0)
		{
			if (decimal || digits)	
				trailing_blank = true;
		}
		else if (trailing_blank)
			return false;
		else
			digits = true;
	}	

	return true
}


function _CF_checkrange(object_value, min_value, max_value)
{
	if (object_value.length == 0)
		return true;

	if (!_CF_checknumber(object_value))
		return false;
	else
		return (_CF_numberrange((eval(object_value)), min_value, max_value));

	return true;
}


function _CF_checktime(object_value)
{
	if (object_value.length == 0)
		return true;

	isplit = object_value.indexOf(':');

	if (isplit == -1 || isplit == object_value.length)
		return false;

	sHour = object_value.substring(0, isplit);
	iminute = object_value.indexOf(':', isplit + 1);

	if (iminute == -1 || iminute == object_value.length)
		sMin = object_value.substring((sHour.length + 1));
	else
		sMin = object_value.substring((sHour.length + 1), iminute);

	if (!_CF_checkinteger(sHour))
		return false;
	else if (!_CF_checkrange(sHour, 0, 23))
		return false;

	if (!_CF_checkinteger(sMin))
		return false;
	else
	if (!_CF_checkrange(sMin, 0, 59))
		return false;

	if (iminute != -1)
	{
		sSec = object_value.substring(iminute + 1);

		if (!_CF_checkinteger(sSec))
			return false;
		else if (!_CF_checkrange(sSec, 0, 59))
			return false;	
	}

	return true;
}


function _CF_checkphone(object_value)
{
	if (object_value.length == 0)
		return true;

	if (object_value.length != 12)
		return false;

	if (!_CF_checknumber(object_value.substring(0,3)))
		return false;
	else if (!_CF_numberrange((eval(object_value.substring(0,3))), 100, 1000))
		return false;

	if (object_value.charAt(3) != "-" && object_value.charAt(3) != " ")
		return false

	if (!_CF_checknumber(object_value.substring(4,7)))
		return false;
	else if (!_CF_numberrange((eval(object_value.substring(4,7))), 100, 1000))
		return false;

	if (object_value.charAt(7) != "-" && object_value.charAt(7) != " ")
		return false;

	if (object_value.charAt(8) == "-" || object_value.charAt(8) == "+")
		return false;
	else
		return (_CF_checkinteger(object_value.substring(8,12)));
}


function _CF_checkzip(object_value)
{
	if (object_value.length == 0)
		return true;

	if (object_value.length != 5 && object_value.length != 10)
		return false;

	if (object_value.charAt(0) == "-" || object_value.charAt(0) == "+")
		return false;

	if (!_CF_checkinteger(object_value.substring(0,5)))
		return false;

	if (object_value.length == 5)
		return true;

	if (object_value.charAt(5) != "-" && object_value.charAt(5) != " ")
		return false;

	if (object_value.charAt(6) == "-" || object_value.charAt(6) == "+")
		return false;

	return (_CF_checkinteger(object_value.substring(6,10)));
}


function _CF_checkcreditcard(object_value)
{
	if (object_value.length == 0)
		return true;
	var white_space = " -";
	var creditcard_string="";
	var check_char;

	for (var i = 0; i < object_value.length; i++)
	{
		check_char = white_space.indexOf(object_value.charAt(i));
		if (check_char < 0)
			creditcard_string += object_value.substring(i, (i + 1));
	}	

	if (creditcard_string.length < 13 || creditcard_string.length > 19)
		return false;

	if (creditcard_string.charAt(0) == "+")
		return false;

	if (!_CF_checkinteger(creditcard_string))
		return false;

	var doubledigit = creditcard_string.length % 2 == 1 ? false : true;
	var checkdigit = 0;
	var tempdigit;

	for (var i = 0; i < creditcard_string.length; i++)
	{
		tempdigit = eval(creditcard_string.charAt(i));

		if (doubledigit)
		{
			tempdigit *= 2;
			checkdigit += (tempdigit % 10);

			if ((tempdigit / 10) >= 1.0)
				checkdigit++;

			doubledigit = false;
		}
		else
		{
			checkdigit += tempdigit;
			doubledigit = true;
		}
	}	
	return (checkdigit % 10) == 0 ? true : false;
}


function _CF_checkssc(object_value)
{
	var white_space = " -+.";
	var ssc_string="";
	var check_char;

	if (object_value.length == 0)
		return true;

	if (object_value.length != 11)
		return false;

	if (object_value.charAt(3) != "-" && object_value.charAt(3) != " ")
		return false;

	if (object_value.charAt(6) != "-" && object_value.charAt(6) != " ")
		return false;

	for (var i = 0; i < object_value.length; i++)
	{
		check_char = white_space.indexOf(object_value.charAt(i));
		if (check_char < 0)
			ssc_string += object_value.substring(i, (i + 1));
	}

	if (ssc_string.length != 9)
		return false;

	if (!_CF_checkinteger(ssc_string))
		return false;

	return true;
}


function _CF_setFormParam( strFormName, strParamName, strParamValue )
{
	var strObjName = "document." + strFormName + "." + strParamName;
	var obj = eval( strObjName );
	obj.value = strParamValue;
	return true;
}


function _CF_checkregex(object_value, regex)
{
	return regex.test(object_value);
}


function  _CF_checkorder(_CF_this)
{
	if  (!_CF_hasValue(_CF_this.amount, "TEXT" ))
	{
		if  (!_CF_onError(_CF_this, _CF_this.amount, _CF_this.amount.value, "Please complete the 'gift card amount' field"))
		{
			return false;
		}
	}


	if  (!_CF_hasValue(_CF_this.recipient_name, "TEXT" ))
	{
		if  (!_CF_onError(_CF_this, _CF_this.recipient_name, _CF_this.recipient_name.value, "Please complete the 'recipient name' field"))
		{
			return false;
		}
	}

	if  (!_CF_hasValue(_CF_this.address, "TEXT" ))
	{
		if  (!_CF_onError(_CF_this, _CF_this.address, _CF_this.address.value, "Please complete the 'address' field"))
		{
			return false;
		}
	}

	if  (!_CF_hasValue(_CF_this.city, "TEXT" ))
	{
		if  (!_CF_onError(_CF_this, _CF_this.city, _CF_this.city.value, "Please complete the 'city' field"))
		{
			return false;
		}
	}

	if  (!_CF_hasValue(_CF_this.state, "TEXT" ))
	{
		if  (!_CF_onError(_CF_this, _CF_this.state, _CF_this.state.value, "Please complete the 'state' field"))
		{
			return false;
		}
	}

	if  (!_CF_hasValue(_CF_this.zip, "TEXT" ))
	{
		if  (!_CF_onError(_CF_this, _CF_this.zip, _CF_this.zip.value, "Please complete the 'zip' field"))
		{
			return false;
		}
	}

	/* if  (!_CF_hasValue(_CF_this.email, "TEXT" ))
	{
		if  (!_CF_onError(_CF_this, _CF_this.email, _CF_this.email.value, "Please complete the 'email' field"))
		{
			return false;
		}
	} */
	

	if  (!_CF_hasValue(_CF_this.phone, "TEXT" ))
	{
		if  (!_CF_onError(_CF_this, _CF_this.phone, _CF_this.phone.value, "Please complete the 'telephone' field"))
		{
			return false;
		}
	}

	if  (!_CF_hasValue(_CF_this.billname, "TEXT" ))
	{
		if  (!_CF_onError(_CF_this, _CF_this.billname, _CF_this.billname.value, "Please complete the 'billing name' field"))
		{
			return false;
		}
	}

	if  (!_CF_hasValue(_CF_this.ccno, "TEXT" ))
	{
		if  (!_CF_onError(_CF_this, _CF_this.ccno, _CF_this.ccno.value, "Please complete the 'Credit Card' field"))
		{
			return false;
		}
	}

	if  (!_CF_hasValue(_CF_this.ccexp, "TEXT" ))
	{
		if  (!_CF_onError(_CF_this, _CF_this.ccexp, _CF_this.ccexp.value, "Please complete the 'expiration' field"))
		{
			return false;
		}
	}
	
	if  (!_CF_hasValue(_CF_this.billemail, "TEXT" ))
	{
		if  (!_CF_onError(_CF_this, _CF_this.billemail, _CF_this.billemail.value, "Please complete the 'billing email' field"))
		{
			return false;
		}
	}
	
}


/* 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";
	}
}

//-->
