var pageParams = document.location.search.substring(1).split(",");
var isShop = (pageParams[0] == "shop");
var doGoogle = true;

function getexpirydate(nodays)
{
  var UTCstring;
  Today = new Date();
  nomilli=Date.parse(Today);
  Today.setTime(nomilli+nodays*24*60*60*1000);
  UTCstring = Today.toUTCString();
  return UTCstring;
}

function setCookie(name,value,duration)
{
  cookiestring = name + "=" + escape(value) + ";EXPIRES=" + getexpirydate(duration);
  document.cookie = cookiestring;
}

function getCookie(cookiename)
{
  var cookiestring = "" + document.cookie;
  var index1 = cookiestring.indexOf(cookiename);
  if ((index1 == -1) || (cookiename == ""))
    return ""; 
  var index2 = cookiestring.indexOf(';',index1);
  if (index2 == -1)
    index2 = cookiestring.length; 
  return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}


var tabDataMain = [
	["products","spherolinder.html"],
	["about","g2-about.html"],
	["facilities","g2-facilities.html"],
	["contact","g2-contact.html"],
	["",""],
	["",""],
	["",""]
]

var tabDataProd;

var tabDataProd1 = [
[   ["spherolinder","spherolinder.html"],
	["catalog","spherolinder-catalog.html"],
	["<nobr>papers &<nobr><br>datasheets","spherolinder-applications.html"],
	["load<br>calculator","spherolinder-calculator.html"],
    ["press","spherolinder-press.html"],
	["<font color='red'>buy</font>","spherolinder-catalog-25.html?shop"],
	["",""]  ]
];


var tabDataProd2 = [
[   ["spherolinder","spherolinder.html"],
	["catalog","spherolinder-catalog.html"],
	["white<br>papers","spherolinder-applications.html"],
	["load<br>calculator","spherolinder-calculator.html"],
    ["press","spherolinder-press.html"],
	["",""],
	["",""]  ],

[   ["diagoSeal","diagoseal.html"],
	["principle","diagoseal-principle.html"],
	["applications","diagoseal-applications.html"],
	["catalog","diagoseal-catalog.html"],
	["",""],
	["",""],
	["",""]  ]
];


var spCatBarData = [
["overview","spherolinder-catalog.html"],
["M25","spherolinder-catalog-25.html"],
["M10","spherolinder-catalog-10.html"],
["<small>assembly<br>instructions</small>","spherolinder-catalog-instructions.html"]
]

var spOvrBarData = [
["applications","spherolinder-applications.html"],
["principle","spherolinder-engineering.html"],
["math","spherolinder-math.html"],
["kinematic<br>tutorial","spherolinder-tutorial.html"]
]



//--------------------

function writePageTableAndLogo()
{
  document.write("<table bgcolor='#ffffff' cellspacing=5 cellpadding=0><tr>");
  document.write("<td class='tableCellBlue' width=10 height=10 align='bottom' onclick='window.location.href=\"index.html\"' style='padding:0px'><a href='index.html'><img border=0 width=109 height=136 src='images/g2.jpg'></a></td>");
}

function writePageHeaderMain(tabN)
{
  writePageTableAndLogo()
  for (var i=0; i<tabDataMain.length; i++)
    drawOneTabMain(i,tabN);
  document.write("</tr>");
}

function drawOneTabMain(tabN,selTabN)
{
  var text = tabDataMain[tabN][0];
  var url = tabDataMain[tabN][1];
  var cellClassName = (selTabN == tabN) ? "tableCellGray" : "tableCellBlue";
  var textClassName = (selTabN == tabN) ? "tabberLinkBlue" : "tabberLinkWhite";
  var oc = text ? "onClick='window.location.href=\""+url+"\"'" : "";

  document.write("<td class='"+cellClassName+"' width=10 valign='bottom' style='padding-bottom:2px' "+oc+">");
  document.write("<img border=0 width=118 src='images/spacer118w.gif'><br>");
  if (text)
  {
    document.write("<div style='margin-left:3px'><a class='"+textClassName+"' href='"+url+"'>");
    document.write(text);
    document.write("</a></div>");
  }
  document.write("</td>");
}


//-----------------------------

function writePageHeaderProd(prodN,tabN)
{
  tabDataProd = tabDataProd1;
  if (getCookie('showSeal'))
    tabDataProd = tabDataProd2;

  writePageTableAndLogo()
  for (var i=0; i<tabDataProd[prodN].length; i++)
    writeTabProd(prodN,i,tabN);
  document.write("</tr>");
}

function writeTabProd(prodN,tabN,selTabN)
{
  if (tabN == 0)
    writeIndexTabProd(prodN,selTabN)
  else
    writeOneTabProd(prodN,tabN,selTabN)
}

//tabNo=0
function writeIndexTabProd(prodN,selTabN)
{
  var cellClassName = (selTabN == 0) ? "tableCellGray" : "tableCellBlue";
  var oc = (selTabN == 0) ? "" : "onClick='window.location.href=\""+tabDataProd[prodN][0][1]+"\"'";

  document.write("<td class='"+cellClassName+"' width=10 valign='top' style='padding-top:3px'>");
  for (var i=0; i<tabDataProd.length; i++)
  {
    var textClassName = (selTabN == 0) ?
                        ( (i == prodN) ? 'prodTabHiTextHi' : 'prodTabHiText' ) :  //gray bgnd
                        ( (i == prodN) ? 'prodTabTextHi' : 'prodTabText' );       //blue bgnd
    document.write("<a class='"+textClassName+"' style='margin-left:3px;'  href='"+tabDataProd[i][0][1]+"'>");
    document.write(tabDataProd[i][0][0]);
    document.write("</a><br>");
  }
  document.write("<img border=0 width=118 src='images/spacer118w.gif'>");
  document.write("</td>");
}

//tabNo=1,2,3
function writeOneTabProd(prodN,tabN,selTabN)
{
  var text = tabDataProd[prodN][tabN][0];
  var url = tabDataProd[prodN][tabN][1];
  var cellClassName = (selTabN == tabN) ? "tableCellGray" : "tableCellBlue";
  var textClassName = (selTabN == tabN) ? "tabberLinkBlue" : "tabberLinkWhite";
  var oc = text ? "onClick='window.location.href=\""+url+"\"'" : "";

  document.write("<td class='"+cellClassName+"' width=10 valign='bottom' style='padding-bottom:2px' "+oc+">");
  document.write("<img border=0 width=118 src='images/spacer118w.gif'><br>");
  if (text)
  {
    document.write("<div style='margin-left:3px'><a class='"+textClassName+"' href='"+url+"'>");
    document.write(text);
    document.write("</a></div>");
  }
  document.write("</td>");

}


//----------------------------------

function writePageFooter()
{
  document.write("<tr><td height=18 class='tableCellBlue' colspan=8 valign='middle'>");
  document.write("<table height='100%' width='100%' border=0><tr><td align='left'>");
  document.write("<div class='legal'><a class='btmTabberLinkWhite' href='javascript:setCookie(\"showSeal\",\"x\",1);alert(\"Seal pages enabled for 1 day\")'>&nbsp;</a></div>");
  document.write("</td><td align='right'>");
  document.write("<div class='legal'>&copy; 2005 g<sup>2</sup> engineering&nbsp;&nbsp;</div>");
  document.write("</td></tr></table>");
  document.write("</td></tr></table>");  //end page table

//  document.write("<tr><td height=18 class='tableCellBlue' colspan=8 valign='middle' align='right'>");
//  document.write("<div class='legal'>&copy; 2005 g<sup>2</sup> engineering&nbsp;&nbsp;</div></td></tr></table>");
}

function writePageFooterSpherolinder()
{
  document.write("<tr><td height=18 class='tableCellBlue' colspan=8 valign='middle'>");
  document.write("<table height='100%' width='100%' border=0><tr><td align='left'>");
  document.write("<div class='legal'><a class='btmTabberLinkWhite' href='index.html'>home</a>&nbsp;|&nbsp;<a class='btmTabberLinkWhite' href='g2-contact.html'>contact</a>&nbsp;|&nbsp;<a class='btmTabberLinkWhite' href='spherolinder.html'>spherolinder</a></div>");
  document.write("</td><td align='right'>");
  document.write("<div class='legal'>US patent 6729589&nbsp;|&nbsp;&copy; 2005 g<sup>2</sup> engineering&nbsp;&nbsp;</div>");
  document.write("</td></tr></table>");
  document.write("</td></tr></table>");  //end page table
//  document.write("<div class='legal'>US patent 6729589&nbsp;|&nbsp;&copy; 2005 g<sup>2</sup> engineering&nbsp;&nbsp;</div></td></tr></table>");
}

function writePageFooterDiagoseal()
{
  document.write("<tr><td height=18 class='tableCellBlue' colspan=8 valign='middle'>");
  document.write("<table height='100%' width='100%' border=0><tr><td align='left'>");
  document.write("<div class='legal'><a class='btmTtabberLinkWhite' href='index.html'>home</a>&nbsp;|&nbsp;<a class='tabberLinkWhite' href='g2-contact.html'>contact</a>&nbsp;|&nbsp;<a class='tabberLinkWhite' href='spherolinder.html'>spherolinder</a>&nbsp;|&nbsp;<a class='tabberLinkWhite' href='diagoseal.html'>diagoseal</a></div>");
  document.write("</td><td align='right'>");
  document.write("<div class='legal'>US patent 6729589&nbsp;|&nbsp;&copy; 2005 g<sup>2</sup> engineering&nbsp;&nbsp;</div>");
  document.write("</td></tr></table>");
  document.write("</td></tr></table>");  //end page table
//  document.write("<div class='legal'>US patent 6729589&nbsp;|&nbsp;&copy; 2005 g<sup>2</sup> engineering&nbsp;&nbsp;</div></td></tr></table>");
}

//-------------------------------------

function spCatBarCell(i,n)
{
  var spUrl = spCatBarData[i][1];
  if (isShop)
    spUrl += "?shop"
  if (i==n)
    document.writeln("<td class='tableCellGray' align='center' valign='middle' height=30 nowrap style='padding: 0px 10px'>"+spCatBarData[i][0]+"</td>");
  else
    document.writeln("<td class='tableCellBlue' align='center' valign='middle' height=30 nowrap style='padding: 0px 10px'><a class='tabberLinkWhite' href='"+spUrl+"'>"+spCatBarData[i][0]+"</a></td>");
}

function spCatBar(n)
{
  document.writeln("<table align='center' bgcolor='white' cellspacing=5 cellpadding=0 style='border-top: thin black solid; border-bottom: thin black solid'><tr>");
  for (var i=0; i<spCatBarData.length; i++)
    spCatBarCell(i,n);
  document.writeln("</tr></table><p>");
}

//-------------------------------------

function spOvrBarCell(i,n)
{
  if (i==n)
    document.writeln("<td class='tableCellGray' align='center' valign='middle' height=30 nowrap style='padding: 0px 10px'>"+spOvrBarData[i][0]+"</td>");
  else
    document.writeln("<td class='tableCellBlue' align='center' valign='middle' height=30 nowrap style='padding: 0px 10px'><a class='tabberLinkWhite' href='"+spOvrBarData[i][1]+"'>"+spOvrBarData[i][0]+"</a></td>");
}

function spOvrBar(n)
{
  document.writeln("<table align='center' bgcolor='white' cellspacing=5 cellpadding=0 style='border-top: thin black solid; border-bottom: thin black solid'><tr>");
  for (var i=0; i<spOvrBarData.length; i++)
    spOvrBarCell(i,n);
  document.writeln("</tr></table><p>");
}

// -------------  catalog/shop ------------------

//item_name, price, pp_description
var catalogList = [
["SPH-ST-SS1-M25", 350, "M25 Spherolinder, Stainless Steel 440C, Standard"],
["SPH-ST-SS2-M25", 275, "M25 Spherolinder, Stainless Steel 17-4 PH, Standard"],
["SPH-ST-AL1-M25", 200, "M25 Spherolinder, Aluminum 7075, Standard"],
["SPH-VBLK-SS1-M25", 250, "V-block for M25 Spherolinder, Stainless Steel 440C"],
["SPH-VBLK-SS2-M25", 200, "V-block for M25 Spherolinder, Stainless Steel 17-4 PH"],
["SPH-VBLK-AL1-M25", 150, "V-block for M25 Spherolinder, Aluminum 7075"],
["SPH-CBLK-SS1-M25", 250, "Cone-block for M25 Spherolinder, Stainless Steel 440C"],
["SPH-CBLK-SS2-M25", 200, "Cone-block for M25 Spherolinder, Stainless Steel 17-4 PH"],
["SPH-CBLK-AL1-M25", 150, "Cone-block for M25 Spherolinder, Aluminum 7075"],
["SPH-RTNRB-SS2-M25", 100, "Blind retainer for M25 Spherolinder, Stainless Steel PH 17-4"],
["SPH-RTNRT-SS2-M25", 125, "Thru retainer for M25 Spherolinder, Stainless Steel PH 17-4"],
["SPH-RTNRG-AL2-M25", 25, "Alignment Guide for M25 Spherolinder, Aluminum"],
["SPH-FPA-SS2-M25", 20, "Flat plate adapters for M25 Mounting Blocks, Stainless Steel PH 17-4"],
["SPH-MPLTM-AL2-M25", -1, "Modular plate for M25 Mounting Blocks, Metric Grid, Aluminum 6061"],
["SPH-MPLTS-AL2-M25", -1, "Modular plate for M25 Mounting Blocks, Standard Grid, Aluminum 6061"],

["SPH-ST-SS1-M10", 325, "M10 Spherolinder, Stainless Steel 440C, Standard"],
["SPH-ST-SS2-M10", 250, "M10 Spherolinder, Stainless Steel 17-4 PH, Standard"],
["SPH-ST-AL1-M10", 175, "M10 Spherolinder, Aluminum 7075, Standard"],
["SPH-VBLK-SS1-M10", 225, "V-block for M10 Spherolinder, Stainless Steel 440C"],
["SPH-VBLK-SS2-M10", 175, "V-block for M10 Spherolinder, Stainless Steel 17-4 PH"],
["SPH-VBLK-AL1-M10", 125, "V-block for M10 Spherolinder, Aluminum 7075"],
["SPH-CBLK-SS1-M10", 225, "Cone-block for M10 Spherolinder, Stainless Steel 440C"],
["SPH-CBLK-SS2-M10", 175, "Cone-block for M10 Spherolinder, Stainless Steel 17-4 PH"],
["SPH-CBLK-AL1-M10", 125, "Cone-block for M10 Spherolinder, Aluminum 7075"],
["SPH-RTNRB-SS2-M10", 65, "Blind retainer for M10 Spherolinder, Stainless Steel PH 17-4"],
["SPH-RTNRT-SS2-M10", 115, "Thru retainer for M10 Spherolinder, Stainless Steel PH 17-4"],
["SPH-FPA-SS2-M10", 15, "Flat plate adapters for M10 Mounting Blocks, Stainless Steel PH 17-4"],
["SPH-MPLTM-AL2-M10", -1, "Modular plate for M10 Mounting Blocks, Metric Grid, Aluminum 6061"],
["SPH-MPLTS-AL2-M10", -1, "Modular plate for M10 Mounting Blocks, Standard Grid, Aluminum 6061"],

["SPH-KIT1-TS-M25", 750, "M25 Stack TS Special"],
["SPH-KIT3-TS-M25", 2000, "M25 3-Stack TS Special"],

["TEST-1", 0.01, "Test transfer"]

]

var catalog = new Object()
for (var i=0; i<catalogList.length; i++)
  catalog[catalogList[i][0]] = catalogList[i];


function writeCatLink()
{
  if (!isShop)
    document.write("<font color='red'>New!...</font>&nbsp;&nbsp;<a href='?shop'>Buy Online!</a>");
  document.write("<p><br>");
}
  
function writeCatHeader()
{
  document.write("<table border=0>");
}

function writeCatFooter()
{
  document.write("</table>");
}
  
function writeHeadLine(html,imageHTML,nRows)
{
  document.write("<tr><td colspan=5>"+html+"</td>");
  if (nRows > 0)
    document.write("<td valign='middle' width=125 align='center' rowspan="+nRows+">"+imageHTML+"</td>");
  document.write("</tr>");
}

function writeSepLine()
{
  document.write("<tr><td colspan=6><hr></td></tr>");
}
  
function writeItemLine(itemName, text, specUrl)
{
  document.write("<tr><td width=10>&bull;</td>");
  document.write("<td width=150>"+text+"</td>");
  if (!specUrl)
    document.write("<td width=175>"+itemName+"</td>");
  else
    document.write("<td width=175><a class='docLink' target='exDocWin' href='documents/spherolinder/"+specUrl+"'>"+itemName+"</a></td>");  
  var price = catalog[itemName][1];
  var priceStr = (price == -1) ? "call" : "$"+price;
  document.write("<td width=75>"+priceStr+"</td>");
//  var disStr = (price == -1) ? " disabled" : "";
  var boxHTML = "";
  if (isShop)
    boxHTML = (price == -1) ? "<hr width=30>" : "<input id='q_"+itemName+"' name='q_"+itemName+"' type='text' size=2 onkeyDown='window.doNum(event,this,2)' onKeyUp='window.doRecalc()' onChange='window.doRecalc()'>";
  var boxWidth = isShop ? 70 : 1;
  document.write("<td width="+boxWidth+">"+boxHTML+"</td>");
  document.write("</tr>");
}

function writeTotalLine()
{
  if (isShop)
  {
    document.write("<tr><td colspan=6><hr></td></tr>");
    document.write("<tr><td colspan=1><b>#</b></td><td align='right' colspan=1><b>Quantity</b> x </td><td colspan=1><b>Item</b></td><td colspan=1><b>Price</b></td><td colspan=2><b>Extended</b></td></tr>");
    document.write("<tr><td id='lineItemN' colspan=1></td><td id='lineItemQ' align='right' colspan=1></td><td id='lineItemI' colspan=1></td><td colspan=1 id='lineItemP'></td><td colspan=2 id='lineItemEP'></td></tr>");
    document.write("<tr><td colspan=4><b>Total</b></td><td colspan=2 id='totalCostCell'>$0.00</td></tr>");
    if (getCookie("shopTS"))
      document.write("<tr><td colspan=4><b>Total</b></td><td colspan=2 id='totalCostCell2'><input id='total2' name='total2' type='text' size=7 onkeyDown='doNum(this,9)' onKeyUp='doRecalc()' onChange='doRecalc()'></td></tr>");
if (!doGoogle)
{  
//	document.write("<tr><td colspan=3>If non-taxable, enter reseller ID:</td><td colspan=3><input id='resellId' name='resellId' type='text' size=9 onkeyDown='doNum(this,9)' onKeyUp='doRecalc()' onChange='doRecalc()'></td></tr>");
//	document.write("<tr><td colspan=3>If government, enter tax exempt ID:</td><td colspan=3><input id='exemptId' name='exemptId' type='text' size=9 onkeyDown='doNum(this,9)' onKeyUp='doRecalc()' onChange='doRecalc()'></td></tr>");
//	document.write("<tr><td colspan=3>Please select shipping address state:</td><td colspan=3><select id='stateCode' name='stateCode' onchange='doRecalc()'><option value=''></option>")
//	for (var i=0; i<stateCodes.length; i++)
//	  document.write("<option value='"+stateCodes[i]+"'>"+stateCodes[i]+"</option>");
//	for (var i=0; i<otherCodes.length; i++)
//	  document.write("<option value='"+otherCodes[i]+"'>"+otherCodes[i]+"</option>");
//	document.write("</select></td></tr>");
//    document.write("<tr><td colspan=4>Tax</td><td colspan=2 id='taxCell'>$0.00</td></tr>");
//    document.write("<tr><td colspan=4>Shipping and Handling</td><td colspan=2 id='shCell'>$0.00</td></tr>");
//    document.write("<tr><td colspan=4>Billing Total</td><td colspan=2 id='totalBillCell'>$0.00</td></tr>");
}
    document.write("<tr><td colspan=6><hr></td></tr>");
    document.write("<tr>");
//	document.write("<td colspan=4>For a secure credit card payment through the PayPal&trade;<br>payment system, please hit the \"check out\" button.<br><u>Use any card, you do not need to open a PayPal account.</u><br>Please be sure to fill in the contact phone number, since<br>supply times may vary. With any questions, please contact<br>us at 650-605-4500 or <a href='mailto:sales@g2-engineering.com'>sales@g2-engineering.com.</a></td>");
	document.write("<td colspan=4>Free ground shipping on web orders.<br>Please contact us with any questions at 650-605-4500<br>or email us at <a href='mailto:sales@g2-engineering.com'>sales@g2-engineering.com.</a></td>");
    document.write("<td colspan=2 align='center'>");
	document.write("<img src='images/paypal/logo_ccVisa.gif'><img src='images/paypal/logo_ccMC.gif'><img src='images/paypal/logo_ccAmex.gif'><img src='images/paypal/logo_ccDiscover.gif'><img src='images/paypal/logo_ccEcheck.gif'><p>");
//	document.write("<img src='images/paypal/icon_payPalLogo_30x30.gif'><img src='images/paypal/logo_ccVisa.gif'><img src='images/paypal/logo_ccMC.gif'><img src='images/paypal/logo_ccAmex.gif'><img src='images/paypal/logo_ccDiscover.gif'><img src='images/paypal/logo_ccEcheck.gif'><p>");
	document.write("<button onclick='doSubmit()'>accept and check out</button></td></tr>");
    document.write("<tr><td colspan=6><hr></td></tr>");
    document.write("<tr><td colspan=6><iframe id='submitFrame' name='submitFrame' width='500' height=0 src='about:blank'></iframe></td></tr>");
  }
  else
    document.write("<tr><td colspan=6><small>All prices and specifications are subject to change.</small></td></tr>");
}

function doNum(event,f,n)
{
  var isFull = (f.value.length >= n);
  var kc=event.keyCode;

  var isNumKey = (((kc >= 48) && (kc < 58)) || ((kc >= 96) && (kc < 106)));
  var isCtrlKey = ((kc < 48) || (kc == 144) || event.ctrlKey || event.altKey);
  
  if (isCtrlKey || (!isFull && isNumKey))
    return;
alert(9)
//  event.returnValue = false;
  return false;
}

function formatDollars(num)
{
  num = num.toString().replace(/\$|\,/g,'');
  if(isNaN(num))
    num = "0";
  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num*100+0.50000000001);
  cents = num%100;
  num = Math.floor(num/100).toString();
  if(cents<10)
    cents = "0" + cents;
  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
  return (((sign)?'':'-') + '$' + num + '.' + cents);
}

var totalCost = 0;
var tax = 0;
var sh = 0;
var totalBill = 0;

function doRecalc()
{
  totalCost = 0;
  var n = 0;
  var lineItemN = "";
  var lineItemQ = "";
  var lineItemI = "";
  var lineItemP = "";
  var lineItemEP = "";
  for (var i=0; i<catalogList.length; i++)
  {
    var itemName = catalogList[i][0];
    var f = document.getElementById("q_"+itemName)
	if (f == null)
	  continue;
    if (f.value == null)
	  continue;
    if (!f.value)
	  continue;
	n ++;
	lineItemN = lineItemN + n + ".<br>"
	totalCost += catalog[itemName][1] * f.value;
    lineItemQ = lineItemQ + f.value + " x <br>";
    lineItemI = lineItemI + itemName + "<br>";
    lineItemP = lineItemP + formatDollars(catalog[itemName][1]) + "<br>";
    lineItemEP = lineItemEP + formatDollars(f.value * catalog[itemName][1]) + "<br>";
  }

  if (n==0)
    lineItemI = "(no items)";
/*
  var taxRate = 0.0825;
  if (document.getElementById("resellId").value > 0)
    taxRate = 0;

  if (document.getElementById("exemptId").value > 0)
    taxRate = 0;

  if (document.getElementById("stateCode").value != "CA")
    taxRate = 0;
*/
  document.getElementById("lineItemN").innerHTML = lineItemN;
  document.getElementById("lineItemQ").innerHTML = lineItemQ;
  document.getElementById("lineItemI").innerHTML = lineItemI;
  document.getElementById("lineItemP").innerHTML = lineItemP;
  document.getElementById("lineItemEP").innerHTML = lineItemEP;
  document.getElementById("totalCostCell").innerText = formatDollars(totalCost);
//  tax = totalCost * taxRate;
//  sh = 20;
//  totalBill = totalCost + tax + sh;
//  document.getElementById("taxCell").innerText = formatDollars(tax);
//  document.getElementById("shCell").innerText = formatDollars(sh);
//  document.getElementById("totalBillCell").innerText = formatDollars(totalBill);
}

function doSubmit()  //called on submit
{
  doRecalc();
  var d = window.submitFrame.document;
  d.open();
  d.write("<html><head></head><body>");
  
  if (doGoogle)
  {
    d.write("<form name='submitForm' id='submitForm' method='post' action='https://checkout.google.com/cws/v2/Merchant/609056161857007/checkoutForm' target='_parent' accept-charset='utf-8'>");
    d.write("<input type='hidden' name='tax_us_state' value='CA'>");
    d.write("<input type='hidden' name='tax_rate' value='0.0725'>");
    d.write("<input type='hidden' name='_charset_'> ");
    d.write("<input type='image' name='Google Checkout' alt='Fast checkout through Google'\
      src='http://sandbox.google.com/checkout/buttons/checkout.gif?merchant_id=1234567890&w=180&h=46&style=white&variant=text&loc=en_US' height='46' width='180'>");

    itemCount = 0;
    for (var i=0; i<catalogList.length; i++)
    {
      var itemName = catalogList[i][0];
      var f = document.getElementById("q_"+itemName);
	  if (f == null)
	    continue;
      if (f.value == null)
	    continue;
      if (!f.value)
	    continue
      itemCount++;
  	  d.write("<input type='hidden' name='item_name_"+itemCount+"' value='"+itemName+"'>");
	  d.write("<input type='hidden' name='item_description_"+itemCount+"' value='"+catalog[itemName][2]+"'>");
	  d.write("<input type='hidden' name='item_price_"+itemCount+"' value='"+catalog[itemName][1]+"'>");
	  d.write("<input type='hidden' name='item_quantity_"+itemCount+"' value='"+f.value+"'>");
    }
    d.write("</form>");
  }
  else //doPayPal
  {
    d.write("<form name='submitForm' id='submitForm' action='https://www.paypal.com/cgi-bin/webscr' method='post' target='_parent'>");
    d.write("<input type='hidden' name='cmd' value='_cart'>");
    d.write("<input type='hidden' name='upload' value='1'>");
    d.write("<input type='hidden' name='business' value='jerri@gizmonicsInc.com'>");
    d.write("<input type='hidden' name='currency_code' value='USD'>");
    d.write("<input type='hidden' name='return' value='http://www.g2-engineering.com/spherolinder-paypal-ok.html'>");
    d.write("<input type='hidden' name='cancel_return' value='http://www.g2-engineering.com/spherolinder-paypal-cancel.html'>");
    d.write("<input type='hidden' name='state' value='"+document.getElementById("stateCode").value+"'>");
    d.write("<input type='hidden' name='tax' value='"+tax+"'>");
    d.write("<input type='hidden' name='shipping_1' value='"+sh+"'>");
    d.write("<input type='hidden' name='custom' value='"+document.getElementById("resellId").value+"/"+document.getElementById("exemptId").value+"'>");
    
    itemCount = 0;
    for (var i=0; i<catalogList.length; i++)
    {
      var itemName = catalogList[i][0];
      var f = document.getElementById("q_"+itemName);
	  if (f == null)
	    continue;
      if (f.value == null)
	    continue;
      if (!f.value)
	    continue
      itemCount++;
  	  d.write("<input type='hidden' name='item_name_"+itemCount+"' value='"+itemName+"'>");
	  d.write("<input type='hidden' name='amount_"+itemCount+"' value='"+catalog[itemName][1]+"'>");
	  d.write("<input type='hidden' name='quantity_"+itemCount+"' value='"+f.value+"'>");
    }
    d.write("</form>");
  }  
  
  d.write("</body></html>");
  d.close();
//  document.getElementById("submitFrame").height=400;
  if (itemCount > 0)
    d.submitForm.submit();
  else
    event.returnValue = false;
  d.open();
  d.close();
}


function writeEmailLink(s1,s2,s3)
{
  s0 = s1+"@"+s2+"."+s3;
  document.write("<a href='mailto:"+s0+"'>"+s0+"</a>");
}

var stateCodes = ['AK','AL','AR','AZ','CA','CO','CT','DC','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN',
'MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI','WV','WY']
var otherCodes = ['AA','AE','AP','AS','FM','GU','MH','MP','PR','PW','VI']
