// main.js

function up( aHref)
{
  
  window.open( aHref + '/up', 'PopUpWindow',
               'left=12, top=12, width=570, height=660, scrollbars=yes');
  return( false); // <--important!
}

function changeProdQty( qty)
{
  var elA= document.getElementById( "lnkBuyOne");

  if( elA)
  {
    var pos= elA.href.indexOf( "=");
    if( pos == -1)
      elA.href= elA.href + "=" + qty
    else
      elA.href= elA.href.substr( 0, pos + 1) + qty;

    elA.title= "Click to buy " + qty + elA.title.substr( elA.title.indexOf( "x"));
  }
}

function inpRegisterFormEvents()
{
  //
  // Called once all the form fields have been loaded.
  //
  // And yes, there is a better way to do this.
  // I'm just too f**king lazy now.
  //

  //
  // The following are *not* events, just default values:
  //

  if( document.URL.indexOf( "/talkback/new") > -1)
  {
    if( document.getElementById( "inpINPUTone"))
    {
      if( document.getElementById( "inpINPUTone").value == "") {
        document.getElementById( "inpINPUTone").style.color= "#999";
        document.getElementById( "inpINPUTone").value= "No title";
      }
    }
  
    //
    // document.getElementById( "inpINPUTtwo") is <TEXTAREA>,
    // no default value
    //
  
    if( document.getElementById( "inpINPUTthree"))
    {
      if( document.getElementById( "inpINPUTthree").value == "") {
        document.getElementById( "inpINPUTthree").style.color= "#999";
        document.getElementById( "inpINPUTthree").value= "none";
      }
    }

    if( document.getElementById( "inpINPUTfour"))
    {
      if( document.getElementById( "inpINPUTfour").value == "") {
        document.getElementById( "inpINPUTfour").style.color= "#999";
        document.getElementById( "inpINPUTfour").value= "Anonymous";
      }
    }

    if( document.getElementById( "inpINPUTfive"))
    {
      if( document.getElementById( "inpINPUTfive").value == "") {
        document.getElementById( "inpINPUTfive").style.color= "#999";
        document.getElementById( "inpINPUTfive").value= "Undisclosed location";
      }
    }

  } // end if( document.URL.indexOf( "/talkback/new") > -1)

  //
  // <TR> events:
  //

  if( document.getElementById( "inpTRone"))
  {
    document.getElementById( "inpTRone").onmouseover=
      function() { document.getElementById( "inpTRone").style.backgroundColor="#eee"; }
    document.getElementById( "inpTRone").onmouseout=
      function() { document.getElementById( "inpTRone").style.backgroundColor="#fff"; }
  }

  if( document.getElementById( "inpTRtwo"))
  {
    document.getElementById( "inpTRtwo").onmouseover=
      function() { document.getElementById( "inpTRtwo").style.backgroundColor="#eee"; }
    document.getElementById( "inpTRtwo").onmouseout=
      function() { document.getElementById( "inpTRtwo").style.backgroundColor="#fff"; }
  }

  if( document.getElementById( "inpTRthree"))
  {
    document.getElementById( "inpTRthree").onmouseover=
      function() { document.getElementById( "inpTRthree").style.backgroundColor="#eee"; }
    document.getElementById( "inpTRthree").onmouseout=
      function() { document.getElementById( "inpTRthree").style.backgroundColor="#fff"; }
  }

  if( document.getElementById( "inpTRfour"))
  {
    document.getElementById( "inpTRfour").onmouseover=
      function() { document.getElementById( "inpTRfour").style.backgroundColor="#eee"; }
    document.getElementById( "inpTRfour").onmouseout=
      function() { document.getElementById( "inpTRfour").style.backgroundColor="#fff"; }
  }

  if( document.getElementById( "inpTRfive"))
  {
    document.getElementById( "inpTRfive").onmouseover=
      function() { document.getElementById( "inpTRfive").style.backgroundColor="#eee"; }
    document.getElementById( "inpTRfive").onmouseout=
      function() { document.getElementById( "inpTRfive").style.backgroundColor="#fff"; }
  }

  //
  // <INPUT> events:
  //

  if( document.getElementById( "inpINPUTone"))
  {
    document.getElementById( "inpINPUTone").onfocus= function() {
      document.getElementById( "inpTRone").style.backgroundColor="#eee";
      document.getElementById( "inpINPUTone").style.color= "#000";
      if( document.URL.indexOf( "/talkback/new") > -1)
        if( document.getElementById( "inpINPUTone").value == "No title")
          document.getElementById( "inpINPUTone").value= "";
    }
    document.getElementById( "inpINPUTone").onblur= function() {
      document.getElementById( "inpTRone").style.backgroundColor="#fff";
      if( document.URL.indexOf( "/talkback/new") > -1)
        if( document.getElementById( "inpINPUTone").value == "") {
          document.getElementById( "inpINPUTone").style.color= "#999";
          document.getElementById( "inpINPUTone").value= "No title";
        }
    }
  }

  if( document.getElementById( "inpINPUTtwo"))
  {
    document.getElementById( "inpINPUTtwo").onfocus= function() {
      document.getElementById( "inpTRtwo").style.backgroundColor="#eee";
    }
    document.getElementById( "inpINPUTtwo").onblur= function() {
      document.getElementById( "inpTRtwo").style.backgroundColor="#fff";
    }
  }

  if( document.getElementById( "inpINPUTthree"))
  {
    document.getElementById( "inpINPUTthree").onfocus= function() {
      document.getElementById( "inpTRthree").style.backgroundColor="#eee";
      document.getElementById( "inpINPUTthree").style.color= "#000";
      if( document.URL.indexOf( "/talkback/new") > -1)
        if( document.getElementById( "inpINPUTthree").value == "none")
          document.getElementById( "inpINPUTthree").value= "";
    }
    document.getElementById( "inpINPUTthree").onblur= function() {
      document.getElementById( "inpTRthree").style.backgroundColor="#fff";
      if( document.URL.indexOf( "/talkback/new") > -1)
        if( document.getElementById( "inpINPUTthree").value == "") {
          document.getElementById( "inpINPUTthree").style.color= "#999";
          document.getElementById( "inpINPUTthree").value= "none";
        }
    }
  }

  if( document.getElementById( "inpINPUTfour"))
  {
    document.getElementById( "inpINPUTfour").onfocus= function() {
      document.getElementById( "inpTRfour").style.backgroundColor="#eee";
      document.getElementById( "inpINPUTfour").style.color= "#000";
      if( document.URL.indexOf( "/talkback/new") > -1)
        if( document.getElementById( "inpINPUTfour").value == "Anonymous")
          document.getElementById( "inpINPUTfour").value= "";
    }
    document.getElementById( "inpINPUTfour").onblur= function() {
      document.getElementById( "inpTRfour").style.backgroundColor="#fff";
      if( document.URL.indexOf( "/talkback/new") > -1)
        if( document.getElementById( "inpINPUTfour").value == "") {
          document.getElementById( "inpINPUTfour").style.color= "#999";
          document.getElementById( "inpINPUTfour").value= "Anonymous";
        }
    }
  }

  if( document.getElementById( "inpINPUTfive"))
  {
    document.getElementById( "inpINPUTfive").onfocus= function() {
      document.getElementById( "inpTRfive").style.backgroundColor="#eee";
      document.getElementById( "inpINPUTfive").style.color= "#000";
      if( document.URL.indexOf( "/talkback/new") > -1)
        if( document.getElementById( "inpINPUTfive").value == "Undisclosed location")
          document.getElementById( "inpINPUTfive").value= "";
    }
    document.getElementById( "inpINPUTfive").onblur= function() {
      document.getElementById( "inpTRfive").style.backgroundColor="#fff";
      if( document.URL.indexOf( "/talkback/new") > -1)
        if( document.getElementById( "inpINPUTfive").value == "") {
          document.getElementById( "inpINPUTfive").style.color= "#999";
          document.getElementById( "inpINPUTfive").value= "Undisclosed location";
        }
    }
  }

} // end function inpRegisterFormEvents()

var ec= 0; // <--global & important!

function inpCheckTextareaScroll()
{
  // Must set <textarea id="inpINPUTtwo" style="height: 160px" ...> in HTML
  var elTextarea= document.getElementById( "inpINPUTtwo");
  if( elTextarea)
  {
    if ( elTextarea.scrollTop > 0 ) { ec++; elTextarea.style.height= ( 160+(ec*80+9-ec) ) + "px"; }
    if ( ( (ec < 4) && (window.screen.height >= 760) ) || (ec < 3) ) { setTimeout( "inpCheckTextareaScroll()", 200); }
  }
}

function inpSubmitForm()
{
  var notEnteredWhat= "message";

  if( document.getElementById( "inpINPUTtwo"))
    if( document.getElementById( "inpINPUTtwo").value == "") {
      document.getElementById( "inpTRtwo").style.backgroundColor= "#ff6";
      if( document.URL.indexOf( "/talkback/new") > -1)
        notEnteredWhat= "comment";
      alert( "You have not entered any " + notEnteredWhat + "!");
      document.getElementById( "inpTRtwo").style.backgroundColor= "#fff";
      return( false);
    }

  if( document.URL.indexOf( "/talkback/new") > -1)
  {
    if( document.getElementById( "inpINPUTone"))
      if( document.getElementById( "inpINPUTone").value == "No title")
        document.getElementById( "inpINPUTone").value= "";
  
    if( document.getElementById( "inpINPUTthree"))
      if( document.getElementById( "inpINPUTthree").value == "none")
        document.getElementById( "inpINPUTthree").value= "";
  
    if( document.getElementById( "inpINPUTfour"))
      if( document.getElementById( "inpINPUTfour").value == "Anonymous")
        document.getElementById( "inpINPUTfour").value= "";
  
    if( document.getElementById( "inpINPUTfive"))
      if( document.getElementById( "inpINPUTfive").value == "Undisclosed location")
        document.getElementById( "inpINPUTfive").value= "";
  }
  
  return( true);
}

function phone()
{
  document.write(
      "\n" + '<h4>Prefer to pick up the phone<i>?</i></h4>'
    + "\n" + '<p>Customer care is available through support lines in:</p>'
    + "\n" + '<p><img src="/img/phone.gif" style="float: left; margin-right: 11px; position: relative; top: -3px"><span>UK</span> +44-1' + '31-20' + '8-3' + '550<br>'
    + "\n" + '<span>USA</span> +1-9' + '78-63' + '3-7' + '550</p>'
    + "\n"
  );
}

