function hide(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
}
function show(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != '' ) {
		el.style.display = '';
	}
}
// ||||||||||||||||||||||||||||||||||||||||||||||||||
function sendPage() 
{
 var width  	= 500;
 var height 	= 400;
 var left   	= (screen.width  - width)/2;
 var top    	= (screen.height - height)/2;
 var params 	= 'width='+width+', height='+height;
 var title 		= escape(document.title);
 var location 	= escape(document.location);
 var url		= '/send_page/index.php';
 params += ', top='+top+', left='+left;
 params += ', directories=no';
 params += ', location=no';
 params += ', menubar=no';
 params += ', resizable=no';
 params += ', scrollbars=no';
 params += ', status=no';
 params += ', toolbar=no';
 newwin=window.open(url+'?title='+title+'&location='+location,'emailPage', params);
 if (window.focus) {newwin.focus()}
 return false;
}
// ||||||||||||||||||||||||||||||||||||||||||||||||||
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
  {alert(alerttxt);return false;}
else {return true}
}
}
// ||||||||||||||||||||||||||||||||||||||||||||||||||
function validate_br_locator(thisform) {
	with (thisform) {
		if (validate_required(b_locator_zip,"Please enter your zip code")==false) {
			b_locator_zip.focus();return false;
		}
		if(getSelectedRadio(document.br_locator_form.b_locator_service) == -1) {
			alert('Please select a service');return false;
		}
	}
}
// ||||||||||||||||||||||||||||||||||||||||||||||||||
function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function
// ||||||||||||||||||||||||||||||||||||||||||||||||||
function pviiClassNew(obj, new_style) {
    obj.className = new_style;
}
// ||||||||||||||||||||||||||||||||||||||||||||||||||
function getElementsByClassName(oElm, strTagName, strClassName) {
	var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName),
	arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	for(var i=0; i<arrElements.length; i++)
	if(oRegExp.test(arrElements[i].className))
	arrReturnElements.push(arrElements[i]);
	return (arrReturnElements);
}
// ||||||||||||||||||||||||||||||||||||||||||||||||||
Menu = {timer : null, current : null};
Menu.getStyle = function(name){
	if(document.getElementById) return document.getElementById(name).style;
	else if(document.all) return document.all[name].style;
	else if(document.layers) return document.layers[name];
}
Menu.show = function(name,id){
	if(this.timer) clearTimeout(this.timer);
	if(this.getStyle(name).display == 'none') {
		var obj = document.getElementById(id);
		var xlocation = parseInt(obj.offsetLeft);
		var ylocation = parseInt(obj.offsetTop);
		document.getElementById(name).style.left = xlocation + 'px';
		show(''+name+'');
		this.current = name;
	}
}
Menu.hide = function(){
	this.timer = setTimeout("Menu.doHide();showFlyOut();",500);
}
Menu.doHide = function(){
	if(this.current){
		hide(''+this.current+'');
		showFlyOut();
		this.current = null;
	}
}
function switchClass(obj, new_style) {
    document.getElementById(obj).className = new_style;
}
function showFlyOut(id) {
	var elements = window.document.getElementsByTagName("div");
	for(var i=0;i<elements.length;i++) {
		if (elements[i].className == 'flyOut') {
			var ol = document.getElementById(''+elements[i].id+'');
			hide(''+elements[i].id+'');
		}
	}
	if (id) {
		show(''+id+'');
	}
}
// ||||||||||||||||||||||||||||||||||||||||||||||||||
function setClassSwitch(o, f, a) {
	var e = getElementsByClassName(document, "*", o);
	for(var i=0;i<e.length;i++) {
		e[i].origClass = o;
		e[i].newClass = f;
		if (a == 'of') {
			e[i].onfocus = function() {
				this.className = this.newClass;
				var d = document.getElementById(this.name);
			}
			e[i].onblur = function() {
				this.className = this.origClass;
			}
		}
		if (a == 'om') {
			e[i].onmouseover = function() {
				this.className = this.newClass;
			}
			e[i].onmouseout = function() {
				this.className = this.origClass;
			}
		}
		if (a == 'oc') {
			e[i].onclick = function() {
				this.className = this.newClass;
			}
		}				
	}
}
// ||||||||||||||||||||||||||||||||||||||||||||||||||
function eventAdder(objAttrib,handler,addFunction){
     
   if ((!document.all)&&(document.getElementById)){
       objAttrib.setAttribute(handler,addFunction);
   }    
   //workaround for IE 5.x
   if ((document.all)&&(document.getElementById)){
       objAttrib[handler]=new Function(addFunction);
   }
}
// ||||||||||||||||||||||||||||||||||||||||||||||||||
isFade = true;
toolTip = {timer : null, current : null};
toolTip.getStyle = function(name){
	if(document.getElementById) return document.getElementById(name).style;
	else if(document.all) return document.all[name].style;
	else if(document.layers) return document.layers[name];
}
toolTip.show = function(name){
	if(this.timer) clearTimeout(this.timer);
	this.getStyle(name).display = "";
	this.current = name;
	if( isFade )
	{
	opacity(this.current, 0, 100, 200)
	}
	isFade = false;
}
toolTip.hide = function(){
	this.timer = setTimeout("toolTip.doHide()",400);
}
toolTip.doHide = function(){
	if(this.current){
		this.getStyle(this.current).display = "none";
		changeOpac(0,this.current)
		this.current = null;
		isFade = true;
	}
}
// ||||||||||||||||||||||||||||||||||||||||||||||||||
function chgActiveToolTip(title,tip) {
	toolTip.doHide();
	document.getElementById('fieldTitle').innerHTML = title;
	document.getElementById('fieldInfo').innerHTML = tip;
	toolTip.show('toolTip');
}
// ||||||||||||||||||||||||||||||||||||||||||||||||||
function numbersonly(myfield, e, dec)
{
var key;
var keychar;
if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) ) {
   return true;
	 
// numbers
} else if ((("0123456789").indexOf(keychar) > -1)) {
	return true;
	
// decimal point jump
} else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   
   }
else {
   return false;
  }
}
// ||||||||||||||||||||||||||||||||||||||||||||||||||
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}
// ||||||||||||||||||||||||||||||||||||||||||||||||||
function checkdate(input){
	//var el = document.getElementById(input);
	var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
	var returnval=false
	if (input.value != '') {
		if (!validformat.test(input.value)) {
			alert("Invalid Date Format.");
			//document.myForm.input.focus();
		} else { //Detailed check for valid date ranges
			var monthfield=input.value.split("/")[0]
			var dayfield=input.value.split("/")[1]
			var yearfield=input.value.split("/")[2]
			var dayobj = new Date(yearfield, monthfield-1, dayfield)
			if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield)) {
				alert("Invalid Day, Month, or Year range detected.")
			} else {
				returnval=true
			}
		}
		if (returnval==false) {
			input.select()
			return returnval
		}
	}
}

//////////////////////////////////////////
function CheckFieldLength(fn,wn,rn,mc) {
  var len = fn.value.length;
  if (len > mc) {
    fn.value = fn.value.substring(0,mc);
    len = mc;
  }
  document.getElementById(wn).innerHTML = len;
  document.getElementById(rn).innerHTML = mc - len;
}