var exploreSubs=[

["9780431079639","Explore Active Science","1","-250"],
["9780431079646","Explore Active Science","1","+250"],
["9780431079653","Explore Active Science","2","-250"],
["9780431079660","Explore Active Science","2","+250"],
["9780431079899","Explore Active Science","3","-250"],
["9780431079905","Explore Active Science","3","+250"],
["9780431079493","Explore Active Science","4","-250"],
["9780431079509","Explore Active Science","4","+250"],
["9780431100685","Explore Key Stage 2 Geography","1","-250"],
["9780431187785","Explore Key Stage 2 Geography","1","+250"],
["9780431102740","Explore Key Stage 2 Geography","2","-250"],
["9780431187853","Explore Key Stage 2 Geography","2","+250"],
["9780431188683","Explore Key Stage 2 Geography","3","-250"],
["9780431188690","Explore Key Stage 2 Geography","3","+250"],
["9780431188706","Explore Key Stage 2 Geography","4","-250"],
["9780431188713","Explore Key Stage 2 Geography","4","+250"],
["9780431099606","Explore Key Stage 2 History","1","-250"],
["9780431187730","Explore Key Stage 2 History","1","+250"],
["9780431102696","Explore Key Stage 2 History","2","-250"],
["9780431187808","Explore Key Stage 2 History","2","+250"],
["9780431188294","Explore Key Stage 2 History","3","-250"],
["9780431188300","Explore Key Stage 2 History","3","+250"],
["9780431188317","Explore Key Stage 2 History","4","-250"],
["9780431188324","Explore Key Stage 2 History","4","+250"],
["9780431099903","Explore Key Stage 2 Science","1","-250"],
["9780431187761","Explore Key Stage 2 Science","1","+250"],
["9780431102726","Explore Key Stage 2 Science","2","-250"],
["9780431187839","Explore Key Stage 2 Science","2","+250"],
["9780431188089","Explore Key Stage 2 Science","3","-250"],
["9780431188096","Explore Key Stage 2 Science","3","+250"],
["9780431188102","Explore Key Stage 2 Science","4","-250"],
["9780431188119","Explore Key Stage 2 Science","4","+250"],
["9780431099613","Explore Key Stage 3 History","1","-250"],
["9780431187747","Explore Key Stage 3 History","1","+250"],
["9780431102702","Explore Key Stage 3 History","2","-250"],
["9780431187815","Explore Key Stage 3 History","2","+250"],
["9780431188331","Explore Key Stage 3 History","3","-250"],
["9780431188348","Explore Key Stage 3 History","3","+250"],
["9780431188355","Explore Key Stage 3 History","4","-250"],
["9780431188362","Explore Key Stage 3 History","4","+250"],
["9780431099897","Explore Key Stage 3 Science","1","-250"],
["9780431187778","Explore Key Stage 3 Science","1","+250"],
["9780431102733","Explore Key Stage 3 Science","2","-250"],
["9780431187846","Explore Key Stage 3 Science","2","+250"],
["9780431188126","Explore Key Stage 3 Science","3","-250"],
["9780431188133","Explore Key Stage 3 Science","3","+250"],
["9780431188140","Explore Key Stage 3 Science","4","-250"],
["9780431188157","Explore Key Stage 3 Science","4","+250"],
["9780431103716","Young Explorer","1","-250"],
["9780431187792","Young Explorer","1","+250"],
["9780431102757","Young Explorer","2","-250"],
["9780431187860","Young Explorer","2","+250"],
["9780431102771","Young Explorer","3","-250"],
["9780431102788","Young Explorer","3","+250"],
["9780431102795","Young Explorer","4","-250"],
["9780431102924","Young Explorer","4","+250"]

]

function showProductChooser(){

var outputHTML="";

    outputHTML+='<select id="productSel" style="width:200px">';

    var lastProduct;
    for (var i=0, j=exploreSubs.length;i<j;i++){
        var product=exploreSubs[i][1];
        if (product==lastProduct){continue;}
        outputHTML+='<option value="'+product+'">'+product+'</option>';
        lastProduct=product;
    }

    outputHTML+='</select>';

document.getElementById("productChoice").innerHTML=outputHTML;
document.getElementById("productSel").value="";
}

function showSubLengthDD(){
var outputHTML="";

    outputHTML+='<select id="subLengthSel" style="width:200px">';
    for (var i=1, j=4;i<=j;i++){
        outputHTML+='<option value="'+i+'">'+i+' Year</option>';
    }
    outputHTML+='</select>';

document.getElementById("subLengthChoice").innerHTML=outputHTML;
document.getElementById("subLengthSel").value="";
}

function showSchoolSizeDD(){
var outputHTML="";

    outputHTML+='<select id="schoolSizeSel" style="width:200px">';
    outputHTML+='<option value="-250">Fewer than 250 pupils</option>';
    outputHTML+='<option value="+250">More than 250 pupils</option>';
    outputHTML+='</select>';

document.getElementById("schoolSizeChoice").innerHTML=outputHTML;
document.getElementById("schoolSizeSel").value="";
}

function showSubTypeDD(){
var outputHTML="";

    outputHTML+='<select id="subTypeSel" style="width:200px">';
    outputHTML+='<option value="trial">Free Trial</option>';
    outputHTML+='<option value="sub">Subscription</option>';
    outputHTML+='</select>';

if (typeof(pageDefinedType)=="undefined"){pageDefinedType="";}

document.getElementById("subTypeSelChoice").innerHTML=outputHTML;
document.getElementById("subTypeSel").value=pageDefinedType;

}

showProductChooser();
showSubLengthDD();
showSchoolSizeDD();
showSubTypeDD();

function gotoChosenSub(){
var uProduct=document.getElementById("productSel").value;
var uLength=document.getElementById("subLengthSel").value;
var uSize=document.getElementById("schoolSizeSel").value;
var uType=document.getElementById("subTypeSel").value;
var gotoUrl;

if (!uProduct){
alert("Please choose a product using the drop-down\nmenus then click the 'Next' button again.");
return;
}

if (!uLength){
//assume 1 year
uLength="1";
}

if (!uSize){
//assume 250+
uSize="+250";
}

if (!uType || uType=="trial"){uType="&try=1";}//query string for trials
else {uType=""}

    for (var i=0, j=exploreSubs.length;i<j;i++){
        var arrIsbn=exploreSubs[i][0];
        var arrProduct=exploreSubs[i][1];
        var arrLength=exploreSubs[i][2];
        var arrSize=exploreSubs[i][3];

        if (arrProduct!=uProduct || uLength!=arrLength || uSize!=arrSize){
        continue;
        }
        else {
        gotoUrl="http://www.heinemannlibrary.co.uk/Product/" + arrIsbn;
        }
    }

if(gotoUrl){window.location=gotoUrl;}
else {alert("Could not find the requested subscription.\n\nPlease try again.")}

}
