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 getShirtIndex(form){
	style = form.Style.selectedIndex
	color = form.Color.selectedIndex
	if (style == 1){
		if (color == 1){
			shirtIndex = 1;
		}else{
		if (color == 2){
			shirtIndex = 2;
		}}
	}else{
	if (style == 2){
		if (color == 1){
			shirtIndex = 3;
		}else{
		if (color == 2){
			shirtIndex = 4;
		}}
}}
return shirtIndex;
}

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 = getShirtIndex(form);
		thisAdultShirtPrice = adultShirtPrice[index];
		shirtMarkup = getMarkup(form.quanitity.value);
		quanit = form.quanitity.value;
		
		for (pp = 1; pp < 7; pp++){
			printingPrice[pp] = getPrintingPrice(quanit, pp, form);
		}
		for (b = 1; b < 7; b++){
			aelement = 2 + b;
			if (thisAdultShirtPrice == "NA"){
				form.elements[aelement].value = "NA";
			}else{
				aShirt = parseFloat(thisAdultShirtPrice);
				aPrice = (aShirt * shirtMarkup) + printingPrice[b];
				aFinnalPrice = roundOff(aPrice);
				form.elements[aelement].value = aFinnalPrice;
			}
		}		
	}
}	

var printingPrice = new creatArray(6);

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

var lightPrice = new creatArray(6);
lightPrice[1] = .23;
lightPrice[2] = .26;
lightPrice[3] = .30;
lightPrice[4] = .43;
lightPrice[5] = .67;
lightPrice[6] = 1.00;

var darkPrice = new creatArray(6);
darkPrice[1] = .33;
darkPrice[2] = .50;
darkPrice[3] = .71;
darkPrice[4] = .92;
darkPrice[5] = 1.20;
darkPrice[6] = 1.80;

var adultShirtPrice = new creatArray(4);
adultShirtPrice[1] = "3.80";   // Style 4200 -- color 1
adultShirtPrice[2] = "3.80";   // Style 4200 -- color 2
adultShirtPrice[3] = "4.90";   // Style 4350 -- color 1
adultShirtPrice[4] = "4.90";   // Style 4350 -- color 2

