﻿function externallinks()
{
  var ls=document.getElementsByTagName('a');
  for(var i=0;i<ls.length;i++)
  {
    if(ls[i].getAttribute('rel')=='external')
    {
      ls[i].target='_blank';
    }
  }
}

window.onload=function(){
    if(!document.getElementById && !document.createTextNode){return;}
    externallinks();
}


function getValue(varname)
{
  var url    = "";
  var qparts = "";
  var query  = "";
  var vars   = "";
  var value  = "";

  // First, we load the URL into a variable
  url = window.location.href;

  if(url.indexOf('?') == -1)
  {
    return "END";
  }

  // Next, split the url by the ?
  qparts = url.split("?");
 
  // Check that there is a querystring, return "" if not
  if (qparts[1] == "")
  {
    return "END";
  }
  else
  {
    // Then find the querystring, everything after the ?
    query = qparts[1];

    // Split the query string into variables (separates by &s)
    vars = query.split("&");

    // Initialize the value with "" as default

    // Iterate through vars, checking each one for varname
    for (i=0;i<vars.length;i++)
    {
      // Split the variable by =, which splits name and value
      var parts = vars[i].split("=");

      // Check if the correct variable
      if (parts[0] == varname)
      {
        // Load value into variable
        value = parts[1];

        // End the loop
        break;
      }
    }

    // Convert escape code
    value = unescape(value);

    // Convert "+"s to " "s
    value.replace(/\+/g," ");

    // Return the value
    return value;
  }
  return "END";
}

function pCPrintView(varnum)
{
  var directorsVal  = "";
  var turnoverVal   = "";

  directorsVal = getValue("directors");
  turnoverVal = getValue("turnover");
  
  if((directorsVal != "END") && (turnoverVal != "END"))
  {
    if(varnum=="1")
    {
      window.location="../print_views/price_calculator.html?directors="+directorsVal+"&turnover="+turnoverVal;
    }
    else
    {
      window.location="../site_source/price_calculator.html?directors="+directorsVal+"&turnover="+turnoverVal;
    }
  }
  else
  {
    if(varnum=="1")
    {
      window.location="../print_views/price_calculator.html";
    }
    else
    {
      window.location="../site_source/price_calculator.html";
    }
  }
}