﻿function ShowDiv(divID)
{
    //alert('Show - Finding div...');
    var div = document.getElementById(divID);
    if (!div)
        return;

    //alert('Show - Found div...');
    div.style.visibility = 'visible';
}

function HideDiv(divID)
{
    //alert('Hide - Finding div...');
    var div = document.getElementById(divID);
    if (!div)
        return;

    //alert('Hide - Found div...');
    div.style.visibility = 'hidden';
}

function CloseDiv(divID)
{
  // Mark as blurred
    eval('window.focus_' + divID + ' = false;');
  
  // Close popup  
  HideDiv(divID);
}

function FocusDiv(divID)
{
    // Mark as focused
    eval('window.focus_' + divID + ' = true;');

    // Show popup
    ShowDiv(divID);
}

function ShowHideDiv(divID)
{
    var div = document.getElementById(divID);
    if (!div)
        return;

    if(div.style.visibility == 'hidden')
    {
      FocusDiv(divID);
    }
    else if(div.style.visibility == 'visible')
    {
      CloseDiv(divID);
    }
}

function DivBlock(divID)
{
    //alert('Show - Finding div...');
    var div = document.getElementById(divID);
    if (!div)
        return;

    //alert(div.style.display);
    div.style.display = 'block';
    //alert(div.style.display);
}

function DivNone(divID)
{
    //alert('Hide - Finding div...');
    var div = document.getElementById(divID);
    if (!div)
        return;

    //alert(div.style.display);
    div.style.display = 'none';
    //alert(div.style.display);
}

function ToggleHeaderClass(spanID)
{
    var span = document.getElementById(spanID);
    if (!span)
        return;

    if(span.className == 'crumbActive')
    {
      span.className = '';
    }
    else if(span.className == '')
    {
      span.className = 'crumbActive';
    }
}

function showspan(spanID)
{
  var srcElement = document.getElementById(spanID);

  if(srcElement != null)
  {
    if(srcElement.style.display == "none")
    {
       srcElement.style.display= 'inline';
    }
  }
}

function hidespan(spanID)
{
  var srcElement = document.getElementById(spanID);

  if(srcElement != null)
  {
    if(srcElement.style.display == "inline")
    {
       srcElement.style.display= 'none';
    }
  }
}

function ToggleSearchLetterClass(linkID)
{
    var children = document.getElementById('SearchLetters').getElementsByTagName('a');
    for(var i=0; i<children.length; i++)
    {
      children[i].className = 'crumbLink';
    }

    var link = document.getElementById(linkID);
    if (!link)
        return;

    link.className = 'crumbActive';
}

// Search Box
function searchFocus(box, text)
{
    if (box.value == text)
    {
        box.value = '';
    }
}

function searchBlur(box, text)
{
    if (box.value == '')
    {
        box.value = text;
    }
}

// Contact Us form
function ValidateContactForm()
{
  // Reset the form
  hidespan('FirstNameError');
  hidespan('LastNameError');
  hidespan('StateError');
  hidespan('PhoneError');
  hidespan('EmailError');
  hidespan('CommentError');
  hidespan('TermsError');
  
  var isValid = true;

  // First Name
  var fname = document.forms[0].FirstName;
  if(fname.value == null || fname.value == "")
  {
    showspan('FirstNameError');
    isValid = false;
  }
  
  // Last Name  
  var lname = document.forms[0].LastName;
  if(lname.value == null || lname.value == "")
  {
    showspan('LastNameError');
    isValid = false;
  }
  
  // State  
  var ddlstate = document.forms[0].State;
  if(ddlstate.selectedIndex == -1 || ddlstate.selectedIndex == 0)
  {
    showspan('StateError');
    isValid = false;
  }
  
  // Phone  
  var txtphone = document.forms[0].Phone;
  var phregex=new RegExp("^([\(]?([0-9]{3})[\)]?)?[ \.\-]?([0-9]{3})[ \.\-]([0-9]{4})");
  if((phregex.test(txtphone.value) == false) || txtphone.value == null || txtphone.value == "")
  {
    showspan('PhoneError');
    isValid = false;
  }

  // Email  
  var txtemail = document.forms[0].Email;
  var emailregex=new RegExp("^([A-Za-z0-9!#-'\*\+\-\/=\?\^_`\{-~]+(\.[A-Za-z0-9!#-'\*\+\-\/=\?\^_`\{-~]+)*@[A-Za-z0-9!#-'\*\+\-\/=\?\^_`\{-~]+(\.[A-Za-z0-9!#-'\*\+\-\/=\?\^_`\{-~]+)*)$|^$");
  if((emailregex.test(txtemail.value) == false) || txtemail.value == null || txtemail.value == "")
  {
    showspan('EmailError');
    isValid = false;
  }

  // Comments  
  var comment = document.forms[0].Comments;
  if(comment.value == null || comment.value == "")
  {
    showspan('CommentError');
    isValid = false;
  }
  
  // Terms
  var terms = document.forms[0].TermsAgreement;
  if(terms.checked == false)
  {
    showspan('TermsError');
    isValid = false;
  }
  
  if(isValid)
  {
    return true;
  }
  else
  {
    return false;
  }
}
