// JavaScript Document

////AUTO TAB

$(document).ready(function() {
$('#Home1').autotab({ target: 'Home2', format: 'numeric' });
$('#Home2').autotab({ target: 'Home3', format: 'numeric', previous: 'area_code' });
$('#Home3').autotab({ previous: 'Home2', format: 'numeric' });

$('#Work1').autotab({ target: 'Work2', format: 'numeric' });
$('#Work2').autotab({ target: 'Work3', format: 'numeric', previous: 'area_code' });
$('#Work3').autotab({ previous: 'Work2', format: 'numeric' });

$('#Cell1').autotab({ target: 'Cell2', format: 'numeric' });
$('#Cell2').autotab({ target: 'Cell3', format: 'numeric', previous: 'area_code' });
$('#Cell3').autotab({ previous: 'Cell2', format: 'numeric' });

$('#Home1-1').autotab({ target: 'Home2-1', format: 'numeric' });
$('#Home2-1').autotab({ target: 'Home3-1', format: 'numeric', previous: 'area_code' });
$('#Home3-1').autotab({ previous: 'Home2-1', format: 'numeric' });

$('#Work1-1').autotab({ target: 'Work2-1', format: 'numeric' });
$('#Work2-1').autotab({ target: 'Work3-1', format: 'numeric', previous: 'area_code' });
$('#Work3-1').autotab({ previous: 'Work2-1', format: 'numeric' });

$('#Cell1-1').autotab({ target: 'Cell2-1', format: 'numeric' });
$('#Cell2-1').autotab({ target: 'Cell3-1', format: 'numeric', previous: 'area_code' });
$('#Cell3-1').autotab({ previous: 'Cell2-1', format: 'numeric' });
});

////////////MENU FUNCTIONS
var timeout         = 0;
var closetimer		= 0;
var ddmenuitem      = 0;
function menu_open(){
menu_canceltimer();
menu_close();
ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}
function menu_close(){
if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}
function menu_timer(){
closetimer = window.setTimeout(menu_close, timeout);}
function menu_canceltimer(){
if(closetimer){
window.clearTimeout(closetimer);
closetimer = null;}}
$(document).ready(function(){
$('#menu > li').bind('mouseover', menu_open)
$('#menu > li').bind('mouseout',  menu_timer)});

 $(function() {

    //Preserves the mouse-over on top-level menu elements when hovering over children
    $("#menu ul").each(function(i){
      $(this).hover(function(){
        $(this).parent().find("a").slice(0,1).addClass("active");
      },function(){
        $(this).parent().find("a").slice(0,1).removeClass("active");
      });
    });

    // IE6 Fix: Drop-down fix due to lack of support for :hover on list elements
    if($.browser.msie && ($.browser.version < 7)) {
      $("#menu").each(function(i){
        $(this).find("li").hover(function(){
          $(this).addClass("active");
        },function(){
          $(this).removeClass("active");
        });
      });
    }

  });

document.onclick = menu_close;
////////////END MENU FUNCTIONS




////////////SLIDESHOW

function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});


function fnSubmit()
{
	
	if (checkEmpty() && CheckPhones()) {
	
	document.form1.submit();
	}
}

function fnSubmit2()
{
	if (checkEmpty2() && CheckPhones()) {
	
	document.form1.submit();
	}
}

function checkEmpty()
{
	if(document.form1.FullName.value == '' || document.form1.Email.value == ''){
		alert("Please fill out the required information ");
		return false;
		
	}else{
		return true;	
	}
} 

function checkEmpty2()
{
	if(document.form1.FirstName.value == '' || document.form1.LastName.value == '' || document.form1.Email.value == ''){
		alert("Please fill out the required information ");
		return false;
		
	}else{
		return true;	
	}
} 

function CheckPhones()
{
	FillOnePhone = false;
	AllPhonesOk = true;
	Phone1RegExp = /^(\d{10})$/;
	var FeildsNames = new Array("Home", "Cell", "Work");
	for(i=0;i<FeildsNames.length;i++)
	{
		PhoneVal = eval("document.form1."+ FeildsNames[i]+ "1.value + document.form1." + FeildsNames[i]+ "2.value + document.form1." + FeildsNames[i]+ "3.value");
		if (PhoneVal == '') continue
		else
		{
		  FillOnePhone = true;
			if (!Phone1RegExp.test(PhoneVal))
			{
				alert("Insert a valid number, please!");
				eval("document.form1." + FeildsNames[i] + "1.focus()");
				AllPhonesOk = false;
				break;
			}
		}
	}
	if (!FillOnePhone)
	{
  	alert('Please fill out at least one phone number.');
		return false;
	}
	else
	  if (AllPhonesOk) return true
		else return false;
} 


function downloadAlert(){
	alert("A download for this article is not yet available. Check back soon.");	
	
}


