

function addLoadEvent(func)
{
  // Script by Simon Willison
  // http:simon.incutio.com/
  
  var oldonload = window.onload;
  if (typeof window.onload != 'function')
  {
    window.onload = func;
  }
  else
  {
    window.onload = function()
    {
      oldonload();
      func();
    }
  }
}



// function from Dates
// Copyright 2006 Professional Website Design.
// For other useful scripts and tutorials, see
// http://www.professorscodingcorner.com/
// You may use or modify the script in any way
// you want, but do not remove the first four
// lines above. Although it's not required, I
// would appreciate an email to let me know
// the URL of the page where are using it.

function currentYear()
{
  if (!document.getElementById("currentYear")) return false;
  var obj = document.getElementById("currentYear");
  var today = new Date();
  var year = today.getFullYear();
  var txt = document.createTextNode(year);
  obj.appendChild(txt);
}



function mailTo()
{
  // Copyright 2006 Professional Website Design.
  // For other useful scripts and tutorials, see
  // http://www.professorscodingcorner.com/
  // You may use or modify the script in any way
  // you want, but do not remove the first three
  // lines above. Although it's not required, I
  // would appreciate an email to let me know
  // the URL of the page where you used it.
  //
  // Modified June 24, 2007.
  // Can now have more than one email link on a
  // page. Uses Class instead of Id. Now the 
  // containing element MUST be a span.

  if (!document.getElementsByTagName("span")) return false;
  var spans = document.getElementsByTagName("span");
  for (var i=0; i<spans.length; i++)
    {
      if (spans[i].className == "mailTo")
        {
          var anch = document.createElement("a");
          var email = "contact@your-homeremedies.com";
          var mailto = "mailto:" + email;
          anch.setAttribute("href",mailto);
          spans[i].appendChild(anch);
          var txt = document.createTextNode(email);
          anch.appendChild(txt);
        }
    }
  return true;
}



// Popup Script
// Copyright 2006 Professional Website Design
// professorscodingcorner.com
// Script inspired by William Bontrager,
// willmaster.com, January 29,2001
// Extensively modified by the Professor June 22, 2008
// to be used offpage, and to handle multiple anchors

function showPopup(whichanchor) 
{
  var URL = whichanchor.getAttribute("href");
  var POPUP = window.open(URL,'popup','width=600,height=300,left=0,top=30,scrollbars=1,resizable=1');
  POPUP.focus();
  return false;
}

function Popup()
{
  if (!document.getElementsByTagName) return false;
  var anchor = document.getElementsByTagName("a");
  for (var k=0; k<anchor.length; k++)
  {
    if (anchor[k].className == "pop")
    {
      anchor[k].onclick = function()
      { showPopup(this); return false; }
    }
  }
  return true;
}



// Mini-Quiz
// Coyright 2008 Professional Website Design.

function setVisibility(id, visibility)
{
  document.getElementById(id).style.display = visibility;
}

function validate(cor)
{
  if (cor.checked )
    {
      setVisibility('sub1', 'inline');
      setVisibility('sub2', 'none');
    }
  else
    {
      setVisibility('sub2', 'inline');
      setVisibility('sub1', 'none');
    }
}

function erase()
{
  setVisibility('sub1', 'none');
  setVisibility('sub2', 'none');
}

function miniquiz()
{
  if (!document.getElementById) return false;
  if (!document.getElementById("correct")) return false;
  var correct = document.getElementById("correct").value;
  var quiz = document.getElementById("quiz");
  var inputs = quiz.getElementsByTagName("input");
  for ( var i=0; i < inputs.length; i++)
    {
      inputs[i].onclick = function()
        {
          erase();
          return true;
        }
    }
  var sbmt = document.getElementById("quizsubmit");
  var corans = inputs[correct - 1];
  sbmt.onclick = function() 
    {
      validate(corans);
      return false;
    }
}



// Overlay Box, v1.2
// Copyright 2006 Professional Website Design.
// For other useful scripts and tutorials, see
// http://www.professorscodingcorner.com/
// Modified 5/9/06: use ANY tag for the link
// to show the box, not just a button tag.
// Modified 7/26/06: cleaned up the coding to
// eliminate Javascript warnings
// You may use or modify the script in any way
// you want, but do not remove the first four
// lines above. Although it's not required, I
// would appreciate an email to let me know
// the URL of the page where are using it.

function showBox(whichelement)
{
  if (!whichelement.nextSibling) return false;
  
  // Find the box located (in the HTML) just below 
  // the button clicked, and make it visible.
  var box = null;
  var nsib = whichelement.nextSibling;
  for (var i=0; i<3; i++)
  {
    if ((nsib.className) && (nsib.className == "box"))
    { box = nsib; }
    if (box || !nsib.nextSibling) break;
    nsib = nsib.nextSibling;
  }
  if (!box) return false;
  box.style.visibility = "visible";
  return true;
}

function hideBox(whichanchor)
{
  // Find the box located (in the HTML) just above
  // the anchor clicked, and hide it.
  var box = null;
  var par = whichanchor.parentNode;
  for (var j=0; j<3; j++)
  {
    if (par.className == "box")
    { box = par; }
    if (box) break;
    par = par.parentNode;
  }
  if (!box) return false;
  box.style.visibility = "hidden";
  return true;
}

function Overlay()
{
  if (!document.getElementsByTagName) return false;
  if (!document.getElementsByTagName("a")) return false;
  
  // Show box
  var el = document.getElementsByTagName("*");
  for (var i=0; i<el.length; i++)
  {
    if (el[i].className == "show")
    {
      el[i].onclick = function()
      { showBox(this); return; }
    }
  } 
  
  // Hide box
  var anchor = document.getElementsByTagName("a");
  for (var j=0; j<anchor.length; j++)
  {
    if (anchor[j].className == "hide")
    {
      anchor[j].onclick = function()
      { hideBox(this); return false;}
    }
  }
  return true;
} 



var count = 0;
function submitForm()
{
  // Submit Form
  // Copyright 2006 Professional Website Design.
  // For other useful scripts and tutorials, see
  // http://www.professorscodingcorner.com/
  // You may use or modify the script in any way
  // you want, but do not remove the first three
  // lines above. Although it's not required, I
  // would appreciate an email to let me know
  // the URL of the page where are using it.

  if (!document.getElementById) return false;
  var sub = document.getElementById("submit");
  var form = document.getElementById("form");
  var val = sub.getAttribute("value");
  sub.onclick = function()
  {
    var email = document.getElementById("email");
    if (email.value.length < 6)
    {
      alert("You forgot to enter your email address.");
      return false;
    }
    if (count == 0)
    {
      count++;
      var url = "http://www.tropicalhouseplants.net/cgi-bin/subscribe.cgi";
      form.setAttribute("action",url);
      sub.setAttribute("value","Please Wait");
      sub.style.backgroundColor = "#F00";
      form.submit;
      return;
    }
    return false;
  }
  return true;
}



// New-Window Links in a Standards-Compliant World
// by Kevin Yank
// Copyright 2003 Sitepoint

function externalLinks() {
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     anchor.target = "_blank"; 
 } 
} 


addLoadEvent(externalLinks);
addLoadEvent(submitForm);
//addLoadEvent(currentYear);
//addLoadEvent(mailTo);
//addLoadEvent(Popup);
//addLoadEvent(miniquiz);
//addLoadEvent(Overlay);


