/** Copyright (C) 2002 Dan Heuston. **/

/** All rights reserved.            **/





/* Define global variables */

weightunits = new String

capacityunits = new String

dimunits = new String







/** Set all radio-buttons to either metric or imperial units **/

function resetUnits(formname, type) {



 if(type == "metric") {

  formname.weight[0].checked=true

  formname.dimensions[0].checked=true 

  formname.capacity[0].checked=true  

 }



 if(type == "imperial") {

  formname.weight[1].checked=true

  formname.dimensions[0].checked=true 

  formname.capacity[1].checked=true  

 }

 

 saveUnits(formname)

}







/** Save users selections in cookies, update the parent window and close **/

function saveUnits(thisForm) {



 if(thisForm.weight[0].checked==true) weightunits="kg" 

 if(thisForm.weight[1].checked==true) weightunits="tons"



 if(thisForm.dimensions[0].checked==true) dimunits="mm"

 if(thisForm.dimensions[1].checked==true) dimunits="m"

 if(thisForm.dimensions[2].checked==true) dimunits="ft" 

 

 if(thisForm.capacity[0].checked==true) capacityunits="litres"

 if(thisForm.capacity[1].checked==true) capacityunits="gals" 



 setCookie("ckunitsweight", weightunits, "long")

 setCookie("ckunitsdimensions", dimunits, "long")

 setCookie("ckunitscapacity", capacityunits, "long")





 /* Refresh the parent page*/ 

 refreshhref = opener.location.href



 if(refreshhref.indexOf("#") != -1) {

  temp = refreshhref

  refreshhref = temp.substring(0, temp.indexOf("#"))

 }

 

 opener.location = refreshhref

 window.close()

}







/* Retrieves the units of measurements and sets the radio buttons appropriately. */

function setUnits(thisForm) {



 getUnits()

 

 if(weightunits=="kg") thisForm.weight[0].checked=true

 if(weightunits=="tons") thisForm.weight[1].checked=true



 if(dimunits=="mm") thisForm.dimensions[0].checked=true

 if(dimunits=="m") thisForm.dimensions[1].checked=true

 if(dimunits=="ft") thisForm.dimensions[2].checked=true

 

 if(capacityunits=="litres") thisForm.capacity[0].checked=true

 if(capacityunits=="gals") thisForm.capacity[1].checked=true

}









function getUnits() {



 weightunits = getCookie("ckunitsweight")

 if(weightunits == "") weightunits = "kg"



 capacityunits = getCookie("ckunitscapacity")

 if(capacityunits == "") capacityunits = "litres"

 

 dimunits = getCookie("ckunitsdimensions")

 if(dimunits == "") dimunits = "mm"



}







function getWeight(thisvalue) {



 if(weightunits == "tons") {



   thisvalue = thisvalue * 0.0009842

   temp = thisvalue*100

   thisvalue = (Math.round(temp))/100

 }

 

 return thisvalue

}







function getCapacity(thisvalue) {



 if(capacityunits == "gals") {



   thisvalue = thisvalue * 0.2199

   temp = thisvalue*100

   thisvalue = (Math.round(temp))/100

 }

 

 return thisvalue

}







function getDimensions(thisdim) {



 var buffer = new String



 if(dimunits == "ft") factor = 0.003281

 else if(dimunits == "m") factor = 0.001

 else factor = 1



 for(g=0; g < thisdim.length; g++) {



   thisdim[g] = thisdim[g] * factor

   temp = thisdim[g]*100

   thisdim[g] = (Math.round(temp))/100

 }

 

 buffer = thisdim[0] + " x " + thisdim[1] + " x " + thisdim[2] + " " + dimunits

 return buffer

}







function openUnits() {



 winWidth  = 550

 winHeight = 185

 winparams = "scrollbars=yes, menubar=no, width=" + winWidth + ", height=" + winHeight + ", resizable=yes, left=0, top=0, status=no"



 unitWin = window.open("units.htm", "unitWin", winparams)

 unitWin.focus()

 

}







function getProductType(cookiename) {



 /* Firstly, we look to the URL for the product type */

 params = getParam(this.location.href)



 /* There are no params in the URL (i.e. no trailer.htm?something) we get it from the cookie. */

 if(params == "") {

  params = getCookie(cookiename)



  if(params == "") {

   params = "nochoice"

  } 

 }



 /* A little Netscape code to make sure we do not have any #something cookies stored */

 ishash = params.indexOf("#")

 if(ishash != -1) {

  params = params.substring(0, ishash)

 }



 return params

}









/* Displays the fast path links for the trailers or roofboxes */

function displayFastPaths(productarray, producttype) {



 type=0

 manu=1

 model=2



 if(producttype != "nochoice") {

  document.write("<div class='fastpaths'")

  document.write("<p><b><br>Available Products:<\/b><\/p>")

  document.write("<ul>")

  for(i=1; i < productarray.length; i++) {

   if(productarray[i][type].indexOf(producttype) != -1 || producttype == "All") {

    document.write("<li><a href='#" + productarray[i][manu] + productarray[i][model] + "' title='Click here to view details of this trailer.'>" + productarray[i][manu] + " " + productarray[i][model] + "<\/a><br>")

   }

  }

  document.write("<\/ul><\/div>")

 }

} 







function setParent(ref) {



 opener.location.href=ref

 opener.focus()

}







function openComparisons(product, productref, producttype) {



 winWidth  = 600

 winHeight = 400

 winparams = "scrollbars=yes, menubar=no, width=" + winWidth + ", height=" + winHeight + ", resizable=yes, left=0, top=0, status=no"



 compWin = window.open("comparison.htm?" + product + "=" + productref + "&" + producttype, product, winparams)

 compWin.focus()

 

}







function showComparison() {



 var productarray = new Array

 var prtype = new String

 manu = 1

 model = 2

 

 /* First we get the parameter from the URL, and separate out the selected trailer and the trailer type to view */ 

 currentparam = getParam(this.location.href)

 eqpos = currentparam.indexOf('=')

 product = currentparam.substring(0, eqpos)

 

 ref = currentparam.indexOf('&')

 producttype = currentparam.substring(ref+1, currentparam.length)

 selected = currentparam.substring(eqpos+1, ref)



 /* Now draw the table and add the table headers. */

 document.write("<table cellspacing=0 cellpadding=10 width='100%' class='comparison'>")

 document.write("<tr valign=top align=center class='comp_hdr'>")

 

 if(product == trailers[0][0]) {

  productarray = trailers

  document.write("<td width=100>" + productarray[0][trmanu] + "/" + productarray[0][trmodel] + "<\/td><td>" + productarray[0][trbox] + "<\/td><td>" + productarray[0][trdim] + 

                 "<\/td><td>" + productarray[0][trcc] + "<\/td><td>" + productarray[0][trgc] + "<\/td><td>" + productarray[0][trwt])



  maxcount = trailerslen

  prtype = trtype

 }

 else if(product == roofbox[0][0]) {

  productarray = roofbox

  document.writeln("<td width=100>" + roofbox[0][rbmanu] + "/" + roofbox[0][rbmodel] + "<\/td><td>" + roofbox[0][rbls] + "<\/td><td>" + roofbox[0][rbdim] + 

                   "<\/td><td>" + roofbox[0][rbcc] + "<\/td><td>" + roofbox[0][rbweight])



  maxcount = roofboxlen 

  prtype = rbtype

 }

 

 getUnits()



 for(i=1; i < maxcount; i++) {

 

  if(productarray[i][prtype].indexOf(producttype) != -1 || producttype == "All") {

   productref = productarray[i][manu] + productarray[i][model]



   if(selected == i) {

    document.write("<tr valign=top align=center style='background-color: #C0C0C0; color: #000000'>")

	selected = productref

   }

   else if(i%2 == 0)

    document.write("<tr valign=top align=center>") 

   else

    document.write("<tr valign=top align=center style='background-color: #FFFFE0; color: #000000'>")  





   if(product == trailers[0][0]) {   

     document.write("<td><a name='"  + productref +  "'>&nbsp<\/a><a class='comp' href='javascript:setParent(\"trailers.htm#" + productref + "\")' title='Click here to switch the main page to view this trailer.'>")

     document.write(trailers[i][trmanu] + " " + trailers[i][trmodel] + "<\/a>")

	 document.write("<\/td>")

	 if(trailers[i][trbox] != "") { document.write("<td>" + trailers[i][trbox]) } else { document.write("<td>&nbsp;") } 

	 document.write("<\/td>")

	 if(trailers[i][trdim][0] != 0) { document.write("<td>" + getDimensions(trailers[i][trdim]) ) } else { document.write("<td>&nbsp;") }

	 document.write("<\/td>")

	 if(trailers[i][trcc] != 0) { document.write("<td>" + getWeight(trailers[i][trcc]) + " " + weightunits) } else { document.write("<td>&nbsp;") }

	 document.write("<\/td>")

	 if(trailers[i][trgc] != 0) { document.write("<td>" + getWeight(trailers[i][trgc]) + " " + weightunits) } else { document.write("<td>&nbsp;") }

	 document.write("<\/td>")

	 if(trailers[i][trwt] != "") { document.write("<td>" + trailers[i][trwt]) } else { document.write("<td>&nbsp;") }

	 document.write("<\/td>")

	}

	else {

     document.write("<td><a name='"  + productref +  "'>&nbsp;<\/a><a class='comp' href='javascript:setParent(\"roofboxes.htm#" + productref + "\")' title='Click here to switch the main page to view this roof box.'>")

     document.write(roofbox[i][rbmanu] + " " + roofbox[i][rbmodel] + "<\/a>")

	 document.write("<\/td>")	 

	 if(roofbox[i][rbls] != "") { document.write("<td>" + roofbox[i][rbls]) } else { document.write("<td>&nbsp;") }

	 document.write("<\/td>")	 

 	 if(roofbox[i][rbdim][0] != 0) { document.write("<td>" + getDimensions(roofbox[i][rbdim])) } else { document.write("<td>&nbsp;") }

	 document.write("<\/td>")	 

	 if(roofbox[i][rbcc] != 0) { document.write("<td>" + getCapacity(roofbox[i][rbcc]) + " " + capacityunits) } else { document.write("<td>&nbsp;") }

	 document.write("<\/td>")	 

	 if(roofbox[i][rbweight] != 0) { document.write("<td>" + getWeight(roofbox[i][rbweight]) + " " + weightunits) } else { document.write("<td>&nbsp;") }

	 document.write("<\/td>")	 

	}

   document.write("<\/tr>")

  }

 }



 document.write("<\/table>")

 stdFooter()

 self.location = "#" + selected

}









function openPrintwindow(product, productref) {



 winWidth  = 650

 winHeight = 500

 winparams = "scrollbars=yes, menubar=yes, location=yes, width=" + winWidth + ", height=" + winHeight + ", resizable=yes, left=0, top=0, status=no"



 printWin = window.open("print.htm?" + product + "=" + productref, "printWin", winparams)

 printWin.focus()

}







function printProduct() {



 /* Set limiter parameters to prevent the Prev and Next buttons */

 subsetTrailerslen=2

 subsetTrailers = ""

 

 /* Get the product type and reference from the address bar */

 buffer = getParam(this.location.href)

 eqpos = buffer.indexOf('=')

 product = buffer.substring(0, eqpos)

 productref = buffer.substring(eqpos+1, buffer.length)

 

 if(product == trailers[0][0]) {

  titlebar = picDir + "\/bTrailers.gif"

  productarray = trailers

 }

 else if(product == roofbox[0][0]) {

  titlebar = picDir + "\/bRoofBoxes.gif" 

  productarray = roofbox

 }



 if(navigator.appName == "Microsoft Internet Explorer")

  printheader.src = titlebar

 else

  document.printheader.src = titlebar

  

 getUnits()

 

 /* Now display the appropriate product */

 showProduct(productarray, productref, "All", "", 1, "print")

}





function displayProduct(productarray, cookiename) {



 var 

  subsetcount = 1

  subsetProduct = new Array

  subsetProduct[0] = productarray[0]

  

 /* First, get the product type */

 producttype = getProductType(cookiename)





 /* If there is no selection, just display the product home page */

 if(producttype == "nochoice") {

    summaryPage()

 }

 else {

  /* otherwise display the chosen product */

  document.writeln("<table border='0' width='100%' cellspacing='0' cellpadding='2'>")

  document.writeln("<tr valign=top><td width='25%'>")



   /* Show all the fast paths links in the left column. */

   displayFastPaths(productarray, producttype)

   document.writeln("<\/td><td width='75%'>")



   /* Build a subset array of all products matching the product type. */

   for(i=1; i < productarray.length; i++) {

    if(productarray[i][0].indexOf(producttype) != -1 || producttype == "All") {

     subsetProduct[subsetcount] = i

     subsetcount++

    }

   }



   document.write("<table width='100%' cellspacing=2 cellpadding=0 border=0><tr>")

   document.write("<td><p class='view' style='text-align: left'><a href='javascript:openUnits()'>Show metric/imperial<\/a><\/p><\/td>")

   document.write("<td><p class='view'>Current view: " + producttype + " -> " + (subsetProduct.length - 1) + " matches found<\/p><\/td>")

   document.write("<\/tr><\/table>")



   /* Set the global units variables to specify which measurements to display i.e. metric or imperial. */

   getUnits()





   /* Now loop through the subset array and display the products in detail. */

   for(i=1; i < subsetProduct.length; i++) {



    thisproduct = subsetProduct[i]

    if(productarray[thisproduct][0].indexOf(producttype) != -1 || producttype == "All") {

     showProduct(productarray, thisproduct, producttype, subsetProduct, i, "display")

    }

   }

 

  document.writeln("<\/td><\/table>")

 }

 setCookie(cookiename, producttype, "short") 

}







/* Displays trailer in formatted table. */

function showProduct(productarray, thisproduct, producttype, subsetProduct, subsetref, mode) {



  var type=0, manu=1, model=2

   

  if(productarray[0][0] == trailers[0][0]) {

   pic = trpic, info = trinfo, box = trbox, dim = trdim, cc = trcc, gc = trgc, wt = trwt, feat = trfeat, info = trinfo, cost = trcost

  }

  else if(productarray[0][0] == roofbox[0][0]) {

   pic = rbpic, info = rbinfo, box = rbls, dim = rbdim, cc = rbcc, gc = rbweight, wt = 0, feat = rbfeat, info = rbinfo, cost = rbcost

  }

   

  /* Set anchor */

  productref = productarray[thisproduct][manu] + productarray[thisproduct][model]

  document.write("<a name='" + productref + "'>&nbsp;<\/a>")  



  /* Set-up table */

  document.write("<table cellspacing=0 cellpadding=10 width='100%' class='bordered'>")

  document.write("<tr valign=top align=center><td rowspan=2 width=310><br>")

  

  /* Show photograph and display freeform information text. */

  document.write("<img class='whiteframe' src='" + picDir + "\/" + productarray[thisproduct][pic] + "' alt='[" + productarray[thisproduct][model] + " picture]' title=''><br>")

  document.write("<p>" + productarray[thisproduct][info] + "<\/p>")



  /* As long as we are not in print mode, display the buttons */

  if(mode != "print") {
   document.writeln("<a href='javascript:openComparisons(\"" + productarray[0][0] + "\", \"" + thisproduct + "\", \"" + producttype + "\")'><img src='" + picDir + "\/bCompare.gif' border=0 alt='[Compare]' title=''><\/a>")
  }

  document.write("<\/td>")

  

  document.write("<td width='*' style='background: #F0F0F0'><hr width='100%' size=2>")

  

  /* Draw out the title and add in the Prev & Next buttons */

  document.write("<table width='100%' cellspacing=0 cellpadding=0 border=0>")

  document.write("<tr valign=middle><td width='20%' align=left>")



  if(mode != "print" && subsetref != 1) {

    prevref = subsetProduct[subsetref-1]

    document.write("<a href='#" + productarray[prevref][manu] + productarray[prevref][model] + "'><img src='" + picDir + "\/LArrowB.gif' border=0 title='View previous'><\/a>")

  }

  else

   document.write("&nbsp;")



  document.write("<\/td><td width='60%'><p class='producttitle'>" + productarray[thisproduct][manu] + " " + productarray[thisproduct][model] + " ")



  document.write("<\/td><td width='20%' align=right>")



  if(mode != "print" && subsetref != (subsetProduct.length-1)) {

    nextref = subsetProduct[subsetref+1]

    document.write("<a href='#" + productarray[nextref][manu] + productarray[nextref][model] + "'><img src='" + picDir + "\/RArrowB.gif' border=0 title='View next'><\/a>")

  }

  else

   document.write("&nbsp;")



  document.write("<\/td><\/tr><\/table>") 





  /* Display the key details for the product */	 

  document.write("<p class='centered'>")



  if(productarray[thisproduct][box] != "") document.write("<b>" + productarray[thisproduct][box] + "<\/b>")

  if(productarray[thisproduct][box] != "" && productarray[thisproduct][dim][0] != 0) document.write(" : ")

  if(productarray[thisproduct][dim][0] != 0) document.write(getDimensions(productarray[thisproduct][dim]))



  document.write("<br>")



  if(productarray[thisproduct][cc] != 0) document.write("<b>" + productarray[0][cc]  + "<\/b> : ")

  if(productarray[0][0] == trailers[0][0])

   document.write(getWeight(productarray[thisproduct][cc])  + " " + weightunits + "<br>") 

  else 

   document.write(getCapacity(productarray[thisproduct][cc])  + " " + capacityunits + "<br>")



  if(productarray[thisproduct][gc] != 0) document.write("<b>" + productarray[0][gc]  + "<\/b> : " + getWeight(productarray[thisproduct][gc])  + " " + weightunits + "<br>")  



  if(productarray[0][0] == trailers[0][0] && productarray[thisproduct][wt] != "") 

   document.write("<b>" + productarray[0][wt]  + " : <\/b>" + productarray[thisproduct][wt]  + "<\/p>")  


  if(productarray[0][0] == roofbox[0][0])
    document.write("<p class='productemph'>" + productarray[thisproduct][cost] + "<\/p>")

  if(mode != "print") {

   document.write("<br><a href='contactus.htm?" + productarray[0][0] + "=" + thisproduct + "'><img src='" + picDir + "\/bEnquiry.gif' border=0 alt='[Enquiry]' title=''><\/a>")

   if(productarray[thisproduct][type].indexOf("Hire") != -1) {
    document.write("<br><a href='trailerhire.htm#" + productref + "' title='Click here to enquire about hiring this product.'><img src='" + picDir + "\/bHireIt.gif' border=0 alt='[Hire this product]' title=''><\/a>")
   }    

  }

   

  /* Display all the features, providing some have been loaded! */

  if(productarray[thisproduct][feat][0] != "") {

   document.write("<tr><td style='background: #F0F0F0'>")

   document.write("<p class='productemph'>" + productarray[0][feat] + ":<\/p>")

   document.write("<ul>")

   for(j=0; j < productarray[thisproduct][feat].length; j++) {

    document.write("<li>" + productarray[thisproduct][feat][j] + "<br>")

   }

   document.write("<\/ul>")

  }



  /* Display the Print button, as long as we are not already in the print window. */

  if(mode != "print")

   document.write("<p class='smallprint' style='text-align: right'><a href='javascript:openPrintwindow(\"" + productarray[0][0] + "\", " + thisproduct + ")'>Print<\/a><\/p>")



  document.write("<hr width='100%' size=2>")

  document.write("<\/td><\/tr><\/table><br><br>")

}

