var fullname="";
var sval=0;
var amounttot=0;
var fullship=0; 
var maxset=20; 
var hex=0;
var setyn=new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
var setname=new Array(0,"MAME Hard Drive","Complete Hard Drive","MAME ROMs","MAME .36","MAME Update 144","MAME Update 143","DAPHNE","Unemulated Laser Games","GameBoys","S/NES","N64","Sega","Atari/Apple","Amiga","C64","PCE TG16","PCE ISO");
var sname=new Array("Please Select a Shipping Destination","the U.S. (First Class)","the U.S. (Priority Mail)","Canada","Mexico","Western Europe or Israel","Australia, New Zealand or Japan","Rest of the World");
var count=new Array(0,20,20,13,4,7,4,5,4,13,4,7,4,4,4,4,4,4);
var setcost=new Array(0,95,140.00,22.00,2.00,14.00,4.00,8.00,4.00,26.00,6.00,14.00,2.00,4.00,6.00,6.00,2.00,2.00);
var shipfactors=new Array(0,.47,5.15,.87,.92,.98,.98,.98);
var nopp=0;
var sfactor=0
var counttotal=0;
var pricetotal=0;
var amountdonation=0;
var newdonation=0;
var amountship=0;
var digits = "0123456789.";

function trackdonation(num2)

{ 
  if (num2.value == "")
  {
    amountdonation=0
	return;
  }
  for (var i = 0; i <num2.value.length; i++)
  {
    temp = num2.value.substring(i, i+1)

    if (digits.indexOf(temp) == -1 && 
     num2.value != "")
    {
      amountdonation=0
	  return;
    }
   }

   	amountdonation=(formatCurrency(num2.value));
	return;
}

function validater()

{	
	if (sval == 0)
	
	{
	alert("Please Make A ROM Set Selection");
	return false;
	}
	
	else
	
	if (fullship == 0)
	
	{
	alert("Please Choose a Shipping Location");
	return false;
	}
	
	else 
	
	if (document.myForm.Address.value.length  == 0)
	
	{
	alert("Please Enter Your Postal Address");
	return false;
	}
		
	var str=document.myForm.email.value
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
	{
		return true;
	}
	else
	{
		alert("Please Enter a Valid Email Address!");
		return false
	}

return true;

}


function sendit()

{	
	if (sval == 0)
	
	{
	alert("Please Make a Selection");
	return;
	}
	
	else
	
	if (fullship == 0)
	
	{
	alert("Please Select a Shipping Destination");
	return;
	}
	
	else 
	
	var donationname="";
	var fullname="";
	for (var id = 1; id <= maxset; id++)
 	{
	if (setyn[id] == 1) 
		
		{ 
		var fullname=(fullname + '-' + setname[id] + '-');
		}
	}
		
	var amounttot = (eval(document.roms.pricetotal.value) + eval(amountdonation));
	var amounttot = formatCurrency(amounttot);
	
	if (amountdonation != 0)
	 
	{
	var donationname="::Thanks for your Donation!:";;
	}
	
	document.myForm.Selections.value = document.roms.Selections.value;
	return;
}


function sendit2()

{	
	if (sval == 0)
	
	{
	document.myForm.Selections.value = "";
	return;
	}
	
	else
	
	if (fullship == 0)
	
	{
	document.myForm.Selections.value = "";
	return;
	}
	
	else 
	
	var donationname="";
	var fullname="";
	for (var id = 1; id <= maxset; id++)
 	{
	if (setyn[id] == 1) 
		
		{ 
		var fullname=(fullname + '-' + setname[id] + '-');
		}
	}
		
	var amounttot = (eval(document.roms.pricetotal.value) + eval(amountdonation));
	var amounttot = formatCurrency(amounttot);
	
	if (amountdonation != 0)
	 
	{
	var donationname="::Thanks for your Donation!:";;
	}
	
	document.myForm.Total.value = amounttot;
	document.myForm.Selections.value = "I would like the following sets:\r\n\r\n"+fullname+"\r\n\r\nShipped to "+shipname+" for a total of $"+amounttot;
 	
}



function CheckChoice(whichbox)
	{  
		with (whichbox.form)
		{
			
			//Handle differently, depending on type of input box.
			if (whichbox.name == "shipto")
			{
				shipname=sname[whichbox.value];
				sfactor=shipfactors[whichbox.value];
								
				if (sfactor != 5.15)
					{fullship=eval(sfactor*counttotal.value);}
					else
					{fullship=5.15;}
				
				if (counttotal.value == 0)
					{fullship=0;amountship.value=0}
					
				//First, back out the prior radio selection's price from the total:
				pricetotal.value = eval(pricetotal.value) - eval(amountship.value);
				//Then, save the current radio selection's price:
				amountship.value = fullship;
				//Now, apply the current radio selection's price to the total:
				pricetotal.value = eval(pricetotal.value) + fullship;
				nopp.value = formatCurrency(pricetotal.value-((pricetotal.value * .029)+.30));
 			}
			else
			{	//If box was checked, accumulate the checkbox value as the form total,
				//Otherwise, reduce the form total by the checkbox value:
				if (whichbox.checked == false)
					
				{
				setyn[whichbox.id]=0;
				pricetotal.value = eval(pricetotal.value) - eval(whichbox.value); 
				counttotal.value = eval(counttotal.value) - eval(count[whichbox.id]);
				sval = counttotal.value;
				
				if (sfactor != 5.15)
					{fullship=eval(sfactor*counttotal.value);}
					else
					{fullship=5.15;}
					
					if (counttotal.value == 0)
					{fullship=0;amountship.value=0}
					
				//First, back out the prior radio selection's price from the total:
				pricetotal.value = eval(pricetotal.value) - eval(amountship.value);
				//Then, save the current radio selection's price:
				amountship.value = fullship;
				//Now, apply the current radio selection's price to the total:
				pricetotal.value = eval(pricetotal.value) + fullship;
				nopp.value = formatCurrency(pricetotal.value-((pricetotal.value * .029)+.30));
				}
				
				else
				
				{
				setyn[whichbox.id]=1;
				pricetotal.value = eval(pricetotal.value) + eval(whichbox.value); 
				counttotal.value = eval(counttotal.value) + eval(count[whichbox.id]);
				sval = counttotal.value;
				
				if (sfactor != 5.15)
					{fullship=eval(sfactor*counttotal.value);}
					else
					{fullship=5.15;}
					
					if (counttotal.value == 0)
					{fullship=0;amountship.value=0}
					
				//First, back out the prior radio selection's price from the total:
				pricetotal.value = eval(pricetotal.value) - eval(amountship.value);
				//Then, save the current radio selection's price:
				amountship.value = fullship;
				//Now, apply the current radio selection's price to the total:
				pricetotal.value = eval(pricetotal.value) + fullship;
				nopp.value = formatCurrency(pricetotal.value-((pricetotal.value * .029)+.30));
				}
			}
			
			if (counttotal.value <=0 || pricetotal.value < 0)
				{
				document.roms.reset();InitForm();
				}
	 
			//Now, return with formatted total:
			return(sendit2(formatCurrency(pricetotal.value)));
		}
}

//Define function to format a value as currency:
function formatCurrency(val)
{		 
	var str,pos;
 	str = escape (val*1.0 + 0.005001);
  	pos = str.indexOf (".");
  	if (pos > 0) str = str.substring (0, pos + 3);
  	return str;

} 

function InitForm()
{
		//Reset the displayed total on form:
		document.roms.total.value=0;
		document.roms.nopp.value=0;
		document.roms.pricetotal.value=0;
		document.roms.amountship.value=0;
		document.roms.counttotal.value=0;
		var ppwin=null;
var fullname="";
var amounttot=0; 
var hex=0;
var fullship=0;
var nopp=0;
var sfactor=0
var counttotal=0;
var pricetotal=0;
var amountdonation=0;
var amountship=0;
var digits = "0123456789";
}
