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];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
    window.open(theURL,winName,features);
}
// JS Calendar
var calendar = null; // remember the calendar object so that we reuse
// it and avoid creating another

// This function gets called when an end-user clicks on some date
function selected(cal, date) {
	cal.sel.value = date; // just update the value of the input field
}		
// And this gets called when the end-user clicks on the _selected_ date,
// or clicks the "Close" (X) button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
	cal.hide();			// hide the calendar

	// don't check mousedown on document anymore (used to be able to hide the
	// calendar when someone clicks outside it, see the showCalendar function).
	Calendar.removeEvent(document, "mousedown", checkCalendar);
}

// This gets called when the user presses a mouse button anywhere in the
// document, if the calendar is shown.  If the click was outside the open
// calendar this function closes it.
function checkCalendar(ev) {
	var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
	for (; el != null; el = el.parentNode)
	// FIXME: allow end-user to click some link without closing the
	// calendar.  Good to see real-time stylesheet change :)
	if (el == calendar.element || el.tagName == "A") break;
	if (el == null) {
		// calls closeHandler which should hide the calendar.
		calendar.callCloseHandler(); Calendar.stopEvent(ev);
	}
}		
// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
function showCalendar(id) {
	var el = document.getElementById(id);
	// alert(el.value);
	if (el.value == 'dd/mm/yyyy') {
		el.value = '';
	}
	if (calendar != null) {
		// we already have one created, so just update it.
		calendar.hide();		// hide the existing calendar
		calendar.parseDate(el.value); // set it to a new date
	} else {
		// first-time call, create the calendar
		var cal = new Calendar(true, null, selected, closeHandler);
		calendar = cal;		// remember the calendar in the global
		cal.setRange(2010, 2012);	// min/max year allowed
		calendar.create();		// create a popup calendar
		calendar.parseDate(el.value); // set it to a new date
	}
	calendar.sel = el;		// inform it about the input field in use
	calendar.showAtElement(el);	// show the calendar next to the input field

	// catch mousedown on the document
	Calendar.addEvent(document, "mousedown", checkCalendar);
	return false;
}		

function filterNonNumeric(field) {
var result = new String();
var numbers = "0123456789";
var chars = field.value.split(""); // create array 
	for (i = 0; i < chars.length; i++) {
	if (numbers.indexOf(chars[i]) != -1) result += chars[i];
	}
	if (field.value != result) field.value = result;
}

var agent  = navigator.userAgent.toLowerCase();
var isNN = (agent.indexOf("netscape")!=-1);
var isOpera = (agent.indexOf("opera")!=-1);
var isIE = (agent.indexOf("msie") != -1);

function autoTab(eCtrl,len, e) {
   var keyCode;
   var filter;

   if (isOpera | isIE)
   {
      keyCode = e.keyCode;
      filter = [0,8,9,16,17,18,37,38,39,40,46];
   }
   else if (isNN)
   {
      keyCode = e.which;
      filter = [0,8,9];
   } else {
      keyCode = e.which;
      filter = [0,8,9];
	}

   if(eCtrl.value.length >= len && !containsElement(filter,keyCode))
   {
      eCtrl.value = eCtrl.value.slice(0, len);
      eCtrl.form[(getIndex(eCtrl)+1) % eCtrl.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(eCtrl)
   {

      var index = -1, i = 0, found = false;

      while (i < eCtrl.form.length && index == -1)

         if (eCtrl.form[i] == eCtrl) index = i;
         else i++;

      return index;
   }
   
   return true;
}

//------------------- for clearing and replacing text in form input fields and textareas -------------------//
function clearText(thefield, basevalue) {
  if (thefield.defaultValue==basevalue) { thefield.value = "" }
} 
function replaceText(thefield, basevalue) {
  if (thefield.value=="") { thefield.value = basevalue }
}

function changeTime(){
	var frm = document.forms["book"];
	if(frm.ba_location.value == 'Toronto'){
		frm.ba_appointmentTime1.options[6].disabled = true;
		frm.ba_appointmentTime2.options[6].disabled = true;
		frm.ba_appointmentTime1.options[10].disabled = true;
		frm.ba_appointmentTime2.options[10].disabled = true;
	}
	else{
		frm.ba_appointmentTime1.options[6].disabled = false;
		frm.ba_appointmentTime2.options[6].disabled = false;
		frm.ba_appointmentTime1.options[10].disabled = false;
		frm.ba_appointmentTime2.options[10].disabled = false;
	}
}

/*-------------------------------------------- from index.php ------------------------------------ */
		var bookopen = 'no';
		var candidateopen = 'no';

		function openCloseBook () {
			if (bookopen == 'yes') {
				var myEffects = new Fx.Styles('bookslider', {duration: 1000, transition: Fx.Transitions.linear});
				myEffects.start({ 'top': [-66] });		
				bookopen = 'no';	
			} else {
				var myEffects = new Fx.Styles('bookslider', {duration: 1000, transition: Fx.Transitions.linear});
				myEffects.start({ 'top': [0] });		
				bookopen = 'yes';	
			}
		}
		function openCloseCandidate () {
			if (candidateopen == 'yes') {
				var myEffects = new Fx.Styles('candidateslider', {duration: 1000, transition: Fx.Transitions.linear});
				myEffects.start({ 'top': [-68] });		
				candidateopen = 'no';	
			} else {
				var myEffects = new Fx.Styles('candidateslider', {duration: 1000, transition: Fx.Transitions.linear});
				myEffects.start({ 'top': [0] });		
				candidateopen = 'yes';	
			}
		}		
		
		function is_AC_FL_RunContent () {
				if (AC_FL_RunContent == 0) {
					alert("This page requires AC_RunActiveContent.js.");
				} else {
					AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0','width','334','height','260','id','bochner_video','align','middle','src','bochner_video_v3','quality','high','bgcolor','#ffffff','name','bochner_video','allowscriptaccess','sameDomain','allowfullscreen','false','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','bochner_video_v3' ); //end AC code
				}
		}


//------------------- pop-up windows (for book cover images) -------------------//

function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=820,height=620,scrollbars=yes');
return false;
}
//------------------- pop-up windows (for multi-video videoplayer i.e. Dr. Raymond's styled by jury link -----------//
function videoPopup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=698,height=410,scrollbars=no');
return false;
}