var answers=[];

function getUrlAnswers() {
    var hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++){
	hash = hashes[i].split('=');
	answers.push(hash[1]);
    }
} 

Array.prototype.max = function () {
if (this.length == 0) return undefined;
var n = Number(this[0]);
for (var i=1; i<this.length; i++) {n = Math.max(n, this[i])};
return n;
}

function findScanner(){
    var scanners=Array(0,0,0,0,0,0,0,0,0,0,0);
    var extra=Array(0,0,0,0,0,0);

    for (i = 0; (i < answers.length); i++) {
	switch(answers[i]) {
	case "q1a1":
	case "q2a1": 
	    scanners[0]+=1;
	    scanners[1]+=1;
	    scanners[2]+=1;
	    scanners[3]+=1;
	    scanners[4]+=1;
	    scanners[5]+=1;
	    scanners[6]+=1;
	    scanners[7]+=1;
	    scanners[8]+=1;
	    scanners[9]+=1;
	    scanners[10]+=1;
	    break;
	case "q1a2": 
	    scanners[0]+=1;
	    scanners[0]+=1;
	    scanners[2]+=1;
	    scanners[3]+=1;
	    scanners[4]+=1;
	    scanners[5]+=1;
	    scanners[6]+=1;
	    scanners[7]+=1;
	    scanners[8]+=1;
	    scanners[9]+=1;
	    scanners[10]+=1;
	    break;
	case "q1a3":
	case "q2a2":
	case "q2a3":
	    scanners[5]+=1;
	    scanners[6]+=1;
	    scanners[7]+=1;
	    scanners[8]+=1;
	    scanners[9]+=1;
	    scanners[10]+=1;
	    break;
	case "q3a1":
	    scanners[0]+=1;
	    scanners[5]+=1;
	    scanners[6]+=1;
	    break;
	case "q3a2":
	    scanners[1]+=1;
	    scanners[2]+=1;
	    scanners[3]+=1;
	    scanners[4]+=1;
	    scanners[5]+=1;
	    scanners[6]+=1;
	    extra[3]=-10; // eliminate XD MFP
	    break;
	case "q3a3":
	    scanners[1]+=1;
	    scanners[2]+=1;
	    scanners[3]+=1;
	    scanners[4]+=1;
	    scanners[7]+=1;
	    scanners[8]+=1;
	    scanners[9]+=1;
	    extra[3]=-10; // eliminate XD MFP
	    break;
	case "q3a4":
	    scanners[1]+=1;
	    scanners[2]+=1;
	    scanners[3]+=1;
	    scanners[4]+=1;
	    scanners[10]+=1;
	    extra[3]=-10; // eliminate XD MFP
	    break;
	case "q4a1":
	    scanners[1]+=1;
	    scanners[2]+=1;
	    scanners[5]+=1;
	    scanners[7]+=1;
	    scanners[8]+=1;
	    break;
	case "q4a2":
	    scanners[1]+=1;
	    scanners[2]+=1;
	    scanners[3]+=1;
	    scanners[5]+=1;
	    scanners[6]+=1;
	    scanners[7]+=1;
	    scanners[8]+=1;
	    scanners[9]+=1;
	    break;
	case "q4a3":
	    scanners[1]+=1;
	    scanners[4]+=1;
	    scanners[6]+=1;
	    scanners[9]+=1;
	    extra[0]+=1;
	    break;
	case "q5a1":
	case "q5a2":
	    extra[4]+=1;
	    break;
	case "q5a3":
	    extra[1]+=1;
	    extra[2]+=1;
	    extra[3]+=1;
	    extra[5]+=1;
	    extra[4]=-10; //eliminiate NI Scan
	    break;
	} // switch
    } //foreach

    var maxscanner=scanners.max();
    var maxextra=extra.max();

// the format is ["Scanner name", "image name" (assumes .jpg!), "description"]
    var scannername=[
	["<a href='http://www.contex.com/english/scanners/sd_xd_series/24-quot_xd2490/product_overview.aspx'>XD2490</a>","xd2490","Scans technical drawings, maps, data logs, or other text&ndash;based information up to A1 or D&ndash;size, with incredible sharpness and detail."],
	["<a href='http://www.contex.com/english/scanners/sd_xd_series/36-quot_sd3600/product_overview.aspx'>SD3610</a>","sd3610","Scans technical drawings, maps, data logs, newspaper or other text&ndash;based information in black&frasl;white or grayscale up to 36&ndash;inches wide, with incredible sharpness and detail."],
	["<a href='http://www.contex.com/english/scanners/sd_xd_series/36-quot_sd3600/product_overview.aspx'>SD3650</a>","sd3650+","Scans technical drawings, maps, data logs, newspaper or other text&ndash;based information in full color, black&frasl;white, or grayscale up to 44&ndash;inches wide, with incredible sharpness and detail."],
	["<a href='http://www.contex.com/english/scanners/sd_xd_series/44-quot_sd4400/product_overview.aspx'>SD4450</a>","sd4450","Scans technical drawings, maps, data logs, newspaper or other text&ndash;based information in full color, black&frasl;white, or grayscale up to 44&ndash;inches wide, with incredible sharpness and detail."],
	["<a href='http://www.contex.com/english/scanners/sd_xd_series/44-quot_sd4400/product_overview.aspx'>SD4490</a>","sd4490","Scans technical drawings, maps, data logs, newspaper or other text&ndash;based information in full color, black&frasl;white, or grayscale up to 44&ndash;inches wide, with incredible sharpness and detail."],
	["<a href='http://www.contex.com/english/scanners/hd_ultra_series/hd_ultra_office.aspx'>HD Ultra 3630</a>","hd_ultra","Highly flexible with the ability to scan anything up to 36&ndash;inches wide and 0.6&ndash;inches thick &ndash; from technical drawings and maps to photos and artwork, with the best color accuracy available."],
	["<a href='http://www.contex.com/english/scanners/hd_ultra_series/hd_ultra_professional.aspx'>HD Ultra 3650+</a>","hd_ultra","Highly flexible with the ability to scan anything up to 36&ndash;inches wide and 0.6&ndash;inches thick &ndash; from technical drawings and maps to photos and artwork, with the best color accuracy available."],
	["<a href='http://www.contex.com/english/scanners/hd_ultra_series/hd_ultra_office.aspx'>HD Ultra 4230</a>","hd_ultra","Highly flexible with the ability to scan anything up to 42&ndash;inches wide and 0.6&ndash;inches thick &ndash; from technical drawings and maps to photos and artwork, with the best color accuracy available."],
	["<a href='http://www.contex.com/english/scanners/hd_ultra_series/hd_ultra_office.aspx'>HD Ultra 4230i</a>","hd_ultra","?adds Ethernet network connectivity to the already flexible HD Ultra 4230 scanner."],
	["<a href='http://www.contex.com/english/scanners/hd_ultra_series/hd_ultra_professional.aspx'>HD Ultra 4250+</a>","hd_ultra","Highly flexible with the ability to scan anything up to 42&ndash;inches wide and 0.6&ndash;inches thick &ndash; from technical drawings and maps to photos and artwork, with the best color accuracy available."],
	["<a href='http://www.contex.com/english/scanners/hd_series/54-quot_hd5400/product_overview.aspx'>HD5400 PLUS</a>","hd5400PLUS","Highly flexible with the ability to scan anything up to 54&ndash;inches wide and 0.6&ndash;inches thick &ndash; from technical drawings and maps to photos and artwork, with the best color accuracy available."]];

    var extraname=[
	["High Speed Upgrade","blank","Add additional speed with a simple upgrade license key &ndash; ask for details&#33;"],
	["<a href='http://www.contex.com/english/scanners/mfp_solutions/hd_ultra_3630_mfp/overview.aspx'>HD Ultra MFP</a>","hd_ultramfp","With an ultra&ndash;flexible HD series scanner, Nextimage MFP touch&ndash;screen operated multifunction software and an intelligent single footprint stand, the HD Ultra MFP is the perfect solution for distributing copies jobs to all your wide format printers."],
	["<a href='http://www.contex.com/english/scanners/mfp_solutions/sd4420_mfp/overview.aspx'>SD MFP</a>","sdmfp","With a reliable, easy to use SD series scanner, Nextimage MFP touch&ndash;screen operated multifunction software and an intelligent single footprint stand that fits your wide format printer, the SD MFP is the perfect wide format office copier."],
	["<a href='http://www.contex.com/english/scanners/mfp_solutions/xd2490_mfp/overview.aspx'>XD MFP</a>","xdmfp","With the compact XD series scanner, Nextimage MFP touch&ndash;screen operated multifunction software and an intelligent single footprint stand that fits your wide format printer, the XD MFP is the perfect wide format office copier."],
	["<a href='http://www.contex.com/english/software/nextimage.aspx'>Nextimage Scan+Archive</a>","nextimage","Whether you?re scanning one or one thousand documents for editing or for archiving, ?Nextimage provides a simple interface for getting the best images ? fast."],
	["<a href='http://www.contex.com/english/software/nextimage.aspx'>Nextimage Repro</a>","nextimage","Combining the ability to scan, copy, email, and print in wide format with built&ndash;in support for most wide format printers, Nextimage is the powerful multi&ndash;function software designed especially for Contex scanners."]
    ];

    document.write("<table border='0' width='100%'>\n");

    for (i = 0; (i < scanners.length); i++) {
	if (scanners[i] == maxscanner) {
	    document.write('<tr><td>\n');
	    document.write("<p><br /><img src='/Files/System/js/img/"+scannername[i][1]+".jpg' border='0' align='left' style='margin-right: 10px; padding-right: 10px; border-right: 1px solid #000000;'>");
	    document.write('<h2 class="h2">'+scannername[i][0]+'</h2>\n');
	    document.write(scannername[i][2]+"</p>\n");
	    document.write('</td></tr>\n');
	} // if
    } // for..next

    document.write("<tr><td><br /><br /><h1 class='h1'>Recommended Accessories</h1></td></tr>");

    for (i = 0; (i < extra.length); i++) {
	if (extra[i] == maxextra) {
	    document.write('<tr><td>\n');
	    document.write("<p><br /><img src='/Files/System/js/img/"+extraname[i][1]+".jpg' border='1' align='left' style='margin-right: 10px; padding-right: 10px; border-right: 1px solid #000000;'>");
	    document.write('<h2 class="h2">'+extraname[i][0]+'</h2>\n');
	    document.write(extraname[i][2]+"</p>\n");
	    document.write('</td></tr>\n');
	} // if
    } // for..next
    document.write('</table>\n');
}

