// JavaScript Document



function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}



//Rotating Banner

var BannerArray = new Array("banner1", "banner2", "banner3");

var CurrentContainer = "none";
var NewContainer = "none";
var OldContainer = "none";

function RandomBanner() {
	var MaxValue = BannerArray.length;
	var RandomNum = Math.floor(Math.random()*MaxValue);
	return BannerArray[RandomNum];
}

function RotateBanner() {
	
	if (NewContainer == "none") {
		NewContainer = RandomBanner();
		FadeIn(NewContainer);
		CurrentContainer = NewContainer;
		NewContainer = RandomBanner();
		while (NewContainer == CurrentContainer) {
			NewContainer = RandomBanner();
		}
	} else {
		FadeIn(NewContainer);
		FadeOut(CurrentContainer);
		CurrentContainer = NewContainer;
		NewContainer = RandomBanner();
		while (NewContainer == CurrentContainer) {
			NewContainer = RandomBanner();
		}
		
	}
	
	//interval for rotating banner
	//var t=setTimeout("RotateBanner();",8000);
	
}

function SelectBanner(banner){
			if (CurrentContainer == banner){}
			else{
				NewContainer = banner;
				FadeIn(NewContainer);
				if (CurrentContainer=="none"){}
				else{FadeOut(CurrentContainer);}
				CurrentContainer = NewContainer;
				NewContainer = RandomBanner();
				while (NewContainer == CurrentContainer) {
					NewContainer = RandomBanner();
				}
			}
		}
		 

function FadeOut(container) {
	//time is how long is takes to fade in or out (milliseconds)
	var time = 1000;
	opacity(container, 99, 0, time);
	//using 99 instead of 100 fixes a flicker glitch in older versions of mozilla
	var t=setTimeout("DisplayOff(OldContainer);",time);
	
}

function FadeIn(container) {
	document.getElementById(container).style.display = "inline";
	opacity(container, 0, 99, 1000);
	//using 99 instead of 100 fixes a flicker glitch in older versions of mozilla
}
 function DisplayOff(container){
	 document.getElementById(container).style.display = "none";
 }
 
 /****************************************************************************/
//fade scripts from http://brainerror.net/scripts_js_blendtrans.php

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
		//In order to turn off the display of this element:
		OldContainer = id;
		
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}



//******************FORM VALIDATION************************************************

function validate_required(field,alerttxt) {
	with (field) {
		if (value==null||value=="")
		  {alert(alerttxt);return false}
		else {return true}
	}
}

function validate_email(field,alerttxt) {
	with (field) {
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		if (apos<1||dotpos-apos<2) 
		  {alert(alerttxt);return false}
		else {return true}
	}
}

//email form
function validate_form2(thisform) {

	with (thisform) {
		if (validate_required(F_Name,"Please enter your first name.")==false)
		  {F_Name.focus();return false}
	}
	with (thisform) {
		if (validate_required(L_Name,"Please enter your last name.")==false)
		  {L_Name.focus();return false}
	}
	with (thisform) {
		if (validate_email(Email,"Please enter valid e-mail address.")==false)
		  {Email.focus();return false}
	}
	with (thisform) {
		if (validate_required(Phone,"Please enter phone number.")==false)
		  {Phone.focus();return false}
	}
	with (thisform) {
		if (validate_required(Address,"Please enter your address.")==false)
		  {Address.focus();return false}
	}
	with (thisform) {
		if (validate_required(City,"Please enter your city.")==false)
		  {City.focus();return false}
	}
	with (thisform) {
		if (validate_required(State,"Please select your state.")=="")
		  {State.focus();return false}
	}
	with (thisform) {
		if (validate_required(Zip,"Please enter your zip code.")==false)
		  {Zip.focus();return false}
	}
	
}