var nt='</table>'
var cll='<br></td><td>'
var wid='<br></td><td width='
var clll='<br>' + cll
var cllc=cll + '<center>'


function message3() {
DispWin = window.open('','howto', 'toolbar=no,status=no,resizable=yes,width=500,height=300,scrollbars=no,menubar=yes')

message ='Print or remember this page.<br><br>The route card you have just created is on the other window that has just opened. It contains all the formulas that excel can use to display the route. However as it is you wont be able to use it to follow a route by.<bR><br>To export it to excel, go to the "View" menu, and select "Source". This will open another window - probably using "notebook" and then select the "File" menu from this and "Save As". Save the file using whatever name you want and - THIS IS IMPORTANT - end the filename with ".xls" you can then open this file in excel and it will work.<br><br>'

message = message +'<center><input type=button value="Close" onclick=self.close()></center>'

+ '</ULul>';
DispWin.document.write(message);
}



function create2excel() {

var test=document.route.date1.value
if (test=='dd/mm/yyyy'){test='01/01/2006'}
var test2=(test.substring((test.length-2),test.length))*1
var test3=3+11/12
if (test2>=0){if (test2<=99){var test2=(test2*1)+2000}}
else {var today = new Date();test2 = today.getYear()}
test3=(test3)-(test2-2004)*13/60
if (test3<0){test3=test3*(-1)}
if (test3==0){test3=0}
document.route.magnetic.value=Math.round(test3)

DispWin = window.open('','routetoexcel', 'toolbar=no,status=no,resizable=no,width=550,height=450,scrollbars=no,menubar=yes')

message ='<ULli><lili><link rel=stylesheet type=text/css href=white2.css title=style><style type=text/css></style>'

message += '<ULli>'

message += '<table width=100% border=0 cellpadding=1 cellspacing=2><tr><td width=10%>' + wid + '10%>' + wid + '46%>' + wid + '4%>' + wid + '4%>' + wid + '6%>' + wid + '6%>' + wid + '10%>' + wid + '4%>' + wid + '10%></tr>'

var noofpoints=0
for (var j=30; j<((routelength*9)+28); j=j+9) {
if (document.route.elements[j].value!='') {
noofpoints = noofpoints + 1}}

if (document.route.groupname.value==0){message += '<tr><td colspan=10><center><b><font size=4>My Group</b></font>' + nd + '<tr>'}

else{message += '<tr><td colspan=10><center><b><font size=4>' + document.route.groupname.value + '</b></font>' + nd + '<tr>'}

message += '<td colspan=3>Walk Date: '+ document.route.date1.value + '<br></td><td colspan=4><br></td><td colspan=3 align=right>Page ' + document.route.page.value + ' of ' + document.route.pages.value + nd + '<tr>'

message += '<td align=right><br></td><td align=right>Map: <br></td><td colspan=3>' + document.route.map_name.value + ', Map No. ' + document.route.map.value + '<br></td><td colspan=5><br>' + nd + '<tr>'

message += '<td colspan=2 align=right>Map scale: <br></td><td>' + document.route.scale.value + '<br></td><td><br></td><td colspan=6><center>Group Members' + nd + '<tr>'

message +='<td width=20% colspan=2 align=right>Start Grid Ref.<br></td><td>=B27<br></td><td colspan=4>1. ' + document.route.elements[3].value + '<br></td><td colspan=3>2. ' + document.route.elements[4].value + nd + '<tr>'

message +='<td width=20% colspan=2 align=right>End Grid Ref.<br></td><td>=B' + (27+noofpoints) + '<br></td><td colspan=4>3. ' + document.route.elements[5].value + '<br></td><td colspan=3>4. ' + document.route.elements[6].value + nd + '<tr>'

message +='<td width=20% colspan=2 align=right>Start Height<br></td><td>' + document.route.height1.value + '<br></td><td colspan=4>5. ' + document.route.elements[7].value + '<br></td><td colspan=3>6. ' + document.route.elements[8].value + nd + '<tr>'

message +='<td width=20% colspan=2 align=right>End Height<br></td><td>=C7+D' + (28+noofpoints*1) + '-E' + (28+noofpoints*1) + ')<br></td><td colspan=4>7. ' + document.route.elements[9].value + '<br></td><td colspan=3>8. ' + document.route.elements[10].value + nd + '<tr>'

message +='<td colspan=2 align=right>Walking Speed: <br></td><td>' + document.route.speed1.value + ' km/h<br></td><td colspan=7>Group Contact: ' + document.route.contactname.value + nd + '<tr>' + '<br><td colspan=2 align=right>Car Reg. No. _____________<br></td><td><br></td><td colspan=6>Telephone No. ' +  document.route.telno1.value + nd + '<tr>'

message += '<td colspan=10><hr>' + nd + '<tr><td colspan=2 align=right><b>Home Contact </b><br></td><td>' + document.route.homecontact.value + '<br></td><td colspan=3 align=right>Tel. No.<br></td><td colspan=4 align=left>' + document.route.telno2.value + nd + '<tr><td colspan=2 align=right>Address <br></td><td colspan=4>' + document.route.address1.value + ', ' + document.route.address2.value + '<br></td><td colspan=4><br>' + nd + '<tr>'

message += '<td colspan=10><hr>' + nd + '<tr><td colspan=2 align=right>Walk Objective: <br></td><td colspan=8>' + document.route.objective.value + nd + '<tr><td colspan=10><hr>' + nd + '<tr><td colspan=3>Weather Forecast: <br></td><td colspan=7>_________________________________________' + nd +'<tr><td colspan=2 align=right>Sunrise: <br></td><td>_____ : _____<br></td><td align=right>Sunset: <br></td><td colspan=3>_____ : _____<br></td><td><br></td><td>' + nd

message += '<tr><td colspan=10><br></td></tr><tr><td colspan=10><hr>' + nd + nt

message += '<table width=200% border=0 cellpadding=1 cellspacing=2><tr><td width=5%>' + wid + '5%>' + wid + '23%>' + wid + '2%>' + wid + '2%>' + wid + '3%>' + wid + '3%>' + wid + '5%>' + wid + '2%>' + wid + '5%>' + wid + '22%>' + wid + '22%>' + wid + '6%></tr>'

message += '<tr><td>From: <br></td><td>To: <br></td><td>Description of place going to<br>Route description and notes<br></td><td colspan=2>Height<br>Changes<br></td><td>Breaks<br></td><td>Dist. <br></td><td>Bearing<br></td><td>Time<br></td><td>ETA'+ cll + 'Eastings' + cll + 'Northings' + cll + 'Height' + nd

message += '<tr><td>xxxxxx' +cll + document.route.ref00.value + cll + document.route.goingto00.value + cllc + '+' +cllc+ '-' +cllc+ '(mins)' +cllc+ '(km)' +cllc+ '(Deg)' +cllc+ '(mins)' + cll + document.route.ETA00.value + cll  + '=(LEFT(B27,IF(LEN(B27)>5,3,LEN(B27)-3)))*1' + cll + '=(RIGHT(B27,3))*1' + cll + '=$C$7' + nd

var x=2

for (var j=30; j<((routelength*9)+28); j=j+9) {
if (document.route.elements[j].value!='') {

message += '<tr><td>=B' + (26+(j-21)/9)
message += clll + document.route.elements[j+0].value;
message += clll + document.route.elements[j+1].value;
message += clll + document.route.elements[j+2].value;
message += clll + document.route.elements[j+3].value;
message += clll + document.route.elements[j+4].value;

message += clll + '=IF(ISNUMBER(B' + (27+(j-21)/9) + '),((IF((K' + (27+(j-21)/9) + '-K' + (26+(j-21)/9) + ')^2>250000,(MIN(K' + (26+(j-21)/9) + ':K' + (27+(j-21)/9) + ')+1000)-MAX(K' + (26+(j-21)/9) + ':K' + (27+(j-21)/9) + '),(MIN(K' + (26+(j-21)/9) + ':K' + (27+(j-21)/9) + '))-MAX(K' + (26+(j-21)/9) + ':K' + (27+(j-21)/9) + ')))^2+(IF((L' + (27+(j-21)/9) + '-L' + (26+(j-21)/9) + ')^2>250000,(MIN(L' + (26+(j-21)/9) + ':L' + (27+(j-21)/9) + ')+1000)-MAX(L' + (26+(j-21)/9) + ':L' + (27+(j-21)/9) + '),(MIN(L' + (26+(j-21)/9) + ':L' + (27+(j-21)/9) + '))-MAX(L' + (26+(j-21)/9) + ':L' + (27+(j-21)/9) + ')))^2)^0.5/10,0)*(100+$D$' + ((29)+noofpoints*1) + ')/100'

message += clll + '=IF(OR(B' + (26+(j-21)/9) + '="",B' + (27+(j-21)/9) + '="",B' + (26+(j-21)/9) + '=B' + (27+(j-21)/9) + '),"",IF(B' + (27+(j-21)/9) + '>0,SQRT(((57.2958*ASIN((k' + (27+(j-21)/9) + '-k' + (26+(j-21)/9) + ')/(IF(ISNUMBER(B' + (27+(j-21)/9) + '),((k' + (27+(j-21)/9) + '-k' + (26+(j-21)/9) + ')^2+(l' + (27+(j-21)/9) + '-l' + (26+(j-21)/9) + ')^2)^0.5/10,0)*10)))+(IF(B' + (27+(j-21)/9) + '>=B' + (26+(j-21)/9) + ',(IF((B' + (27+(j-21)/9) + '-1000*k' + (27+(j-21)/9) + ')>=(B' + (26+(j-21)/9) + '-1000*k' + (26+(j-21)/9) + '),0,-180)),(IF((B' + (26+(j-21)/9) + '-1000*TRUNC(B' + (26+(j-21)/9) + '/1000))>=(B' + (27+(j-21)/9) + '-1000*TRUNC(B' + (27+(j-21)/9) + '/1000)),-180,360)))))^2),0))'

message += clll + '=IF(ISNUMBER(B' + (27+(j-21)/9) + '),G' + (27+(j-21)/9) + '*60/TRIM(LEFT($C$9,2))+(D' + (27+(j-21)/9) + '/10+F' + (27+(j-21)/9) + '+if(E' + (27+(j-21)/9) + '/(G' + (27+(j-21)/9) + '*1000)>$D$' + ((30)+noofpoints*1) + '/100,E' + (27+(j-21)/9) + '/20,0)),0)'

message += clll + '=IF(ISNUMBER(B' + (27+(j-21)/9) + '),TIME(HOUR($J$27),MINUTE($J$27)+int(sum($I$28:I' + (27+(j-21)/9) + ')),sum($I$28:I' + (27+(j-21)/9) + ')-int(sum($I$28:I' + (27+(j-21)/9) + '))))'

message += cll + '=(LEFT(B' + (27+(j-21)/9) + ',IF(LEN(B' + (27+(j-21)/9) + ')>5,3,LEN(B' + (27+(j-21)/9) + ')-3)))*1' + cll + '=(RIGHT(B' + (27+(j-21)/9) + ',3))*1' + cll + '=m' + (26+(j-21)/9) + '+D' + (27+(j-21)/9) + '-E' + (27+(j-21)/9) + nd

var x=9}}

document.route.totaltime.value=Math.round(document.route.totaltime.value)

message += '<tr border=1><td colspan=3 align=right>Totals: ' +cllc + '=sum(D28:D' + (27+noofpoints*1) + ')' + cllc + '=sum(E28:E' + (27+noofpoints*1) + ')' + cllc + 'XXX' + cllc + '=sum(G28:G' + (27+noofpoints*1) + ')' + cllc+ 'XXX' +cllc + '=sum(I28:I' + (27+noofpoints*1) + ')' + cllc + '=TIME(HOUR(J27),MINUTE(J27)+INT(I' + (28+noofpoints*1) + '),SECOND((I' + (28+noofpoints*1) + '-INT(I' + (28+noofpoints*1) + '))*60))' + nd

message +='<tr><td colspan=3 align=right>Distances vary by </td><td>' + document.route.wiggle.value + '</td><td colspan=6 align=left>% from a straight line</td>' + nd

message +='<tr><td colspan=3 align=right>Steep downhill - more than </td><td>'  + document.route.steep.value +  '</td><td colspan=6 align=left>m down per 100m take longer</td>' + nd

message +='<tr><td colspan=10 align=left>Magnetic Variation: The difference between Magnetic North and Grid North. For your expedition date, this is estimated as ' + document.route.magnetic.value;
message += '<LIli><sup>o</sup>' + nt

+ '</ULul>';
DispWin.document.write(message);}
