<!--
var state = 'none';
var applydiscount = false;
function showhide(layer_ref) {

if (state == 'block') {
state = 'none';
}
else {
state = 'block';
}
if (document.all) { //IS IE 4 or 5 (or 6 beta)
eval( "document.all." + layer_ref + ".style.display = state");
}
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[layer_ref].display = state;
}
if (document.getElementById &&!document.all) {
hza = document.getElementById(layer_ref);
hza.style.display = state;
}
}

var rad_val="";

function get_radio_value()
{
for (var i=0; i < document.FormX.shiptype.length; i++)
   {
   if (document.FormX.shiptype[i].checked)
      {
       rad_val = document.FormX.shiptype[i].value;
     
      }
   }
}


function KYSalesTax(){
	var bookcost = 35;
	if (applydiscount ==true ){
		var mydisc = bookcost *.1;
		bookcost = bookcost - (mydisc);
		document.getElementById('discount').innerHTML='All pre-orders before December 15, 2009 will receive a 10% discount.<br>-$'+ formatCurrencyN(mydisc * document.FormX.myquantity.value);
		}
	var taxrate = .06;	
	var subtotal = bookcost * document.FormX.myquantity.value;
	document.getElementById('subtotal').innerHTML =  formatCurrencyN(subtotal) ;
 	var taxable = (subtotal) + parseInt(calculateShipping());
 	
 	document.FormX.transactionamount.value = formatCurrencyN(taxable);
	var mytax = taxable * taxrate;
	
	var newamt;
	if(document.FormX.state.value=='KY')  {
		alert('Kentucky residents will be assesed a 6% sales tax.');
		document.getElementById("kytax").innerHTML ="Kentucky Sales tax of $" +formatCurrencyN(mytax) +" is being added to your total.";
		newamt = taxable + mytax;
	}else{
	document.getElementById("kytax").innerHTML ="";
	newamt = taxable;
	}	
	document.FormX.transactionamount.value = formatCurrencyN(newamt) ;
	}
	
	
function calculateShipping(){
		var shipamt = 10;
		get_radio_value();
		 shipamt = rad_val;
		
	//document.getElementById('shippingamount').innerHTML=rad_val;
	
	
		shipamt = 	document.FormX.myquantity.value * shipamt;
		shipamt = formatCurrencyN(shipamt);
		//document.FormX.transactionamount.value = formatCurrencyN(parseInt(shipamt) + parseInt(myamt)) ;
		document.getElementById('shippingamount').innerHTML = shipamt;
		document.FormX.shippingamount.value = shipamt;
		
		return shipamt;
}

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   valid = false
		}

		else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   valid =  false
		}

	else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    valid =  false
		}

		else if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    valid =  false
		 }

		 else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    valid =  false
		 }

		 else if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    valid =  false
		 }
		
		 else if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    valid =  false
		 }

 		// valid =  true					
	}

function ValidateForm(){
	var emailID= document.FormX.email
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		valid= false
	}
	else if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		valid= false
	}
	
//	KySalesTax();
	//valid= true
 }



//--------------------------------------------------------------------------------
//    Function: isCreditCard(strInput)
// Description: Checks to see that the number passes the Luhn Mod-10 test
//       Input: strInput - the credit card number to be checked
//     Returns: true  - if field only contains proper characters
//              false - if credit card failed test
//  Disclaimer:	Skipjack Financial Services grants you a nonexclusive copyright license to use
//		this sample code from which you can generate similar function tailored to your own
//		specific needs.
//
//		This sample is provided by Skipjack Financial Services for illustrative purposes
//		only. It has not been thoroughly tested under all conditions. Skipjack, therefore,
//		cannot guarantee or imply reliability, serviceability, or function.
//
//		The sample code contained herein is provided to you "AS IS" without any	warranties 
//		of any kind. The implied warranties of non-infringement, merchantability and 
//		fitness for a particular purpose are expressly disclaimed.
//--------------------------------------------------------------------------------
function isCreditCard(strInput)
{
	// Encoding only works on cards with less than 19 digits	
	if (strInput.length > 19) valid= (false);  

	var sum = 0; 
	var mul = 1; 
	var l = strInput.length;
	
	for (i = 0; i < l; i++)
	{
		var digit    = strInput.substring(l-i-1,l-i);
    		var tproduct = parseInt(digit ,10) * mul;

	    	if (tproduct >= 10) 
		{ sum += (tproduct % 10) + 1; }
    		else
		{ sum += tproduct; }

    		if (mul == 1)       
		{ mul++; }
	    	else
		{ mul--; }
  	}	

  	if ((sum % 10) == 0) valid = true ;//return (true)
  	else                  
  	{
  	alert('The Credit Card Number is not valid.  Please try again.');
  //	return (false);
  valid = false;
  	}
}

function isNotBlank()
{
var myordernumber = Math.floor(Math.random()*111111111111101);

document.FormX.ordernumber.value = myordernumber;
valid = true;





if (document.FormX.sjname.value.length < 1)
{
  alert('Name is blank.  Please try again.'); valid = false; 
  }
  else if (document.FormX.streetaddress.value.length < 1) 
  {
  alert('Address is blank.  Please try again.');valid = false;
  }
  else if (document.FormX.city.value.length < 1) 
  {
  alert('City is blank.  Please try again.');valid = false;
  }
  else if (document.FormX.state.value.length < 1) 
  {
  alert('State is blank.  Please try again.');valid = false;
  }
      else if (document.FormX.zipcode.value.length < 1) 
  {
  alert('Zip Code is blank.  Please try again.');valid = false;
  }
      else if (document.FormX.shiptophone.value.length < 1) 
  {
  alert('Phone is blank.  Please try again.');valid = false;
  }
      else if (document.FormX.email.value.length < 1) 
  {
  alert('Email is blank.  Please try again.');valid = false;
  }
      else if (document.FormX.transactionamount.value < 1) 
  {
  alert('Amount is blank.  Please try again.');valid = false;
  }
      else if (document.FormX.accountnumber.value.length < 1) 
  {
  alert('Credit Card Number is blank.  Please try again.');valid = false;
  }
      else if (document.FormX.month.value.length < 1) 
  {
  alert('Month is blank.  Please try again.');valid = false;
  }
      else if (document.FormX.year.value.length < 1) 
  {
  alert('Year is blank.  Please try again.');valid = false;
  }
else 
{
isCreditCard(document.FormX.accountnumber.value);
}
 //Check if shipped to friend.
            if (document.FormX.isGift.checked) 
            {
                    if (document.FormX.ShipToName.value.length < 1) {
                      alert('Ship To Name is blank.  Please try again.');valid = false;
                    }
                    else if (document.FormX.ShipToAddress.value.length < 1) {
                      alert('Ship To Address is blank.  Please try again.');valid = false;
                    }
                    else if (document.FormX.ShipToCity.value.length < 1) {
                      alert('Ship To City is blank.  Please try again.');valid = false;
                    }
                    else if (document.FormX.ShipToState.value.length < 1) {
                      alert('Ship To State is blank.  Please try again.');valid = false;
                    }
                    else if (document.FormX.ShipToZipCode.value.length < 1) {
                      alert('Ship To Zip Code is blank.  Please try again.');valid = false;
                    }
                    else if (document.FormX.ShipToPhone.value.length < 1) {
                      alert('Ship To Telephone is blank.  Please try again.');valid = false;
                    }
            }

ValidateForm();

if (valid == true) {
if (confirm("Click OK to charge your Credit Card with your purchase.")){
    document.FormX.mySubmitButton.value = ('Please Wait...');
    document.FormX.mySubmitButton.disabled = true ;
    document.forms[0].submit();
    }
    else{
    valid = false;
    }
}
//if (confirm("Click OK to charge your Credit Card with the Gift Certificate purchase."))
//{}
return valid;
}

function BuildOrderString()
{
var os = "ItemNumber~itemDescription~ItemCost~Quantity~N~||";
os = ("GC~Jonathan at Gratz Park Gift Certificate~"+ document.FormX.transactionamount.value +"~1~N~||");
document.FormX.orderstring.value=os;
//alert(os);
}

function formatCurrency(obj)
{
       userVal=(obj.value.replace(/[^\d\.]/g, "")*1).toFixed(2);
       for(i=userVal.length-6;i>0;i-=3)
      userVal = userVal.substr(0,i)+","+userVal.substr(i)
       return userVal;

}


function formatCurrencyN(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '' + num + '.' + cents);
}

function discount(){

var now = new Date();
var then = new Date('12/15/2009');
if (now < then) {
	applydiscount = true;
}
else
{
	
		document.getElementById('discountmsg').innerHTML = '';
}

	}

function BuildBookString()
{
	//document.FormX.transactionamount.value = (document.FormX.myquantity.value * 35);
discount();
calculateShipping();
KYSalesTax();
//document.FormX.transactionamount.value = formatCurrency(document.FormX.transactionamount);
	
var os = "ItemNumber~itemDescription~ItemCost~Quantity~N~||";
os = ("BK~Jonathans Bluegrass Table~"+ formatCurrency(document.FormX.transactionamount) +"~"+ document.FormX.myquantity.value +"~N~||");
document.FormX.orderstring.value=os;
//alert(os);
}



/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Don Demrow |  */
function autoYear() {
  var time = new Date();
  var year = time.getYear();
 
  if (year < 1900) {
    year = year + 1900;
  }
//alert(year);
  var date = year; /*change the '25' to the number of years in the past you want to show */
  var future = year + 5; /*change the '10' to the number of years in the future you want to show */ 

  document.writeln ("<select name='year'><option value=\"\">--Choose--");
  do {
    
    document.write ("<option value=\"" +date+"\">" +date+ "");
    date++;
  }
  while (date < future)
  document.write ("</select>");
}





//-->
// JScript File

