//global variables
var dateAdj,xmlhttp,cost,item_total,x,i,c,z,str;
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);

//random functions usable across all pages

//ajax xmlhttp function (reusable)
function getXmlHttpObject(){
if(window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();}
if(window.ActiveXObject){// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");}
return null;}

function trim(stringToTrim) {return stringToTrim.replace(/^\s+|\s+$/g,"");}
function ltrim(stringToTrim) {return stringToTrim.replace(/^\s+/,"");}
function rtrim(stringToTrim) {return stringToTrim.replace(/\s+$/,"");}
function numTrim(stringToTrim) {return stringToTrim.replace(/[^\D]/g, "");}
function trimToNum(field){
	var fValue=document.getElementById(field).value;
	var trimVal=numTrim(fValue);
	fValue=trimVal;
}

function unCheckRadio(oRadio){
var or=document.getElementsByName(oRadio);
for (i=0;i<or.length;i++){or[i].checked=false;}
}

//set the radio button with the given value as being checked
//do nothing if there are no radio buttons
//if the given value does not exist, all the radio buttons
//are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj){
		return;}
	if(newValue=="created_in"){
		newValue=document.getElementById('created_in').value;
		newValue=newValue.substring(newValue.indexOf("("))
		newValue=newValue.replace("(","");
		newValue=newValue.replace(")","");
		if(newValue!="PC"&&newValue!="Mac"){
			return;}
	}
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

//return the value of the radio button that is checked
//return an empty string if none are checked, or
//there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function setVal(sel,str){//set select value
for(z=0;z<sel.options.length;z++){if(str==sel.options[z].value){sel.selectedIndex=z;}}}

function EnforceMaximumLength(field, len){
	ltrim(field.value)
	if(field.value.length>len){field.value=field.value.substr(0, len);
	alert("This field restricted to "+len+" characters!");}
	}

function unRedBorder(elem){for(i=0;i<10;i++){if(document.getElementById(elem+i)!=null){document.getElementById(elem+i).style.borderColor="black";}}}

function unRed(elem){
var elemID = document.getElementById(elem)
if(elemID){
if(elem.substring(0,4)==="file"){
	elemID.style.backgroundColor="#f0f8ff";
	elemID.setAttribute("background-color", "#f0f8ff");}
elemID.style.color='#000';
elemID.setAttribute("color", "#000");
}else if(elem="delivery_method"){
arr=document.getElementsByName('delivery_method');
var arlen=arr.length;
for(var i=0; i < arlen; i++){
var obj=document.getElementsByName('delivery_method').item(i);
obj.parentNode.style.color='#000';
obj.parentNode.setAttribute("color", "#000");}
}return true;}

//functions for page 1 (file and price info)
//date functions


Date.prototype.addDays=function(d){this.setDate( this.getDate()+d );};
Date.prototype.setSaturdayThisWeek=function(){this.setDate(this.getDate()+6-this.getDay());};
Date.prototype.setNextMonday=function(){
	if(this.getDay()==0){
		this.setDate(this.getDate() + 1)
	}else if(this.getDay==1){
		this.setDate(this.getDate() + 0);
	}else{
		this.setDate(this.getDate() +(8-this.getDay()));
	}
}
Date.prototype.addWeekDays=function(d){
var startDay=0;
startDay=this.getDay();//current weekday 0 thru 6
var wkEnds=0;//# of weekends needed
var partialWeek=d % 5;//# of weekdays for partial week
if(d < 0){//subtracting weekdays 
wkEnds=Math.ceil(d/5); //negative number weekends
switch (startDay){
case 6://start Sat. 1 less weekend
if(partialWeek===0 && wkEnds < 0) 
wkEnds++;
break;
case 0://starting day is Sunday
if(partialWeek===0) 
d++;//decrease days to add
else 
d--;//increase days to add
break;
default:
if(partialWeek <= -startDay) 
wkEnds--;
}
}else if(d>0){//adding weekdays
wkEnds=Math.floor(d/5);
var w=wkEnds;
switch (startDay){
case 6:
/* If staring day is Sat. and
* no partial week one less day needed
* if partial week one more day needed
*/
if(partialWeek===0)
d--;
else
d++;
break;
case 0://Sunday
if(partialWeek===0 && wkEnds>0) 
wkEnds--;
break;
default:
if(5 - startDay < partialWeek) 
wkEnds++;}
}
d += wkEnds * 2;
this.addDays(d);
};

//function to calculate local (Plymouth, NH) time in a city given the city's UTC offset
function calcPlymTime() {
var pDate=document.getElementById('order_date').value;
var d = new Date(pDate.substring(0,4),(pDate.substring(5,7)-1),pDate.substring(8,10),pDate.substring(11,13),pDate.substring(14,16),pDate.substring(17,19));
// offset entered here - one each for Spring (-4) and Fall (-5) 
if (isDST()==="true"){var offset="-4";}else{var offset="-5";}
var utc = d.getTime() + (d.getTimezoneOffset() * 60000);
var nd = new Date(utc + (3600000*offset));
return nd;
}

function isDST() {
var pDate=document.getElementById('order_date').value;
var b,e,c;
var year =new Date(pDate.substring(0,4),(pDate.substring(5,7)-1),pDate.substring(8,10),pDate.substring(11,13),pDate.substring(14,16),pDate.substring(17,19)); 
year=year.getFullYear();
var mar1 = new Date(year, 2, 1);
var sun2mar = 15 - mar1.getDay();
var spring = new Date("Mar " + sun2mar + ", " + year + " 2:00:00");
var b = Date.parse(spring);
// Get the date to 'fall back'
var nov1 = new Date(year, 10, 1);
var sun1nov = 8 - nov1.getDay();
var fall = new Date("Nov " + sun1nov + ", " + year + " 2:00:00");
var e = Date.parse(fall);
var c = new Date(pDate.substring(0,4),(pDate.substring(5,7)-1),pDate.substring(8,10),pDate.substring(11,13),pDate.substring(14,16),pDate.substring(17,19));
if((c <= e && c >= b)) {
return true;
}
return false;
}

function dueDate(hMonth,hDay,hYear,ele){
	var dateEle=ele+'Date';
	var dueDate=calcPlymTime();
	var xmlhttp=getXmlHttpObject();
	if(xmlhttp==null){alert("Browser does not support HTTP Request");return;}
	var url="./ajax/holiday.php";
	url=url+"?month="+hMonth;
	url=url+"&day="+hDay;
	url=url+"&year="+hYear;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=function(){
	if(xmlhttp.readyState==4){
		if(xmlhttp.status==200){
			var dateAdj=xmlhttp.responseText;
			dueDate.setFullYear(hYear);
			dueDate.setMonth(hMonth);
			dueDate.setDate(hDay);
			dueDate.addWeekDays(Number(dateAdj));
			if(ele=='sd'){
				var dueToday=calcPlymTime();
				var numItems=document.getElementById('num_items').value;
				if(dueToday.getDay()==4&&dueToday.getHours()>=3&&numItems<=10){
					dueToday.setSaturdayThisWeek();
					document.getElementById('SD').disabled=false;
					document.getElementById('sdDate').value=dueToday.toDateString();
				}else if(dueToday.getDay()==5&&dueToday.getHours()<12&&numItems<=10){
					dueToday.setSaturdayThisWeek();
					document.getElementById('SD').disabled=false;
					document.getElementById('sdDate').value=dueToday.toDateString();
				}else if(dueToday.getDay()==5&&dueToday.getHours()>=12&&dueToday.getHours()<15&&numItems<=5&&document.getElementById('rush_ship').checked==true){
					dueToday.setSaturdayThisWeek();
					document.getElementById('SD').disabled=false;
					document.getElementById('sdDate').value=dueToday.toDateString();
				}else{
					dueDate.setDate(dueDate.getDate()+6 - dueDate.getDay());
					document.getElementById('sdCost').value="";
					document.getElementById('sdDate').value="";
					document.getElementById('SD').checked=false;
					document.getElementById('SD').disabled=true;}
			}else{			
			document.getElementById(dateEle).value=dueDate.toDateString();}
		fillDate('delivery_method');}}
	};
	xmlhttp.open("GET", url, true);
	xmlhttp.send(null);
}

function showRush(){
	var subTotal = document.getElementById('sub_total').value;
	var tubeTotal = document.getElementById('tube_cost').value;
	if(isNaN(parseFloat(tubeTotal))){tubeTotal=0;}
	if(isNaN(parseFloat(subTotal))){subTotal=0;}
	var charge=(parseFloat(subTotal)-parseFloat(tubeTotal))*.25;
		var rushCostObj=document.getElementById('rush_cost');
		var rushCostRow=document.getElementById('rush_cost_row');
		if(document.getElementById('rush_ship').checked===true){
			var r=confirm("Would you like to submit this as a rush job for $"+charge+"? (+25%) This will ensure your order is shipped today.");
			if (r==true){
				rushCostObj.value=charge.toFixed(2);
				rushCostRow.className="viz";
				rushCostRow.setAttribute("className","viz");
				rushCostRow.setAttribute("class","viz");
				document.getElementById('SD').disabled=false;
				shipFill();
			}else{
				rushCostObj.value=0;
				rushCostRow.className="hidden";
				rushCostRow.setAttribute("className","hidden");
				rushCostRow.setAttribute("class","hidden");
				document.getElementById('SD').disabled=true;
			}
		}else{
			var r=confirm("Cancel rush option?");
			if (r==true){
				rushCostObj.value=0;
				rushCostRow.className="hidden";
				rushCostRow.setAttribute("className","hidden");
				rushCostRow.setAttribute("class","hidden");
				document.getElementById('SD').disabled=true;
			}else{
				rushCostObj.value=charge.toFixed(2);
				rushCostRow.className="viz";
				rushCostRow.setAttribute("className","viz");
				rushCostRow.setAttribute("class","viz");
				document.getElementById('SD').disabled=false;
				shipFill();
			}
		}
	if(document.getElementById('ship_cost').value==="Free!"||document.getElementById('ship_cost').value==""){ship_Cost=0;}else{ship_Cost=document.getElementById('ship_cost').value;}
		var subShip=parseFloat(ship_Cost)+parseFloat(document.getElementById('sub_total').value);
	subShip=subShip.toFixed(2)
	var rushCost=document.getElementById('rush_cost').value;
	rushCost=parseFloat(rushCost);
	if(isNaN(rushCost)){rushCost=0;}else{rushCost=rushCost.toFixed(2);}
	var rushShip = document.getElementById('rush_ship');
	if(rushShip){
		if(document.getElementById('rush_ship').checked!==true){var totalCost=parseFloat(subShip);}else{var totalCost=parseFloat(subShip)+parseFloat(rushCost);}
	}else{var totalCost=parseFloat(subShip);}
	document.getElementById('total_cost').value=totalCost.toFixed(2);
	deliveryDate();
}

function deliveryDate(){
var noItems=document.getElementById('num_items').value;
var shipZip=document.getElementById('ship_zip').value;
shipZip=shipZip.replace(/^\s+/,"");
document.getElementById('ship_zip').value=shipZip;
if(!noItems||noItems==0||noItems==''||!shipZip||shipZip==''){return false;
}else{
var itemAdj=(Math.ceil(noItems/20));
//add a day for weekday orders after 12PM unless customer chooses 'rush' option. Specifically checking time at MP!
var plymDate=calcPlymTime();
var plymTime=plymDate.getHours();
if(plymDate.getDay()!=0&&plymDate.getDay()!=6&&plymTime>=11&&(document.getElementById('rush_ship')==null||document.getElementById('rush_ship').checked==false)){itemAdj++;}
//Set up shipping element array, first is element code ("pu") second is itemAdj adjustment
var shipEle = [['pu', 0 ],['es', 1],['so', 0],['po', 0],['sd', 0]];
var eleLength=shipEle.length;
for(i=0;i<eleLength;i++){
ele = shipEle[i][0];
adj = shipEle[i][1];
var shipDateItemAdj=itemAdj+adj;
var shipDate=calcPlymTime();
if(shipDate.getDay()==0||shipDate.getDay()==6){shipDate.setNextMonday();}
shipDate.addWeekDays(Number(shipDateItemAdj));
var newShipDate=dueDate(shipDate.getMonth(),shipDate.getDate(),shipDate.getFullYear(),ele);
}
}
//test to see if quantity has changed since start of calculations
var nItems=document.getElementById('num_items').value;
if(nItems!=noItems){deliveryDate();}

}

function fillDate(radioObjName){
var e=document.getElementsByName(radioObjName);
if(e[0].checked){
var methodDate=document.getElementById('esDate').value;
var methodCost=document.getElementById('esCost').value;
var shipMethod="via FedEx 2nd Day.<br />On "+methodDate;
}else if(e[1].checked){
var methodDate=document.getElementById('soDate').value;
var methodCost=document.getElementById('soCost').value;
var shipMethod="via FedEx Standard<br />On "+methodDate;
}else if(e[2].checked){
var methodDate=document.getElementById('poDate').value;
var methodCost=document.getElementById('poCost').value;
var shipMethod="via FedEx Priority<br />On "+methodDate;
}else if(e[3].checked){
var methodDate=document.getElementById('intDate').value;
var methodCost=document.getElementById('intCost').value;
var shipMethod="International delivery - call for pricing and ship times.";
}else if(e[4].checked){
var methodDate=document.getElementById('puDate').value;
var methodCost=document.getElementById('puCost').value;
var shipMethod="Pick up at our office.<br />No earlier than "+methodDate;
}else if(e[5].checked){
var methodDate=document.getElementById('sdDate').value;
var methodCost=document.getElementById('sdCost').value;
var shipMethod="via FedEx Sat. Delivery<br />On "+methodDate;
}else{
document.getElementById('ship_meth').innerHTML="";}
var methDate=new Date(methodDate);
var shipMeth = document.getElementById('ship_meth');
if (methDate.toDateString()!=="Invalid Date"){
document.getElementById('deliver_date').value=methDate.toDateString();}
var shpCost=document.getElementById('ship_cost');
if(methodCost==="Free!"){shpCost.style.color="#F30";shpCost.style.fontStyle="italic";}else{shpCost.style.color="#000";shpCost.style.fontStyle="normal";}
if(!methodCost){
document.getElementById('ship_cost').value='';
var arr=new Array();
arr=document.getElementsByName('delivery_method');
var arlen=arr.length;
for(var i=0; i < arlen; i++){
var obj=document.getElementsByName('delivery_method').item(i);
obj.parentNode.style.color='red';}
}else{
try {if(document.getElementById('fedex_acct')) var fedEx=document.getElementById('fedex_acct').value;} catch(e){var fedEx=0;}
if(fedEx.length>8){methodCost=0;
shipMethod=shipMethod+"<br/>(Billed to your account)";}
shpCost.value=methodCost;
if(shpCost.value==='Free!'){var subShip=parseFloat(document.getElementById('sub_total').value);
}else{
var subShip=parseFloat(shpCost.value)+parseFloat(document.getElementById('sub_total').value);
}
subShip=subShip.toFixed(2);
var rushCost=document.getElementById('rush_cost').value;
rushCost=parseFloat(rushCost);
if(isNaN(rushCost)){rushCost=0;}else{rushCost=rushCost.toFixed(2);}
var rushShip = document.getElementById('rush_ship');
if(rushShip){if(document.getElementById('rush_ship').checked===true){var totalCost=parseFloat(subShip)+parseFloat(rushCost);}else{var totalCost=parseFloat(subShip);}
}else{var totalCost=parseFloat(subShip);}
document.getElementById('total_cost').value=totalCost.toFixed(2);
shipMeth.innerHTML=shipMethod;
shipMeth.className=="viz_ship";
shipMeth.setAttribute("class", "viz_ship");
shipMeth.setAttribute("className", "viz_ship");
var arr=new Array();
arr=document.getElementsByName('delivery_method');
var arlen=arr.length;
for(var i=0; i < arlen; i++){
var obj=document.getElementsByName('delivery_method').item(i);
obj.parentNode.style.color='#000';}
}
var delivDate=document.getElementById('deliver_date');
var totCost=document.getElementById('total_cost');
var shpCost=document.getElementById('ship_cost');
if(shpCost.value!=''&&shpCost.value!=null&&delivDate.value!=''&&delivDate.value!=null&&delivDate.value!=0&&totCost.value!=''&&totCost.value!=null&&totCost.value!=0&&totCost.value!=shpCost.value){document.getElementById('next').disabled=false;}
}

//main ajax cost lookup function
function itemCost(x){
handCost(x)
var str= document.getElementById('code'+x).value;
var xmlhttp=getXmlHttpObject();
if(xmlhttp==null){alert("Browser does not support HTTP Request form will not be able to calculate costs!");
return;}
var url="./ajax/cost.php";
url=url+"?key="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=function (){
if(xmlhttp.readyState==4){
if(xmlhttp.status==200) {var unitPreCost=xmlhttp.responseText;
try {if(document.getElementById('d1'+x)!==null&&document.getElementById('d1'+x).value) var objL1=parseInt(document.getElementById('d1'+x).value);} catch(e){var objL1=0;}
try {if(document.getElementById('d2'+x)!==null&&document.getElementById('d2'+x).value) var objL2=parseInt(document.getElementById('d2'+x).value);} catch(e){var objL2=0;}
if(objL1!=0 && objL2!=0){
var objA=(objL1 * objL2)/144;}
document.getElementById('area'+x).value=objA;
var qty=document.getElementById('qty'+x).value;
var disCount=1;
//discount if-then
totalQty=document.getElementById('num_items').value;
if(totalQty>4){disCount=.9;}else{disCount=1;}
var adjItemCost=(parseFloat(unitPreCost)*parseFloat(disCount));
var unitValue=parseFloat(adjItemCost);
var unitValue=unitValue.toFixed(2);
if(isNaN(unitValue)){document.getElementById('unit_cost'+x).value='';
}else{document.getElementById('unit_cost'+x).value=unitValue;}
var itemTotalCost=(unitValue*parseFloat(qty));}
var itemTotalCost=itemTotalCost.toFixed(2);
if(isNaN(itemTotalCost)){document.getElementById('item_total'+x).value='';
}else{
	var handCost=document.getElementById('hand_total'+x).value;
	handCost=parseFloat(handCost);
	itemTotalCost=parseFloat(itemTotalCost);
	if(isNaN(handCost)){handCost=0;}
	if(isNaN(itemTotalCost)){itemTotalCost=0;}
	itemTotalCost=itemTotalCost+handCost;
	document.getElementById('item_total'+x).value=itemTotalCost.toFixed(2);}
// get total number of items
var i, count=document.getElementsByTagName("input");
var countElm=0;
for (i=0; i < count.length; i++){
if(count[i].id.match(/^qty\d/)){countElm++;}
}
var sum=0; // The sum starts off at 0
for (var i=0; i < countElm; i++){
var qtZ=0;
try {if(document.getElementById('qty'+i).value) qtZ=document.getElementById('qty'+i).value;} catch(e){qtZ=0;}
if(isNaN(parseInt(qtZ))){qtZ=0;}
sum += parseInt(qtZ);} // Add the value to the sum
var freeShipObj=document.getElementById('free_ship');
var rushRowObj=document.getElementById('rush_row');
if(sum>1){
	freeShipObj.className="viz";freeShipObj.setAttribute("class","viz");freeShipObj.setAttribute("className","viz");
}else{
	freeShipObj.className="hidden";freeShipObj.setAttribute("class","hidden");freeShipObj.setAttribute("className","hidden");
};
tQty=parseInt(document.getElementById('tube_qty').value);
if(isNaN(tQty)){tQty=0;}
sum += tQty;
document.getElementById('num_items').value=parseInt(sum);
var rushShip=document.getElementById('rush_ship');
if(rushShip){
if(sum>20){
	rushRowObj.className="hidden";rushRowObj.setAttribute("class","hidden");
	rushRowObj.setAttribute("className","hidden");
	if(rushShip.checked==true){
		rushShip.checked=false;
		alert('Cancelling rush shipment. Rush processing only available on orders of 20 or fewer pieces.');}
	document.getElementById('rush_cost').value=0;
	var rushCostRow=document.getElementById('rush_cost_row');
	rushCostRow.className="hidden";
	rushCostRow.setAttribute("className","hidden");
	rushCostRow.setAttribute("class","hidden");

}else{
	rushRowObj.className="viz";
	rushRowObj.setAttribute("class","viz");
	rushRowObj.setAttribute("className","viz");
};
}
// subtotal and total costs
var i, count=document.getElementsByTagName("input");
var countElm=0;
for (i=0; i < count.length; i++){
if(count[i].id.match(/^item_total\d/)){countElm++;}
}
var sumz=0; // The sum starts off at 0
for (var i=0; i < countElm; i++){
var item_totalz=0;
try{if(document.getElementById('item_total'+i)!==null&&document.getElementById('item_total'+i).value) item_totalz=document.getElementById('item_total'+i).value;} catch(e){item_totalz=0;}
if(isNaN(parseFloat(item_totalz))){item_totalz=0;}
sumz += parseFloat(item_totalz);} // Add the value to the sum
if(document.getElementById('tube_cost')!==null&&(document.getElementById('tube_qty')!==null||document.getElementById('tube_qty')!==''||document.getElementById('tube_qty')!=0)){tubeCost=document.getElementById('tube_cost').value;} else{tubeCost=0;}
if(isNaN(parseFloat(tubeCost))){tubeCost=0;}
sumz += parseFloat(tubeCost);
document.getElementById('sub_total').value=sumz.toFixed(2);
var rushCost=parseFloat((sumz-parseFloat(tubeCost))*.25);
document.getElementById('rush_cost').value=rushCost.toFixed(2);
var rushShip = document.getElementById('rush_ship');
if(rushShip){if(document.getElementById('rush_ship').checked===true){sumz+=rushCost;}}
var ship_Cost=document.getElementById('ship_cost');
if(ship_Cost.value==0||ship_Cost.value==null||ship_Cost.value==''||ship_Cost.value==="Free!"){
document.getElementById('total_cost').value=sumz.toFixed(2);}
itemWeight(x);}
};
xmlhttp.open("GET", url, true);
xmlhttp.send(null);}

//extra handout cost lookup function
function handCost(x){
	var handSize=document.getElementById('handdim'+x).value;
	var handQty=document.getElementById('handqty'+x).value;
	if(handQty != null && handQty!=0&& handQty!=''&&handSize!=0){
		var xmlhttp=getXmlHttpObject();
		if(xmlhttp==null){alert("Browser does not support HTTP Request form will not be able to calculate costs!");return;}
		var url="./ajax/cost.php";
		url=url+"?key="+handSize;
		url=url+"&sid="+Math.random();
		xmlhttp.onreadystatechange=function (){
		if(xmlhttp.readyState==4){
			if(xmlhttp.status==200) {
				var handCost=xmlhttp.responseText;
				handCost=handCost*handQty;
				if(handCost!=0){
				document.getElementById('hand_total'+x).value=handCost.toFixed(2);
				}else{
				document.getElementById('hand_total'+x).value='';
				}}
		}
		};
		xmlhttp.open("GET", url, true);
		xmlhttp.send(null);
	}else{document.getElementById('hand_total'+x).value='';}
	handWeight(x);
}

//extra tube cost lookup function
function tubePrice(){
	var tubeSize=document.getElementById('tubedim').value;
	var tube_qty=document.getElementById('tube_qty').value;
	if(tube_qty != null && tube_qty!=0&& tube_qty!=''&&tubeSize!=0){
		var xmlhttp=getXmlHttpObject();
		if(xmlhttp==null){alert("Browser does not support HTTP Request form will not be able to calculate costs!");return;}
		var url="./ajax/cost.php";
		url=url+"?key="+tubeSize;
		url=url+"&sid="+Math.random();
		xmlhttp.onreadystatechange=function (){
		if(xmlhttp.readyState==4){
			if(xmlhttp.status==200) {
				var tubeCost=xmlhttp.responseText;
				tubeCost=tubeCost*tube_qty;
				if(tubeCost!=0){
				document.getElementById('tube_cost').value=tubeCost.toFixed(2);
				}else{
				document.getElementById('tube_cost').value='';
				}}
		}
		};
		xmlhttp.open("GET", url, true);
		xmlhttp.send(null);
	}else{document.getElementById('tube_cost').value='';}
	tubeWeight();
	itemCost(1);
}

//check if only ordering tubes, if so, add # tubes to # items so cart will progress
function tubeOnly(){
	var numItems=document.getElementById('num_items').value;
	var tubeQty=document.getElementById('tube_qty').value;
	if (isNaN(tubeQty)){tubeQty=0;}
	if (isNaN(numItems)){numItems=0;}
	if(numItems.value==0){
	numItems.value=parseInt(tubeQty.value);}
}


//shipping weight funtions
function itemWeight(x){
var strIW=document.getElementById('code'+x).value;
var itemQty =document.getElementById('qty'+x).value;
var handWt=document.getElementById("hand_wt"+x).value;
handWt=parseFloat(handWt);
if(isNaN(handWt)){handWt=0;}
var weightCode=strIW.slice(0,2);

if(weightCode==="FB"){
	var itemWeight=1;
	var subWeight=parseFloat(itemWeight)*parseInt(itemQty);
	subWeight+=handWt;
	document.getElementById("weight"+x).value=subWeight.toFixed(2);
	pkgWeight(x);
}else{
	var xmlhttpIW=getXmlHttpObject();
	if(xmlhttpIW==null){alert("Browser does not support HTTP Request");return;}
	var url="./ajax/weight.php";
	url=url+"?key="+weightCode;
	url=url+"&sid="+Math.random();
	xmlhttpIW.onreadystatechange=function(){
	if(xmlhttpIW.readyState==4){
	if(xmlhttpIW.status==200) {
	var itemWeight=xmlhttpIW.responseText;
	itemWeight=parseFloat(itemWeight);
	var subWeight=parseFloat(itemWeight)*parseInt(itemQty);}
	subWeight=subWeight*document.getElementById('area'+x).value;
	subWeight+=handWt;
	document.getElementById("weight"+x).value=subWeight.toFixed(2);
	pkgWeight(x);}
	};
	xmlhttpIW.open("GET", url, true);
	xmlhttpIW.send(null);
}
}

function tubeWeight(){
	var tube_qty =document.getElementById('tube_qty').value;
	if(tube_qty!=0&&tube_qty!=''&&tube_qty!==undefined&&tube_qty!==null){
		var weightCode=document.getElementById('tubedim').value;
		var xmlhttpIW=getXmlHttpObject();
		if(xmlhttpIW==null){alert("Browser does not support HTTP Request");
		return;}
		var url="./ajax/weight.php";
		url=url+"?key="+weightCode;
		url=url+"&sid="+Math.random();
		xmlhttpIW.onreadystatechange=function(){
		if(xmlhttpIW.readyState==4){
		if(xmlhttpIW.status==200) {
		var tubeWeight=xmlhttpIW.responseText;
		tubeWeight=parseFloat(tubeWeight);
		var subWeight=parseFloat(tubeWeight)*parseInt(tube_qty);}
		
		document.getElementById("tube_wt").value=subWeight.toFixed(2);
		;}
		};
		xmlhttpIW.open("GET", url, true);
		xmlhttpIW.send(null);
	}else{document.getElementById("tube_wt").value=0;}
	totalWeight();	}

function handWeight(x){
	var handQty =document.getElementById('handqty'+x).value;
	if(handQty!=0&&handQty!=''&&handQty!==undefined&&handQty!==null){
	var weightCode=document.getElementById('handdim'+x).value;
	var xmlhttpIW=getXmlHttpObject();
	if(xmlhttpIW==null){alert("Browser does not support HTTP Request");
	return;}
	var url="./ajax/weight.php";
	url=url+"?key="+weightCode;
	url=url+"&x="+x;
	url=url+"&sid="+Math.random();
	xmlhttpIW.onreadystatechange=function(){
	if(xmlhttpIW.readyState==4){
	if(xmlhttpIW.status==200) {
	var handWeight=xmlhttpIW.responseText;
	handWeight=parseFloat(handWeight);
	var subWeight=parseFloat(handWeight)*parseInt(handQty);}
	document.getElementById('hand_wt'+x).value=subWeight.toFixed(2);
	}
	};
	xmlhttpIW.open("GET", url, true);
	xmlhttpIW.send(null);
	}else{document.getElementById('hand_wt'+x).value=0;}
	totalWeight();}

function pkgWeight(x){
try {if(document.getElementById('order_type')) var orderType=document.getElementById('order_type').value;} catch(e){var orderType=0;}
var strPW=document.getElementById('code'+x).value;
var weightCode=strPW.slice(0,2);
var xmlhttpPW=getXmlHttpObject();
if(xmlhttpPW==null){alert("Browser does not support HTTP Request");return;}
var url="./ajax/pkg.php";
url=url+"?key="+weightCode;
url=url+"&x="+x;
url=url+"&sid="+Math.random();
xmlhttpPW.onreadystatechange=function(){
if(xmlhttpPW.readyState==4){
if(xmlhttpPW.status==200) {
var pkWeight=xmlhttpPW.responseText;
if(document.getElementById('d1'+x).value>36){var sizeMult=2;}else{var sizeMult=1;}
document.getElementById("pkg_wt"+x).value=pkWeight*sizeMult;}
totalWeight();}
};
xmlhttpPW.open("GET", url, true);
xmlhttpPW.send(null);}

function totalWeight(){
var sumWt=0;
// total item weight
var sumw=0; // The sum starts off at 0
for (var t=0; t < 10; t++){
var wtZ=0;
try {if(document.getElementById('weight'+t)!==null&&document.getElementById('weight'+t).value!==undefined) wtZ=document.getElementById('weight'+t).value;} catch(e){ wtZ=0;}
if(isNaN(parseFloat(wtZ))){wtZ=0;}
sumw += (parseFloat(wtZ)); /* Add the value to the sum*/}
sumWt=sumw; 
// total pkg weight
var sump=0; // The sum starts off at 0
for (var x=0; x < 10; x++){
var pkgWtz=0;
try {if(document.getElementById('pkg_wt'+x)!==null&&document.getElementById('pkg_wt'+x).value!==undefined) pkgWtz=document.getElementById('pkg_wt'+x).value;} catch(e){ pkgWtz=0;}
if(isNaN(parseFloat(pkgWtz))){pkgWtz=0;}
if(pkgWtz>sump){sump = parseFloat(pkgWtz);} /* Add the value to the sum*/}
sumWt=sumw+sump;
var tubeWt=document.getElementById('tube_wt').value;
tubeWt=parseFloat(tubeWt);
if(isNaN(tubeWt)){tubeWt=0;}
sumWt+=tubeWt;
document.getElementById('total_wt').value=sumWt.toFixed(2);
try { if(document.getElementById('ship_zip').value ) var shipZip=document.getElementById('ship_zip').value;} catch(e){ var shipZip='';}
if(shipZip!=''){shipFill();}
}

//shipping cost functions

function shipCost(ship){
var weight=document.getElementById("total_wt").value;
var zip=document.getElementById("ship_zip");
var tQty=parseInt(document.getElementById("tube_qty").value);
if(isNaN(tQty)){tQty=0;}
var quan=parseInt(document.getElementById("num_items").value)-tQty;
if(zip.value=='' && quan!=''){document.getElementById("zip_label").style.color='red';
if(document.getElementById('created')!==null&&getCheckedValue(document.forms['orderForm'].elements['created'])!="PC"&&getCheckedValue(document.forms['orderForm'].elements['created'])!="Mac"){
document.getElementById("created").style.color='red';document.getElementById("created2").style.color='red';}}
var xmlhttpSC=getXmlHttpObject();
if(xmlhttpSC==null){alert("Browser does not support HTTP Request");
return;}
var url="./ajax/ship.php";
url=url+"?weight="+weight;
url=url+"&ship="+ship;
url=url+"&zip="+zip.value;
url=url+"&sid="+Math.random();
xmlhttpSC.onreadystatechange=function(){
if(xmlhttpSC.readyState==4){
if(xmlhttpSC.status==200) {
var ship_cost=xmlhttpSC.responseText;
var code=0;
if(ship=="Standard"){code="soCost";
}else if(ship=="Priority"){code="poCost";
}else if(ship=="2nd_Day"){code="esCost";
}else if(ship=="Saturday"){code="sdCost";}
if(isNaN(parseFloat(ship_cost))){ship_cost=0;}
var ship_cost_pre_round=parseFloat(ship_cost)+3;
if(ship_cost_pre_round>3){
document.getElementById(code).value=ship_cost_pre_round.toFixed(2);
if(quan>1){
	document.getElementById('esCost').value="Free!";
	document.getElementById('esCost').style.color="#F30";
	document.getElementById('esCost').style.fontWeight="bold";
}else{
	document.getElementById('esCost').style.color="#000";
	document.getElementById('esCost').style.fontWeight="normal";}
if(code=="poCost"){satDeliveryPrice(25);}
}else{document.getElementById(code).value='';}
}}};
xmlhttpSC.open("GET", url, true);
xmlhttpSC.send(null);
fillDate('delivery_method');}

function shipFill(){
	document.getElementById('next').disabled=true;
	var shipStd=shipCost("Standard");
	var shipExp=shipCost("2nd_Day");
	var shipPro=shipCost("Priority");
	return shipStd;
	return shipExp;
	return shipPro;}

function satDeliveryPrice(x){
	if(document.getElementById('SD').disabled!=true){
	var PrioCost=document.getElementById('poCost').value;
	PrioCost=parseFloat(PrioCost)+x;
	if(PrioCost>0){document.getElementById('sdCost').value=PrioCost.toFixed(2);
	}else{document.getElementById('sdCost').value='';}
	fillDate('delivery_method');
	}
	}

function shipPrice(x){
var ship_price=document.getElementById(x).value;
var ship_Cost=document.getElementById('ship_cost');
if(ship_price!=0){ship_Cost.value=parseFloat(ship_price).toFixed(2);}
if(ship_Cost.value==="Free!"){var shipPrice=0;}else{var shipPrice=parseFloat(ship_Cost.value);}
var totalCost=(parseFloat(document.getElementById('sub_total').value)+shipPrice);
document.getElementById('total_cost').value=totalCost.toFixed(2);}

function fedExAcct(){
	document.getElementById('fedex_acct').style.color="black";
var fedEx=document.getElementById('fedex_acct').value;
if(fedEx.length>8){
document.getElementById('ship_cost').value=0;
document.getElementById('total_cost').value=document.getElementById('sub_total').value;
var shipMeth = document.getElementById('ship_meth');
shipBefore=shipMeth.innerHTML;
if(!shipBefore.match("charged")){
shipAfter=shipBefore+" (charged)";
}else{shipAfter=shipBefore;}
shipMeth.innerHTML=shipAfter;
}
else{
	var delivSel=getCheckedValue(document.forms['orderForm'].elements['delivery_method']);
	switch(delivSel){
	case "FedEx Second Day":var delivPrice="esCost";
	break;
	case "FedEx Standard Overnight":var delivPrice="soCost";
	break;
	case "FedEx Priority":var delivPrice="poCost";
	break;
	case "Pickup":var delivPrice="puCost";
	break;
	case "FedEx Saturday Delivery":var delivPrice="sdCost";
	break;
	case "FedEx International":var delivPrice="intCost";
	break;
	default:var delivPrice="error";
	break;}
	if(delivPrice!="error"){shipPrice(delivPrice);}
	document.getElementById('fedex_acct').style.color="red";
}
}

function intlZip(){
var zip=document.getElementById('ship_zip');
var zipVal=trim(zip.value);
zip.value=zipVal;
var zipCodePattern=/^\d{5}$|^\d{5}-\d{4}$/;
function zipTest(zip){return zipCodePattern.test(zipVal);}
if(zipVal.length!=0 && zipVal.length!=5 && zipVal.length!=10){
if(!zipTest(zip)){
var answer=confirm('This site does not calculate costs or transit times for international shipments. \nFedex.com can do this for you. Generally, we get next day service to major cities in Canada. \nLondon, Paris, and Berlin take two days; Rome, Tokyo, and Rio are three days. \n \nIf you wish to have this shipped internationally click \"OK\", otherwise, click \"Cancel\"')
if(answer){
document.getElementById('ship_cost').value=0;
document.getElementById('international_delivery').checked=true;
document.getElementById('intl_ship_row').setAttribute("class","viz");
document.getElementById('intl_ship_row').setAttribute("className","viz");
document.getElementById('PU_ship_row').setAttribute("class","hidden");
document.getElementById('PU_ship_row').setAttribute("className","hidden");
if(document.getElementById('puCost')){document.getElementById('esCost').value=0;}
if(document.getElementById('esCost')){document.getElementById('esCost').value=0;}
if(document.getElementById('soCost')){document.getElementById('soCost').value=0;}
if(document.getElementById('poCost')){document.getElementById('poCost').value=0;}
if(document.getElementById('sdCost')){document.getElementById('sdCost').value=0;}
document.getElementById('total_cost').value=document.getElementById('sub_total').value;
unRed('delivery_method');
}else{return;}
}
}else{
	document.getElementById('international_delivery').checked=false;
	document.getElementById('intl_ship_row').setAttribute("class","hidden");
	document.getElementById('intl_ship_row').setAttribute("className","hidden");
	document.getElementById('PU_ship_row').setAttribute("class","viz");
	document.getElementById('PU_ship_row').setAttribute("className","viz");}
fillDate('delivery_method');}

//main formCalc start
function initFormCalc(x){
	var sum=0;
	for (var i=0; i < 10; i++){
		var qtZ=0;
		try {if(document.getElementById('qty'+i).value) qtZ=document.getElementById('qty'+i).value;} catch(e){qtZ=0;}
		if(isNaN(parseInt(qtZ))){qtZ=0;}
		sum += parseInt(qtZ);} // Add the value to the sum
	document.getElementById('num_items').value=parseInt(sum);
	for(i=0;i<10;i++){
	var shortDim=0;
	try { if(document.getElementById('d1'+i).value ) shortDim=document.getElementById('d1'+i).value;} catch(e){ shortDim=0;}
	if(shortDim!=0){
		var longDim=0;
		try { if(document.getElementById('d2'+i).value ) longDim=document.getElementById('d2'+i).value;} catch(e){ longDim=0;}
		if(longDim!=0){
			var material=0;
			try { if(document.getElementById('material'+i).value ) material=document.getElementById('material'+i).value;} catch(e){ material=0;}
			if(material!=0){
				var mount=0;
				var itemCode=material+longDim+shortDim;
			}
		}
	}
		var qtyX=0;
		try {if(document.getElementById('qty'+i).value) qtyX=document.getElementById('qty'+i).value;} catch(e){qtyX=0;}
		if(qtyX!==undefined&&qtyX!=0&&qtyX!==''){
			calcEnd(i,itemCode);
		}else{
			document.getElementById('unit_cost'+i).value='';
			document.getElementById('item_total'+i).value='';}
		}
}

function calcEnd(x,itemCode){
	if(itemCode!==null){
	document.getElementById('code'+x).value=itemCode;
	itemCost(x);
	}else{
	try {if(document.getElementById('code'+x).value ) document.getElementById('code'+x).value='Item Not in Database!';} catch(e){return false;}
	document.getElementById('code'+x).value='Item Not in Database!';}
	return false;
}

//choice limiting functions
function dimRestrict(x){
	var totCost=document.getElementById('total_cost');
	var shpCost=document.getElementById('ship_cost');
	var delivDate=document.getElementById('deliver_date');
	if(shpCost.value==''||shpCost.value==null||delivDate.value==''||delivDate.value==null||delivDate.value==0||totCost.value==''||totCost.value==null||totCost.value!=0||totCost.value==shpCost.value){document.getElementById('next').disabled=true;}
var material=document.getElementById('material'+x);
var selectedMaterial=material[material.selectedIndex].value;
var dim1=document.getElementById('d1'+x);
var dim2=document.getElementById('d2'+x);
var d1si=document.getElementById('d1b'+x);
var d2si=document.getElementById('d2b'+x);
d1si.value=dim1.value;
d2si.value=dim2.value;
var sMax;
var lMax;
if(selectedMaterial==='TM' || selectedMaterial==='TG'){sMax=36;lMax=48;
dim1.options.length=0;
dim1.options[0]=new Option(sMax, sMax);
dim2.options.length=0;
dim2.options[0]=new Option(lMax, lMax);
}else{sMax=48;lMax=96;
dim1.options.length=0;
for (i=12; i <=(sMax/2); i++){
var dbl=i*2;
var iid=i-12;
dim1.options[iid]=new Option(dbl, dbl);}
dim2.options.length=0;
for (i=18; i <=(lMax/2); i++){
var dbl=i*2;
var iid=i-18;
dim2.options[iid]=new Option(dbl, dbl);}
setVal(dim1,d1si.value);
setVal(dim2,d2si.value);}}

function changeSoft(){
	var objBack=document.getElementById('created_in');
	var selBack=document.getElementById('created_in').value;
	var newSelBack = selBack.replace(" (PC)", "");
	var newSelBack = newSelBack.replace(" (Mac)", "");
	var selectedCheck=getCheckedValue(document.forms['orderForm'].elements['created']);
	
	if(selectedCheck=='PC'){
		objBack.options.length=0;
		objBack.options[0]=new Option('Choose one...', '');
		objBack.options[1]=new Option('PowerPoint 2010', 'PowerPoint 2010');
		objBack.options[2]=new Option('PowerPoint 2007', 'PowerPoint 2007');
		objBack.options[3]=new Option('PowerPoint 2003', 'PowerPoint 2003');
		objBack.options[4]=new Option('PowerPoint 2002', 'PowerPoint 2002');
		objBack.options[5]=new Option('PowerPoint 2000', 'PowerPoint 2000');
		objBack.options[6]=new Option('PowerPoint 97', 'PowerPoint 97');
		objBack.options[7]=new Option('PDF', 'PDF');
		objBack.options[8]=new Option('Other', 'Other');
		setVal(objBack,newSelBack);
	} else if(selectedCheck=='Mac'){
		objBack.options.length=0;
		objBack.options[0]=new Option('Choose one...', '');
		objBack.options[1]=new Option('PowerPoint 2008', 'PowerPoint 2008');
		objBack.options[2]=new Option('PowerPoint 2004', 'PowerPoint 2004');
		objBack.options[3]=new Option('PowerPoint X', 'PowerPoint X');
		objBack.options[4]=new Option('Keynote', 'Keynote');
		objBack.options[5]=new Option('PDF', 'PDF');
		objBack.options[6]=new Option('Other', 'Other');
		setVal(objBack,newSelBack);
	}else{
		objBack.options.length=0;
		objBack.options[0]=new Option('Choose an OS first', 'NO');
	}
}

//form layout funtions (hide and clear rows)
function deleteFile(x){
var fileD=document.getElementById('file_cell'+x);
fileD.innerHTML = fileD.innerHTML;
var d1D=document.getElementById('d1'+x);
if(d1D){d1D.value='';d1D.selectedIndex=0;}
var d2D=document.getElementById('d2'+x);
if(d2D){d2D.value='';d2D.selectedIndex=0;}
var d1bD=document.getElementById('d1b'+x);
if(d1bD){d1bD.value='';d1bD.value=0;}
var d2bD=document.getElementById('d2b'+x);
if(d2bD){d2bD.value='';d2bD.value=0;}
var materialD=document.getElementById('material'+x);
if(materialD){materialD.value='';materialD.selectedIndex=0;}
var qtyD=document.getElementById('qty'+x);
if(qtyD){qtyD.value='';}
var unitD=document.getElementById('unit_cost'+x);
if(unitD){unitD.value='';}
var itemD=document.getElementById('item_total'+x);
if(itemD){itemD.value='';}
var codeD=document.getElementById('code'+x);
if(codeD){codeD.value='';}
var weightD=document.getElementById('weight'+x);
if(weightD){weightD.value='';}
var pkgD=document.getElementById('pkg_wt'+x);
if(pkgD){pkgD.value='';}
initFormCalc(x);
}

function unHide(elem,newClass){
var invisElem=document.getElementById(elem);
if(invisElem!="" && invisElem!==null && invisElem!==undefined){
invisElem.style.display="inline";
invisElem.className=newClass;
invisElem.setAttribute("class", newClass);
invisElem.setAttribute("className", newClass);}
}

function unHideRow(x){
var y=x+1;
var invisRow=document.getElementById('row'+x);
if(invisRow!="" && invisRow!==null && invisRow!==undefined){
invisRow.style.display=="table-row";
invisRow.className=="viz";
invisRow.setAttribute("class","viz");
invisRow.setAttribute("className","viz");
}}

//functions for page 2 (bill-ship-contact info)
function resShip(){
if(document.getElementById('res_add').checked==true){
document.getElementById('res_ship').value=3;
}else{document.getElementById('res_ship').value=0;} 
}

function intlShip(sel){
if(sel.options.selectedIndex==1 || sel.options.selectedIndex==2){
alert('This site does not calculate costs or transit times for international shipments. \nFedex.com can do this for you. Generally, we get next day service to major cities in Canada. \nLondon, Paris, and Berlin take two days; Rome, Tokyo, and Rio are three days. \n \nThank you!');
document.getElementById('ship_cost').value=0;
document.getElementById('delivery_method').value="FedEx International";}
return false;}

function PO(){
var sub_add=document.getElementById('ship_add1').value;
var sub_addA=sub_add.substring(0,4);
var sub_addB=sub_addA.toLowerCase();
if(sub_addB.length >= 4){ 
	if(sub_addB=="pobo" || sub_addB=="po b" || sub_addB=="p o " || sub_addB=="p.o."){
		var answer=confirm('Fedex will not deliver to PO Boxes!\nTri-fold posters cannot be shipped to PO boxes!\nIf you must have your product shipped to a PO Box, we can ship it via USPS Priority Mail for the same price as Fedex 2nd Day shipping.\n\nRollable products can only be sent via priority mail.\n\nIf you need this shipped to a PO Box, and would like us to change your shipping selection (and price) to accomodate this click OK, if not, please click Cancel.');
		if(answer){
			document.getElementById('ship_cost').value=document.getElementById('esCost').value;
			document.getElementById('delivery_method').value="USPS Priority Mail";
			alert("Shipping changed!");
			document.getElementById('ship_add1').onkeyup="EnforceMaximumLength(this,30)";
		}else{
			document.getElementById('ship_add1').value='';}
		}
	}
}

function shipToBill(){
document.getElementById('bill_name').value=document.getElementById('ship_name').value;
document.getElementById('bill_company').value=document.getElementById('ship_company').value;
document.getElementById('bill_add1').value=document.getElementById('ship_add1').value;
document.getElementById('bill_add2').value=document.getElementById('ship_add2').value;
document.getElementById('bill_city').value=document.getElementById('ship_city').value;
document.getElementById('bill_state').value=document.getElementById('ship_state').value;
document.getElementById('bill_zip').value=document.getElementById('ship_zip').value;
document.getElementById('bill_country').value=document.getElementById('ship_country').value;
document.getElementById('bill_phone').value=document.getElementById('ship_phone').value;}
function billToShip(){
document.getElementById('ship_name').value=document.getElementById('bill_name').value;
document.getElementById('ship_company').value=document.getElementById('bill_company').value;
document.getElementById('ship_add1').value=document.getElementById('bill_add1').value;
document.getElementById('ship_add2').value=document.getElementById('bill_add2').value;
document.getElementById('ship_city').value=document.getElementById('bill_city').value;
document.getElementById('ship_state').value=document.getElementById('bill_state').value;
document.getElementById('ship_zip').value=document.getElementById('bill_zip').value;
document.getElementById('ship_country').value=document.getElementById('bill_country').value;
document.getElementById('ship_phone').value=document.getElementById('bill_phone').value;
PO();}
function sbToContact(){
if(document.getElementById('sbTc2').checked==true){
document.getElementById('con_name').value=document.getElementById('ship_name').value;
document.getElementById('con_company').value=document.getElementById('ship_company').value;
document.getElementById('con_phone').value=document.getElementById('ship_phone').value;
}else if(document.getElementById('sbTc3').checked==true){
document.getElementById('con_name').value=document.getElementById('bill_name').value;
document.getElementById('con_company').value=document.getElementById('bill_company').value;
document.getElementById('con_phone').value=document.getElementById('bill_phone').value;}
}

//funtions for page 3 (financial info)
function ccRequires(){
var objPaymentType=document.getElementById('cc_type');
var cardName=objPaymentType.options[objPaymentType.selectedIndex].value;
var cardNumCell=document.getElementById('card_num_cell');
var ccNum=document.getElementById('cc_number');
var cardNum=document.getElementById('card_num');
var expyCell=document.getElementById('expy_cell');
var ccExpy=document.getElementById('cc_expy');
var csvCell=document.getElementById('csv_cell');
var ccCSV=document.getElementById('cc_csv');
var ccNote=document.getElementById('cc_note');
var ppNote=document.getElementById('paypal_note');
if(cardName=='VISA' || cardName=='MasterCard' || cardName=='Discover' || cardName=='American Express'){
cardNumCell.style.display='block';
cardNum.innerHTML='<img src="./images/promotion.png" width="16" height="16" alt="promotion (1K)" /> Card Number:';
expyCell.style.display='block';
csvCell.style.display='block';
ccNote.style.display='block';
ppNote.style.display='none';
}else if(cardName=='Purchase Order' || cardName==''){
cardNumCell.style.display='block';
ccNum.value='';
cardNum.innerHTML='<img src="./images/promotion.png" width="16" height="16" alt="promotion (1K)" /> P.O.Number:';
expyCell.style.display='none';
ccExpy.value='';
csvCell.style.display='none';
ccCSV.value='';
ccNote.style.display='none';
ppNote.style.display='none';
}else if(cardName=='MegaPrint Account'){
cardNumCell.style.display='none';
ccNum.value='';
expyCell.style.display='none';
ccExpy.value='';
csvCell.style.display='none';
ccCSV.value='';
ccNote.style.display='none';
ppNote.style.display='none';
}else if(cardName=='PayPal'){
cardNumCell.style.display='block';
ccNum.value='';
cardNum.innerHTML='<img src="./images/promotion.png" width="16" height="16" alt="promotion (1K)" /> Account Email:';
expyCell.style.display='none';
ccExpy.value='';
csvCell.style.display='none';
ccCSV.value='';
ccNote.style.display='none';
ppNote.style.display='block';}
}