// BANNER PRICER SCRIPT - @AKSARBEN 2005

// Initialize Global Variables

	var FABmsg="10oz Printers Choice, "	// Fabric Name

	var HG=(0.80 * 1);		// Price per sq foot: hem/grom
	var WDR=(0.95 * 1);		// Price per sq foot: webbing,D-rings or Rope
	var WT=(0.625 * 1);  		// Weight

	var BANmin=(8.5 *1);		// Minimum banner price
	var BANmin_vol=(8.08 *1);	// Minimum banner price with volume disc
	var velPRICE=.60;		// Velcro Price Per Linear Foot
	var corPRICE=8.0;		// Reinforced corner price
	var DISC=(.95 * 1);		// Volume Discount

	var width=(0 * 1);
	var banner="";			// calculated text for description
	var CORNERmsg="";		// description for reinforced corners

	var ppsf=(0 * 1);		// Generic Price Per Square Foot
	var DISCmsg="";			// Discount Message
	var MINmsg="";			// Minimum Banner Pricing Message
	var prefix="$";			// used in calc to display dollar sign

function show_cartbutton() {

	//for IE 5 & Netscape 6 Browsers
	if (document.getElementById)				
		{document.getElementById("cartbutton").style.visibility = "visible";
		 document.getElementById("cartmess").style.visibility = "visible";}

	//for older IE browsers
	else if (window.document.all)				
		{window.document.all.cartbutton.style.visibility = "visible";
		 window.document.all.cartmess.style.visibility = "visible";}

	//for Netscapt 4.0 or older browsers
	else if (document.layers)	
		{window.document.cartbutton.visibility = "visible";
		 window.document.cartmess.visibility = "visible";}
	else 
		{alert("Sorry, this doesnt work in your browser.");
		return;}
	}

function hide_cartbutton() {

	//for IE 5 & Netscape 6 Browsers
	if (document.getElementById)				
		{document.getElementById("cartbutton").style.visibility = "hidden";
	   	 document.getElementById("cartmess").style.visibility = "hidden";}

	//for older IE browsers
	else if (window.document.all)				
		{window.document.all.cartbutton.style.visibility = "hidden";
		 window.document.all.cartmess.style.visibility = "hidden";}

	//for Netscapt 4.0 or older browsers
	else if (document.layers)	
		{window.document.cartbutton.visibility = "hidden";
		 window.document.cartmess.visibility = "hidden";}
	else 
		{alert("Sorry, this doesnt work in your browser.");
		return;}
	}

//SHOW DISCOUNT DIV ---------------------------------------------------------
function show_discount() {
	//for IE 5 & Netscape 6 Browsers
	if (document.getElementById)
		{document.getElementById("discount").style.visibility = "visible";}

	//for older IE browsers
	else if (window.document.all)				
		{window.document.all.discount.style.visibility = "visible";}
	
	//for Netscape 4.0 or older browsers
	else if (document.layers)	
		{window.document.discount.visibility = "visible";}
	else 
		{alert("Sorry, this doesnt work in your browser.");
		return;}
}


//HIDE DISCOUNT DIV ---------------------------------------------------------
function hide_discount() {
	//for IE 5 & Netscape 6 Browsers
	if (document.getElementById)
		{document.getElementById("discount").style.visibility = "hidden";}

	//for older IE browsers
	else if (window.document.all)				
		{window.document.all.discount.style.visibility = "hidden";}
	
	//for Netscapt 4.0 or older browsers
	else if (document.layers)	
		{window.document.discount.visibility = "hidden";}
	else 
		{alert("Sorry, this doesnt work in your browser.");
		return;}
}

//SHOW MIN_PRICE DIV ---------------------------------------------------------
function show_min_price() {
	//for IE 5 & Netscape 6 Browsers
	if (document.getElementById)
		{document.getElementById("min_price").style.visibility = "visible";}

	//for older IE browsers
	else if (window.document.all)				
		{window.document.all.min_price.style.visibility = "visible";}
	
	//for Netscape 4.0 or older browsers
	else if (document.layers)	
		{window.document.min_price.visibility = "visible";}
	else 
		{alert("Sorry, this doesnt work in your browser.");
		return;}
}

//HIDE MIN_PRICE DIV ---------------------------------------------------------
function hide_min_price() {
	//for IE 5 & Netscape 6 Browsers
	if (document.getElementById)
		{document.getElementById("min_price").style.visibility = "hidden";}

	//for older IE browsers
	else if (window.document.all)				
		{window.document.all.min_price.style.visibility = "hidden";}
	
	//for Netscapt 4.0 or older browsers
	else if (document.layers)	
		{window.document.min_price.visibility = "hidden";}
	else 
		{alert("Sorry, this doesnt work in your browser.");
		return;}
}

//SHOW VELCRO DIV ---------------------------------------------------------
function show_velDIV() {
	//for IE 5 & Netscape 6 Browsers
	if (document.getElementById)
		{document.getElementById("velDIV").style.visibility = "visible";}

	//for older IE browsers
	else if (window.document.all)				
		{window.document.all.velDIV.style.visibility = "visible";}
	
	//for Netscape 4.0 or older browsers
	else if (document.layers)	
		{window.document.velDIV.visibility = "visible";}
	else 
		{alert("Sorry, this doesnt work in your browser.");
		return;}
}

//HIDE VELCRO DIV ---------------------------------------------------------
function hide_velDIV() {
	//for IE 5 & Netscape 6 Browsers
	if (document.getElementById)
		{document.getElementById("velDIV").style.visibility = "hidden";}

	//for older IE browsers
	else if (window.document.all)				
		{window.document.all.velDIV.style.visibility = "hidden";}
	
	//for Netscapt 4.0 or older browsers
	else if (document.layers)	
		{window.document.velDIV.visibility = "hidden";}
	else 
		{alert("Sorry, this doesnt work in your browser.");
		return;}
}

//SHOW POLE POCKET DIV - HIDE REINFORCED CORNER DIV -------------------------
function show_PPKTdiv() {
	//for IE 5 & Netscape 6 Browsers
	if (document.getElementById)
		{
		document.getElementById("divPPKT").style.visibility = "visible";
		document.getElementById("divCORNER").style.visibility = "hidden";
		}
	//for older IE browsers
	else if (window.document.all)				
		{
		window.document.all.divPPKT.style.visibility = "visible";
		window.document.all.divCORNER.style.visibility = "hidden";
		}
	
	//for Netscape 4.0 or older browsers
	else if (document.layers)	
		{
		window.document.divPPKT.visibility = "visible";
		window.document.divCORNER.visibility = "hidden";
		}
	else 
		{alert("Sorry, this doesnt work in your browser.");
		return;}
}

//HIDE POLE POCKET DIV - SHOW REINFORCED CORNER DIV -------------------------
function hide_PPKTdiv() {
	//for IE 5 & Netscape 6 Browsers
	if (document.getElementById)
		{
		document.getElementById("divPPKT").style.visibility = "hidden";
		document.getElementById("divCORNER").style.visibility = "visible";
		}
	//for older IE browsers
	else if (window.document.all)				
		{
		window.document.all.divPPKT.style.visibility = "hidden";
		window.document.all.divCORNER.style.visibility = "visible";
		}
	
	//for Netscape 4.0 or older browsers
	else if (document.layers)	
		{
		window.document.divPPKT.visibility = "hidden";
		window.document.divCORNER.visibility = "visible";
		}
	else 
		{alert("Sorry, this doesnt work in your browser.");
		return;}
}

//SHOW WIDTH72 DIV ---------------------------------------------------------
function show_width72() {
	//for IE 5 & Netscape 6 Browsers
	if (document.getElementById)
		{document.getElementById("width72").style.visibility = "visible";
		 document.getElementById("width59").style.visibility = "hidden";}

	//for older IE browsers
	else if (window.document.all)				
		{window.document.all.width72.style.visibility = "visible";
		 window.document.all.width59.style.visibility = "hidden";}
	
	//for Netscape 4.0 or older browsers
	else if (document.layers)	
		{window.document.width72.visibility = "visible";
		 window.document.width59.visibility = "hidden";}
	else 
		{alert("Sorry, this doesnt work in your browser.");
		return;}
}

//SHOW WIDTH59 DIV ---------------------------------------------------------
function show_width59() {
	//for IE 5 & Netscape 6 Browsers
	if (document.getElementById)
		{document.getElementById("width59").style.visibility = "visible";
		 document.getElementById("width72").style.visibility = "hidden";}

	//for older IE browsers
	else if (window.document.all)				
		{window.document.all.width59.style.visibility = "visible";
		 window.document.all.width72.style.visibility = "hidden";}
	
	//for Netscape 4.0 or older browsers
	else if (document.layers)	
		{window.document.width59.visibility = "visible";
		 window.document.width72.visibility = "hidden";}
	else 
		{alert("Sorry, this doesnt work in your browser.");
		return;}
}

//MAIN CALC FUNCTION ---------------------------------------------------------
function calcPRICE() {
// Set Local Variables that need to be reinitialized each time a form field changes
	var fin=document.pricer.finish.value;
	var orient=document.pricer.orientation.value;
	var color=document.pricer.opt1.value;
	var widthtest;
	var widthA=document.pricer.opt2a.value;
	var widthB=document.pricer.opt2b.value;
	var velcroA=document.pricer.velA.value;
	var velcroB=document.pricer.velB.value;
	var length=document.pricer.opt3.value;
	var quantity=document.pricer.op5.value;
	var grommets=document.pricer.grom.value;
	var ppktTB="";
	var ppktSIZE="";
	var ppktWID=0;
	var ppktLEN=0;
	var velLEN=0;
	var velTOTAL=0;

// Determine Color Choice and display the appropriate Width Field
	if ( color == "Neon Cosmic Yellow" || color == "White" || color == "Black" || color == "Red" || color == "Yellow" || color == "Blue" ) 
		{ show_width72();
		  widthtest=72;
		  width=widthA;}
	else { show_width59();
	       widthtest=59;
	       width=widthB;}

// Switch Values in Width Fields
	if (widthA > 0 && widthA < 72 && widthtest == 59)
		{document.pricer.opt2b.value=widthA;
		 document.pricer.opt2a.value=0;
		 width=widthA;}
	else if (widthB > 0 && widthtest == 72)
		{document.pricer.opt2a.value=widthB;
		 document.pricer.opt2b.value=0;
		 width=widthB;}
	else if	(widthA > 59 && widthtest == 59)
		{
		 alert("Sorry, but " + color +" is not available in 72 inch width. Please reselect.")
 		 document.pricer.opt2b.value=0;
		 document.pricer.opt2a.value=0;
		 width="0";
		}

// Determine if Pole Pockets are Ordered
	var corner=(document.pricer.opt4.value * 1); // Pull Value From Form
	if (corner>0) corner=corPRICE;

	if (fin=="Pole Pocket")
		{
		document.pricer.opt4.value="0";
		corner=0;
		show_PPKTdiv();
		ppktTB=document.pricer.poleTB.value;
		ppktSIZE=document.pricer.poleSIZE.value;
		if(orient=="Horizontal Banner"){ppktWID=12;}
		   else {ppktLEN=12;}
		if(ppktTB==" on Top Only, Hemmed Other Sides ")
		   {ppktWID=ppktWID/2;
		    ppktLEN=ppktLEN/2;}
		   else {}
		}
	else
		{hide_PPKTdiv();
		 ppktWID=0;
		 ppktLEN=0;}

// Determine if Reinforced Corners are Ordered
	if (corner>0)
		{CORNERmsg=", Reinforced Corners"}
	else
		{CORNERmsg=""}

// Determine if Velcro is Ordered
	if (velcroA =="") {		
		hide_velDIV();
		velLEN=0;
		}
	else 	{show_velDIV();
		var velWID=width/12;
		if (velcroA==", Hook Velcro all 4 Edges" || velcroA==", Loop Velcro all 4 Edges")
			{velLEN=(velWID *2) + (length *2)}
	    	else if (velcroA==", Hook Velcro Top and Bottom" || velcroA==", Loop Velcro Top and Bottom" && orient=="Horizontal Banner")
			{velLEN=(length*2)}
	  	else if (velcroA==", Hook Velcro Top and Bottom" || velcroA==", Loop Velcro Top and Bottom" && orient=="Vertical Banner")
			{velLEN=(velWID *2)}
		else if (velcroA==", Hook Velcro Top Only" || velcroA== ", Loop Velcro Top Only" && orient=="Horizontal Banner")
			{velLEN=(length)}
		else if (velcroA==", Hook Velcro Top Only" || velcroA== ", Loop Velcro Top Only" && orient=="Vertical Banner")
		      	{velLEN=(velWID)}
		else {}

		if (velcroB==", Corresponding Velcro Included")
			{velLEN=(velLEN *2)}		// CORRESPONDING IS TWICE AS LONG
		else{}

		velTOTAL=velLEN * velPRICE;		// CALCULATE PRICE

		}

// Validate Fields and Hide Price Fields and Cart Button if Validation Fails
	if (length>0 && width>0 && quantity>0)
		testresult=true
	else{
		document.pricer.price.value=""; 
		document.pricer.op33.value="";
		hide_cartbutton();
		return false}


// Set Price based on Finishing Style Selected
	if(fin=="Hemmed")
		ppsf = HG;
	else 
		ppsf = WDR;

// Calculate Discount
	var cut_width=((width * 1) + 2 + ppktWID);
	var cut_length=((length * 12) + 2 + ppktLEN);
	var sq_ft=((cut_width * cut_length) / 144);
	var sq_ftTotal=(sq_ft * quantity);

	if(sq_ftTotal>149)
	{ 
		DISCmsg="5% Volume Discount applied";
		var DISCtemp=DISC;
		show_discount();
	}
	else{
		DISCmsg="";
		var DISCtemp=(1 * 1);
		hide_discount();
		}

// Calculate Price

	calc = ((ppsf * sq_ft) + corner + velTOTAL )*DISCtemp;	// ADD IT ALL UP
	round=Math.round(calc*100);				// ROUND IT OFF TO 2 DECIMAL...
	tempnum=''+round/100+''					
	loc=tempnum.indexOf(".");				
	if (loc>0) {tempnum=tempnum+"00";tempnum=tempnum.substring(0,loc+3);}
	MINmsg="";						// CLEAR MINIMUM PRICE MESSAGE

	if (tempnum<BANmin) 					// CHECK FOR MIN PER ITEM PRICE
	{
		show_min_price();
		MINmsg="Per-banner minimum price applied. ";

		if (DISCtemp<1) 
			tempnum=BANmin_vol;			// Qualifies for voluming pricing
		else 
			tempnum=BANmin+"0";			// Set minimum price
	}
	
	else hide_min_price();

	document.pricer.op33.value=tempnum;  			// WRITE PRICE TO HIDDEN FIELD - NO $
	document.pricer.price.value=prefix+tempnum;		// WRITE PRICE TO VISIBLE FORM FIELD 



// Calculate Weight
	calc = (WT * sq_ft / 9) + 2;			// CALCS WEIGHT BASED ON SQ YDS & ADDS 2LBS FOR BOX
	round=Math.round(calc*1);
	tempnum=''+round/1+''				// tempnum is reset to weight value
	document.pricer.op11.value=tempnum;  		// WRITE WEIGHT TO HIDDEN FIELD


// Show Cart Button
	show_cartbutton();	

// Write Info to Screen and Hidden Fields -------------------------------

// CREATE COMPOSITE TEXT from input values 

	banner=(FABmsg + color + ", " + width + " IN x " + length + " FT, " + orient + ", " + fin + ppktTB + ppktSIZE + CORNERmsg + grommets + velcroA + velcroB + ". " + MINmsg + DISCmsg); 

	document.pricer.op1.value=banner; 			// WRITE COMPOSITE TO HIDDEN FIELD USED BY CART
	document.desc.info.value=banner; 			// WRITE COMPOSITE TO VISIBLE FIELD


}

// End of script

