// JavaScript Document

/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Kevin Hartig :: http://www.grafikfx.net/ */

// Calculate the total for items in the form which are selected.
function calculateTotal(inputItem) {
  with (inputItem.form) {
    // Process each of the different input types in the form.
    if (inputItem.type == "radio") {   // Process radio buttons.
      // Subtract the previously selected radio button value from the total.
      calculatedTotal.value = eval(calculatedTotal.value) - eval(previouslySelectedRadioButton.value);
      // Save the current radio selection value.
      previouslySelectedRadioButton.value = eval(inputItem.value);
      // Add the current radio button selection value to the total.
      calculatedTotal.value = eval(calculatedTotal.value) + eval(inputItem.value);
    } else {   // Process check boxes.
      if (inputItem.checked == false) {   // Item was uncheck. Subtract item value from total.
          calculatedTotal.value = eval(calculatedTotal.value) - eval(inputItem.value);
      } else {   // Item was checked. Add the item value to the total.
          calculatedTotal.value = eval(calculatedTotal.value) + eval(inputItem.value);
      }
    }

    // Total value should never be less than 0.
    if (calculatedTotal.value < 0) {
      InitForm();
    }

    // Return total value.
    return(formatCurrency(calculatedTotal.value));
  }
}

// Format a value as currency.
function formatCurrency(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);
}

// This function initialzes all the form elements to default values.
function InitForm() {
  // Reset values on form.
  document.selectionForm.total.value='$0';
  document.selectionForm.calculatedTotal.value=0;
  document.selectionForm.previouslySelectedRadioButton.value=0;

  // Set all checkboxes and radio buttons on form to unchecked.
  for (i=0; i < document.selectionForm.elements.length; i++) {
    if (document.selectionForm.elements[i].type == 'checkbox' | document.selectionForm.elements[i].type == 'radio') {
      document.selectionForm.elements[i].checked = false;
    }
  }
}




<!--
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];}
}



<!-- Start hiding from older browsers. 
//  This JavaScript written by:  Todd Schacherl
//  Copyright 1997, 1998, 2003 Todd Schacherl
//  Contact at todds@zone0ne.com
//  Version: 2.1
//

//  This function displays the nag screen when a field hasn't been filled in.
/*function nag(form, field, x)
{       
        ufield=field.toUpperCase();
        alert("Oops... You didn't fill out the field " + ufield + "!" + "\n\nPlease fill in the field and submit the form again.");
        form.elements[x].focus();
} */

function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }
//-->
//  This function is used to round the tax amount to the nearest hundreths.
function roundPrice(price)
{
  //  save a copy of the price in case it is an even dollar amount.
  var workPrice = price;

  // Make the price a string by adding a string 0 to the end.
  workPrice  += "0"; 

  // Find out where the decimal point is.
  var pointIndex = workPrice.indexOf(".",0);

// If there is a decimal point now check to see if it needs to be rounded up.
if (pointIndex >= "0") {

  //  Set an index for the thousands digit.
  var thousands = pointIndex +3;

  // if the third number past the decimal point is greater than or 
  // equal to 5, then we need to round up the hundredth digit.
  if (workPrice.charAt(thousands) >= "5") 
  {
   //  Turn the price into a number.
   workPrice=parseFloat(price);
   
   //  Round up the price.
   workPrice=workPrice + .01;

   //  Turn it back into a string.
   workPrice=workPrice + "0";

   //  Cut off the thousands on down.
     rPrice = workPrice.substring(0,thousands);

   } else {

   //  We didn't need to round the price up so cut off the
   //  thousands on down and return the price
   rPrice = workPrice.substring(0,thousands);
   }

//  Its an even dollar amount so just put on the .00 on the end.
} else {
  rPrice = price + ".00";
}

 // Now return the rounded price.
 return rPrice;
}


//  This function calculates the form.
function updatePrice()
{
   //  Reset the subtotal price
   var addPrice = 0;

   //  Reset the running total prices.
   var nowPrice = 0;

   //  Reset the number of part ordered.
   var partcount = 0;

   //  Step through each element in the form.
   for (i = 0; i < parseInt(self.document.forms[0].elements.length); i++)
   {

      //  If the form element has "qty" in the name then we need to process it.
      if (self.document.forms[0].elements[i].name.substring(0,3) == 'qty')
      {

         // If the item has a quantity of not 0, then we need to process it.
         if (self.document.forms[0].elements[i].value != 0)
         {

			// Locate the cost
			costIndex = i + 1;

            //  Increment the part counter.
            partcount++;

            //  Get the actual value for the quantity.
            nowQty = eval(self.document.forms[0].elements[i].value);

            //  Get the cost of the item.
            nowPrice = eval(self.document.forms[0].elements[costIndex].value);

            //  Calculate the extended cost (i.e., quanty * cost).
            nowPrice = eval(nowPrice * nowQty);

	    //  Add to the subtotal.
            addPrice += nowPrice;
         }  
      }
   }

   //  Round off the subTotal price.
   subTotal=roundPrice(addPrice);

   //  Put the sub total price into the form.
   self.document.forms[0].subtot.value = subTotal;

   // Figure the tax.
   tax = parseFloat(self.document.forms[0].taxrate.value * addPrice);

   //  Round off the tax price.
   totalTax = roundPrice(tax);

   //  Put the total tax into the form.
   self.document.forms[0].totaltax.value = totalTax;


   // Start figuring the total including tax.
   //  Turn the price string into a number.
   subPrice =  parseFloat(addPrice);

   // Turn the tax string into a number.
   addTax = parseFloat(totalTax);

   //  Add the tax and subtotal to get the total price.
   totalPrice = (addTax + subPrice);

   //  Round the total price.
   finalPrice = roundPrice(totalPrice);

   //  Update the form with the total cost.
   self.document.forms[0].cost.value = finalPrice;

   //  Update the form with the number of line items.
   self.document.forms[0].items.value = partcount;
}

function orderIt(form)
{
  //  If the order is zero, display a message.
  if (form.cost.value == "0.00")
  {
      alert("You have not ordered anything.  Please select an item and re-submit your order.")
  } else {

    if (form.elements[0].value == "")
        {
                nag(form, form.elements[0].name,0)
        } else if (form.elements[1].value == "")
        {
                nag(form, form.elements[1].name, 1)
        } else if (form.elements[2].value == "")
        {
                nag(form, form.elements[2].name, 2)
        } else if (form.elements[4].value == "")
        {
        nag(form, form.elements[4].name, 4);
        } else if (form.elements[5].value == "")
        {
        nag(form, form.elements[5].name, 5);
        } else if (form.elements[6].value == "")
        {
        nag(form, form.elements[6].name, 6);
        } else if (form.elements[10].value == "")
        {
        nag(form, form.elements[10].name, 10);

     } else {
   var message = "You have ordered the following items:\n";
   message = message + "Qty\tPart Num\tDescription\n";

   // Step through each element in the form.
   for (i = 0; i < parseInt(self.document.forms[0].elements.length); i++)
   {

      //  If the form element has "qty" in the name then we need to process it.
      if (self.document.forms[0].elements[i].name.substring(0,3) == 'qty' && self.document.forms[0].elements[i].value !=0)
      {

         //  Get the quantity.
         qtyItem = self.document.forms[0].elements[i].value; 

		 partItem = self.document.forms[0].elements[i-2].value;
   
         //  Get the description.
         descItem = self.document.forms[0].elements[i-1].value;

         //  add the line item to the confirmation message.
         message = message + qtyItem + "\t" + partItem + "\t" + descItem + "\n";
      }
      
   }

    message = message + "\nOrder total: $" + self.document.forms[0].cost.value
	if (confirm(message)) 
	{ 
	self.document.forms[0].submit();
	}
      }
   }
}
// end hiding from older browsers -->




//-->

// Set slideShowSpeed (milliseconds)

var slideShowSpeed = 5000



// Duration of crossfade (seconds)

var crossFadeDuration = 3



// Specify the image files

var Pic = new Array() // don't touch this

// to add more images, just continue

// the pattern, adding to the array below



Pic[0] = 'images/ss_table1_03.jpg'

Pic[1] = 'images/ss_dreamon_03.jpg'

Pic[2] = 'images/ss_childhood_03.jpg'

Pic[3] = 'images/ss_911_03.jpg'

Pic[4] = 'images/ss_table2_03.jpg'

Pic[5] = 'images/ss_box_03.jpg'

Pic[6] = 'images/ss_mirror_03.jpg'

Pic[7] = 'images/ss_bread_03.jpg'

Pic[8] = 'images/ss_juliana.jpg'




// =======================================

// do not edit anything below this line

// =======================================



var t

var j = 0

var p = Pic.length



var preLoad = new Array()

for (i = 0; i < p; i++){

   preLoad[i] = new Image()

   preLoad[i].src = Pic[i]

}



function runSlideShow(){

   if (document.all){

      document.images.SlideShow.style.filter="blendTrans(duration=2)"

      document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)"

      document.images.SlideShow.filters.blendTrans.Apply()      

   }

   document.images.SlideShow.src = preLoad[j].src

   if (document.all){

      document.images.SlideShow.filters.blendTrans.Play()

   }

   j = j + 1

   if (j > (p-1)) j=0

   t = setTimeout('runSlideShow()', slideShowSpeed)

}


