/*****************************************************************************
 * Filename: main.js                                                         *
 * Language: Javascript                                                      *
 * Purpose:  Provide functions for fading text in and out as well as changing*
 *           the text inside the box between each fade.                      *
 *           Also handles the fading and rotation of the Testimonials.       *
 ****************************************************************************/

//Global Variables
var hex=255, hex2=255; //initial color variable
var oldR1=99, oldR2=98, oldR3=97, oldR4=96, oldR5=95; //oldRandom values
var oldT=99;
var List = new Array(99), onceThrough=0, popList=0, lCount=0;

function fadeIn(divName)
{ 
	if(hex>0) 
	{ //If color is not black yet
		hex-=10; // increase color darkness
		document.getElementById(divName).style.color="rgb("+hex+","+hex+","+hex+")";
		setTimeout("fadeIn('" + divName + "')", 20); // continue fading in, # miliseconds between each shade
	}
	else
		setTimeout("fadeOut('" + divName + "')", 500); //fade out, # miliseconds before fading out

}

function fadeOut(divName) //Function to fade text from black to white (fade out)
{ 
	if(hex<255) 
	{ //If color is not white yet
		hex+=10; // increase color brightness
		document.getElementById(divName).style.color="rgb("+hex+","+hex+","+hex+")";
		setTimeout("fadeOut('" + divName + "')", 12); 
	}
	else
	{
		setTimeout("changeText('" + divName + "')", 100);//change Text, # miliseconds before changing text
	}
}

function changeText(divName)
{
	var newContent;
	var ran;
	var TopLevel = 52;
	if (popList==0)//If the array has not yet been populated (just entered the site, first time through function)
	{
	   var rTemp;//create temp random variable
	   for( i=0; i < TopLevel; i++ )
	   {
	      var use=1; //use this value? by default yes
	      rTemp = Math.floor(Math.random() * TopLevel);//set rTemp to random value
	      for( n=0; n <= i; n++)//loop through the currently stored values
	      	if( List[n] == rTemp )//if that value is already stored
	      	   use=0;//do not use!
	      if( use == 1 )//if we should use that value
	         List[i] = rTemp;//add it to the list
	      else
	         i--;//retry a new random value for that index
	   }
	   popList=1;//list has been populated
	}
	if( onceThrough == 0 )//if has not completed the first loop through the list
	{
	   ran = List[lCount++];//set next value = next on the array
	   if( lCount == TopLevel )//if on the last value
	   {
	   	onceThrough = 1;//set onceThrough to 1
	   	oldR1 = List[TopLevel-1];
	   	oldR2 = List[TopLevel-2];
	   	oldR3 = List[TopLevel-3];
	   	oldR4 = List[TopLevel-4];
	   	oldR5 = List[TopLevel-5];
	   }
	}
	else //if onceThrough is not 0 (already completed the unique pass through the list)
	{
   	   do //pull a number at random, ensuring it is not one of the last 5 displayed
	   {
	      ran = Math.floor(Math.random() * TopLevel);
	   }while(ran == oldR1 || ran == oldR2 || ran == oldR3 || ran == oldR4 || ran == oldR5);
	   // ^-Prevents the same content appearing withing 5 rotations.
   
	   oldR5 = oldR4;
	   oldR4 = oldR3;
	   oldR3 = oldR2;
	   oldR2 = oldR1;
	   oldR1 = ran;
	}

	switch(ran) //Select text based on random number (0-35)
	{
	   case 0:
	      newContent = "DUI / DWI";
	      break;
	   case 1:
	      newContent = "ADULT PROBATION";
	      break;
	   case 2:
	      newContent = "JUVENILE PROBATION";
	      break;
	   case 3:
	      newContent = "COURTS";
	      break;
	   case 4:
	      newContent = "COUNSELING";
	      break;
	   case 5:
	      newContent = "INTAKE";
	      break;
	   case 6:
	      newContent = "ANGER MANAGEMENT";
	      break;
	   case 7:
	      newContent = "SEX OFFENDERS";
	      break;
	   case 8:
	      newContent = "DOMESTIC VIOLENCE";
	      break;
	   case 9:
	      newContent = "GAMBLERS";
	      break;
	   case 10:
	      newContent = "TREATMENT";
	      break;
	   case 11:
	      newContent = "INMATES";
	      break;
	   case 12:
	      newContent = "MISDEMEANORS";
	      break;
	   case 13:
	      newContent = "SUBSTANCE ABUSE";
	      break;
	   case 14:
	      newContent = "VIOLENCE";
	      break;
	   case 15:
	      newContent = "SUICIDE";
	      break;
	   case 16:
	      newContent = "DEFENDANTS";
	      break;
	   case 17:
	      newContent = "ADULTS & JUVENILES";
	      break;
	   case 18:
	      newContent = "VICTIMS";
	      break;
	   case 19:
	      newContent = "SCHOOLS";
	      break;
	   case 20:
	      newContent = "PRE & POST TREATMENT";
	      break;
	   case 21:
	      newContent = "INPATIENTS";
	      break;
	   case 22:
	      newContent = "OUTPATIENTS";
	      break;
	   case 23:
	      newContent = "FELONIES";
	      break;
	   case 24:
	      newContent = "PATIENTS";
	      break;
	   case 25:
	      newContent = "SUBSTANCE ABUSERS";
	      break;
	   case 26:
	      newContent = "COUNSELING PATIENTS";
	      break;
	   case 27:
	      newContent = "DUI/DWI OFFENDERS";
	      break;
	   case 28:
	      newContent = "PROBATIONERS";
	      break;
	   case 29:
	      newContent = "DRUG COURTS";
	      break;
	   case 30:
	      newContent = "OUTPATIENTS";
	      break;
	   case 31:
	      newContent = "MALES & FEMALES";
	      break;
	   case 32:
	      newContent = "VIOLENCE";
	      break;
	   case 33:
	      newContent = "HMO & EAP PROGRAMS";
	      break;
	   case 34:
	      newContent = "JUVENILES";
	      break;
	   case 35:
	      newContent = "ADULT CLIENTS";
	      break;
	   case 36:
	      newContent = "ADULT PROBATIONERS";
	      break;
	   case 37:
	      newContent = "ADULTS"
	      break;
	   case 38:
	      newContent = "JUVENILE PATIENTS"
	      break;
	   case 39:
	      newContent = "ANGER-MANAGEMENT"
	      break;
	   case 40:
	      newContent = "SEX OFFENDER TEST"
	      break;
	   case 41:
	      newContent = "SUICIDE TEST"
	      break;
	   case 42:
	      newContent = "TREATMENT EFFECTIVENESS"
	      break;
	   case 43:
	      newContent = "VOCATIONAL TEST"
	      break;
	   case 44:
	      newContent = "WELFARE RECIPIENT"
	      break;
	   case 45:
	      newContent = "JUVENILE DETENTION"
	      break;
	   case 46:
	      newContent = "RELIABLE TESTS"
	      break;
	   case 47:
	      newContent = "ACCURATE TESTS"
	      break;
	   case 48:
	      newContent = "VALID TESTS"
	      break;
	   case 49:
	      newContent = "SUBSTANCE ABUSE TESTS"
	      break;
	   case 50:
	      newContent = "ADULT PATIENTS"
	      break;
	   case 51:
	      newContent = "JUVENILE PATIENTS"
	      break;
	   case 52:
	      newContent = "ASSESSMENT INSTRUMENTS"
	      break;
	   default: //to catch 52 and anything above (should only be 0-52)
	      newContent = "CORRECTIONS"
	      break;
	}
	
	document.getElementById(divName).innerHTML=newContent; //Set new content
	fadeIn(divName); //begin fade
}

function fadeInTestimonial(divName, divSig)
{ 
	if(hex2>0) 
	{ //If color is not black yet
		hex2-=10; // increase color darkness
		document.getElementById(divName).style.color="rgb("+hex2+","+hex2+","+hex2+")";
		document.getElementById(divSig).style.color="rgb("+hex2+","+hex2+","+hex2+")";
		setTimeout("fadeInTestimonial('" + divName + "', '" + divSig + "')", 20); // continue fading in, # miliseconds between each shade
	}
	else
		setTimeout("fadeOutTestimonial('" + divName + "', '" + divSig + "')", 18000); //fade out, # miliseconds before fading out

}

function fadeOutTestimonial(divName, divSig) //Function to fade text from black to white (fade out)
{ 
	if(hex2<255) 
	{ //If color is not white yet
		hex2+=10; // increase color brightness
		document.getElementById(divName).style.color="rgb("+hex2+","+hex2+","+hex2+")";
		document.getElementById(divSig).style.color="rgb("+hex2+","+hex2+","+hex2+")";
		setTimeout("fadeOutTestimonial('" + divName + "', '" + divSig + "')", 12); 
	}
	else
	{
		setTimeout("changeTestimonial('" + divName + "', '" + divSig + "')", 100);//change Text, # miliseconds before changing text
	}
}

function changeTestimonial(divContent, divSig)
{
	var newContent;
	var newSig;

	if( oldT > 90 ) //first run through changeTestimonials
	   var ran = Math.floor(Math.random() * 7); //pick a random starting point
	else
	   var ran = oldT + 1; //not first run, increment position

	if(ran > 9) //if over highest position reset to lowest (wrap around)
	   ran = 0;

	oldT = ran; //reset new last number
	switch(ran) //Content and Signature
	{
	case 1:
	   newContent = "<I>\"I am still in shock over your prices.  Anybody can afford $9.95.  The \"pay as you go\" works for me.  And having a list of superior tests to choose from saves me lots of searching.\"</I>";
	   newSig = "<I>Joanne Barry<BR>Pittsburgh, Pennsylvania</I>";
	break;
	case 2:
	   newContent = "<I>\"I didn't believe it until I actually used it.  I gave a group of 12 adolescents test booklets and answer sheets.  It took them all about 25 minutes to complete the test.  Two days later my assistant used the data entry method and has scored and printed all 12 reports in just over one hour.  This saved us hours over our old testing program.\"</I>";
	   newSig = "<I>Steven Morgan<BR>Huntsville, Alabama</I>";
	break;
	case 3:
	   newContent = "<I>\"After using Online's multi-scale tests, I am now a steadfast believer in \"a specific test for a specific assessment question or purpose.\" Your list of tests is very impressive.\"</I>";
	   newSig = "<I>Jared Wendell<BR>Chicago, Illinois</I>";
	break;
	case 4:
	   newContent = "<I>\"Your testing site fits my needs to a \"T\". I use the test booklet and answer sheet testing method. We test clients every Tuesday and Thursday, I score the tests every Friday in my office and my secretary prints the reports on Monday morning before court.\"</I>";
	   newSig = "<I>Malcom Crandall<BR>Dallas, Texas</I>";
	break;
	case 5:
	   newContent ="<I>\"Your tests are first-rate!  I am a solo practitioner and need a variety of tests that hold up in court.  Attorneys and judges really like the Truthfulness Scales.  I use the Substance Abuse, Domestic Violence and Sex Offender tests a lot.  Keep up the good work!\"</I>";
	   newSig = "<I>Catherine Lorain<BR>Bend, Oregon</I>";
	   break;
	case 6:
	   newContent ="<I>\"It's not often that one testing company offers such a variety of tests in such an informative, helpful and professional manner. My referrals have dramatically increased since I started using Online's tests.\"</I>";
	   newSig = "<I>Karol Taylor<BR>Chicago, Illinois</I>";
	   break;
	case 7:
	   newContent ="<I>\"Outstanding in every way. I can now pay for tests as I need them. I appreciate online testing's service now available over the internet.\"</I>";
	   newSig = "<I>Matt Reyes<BR>Boise, Idaho</I>";
	   break;
	case 8:
	   newContent ="<I>\"This was a very valuable experience for me. It gives me test alternatives when I need them. Online testing helps me expand my practice and my accounts receivable.\"</I>";
	   newSig = "<I>Karen Powell<BR>Charlotte, North Carolina</I>";
	   break;
	case 9:
	   newContent ="<I>\"This is just to thank Online Testing for the materials and services offered. As a sole practitioner, I greatly appreciate the ready availability of tests that augment my work and enhance my ability to serve clients.\"</I>";
	   newSig = "<I>Deborah Scott<BR>Daytona Beach, Florida</I>";
	   break;
	default:
	   newContent = "<I>\"The convenience of your site is its number one value.  I test my clients in the office during the week and then I score the reports at home on the weekend, enabling me to get some work done and still be at home with my family.  Thanks!\"</I>";
	   newSig = "<I>Margaret Di Arcolo<BR>New York, NY</I>";
	break;
	}
	
	document.getElementById(divContent).innerHTML = newContent; //populate newContent
	document.getElementById(divSig).innerHTML = newSig; //populate newSig

	fadeInTestimonial(divContent, divSig); //fade content and sig
}

function horizontalBar()
{
  document.write("<TABLE cellspacing=5 cellpadding=0 width=\"435\">");
    document.write("<TR>");
     document.write("<TD onMouseOver=\"this.className='NewAccountOver';\" onMouseOut=\"this.className='NewAccountOut';\" onClick=\"window.location='main/public/account.aspx';\" class=\"NewAccountOut\" style=\"width:105px; height:45px;\">");
     document.write("<TD onMouseOver=\"this.className='LoginOver';\" onMouseOut=\"this.className='LoginOut';\" onClick=\"window.location='main/confirm.aspx';\" class=\"LoginOut\" style=\"width:105px; height:45px;\">");
     document.write("<TD onMouseOver=\"this.className='StateLoginOver';\" onMouseOut=\"this.className='StateLoginOut';\" onClick=\"window.location='states.html';\" class=\"StateLoginOut\" style=\"width:105px; height:45px;\">");
     document.write("<TD onMouseOver=\"this.className='IntroOver';\" onMouseOut=\"this.className='IntroOut';\" onClick=\"window.location='intro.html';\" class=\"IntroOut\" style=\"width:105px; height:45px;\">");
   document.write("</TABLE>");
}


function introButtonsBar()
{
  document.write("<TABLE cellspacing=6 cellpadding=0 width=\"955\">");
    document.write("<TR>");
     document.write("<TD onMouseOver=\"this.className='DRI2Over';\" onMouseOut=\"this.className='DRI2Out';\" onClick=\"window.location='main/public/intro.html';\" class=\"DRI2Out\" style=\"width:315px; height:45px;\">");     
     document.write("<TD onMouseOver=\"this.className='JUVOver';\" onMouseOut=\"this.className='JUVOut';\" onClick=\"window.location='main/public/juvintro.html';\" class=\"JUVOut\" style=\"width:315px; height:45px;\">");
     document.write("<TD onMouseOver=\"this.className='SAQOver';\" onMouseOut=\"this.className='SAQOut';\" onClick=\"window.location='main/public/saqintro.html';\" class=\"SAQOut\" style=\"width:315px; height:45px;\">");
     document.write("<TR>");
     document.write("<TD onMouseOver=\"this.className='GAIOver';\" onMouseOut=\"this.className='GAIOut';\" onClick=\"window.location='main/public/gaiintro.html';\" class=\"GAIOut\" style=\"width:315px; height:45px;\">");
     document.write("<TD onMouseOver=\"this.className='WELFAREOver';\" onMouseOut=\"this.className='WELFAREOut';\" onClick=\"window.location='main/public/welfareintro.html';\" class=\"WELFAREOut\" style=\"width:315px; height:45px;\">");
     document.write("<TD onMouseOver=\"this.className='RRIOver';\" onMouseOut=\"this.className='RRIOut';\" onClick=\"window.location='main/public/rriintro.html';\" class=\"RRIOut\" style=\"width:315px; height:45px;\">");
  document.write("</TABLE>");
}