function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


//MAIN PAGE IMAGE ROTATOR
var theImages = new Array()

theImages[0] = '/images/design012/MP_girlsPapers.gif'
theImages[1] = '/images/design012/MP_graduates.gif'
theImages[2] = '/images/design012/MP_kidsInLine.gif'
theImages[3] = '/images/design012/MP_teensArmWrap.gif'


var j = 0
var p = theImages.length;

var preBuffer = new Array()
for (i = 0; i < p; i++){
   preBuffer[i] = new Image()
   preBuffer[i].src = theImages[i]
}

var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.write('<img src="'+theImages[whichImage]+'">');
}


//TOP NAVIGATION LAYERS
 var bName = navigator.appName;
 var bVer = parseInt(navigator.appVersion);
 var NS6 = (bName == "Netscape" && bVer >= 5);
 var NS4 = (bName == "Netscape" && bVer >= 4 && bVer < 5);
 var IE4 = (bName == "Microsoft Internet Explorer" && bVer >= 4);
 var NS3 = (bName == "Netscape" && bVer < 4);
 var IE3 = (bName == "Microsoft Internet Explorer" && bVer < 4);
 window.onerror = null;
 var menuActive = 0
 var menuOn = 0
 var onLayer
 var timeOn = null // LAYER SWITCHING CODE
 if (NS4 || IE4 || NS6) {
	 if (navigator.appName == "Netscape" && !document.getElementById){
	 layerStyleRef="layer.";
	 layerRef="document.layers";
	 styleSwitch="";
	 layerVis="show";
	 layerHid="hide";
	 }
	 else if (!document.all && document.getElementById) {
	 layerStyleRef="layer.style.";
	 layerRef="document.getElementById";
	 styleSwitch=".style";
	 layerVis="visible";
	 layerHid="hidden";
	 }
	 else {
	 layerStyleRef="layer.style.";
	 layerRef="document.all";
	 styleSwitch=".style";
	 layerVis="visible";
	 layerHid="hidden";
	 }
 }
// SHOW MENU
function shLayer(layerName){
 img = getImage("imgTabs");
 x = getImagePageLeft(img);
 y = getImagePageTop(img);
 menuTop = y + 30 ; // LAYER TOP POSITION
 SerL = x + 1 ; // 'Ser' LAYER LEFT POSITION
 ProL = x + 126 ;  // 'Pro' LAYER LEFT POSITION
 RatL = x + 628 ;  // 'Rat' LAYER LEFT POSITION
if (NS4 || IE4 || NS6) {
 if (timeOn != null) {
 clearTimeout(timeOn)
 hideLayer(onLayer)
 }
 if (NS4 || IE4) {
 eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="'+layerVis+'"');
 eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.top="'+menuTop+'"');
 eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.left="'+eval(layerName+'L')+'"');
 } 
 if (NS6) {
 eval(layerRef+'("'+layerName+'")'+styleSwitch+'.visibility="'+layerVis+'"');
 eval(layerRef+'("'+layerName+'")'+styleSwitch+'.top="'+menuTop+'"');
 eval(layerRef+'("'+layerName+'")'+styleSwitch+'.left="'+eval(layerName+'L')+'"');
 } 
 onLayer = layerName
 }
}// HIDE MENU
function hideLayer(layerName){
 if (menuActive == 0) {
 if (NS4 || IE4) {
 eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="'+layerHid+'"');
 }
 if (NS6) {
 eval(layerRef+'("'+layerName+'")'+styleSwitch+'.visibility="'+layerHid+'"');
 }
 }
}// TIMER FOR BUTTON MOUSE OUT
function btnTimer() {
 timeOn = setTimeout("btnOut()",1000)
}// BUTTON MOUSE OUT
function btnOut(layerName) {
 if (menuActive == 0) {
 hideLayer(onLayer)
 }
}// MENU MOUSE OVER 
function menuOver(itemName) {
 clearTimeout(timeOn)
 menuActive = 1
}// MENU MOUSE OUT 
function menuOut(itemName) {
 menuActive = 0 
 timeOn = setTimeout("hideLayer(onLayer)", 400)

 }// SET BACKGROUND COLOR 
function setBgColor(layer, color) {
  if (NS6){
    eval('document.getElementById("'+layer+'").style.backgroundColor="'+color+'"');
  }
  else if (NS4){
    eval('window.document.layers["'+layer+'"].document.bgColor="'+color+'"');
	eval('window.document.layers["'+layer+'"].saveColor="'+color+'"');
  }
  else if (IE4){
    eval('document.all.'+layer+'.style.backgroundColor="'+color+'"');
  }
}

function getImage(name) {
  if (NS4 || NS6) {
    return findImage(name, document);
  }
  if (IE4 || NS6)
    return eval('document.all.' + name);
  return null;
}

function findImage(name, doc) {
  var i, img;
  for (i = 0; i < doc.images.length; i++)
    if (doc.images[i].name == name)
      return doc.images[i];
  for (i = 0; i < doc.layers.length; i++)
    if ((img = findImage(name, doc.layers[i].document)) != null) {
      img.container = doc.layers[i];
      return img;
    }
  return null;
}

function getImagePageLeft(img) {
  var x, obj;
  if (NS4 || NS6) {
    if (img.container != null)
      return img.container.pageX + img.x - 1;
    else
      return img.x - 1;
  }
  if (IE4) {
    x = 0;
    obj = img;
    while (obj.offsetParent != null) {
      x += obj.offsetLeft;
      obj = obj.offsetParent;
    }
    x += obj.offsetLeft;
    return x;
  }
  return -1;
}

function getImagePageTop(img) {
  var y, obj;
  if (NS4 || NS6) {
    if (img.container != null)
      return img.container.pageY + img.y;
    else
      return img.y;
  }
  if (IE4) {
    y = 0;
    obj = img;
    while (obj.offsetParent != null) {
      y += obj.offsetTop;
      obj = obj.offsetParent;
    }
    y += obj.offsetTop;
    return y;
  }
  return -1;
}

//SEARCH FUNCTION
function qsearch()
{
var strVal = document.forms[0].query.value;
var i;
var len = strVal.length;
var strOK = false;

for (i = 0; i < len; i++) {
   if (strVal.charAt(i) != " ") {
     strOK = true;
    break;
   }
}

if (strOK == "1") {
// if (document.forms[0].query.value != "") {
	newwindow=window.open("");
	newwindow.location.href='http://search.bjc.org/soyd_search.asp?col=SOYD&q=' + document.forms[0].query.value;
	document.forms[0].action = 'http://search.bjc.org/soyd_search.asp?col=SOYD&q=' + document.forms[0].query.value;
 }	
 return false;
}

//SCHEDULING FORM VALIDATION
function validateInput() {
	var themessage = "You are required to complete the following fields: ";
	if (document.feedback.firstName.value=="") 
	{
		themessage = themessage + "\n      - your first name";
	}
	if (document.feedback.lastName.value=="") 
	{
		themessage = themessage + "\n      - your last name";
	}
	if  ( ((document.feedback.phone1.value=="") || (document.feedback.phone2.value=="") || (document.feedback.phone3.value=="")) && ((document.feedback.fax1.value=="") || (document.feedback.fax2.value=="") || (document.feedback.fax3.value=="")) && (document.feedback.email.value=="") )
		{
		themessage = themessage + "\n      - your complete contact information";
		}
	if ((document.feedback.address.value=="") || (document.feedback.city.value=="") || (document.feedback.zip1.value=="")) 
		{
		themessage = themessage + "\n      - your complete mailing address";
		}

	// alert if fields are empty and cancel form submit
	if (themessage == "You are required to complete the following fields: ") 
	{
	document.feedback.submit();
	}
	else {
	alert(themessage);
	return false;
	}
}


//OBESITY REGISTRATION VALIDATION
function validateInputOB() {
	var themessage = "You are required to complete the following fields: ";
	if (document.feedback.firstName.value=="") 
	{
		themessage = themessage + "\n      - your first name";
	}
	if (document.feedback.lastName.value=="") 
	{
		themessage = themessage + "\n      - your last name";
	}
	if  ( ((document.feedback.phone1.value=="") || (document.feedback.phone2.value=="") || (document.feedback.phone3.value=="")) && ((document.feedback.fax1.value=="") || (document.feedback.fax2.value=="") || (document.feedback.fax3.value=="")) && (document.feedback.email.value=="") )
		{
		themessage = themessage + "\n      - your complete contact information";
		}
	if ((document.feedback.address.value=="") || (document.feedback.city.value=="") || (document.feedback.zip1.value=="")) 
		{
		themessage = themessage + "\n      - your complete mailing address";
		}
    if (RadioValue(feedback.PreferredMethodContact) == "E-Mail")
    {
        if (document.feedback.email.value == "")
        {
            themessage = themessage + "\n      - your preferred method of contact is e-mail but your e-mail address is missing.";
        }
    }

	// alert if fields are empty and cancel form submit
	if (themessage == "You are required to complete the following fields: ") 
	{
	document.feedback.submit();
	}
	else {
	alert(themessage);
	return false;
	}
}


function RadioValue(radio) {
  for (var i = 0; i < radio.length; i++) {
     if (radio[i].checked) {
        return radio[i].value;
     }
  }
}

//AUTO-TAB
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;
}
