function GetURLParam(strParamName)
{
  var strReturn = "";
  var strHref = window.location.href;
  
  if (strHref.indexOf("?") > -1)
  {
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for (var iParam = 0; iParam < aQueryString.length; iParam++ )
    {
      if (aQueryString[iParam].indexOf(strParamName + "=") > -1 )
      {
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return strReturn;
} 

function InitForm()
{
  var prg = GetURLParam("prg");
  if (prg == "bookcat")
    {
      document.fnprg_order.bookcat.checked = true;
    }  
  if (prg == "catraxx")
    {
      document.fnprg_order.catraxx.checked = true;
    }
  if (prg == "catvids")
    {
      document.fnprg_order.catvids.checked = true;
    }
  if (prg == "softcat")
    {
      document.fnprg_order.softcat.checked = true;
    }
  if (prg == "stampcat")
    {
      document.fnprg_order.stampcat.checked = true;
    }
  UpdateTotal();
}

function Checkout() 
{
  if (CountProducts() == 0)
    {
      alert('You must select at least one product!');
      document.fnprg_order; return false;
    }
  else
    {
      document.fnprg_order; return true;
    }
}

function CountProducts()
{
  var Count = 0
  if (document.fnprg_order.bookcat.checked)
    {
      Count = Count + 1;
    }
  if (document.fnprg_order.catraxx.checked)
    {
      Count = Count + 1;
    }
  if (document.fnprg_order.catvids.checked)
    {
      Count = Count + 1;
    }
  if (document.fnprg_order.softcat.checked)
    {
      Count = Count + 1;
    }
  if (document.fnprg_order.stampcat.checked)
    {
      Count = Count + 1;
    }
  return Count;
}

function UpdateTotal()
{  	
  var ProdPrice = 0;
  var ProcPriceDisc = 0;
  var SubTotal = 0;
  var Total = 0;
  var Discount = 0;
  var YouSave = 0;  
  var ProdCount = CountProducts(); 
  var Currency = 'US $';
  var CurrencyConv = 1;
  var nbsp = String.fromCharCode(160);
  
  // EURO
  if (document.fnprg_order.currency[1].checked)
    {
      Currency = "EUR ";
      CurrencyConv = 0.7822;  
    }   

  switch (ProdCount) 
  {
    case 1: 
      Discount = 0
      break
    case 2: 
      Discount = 20
      break       
    case 3: 
      Discount = 30
      break  
    case 4: 
      Discount = 35 
      break
	case 5: 
      Discount = 40 
      break
  }
  
  if (document.fnprg_order.bookcat.checked)
    {
      SubTotal = SubTotal + 39.95;
    }
  if (document.fnprg_order.catraxx.checked)
    {
      SubTotal = SubTotal + 39.95;
    }
  if (document.fnprg_order.catvids.checked)
    {
      SubTotal = SubTotal + 39.95;
    }
  if (document.fnprg_order.softcat.checked)
    {
      SubTotal = SubTotal + 29.95;
    }
  if (document.fnprg_order.stampcat.checked)
    {
      SubTotal = SubTotal + 29.95;
    }

  SubTotal = SubTotal * CurrencyConv;
  Total = SubTotal * ((100 - Discount) / 100);  
  YouSave = SubTotal - Total;  
 
  {
    // $39.95 products
    ProdPrice = 39.95 * CurrencyConv;
    document.getElementById('bookcat_price').firstChild.data = nbsp + Currency + ProdPrice.toFixed(2) + nbsp;
    document.getElementById('catraxx_price').firstChild.data = nbsp + Currency + ProdPrice.toFixed(2) + nbsp;
    document.getElementById('catvids_price').firstChild.data = nbsp + Currency + ProdPrice.toFixed(2) + nbsp;      
    ProdPriceDisc = ProdPrice * ((100 - Discount) / 100);
    // BookCAT
    if (document.fnprg_order.bookcat.checked)
      {
        if (ProdCount > 1)
          {
            document.getElementById('bookcat_price2').firstChild.data = Currency + ProdPriceDisc.toFixed(2);
 	        }
 	      else
 	        {
 	          document.getElementById('bookcat_price2').firstChild.data = '';
 	        }    	        
      }
    else
      {
        document.getElementById('bookcat_price2').firstChild.data = '';
      }
    if (document.getElementById('bookcat_price2').firstChild.data == '')
      {
        document.getElementById('bookcat_price').style.textDecoration = '';
      }
    else
      {
        document.getElementById('bookcat_price').style.textDecoration = 'line-through';          
      }
    // CATraxx
    if (document.fnprg_order.catraxx.checked)
      {
        if (ProdCount > 1)
          {
            document.getElementById('catraxx_price2').firstChild.data = Currency + ProdPriceDisc.toFixed(2);
 	        }
 	      else
 	        {
 	          document.getElementById('catraxx_price2').firstChild.data = '';
 	        }    	        
      }
    else
      {
        document.getElementById('catraxx_price2').firstChild.data = '';
      }
    if (document.getElementById('catraxx_price2').firstChild.data == '')
      {
        document.getElementById('catraxx_price').style.textDecoration = '';
      }
    else
      {
        document.getElementById('catraxx_price').style.textDecoration = 'line-through';          
      }
    // CATVids
    if (document.fnprg_order.catvids.checked)
      {
        if (ProdCount > 1)
          {
            document.getElementById('catvids_price2').firstChild.data = Currency + ProdPriceDisc.toFixed(2);
 	        }
 	      else
 	        {
 	          document.getElementById('catvids_price2').firstChild.data = '';
 	        }    	        
      }
    else
      {
        document.getElementById('catvids_price2').firstChild.data = '';
      }
    if (document.getElementById('catvids_price2').firstChild.data == '')
      {
        document.getElementById('catvids_price').style.textDecoration = '';
      }
    else
      {
        document.getElementById('catvids_price').style.textDecoration = 'line-through';          
      }
    // $29.95 products
    ProdPrice = 29.95 * CurrencyConv;
    document.getElementById('softcat_price').firstChild.data = nbsp + Currency + ProdPrice.toFixed(2) + nbsp;
    document.getElementById('stampcat_price').firstChild.data = nbsp + Currency + ProdPrice.toFixed(2) + nbsp;
    ProdPriceDisc = ProdPrice * ((100 - Discount) / 100);
    // SoftCAT
    if (document.fnprg_order.softcat.checked)
      {
        if (ProdCount > 1)
          {
            document.getElementById('softcat_price2').firstChild.data = Currency + ProdPriceDisc.toFixed(2);
 	        }
 	      else
 	        {
 	          document.getElementById('softcat_price2').firstChild.data = '';
 	        }    	        
      }
    else
      {
        document.getElementById('softcat_price2').firstChild.data = '';
      }
    if (document.getElementById('softcat_price2').firstChild.data == '')
      {
        document.getElementById('softcat_price').style.textDecoration = '';
      }
    else
      {
        document.getElementById('softcat_price').style.textDecoration = 'line-through';          
      }
    // StampCAT
    if (document.fnprg_order.stampcat.checked)
      {
        if (ProdCount > 1)
          {
            document.getElementById('stampcat_price2').firstChild.data = Currency + ProdPriceDisc.toFixed(2);
 	        }
 	      else
 	        {
 	          document.getElementById('stampcat_price2').firstChild.data = '';
 	        }    	        
      }
    else
      {
        document.getElementById('stampcat_price2').firstChild.data = '';
      }
    if (document.getElementById('stampcat_price2').firstChild.data == '')
      {
        document.getElementById('stampcat_price').style.textDecoration = '';
      }
    else
      {
        document.getElementById('stampcat_price').style.textDecoration = 'line-through';          
      }
    // Total
    document.getElementById('subtotal').firstChild.data = Currency + SubTotal.toFixed(2);
    document.getElementById('discount').firstChild.data = Discount.toFixed(0) + "%"; 
    document.getElementById('total').firstChild.data = Currency + Total.toFixed(2);
    document.getElementById('yousave').firstChild.data = Currency + YouSave.toFixed(2);
	}
} 

