//<![CDATA[
/* Start main code (C) Landis media 2008 - Howard Williams */
// Global addopts, checkhgvoption1, checkoption2, checkoption3, dcode, delopts, dflag, dvalu, hgvoption1desc, hgvoption1flag, hgvoption2flag, hgvoption3flag, i, list1, list2, list3, list4, modlist, modname, modoptdisplay, resetmessage, showhide, t, updateorder, workingcost, writing1, writing2
var list1=['Please select a model','TomTom TOYOTA','TomTom GO Classics','TomTom GO 940 Traffic','TomTom GO 940','TomTom GO 930 Traffic','TomTom GO 930','TomTom GO 920 T','TomTom GO 920','TomTom GO 910','TomTom GO 740 Traffic','TomTom GO 740','TomTom GO 730 Traffic','TomTom GO 730','TomTom GO 720 T (Traffic)','TomTom GO 720','TomTom GO 710(WORK)','TomTom GO 710','TomTom GO 700','TomTom GO 540 Traffic','TomTom GO 540','TomTom GO 530 Traffic','TomTom GO 530','TomTom GO 520 T (Traffic)','TomTom GO 520 Music Edition','TomTom GO 520','TomTom GO 510','TomTom GO 500','TomTom GO 300','TomTom ECLIPSE','TomTom DAIHATSU','RIDER 2nd Edition','RIDER (local)','RIDER','ONE XL S','ONE XL Regional','ONE XL HDT','ONE XL Europe','ONE XL','ONE T Regional (Traffic)','ONE T Europe (Traffic)','ONE Regional','ONE New Edition Regional','ONE New Edition Europe','ONE Explore','ONE Europe 22 (new)','ONE Europe','ONE 3rd Edition','ONE 2nd Edition','ONE 1st Edition','NEW XL (30 Series)','NEW ONE Regional Traffic','NEW ONE Regional','NEW ONE (30 Series)','NAVIGATOR 6 on HP iPAQ','NAVIGATOR 6','TomTom GO 630','TomTom GO 650','TomTom START (all types)','XL IQ Routes edition','XXL IQ routes edition','TomTom GO LIVE 950','TomTom GO LIVE 550','TomTom GO LIVE 750','TomTom GO 7000 Truck'];
var list2=['-1','199001','199002','199003','199004','199005','199006','199007','199008','199009','199010','199011','199012','199013','199014','199015','199016','199017','199018','199019','199020','199021','199022','199023','199024','199025','199026','199027','199028','199029','199030','199031','199032','199033','199034','199035','199036','199037','199038','199039','199040','199041','199042','199043','199044','199045','199046','199047','199048','199049','199050','199051','199052','199053','199054','199055','199056','199057','199058','199059','199060','199061','199062','199063','199064'];
var list3=['Please select a model','Garmin Colorado 300','Garmin Colorado 400c','Garmin Colorado 400i','Garmin Colorado 400t','Garmin eTrex Legend Cx','Garmin eTrex Venture Cx','Garmin eTrex Vista Cx','Garmin GPSMAP 496','Garmin GPSMAP 60CSx','Garmin GPSMAP 60Cx','Garmin GPSMAP 76CSx','Garmin GPSMAP 76Cx','Garmin iQue M3','Garmin iQue M4','Garmin nuvi 200','Garmin nuvi 200w','Garmin nuvi 205','Garmin nuvi 205t','Garmin nuvi 205w','Garmin nuvi 215','Garmin nuvi 215w','Garmin nuvi 250','Garmin nuvi 250w','Garmin nuvi 255','Garmin nuvi 255w','Garmin nuvi 260','Garmin nuvi 260w','Garmin nuvi 265t','Garmin nuvi 265wt','Garmin nuvi 270','Garmin nuvi 275t','Garmin nuvi 300','Garmin nuvi 310','Garmin nuvi 310t','Garmin nuvi 350','Garmin nuvi 360','Garmin nuvi 370','Garmin nuvi 3760t','Garmin nuvi 3790t','Garmin nuvi 500','Garmin nuvi 5000','Garmin nuvi 550','Garmin nuvi 600','Garmin nuvi 610','Garmin nuvi 650','Garmin nuvi 660','Garmin nuvi 670','Garmin nuvi 680','Garmin nuvi 750','Garmin nuvi 755t','Garmin nuvi 760','Garmin nuvi 760t','Garmin nuvi 765t','Garmin nuvi 770','Garmin nuvi 775t','Garmin nuvi 780','Garmin nuvi 785t','Garmin nuvi 850','Garmin nuvi 855','Garmin nuvi 865t','Garmin nuvi 880','Garmin nuvi 885t','Garmin nuvi 1200','Garmin nuvi 1210','Garmin nuvi 1240','Garmin nuvi 1300','Garmin nuvi 1300t','Garmin nuvi 1310','Garmin nuvi 1340','Garmin nuvi 1340t','Garmin nuvi 1370t','Garmin nuvi 1390t','Garmin nuvi 1490t','Garmin nuvi 1690','Garmin Oregon 300','Garmin Oregon 400c','Garmin Oregon 400i','Garmin Oregon 400t','Garmin Quest 2','Garmin StreetPilot 2720','Garmin StreetPilot 2730','Garmin StreetPilot 7200','Garmin StreetPilot 7500','Garmin StreetPilot c310','Garmin StreetPilot c320','Garmin StreetPilot c330','Garmin StreetPilot c340','Garmin StreetPilot c510','Garmin StreetPilot c550','Garmin StreetPilot c580','Garmin StreetPilot i2','Garmin StreetPilot i3','Garmin StreetPilot i5','Garmin zumo 450','Garmin zumo 500','Garmin zumo 550'];
var list4=['-1','299001','299002','299003','299004','299005','299006','299007','299008','299009','299010','299011','299012','299013','299014','299015','299016','299017','299082','299018','299080','299081','299019','299020','299021','299022','299023','299024','299025','299026','299027','299028','299029','299030','299079','299031','299032','299033','299095','299096','299034','299035','299036','299037','299038','299039','299040','299041','299042','299043','299044','299045','299078','299046','299047','299048','299049','299050','299051','299052','299077','299053','299054','299094','299093','299092','299090','299091','299089','299088','299087','299086','299085','299084','299083','299055','299056','299057','299058','299059','299060','299061','299062','299063','299064','299065','299066','299067','299068','299069','299070','299071','299072','299073','299074','299075','299076'];
var list5=['Please select a model','Navman B10','Navman F20','Navman F20','Navman F20 Europe','Navman F30','Navman F30','Navman F40','Navman F40 Europe','Navman F50','Navman F50','Navman iCN 320','Navman iCN 330','Navman iCN 520','Navman iCN 530','Navman iCN 550','Navman iCN 720','Navman iCN 750','Navman iCN510','Navman iCN520','Navman iCN530','Navman iCN550','Navman iCN610','Navman iCN620','Navman iCN630','Navman iCN635','Navman iCN650','Navman iCN720','Navman iCN750','Navman N20','Navman N20','Navman N40i','Navman N40i','Navman N60i','Navman N60i','Navman PiN 570','Navman PIN300','Navman PIN570','Navman Pocket PC (V3 and newer)','Navman S100','Navman S200 Europe','Navman S30 (with Navdesk Custom POI)','Navman S30 3D (with Navdesk Custom POI)','Navman S300T','Navman S50','Navman S50','Navman S50 3D','Navman S70','Navman S70','Navman S70 3D','Navman S80','Navman S90i','Navman S90i'];
var list6=['-1','399001','399002','399003','399004','399005','399006','399007','399008','399009','399010','399011','399012','399013','399014','399015','399016','399017','399018','399019','399020','399021','399022','399023','399024','399025','399026','399027','399028','399029','399030','399031','399032','399033','399034','399035','399036','399037','399038','399039','399040','399041','399042','399043','399044','399045','399046','399047','399048','399049','399050','399051','399052'];
var list7=['Please select a model','Autoroute Other','Autoroute 2006','Autoroute 2007','Autoroute 2008'];
var list8=['-1','499001','499002','499003','499004'];


var modname=["TOMTOM","GARMIN","NAVMAN","AUTOROUTE"];
var modlist=[list1,list3,list5,list7];
var modcodes=[list2,list4,list6,list8];

var item_code=['FLBTT','FLBGAR','FLBNAV','FLBAUT'];
var modoptdisplay = ["show","hide","hide","hide"]; // this is the status for option 1 depending on the selection in this case a manual
// discos
var dcode=['++'];
var dvalu=['1'];
var dcodeid=['1'];
// options															
var hgvoption1flag = false; // this is because its hidden as default 
var hgvoption2flag = false; // this is because its hidden as default 
var hgvoption3flag = false; // this is because its hidden as default 
var orderready = false;
var hgvoption1desc = "Printed Color User Guide and Drivers Tips";
var i;
var t;
var writing1 =''; // initialise writing
var writing2 =''; // initialise writing
var resetmessage="Please select a model and make";
var dflag=false;
var workingcost = 20;	// this is the base temp money setup  - must be set hyere or will keep rising
var ordersum ='';
var ditem;
var sitem;
var howfound='';


// this option removes select items
function delopts(selectbox)
{
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		//selectbox.options.remove(i);
		selectbox.remove(i);
	}
}

// this adds itmes to a listbox
function addopts(selectbox, valuein, textin )
{
	var optn = document.createElement("OPTION");
	optn.text = textin;
	optn.value = valuein;
	selectbox.options.add(optn);
}


function writeorder (messobj,messg){
document.getElementById(messobj).innerHTML = messg; // apply writing to the printout area
//document.getElementById('orderdesc').style.align="left"; // align it left
return;
}

function resetorder () {
writeorder('orderdesc',resetmessage);
writeorder('totalcost',"Total Cost= &pound;" );
//alert(document.mainform.cdmake.value);
delopts(document.getElementById("modeltypeid"));
addopts(document.getElementById("modeltypeid"),"default","Please select your brand");
orderready=false;
return;
}






// this turns an option or off
function showhide (obj,state) {
if (state === "show") {document.getElementById(obj).style.display = "block"; return;} else {document.getElementById(obj).style.display = "none"; return;}
}


// code for checking an option
function checkhgvoption1 () {
// first is if its visible or not other option may hide or show this
			if (document.getElementById("hgvoption1id").style.display === "block")
			{
			// do this if its visible
						// this option is a checkbox type
						if (document.getElementById("hgvoption1inputid").checked === true)
						{
						// do this if it is  checked
						//alert("OPTION1 CHECKBOX IS CHECKED AND IS VISIBLE");
						hgvoption1flag = true;
						workingcost +=4.99;
						document.mainform.hgvoptionscode.value = 'M';
						}
						else
						{
						// do this if not checked
						//	alert("OPTION1 CHECKBOX IS not CHECKED AND IS VISIBLE");
						hgvoption1flag = false;
						document.mainform.hgvoptionscode.value = '';
						}	
			}				
			else 
			{
					// do this if the option box is hidden
			//alert("OPTION1 CHECKBOX IS not VISIBLE");
						hgvoption1flag = false;
						document.mainform.hgvoptionscode.value = '';
			}
			return (true);
}

//placeholder
function checkoption2 () {
						if (document.mainform.hgvoption2input.selectedIndex===0 )
						{alert("Please select how you found us before you checkout");hgvoption2flag=false;return;}
						else
						{howfound = document.mainform.hgvoption2input.value;hgvoption2flag=true;}
			return (true);
}

function checkoption3 () {
}


function checkformakemodel () {

// if the user hasnt selected a make or model they are asked to
if (document.mainform.cdmake.selectedIndex===0)  {resetorder();alert("Please select a satnav brand first");return(false);}

// if the user hasnt selected a model they are asked to
if (document.mainform.modeltype.selectedIndex===0) {alert("Please select a " + document.mainform.cdmake.value + " model");return(false);}

// if the cd rom isnt checked the its download
return(true)

}



function checkforfilling(){
// check the satnav make and model have been chosen
if (checkformakemodel() != true){return;}

// check for the way they found us being chosen
if (checkoption2() != true){return;}

// if all is correct then make sure order is ready
//alert("setting ordeready to true");
orderready = true;
return;
}



// this is the main update order routing - called to check all selections
function updateorder(){
workingcost = 20;
// this is the base cost used for the item
// alert("temp cost = " + temcost);

			if (document.getElementById("cdrom").checked !== true)  // this checks and flags the cdrom over
			{
			//alert('SUCCESS - DOWNLOAD APPLIED');
			//document.getElementById("checkoutbuttons").style.display="block";  left behind to turn on and off checkout
			document.mainform.shipping.value="0"; // set shipping to nothing
			document.mainform.delivery.value="DOWNLOAD"; // set text description to download
  		showhide("downloadicon","show");
	  	showhide("cdromicon","hide");
			document.mainform.hgvformatcode.value ='DL';
			}
			else {
			//alert('SUCCESS - CD ROM APPLIED');
			//document.getElementById("checkoutbuttons").style.display="block"; as above
			document.mainform.shipping.value="3.99"; // set shiiping to 3.99
			//temcost += 3.99; // add shipping to the temp cost
			document.mainform.delivery.value="CD-ROM (3.99 for P&P)";
			showhide("downloadicon","hide");
			showhide("cdromicon","show");
			document.mainform.hgvformatcode.value ='CD';
			}
			
// now for themanual if they have selected a model that will make it visible
checkhgvoption1();

// check for a discount
if (document.mainform.disco.value !== "OFF") {workingcost -= document.mainform.disco.value;} // apply the discount value from code used
document.mainform.tempcost.value = Math.round(workingcost*100)/100;

		// writing is below
		writing1 = "PRODUCT: <b>Fleet and Low Bridges<\/b> MAKE:<b>" + document.mainform.cdmake.value.toUpperCase() + "<\/b><br/>";
		writing1 += document.mainform.cdmake.value.toUpperCase() + " MODEL: <b>" + document.mainform.modeltype.value.toUpperCase() + "<\/b><br/>";
		writing1 += "SUPPLIED ON A: <b>" + document.mainform.delivery.value + "<\/b><br/>";
		if (hgvoption1flag === true) {writing1 += "WITH OPTION: <b>" + hgvoption1desc + "<\/b><br/>";}
		writing2 = "Total Cost= &pound;" + document.mainform.tempcost.value;
writeorder('orderdesc',writing1); // write to screen
writeorder('totalcost',writing2); // write to screen


// write ready for submit

ordersum = "Product: Fleet and Low Bridges " + " Make:" +  document.mainform.cdmake.value.toUpperCase() + " Model:" + document.mainform.modeltype.value.toUpperCase() + " Supplied: " + document.mainform.delivery.value ; 
document.mainform.os1.value = howfound;
document.mainform.custom.value = "0";
if (document.mainform.disco.value !== "OFF") {document.mainform.custom.value = document.mainform.discountid.value;} // apply the discount value from code used
document.mainform.on0.value = "Voucher: " + ditem;
document.mainform.on1.value = document.mainform.delivery.value;
//document.mainform.os0.value = document.mainform.cdmake.value.toUpperCase() + " Model:" + document.mainform.modeltype.value.toUpperCase();//
document.mainform.os0.value = document.mainform.modeltype.value.toUpperCase();
document.mainform.item_number.value = document.mainform.hgvmodelcode.value + document.mainform.hgvformatcode.value + document.mainform.hgvoptionscode.value;
//alert(document.mainform.item_number.value);
//document.mainform.item_name.value = ordersum; // chnaged for testing with ukp
//document.mainform.item_name.value = 'proCAB PLUS item:PTDM';
// test remove this if (hgvoption1flag === true) {document.mainform.item_name.value += hgvoption1desc;document.mainform.os1.value += hgvoption1desc;}
document.mainform.item_name.value =  "Fleet and Low Bridges" + " for " +  document.mainform.cdmake.value.toUpperCase();
document.mainform.amount.value = document.mainform.tempcost.value;

//document.mainform.os2.if (document.mainform.os2.checked = true) {alert(document.mainform.os2.checked.value);};
//document.getElementById('orderdesc').innerHTML = "hello";
// write the return address


//test  chnage - if a dowenload then chnage return page - taken out
//if (document.getElementById("cdrom").checked !== true)  // this checks and flags the cdrom over
//{document.getElementById('preturn').value="http://www.hgvsolutions.com/success_pcplus"+ sitem.substr(0,3).toLowerCase() +"dl.htm";}

// set order ok to false so will go true once verified form
orderready=false;
//checkoption2();
}

function subform () {
updateorder();
//alert("now calling the checker");
checkforfilling();
//alert("got here to checkout and orderready is = " + orderready);
if (orderready===true){document.mainform.submit();return;}
}


// this applies the relevant dropdowns - the manual is turned on and off by this
function hgvselections () 
{
sitem = document.mainform.cdmake.value;
for (i=0;i<modname.length;i++){
															if(modname[i]===sitem)
																									{
																									var listuse = modlist[i];
																									var codeuse = modcodes[i];
																									var modtypelist = document.getElementById("modeltypeid");
																									//alert("got here" + modoptdisplay[i]);														
																									showhide("hgvoption1id",modoptdisplay[i]); // shows or hides option 1 as per model
																									document.mainform.hgvmodelcode.value =  item_code[i];
																									delopts(modtypelist);
																									for (t=0;t<listuse.length;t++){addopts(modtypelist,codeuse[t],listuse[t]);}
																									updateorder();
																									return;
																									}		
															}
resetorder();
updateorder();
return;
}

															
															
// this applies the relevant dropdowns - the manual is turned on and off by this
function checkdiscount ()
{
ditem = document.mainform.voucher.value.toUpperCase();
if (dflag){ alert("You have already applied a discount code");return;}
if ((document.mainform.voucher.value ==="") || (document.mainform.voucher.value === "undefined" )) {alert("Please enter a code in the box");return;}
for (i=0;i<dcode.length;i++){if(dcode[i]===ditem){dflag=true;var damnt=dvalu[i];var dcodeidtmp = dcodeid[i];}}
if (dflag){
					alert('SUCCESS - your discount have been discounted ' + damnt +" pounds");
					document.mainform.disco.value = damnt; // apply the discount value to input field so no more can be used
					document.mainform.discountid.value = dcodeidtmp;
					//	alert("Disco is " + document.mainform.disco.value);
					updateorder(); // now update the order
					return;
					}
					else
					{
					alert(ditem+' - is not a valid discount code'); // code ot recognised
					}
																									
}		
//]]>

