// JavaScript Document
// Author - M Mahoney

// Preload Images for slideshow start.
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];}}
}
// Preload Images for slideshow end.

// Invisalign rollover code start.
function mouseOver1(){
	document.invisalign1.src ="http://www.thewhytehouse.com/images/invisalign/treatment1animation.gif";
}

function mouseOut1(){
	document.invisalign1.src ="http://www.thewhytehouse.com/images/invisalign/treatment1thumb.gif";
}

function mouseOver2(){
	document.invisalign2.src ="http://www.thewhytehouse.com/images/invisalign/treatment2animation.gif";
}

function mouseOut2(){
	document.invisalign2.src ="http://www.thewhytehouse.com/images/invisalign/treatment2thumb.gif";
}

function mouseOver3(){
	document.invisalign3.src ="http://www.thewhytehouse.com/images/invisalign/treatment3animation.gif";
}

function mouseOut3(){
	document.invisalign3.src ="http://www.thewhytehouse.com/images/invisalign/treatment3thumb.gif";
}

function mouseOver4(){
	document.invisalign4.src ="http://www.thewhytehouse.com/images/invisalign/treatment4animation.gif";
}

function mouseOut4(){
	document.invisalign4.src ="http://www.thewhytehouse.com/images/invisalign/treatment4thumb.gif";
}

function mouseOver5(){
	document.invisalign5.src ="http://www.thewhytehouse.com/images/invisalign/treatment5animation.gif";
}

function mouseOut5(){
	document.invisalign5.src ="http://www.thewhytehouse.com/images/invisalign/treatment5thumb.gif";
}

function mouseOver6(){
	document.invisalign6.src ="http://www.thewhytehouse.com/images/invisalign/treatment6animation.gif";
}

function mouseOut6(){
	document.invisalign6.src ="http://www.thewhytehouse.com/images/invisalign/treatment6thumb.gif";
}
// Invisalign rollover code end.

// Validation code start.
function validateFeedback() {
var myindexa = document.frmFeedback.txtPrefixName.selectedIndex
		
	if (myindexa == false) {
	    window.alert("Please select a prefix name");
		document.frmFeedback.txtPrefixName.focus()
		return false;
    }
	
	if (document.frmFeedback.txtFirstName.value.length < 1) {
		window.alert("Please enter your first name");
		document.frmFeedback.txtFirstName.focus()
		return false;
	}
	
	if (document.frmFeedback.txtLastName.value.length < 1) {
		window.alert("Please enter your last name");
		document.frmFeedback.txtLastName.focus()
		return false;
	}

	if (document.frmFeedback.txtTownCity.value.length < 1) {
		window.alert("Please enter your city/town");
		document.frmFeedback.txtTownCity.focus()
		return false;
	}

	if (document.frmFeedback.txtFeedback.value.length < 1) {
		window.alert("Please enter your feedback");
		document.frmFeedback.txtFeedback.focus()
		return false;
	}
	
return true;
}

function validateQuestion() {
var myindexa = document.frmQuestion.txtPrefixName.selectedIndex
		
	if (myindexa == false) {
	    window.alert("Please select a prefix name");
		document.frmQuestion.txtPrefixName.focus()
		return false;
    }
	
	if (document.frmQuestion.txtFirstName.value.length < 1) {
		window.alert("Please enter your first name");
		document.frmQuestion.txtFirstName.focus()
		return false;
	}
	
	if (document.frmQuestion.txtLastName.value.length < 1) {
		window.alert("Please enter your last name");
		document.frmQuestion.txtLastName.focus()
		return false;
	}

	if (document.frmQuestion.txtEmailAddress.value.length < 1) {
		window.alert("Please enter your email address");
		document.frmQuestion.txtEmailAddress.focus()
		return false;
	}
               if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.frmQuestion.txtEmailAddress.value)){

                 }else{
               window.alert("Invalid email address, please re-enter.")
			   document.frmQuestion.txtEmailAddress.focus()
               return false;
               }
			   
	if (document.frmQuestion.txtQuestion.value.length < 1) {
		window.alert("Please enter your question");
		document.frmQuestion.txtQuestion.focus()
		return false;
	}
	
return true;
}

function validateForm() {
var myindexa = document.frmDetails.txtPrefixName.selectedIndex
		
	if (myindexa == false) {
	    window.alert("Please select a prefix name");
		document.frmDetails.txtPrefixName.focus()
		return false;
    }
	
	if (document.frmDetails.txtFirstName.value.length < 1) {
		window.alert("Please enter your first name");
		document.frmDetails.txtFirstName.focus()
		return false;
	}
	
	if (document.frmDetails.txtLastName.value.length < 1) {
		window.alert("Please enter your last name");
		document.frmDetails.txtLastName.focus()
		return false;
	}

	if (document.frmDetails.txtAddress1.value.length < 1) {
		window.alert("Please enter your address");
		document.frmDetails.txtAddress1.focus()
		return false;
	}

	if (document.frmDetails.txtCity.value.length < 1) {
		window.alert("Please enter your city/town");
		document.frmDetails.txtCity.focus()
		return false;
	}

	if (document.frmDetails.txtPostCode.value.length < 1) {
		window.alert("Please enter your postal code");
		document.frmDetails.txtPostCode.focus()
		return false;
	}

	if (document.frmDetails.txtEmailAddress.value.length < 1) {
		window.alert("Please enter your email address");
		document.frmDetails.txtEmailAddress.focus()
		return false;
	}
               if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(frmDetails.txtEmailAddress.value)){

                 }else{
               window.alert("Invalid email address, please re-enter.")
			   document.frmDetails.txtEmailAddress.focus()
               return false;
               }
	
return true;
}

function validateRequest() {
var myindexa = document.frmDetails.txtPrefixName.selectedIndex
		
	if (myindexa == false) {
	    window.alert("Please select a prefix name");
		document.frmDetails.txtPrefixName.focus()
		return false;
    }
	
	if (document.frmDetails.txtFirstName.value.length < 1) {
		window.alert("Please enter your first name");
		document.frmDetails.txtFirstName.focus()
		return false;
	}
	
	if (document.frmDetails.txtLastName.value.length < 1) {
		window.alert("Please enter your last name");
		document.frmDetails.txtLastName.focus()
		return false;
	}

	if (document.frmDetails.txtTelephone.value.length < 1) {
		window.alert("Please enter your telephone number");
		document.frmDetails.txtTelephone.focus()
		return false;
	}
	
return true;
}

function validateTestimonial() {
var myindexa = document.frmTestimonial.txtCategoryID.selectedIndex
		
	if (myindexa == false) {
	    window.alert("Please select a category");
		document.frmTestimonial.txtCategoryID.focus()
		return false;
    }
	
	if (document.frmTestimonial.txtTestimonial.value.length < 1) {
		window.alert("Please enter the testimonial");
		document.frmTestimonial.txtTestimonial.focus()
		return false;
	}
	
	if (document.frmTestimonial.txtFrom.value.length < 1) {
		window.alert("Please enter the patient's name");
		document.frmTestimonial.txtFrom.focus()
		return false;
	}

	if (document.frmTestimonial.txtLocation.value.length < 1) {
		window.alert("Please enter the patient's location");
		document.frmTestimonial.txtLocation.focus()
		return false;
	}
	
return true;
}

function validateFileUpload() {
var myindexa = document.frmFileUpload.txtCategoryID.selectedIndex
var myindexb = document.frmFileUpload.txtProcedureID.selectedIndex
		
	if (myindexa == false) {
	    window.alert("Please select a category");
		document.frmFileUpload.txtCategoryID.focus()
		return false;
    }
	
	if (myindexb == false) {
	    window.alert("Please select a procedure");
		document.frmFileUpload.txtProcedureID.focus()
		return false;
    }
	
	if (document.frmFileUpload.File1.value.length < 1) {
		window.alert("Please enter the location of the 'before' photo");
		document.frmFileUpload.File1.focus()
		return false;
	}

	if (document.frmFileUpload.File2.value.length < 1) {
		window.alert("Please enter the location of the 'after' photo");
		document.frmFileUpload.File2.focus()
		return false;
	}
	
return true;
}
// Validation code end.

// Slide show
// Browser Slide-Show script. With image cross fade effect for those browsers
// that support it.
// Script copyright (C) 2004-2008 www.cryer.co.uk.
// Script is free to use provided this copyright header is included.
var FadeDurationMS=1000;
function SetOpacity(object,opacityPct)
{
  // IE.
  object.style.filter = 'alpha(opacity=' + opacityPct + ')';
  // Old mozilla and firefox
  object.style.MozOpacity = opacityPct/100;
  // Everything else.
  object.style.opacity = opacityPct/100;
}
function ChangeOpacity(id,msDuration,msStart,fromO,toO)
{
  var element=document.getElementById(id);
  var msNow = (new Date()).getTime();
  var opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
  if (opacity>=100)
  {
    SetOpacity(element,100);
    element.timer = undefined;
  }
  else if (opacity<=0)
  {
    SetOpacity(element,0);
    element.timer = undefined;
  }
  else 
  {
    SetOpacity(element,opacity);
    element.timer = window.setTimeout("ChangeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")",10);
  }
}
function FadeInImage(foregroundID,newImage,backgroundID)
{
  var foreground=document.getElementById(foregroundID);
  if (foreground.timer) window.clearTimeout(foreground.timer);
  if (backgroundID)
  {
    var background=document.getElementById(backgroundID);
    if (background)
    {
      if (background.src)
      {
        foreground.src = background.src; 
        SetOpacity(foreground,100);
      }
      background.src = newImage;
      background.style.backgroundImage = 'url(' + newImage + ')';
      background.style.backgroundRepeat = 'no-repeat';
      var startMS = (new Date()).getTime();
      foreground.timer = window.setTimeout("ChangeOpacity('" + foregroundID + "'," + FadeDurationMS + "," + startMS + ",100,0)",10);
    }
  } else {
    foreground.src = newImage;
  }
}
var slideCache = new Array();
function RunSlideShow(pictureID,backgroundID,imageFiles,displaySecs)
{
  var imageSeparator = imageFiles.indexOf(";");
  var nextImage = imageFiles.substring(0,imageSeparator);
  FadeInImage(pictureID,nextImage,backgroundID);
  var futureImages = imageFiles.substring(imageSeparator+1,imageFiles.length)+ ';' + nextImage;
  setTimeout("RunSlideShow('"+pictureID+"','"+backgroundID+"','"+futureImages+"',"+displaySecs+")",displaySecs*1000);
  // Cache the next image to improve performance.
  imageSeparator = futureImages.indexOf(";");
  nextImage = futureImages.substring(0,imageSeparator);
  if (slideCache[nextImage] == null)
  {
    slideCache[nextImage] = new Image;
    slideCache[nextImage].src = nextImage;
  }
}

// Slide show