// JavaScript Document
function doagreefunction() {
	agewindow=dhtmlmodal.open('agebox', 'div', 'modalalertdiv', '', 'width=595px,height=740px,padding=0px,top=10px,left=300px,resize=0,scrolling=0')
/* var agreewin=dhtmlmodal.open("agreebox", "iframe", "popup-<?= $pg; ?>.html", "", "width=606px,height=744px,center=1,resize=0,scrolling=0", "recal")

agreewin.onclose=function(){ //Define custom code to run when window is closed
	var theform=this.contentDoc.getElementById("eula") //Access form with id="eula" inside iframe
	
	return true //Allow closing of window in both cases
} */
}
function process_age(whichbutton){
	if (whichbutton=="no")
		alert("Close")
	agewindow.hide()
}
function changeAction(formname,url) {
    formname.action = url;	
}

function matchEmails(email, email2) {
/* onSubmit="return matchEmails(this.email.value,this.email2.value)" */
if(email == email2) return true;
else  {
alert("Please make sure the email addresses match.");
return false; }
}

function fillShip()
{
this.orderform=document.forms['orderform'];
if(!this.orderform.ship_lname.value||!this.orderform.ship_fname.value||!this.orderform.ship_address.value||!this.orderform.ship_city.value||!this.orderform.ship_state.value||!this.orderform.ship_zip.value) {
this.orderform.ship_lname.value=this.orderform.name_card.value; this.orderform.ship_fname.value=this.orderform.name_cardf.value; this.orderform.ship_address.value=this.orderform.address.value; this.orderform.ship_city.value=this.orderform.city.value; this.orderform.ship_state.value=this.orderform.state.value;this.orderform.ship_zip.value=this.orderform.zip.value;
}
}
function fixCard()
{
this.orderform=document.forms['orderform'];
var cardnum = this.orderform.card_number.value;
cardnum = cardnum.replace(/\s+/g,'');
this.orderform.card_number.value=cardnum.replace(/-/g, '');
}

function getSum()
{
this.orderform=document.forms['orderform'];
//this.orderform.sub_total.value = formatDollar (Number(this.orderform.singleitemtotal.value) + Number(this.orderform.specialoffertotal.value));
//this.orderform.sub_total.value = formatDollar ((Number(this.orderform.quantity.value*10.95))+Number(this.orderform.specialoffertotal.value));
//var myindex  = this.orderform.quantity.selectedIndex;    
//this.orderform.sub_total.value = formatDollar (Number(this.orderform.p3quantity.value*10.95)+Number(this.orderform.p4quantity.value*10.95)+Number(this.orderform.specialoffertotal.value));
//this.orderform.subt1.value=Number(this.orderform.p1quantity.value*this.orderform.p1.value).toFixed(2)
this.orderform.singleitemtotal.value = formatDollar (Number(this.orderform.p3quantity.value*this.orderform.p3.value).toFixed(2));
this.orderform.specialoffertotal.value = formatDollar ((Number(this.orderform.p1quantity.value*this.orderform.p1.value)+Number(this.orderform.p2quantity.value*this.orderform.p2.value)).toFixed(2));
this.orderform.sub_total.value = formatDollar (Number(this.orderform.singleitemtotal.value)+Number(this.orderform.specialoffertotal.value));
getTax();
shippingamount =0;
var found_it 
for (var i=0; i<this.orderform.shippingt.length; i++)  {
    if (this.orderform.shippingt[i].checked)  {
    found_it = this.orderform.shippingt[i].value 
    } 
}
if(this.orderform.p2quantity.value>0){ 
	if(found_it=='RE1') shippingamount=Number(this.orderform.p2s.value); 
	else  shippingamount=Number(this.orderform.p2rs.value); } 
else if(this.orderform.p1quantity.value>0){ 
	if(found_it=='RE1') shippingamount=Number(this.orderform.p1s.value); 
	else shippingamount=Number(this.orderform.p1rs.value); 
}
else if(this.orderform.p3quantity.value>0){ 
	if(found_it=='RE1') shippingamount=Number(this.orderform.p3s.value); 
	else shippingamount=Number(this.orderform.p3rs.value); 
}
this.orderform.shipping.value=formatDollar (shippingamount);
this.orderform.total.value = formatDollar (Number(this.orderform.sub_total.value) + Number(this.orderform.salestax.value) + Number(this.orderform.shipping.value) - Number(this.orderform.discount.value));
this.orderform.total_amount.value = formatDollar (Number(this.orderform.sub_total.value) + Number(this.orderform.salestax.value) + Number(this.orderform.shipping.value) - Number(this.orderform.discount.value)); 
if(this.orderform.autoterms.checked || (this.orderform.p2quantity.value==0 && this.orderform.p1quantity.value==0)) 
{ this.orderform.submit.disabled=false;  this.orderform.submit.value='Click here to Submit Order'; } 
else { this.orderform.submit.disabled=true; this.orderform.submit.value='Please check the Auto ship Terms & Conditions box above.'; }
}