// JavaScript Document
function $_(_id)
{
	if (typeof _id == "string")	
		return document.getElementById(_id);
	return _id;
}
function ET(_event)

{ var targ;

  if (!_event) 
  { var _event=window.event;
  }

  if (_event.target)  
  {  targ=_event.target;
  }
  else if (_event.srcElement)  
  {  targ=_event.srcElement;
  }
  
  if (targ.nodeType==3) 
  { targ = targ.parentNode;
  }
  return targ;
}


function myEvent(_this,_event)
{ var targ;
  if (!_event) 
  { var _event=window.event;
  }
    
  if (_event.target)  
  {  targ=_event.target;
  }
  else if (_event.srcElement)  
  {  targ=_event.srcElement;
  }
  return ( _this === targ );
}

function rolloverHome( _this, _event ) {
	var img = ps(_this);

//	$_('subbanner').src = img.src;
}

function rollover4( _this, _event ) { 
	
	return;
	
	if ( !myEvent( _this, _event ) ) 
	{
		_event.cancelBubble = true;
		return;
	}
	var _next = _this.firstChild;
	var _prev = _this.previousSibling;
	
	if ( _next.nodeType == 3 ) _next = _next.nextSibling;
	if ( _prev.nodeType == 3 ) _prev = _prev.previousSibling;

//	$_('subbanner').src = _next.src;
//	$_('topic').src = _prev.src;
	
	_next = _next.nextSibling;
	if ( _next.nodeType == 3 ) _next = _next.nextSibling;

//	$_('titler').innerHTML = _next.innerHTML;
	
	_next = _next.nextSibling;
	if ( _next.nodeType == 3 ) _next = _next.nextSibling;

//	$_('description').innerHTML = _next.innerHTML;
	
	_next = _next.nextSibling;
	if ( _next.nodeType == 3 ) _next = _next.nextSibling;

//	$_('headline').innerHTML = _next.innerHTML;
}

function click4( _this, _tgt, _event ) { 
	if ( !myEvent( _this, _event ) ) 
	{
		_event.cancelBubble = true;
		return;
	}
	$('#'+_tgt).click()
}
function click5( _this, _event ) {
	if ( !myEvent( _this, _event ) ) 
	{
		_event.cancelBubble = true;
		return;
	}
	var _item = pn(_this);
	var _next = fc(_item);
	var _prev = ps(_item);
	
	if ( lastRead )
	   remClass( lastRead, 'reading' );
	lastRead=0;
	
	if ( !_item.parentNode.was )
		toggle( _item, _event );
	
	if ( _item.parentNode.was && _item.parentNode.was != lc(_item))
	{
		$(_item.parentNode.was).hide('slow');
		toggle( _item, _event );
	}
	_item.parentNode.was = lc(_item);
		
	doRandomPics();
	
	$_('topic').src     = _prev.src;
	_prev = ps(_prev);
	$_('titler').innerHTML = _prev.innerHTML;
	
	topImage = _next.id;
//	$_('subbanner').src = _next.src;
	
	_next = ns(_next);
	$_('chooseus').innerHTML = _next.innerHTML;
	
	_next = ns(_next);
	$_('description').innerHTML = _next.innerHTML;
	
	_next = ns(_next);
	$_('headline').innerHTML = _next.innerHTML;
	
	$_('picLabel').innerHTML = '&nbsp;';

	
	//pageTracker._trackEvent('click5', 'enter', _next.id );
	
	//gonext = _this.nextSibling;
	//goprev = _this.prevSibling;
	
	imAt = _this;
}

function rollout( _this, _event ) {
	if ( !myEvent( _this, _event ) ) 
	{
		_event.cancelBubble = true;
		return;
	}
//	$_('subbanner').src = $_(topImage).src;
}

function rollover5( _this, _event ) {
	
	return;
	
	if ( !myEvent( _this, _event ) ) 
	{
		_event.cancelBubble = true;
		return;
	}
	var _item = pn(_this);
	var _next = fc(_item);
	var _prev = ps(_item);
	
	$_('topic').src     = _prev.src;
	doRandomPics();
	_prev = ps(_prev);
//	$_('chooseus').innerHTML = _prev.innerHTML;
	
//	$_('subbanner').src = _next.src;
	
	_next = ns(_next);
//	$_('titler').innerHTML = _next.innerHTML;
	
	_next = ns(_next);
//	$_('description').innerHTML = _next.innerHTML;
	
	_next = ns(_next);
//	$_('headline').innerHTML = _next.innerHTML;
	
}

var clickIt = false;
var imAt = 0;

function goNext( _this, _event)
{
	var iam = imAt.id;
	var pos = iam.substring(iam.indexOf('_')+1,iam.length);
	var tgt=0;
	while ( !tgt && pos < 99 )
	{	pos++;
		tgt=$_('O_'+pos);
	}
	tgt=$('#O_'+pos);
	tgt.click();
	return false;
}

function goPrev(_this, _event)
{
	var iam = imAt.id;
	var pos = iam.substring(iam.indexOf('_')+1,iam.length);
	var poswas = Math.floor(pos / 10);
	var tgt=0;
	while ( !tgt && pos > 0 )
	{	pos--;
		tgt=$_('O_'+pos);
	}
	tgt=$('#O_'+pos);
	var posis = Math.floor( pos/10 );
	if ( posis != poswas )
		$('#O_'+(posis*10)).click();
	tgt.click();
	return false;
}

function beep() { alert('beep'); }
function toggle( _this, _event )
{
	var _item = lc(_this);
	
	if ( !_this.style || !_item.style.display )
	{
		_item.style.display = 'block';
		return;
	}
		
	if ( _item.style.display === 'none')
		_item.style.display='block';
	else
		_item.style.display='none';
}

function tog( _this )
{
	if ( !_this.style || !_this.style.display )
	{
		_this.style.display = 'block';
		return;
	}
		
	if ( _this.style.display === 'none')
		_this.style.display='block';
	else
		_this.style.display='none';
}

function showVideo( _this, _event, _src, _params ) {
	if ( press( _this ) )
		{ 
		endRandomPics();
			$("#videoFrame").show();
		  $("#imageFrame").hide();
		  fc(_this).src="images/videoButtonOn.jpg";
		  $('#defaultVideo').click();;
		}
	else
		{ 
		  goRandom();
			$("#videoFrame").hide();
		  $("#imageFrame").show();
		  video( _this, _event, '' );
		  fc(_this).src="images/videoButton.jpg";
		}
}

function video( _this, _event, _src, _params ) {
		if ( _src == '' )
		{
			FlashReplace.replace("flashBox", '', "movie1", 300, 194, '', _params);
			$("flashBox").innerHTML = '&bnsp;';	
			return;
		}
		FlashReplace.replace("flashBox", 'videos/'+_src, "movie1", 300, 194, '', _params);
		$_("videoLabel").innerHTML = _this.title;
}
function video2( _src, _params ) {
		if ( _src == '' )
		{
			FlashReplace.replace("flashBox", '', "movie1", 325, 240, '', _params);
			return;
		}
		FlashReplace.replace("flashBox", 'videos/'+_src, "movie1", 325, 240, '', _params);
}
function video3( _src, _params ) {
		if ( _src == '' )
		{
			FlashReplace.replace("flashBox", '', "movie1", 300, 194, '', _params);
			return;
		}
		FlashReplace.replace("flashBox", 'videos/'+_src, "movie1", 450, 315, '', _params);
}

function video4( _src, _params ) {
		if ( _src == '' )
		{
			FlashReplace.replace("flashBox", '', "movie1", 320, 240, '', _params);
			return;
		}
		FlashReplace.replace("flashBox", 'videos/'+_src, "movie1", 300, 240, '', _params);
}

function videoHover( _this, _event )
{
		$_("videoAnnounce").innerHTML = _this.title;
}

function videoOut( _this, _event )
{
		$_("videoAnnounce").innerHTML = '';
}

function press(_obj )   { return togClass(_obj, 'on' ); }
function togClass( _obj, _class ) { if ( remClass( _obj, _class ) ) return false; addClass( _obj, _class ); return true; }

function addClass( _obj, _class ) { _obj.className=' '+_class+' '+_obj.className; }

function hasClass( _obj, _class ) {
  rep2="\\b"+_class+"\\b";
  rep = new RegExp( rep2, "ig" );
  now=_obj.className.replace(rep,'' );
 return _obj.className != now;
}



function remClass( _obj, _class ) { 
  rep2="\\b"+_class+"\\b";
  rep = new RegExp( rep2, "ig" );
  b4 = _obj.className;
  _obj.className=_obj.className.replace(rep,'' );
  return _obj.className != b4;
}

var lastRead = 0;

function reveal( _item, _event ) {  
        
	_item.style.color='#999999';
	addClass(_item, 'reading' );
	
	if ( lastRead )
	   remClass( lastRead, 'reading' );
	lastRead=_item;
	
	var my   = _item;
	var desc = _item.nextSibling;
	
	doRandomPics();
	
	$_('titler').innerHTML    = ps(_item).innerHTML;
	
	//$('#topic').hide();
	$_('topic').src             = ps(ps(_item)).src;
	//$('#topic').fadeIn( 'slow' );
	$_('chooseus').innerHTML      = _item.innerHTML;
	$_('picLabel').innerHTML = '&nbsp;';
	
	//pageTracker._trackEvent( 'reveal', 'enter', _item.id );
	
	$_('description').innerHTML = ns(_item).innerHTML;
	
	imAt = _item;
}

var myTimer = 0;
var myTimerInterval = 0;
var myTimerInterval2 = 0;
var myBenefitInterval = 0;
var timersOn = 1;

function goRandomQuotes( _delay )
{
	if ( !timersOn ) return;
	
	randomQuote();
	myTimerInterval2 = setInterval( 'randomQuote()', _delay );
}

var quoteLoaded = -1;
function randomQuote()
{
	var index = Math.floor( Math.random() * quoteList.length );
	
	if ( quoteLoaded  === index )
		return randomQuote();
	
	quoteLoaded = index;	
	
	$_('quote').innerHTML = quoteList[index][0];
	$_('quote2').innerHTML = quoteList[index][1];
	
}

function goRandomBenefits(_delay)
{
	if ( !timersOn ) return;
	
	myTimerInterval2 = setInterval( 'randomBenefit()', _delay );
}

var benefitLoaded = -1;
function randomBenefit()
{
	var index = Math.floor( Math.random() * benefitList.length );
	
	if ( benefitLoaded  == index )
		return randomBenefit();
	
	benefitLoaded = index;	
		
	$_('benefit').innerHTML  = benefitList[index][1];	
	$_('keytitle').innerHTML = benefitList[index][0];

}

var picDelay = 0;
var picInterval = 0;

function goRandomPics( _delay, _interval )
{
	picDelay = _delay;
	picInterval = _interval;
}

function doRandomPics()
{
	if ( !timersOn ) return;
	
	if ( myTimer )
		clearTimeout( myTimer );
	if ( myTimerInterval )
		clearInterval( myTimerInterval );
	myTimer = setTimeout( 'goRandom()', picDelay );
}
function goRandom()
{
	if ( picDelay )
		randomPic();
	if ( picInterval )
		myTimerInterval = setInterval( 'randomPic()', picInterval );
}
function endRandomPics()
{
		clearInterval( myTimerInterval );
		clearTimeout( myTimer);
		myTimer = 0;
		myTimerInterval = 0;
}

var picLoaded = -1;
function randomPic()
{
	picLoaded++;
	
	if ( picLoaded === picList.length )
	{
//		endRandomPics();
		picLoaded = -1;
//		$('#videoButtonWrap').click();
		return;
	}
	slowload('topic', 'images/'+picList[ picLoaded ][0] );
	$_('picLabel').innerHTML =  picList[ picLoaded ][1];
	
	randomBenefit();
}
function slowload( _banner, _src )
{		
	$('#topic').fadeOut('fast',function() {
										preload( _banner, _src );
										$('#topic').fadeIn( 1000 );} );
}
	

function unhide( _this, _event ) {  
	_this.style.color = '#999999';

	$_('question').innerHTML = _this.innerHTML;
	var _item = ns(_this);
	
	$_('answer').innerHTML = _item.innerHTML;
	
	return;
	
	if ( !_item.style.display )
	{
		_item.style.display = 'block';
		return;
	}
		
	if ( _item.style.display === 'none')
		_item.style.display='block';
	else
		_item.style.display='none';
}


function rollinto2( _item, _event ) {
	
//	return;
	
	if ( !myEvent( _item, _event ) ) 
	{
		return;
	}
	var my   = _item;
	var desc = _item.nextSibling;
	
	doRandomPics();
	$_('topic').src             = ps(ps(_item)).src;
	//$_('titler').innerHTML    = ps(_item).innerHTML;
		
//	$_('chooseus').innerHTML      = _item.innerHTML;
	
	//$_('description').innerHTML = ns(_item).innerHTML;
}

function ps( _item )
{
	if ( !_item ) return _item;
	
	_item = _item.previousSibling;	
	if ( _item.nodeType == 3 ) _item = _item.previousSibling;	
	return _item;
}
function lc( _item )
{
	if ( !_item ) return _item;
	_item = _item.lastChild;	
	if ( _item.nodeType == 3 ) _item = _item.previousSibling;	
	return _item;
}
function fc( _item )
{
	if ( !_item ) return _item;
	_item = _item.firstChild;	
	if ( _item.nodeType == 3 ) _item = _item.nextSibling;	
	return _item;
}
function ns( _item )
{
	if ( !_item ) return _item;
	_item = _item.nextSibling;	
	if ( _item.nodeType == 3 ) _item = _item.nextSibling;	
	return _item;
}
function pn( _item )
{
	if ( !_item ) return _item;
	return _item.parentNode;
}

function preload( _banner, _src )
{
  var t= $_(_banner);
  if ( t ) t.src = _src;
}

function rollinto( _item, _banner, _event ) {
	if ( !myEvent( _item, _event ) ) 
	{
		_event.cancelBubble = true;
		return;
	}
	var my   = _item;
	var desc = _item.nextSibling;
	
	_item = _item.previousSibling;
	
	if ( _item.nodeType == 3 ) _item = _item.previousSibling;
	if (  desc.nodeType == 3 ) desc = desc.previousSibling;

	$_(_banner).src = _item.src;
	
	$_('titler').innerHTML = my.innerHTML;
	$_('description').innerHTML = desc.innerHTML;
}

// contact form

function validate_text(field,alerttxt) {
if (field.value==null || field.value=="")
	{return false;}
else {return true}
}

function validate_email(field,alerttxt) {
if (field.value==null || field.value=="")
	{return false;}
		var exclude=/[^@\-\.\w\']|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
			var check=/@[\w\-]+\./;
			var checkend=/\.[a-zA-Z]{2,6}$/;
			var invalid = false; //field.length < 80;
			invalid |= field.value.match(exclude) != null; // no spaces and such
			invalid |= field.value.match(check) == null;  // must find @
			invalid |= field.value.match(checkend) == null; // must finish .etc 
			
			return !invalid;
			
			//return (((emailad.length > 80) || (emailad.search(exclude) != -1) || (emailad.search(check)) == -1) || (emailad.search(checkend) == -1))?false:true;
}

function validate_phone(field, alerttxt) {
if (field.value==null || field.value=="")
	{return false;}
		var num = field.value;
		var digits = 0;
		if (num == null) return false;
		for( i=0; i<num.length; i++ ){

				var c = num.charCodeAt(i);  

				if( (c>=48) && (c<=57) ) digits++;
		}    
		return (digits == 10);
}

function squawk( msg )
{
	$_('squawk').innerHTML = msg;
}

function validate_form(thisform)
{
	with (thisform)
	{
		if (validate_text(first_name)==false)
			{first_name.focus();squawk("Missing first name.");return false;}
			
		if (validate_text(last_name)==false)
			{last_name.focus();squawk("Missing last name.");return false;}
			
		if (validate_text(title)==false)
			{title.focus();squawk("What is your position?");return false;}
			
		if (validate_text(company)==false)
			{company.focus();squawk("What company?");return false;}
			
		if (validate_email(email)==false)
			{email.focus();squawk("email? eg. i2iTracks@myclinic.org");return false;}
			
		if (validate_phone(phone)==false)
			{phone.focus();squawk("phone? eg. 800-555-1212");return false;}
			
		if (state.value=="-1")
			{state.focus();squawk("Your state?");return false;}
	}
	return true;
}		
