var edition, total, user, comparison, PO, Check, Info, BankInfo, Print;

function printPage(){
  var newWindow, varBody, varHead, varTable, HTMLString, txt_software, txt_CD, txt_Tech, txt_Security, txt_Report, 
    txt_Total, txt_product, txt_Title, txt_cd_title, varHeader;
  
  //determine web browser before opening new page
  if ((navigator.appName != 'Microsoft Internet Explorer') && (navigator.appName != 'Opera')){
    newWindow = window.open('','','width=800,height=600,resizable=yes,toolbar=yes,scrollbars=yes,menubar=yes');
  }
  else {
    newWindow = window.open('about:blank','','width=800,height=600,resizable=yes,toolbar=yes,scrollbars=yes,menubar=yes');   
  }
  
  varBody = newWindow.document.body;
  newWindow.document.title= var_Print_Page;
  
  Element = document.getElementById("txt_software_order");
  txt_software = Element.value;
  
  txt_cd_title = var_CD_Delivery;
  if (document.main.CD_Delivery.value == '1'){
    txt_CD = '$18';
  }
  else if (document.main.CD_Delivery.value == '2'){
	txt_CD = '$30';
	txt_cd_title = var_CD_Internation;
  }
  else{
    txt_CD = '$0';
  }
  
  Element = document.getElementById("txt_support_order");
  txt_Tech = Element.value;
  
  Element = document.getElementById("txt_security_order");
  txt_Security = Element.value;
  
  Element = document.getElementById("txt_report_order");
  txt_Report = Element.value;
  
  Element = document.getElementById("txt_total");
  txt_Total = Element.value;
  
  Element = document.getElementById("txt_product");
  txt_Product = Element.value;
   
  varHeader = '<form name="headerForm"> <div align="left"><input type="text" style="font-size:12pt; font-family:Verdana;' 
            + 'border:none; font-weight:700;'
  			+ 'color:#3366CC" name="txt_product" readonly size="80></div></form>';
  
  varTable = varHeader + '<form name="tableForm"> <div align="left">' 
  		   + '<table style="font-size:9pt" width="550" border="0"'
  		   + 'cellpadding="2" cellspacing="2">'
           + '<tr><td align="center" bgcolor="#C0C0C0" width="250"><strong>' + var_Product + '</strong></td>'
           + '<td align="center" bgcolor="#C0C0C0" width="300"><strong>' + var_Description + '</strong></td>'
           + '<td align="center" bgcolor="#C0C0C0" width="50"><strong>' + var_Order + '</strong></td></tr>'
		   
		   + '<tr><td bgcolor="#DDDDDD"><strong>' + var_Software + '</strong></td>'
		   + '<td bgcolor="#E9E9E9">' + var_Free_Tech + '<br>' + var_Free_Update +'</td>'
		   + '<td align="right" bgcolor="#E9E9E9"><input type="text" id="txt_software_order" readonly size="4"' 
		   + 'style="background-color:#E9E9E9; font-size: 12pt; font:Verdana; text-align:right; border:none" value="' 
		   + txt_software + '"></td></tr>'
		   
		   + '<tr><td bgcolor="#DDDDDD" ><strong>' + txt_cd_title + '</strong></td>'
		   + '<td bgcolor="#E9E9E9" >' + var_CD_ROM_Soft + '</td>'
		   + '<td align="right" bgcolor="#E9E9E9"><input type="text" id="txt_cd_order" readonly size="4"' 
		   + 'style="background-color:#E9E9E9; font-size: 12pt; font:Verdana; text-align:right; border:none" value="' 
		   + txt_CD + '"></td></tr>'
		   
		   + '<tr><td bgcolor="#DDDDDD"><strong>' + var_Tech_Support + '</strong></td>'
		   + '<td bgcolor="#E9E9E9">' + var_Unlimited_Tech + '<br>' + var_Phone_Support 
		   + '<br>' + var_Discount + '<br>' + var_Priced_Yearly + '</td>'
		   + '<td align="right" bgcolor="#E9E9E9"><input type="text" id="txt_tech_order" readonly size="4"' 
		   + 'style="background-color:#E9E9E9; font-size: 12pt; font:Verdana; text-align:right; border:none" value="' 
		   + txt_Tech + '"></td></tr>'
		   
		   + '<tr><td bgcolor="#DDDDDD"><strong>' + var_Secure_Mod + '</strong></td>'
		   + '<td bgcolor="#E9E9E9">' + var_Permissions + '</td>'
		   + '<td align="right" bgcolor="#E9E9E9"><input type="text" id="txt_security_order" readonly size="4"' 
		   + 'style="background-color:#E9E9E9; font-size: 12pt; font:Verdana; text-align:right; border:none" value="' 
		   + txt_Security + '"></td></tr>'
		   
		   + '<tr><td bgcolor="#DDDDDD"><strong>' + var_Custom_Rpt + '</strong></td>'
		   + '<td bgcolor="#E9E9E9">' + var_Queries + '</td>'
		   + '<td align="right" bgcolor="#E9E9E9"><input type="text" id="txt_report_order" readonly size="4"' 
		   + 'style="background-color:#E9E9E9; font-size: 12pt; font:Verdana; text-align:right; border:none" value="' 
		   + txt_Report + '"></td></tr>'
		   
		   + '<tr><td></td><td align="right" bgcolor="#DDDDDD"><strong>' + var_Total + '</strong></td>'
           + '<td align="right" bgcolor="#E9E9E9"><input type="text" id="txt_total" name="txt_total" readonly size="4"' 
		   + 'style="background-color:#E9E9E9; font-size: 12pt; font:Verdana; text-align:right; border:none; font-weight:700" value=' 
		   + txt_Total + '></td></tr>'
		   + '</table></div></form>';

  if (document.main.PaymentMethod.value == '1'){
	HTMLString = varTable + PO + Info;
	varBody.innerHTML = HTMLString;
	newWindow.document.POPayment.PONumber.value = document.POPayment.PONumber.value;
	newWindow.document.POPayment.PONumber.readOnly = true;
  }
  else if (document.main.PaymentMethod.value == '2'){
	HTMLString = varTable + Check + Info;
	varBody.innerHTML = HTMLString;	  
  }
  else if (document.main.PaymentMethod.value == '3'){
    HTMLString = varTable + BankInfo + Info;
	varBody.innerHTML = HTMLString;  
  } 
  newWindow.document.headerForm.txt_product.value = document.main.txt_product.value;
  newWindow.print();
}

function show_order_details()
{
  var Element, HTMLString;
  if (document.main.PaymentMethod.value == '1'){
	Element = document.getElementById("PaymentRow");
	HTMLString = '<hr> ' + PO + Info + Print + Comparison;
	Element.innerHTML = HTMLString;
    document.main.btn_order.disabled = true;
  }
  else if (document.main.PaymentMethod.value == '2'){
    Element = document.getElementById("PaymentRow");
	HTMLString = '<hr> ' + Check + Info + Print + Comparison;
	Element.innerHTML = HTMLString;
    document.main.btn_order.disabled = true;
  }
  else if (document.main.PaymentMethod.value == '3'){
    Element = document.getElementById("PaymentRow");
	HTMLString = '<hr> ' + BankInfo + Info + Print + Comparison;
	Element.innerHTML = HTMLString;
    document.main.btn_order.disabled = true;
  }
  else{
	Element = document.getElementById("PaymentRow");
	HTMLString = '<hr> ' + Comparison; 
	Element.innerHTML = HTMLString; 
    document.main.btn_order.disabled = false;
  }  
}

function process_order()
{
  var txt_products, txt_variations, txt_shipping, txt_quantity, txt_URL, txt_cd_var;
  
  txt_products = "";
  txt_variations = "";
  txt_shipping = "";
  txt_quantity = "";
  txt_URL = "";
  txt_CD_var = '0';
  
  if (document.main.CD_Delivery.value == '1'){
    txt_CD_var = '0';
  }
  else if (document.main.CD_Delivery.value == '2'){
	txt_CD_var = '1';
  }
  
  //Shop edition
  if (document.main.Q_MP_Professional.value == "1"){
	if (document.main.shMP_Professional.value == "2"){ //with CD
      txt_products = "446471:44647CDROM";
	  txt_variations = (user - 1) + ":" + txt_CD_var;
	  txt_shipping = "0:0";
	  txt_quantity = "1:1";
	}
	else{//without CD
	  txt_products = "446471";
	  txt_variations = (user - 1);
	  txt_shipping = "0";
	  txt_quantity = "1";
	}
  }//Deluxe edition
  else if (document.main.Q_MP_Deluxe.value == "1"){
    if (document.main.shMP_Deluxe.value == "2"){
      txt_products = "446475:44647CDROM";
	  txt_variations = (user - 1) + ":" + txt_CD_var;
	  txt_shipping = "0:0";
	  txt_quantity = "1:1";
	}
	else{
	  txt_products = "446475";
	  txt_variations = (user - 1);
	  txt_shipping = "0";
	  txt_quantity = "1";
	}
  }//Standard edition
  else if (document.main.Q_MP_Standard.value == "1"){
    if (document.main.shMP_Standard.value == "2"){
      txt_products = "446474:44647CDROM";
	  txt_variations = (user - 1) + ":" + txt_CD_var;
	  txt_shipping = "0:0";
	  txt_quantity = "1:1";
	}
	else{
	  txt_products = "446474";
	  txt_variations = (user - 1);
	  txt_shipping = "0";
	  txt_quantity = "1";
	}
  }
  
  //Tech Support
  if (document.main.chk_Tech_Support.checked){
    if (txt_products == ""){
	  txt_products = "446477";	
	  txt_variations = document.main.varTech_Support.value;
	  txt_shipping = "0";
	  txt_quantity = "1";
	}
	else{
	  txt_products = txt_products + ":446477";	
	  txt_variations = txt_variations + ":" + document.main.varTech_Support.value;
	  txt_shipping = txt_shipping + ":0";
	  txt_quantity = txt_quantity + ":1";
	}  
  }
  
  //Report Designer
  if (document.main.chk_Report.checked){
    if (txt_products == ""){
	  txt_products = "4464710";	
	  txt_variations = document.main.varCustom_Report.value;
	  txt_shipping = "0";
	  txt_quantity = "1";
	}
	else{
	  txt_products = txt_products + ":4464710";	
	  txt_variations = txt_variations + ":" + document.main.varCustom_Report.value;
	  txt_shipping = txt_shipping + ":0";
	  txt_quantity = txt_quantity + ":1";
	}  
  }
  
  //Security Module
  if (document.main.chk_Security.checked){
    if (txt_products == ""){
	  txt_products = "446478";	
	  txt_variations = document.main.varSecurity.value;
	  txt_shipping = "0";
	  txt_quantity = "1";
	}
	else{
	  txt_products = txt_products + ":446478";	
	  txt_variations = txt_variations + ":" + document.main.varSecurity.value;
	  txt_shipping = txt_shipping + ":0";
	  txt_quantity = txt_quantity + ":1";
	}  
  }
  
  //generate URL
  txt_URL = "https://usd.swreg.org/cgi-bin/s.cgi?s=44647&p=" + txt_products + "&v=" + txt_variations + "&d=" + txt_shipping
    		+ "&q=" + txt_quantity + "&clr=1&t=";
  //changed location to new URL
  location.href = txt_URL;
}

function process_option(price, order, value, selected)
{
  var txt_order, txt_price;

  if(document.getElementById != null)
  {
    txt_order = document.getElementById(order);
    txt_price = document.getElementById(price);
    if((txt_order != null) && (txt_price != null))
    {
      if(value)
      {
        txt_price.value = ("$" + value);
        if(selected)
        {
          txt_order.value = ("$" + value);
          total += value;
        }
        else txt_order.value = "$0";
      }
      else
      {
        txt_price.value = var_NA;
        txt_order.value = var_NA;
      }
    }
  }
}

function update_options()
{
  var val_cd, val_report, val_security, val_software, val_support;
  var opt_cd = (document.main.CD_Delivery.value != '0');
  var opt_report = document.main.chk_Report.checked;
  var opt_security = document.main.chk_Security.checked;
  var opt_software = document.main.chk_software.checked;
  var opt_support = document.main.chk_Tech_Support.checked;
  document.main.CD_Delivery.disabled = !opt_software;
  
  if (!opt_software)
    document.main.CD_Delivery.value = '0';

  document.main.Q_MP_Standard.value = "";
  document.main.Q_MP_Deluxe.value = "";
  document.main.Q_MP_Professional.value = "";

  if(opt_cd && opt_software)
  {
    document.main.shMP_Standard.value = "2";
    document.main.shMP_Deluxe.value = "2";
    document.main.shMP_Professional.value = "2";
  }
  else
  {
    document.main.shMP_Standard.value = "1";
    document.main.shMP_Deluxe.value = "1";
    document.main.shMP_Professional.value = "1";
  }

  
  //check for overseas shipping
  if (document.main.CD_Delivery.value == '2'){
    val_cd = 30;
  }
  else if (document.main.CD_Delivery.value == '1'){
    val_cd=18;
  }
  else{
    val_cd = 0;
  }
  
  switch(edition)
  {
    // Standard Edition
    case 2:
      if(opt_software) document.main.Q_MP_Standard.value = "1";
      switch(user)
      {
        // 1-User
        case 1:
          val_report = 99;
          val_security = 99;
          val_software = 495;
          val_support = 79;
          break;
        // 2-User
        case 2:
          val_report = 149;
          val_security = 149;
          val_software = 849;
          val_support = 149;
          break;
        // 5-User
        case 3:
          val_report = 299;
          val_security = 295;
          val_software = 1789;
          val_support = 279;
          break;
        // 10-User
        default:
          val_report = 549;
          val_security = 549;
          val_software = 2985;
          val_support = 495;
      }
      break;
    // Deluxe Edition
    case 3:
      if(opt_software) document.main.Q_MP_Deluxe.value = "1";
      switch(user)
      {
        // 1-User
        case 1:
          val_report = 149;
          val_security = 149;
          val_software = 679;
          val_support = 119;
          break;
        // 2-User
        case 2:
          val_report = 199;
          val_security = 195;
          val_software = 1179;
          val_support = 199;
          break;
        // 5-User
        case 3:
          val_report = 349;
          val_security = 349;
          val_software = 2449;
          val_support = 399;
          break;
        // 10-User
        default:
          val_report = 599;
          val_security = 595;
          val_software = 4279;
          val_support = 695;
      }
      break;
    // Professional Edition
    default:
      if(opt_software) document.main.Q_MP_Professional.value = "1";
      switch(user)
      {
        // 1-User
        case 1:
          val_report = 199;
          val_security = 199;
          val_software = 995;
          val_support = 189;
          break;
        // 2-User
        case 2:
          val_report = 249;
          val_security = 249;
          val_software = 1689;
          val_support = 249;
          break;
        // 5-User
        case 3:
          val_report = 399;
          val_security = 395;
          val_software = 3495;
          val_support = 499;
          break;
        // 10-User
        default:
          val_report = 699;
          val_security = 695;
          val_software = 5950;
          val_support = 695;
      }
  }

  total = 0;
  process_option("txt_cd_price", "txt_cd_order", val_cd, (opt_cd && opt_software));
  process_option("txt_report_price", "txt_report_order", val_report, opt_report);
  process_option("txt_security_price", "txt_security_order",  val_security, opt_security);
  process_option("txt_software_price", "txt_software_order", val_software, opt_software);
  process_option("txt_support_price", "txt_support_order", val_support, opt_support);
  if (opt_cd && opt_software){
    total = total + val_cd;
  }
  document.main.txt_total.value = ("$" + total);
  document.main.btn_order.disabled = ((!total) || (document.main.PaymentMethod.value != '0'));
}

function update_user()
{
  document.main.varMP_Standard.value = user;
  document.main.varMP_Deluxe.value = user;
  document.main.varTech_Support.value = ((4 * (edition - 1)) + (user - 1));
  document.main.varSecurity.value = ((4 * (edition - 1)) + (user - 1));
  document.main.varCustom_Report.value = ((4 * (edition - 1)) + (user - 1));
  document.main.varMP_Professional.value = user;

  switch(user)
  {
    // 1-User
    case 1:
      document.main.txt_product.value += var_Single_User;
      break;
    // 2-User
    case 2:
      document.main.txt_product.value += var_2_User;
      break;
    // 5-User
    case 3:
      document.main.txt_product.value += var_5_User;
      break;
    // 10-User
    default:
      document.main.txt_product.value += var_10_User;
  }

  update_options();
}

function update_edition()
{
  switch(edition)
  {
    // Standard Edition
    case 2:
      document.main.txt_product.value = var_MP_Standard;
      break;
    // Deluxe Edition
    case 3:
      document.main.txt_product.value = var_MP_Deluxe;
      break;
    // Professional Edition
    default:
      document.main.txt_product.value = var_MP_Professional;
  }

  update_user();
}

function order_mp()
{
  var i, items, pos;

  edition = 2;
  user = 1;

  Comparison = '<p><br>' + var_Which_Product + '&nbsp;' + var_View + '<a href="comparis.htm">' + var_Compart_Chart 
  			   +'</a>.</p><p><br><br></p>';
  PO = '<form action="" name="POPayment">'
        + 	'<div align="center">'
        + 	'<p style="font-size:10pt"><strong>' + var_PO + '</strong>' + var_Fax + '</p>'
        +   '<table style="font-size:9pt" width="453" border="0">'
        +   '<tr>'
        +   '<td width="206"><span>' + var_Enter_PO + '</span></td>'
        +   '<td width="237"><span>'
        +   '<label></label>'
		+	'<label></label>'
        +   '<label>'
        +   '<input style="font-size: 10pt; font:Verdana" type="text" name="PONumber" id="PONumber" size="20" maxlength="20">'
        +   '</label>'
        +   '</span></td></tr>'
        +   '<tr>'
        +   '<td colspan="2"><span>' + var_Print_Screen + '</span><span>' + var_Mail_Fax + '</span></td>'
        +   '</tr></table></div></form>';
  Info = '<form method="post" name="IMSInfo" action="">'
          +	'<div align="center">'
          +	'<table style="font-size:10pt; font-weight: bold;" width="300" border="2">'
          + '<tr> <td><div align="center"><strong><span>' + var_Remittance + '</span></strong></div></td>'
          + '</tr><tr><td><div align="center">' + var_IMS
		  +	'<br> ' + var_PO_Box 
		  +	'<br> ' + var_City_State
		  +	'<br> ' + var_Fax_No + ' </br>'
          + '</div></td></tr><tr>'
          + '<td><div align="center"><strong><span>' + var_Fed_ID + '</span></strong></div></td>'
          + '</tr></table></div></form>';
  Check = '<form action="" name="CheckPayment">'
        + 	'<div align="center">'
        + 	'<p style="font-size:10pt"><strong>' + var_Check_Money + '</strong> ' + var_Mail_Request + '</p>'
        +   '<table style="font-size:9pt" width="500" border="0">'
        +   '<tr>'
        +   '<td width="500">' + var_Check_Payable
		+	'<div align="center"><strong>' + var_IMS + '</strong></td></div></tr>'
        +   '<tr>'
        +   '<td width="500">' + var_Print_Mail_Check + '</td>'
        +   ' </tr></table></div>'
        +   '</form>';
 BankInfo = '<form action= "" name="IMSBankInfo" method="post" action="">'
          +	'<div align="center">'
		  + '<table border="0" style="font-size:10pt;" width="350" align="center"> <tr><td align="left">'
		  + var_Process + '<br></br>'
		  +' </td></tr><tr><td alignt="left"><ul align="left"><li>' + var_US_Dollars
		  + '<li>' + var_Three_Days
		  + '<li><strong>' + var_Bank_Fees + '</strong>'
		  + '<li>' + var_Pre_Paid
		  + '</ul></td></tr><tr><td>' + var_Bank_Info + '</td></tr></table><br>'
          +	'<table style="font-size:10pt;" width="350" border="2">'
          + '<tr> <td><div align="center"><strong><span>' + var_Bank_Transfer + '</span></strong></div></td>'
          + '</tr><tr><td><div align="left">'                
          + '<strong>' + var_Account_Name + '</strong> ' + var_IMS
		  + '<br><strong>' + var_Acount + '</strong> ' + var_Account_No + '<br><strong>' + var_Routing 
		  + '</strong> ' + var_Routing_No + '</br></div></td></tr>'
		  +	'<tr><td><div align="center"><strong>' + var_Bank_Name + '<br>' + var_Bank_Street +	'<br> ' + var_Bank_PO_Box
		  +	'<br> ' + var_Bank_City_State + '</strong></br>'
          + '</div></td></tr><tr>'
          + '<td><div align="center"><span><strong>' + var_Phone + '</strong> ' + var_Phone_No + '</span></div></td>'
          + '</tr></table></div> <br></br>'
		  + '<table border="0" style="font-size:10pt;" width="350" align="center"><tr><td align="left">' + var_Funds_Tranferred 
		  + '</td></tr></table></form>';
		  
  Print = '<input style="font-size: 10pt; font:Verdana" onClick="printPage();" name="btnPrint" type="button" id="btnPrint"'
  		  + ' value="Print"> <hr>'

  items = window.location.search.substring(1).split('&');
  for(i = 0; i < items.length; i++)
  {
    pos = items[i].indexOf('=');
    if(pos > 0)
    {
      if(items[i].substring(0, pos) == "edition")
      {
        switch(items[i].substring(pos + 1))
        {
          // Standard Edition
          case "2": edition = 2; break;
          // Deluxe Edition
          case "3": edition = 3; break;
          // Professional Edition
          case "4": edition = 4;
        }
      }
      else if(items[i].substring(0, pos) == "license")
      {
        switch(items[i].substring(pos + 1))
        {
          // 1-User
          case "1": user = 1; break;
          // 2-User
          case "2": user = 2; break;
          // 5-User
          case "3": user = 3; break;
          // 10-User
          case "4": user = 4;
        }
      }
    }
  }

  update_edition();
}
