// JavaScript Document
function img_background ( mode )
{
  // Based on what button the user clicks, this will save a cookie,
  // and change the CSS background style for the body tag
  // Everytime a page is loaded img_check_background() is called to
  // see what cookie is saved if any, and select the right CSS background style
  
  var docstring = document.body;
  
  if ( docstring )
  {
    if ( mode == 1 )
    {
      // change style
      docstring.style.background = "url(/images/0001.gif) #333C47 top left repeat-x";
    }
    
    if ( mode == 2 )
    {
      // change style
      docstring.style.background = "url(/images/0000.gif) #B2B3B4 top left repeat-x";
    }
    
    if ( mode )
    {
      // expire 30 days from now
      var expdate = new Date ();
      expdate.setTime ( expdate.getTime () + ( 1000 * 60 * 60 * 24 * 30 ) );
      
      // set cookie
      setCookie ( "background", mode, expdate );
    }
  }
}

function img_check_background ()
{
  // Called onload of the body tag
  // if the cookie is set from img_background
  // load up the proper CSS background style
  // otherwise skip this function until user has saved
  
  var mode = getCookie ( "background" );
  
  if ( mode )
  {
    img_background ( mode );
  }
}

function setCookie ( name, values, expires )
{
  // Universal set cookie script
  // checks the date first
  // deletes existing cookie
  // sets new cookie
  
  if ( !expires )
  {
    expires = new Date ();
  }
  
  delCookie ( name );
  
  document.cookie = name + "=" + escape ( values ) + "; expires=" + expires.toGMTString() + "; path=/";
}
function getCookie ( name )
{
  // call the cookie previously set based on the "name" value
  // submitted through the function
  
  var cookiestring  = document.cookie;
  var cookiename    = name + "=";
  var cookielength  = cookiestring.length;
  
  var cookiebegin    = 0;
  
  while ( cookiebegin < cookielength )
  {
    var vbegin = cookiebegin + cookiename.length;
    
    if ( cookiestring.substring ( cookiebegin, vbegin ) == cookiename )
    {
      var vend = cookiestring.indexOf ( ";", vbegin );
      
      if ( vend == -1 )
      {
        vend = cookielength;
      }
      
      return unescape ( cookiestring.substring ( vbegin, vend ) );
    }
    
    cookiebegin = cookiestring.indexOf ( " ", cookiebegin ) + 1;
    
    if ( cookiebegin == 0 )
    {
      break;
    }
  }
  
  return null;
}
function delCookie ( name )
{
  // Simple script to delete a cookie
  // sets time to Jan 1st, 1970, with no value
  
  document.cookie = name + "= ; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/";
}
function contact_options( divname )
{
  // Declare form name found on contact.tpl
  var formname = "form";
  
  var formstring  = document.forms[formname];
  
  if ( formstring )
  {
    if ( divname )
    {
      if ( divname == "option1" )
      {
        means = "Sales And Quotes";
        
        document.getElementById( 'option1' ).innerHTML = "<span style=\"font-weight: bold; color: #5FC6F4;\">" + means + "</span>";
        document.getElementById( 'option2' ).innerHTML = "<a href=\"javascript:;\" onclick=\"contact_options( 'option2' )\">Information Request</a>";
        document.getElementById( 'option3' ).innerHTML = "<a href=\"javascript:;\" onclick=\"contact_options( 'option3' )\">Job Opportunities</a>";
        document.getElementById( 'option4' ).innerHTML = "<a href=\"javascript:;\" onclick=\"contact_options( 'option4' )\">Executive Help Request</a>";
        
        document.getElementById( 'contact-organization-change' ).innerHTML = "Organization Name";
      }
      if ( divname == "option2" )
      {
        means = "Information Request";
        
        document.getElementById( 'option1' ).innerHTML = "<a href=\"javascript:;\" onclick=\"contact_options( 'option1' )\">Sales And Quotes</a>";
        document.getElementById( 'option2' ).innerHTML = "<span style=\"font-weight: bold; color: #5FC6F4;\">" + means + "</span>";
        document.getElementById( 'option3' ).innerHTML = "<a href=\"javascript:;\" onclick=\"contact_options( 'option3' )\">Job Opportunities</a>";
        document.getElementById( 'option4' ).innerHTML = "<a href=\"javascript:;\" onclick=\"contact_options( 'option4' )\">Executive Help Request</a>";
      
        document.getElementById( 'contact-organization-change' ).innerHTML = "Organization Name";
      }
      if ( divname == "option3" )
      {
        means = "Job Opportunities";
        
        document.getElementById( 'option1' ).innerHTML = "<a href=\"javascript:;\" onclick=\"contact_options( 'option1' )\">Sales And Quotes</a>";
        document.getElementById( 'option2' ).innerHTML = "<a href=\"javascript:;\" onclick=\"contact_options( 'option2' )\">Information Request</a>";
        document.getElementById( 'option3' ).innerHTML = "<span style=\"font-weight: bold; color: #5FC6F4;\">" + means + "</span>";
        document.getElementById( 'option4' ).innerHTML = "<a href=\"javascript:;\" onclick=\"contact_options( 'option4' )\">Executive Help Request</a>";
      
        document.getElementById( 'contact-organization-change' ).innerHTML = "Job Position";
      }
      if ( divname == "option4" )
      {
        means = "Executive Help Request";
        
        document.getElementById( 'option1' ).innerHTML = "<a href=\"javascript:;\" onclick=\"contact_options( 'option1' )\">Sales And Quotes</a>";
        document.getElementById( 'option2' ).innerHTML = "<a href=\"javascript:;\" onclick=\"contact_options( 'option2' )\">Information Request</a>";
        document.getElementById( 'option3' ).innerHTML = "<a href=\"javascript:;\" onclick=\"contact_options( 'option3' )\">Job Opportunities</a>";
        document.getElementById( 'option4' ).innerHTML = "<span style=\"font-weight: bold; color: #5FC6F4;\">" + means + "</span>";
      
        document.getElementById( 'contact-organization-change' ).innerHTML = "Organization Name";
      }
      
      formstring.elements['means'].value = means;
    }
  }
}
function contact_submit()
{
  // Declare form name found on contact.tpl
  var formname = "form";
  
  var formstring  = document.forms[formname];
  
  if ( formstring )
  {
    if ( formstring.elements['means'].value == "" )
    {
      alert ("Please ensure you have selected a Means Of Contact.");
    }
  }
}

