var price_license_full = 6950;
var price_license_static = 4950;
var price_license_academic = 3475;
var price_shifter_fizeau = 5900;
var price_shifter_fizeau_discount = 0.50;
var price_shifter_mic1 = 1318+1682+70;
var price_shifter_pztls = 1950;
var price_computer_desktop_dell = 1900;
var price_computer_laptop_dell = 0;
var price_computer_laptop_thinkpad = 2200;
var price_computer_setup = 400;
var price_imaq1405 = 820;
var price_imaq1410 = 1560;
var price_imaq1422 = 0;
var price_imaq1428 = 1680;
var price_CL_cable = 180;
var price_imperx_vce_pro = 810;
var price_imperx_framelink = 0;
var price_IEEE1394 = 495;
var price_CMU1394 = 0;
var price_nidaq_6024E = 810;
var price_nidaq_6221 = 660;
var price_nidaq_6211 = 890;
var price_daqcard_6024E = 730;
var price_USB_DAQ = 250;
var price_68toLemo = 190;
var price_37toLemo = 190;
var price_daqcard_to_lemo = 250;
var price_LEMOtoLEMO = 0;
var price_VA100 = 1060;
var price_VA1000 = 0;
var price_training = 180;
var price_travel = 1500;


var total_price = 0;
var computer_is_desktop = 1;

function validate_Country() {
  if((window.document.forms[0].Country.value == 'USA') || (window.document.forms[0].Country.value == 'CAN'))
	  export_rate = 1.0;
	else export_rate = 1.1;
  return;
}

function validate_Interferometer() {
	var blurb=document.getElementById('InterferometerBlurb');
  if(window.document.forms[0].Interferometer.value == '4Fizeau')
		blurb.innerHTML = "Any 4-inch Fizeau interferometer with a standard bayonet and video camera but without a phase shift head.";
	else if(window.document.forms[0].Interferometer.value == '4Fizeau')
	  blurb.innerHTML = "&nbsp;";
  else blurb.innerHTML = "&nbsp;";
	return;
}

function validate_License() {
  var item;
  var price=document.getElementById('LicensePrice');
	var blurb=document.getElementById('LicenseBlurb');
  if(window.document.forms[0].License.value == 'Phase') {
		item = price_license_full;
		blurb.innerHTML = "Durango commercial software perpetual license with one hardware key enabling phase shifting and static fringe acquisition. "
		+ "Includes first year support and upgrade subscription.";
	}
	if(window.document.forms[0].License.value == 'Static') {
		item = price_license_static;
		blurb.innerHTML = "Durango commercial software perpetual license with one hardware key enabling static fringe acquisition. "
		+ "Includes first year support and upgrade subscription.";
	}
	if(window.document.forms[0].License.value == 'Academic') {
	  item = price_license_academic;
		blurb.innerHTML = "Durango academic perpetual license with one hardware key enabling phase shifting and static fringe acquisition. Includes Support and Upgrade Subscription.";
	}
	if(window.document.forms[0].License.value == 'Upgrade') {
	  item = price_license_full - price_license_static;
		blurb.innerHTML = "Upgrade from static fringe license to full phase measuring license. ";
	}
	item = Math.round(item*export_rate);
  price.innerHTML = "$" + item;
	total_price += item;
	return;
}

function validate_Computer() {
  var item = 0;
	var blurb=document.getElementById('ComputerBlurb')
  var price=document.getElementById('ComputerPrice')
  if(window.document.forms[0].Computer.value == 'desktop_dell') {
    item = price_computer_desktop_dell + price_computer_setup;
		computer_is_desktop = 1;
	  blurb.innerHTML = "Dell Dimension or OptiPlex, Intel Core 2 Duo &ge;2.4GHz, Microsoft Windows XP Professional, 2GB RAM, &ge;80GB HDD, CD-RW, &ge;19-inch Flat Panel. "
		  + "Quoted price is estimate, not-to-exceed. " 
		  + "You pay Diffraction International&rsquo;s actual invoice cost plus $" + price_computer_setup + " for configuration and setup.";
	}
  if(window.document.forms[0].Computer.value == 'desktop_own') {
		computer_is_desktop = 1;
	  blurb.innerHTML = "You will provide your own desktop computer running Microsoft Windows 2000 or XP.";
	}
  if(window.document.forms[0].Computer.value == 'laptop_dell') {
    item = price_computer_laptop_dell;
		computer_is_desktop = 0;
		blurb.innerHTML = "&nbsp;";
	}
	if(window.document.forms[0].Computer.value == 'laptop_thinkpad') {
    item = price_computer_laptop_thinkpad;
		computer_is_desktop = 0;
	  blurb.innerHTML = "Lenovo ThinkPad T Series, Intel Core 2 Duo &ge;1.8GHz, Microsoft Windows XP Professional, &ge;1024x768 TFT display, "
		+ "2GB RAM, &ge;80GB HDD, CD-RW, Type II PC Card slot. "
		+ "Quoted price is estimate, not-to-exceed. " 
	  + "You pay Diffraction International&rsquo;s actual invoice cost plus $" + price_computer_setup + " for configuration and setup.";
	}
	if(window.document.forms[0].Computer.value == 'laptop_own') {
		computer_is_desktop = 0;
	  blurb.innerHTML = "You will provide your own notebook computer running Windows 2000 or XP.  Must have one Type II PC Card slot.";
	}
	item = Math.round(item*export_rate);
  price.innerHTML = "$" + item;
	total_price += item;
	return;
}

function validate_Image() {
  var item = 0;
  var price=document.getElementById('ImagePrice')
	var blurb=document.getElementById('ImageBlurb')
  if(window.document.forms[0].Image.value == 'Video') {
	  if(computer_is_desktop == 1) {
		  item = price_imaq1410;
		  blurb.innerHTML = "National Instruments IMAQ PCI-1410, 4-channel monochrome, interlaced/non-interlaced, 8 or 10 bit digitization. "
			+ "Compatible with double speed 60 frames/s progressive-scan cameras. Includes NI-IMAQ driver software and 2-m BNC cable. ";
		}
		else {
		  item = price_imperx_vce_pro;
		  blurb.innerHTML = "ImperX VCE-PRO fast analog PCMCIA video capture card.";
		}
	}
  if(window.document.forms[0].Image.value == 'CameraLink') {
	  if(computer_is_desktop == 1) {
		  item = price_imaq1428+price_CL_cable;
		  blurb.innerHTML = "National Instruments IMAQ PCI-1428 base- and medium-configuration image acquisition for Camera Link cameras, 16 MB on-board memory. "
			+"Includes NI-IMAQ driver software and 2-m Camera Link cable. ";
		}
		else {
		  item = price_imperx_framelink;
		  blurb.innerHTML = "ImperX FrameLink Camera Link PCMCIA video capture card.";
		}
	}
  if((window.document.forms[0].Image.value == 'LVDS') || (window.document.forms[0].Image.value == 'RS422')) {
		item = 0;
		blurb.innerHTML = "&nbsp;";
	}
  if(window.document.forms[0].Image.value == '1394') {
		item = price_CMU1394;
		blurb.innerHTML = "Carnegie Mellon University (CMU) IEEE 1394 driver software for FireWire cameras. ";
	}
  if(window.document.forms[0].Image.value == 'USB') {
	  item = 0;
		blurb.innerHTML = "&nbsp;";
		alert("Durango does not yet support any USB cameras.");
	}
	item = Math.round(item*export_rate);
  price.innerHTML = "$" + item;
	total_price += item;
	return;
}

function validate_Shifter() {
  var item = 0;
	var blurb=document.getElementById('ShifterBlurb')
  var price=document.getElementById('ShifterPrice')
  if(window.document.forms[0].Shifter.value == 'Fizeau') {
		blurb.innerHTML = "Diffraction International&rsquo;s 4-inch Fizeau Phase Shifter attaches without tools to standard bayonet "
			+ "and uses existing tilt-tip knobs. Works without voltage amplifer. Includes 2-m LEMO cable and LEMO-to-BNC adapter. ";
		if(window.document.forms[0].License.value == 'Phase') {
      item = price_shifter_fizeau * (1-price_shifter_fizeau_discount);	// Discount if purchased with new Durango license
		  blurb.innerHTML = blurb.innerHTML
			+ " <span style='color:red;'><b>Item price reflects promotional " + price_shifter_fizeau_discount*100 + "% discount with purchase of a full Durango software license.</b></span>";
		}
		else {
		  item = price_shifter_fizeau;
		}
	}
  if(window.document.forms[0].Shifter.value == 'MIC1') {
    item = price_shifter_mic1;
		blurb.innerHTML = "Diffraction International OEM low voltage PZT translator with modified Buccini Instrument Company quick-change mirror mount. "
		+ "Includes 2-m LEMO cable. ";
	}
  if(window.document.forms[0].Shifter.value == 'PZTLS') {
    item = price_shifter_pztls;
    blurb.innerHTML = "An economical and compact phase shifting solution for your Twyman Green or small Fizeau interferometer. Includes 2-m LEMO cable. "
	}
  if(window.document.forms[0].Shifter.value == 'Own') {
		blurb.innerHTML = "You will provide your own phase shifter that accepts -10 to +10V input (or subrange of). ";
	}
	if(window.document.forms[0].Shifter.value == 'None') {
		blurb.innerHTML = "&nbsp;";
	}
	item = Math.round(item*export_rate);
  price.innerHTML = "$" + item;
	total_price += item;
	return;
}

function validate_Controller() {
  var item = 0;
  var price=document.getElementById('ControllerPrice')
	var blurb=document.getElementById('ControllerBlurb')
  if(window.document.forms[0].Controller.value == 'DAQ6024E') {
	  if(computer_is_desktop == 1) {
		  item = price_nidaq_6024E + price_68toLemo;
		  blurb.innerHTML = "National Instruments NIDAQ PCI-6024E (0 to 10V) with custom 68pin-to-LEMO adapter.";
		}
		else {
		  item = price_daqcard_6024E + price_daqcard_to_lemo;
		  blurb.innerHTML = "National Instruments DAQCard 6024E (0 to 10V) with custom DAQCard-to-LEMO adapter.";
		}
	}
  if(window.document.forms[0].Controller.value == 'DAQ6221') {
	  item = price_nidaq_6221 + price_37toLemo;;
	  blurb.innerHTML = "National Instruments NIDAQ PCI-6221 (0 to 10V) with custom 37pin-to-LEMO adapter.";
	}
  if(window.document.forms[0].Controller.value == 'DAQ6211') {
	  item = price_nidaq_6211;
	  blurb.innerHTML = "USB bus-powered NI DAQ USB-6211 (0 to 10V) customized with LEMO receptacle. <span style='color:red;'><b>New!</b></span>";
	}
  if(window.document.forms[0].Controller.value == 'DAQ6008') {
	  item = price_USB_DAQ;
	  blurb.innerHTML = "USB bus-powered NI DAQ USB-6008 (0 to 5V) customized with LEMO receptacle. This controller does not support phase ramping.<span style='color:red;'></span>";
	}
  if(window.document.forms[0].Controller.value == 'Own') {
	  blurb.innerHTML = "You will provide your own Durango-supported phase shift controller. ";
	}
  if(window.document.forms[0].Controller.value == 'None') {
	  blurb.innerHTML = "&nbsp;";
	}
	item = Math.round(item*export_rate);
  price.innerHTML = "$" + item;
	total_price += item;
	return;
}

function validate_Amplifier() {
  var item = 0;
  var price=document.getElementById('AmplifierPrice')
	var blurb=document.getElementById('AmplifierBlurb')
  if(window.document.forms[0].Amplifier.value == 'VA100') {
		item = price_VA100;
		blurb.innerHTML = "Physik Instrumente low voltage PZT amplifier model E-660.00. "
		+ "Control input 0 to +10 V, output +5 to +100 V, peak output current 20 mA. "
		+ "With 12V switching (100-240V) AC adapter. Battery operation is possible.";
	}
  if(window.document.forms[0].Amplifier.value == 'VA1000') {
		item = price_VA1000;
		blurb.innerHTML = "Physik Instrumente high voltage PZT amplifier model E-461.00. "
		+ "Control input 0 to +10 V, output -10 to -1000 V, peak output current 0.5 mA. "
		+ "With 12 VDC power supply. Battery operation is possible.";
	}
  if(window.document.forms[0].Amplifier.value == 'Own') {
	  blurb.innerHTML = "&nbsp;";
  }
  if(window.document.forms[0].Amplifier.value == 'None') {
	  blurb.innerHTML = "&nbsp;";
	}
	item = Math.round(item*export_rate);
  price.innerHTML = "$" + item;
	total_price += item;
	return;
}

function validate_Training() {
  var item = 0;
  var price=document.getElementById('TrainingPrice')
	var blurb=document.getElementById('TrainingBlurb')
  if(window.document.forms[0].Training.value == '1day') {
		item = 8*price_training + price_travel;
		blurb.innerHTML = "Durango on-site training is priced at $180/hr plus instructor&rsquo;s actual travel expenses (est. $"+price_travel+").";
	}
  if(window.document.forms[0].Training.value == '2day') {
		item = 16*price_training + price_travel;
		blurb.innerHTML = "Durango on-site training is priced at $180/hr plus instructor&rsquo;s actual travel expenses (est. $"+price_travel+").";
	}
  if(window.document.forms[0].Training.value == 'None') {
	  blurb.innerHTML = "&nbsp;";
	}
	item = Math.round(item*export_rate);
  price.innerHTML = "$" + item;
	total_price += item;
	return;
}

function validate_Consistency() {
  if((window.document.forms[0].Country.value != 'USA') && (window.document.forms[0].Country.value != 'CAN')) {
	  if((window.document.forms[0].Computer.value != 'laptop_own') && (window.document.forms[0].Computer.value != 'desktop_own')) {
		  alert("Diffraction International does not ship computers to addresses outside the U.S. and Canada.")
      window.document.forms[0].Computer.focus();
			return false;
		}
	}
	if((window.document.forms[0].Shifter.value == 'MIC1') && (window.document.forms[0].Interferometer.value != 'MIC1')) {
	  alert("The Buccini MIC-1 OEM phase shifter is for use only with a Buccini MIC-1 interferometer.");
    window.document.forms[0].Shifter.focus();
		return false;
	}
	if((window.document.forms[0].License.value == 'Static') && (window.document.forms[0].Shifter.value != 'None')) {
	  alert("Use of a phase shifter requires a Durango phase measuring license.");
	  return false;
	}
	if((window.document.forms[0].Interferometer.value == 'FIBO') && (window.document.forms[0].Shifter.value != 'Own')) {
		alert("The FIBO interferometer has its own built-in camera and phase shifter.");
    window.document.forms[0].Shifter.focus();
		return false;
	}
  if((window.document.forms[0].Shifter.value == 'Fizeau') && (window.document.forms[0].Interferometer.value.indexOf('4') < 0)) {
	  alert("Fizeau Phase Shifter requires an interferometer with 4-inch bayonet.");
	  return false;
	}
	if((window.document.forms[0].License.value == 'Static') && (window.document.forms[0].Controller.value != 'None')) {
	  alert("Use of a phase shift controller requires a full Durango software license.");
		window.document.forms[0].License.focus();
	  return false;
	}
  if((window.document.forms[0].Shifter.value != 'None') && (window.document.forms[0].Controller ==  'None')) {
	  alert("A phase shifter generally requires a controller.");
    window.document.forms[0].Controller.focus();
		return false;
	}
	if((window.document.forms[0].Controller.value == 'DAQ6221') && !computer_is_desktop) {
	  alert("NIDAQ 6221 phase shift controller is incompatible with laptop computer.");
    window.document.forms[0].Controller.focus();
	  return false;
	}
  if((window.document.forms[0].Amplifier.value != 'None') && (window.document.forms[0].Shifter.value != 'Own')) {
	  alert("Diffraction International phase shifters do not require a voltage amplifier when used at visible wavelengths.");
    window.document.forms[0].Amplifier.focus();
	  // return false;
	}
  if((window.document.forms[0].Country.value != 'USA') && (window.document.forms[0].Country.value != 'CAN') && (window.document.forms[0].Training.value != 'None')) {
		alert("Diffraction International does not provide on-site training outside the U.S. and Canada.")
    window.document.forms[0].Training.focus();
		return false;
	}
	
	return true;
}

function validate_Form() {
  total_price = 0;
  var price=document.getElementById('TotalPrice')
	validate_Country();
	validate_Interferometer();
	validate_License();
	validate_Computer();
	validate_Image();
	validate_Shifter();
	validate_Controller();
	validate_Amplifier();
	validate_Training();
	if(validate_Consistency())
	  price.innerHTML = '$' + total_price;
  else price.innerHTML = "<input type='button' value='Validate' onClick='validate_Form()'>";
	return;
}

function parse_URL() {
  var object = new ArgumentURL();
  if(object.getArgument('Computer') == 'laptop_thinkpad') {
    window.document.forms[0].Computer.value = 'laptop_thinkpad';
  }
  if(object.getArgument('Interferometer') == 'MIC1') {
    window.document.forms[0].Interferometer.value = 'MIC1';
  }
  if(object.getArgument('Shifter') == 'MIC1') {
    window.document.forms[0].Shifter.value = 'MIC1';
  }
  if(object.getArgument('Controller') == 'USB') {
    window.document.forms[0].Controller.value = 'DAQ6008';
  }
  return;
}

function printWindow() {
  if (window.print)
    window.print();
  else alert("Sorry, your browser doesn't support this feature.\nPlease select Print from the File Menu.");
}

