//resets form boxes  and variables onLoad
function resetForm(){
totalPrice = 0;
totalTemp = 0;
piece0 = 0;
price0 = 0;
quan0 = 0;
tot0 = 0;
piece1 = 0;
price1 = 0;
quan1 = 0;
tot1 = 0;
piece2 = 0;
price2 = 0;
quan2 = 0;
tot2 = 0;
piece3 = 0;
price3 = 0;
quan3 = 0;
tot3 = 0;
piece4 = 0;
price4 = 0;
quan4 = 0;
tot4 = 0;
piece5 = 0;
price5 = 0;
quan5 = 0;
tot5 = 0;

document.forms[0].gTotal.value = '0';

for (i=0; i<100; i++)
	{piece[i] = 0;}


for (i=0; i<100; i++)
	{prod[i] = 0;}


 //variable for round
var totalPrice = 0;
	}

// given a numeral, makes a money-formatted figure:
function round(Number,Decimals,Separator)
{
 // Placed in the public domain by Affordable Production Tools
 // March 21, 1998
 // Web site: http://www.apt.simplenet.com
 Number += ""          // Force argument to string.
 Decimals += ""        // Force argument to string.
 Separator += ""       // Force argument to string.
 if((Separator == "") || (Separator.length > 1))
  Separator = "."
 if(Number.length == 0)
  Number = "0"
 var OriginalNumber = Number  // Save for number too large.
 var Sign = 1
 var Pad = ""
 var Count = 0
 if(parseFloat(Number)){
  Number = parseFloat(Number)} else {
  Number = 0}
 if((parseInt(Decimals,10)) || (parseInt(Decimals,10) == 0)){
  Decimals = parseInt(Decimals,10)} else {
  Decimals = 2}
 if(Number < 0)
 {
  Sign = -1         // Remember sign of Number.
  Number *= Sign    // Force absolute value of Number.
 }
 if(Decimals < 0)
  Decimals *= -1    // Force absolute value of Decimals.
 Number = "" + Math.floor(Number * Math.pow(10,Decimals + 1) + 5)
 if((Number.substring(1,2) == '.')||((Number + '')=='NaN'))
  return(OriginalNumber) // Number too large to format as specified.
 if(Number.length < Decimals +1) // Construct pad string.
 {
  for(Count = Number.length; Count <= Decimals; Count++)
   Pad += "0"
 }
 Number = Pad + Number // Pad number as needed.
 if(Decimals == 0){
  Number = Number.substring(0, Number.length -1)} else {
 Number = Number.substring(0,Number.length - Decimals -1) +
          Separator +
          Number.substring(Number.length - Decimals -1,
          Number.length -1)}
 if(Sign == -1)
  Number = "-" + Number  // Set sign of number.
 if(Number.length == 0)
  Number="0"
totalPrice = Number
 return(totalPrice)
}

//Checks if entry is a numeral:
function isNumber(inputStr){
	for (var i = 0; i < inputStr.length; i++){
		var oneChar = inputStr.substring(i, i + 1)
		if (oneChar < "0" || oneChar > "9") {
			return false;
		}
	}
	return true
}

//working with "isNumber" this changes a string to a numeral to see if it's a number:
//Is this neccesary???
function checkIt(formNum){
	inputStr = eval('document.forms[0].' + formNum + '.value');
	if (isNumber(inputStr)) {
		}
	else{
	alert("Please enter a numeral here");
	eval('document.forms[0].' + formNum + '.focus()');
	}
}

//Validates zip Code if it is an "ADD4" zip code:
function validateZip(t){
	t += "";
		if (t.substring(5,6)=="-" && t.length==10){
		}
		else if (t.length ==5){
		}
		else alert("You did not enter a proper zip code. Please enter a 5 digit zip code or a proper zip with 4 digit extension with a dash between the 5th and 6th numerals");
	}

//Checks 5-digit zip code:
function checkZip(formNum){
	inputStr = eval('document.forms[0].' + formNum + '.value');
	if (isNumber(inputStr)) {
		validateZip(eval('document.forms[0].' + formNum + '.value'));
		}
	else{
		var alertdone = 0;
		inputStr += "";
		if (inputStr.substring(5,6)=='-'){
			firstFive = parseFloat(inputStr.substring(0,5))
			secondFour = parseFloat(inputStr.substring(6,11))
				if ( (isNumber(inputStr.substring(0,5))) && (firstFive < 100000)){
					}
					else{
						alert("You did not enter a proper zip code.");
						alertdone = 1;
					}
				 if (alertdone==0){
			       if ((isNumber((inputStr.substring(6,11)))) && (secondFour < 10000) && (secondFour > 999)){
					}
	       else if ((isNumber(inputStr.substring(6,11))) && (secondFour < 1000) && (inputStr.substring(6,7)=='0')){
		}
			else alert("You did not enter a proper zip code. Please re-enter your 4 digit extension.");
				}
		}
			else alert("You did not enter a proper zip code. Please enter a 5 digit zip code or a proper zip with 4 digit extension");
			eval('document.forms[0].' + formNum + '.focus()');
		}
}


var piece = new Array(100);
for (i=0; i<100; i++)
	{piece[i] = 0;}

var prod = new Array(100);
for (i=0; i<100; i++)
	{prod[i] = 0;}


//sums up all products indicated:
function totalUp(){

	//loops thru each field and adds up prices:
	totalProd = 0;
	for (i=0; i<100; i++){
			if (prod[i]){
			totalTemp = prod[i];
			totalProd = totalProd + totalTemp;
			}
		}
	//sets grand total without sales tax:
	document.forms[0].gTotal.value= "$" + round(parseFloat(totalProd));
}

//takes addIn (form field),
//sets it to array index (i) and sets value by price:
//for 6 products
function addUp0(addIn){
prod[0] = eval((addIn).value * document.forms[0].price0.value);
piece[0] = document.forms[0].piece0.value;
document.forms[0].tot0.value= "$" + round(parseFloat(prod[0]));
totalUp();
}

function openPurch(){
	photo = window.open('http://www.theconnextion.com/index.cfm?ARTISTID=351&NoFrame=Yes', 'gsdsp1', 'resizable=1,toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1');
	photo.location.href = 'http://www.theconnextion.com/index.cfm?ARTISTID=351&NoFrame=Yes';
}

function addUp1(addIn){
prod[1] = eval((addIn).value * document.forms[0].price1.value);
piece[1] = document.forms[0].piece1.value;
document.forms[0].tot1.value= "$" + round(parseFloat(prod[1]));
totalUp();
}

function addUp2(addIn){
prod[2] = eval((addIn).value * document.forms[0].price2.value);
piece[2] = document.forms[0].piece2.value;
document.forms[0].tot2.value= "$" + round(parseFloat(prod[2]));
totalUp();
}

function addUp3(addIn){
prod[3] = eval((addIn).value * document.forms[0].price3.value);
piece[3] = document.forms[0].piece3.value;
document.forms[0].tot3.value= "$" + round(parseFloat(prod[3]));
totalUp();
}

function addUp4(addIn){
prod[4] = eval((addIn).value * document.forms[0].price4.value);
piece[4] = document.forms[0].piece4.value;
document.forms[0].tot4.value= "$" + round(parseFloat(prod[4]));
totalUp();
}

function addUp5(addIn){
prod[5] = eval((addIn).value * document.forms[0].price5.value);
piece[5] = document.forms[0].piece5.value;
document.forms[0].tot5.value= "$" + round(parseFloat(prod[5]));
totalUp();
}

function openPurch(){
photo = window.open('orderform.htm', 'bd1','top=25px,screenY=25px,resizable=1,toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,width=950px,height=750px,left=50px,screenX=50px');
	photo.location.href = 'orderform.htm';
}
