// 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.");	
	
}

function checkAreaCode(val){

	var codes = new Array(201, 202, 203, 205, 206, 207, 208, 209, 210, 212, 213, 214, 215, 216, 217, 218, 219, 224, 225, 228, 229, 231, 234, 236, 239, 240, 248, 251, 253, 254, 256, 260, 262, 267, 269, 270, 276, 278, 281, 283, 301, 302, 303, 304, 305, 307, 308, 309, 310, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 323, 325, 330, 331, 334, 336, 337, 339, 341, 347, 351, 352, 360, 361, 369, 380, 385, 386, 401, 402, 404, 405, 406, 407, 408, 409, 410, 412, 413, 414, 415, 417, 419, 423, 424, 425, 430, 432, 434, 435, 440, 442, 443, 464, 469, 470, 475, 478, 479, 480, 484, 501, 502, 503, 504, 505, 507, 508, 509, 510, 512, 513, 515, 516, 517, 518, 520, 530, 540, 541, 551, 557, 559, 561, 562, 563, 564, 567, 570, 571, 573, 574, 575, 580, 585, 586, 601, 602, 603, 605, 606, 607, 608, 609, 610, 612, 614, 615, 616, 617, 618, 619, 620, 623, 626, 627, 628, 630, 631, 636, 641, 646, 650, 651, 660, 661, 662, 669, 678, 679, 682, 689, 701, 702, 703, 704, 706, 707, 708, 712, 713, 714, 715, 716, 717, 718, 719, 720, 724, 727, 731, 732, 734, 737, 740, 747, 754, 757, 760, 762, 736, 764, 765, 769, 770, 772, 773, 774, 775, 779, 781, 785, 786, 787, 801, 802, 803, 804, 805, 806, 808, 810, 812, 813, 841, 815, 816, 817, 818, 828, 830, 831, 832, 835, 845, 847, 848, 850, 856, 857, 858, 859, 860, 862, 863, 864, 865, 870, 872, 878, 901, 903, 904, 906, 907, 908, 909, 910, 912, 913, 914, 915, 916, 917, 918, 919, 920, 925, 927, 928, 931, 935, 936, 937, 940, 941, 947, 949, 951, 954, 956, 957, 959, 970, 971, 972, 973, 975, 978, 979, 980, 984, 985, 989);
	
	
	 var Found = false;

  for (var i = 0; i < codes.length; i++){
    if (codes[i] == val){
      
	  var Found = true;

      break;
    }
    else if ((i == (codes.length - 1)) && (!Found)){
      if (codes[i] != val){
        alert('Please enter a valid US area code!');
      }
    }
  }

}


