/* function for opening external links in new window */
window.onload = function () { 
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.target = "_blank";
}
}
/* function to solve z-index bug */
$(document).ready(function() {
var zIndexNumber = 1000;
$('div').each(function() {
$(this).css('zIndex', zIndexNumber);
zIndexNumber -= 10;
});
$("#panel").css('zIndex', '1010');
$("#closeit").css('zIndex', '1020');
$("a.trigger").css('zIndex', '1030');
});
/* functions for main horizontal navigation menu */
$(document).ready(function() {
$("#dentnav li ul").css('display','none');
$("#dentnav li").hover(function () {
$('ul:first',this).stop(true, true).delay(50).slideDown(300);
},function() {
$('ul:first',this).css('left','auto');
$('ul:first',this).stop(true, true).delay(50).slideUp(500);
});
$(window).unload(function() {
$("#dentnav li ul").css('display','none');
});
});
/* functions for dynamically manipulating trigger href values */
$(document).ready(function() {
$("#closeit").html('<a class="trigger2" href="#" title="Close this form">Close</a>');
$("a.trigger").attr("href", "#");
});
/* functions for toggling the slidout consultation form */
$(document).ready(function() {
$("a.trigger").click(function(){
$("#panel").toggle("slow");
$(this).toggleClass("active");
$('#reset').click();
$('#n span').hide();
$('#p span').hide();
$('#e span').hide();
return false;
});
$("a.trigger2").click(function(){
$("#panel").toggle("slow");
$("a.trigger").toggleClass("active");
$('#reset').click();
$('#n span').hide();
$('#p span').hide();
$('#e span').hide();
return false;
});
});
/* functions for validating the slidout consultation form */
$(document).ready(function() {
$('#consult-form').submit( function(){
var efilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var pfilter = /[0-9]/;
var email = document.getElementById('e-mail');
var telephone = document.getElementById('telephone');
if (!efilter.test(email.value)) {
$('#e').html("Email: <span>Enter an email address</span>");
} else {$('#e span').hide();}
if (!pfilter.test(telephone.value)) {
$('#p').html("Phone: <span>Enter a phone number</span>");
} else {$('#p span').hide();}
if (document.cform.namen.value == "") {
$('#n').html("Name: <span>Enter a contact name</span>");
} else {$('#n span').hide();}
if ((document.cform.namen.value == "") || (!efilter.test(email.value)) || (!pfilter.test(telephone.value))) {
return false;
}
if ((document.cform.namen.value != "") && (!efilter.test(email.value)) && (!pfilter.test(telephone.value))) {
return true;
} 
});
$('#n').click(function(){
   $('#consult-form').attr('action', 'http://www.tucsonsmile.com/cgi-bin/consult2mail.cgi');
});
$('input#namen').click(function(){
   $('#consult-form').attr('action', 'http://www.tucsonsmile.com/cgi-bin/consult2mail.cgi');
});
});
/* function to open ImplantVision module in new window */
$(document).ready(function() {
$('a[href="http://implantvision.net/implantvideo/videodisplay.php?id=651"]').click(function() {
window.open($(this).attr('href'),'module', 'toolbar=0,menubar=0,resizable=0,width=640,height=480');
return false;
});   
});
