var async = false;
function getHTTPRequestObject()
{
	xmlhttp = false;
	
	try
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(E)
		{
			xmlhttp = false;
		}
	}
	if(!xmlhttp && window.XMLHttpRequest != "undefined")
	{
			xmlhttp = new XMLHttpRequest();
			async = true;
	}
	return xmlhttp;
}	

	
function replaceImages(procedure, patientID, maxpics)
{
	imageName = "images/" + procedure + "/Patient " + patientID + "/" + procedure;
	divID = "largeImages";

	btnClick1(imageName, divID, procedure, patientID);

	divID = "thumbnailImages";

	btnClick2(imageName, divID, procedure, patientID, maxpics);
				
	document.getElementById('photoCaption').innerHTML = " Patient " + patientID;
	return false;
}

function btnClick1(imageName, divID, procedure, patientID)
{
	xmlhttp1 = getHTTPRequestObject();
	
	if(xmlhttp1)
	{
		xmlhttp1.open("GET", "procedures_template.php?procedure=" + procedure + "&patient_number=" + patientID, async);
		xmlhttp1.onreadystatechange = function()
		{
			if(xmlhttp1.readyState == 4)
			{
				if(xmlhttp1.status == 200)
				{
					callback1(imageName, divID, procedure, patientID);
				}
				else
				{
				alert("oops...");
				}
			}
		}
		xmlhttp1.send(null);
	}
}

function callback1(imageName, divID, procedure, patientID)
{
	replacementString = "";
	
	imgSrc = imageName + "1.gif";

	replacementString = replacementString + '<a href="' + imgSrc + '" name="href_1" id="href_1" class="highslide" onclick="return hs.expand(this)">';
	replacementString = replacementString + '<img src="' + imgSrc + '" width="400" height="156" name="image_1" id="image_1" alt="' + procedure + ' Patient ' + patientID + '"';
	replacementString = replacementString + 'title="Click to enlarge" />';
	replacementString = replacementString + '</a>';

	document.getElementById(divID).innerHTML = replacementString;
}

function btnClick2(imageName, divID, procedure, patientID, maxpics)
{
	xmlhttp2 = getHTTPRequestObject();
	
	if(xmlhttp2)
	{
		xmlhttp2.open("GET", "procedures_template.php?procedure=" + procedure + "&patient_number=" + patientID, async);
		xmlhttp2.onreadystatechange = function()
		{
			if(xmlhttp2.readyState == 4)
			{
				if(xmlhttp2.status == 200)
				{
					callback2(imageName, divID, maxpics);
				}
				else
				{
				alert("oops...");
				}
			}
		}
		xmlhttp2.send(null);
	}
}

function callback2(imageName, divID, maxpics)
{
	replacementString = "";
	
	for (i=1; i<=maxpics; i++) {
		imgSrc = imageName + i + ".gif"; 
		
		replacementString = replacementString + '<a href="#_top" onMouseOver="change(\'' + imgSrc + '\')">';
		replacementString = replacementString + "<img src='" + imgSrc + "' border='0' width='177' height='67'>";
		replacementString = replacementString + '</a>';
				
		replacementString = replacementString + '<font size="1"><br>&nbsp;<br></font>';
	}
	document.getElementById(divID).innerHTML = replacementString;
}

var lastfull="";
var lastpartial="";

function displayFullParagraph(paragraphname) {
fullname = paragraphname + "full";
partialname = paragraphname + "partial";

document.getElementById(fullname).style.display = 'inline';
document.getElementById(fullname).style.align = 'left';
document.getElementById(partialname).style.display = 'none';

if(lastfull!="") {
document.getElementById(lastpartial).style.display = 'inline';
document.getElementById(lastpartial).style.align = 'left';
document.getElementById(lastfull).style.display = 'none';
}
lastfull=fullname;
lastpartial=partialname;

return false;
}

	
// Make clickable elements appear so on hover.
//$(document).ready(function() {
//  $('h2, div.button, div.label, span.more, p:eq(2)').hover(function() {
//    $(this).addClass('hover');
//  }, function() {
//    $(this).removeClass('hover');
//  });
//});


function randomImages(){
  if(counter == (imgs.length)){
    counter = 0;
  }
  MM_swapImage('rotator', '','imgs%5Bcounter%2B%2B%5D');
  setTimeout('randomImages()', delay);
}

function echeck(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1)
	{
		return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	{
		return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	{
		return false;
	}

	if (str.indexOf(at,(lat+1))!=-1)
	{
		return false;
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	{
		return false;
	}

	if (str.indexOf(dot,(lat+2))==-1)
	{
		return false;
	}
		
	if (str.indexOf(" ")!=-1)
	{
		return false;
	}
 	return true;	
}

function checkInternationalPhone(strPhone) {
	var digits = "0123456789";
	var minDigitsInIPhoneNumber = 10;
	var phoneNumberDelimiters = "()- ";
	var validWorldPhoneChars = phoneNumberDelimiters + "+";

	s = stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function stripCharsInBag(s, bag) {
    var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function isInteger(s) {   
    var i;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    return true;
}

function ValidateForm() {
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf('netscape') > -1) {
		theform = document.forms[formName];
	} else {
		theform = document.forms[0];
	}

	if ((theform.email.value == null)||(theform.email.value == ""))
	{
		alert("Please enter an email address");
		theform.email.focus();
		return false;
	}

	if (echeck(emailID.value)==false)
	{
		theform.email.value = '';
		theform.email.focus();
		return false;
	}

	if ((theform.contact_home_phone.value==null) || (theform.contact_home_phone.value == ""))
	{
		alert("Please enter your phone number");
		theform.contact_home_phone.focus();
		return false;
	}

	if (checkInternationalPhone(theform.contact_home_phone.value) == false)
	{
		alert("Please enter a valid phone number");
		theform.contact_home_phone.value="";
		theform.contact_home_phone.focus();
		return false;
	}

	return true;
}

function determineTimeZone() {
	var today = new Date();
	var year = y2k(today.getYear());

	var DSTstart = new Date(year,4-1,NthDay(1,1,4,year),2,0,0);
	var DSTend   = new Date(year,10-1,NthDay(-1,1,10,year),2,0,0);

	var todayMS = getMS(today);
	var DSTstartMS = getMS(DSTstart);
	var DSTendMS = getMS(DSTend);
	
	var timeZoneOffsets = new Array(0,0,0,1,2,2,3,3.5,4,5,5,6,7,8,9,9.5,10,11,12,-11,-10,-9,-8.0,-7.0,-7.0,-6,-5,-5,-4,-3.5,-3,-3,-1);
	var timeZoneNames = new Array('Greenwich Mean Time','Universal Coordinated Time','Universal Coordinated Time','European Central Time','Eastern European Time','(Arabic) Egypt Standard Time','Eastern African Time','Middle East Time','Near East Time','Pakistan Lahore Time','India Standard Time','Bangladesh Standard Time','Vietnam Standard Time','China Taiwan Time','Japan Standard Time','Australia Central Time','Australia Eastern Time','Solomon Standard Time','New Zealand Standard Time','Midway Islands Time','Hawaii Standard Time','Alaska Standard Time','Pacific Standard Time','Phoenix Standard Time','Mountain Standard Time','Central Standard Time','Eastern Standard Time','Indiana Eastern Standard Time','Puerto Rico and US Virgin Islands Time','Canada Newfoundland Time','Argentina Standard Time','Brazil Eastern Time','Central African Time');
	var timeZoneAbbreviations = new Array('GMT','UCT','UTC','ECT','EET','ART','EAT','MET','NET','PLT','IST','BST','VST','CTT','JST','ACT','AET','SST','NST','MIT','HST','AST','PST','PNT','MST','CST','EST','IET','PRT','CNT','AGT','BET','CAT');

	var curDateTime = new Date();
	var visitorOffset = -(curDateTime.getTimezoneOffset()/60.0);
	for (var i = 0; i < timeZoneOffsets.length; i++) {
		if (timeZoneOffsets[i]==visitorOffset) break;
	}
	if (todayMS > DSTstartMS && todayMS < DSTendMS) { i--; }

	return timeZoneAbbreviations[i];
}

function openWindow(url, name, width, height) {
	var popupWin;
	if (popupWin && !popupWin.closed) {
               popupWin.close();
	}

	var attr = 'scrollbars=no,status=yes,width=' + width + ',height= ' + height  +',left=1,top=1,resizable=1';
   	popupWin = window.open(url, name, attr);
	popupWin.focus();
}

//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_validateForm() { //v4.0
//  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
//  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
//    if (val) { nm=val.name; if ((val=val.value)!='') {
//      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
//        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
//      } else if (test!='R') { num = parseFloat(val);
//        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
//        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
//          min=test.substring(8,p); max=test.substring(p+1);
//          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
//    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
//  } if (errors) alert('The following error(s) occurred:\n'+errors);
//  document.MM_returnValue = (errors == '');
//}

function escapeTextString(tempString) {
	var temp = escape(tempString);
	temp = temp.replace(/\"/g, '&#034');
      temp = temp.replace(/&/g, '&#038');
	temp = temp.replace(/\'/g, '&#039');
	temp = temp.replace(/\+/g, '&#043');
	temp = temp.replace(/\,/g, '&#044');
      temp = temp.replace(/\//g, '&#047');
	temp = temp.replace(/\=/g, '&#061');
      temp = temp.replace(/\?/g, '&#063');
      temp = temp.replace(/@/g, '&#064');
      return temp;
}

function LTrim(str) {
   var whitespace = new String(' \t\n\r');

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0, i = s.length;

      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      s = s.substring(j, i);
   }
   return s;
}

function RTrim(str) {
   var whitespace = new String(' \t\n\r');

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;

      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }
   return s;
}

function Trim(str) {
   return RTrim(LTrim(str));
}

function parseQueryString() {
  var str = (window.location.search);
  var query = str.charAt(0) == '?' ? str.substring(1) : str;

  var args = new Object();
  if (query) {
    var fields = query.split('&');
    for (var f = 0; f < fields.length; f++) {
      var field = fields[f].split('=');

   args[unescape(field[0].replace(/\+/g, ' '))] = unescape(field[1].replace(/\+/g, ' '));
    }
  }
  var tempString = args['fieldValues'];
  
  var fieldValues = tempString.split(',');
  
  document.forms[0].contact_title.selectedIndex = fieldValues[0];
  document.forms[0].contact_first_name.value = fieldValues[1];
  document.forms[0].contact_last_name.value = fieldValues[2];
  document.forms[0].contact_home_phone.value = fieldValues[3];
  document.forms[0].email.value = fieldValues[4];
  document.forms[0].procedure_of_interest.value = fieldValues[5];
  document.forms[0].referenced_by.selectedIndex = fieldValues[6];
  document.forms[0].contact_comments.value = unescape(fieldValues[7]);
}

function __doPostBack(formName) {

	var theform;
	if (window.navigator.appName.toLowerCase().indexOf('netscape') > -1) {
		theform = document.forms[formName];
	} else {
		theform = document.forms[0];
	}
		theform.submit();
}

function checkForm(formName) {
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf('netscape') > -1) {
		theform = document.forms[formName];
	} else {
		theform = document.forms[0];
	}

	if(formName == 'contactus') {
		errorParameters0 = 'http://www.drstevebrown.com/newerror.php?';
	} else {
		errorParameters0 = 'http://www.drstevebrown.com/error.php?';
	}

	errorParameters1 = 'errors=';

	titleIndex = theform.contact_title.selectedIndex;
	errorParameters2 = 'fieldValues=' + titleIndex;

	if ((theform.contact_first_name.value == null) || (theform.contact_first_name.value == ''))
		errorParameters1 = errorParameters1 + 'contact_first_name,';
	errorParameters2 = errorParameters2 + ',' + escapeTextString(theform.contact_first_name.value);

	if ((theform.contact_last_name.value == null) || (theform.contact_last_name.value == ''))
		errorParameters1 = errorParameters1 + 'contact_last_name,';
	errorParameters2 = errorParameters2 + ',' + escapeTextString(theform.contact_last_name.value);

	//if ((theform.contact_home_phone.value == null) || (theform.contact_home_phone.value == ''))
	if ((theform.contact_home_phone.value == null) || (theform.contact_home_phone.value == '') || (checkInternationalPhone(theform.contact_home_phone.value) == false))
		errorParameters1 = errorParameters1 + 'contact_home_phone,';
	errorParameters2 = errorParameters2 + ',' + escapeTextString(theform.contact_home_phone.value);	//if ((theform.email.value==null) || (theform.email.value==''))

	if ((theform.email.value==null) || (theform.email.value=='') || (echeck(theform.email.value) == false))
		errorParameters1 = errorParameters1 + 'email,';
	errorParameters2 = errorParameters2 + ',' + escapeTextString(theform.email.value);

	errorParameters2 = errorParameters2 + ',' + escapeTextString(theform.procedure_of_interest.value);
	
	referenceIndex = theform.referenced_by.selectedIndex;
	errorParameters2 = errorParameters2 + ',' + referenceIndex;

	var tempString = escapeTextString(theform.contact_comments.value);
	//tempString = tempString.replace(/\"/g, '&#034');
      //tempString = tempString.replace(/&/g, '&#038');
	//tempString = tempString.replace(/\'/g, '&#039');
	//tempString = tempString.replace(/\+/g, '&#043');
	//tempString = tempString.replace(/\,/g, '&#044');
      //tempString = tempString.replace(/\//g, '&#047');
	//tempString = tempString.replace(/\=/g, '&#061');
      //tempString = tempString.replace(/\?/g, '&#063');
      //tempString = tempString.replace(/@/g, '&#064');

	errorParameters2 = errorParameters2 + ',' + escape(tempString);
	
	errorParameters1 = errorParameters1.substring(0, errorParameters1.length - 1);
	
	missingFieldString = errorParameters0 + 'sendingForm=' + formName + '&' + errorParameters1 + '&' + errorParameters2;

	theform.missing_fields_redirect.value = missingFieldString;

	theform.realname.value = escapeTextString(theform.contact_first_name.value) + ' ' + escapeTextString(theform.contact_last_name.value);

	if (titleIndex==0)
		theform.contact_title.options[0].value='';

	if (referenceIndex==0)
		theform.referenced_by.options[0].value='';

	if (theform.contact_comments.value=='Type your question here')
		theform.contact_comments.value='';

    if (theform.contact_comments.value=='')
	{
		theform.recipient.value = "drbrown1@drstevebrown.com";
	} else {
		theform.recipient.value = "drbrown@drstevebrown.com";
	};
		 
	getParameters = 'http://www.drstevebrown.com/confirmation.php';
	getParameters = getParameters + '?contact_title=' + theform.contact_title.options[titleIndex].value; 
	getParameters = getParameters + '&contact_first_name=' + Trim(theform.contact_first_name.value);
	getParameters = getParameters + '&contact_last_name=' + Trim(theform.contact_last_name.value);
	getParameters = getParameters + '&contact_home_phone=' + Trim(theform.contact_home_phone.value);
	getParameters = getParameters + '&email=' + Trim(theform.email.value);
	getParameters = getParameters + '&procedure_of_interest=' + Trim(theform.procedure_of_interest.value);
	getParameters = getParameters + '&referenced_by=' + escapeTextString(theform.referenced_by.options[referenceIndex].value);
	getParameters = getParameters + '&contact_comments=' + escape(tempString);
	//getParameters = getParameters + '&referrer=' + document.referrer;
	theform.redirect.value = getParameters;
	
	theform.submit();
}

function getCalendarDate() {
   var months = new Array(13);
   months[0]  = "January";
   months[1]  = "February";
   months[2]  = "March";
   months[3]  = "April";
   months[4]  = "May";
   months[5]  = "June";
   months[6]  = "July";
   months[7]  = "August";
   months[8]  = "September";
   months[9]  = "October";
   months[10] = "November";
   months[11] = "December";
   var now         = new Date();
   var monthnumber = now.getMonth();
   var monthname   = months[monthnumber];
   var monthday    = now.getDate();
   var year        = now.getYear();
   if(year < 2000) { year = year + 1900; }
   var dateString = monthname + 
                    ' ' + 
                    monthday + 
                    ', ' + 
                    year;
   return dateString;
}

function getClockTime() {
   var now    = new Date();
   var hour   = now.getHours();
   var minute = now.getMinutes();
   var second = now.getSeconds();
   var ap = "AM";
   if (hour   > 11) { ap = "PM";             }
   if (hour   > 12) { hour = hour - 12;      }
   if (hour   == 0) { hour = 12;             }
   if (hour   < 10) { hour   = "0" + hour;   }
   if (minute < 10) { minute = "0" + minute; }
   if (second < 10) { second = "0" + second; }
   var timeString = hour + 
                    ':' + 
                    minute + 
                    ':' + 
                    second + 
                    " " + 
                    ap;
   return timeString;
}

function getTimeDate() {
	var abc;
	
	abc = '<STRONG>Your message was sent on ' + getCalendarDate() + '<br />at ' + getClockTime() + '</STRONG>';
	document.all.dateTime.innerHTML = abc;
}

function makeArray() {
    this[0] = makeArray.arguments.length;
    for (i = 0; i<makeArray.arguments.length; i++)
        this[i+1] = makeArray.arguments[i];
}

var daysofmonth   = new makeArray( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var daysofmonthLY = new makeArray( 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

function LeapYear(year) {
    if ((year/4)   != Math.floor(year/4))   return false;
    if ((year/100) != Math.floor(year/100)) return true;
    if ((year/400) != Math.floor(year/400)) return false;
    return true;
}

function NthDay(nth,weekday,month,year) {
    if (nth > 0) {
		return (nth-1)*7 + 1 + (7 + weekday - DayOfWeek((nth-1)*7 + 1,month,year))%7;
	}
    if (LeapYear(year)) {
		var days = daysofmonthLY[month];
    } else {
        var days = daysofmonth[month];
    }
    return days - (DayOfWeek(days,month,year) - weekday + 7)%7;
}

function DayOfWeek(day,month,year) {
    var a = Math.floor((14 - month)/12);
    var y = year - a;
    var m = month + 12*a - 2;
    var d = (day + y + Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400) + Math.floor((31*m)/12)) % 7;
    return d+1;
}

function y2k(number) {
	return (number < 1000) ? number + 1900 : number;
}

function getMS(date) {
    return Date.UTC(y2k(date.getYear()),date.getMonth(),date.getDate(),date.getHours(),date.getMinutes(),date.getSeconds())
}

function Fade(objID1, CurrentAlpha1, TargetAlpha1, objID2, CurrentAlpha2, TargetAlpha2, steps) {
          var obj1 = document.getElementById(objID1);
          var obj2 = document.getElementById(objID2);
          
          CurrentAlpha1 = parseInt(CurrentAlpha1);
          if (isNaN(CurrentAlpha1)) {
               CurrentAlpha1 = parseInt(obj1.style.opacity*100);
               if (isNaN(CurrentAlpha1)) CurrentAlpha1=100;
          }

          CurrentAlpha2 = parseInt(CurrentAlpha2);
          if (isNaN(CurrentAlpha2)) {
               CurrentAlpha2 = parseInt(obj2.style.opacity*100);
               if (isNaN(CurrentAlpha2)) CurrentAlpha2=100;
          }
          
          var DeltaAlpha1 = parseInt((CurrentAlpha1-TargetAlpha1)/steps);
          var NewAlpha1 = CurrentAlpha1 - DeltaAlpha1;

          var DeltaAlpha2 = parseInt((CurrentAlpha2-TargetAlpha2)/steps);
          var NewAlpha2 = CurrentAlpha2 - DeltaAlpha2;
          
          if (NewAlpha1 == 100 && (navigator.userAgent.indexOf('Gecko') != -1 && navigator.userAgent.indexOf('Safari') == -1)) NewAlpha1 = 99.99;

          obj1.style.opacity = (NewAlpha1 / 100);
          obj1.style.MozOpacity = obj1.style.opacity;
          obj1.style.KhtmlOpacity = obj1.style.opacity;
          obj1.style.filter = 'alpha(opacity='+NewAlpha1+')';

          if (NewAlpha2 == 100 && (navigator.userAgent.indexOf('Gecko') != -1 && navigator.userAgent.indexOf('Safari') == -1)) NewAlpha2 = 99.99;

          obj2.style.opacity = (NewAlpha2 / 100);
          obj2.style.MozOpacity = obj2.style.opacity;
          obj2.style.KhtmlOpacity = obj2.style.opacity;
          obj2.style.filter = 'alpha(opacity='+NewAlpha2+')';
          
          if (steps > 1) {
               setTimeout('Fade("' + objID1 + '", ' + NewAlpha1 + ', ' + TargetAlpha1 + ', "' + objID2 + '", ' + NewAlpha2+', ' + TargetAlpha2 + ', '+(steps-1) + ')', 50);
          }
}

var bName = navigator.appName;
 var bVer = parseInt(navigator.appVersion);
 var NS6 = (bName == "Netscape" && bVer >= 5);
 var Fox = (bName == "Netscape" && navigator.userAgent.indexOf('Firefox') != -1);
 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("bodymap");
 if (NS6) {
	x = 0;
	y = 0;
 }
 else 
 {
 	if (NS4 || IE4) {
		x = 2;
		y = 18;
 	}
 }

 switch(layerName) {
 case "Face":
 		height = 311;
	break;
 case "Breast":
 		height = 409;
	break;
 case "Body":
 		height = 451;
	break;
 case "Skin":
 		height = 551;
	break;
}

 menuTop = y + height ; // LAYER TOP POSITION
 FaceL = x + 510 ; // 'Face' LAYER LEFT POSITION
 BreastL = x + 787 ;  // 'Breast' LAYER LEFT POSITION
 BodyL = x + 516 ;  // 'Body' LAYER LEFT POSITION
 SkinL = x + 801 ;  // 'Skin' LAYER LEFT POSITION

if (NS4 || IE4 || NS6 || Fox) {
 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 || Fox) {
 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)", 300)

 }// 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;
  var ilist = doc.images;
  for (i = 0; i < doc.images.length; i++) {
    if (ilist[i].name == name) {
      return ilist[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;
}

function show_div(div_id) {
	if(div_id == 'PhotoGallerySubMenu' || div_id == 'FinancingSubMenu') {
		if(div_id == 'PhotoGallerySubMenu') {
			currentState = document.getElementById('PhotoGallerySubMenu').style.display;
		} else {
			currentState = document.getElementById('FinancingSubMenu').style.display;
		}
		if(currentState == 'block') {
			document.images["twisty1"].src = "images/twistyright.gif";
			document.getElementById('PhotoGallerySubMenu').style.display = 'none';
		} else {
			document.images["twisty1"].src = "images/twistydown.gif";
			document.getElementById('PhotoGallerySubMenu').style.display = 'block';
		}
	} else {
		currentState = document.getElementById('FacilitiesSubMenu').style.display;
			if(currentState == 'block') {
				document.images["twisty2"].src = "images/twistyright.gif";
				document.getElementById('FacilitiesSubMenu').style.display = 'none';
			} else {
				document.images["twisty2"].src = "images/twistydown.gif";
				document.getElementById('FacilitiesSubMenu').style.display = 'block';
			}
	}	
}

expandingid1 = 0;
expandingid2 = 0;
expandingstep = 0;
expandingwidth = 0;
expandingheight = 0;
expandingtop1 = 0;
expandingleft1 = 0;
expandingtop2 = 0;
expandingleft2 = 0;
expandingtimeout = 0;
expandingtotalsteps = 16;

function expandthumbs1(thumbid1, i, yoffset, fullwidth, fullheight) {
  if (expandingtimeout != 0) {
    clearTimeout(expandingtimeout);
  }
  if (expandingid1 > 0 && expandingid1 != thumbid1) {
    restorethumbs1();
  }
  if (expandingid1 != thumbid1) {
    img1 = document.getElementById("screen" + thumbid1);
    img1.style.display = 'block';
    expandingid1 = thumbid1;
    expandingstep = 1;
    expandingwidth = fullwidth;
    expandingheight = fullheight;
	if(document.all && typeof document.body.scrollTop != "undefined") {
  		jogLeft = (i % 2) ? 2 : -90;
		expandingtop1 = img1.offsetTop + yoffset + 1;
		expandingleft1 = img1.offsetLeft + jogLeft;
	}
	else
	{
		expandingtop1 = img1.offsetTop + yoffset - 135;
		expandingleft1 = img1.offsetLeft + 96;
	}
  } else if (expandingstep < 1) {
    expandingstep = 1;
  }
  expandstep1();
}

function doexpand1() {
  img1 = document.getElementById("screen" + expandingid1);
  thumb1 = document.getElementById(expandingid1);

  myscroll1 = getScroll();
  if (expandingtop1 + thumb1.height > myscroll1.top + myscroll1.height) {
    finaltop1 = myscroll1.top + myscroll1.height - expandingheight;
  } else {
    finaltop1 = expandingtop1 + thumb1.height - expandingheight;
  }
  if (finaltop1 < myscroll1.top) { finaltop1 = myscroll1.top; }
  img1.style.top = finaltop1 + ((expandingtop1 - finaltop1) * (expandingtotalsteps - expandingstep) / expandingtotalsteps) + 'px';

  if (expandingleft1 + thumb1.width > myscroll1.left + myscroll1.width) {
    finalleft1 = myscroll1.left + myscroll1.width - expandingwidth;
  } else {
    finalleft1 = expandingleft1 + thumb1.width - expandingwidth;
  }
  
  if (finalleft1 < myscroll1.left) { finalleft1 = myscroll1.left; }
  img1.style.left = finalleft1 + ((expandingleft1 - finalleft1) * (expandingtotalsteps - expandingstep) / expandingtotalsteps) + 'px';

  img1.width = thumb1.width + ((expandingwidth - thumb1.width) * expandingstep / expandingtotalsteps);
  img1.height = thumb1.height + ((expandingheight - thumb1.height) * expandingstep / expandingtotalsteps);
}

function reducethumbs1(thumbid1) {
  var date = new Date();
  var curDate = null;
  
  do { curDate = new Date(); } 
	while(curDate-date < 20);
  
  if (expandingtimeout != 0) {
	
    clearTimeout(expandingtimeout);
  }
  if (expandingstep > 0) {
    reducestep1();
  }
}

function restorethumbs1() {
  img1 = document.getElementById("screen" + expandingid1);
  img1.style.top = '';
  img1.style.left = '';
  img1.style.display = 'none';
  expandingid1 = 0;
  document.getElementById('expandreduce').innerHTML = "<font color='black'>Click to enlarge</font>";
}

function expandstep1() {
  expandingtimeout = 0;
  doexpand1();
  if (expandingstep < expandingtotalsteps) {
    expandingstep++;
    expandingtimeout = setTimeout("expandstep1()", 20);
  }
  //document.getElementById('expandreduce').innerHTML = "<font color='red'>Click to reduce</font>";
}

function reducestep1() {
  expandingtimeout = 0;
  doexpand1();
  if (expandingstep > 0) {
    expandingstep--;
    expandingtimeout = setTimeout("reducestep1()", 20);
  } else {
    restorethumbs1();
  }
}

function expandthumbs(thumbid1, thumbid2, fullwidth, fullheight) {
  if (expandingtimeout != 0) {
    clearTimeout(expandingtimeout);
  }
  if (expandingid1 > 0 && expandingid1 != thumbid1) {
    restorethumbs();
  }
  if (expandingid1 != thumbid1) {
    img1 = document.getElementById("screen" + thumbid1);
    img1.style.display = 'block';
    img2 = document.getElementById("screen" + thumbid2);
    img2.style.display = 'block';
    expandingid1 = thumbid1;
    expandingid2 = thumbid2;
    expandingstep = 1;
    expandingwidth = fullwidth;
    expandingheight = fullheight;
	if(document.all && typeof document.body.scrollTop != "undefined") {
		expandingtop1 = img1.offsetTop;
		expandingtop2 = img2.offsetTop;
		expandingleft1 = img1.offsetLeft-202;
	}
	else
	{
		expandingtop1 = img1.offsetTop-160;
		expandingtop2 = img2.offsetTop-160;
		expandingleft1 = img1.offsetLeft+40;
	}
	expandingleft2 = img2.offsetLeft+2
  } else if (expandingstep < 1) {
    expandingstep = 1;
  }
  expandstep();
}

function doexpand() {
  img1 = document.getElementById("screen" + expandingid1);
  thumb1 = document.getElementById(expandingid1);
  img2 = document.getElementById("screen" + expandingid2);
  thumb2 = document.getElementById(expandingid2);

  myscroll1 = getScroll();
  if (expandingtop1 + thumb1.height > myscroll1.top + myscroll1.height) {
    finaltop1 = myscroll1.top + myscroll1.height - expandingheight;
  } else {
    finaltop1 = expandingtop1 + thumb1.height - expandingheight;
  }
  if (finaltop1 < myscroll1.top) { finaltop1 = myscroll1.top; }
  img1.style.top = finaltop1 + ((expandingtop1 - finaltop1) * (expandingtotalsteps - expandingstep) / expandingtotalsteps) + 'px';

  if (expandingleft1 + thumb1.width > myscroll1.left + myscroll1.width) {
    finalleft1 = myscroll1.left + myscroll1.width - expandingwidth;
  } else {
    finalleft1 = expandingleft1 + thumb1.width - expandingwidth;
  }
  
  if (finalleft1 < myscroll1.left) { finalleft1 = myscroll1.left; }
  img1.style.left = finalleft1 + ((expandingleft1 - finalleft1) * (expandingtotalsteps - expandingstep) / expandingtotalsteps) + 'px';

  img1.width = thumb1.width + ((expandingwidth - thumb1.width) * expandingstep / expandingtotalsteps);
  img1.height = thumb1.height + ((expandingheight - thumb1.height) * expandingstep / expandingtotalsteps);
  
  myscroll2 = getScroll();
  if (expandingtop2 + thumb2.height > myscroll2.top + myscroll2.height) {
    finaltop2 = myscroll2.top + myscroll2.height - expandingheight;
  } else {
    finaltop2 = expandingtop2 + thumb2.height - expandingheight;
  }
  if (finaltop2 < myscroll2.top) { finaltop2 = myscroll2.top; }
  img2.style.top = finaltop2 + ((expandingtop2 - finaltop2) * (expandingtotalsteps - expandingstep) / expandingtotalsteps) + 'px';
  
  if (expandingleft2 + thumb2.width > myscroll2.left + myscroll2.width) {
    finalleft2 = myscroll2.left + myscroll2.width - expandingwidth;
  } else {
    finalleft2 = expandingleft2 + thumb2.width - expandingwidth;
  }
  
  if (finalleft2 < myscroll2.left) { finalleft2 = myscroll2.left; }
  img2.style.left = finalleft2 + ((expandingleft2 - finalleft2) * (expandingtotalsteps - expandingstep) / expandingtotalsteps) + 'px';
  if(document.all && typeof document.body.scrollTop != "undefined") {
    img2.style.left = '428px';
  }
  else
  {
  	img2.style.left = '430px';
  }
  img2.width = thumb2.width + ((expandingwidth - thumb2.width) * expandingstep / expandingtotalsteps);
  img2.height = thumb2.height + ((expandingheight - thumb2.height) * expandingstep / expandingtotalsteps);
}

function restorethumbs() {
  img1 = document.getElementById("screen" + expandingid1);
  img2 = document.getElementById("screen" + expandingid2);
  img1.style.top = '';
  img2.style.top = '';
  img1.style.left = '';
  img2.style.left = '';
  img1.style.display = 'none';
  img2.style.display = 'none';
  expandingid1 = 0;
  expandingid2 = 0;
  document.getElementById('expandreduce').innerHTML = "<font color='black'>Click to enlarge</font>";
}

function expandstep() {
  expandingtimeout = 0;
  doexpand();
  if (expandingstep < expandingtotalsteps) {
    expandingstep++;
    expandingtimeout = setTimeout("expandstep()", 20);
  }
  document.getElementById('expandreduce').innerHTML = "<font color='red'>Click to reduce</font>";
}

function reducestep() {
  expandingtimeout = 0;
  doexpand();
  if (expandingstep > 0) {
    expandingstep--;
    expandingtimeout = setTimeout("reducestep()", 20);
  } else {
    restorethumbs();
  }
}

function reducethumbs(thumbid1, thumbid2) {
  var date = new Date();
  var curDate = null;
  
  do { curDate = new Date(); } 
	while(curDate-date < 20);
  
  if (expandingtimeout != 0) {
	
    clearTimeout(expandingtimeout);
  }
  if (expandingstep > 0) {
    reducestep();
  }
}

// returns the scroll position and size of the browser
function getScroll() {
  if (document.all && typeof document.body.scrollTop != "undefined") {  
    // IE model
    var ieBox = document.compatMode != "CSS1Compat";
    var cont = ieBox ? document.body : document.documentElement;
    return {
      left:   cont.scrollLeft,
      top:    cont.scrollTop,
      width:  cont.clientWidth,
      height: cont.clientHeight
    };
  } else {
    return {
      left:   window.pageXOffset,
      top:    window.pageYOffset,
      width:  window.innerWidth,
      height: window.innerHeight
    };
  }
}
