window.onload = initPage;
var i = 0;

function initPage() {
  externalLinks();
  if(document.getElementById('treatments')) {
    showTreatments();
  }
  addFieldVal('qcname', 'Name*');
  addFieldVal('qcpractice', 'Practice Name*');
  addFieldVal('qcemail', 'Email*');
  addFieldVal('qcenquiry', 'Enquiry*');

  addFieldVal('isname', 'Name*');
  addFieldVal('istel', 'Tel*');
  addFieldVal('isemail', 'Email*');
  addFieldVal('isconcerns', 'Main Concerns*');

  if(document.getElementById('flash')) {
    insertFlashObject('flash', 'flash/banner.swf', 978, 192);
  }

  if(document.getElementById('bottom_flash')) {
    insertFlashObject('bottom_flash', 'flash/bottom_logos.swf', 418, 69);
  }

  if(document.getElementById('flash-teeth1')) {
    insertFlashObject('flash-teeth1', 'flash/161CD_Ortho_Fixed.swf', 196, 150);
  }

  if(document.getElementById('flash-teeth2')) {
    insertFlashObject('flash-teeth2', 'flash/274CD_20Ortho_DAMON.swf', 196, 150);
  }

  if(document.getElementById('flash-teeth3')) {
    insertFlashObject('flash-teeth3', 'flash/interdenta-brushing.swf', 188, 144);
  }

  hideFullTestimonials();

  /*if(document.getElementById('smile_images')) {
    if(document.forms[0].contact_smile_photos[0].checked == false) {
      document.getElementById('smile_images').style.display = "none";
    }
    document.forms[0].contact_smile_photos[0].onclick = showSmileImageFields;
    document.forms[0].contact_smile_photos[1].onclick = hideSmileImageFields;
  }*/
}

/*function () {
  document.getElementById('smile_images').style.display = "block";
}
function hideSmileImageFields() {
  document.getElementById('smile_images').style.display = "none";
}*/

function addBackground() {
  anchorID = 'a' + this.id.substring(1);
  document.getElementById(anchorID).style.backgroundImage = 'url("images/template/menu-selected.jpg")';
  document.getElementById(anchorID).style.backgroundRepeat = 'repeat-x';
  document.getElementById(anchorID).style.backgroundPosition = 'bottom';
  document.getElementById(anchorID).style.color = '#002CD0';
}

function removeBackground() {
  anchorID = 'a' + this.id.substring(1);
  document.getElementById(anchorID).style.backgroundImage = "";
  document.getElementById(anchorID).style.color = '#000000';
}

function externalLinks() {
  if(!document.getElementsByTagName) {
    return;
  }
  var anchors = document.getElementsByTagName("a");
  for(var i=0;i<anchors.length;i++) {
    var anchor = anchors[i];
    if(anchor.getAttribute("href") && anchor.getAttribute("rel") == "external" || anchor.getAttribute("rel") == "external nofollow" ) {
      anchor.target = "_blank";
    }
  }
}

function addFieldVal(element, val) {
  if(document.getElementById(element)) {
    document.getElementById(element).onfocus = function () {clearfield(this, val);};
    document.getElementById(element).onblur = function () {reinstatefield(this, val);};
  }
}

function trim(str, chars) {
  var replaceLeft, replaceRight;
  chars = chars || "\\s";
  replaceLeft = str.replace(new RegExp("^[" + chars + "]+", "g"), "");
  replaceRight = replaceLeft.replace(new RegExp("[" + chars + "]+$", "g"), "");
  return replaceRight;
}

function clearfield(element, val) {
  trimValue = trim(element.value);
  if(trimValue == val) {
    element.value = '';
  }
}

function reinstatefield(element, val) {
  trimValue = trim(element.value);
  if(trimValue == '') {
    element.value = val;
  }
}

// When page loads, hide some of the content within the testimonials (if applicable). If clicked, the full content will be shown.
function hideFullTestimonials() {
  var elements = document.getElementsByTagName("*");

  // loop through the elements on the page, and find out if any of them contain testimonials
  for (var i = 0; i < elements.length; i++) {
    if(elements[i].className.indexOf("testimonial_container_inner") != -1) {
      // alter this testimonial now to make it hidden
      elements[i].style.cursor = "url(images/cursors/zoomin.cur), auto";
      toggleTestimonialVisibility(elements[i]);
      // if the testimonial is clicked, alter it again
      elements[i].onclick = (function(testimonial) { return function() { toggleTestimonialVisibility(testimonial) }; })(elements[i]);
    }
  }
}

// show or hide the full contents of this testimonial based on its current state
function toggleTestimonialVisibility(testimonial) {
  var elements = testimonial.getElementsByTagName("*");

  // loop through all the elements within this testimonial
  for (var i = 0; i < elements.length; i++) {
    // if the element currently has a 'hidden' class, make it visible
    if(elements[i].className.indexOf("testimonial-hidden") != -1) {
      elements[i].className = elements[i].className.replace("testimonial-hidden", "testimonial-visible");
      if(elements[i].className.indexOf('testimonial-readmore') != -1){
        elements[i].style.cursor = "url(images/cursors/zoomin.cur), auto";
        //alert('pop goes the weasel');
      }else{
        //alert(elements[i].className);
        elements[i].style.cursor = "url(images/cursors/zoomout.cur), auto";
      }
      // if the element currently has a 'visible' class, make it hidden
    } else if(elements[i].className.indexOf("testimonial-visible") != -1) {
      elements[i].className = elements[i].className.replace("testimonial-visible", "testimonial-hidden");
    }

    // set 'Read More' text if applicable
    if(elements[i].className.indexOf("testimonial-readmore") != -1 && elements[i].innerHTML == "") {
      elements[i].innerHTML = "Read More &raquo;";
      //alert('mary had a little lamb');
      elements[i].style.cursor = "url(images/cursors/zoomin.cur), auto";
    }

    // Add zoom cursor to testimonial strapline
    if((elements[i].className.indexOf("testimonial-strapline-zoomin") != -1) && (elements[i].style.cursor.length == 0)) {
      elements[i].style.cursor = "url(images/cursors/zoomin.cur), auto";
      // if the element currently has a 'visible' class, make it hidden
    } else if(elements[i].className.indexOf("testimonial-strapline-zoomin") != -1) {
      // If the testimonial opens, set the cursor on the strapline to the zoomout cursor
      elements[i].className = elements[i].className.replace("testimonial-strapline-zoomin", "testimonial-strapline-zoomout");
      elements[i].style.cursor = "url(images/cursors/zoomout.cur), auto";
    } else if(elements[i].className.indexOf("testimonial-strapline-zoomout") != -1) {
      // If the testimonial closes, set the cursor on the strapline to the zoomin cursor
      elements[i].className = elements[i].className.replace("testimonial-strapline-zoomout", "testimonial-strapline-zoomin");
      elements[i].style.cursor = "url(images/cursors/zoomin.cur), auto";
    }
  }
}

function rotate_homepage_banners() {
  i = (i + 1) % 4;
  ajax_update_value('rotatehomepagebanners', 'bannernum=' + i, 'top-banner', 'innerHTML');
}

function showTreatments() {
document.getElementById('treatments').innerHTML = "" +
"<div style=\"width: 498px; padding-top: 15px;\">\r\n" +
"<div class=\"cta_exp\" style=\"width: 247px; padding-right: 4px;\">\r\n" +
"<a href=\"orthodontic-treatments/invisible-incognito-braces.htm\" style=\"padding-bottom: 5px;\">\r\n" +
"Completely invisible braces fixed at the back of your teeth\r\n" +
"</a>\r\n" +
"</div>\r\n" +
"\r\n" +
"<div class=\"cta_exp\" style=\"width: 247px;\">\r\n" +
"<a href=\"orthodontic-treatments/damon-system.htm\" style=\"padding-bottom: 5px;\">\r\n" +
"Innovative gentle braces that avoid the need for tooth removal\r\n" +
"</a>\r\n" +
"</div>\r\n" +
"\r\n" +
"<div style=\"width: 247px; height: 70;\">\r\n" +
"<a href=\"orthodontic-treatments/invisible-incognito-braces.htm\">\r\n" +
"<img src=\"images/content/home_cta_incognito.jpg\" width=\"247\" height=\"70\" alt=\"incognito cta\" title=\"Incognito - Read more\" /></a>\r\n" +
"</div>\r\n" +
"<div style=\"width: 4px; height: 70px;\"></div>\r\n" +
"<div style=\"width: 247px; height: 70;\">\r\n" +
"<a href=\"orthodontic-treatments/damon-system.htm\">\r\n" +
"<img src=\"images/content/home_cta_damon.jpg\" width=\"247\" height=\"70\" alt=\"damon cta\" title=\"Damon - Read more\" /></a>\r\n" +
"</div>\r\n" +
"</div>\r\n" +
"\r\n" +
"<div style=\"width: 498px; padding: 15px 0px;\">\r\n" +
"\r\n" +
"<div style=\"width: 247px; height: 70;\">\r\n" +
"<a href=\"orthodontic-treatments/clearstep-clear-aligners.htm\">\r\n" +
"<img src=\"images/content/home_cta_clear_aligners.jpg\" width=\"247\" height=\"70\" alt=\"clear aligners cta\" title=\"Clear Aligners - Read more\" /></a>\r\n" +
"</div>\r\n" +
"\r\n" +
"<div style=\"width: 4px; height: 70px;\"></div>\r\n" +
"\r\n" +
"<div style=\"width: 247px; height: 70px;\">\r\n" +
"<a href=\"orthodontic-treatments/clear-fixed-braces.htm\">\r\n" +
"<img src=\"images/content/home_cta_ice_clear.jpg\" width=\"247\" height=\"70\" alt=\"ice clear cta\" title=\"Ice Clear - Read more\" /></a>\r\n" +
"</div>\r\n" +
"\r\n" +
"<div class=\"cta_exp\" style=\"width: 247px; padding-right: 4px;\">\r\n" +
"<a href=\"orthodontic-treatments/clearstep-clear-aligners.htm\" style=\"padding-top: 5px;\">\r\n" +
"Removable, wire-free, nearly invisible braces\r\n" +
"</a>\r\n" +
"</div>\r\n" +
"\r\n" +
"<div class=\"cta_exp\" style=\"width: 247px;\">\r\n" +
"<a href=\"orthodontic-treatments/clear-fixed-braces.htm\" style=\"padding-top: 5px;\">\r\n" +
"Fixed braces with discreet, crystal clear brackets\r\n" +
"</a>\r\n" +
"</div>\r\n" +
"\r\n" +
"</div>\r\n";
}

function insertFlashObject(objID, flashLocation, width, height, flashString) {
  var flashObject;
  flashObject = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='" + width + "' height='" + height + "'>";
  flashObject = flashObject + "<param name='wmode' value='transparent'>";
  flashObject = flashObject + "<param name='movie' value='" + flashLocation + "' />";
  flashObject = flashObject + "<param name='quality' value='high' />";
  if(typeof(flashString) == "undefined") {
    flashObject = flashObject + "<embed src='" + flashLocation + "' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' wmode='transparent'>";
  } else {
    flashObject = flashObject + "<param name='FlashVars' value='" + flashString + "'>";
    flashObject = flashObject + "<embed src='" + flashLocation + "' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + width + "' height='" + height + "' wmode='transparent' ";
    flashObject = flashObject + "FlashVars='" + flashString + "'>";
  }
  flashObject = flashObject + "</embed></object>";
  if(document.getElementById(objID)) {
    document.getElementById(objID).innerHTML = flashObject;
  }
}

function change_gallery_image(galleryFolder, imgName, imgTitle) {
  document.getElementById('display_image').src   = 'images/galleries/' + galleryFolder + '/main/' + imgName;
  document.getElementById('display_image').title = imgTitle;
  document.getElementById('display_image').alt   = imgTitle + ' Gallery Image';
  document.getElementById('overlay_link').href   = 'images/galleries/' + galleryFolder + '/large/' + imgName;
}

function display_overlay(url) {
  var objLink = document.createElement('a');
  objLink.setAttribute('href', url);
  objLink.setAttribute('rel', 'overlay');
  jQuery.prototype.start(objLink);
}

// check if email address has been specified; if not, show confirmation message
function checkEmail() {
  var email = document.getElementById('ref_p_email').value;
  if(email == "") {
    var confirmText = "Priority will be given to those patients who have a valid email address.\n\n";
    confirmText += "Therefore, if you have an email address for the patient, or one they can use, whether family, friend or colleague it would be of great help ";
    confirmText += "to both them and us if you could complete this field.  Completing this field would give the patient the best and quickest experience.\n\n";
    confirmText += "The email address allows us to:\n\n* communicate the next steps to the patient\n* distribute the relevant forms the patient needs to complete\n* send email appointment confirmation.\n\n";
    confirmText += "If you would like to submit this form anyway please click OK; otherwise please click on Cancel...";

    // show confirmation message if email wasn't specified
    if(confirm(confirmText)) {
      return true; // OK clicked; proceed with form submission
    } else {
      return false; // Cancel clicked; halt form submission
    }
  }

  // email address was specified, so proceed with form submission
  return true;
}

if(typeof(jQuery) != "undefined") {
(function($) { $.fn.lightBox = function(settings) {
settings = jQuery.extend({
overlayBgColor: '#000000',
overlayOpacity: 0.6,
fixedNavigation: false,
imageLoading: 'images/icons/loading.gif',
imageBtnClose: 'images/buttons/close_button.gif',
imageBlank: 'images/icons/blank.gif',
containerBorderSize: 10,
containerResizeSpeed: 400,
imageArray: [],
activeImage: 0
},settings);
var jQueryMatchedObj = this;function _initialize(){_start(this,jQueryMatchedObj);return false;}function _start(objClicked,jQueryMatchedObj) {
$('embed, object, select').css({'visibility':'hidden'});_set_interface();settings.imageArray.length=0;settings.activeImage=0;
if(jQueryMatchedObj.length==1){settings.imageArray.push(new Array(objClicked.getAttribute('href'),objClicked.getAttribute('title')));}else{
for(var i=0;i<jQueryMatchedObj.length;i++){settings.imageArray.push(new Array(jQueryMatchedObj[i].getAttribute('href'),jQueryMatchedObj[i].getAttribute('title')));}}
while(settings.imageArray[settings.activeImage][0] != objClicked.getAttribute('href')){settings.activeImage++;} _set_image_to_view();}function _set_interface() {
$('body').append('<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="lightbox-container-image-box"><div id="lightbox-container-image"><img id="lightbox-image"><div id="lightbox-loading"><a href="#" id="lightbox-loading-link"><img src="'+settings.imageLoading+'"></a></div></div></div><div id="lightbox-container-image-data-box"><div id="lightbox-container-image-data"><div id="lightbox-image-details"><span id="lightbox-image-details-caption"></span><span id="lightbox-image-details-currentNumber"></span></div><div id="lightbox-secNav"><a href="#" id="lightbox-secNav-btnClose"><img src="'+settings.imageBtnClose+'"></a></div></div></div></div>');
var arrPageSizes = ___getPageSize();$('#jquery-overlay').css({backgroundColor:settings.overlayBgColor,opacity:settings.overlayOpacity,width:arrPageSizes[0],height:arrPageSizes[1]}).fadeIn();var arrPageScroll = ___getPageScroll();
$('#jquery-lightbox').css({top:arrPageScroll[1]+(arrPageSizes[3]/10),left:arrPageScroll[0]}).show();
$('#jquery-overlay,#jquery-lightbox').click(function(){ _finish();});$('#lightbox-loading-link,#lightbox-secNav-btnClose').click(function(){ _finish();return false;});
$(window).resize(function(){var arrPageSizes = ___getPageSize();$('#jquery-overlay').css({width:arrPageSizes[0],height:arrPageSizes[1]});
var arrPageScroll = ___getPageScroll();$('#jquery-lightbox').css({top:arrPageScroll[1]+(arrPageSizes[3]/10),left:arrPageScroll[0]});});}function _set_image_to_view(){$('#lightbox-loading').show();
if(settings.fixedNavigation){$('#lightbox-image,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();}else{
$('#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();}
var objImagePreloader = new Image();objImagePreloader.onload = function(){
$('#lightbox-image').attr('src',settings.imageArray[settings.activeImage][0]);_resize_container_image_box(objImagePreloader.width,objImagePreloader.height);
objImagePreloader.onload=function(){};};objImagePreloader.src = settings.imageArray[settings.activeImage][0];};function _resize_container_image_box(intImageWidth,intImageHeight){
var intCurrentWidth = $('#lightbox-container-image-box').width();var intCurrentHeight = $('#lightbox-container-image-box').height();var intWidth=(intImageWidth+(settings.containerBorderSize*2));var intHeight=(intImageHeight+(settings.containerBorderSize*2));
var intDiffW = intCurrentWidth-intWidth;var intDiffH = intCurrentHeight-intHeight;
$('#lightbox-container-image-box').animate({width:intWidth,height:intHeight},settings.containerResizeSpeed,function(){ _show_image();});
if((intDiffW==0)&&(intDiffH==0)){if($.browser.msie){___pause(250);}else{___pause(100);}}$('#lightbox-container-image-data-box').css({width:intImageWidth});
$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({height:intImageHeight+(settings.containerBorderSize * 2)});};
function _show_image(){$('#lightbox-loading').hide();$('#lightbox-image').fadeIn(function(){_show_image_data();});};
function _show_image_data(){$('#lightbox-container-image-data-box').slideDown('fast');$('#lightbox-image-details-caption').hide();if(settings.imageArray[settings.activeImage][1]){$('#lightbox-image-details-caption').html(settings.imageArray[settings.activeImage][1]).show();}}
function _finish(){$('#jquery-lightbox').remove();$('#jquery-overlay').fadeOut(function(){$('#jquery-overlay').remove();});$('embed, object, select').css({'visibility':'visible'});}
function ___getPageSize() {var xScroll, yScroll;
if(window.innerHeight && window.scrollMaxY){xScroll = window.innerWidth+window.scrollMaxX;yScroll = window.innerHeight+window.scrollMaxY;}else if(document.body.scrollHeight > document.body.offsetHeight){
xScroll = document.body.scrollWidth;yScroll = document.body.scrollHeight;}else{xScroll = document.body.offsetWidth;yScroll = document.body.offsetHeight;}var windowWidth, windowHeight;
if(self.innerHeight){if(document.documentElement.clientWidth){windowWidth = document.documentElement.clientWidth;}else{windowWidth = self.innerWidth;}windowHeight = self.innerHeight;}else if(document.documentElement && document.documentElement.clientHeight){windowWidth = document.documentElement.clientWidth;windowHeight = document.documentElement.clientHeight;}else if(document.body){windowWidth = document.body.clientWidth;windowHeight = document.body.clientHeight;}
if(yScroll < windowHeight){pageHeight = windowHeight;}else{pageHeight = yScroll;}if(xScroll < windowWidth){pageWidth = xScroll;}else{pageWidth = windowWidth;}
arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);return arrayPageSize;};
function ___getPageScroll(){var xScroll, yScroll;if(self.pageYOffset){yScroll = self.pageYOffset; xScroll = self.pageXOffset;
}else if(document.documentElement && document.documentElement.scrollTop){yScroll = document.documentElement.scrollTop; xScroll = document.documentElement.scrollLeft;
}else if(document.body){yScroll = document.body.scrollTop;xScroll = document.body.scrollLeft;}arrayPageScroll = new Array(xScroll,yScroll);
return arrayPageScroll;};function ___pause(ms) { var date = new Date();curDate = null;do { var curDate = new Date();} while(curDate - date < ms);};
return this.unbind('click').click(_initialize);};$(function(){ $('a[@rel*=overlay]').lightBox();});})(jQuery);}
