// JavaScript Document
function validate(){

if(document.calculate.fname.value == ""){
		alert("Please fill Full Name");
		document.calculate.fname.focus();
		document.calculate.fname.select();
		return false;	
	}	
if(document.calculate.phone.value == ""){
		alert("Please fill Phone Number");
		document.calculate.phone.focus();
		document.calculate.phone.select();
		return false;	
	}
if(document.calculate.email.value == ""){
		alert("Please fill Email");
		document.calculate.email.focus();
		document.calculate.email.select();
		return false;	
	}

if(document.calculate.email.value != "" ){	
				var EmailOk  = true
				var Temp     = document.calculate.email.value
				var AtSym    = Temp.indexOf('@')
				var Period   = Temp.lastIndexOf('.')
				var Space    = Temp.indexOf(' ')
				var Length   = Temp.length - 1   // Array is from 0 to length-1

				if ((AtSym < 1) ||                     // '@' cannot be in first position
	    		(Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
	    		(Period == Length ) ||             // Must be atleast one valid char after '.'
	    		(Space  != -1))                    // No empty spaces permitted
	   		{
	    		  EmailOk = false;
	    		  alert('Please enter a valid e-mail address.');
				  document.calculate.email.focus();
				  document.calculate.email.select();
				  if(EmailOk == false)
	    		  return EmailOk;
	   	}
	}	

}
function calculateColorPrice(t){
	var qty=new Array(9);
	for(var i=0; i<9; i++)
	{
		qty[i] = new Array(6);	
	}

	qty[0][0] = 4.00;	qty[0][1] = 4.50;	qty[0][2] = 5.40;	qty[0][3] = 7.20;	qty[0][4] = 9.00;	qty[0][5] = 10.80;
	qty[1][0] = 3.60;	qty[1][1] = 3.90;	qty[1][2] = 4.50;	qty[1][3] = 5.60;	qty[1][4] = 7.00;	qty[1][5] = 8.30;
	qty[2][0] = 2.50;	qty[2][1] = 3.00;	qty[2][2] = 3.60;	qty[2][3] = 4.60;	qty[2][4] = 5.60;	qty[2][5] = 6.80;
	qty[3][0] = 1.70;	qty[3][1] = 2.10;	qty[3][2] = 2.60;	qty[3][3] = 3.20;	qty[3][4] = 4.00;	qty[3][5] = 4.60;
	qty[4][0] = 1.50;	qty[4][1] = 1.90;	qty[4][2] = 2.30;	qty[4][3] = 2.80;	qty[4][4] = 3.40;	qty[4][5] = 3.90;	
	qty[5][0] = 1.30;	qty[5][1] = 1.50;	qty[5][2] = 1.80;	qty[5][3] = 2.10;	qty[5][4] = 2.50;	qty[5][5] = 2.90;	
	qty[6][0] = 1.10;	qty[6][1] = 1.30;	qty[6][2] = 1.50;	qty[6][3] = 1.70;	qty[6][4] = 2.00;	qty[6][5] = 2.30;	
	qty[7][0] = 1.00;	qty[7][1] = 1.20;	qty[7][2] = 1.40;	qty[7][3] = 1.60;	qty[7][4] = 1.80;	qty[7][5] = 2.10;	
	qty[8][0] = 0.80;	qty[8][1] = 1.00;	qty[8][2] = 1.20;	qty[8][3] = 1.40;	qty[8][4] = 1.70;	qty[8][5] = 2.00;

	t=t-1;
	var quantity = document.qoute.quantity.value;
	//alert ("quantity in function " + quantity);
	//alert ("color value in function " + t);alert("test price " + qty[0][t]);
	
	/*
	if( quantity>11 && quantity<24)			alert(qty[0][t]);
	else if( quantity>23 && quantity<36)		alert(qty[1][t]);
	else if( quantity>35 && quantity<72)		alert(qty[2][t]);
	else if( quantity>71 && quantity<144)		alert(qty[3][t]);
	else if( quantity>143 && quantity<288)	alert(qty[4][t]);
	else if( quantity>287 && quantity<500)	alert(qty[5][t]);
	else if( quantity>499 && quantity<1000)	alert(qty[6][t]);
	else if( quantity>999 && quantity<2000)	alert(qty[7][t]);
	else if( quantity>1999)					alert(qty[8][t]);*/


	if( quantity>=12 && quantity<=23)			return qty[0][t];
	else if( quantity>=24 && quantity<=35)		return qty[1][t];
	else if( quantity>=36 && quantity<=71)		return qty[2][t];
	else if( quantity>=72 && quantity<=143)		return qty[3][t];
	else if( quantity>=144 && quantity<=287)	return qty[4][t];
	else if( quantity>=288 && quantity<=499)	return qty[5][t];
	else if( quantity>=500 && quantity<=999)	return qty[6][t];
	else if( quantity>=1000 && quantity<=1999)	return qty[7][t];
	else if( quantity>=2000)					return qty[8][t];
	
	
}
function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}
function caluculateQuote(){
	if(document.qoute.quantity.value == ""){
		alert("Please Enter Number of shirts Required");
		document.qoute.quantity.focus();
		document.qoute.quantity.select();
		return false;
	}
	if(document.qoute.quantity.value < 12){
		alert("Minimum order will be of 12 shirts");
		document.qoute.quantity.focus();
		document.qoute.quantity.select();
		return false;
	}
	/*
	alert(document.qoute.itemno.value);
	alert(document.qoute.frontLogoColors.value);
	alert(document.qoute.backLogoColors.value);
	alert(document.qoute.quantity.value);
	*/
	var frontColorPrice = calculateColorPrice(parseInt(document.qoute.frontLogoColors.value)); //alert ("front color price " + frontColorPrice);
	var backColorPrice = calculateColorPrice(parseInt(document.qoute.backLogoColors.value)); //alert ("back color price " + backColorPrice);
	var z = (frontColorPrice + backColorPrice)*parseInt(document.qoute.quantity.value);   //alert ("colors " + z);
	var totalColors = parseInt(document.qoute.frontLogoColors.value)+parseInt(document.qoute.backLogoColors.value); //alert ("Total Colors " + totalColors);
	var screenCharges = totalColors*20;  //alert ("Screen Charges " + screenCharges);
	
	z = z+(totalColors)*20 + (parseInt(document.qoute.quantity.value)*parseInt(document.qoute.itemno.value));
	
	var pershirt = z/parseInt(document.qoute.quantity.value);
	var total = z;
	pershirt = roundNumber(pershirt, 2);
	z = roundNumber(z, 2);
	//alert("per shirt " + pershirt);
	//alert("total " + total);
	document.getElementById('ppshirt').value = "$ " + pershirt;
	document.getElementById('totalCost').value = "$ " + total;	
	
}

