function isPosInterger(inputVal){
	inputStr = inputVal.toString()
	for (var i = 0; i < inputStr.length; i++){
		var oneChar = inputStr.charAt(i)
		if (oneChar < "0" || oneChar > "9"){
		return false
		}
	}
	return true
}

function inRange(inputStr){
	num = parseInt(inputStr)
	if (num < 24){
		return false
	}
	return true
}

function getCapIndex(form){
	style = form.Style.selectedIndex
	if (style == 1){
		capIndex = 1;
	}else{
	if (style == 2){
		capIndex = 2;
	}}
return capIndex;
}

function getMarkup(quanitityStr){
	quanitity = parseInt(quanitityStr)
	if (quanitity > 1199){
		markup = 1.30										
		return markup
	}else{
	if (quanitity > 599){
		markup = 1.35								
		return markup
	}else{
	if (quanitity > 299){
		markup = 1.40									
		return markup
	}else{
	if (quanitity > 143){
		markup = 1.45								
		return markup
	}else{
	if (quanitity > 71){
		markup = 1.50								
		return markup
	}else{
	if (quanitity > 35){
		markup = 1.55									
		return markup
	}else{
	markup = 1.60									
	return markup
	}
}}}
}}
}

function checkInput(form){
	if (form.Style.selectedIndex == 0){
		alert("Please select a Style before calculating")
		return false
	}else{
	if (form.Color.selectedIndex == 0){
		alert ("Please select a Color Catagory before calculating")
		return false
	}else{
	if (form.quanitity.value == ""){
		alert ("Please enter a Quantity before calculating")
		return false
	}else{
	if (!isPosInterger(form.quanitity.value)){
		alert ("Please make sure you enter the quanitity in numbers")
		return false
	}else{
	if (!inRange(form.quanitity.value)){
		alert ("The minimum quanitity is 24")
		return false
	}
}}
}}
return true
}

function roundOff(amount){

   var cents = "" + Math.round(amount * 100)
   var dollars = cents.substring(0, cents.length-2)
   cents = cents.substring(cents.length-2, cents.length)
   amount = dollars + "." + cents
   return amount
}

function getPrintingPrice(quanitity, loop, form){
	if(form.Color.selectedIndex == 1){
		setup = setupPrice[loop];
		price = lightPrice[loop];
		quan = parseInt(quanitity);
		printPrice = (setup / quan) + price;				
		return printPrice;
	}else{
		setup = setupPrice[loop];
		price = darkPrice[loop];
		quan = parseInt(quanitity);
		printPrice = (setup / quan) + price;
		return printPrice;
	}
}

function creatArray(size){
	this.length = size;
	for (var i = 1; i <= size; i++){
		this[i] = null;
	}
	return this;
}

function fillPrices(form){
	if (!checkInput(form)){
		return;
	}else{										
		index = getCapIndex(form);
		thisCapPrice = CapPrice[index];
		capMarkup = getMarkup(form.quanitity.value);
		quanit = form.quanitity.value;
		for (pp = 1; pp < 5; pp++){
			printingPrice[pp] = getPrintingPrice(quanit, pp, form);
		}
		for (b = 1; b < 5; b++){
			element = 2 + b;
			if (thisCapPrice == "NA"){
				form.elements[element].value = "NA";
			}else{
				Cap = parseFloat(thisCapPrice);
				Price = (Cap * capMarkup) + printingPrice[b];
				FinnalPrice = roundOff(Price);
				form.elements[element].value = FinnalPrice;
			}
		}		
	}
}	

var printingPrice = new creatArray(4);

var setupPrice = new creatArray(4);
setupPrice[1] = 17.40;
setupPrice[2] = 34.80;
setupPrice[3] = 54.60;
setupPrice[4] = 84.00;

var lightPrice = new creatArray(4);
lightPrice[1] = .50;
lightPrice[2] = .60;
lightPrice[3] = .86;
lightPrice[4] = 1.09;

var darkPrice = new creatArray(4);
darkPrice[1] = .63;
darkPrice[2] = .86;
darkPrice[3] = 1.09;
darkPrice[4] = 1.50;

var CapPrice = new creatArray(2);
CapPrice[1] = "1.00";   // Foam/Mesh
CapPrice[2] = "1.33";   // Cotton/Twill

