/**
* This script is for the flyout menu, but it looks like it is totally uneeded
*/
$(document).ready(function() {

$("#nav li").mouseover(function(){
    $(this).removeClass().addClass(" sfhover");
});
$("#nav li").mouseout(function(){
    $(this).removeClass();
});
$("#newsName").focus(function(){
    $(this).val('');
});
$("#newsName").blur(function(){
    if($(this).val() == ''){
        $(this).val('name');   
    }
});
$("#newsEmail").focus(function(){
    $(this).val('');
});
$("#newsEmail").blur(function(){
    if($(this).val() == ''){
        $(this).val('email address');   
    }


/**
* Autotab for phone numbers
*/
$("#phone1").autotab({target: "phone2",format:"numeric"});
$("#phone2").autotab({target: "phone3",format:"numeric"});

});

/**
* This script finds the page we are on and then sets the header image to active
*/
var pathname = window.location.pathname;

pathname = pathname.split('/');
pathname = pathname[(pathname.length -1)];
//alert(pathname);
switch(pathname){ 
    case 'index.php':
        $("#HomeLink").removeClass().addClass('active');
        break;
    case 'meet-the-doctor.php':
        $("#MeetTheDrLink").removeClass().addClass('active');
        $("#MeetTheDrLink").attr('style','background-position: -85px -55px;');
        break;
    case 'our-office.php':
        $("#OfficeLink").removeClass().addClass('active');
        $("#OfficeLink").attr('style','background-position: -260px -55px;');
        break;
    case 'services.php':
        $("#ServicesLink").removeClass().addClass('active');
        $("#ServicesLink").attr('style','background-position: -388px -55px;');
        break;
    case 'set-an-appointment.php':
        $("#appointmentLink").removeClass().addClass('active');
        $("#appointmentLink").attr('style','background-position: -495px -55px;');
        //scripts to set the date in the selects to tomorrow
        var date = new Date();
        $("#formMonth").val(date.getMonth()+1);
        $("#formDay").val(date.getDate()+1);
        $("#formYear").val(date.getFullYear());
        break;
    case 'directions.php':
        $("#directionsLink").removeClass().addClass('active');
        $("#directionsLink").attr('style','background-position: -697px -55px;');
        break;
    case 'Contact.php':
        $("#contactLink").removeClass().addClass('active');
        $("#contactLink").attr('style','background-position: -815px -55px;');
        break;
    default:
        $("#HomeLink").removeClass().addClass('active');
        break;    
}
});
function validate(form){
    var validation = $("#"+form).validate({
        rules: {
                    full_name: {
                        required: true
                    },
                    email_address:{
                        required: true,
                        email: true
                    },
                    phone1:{
                        required: true,
                        digits: true
                    },
                    phone2:{
                        required: true,
                        digits: true
                    },
                    phone3:{
                        required: true,
                        digits: true
                    }
                },
        messages:{
                phone1: "",
                phone2: "",
                newsName: "",
                newsEmail: "",
        }    
    });
	
	
	
    if(validation.form()){
        if(form == 'dateForm'){
            var aptDate = $("#formMonth").val()+"/"+$("#formDay").val()+"/"+$("#formYear").val();
            var phone = "("+$("#phone1").val()+")"+$("#phone2").val()+"-"+$("#phone3").val();
            //email the information to receptionist
            $.post("mailer.php",{'name':$("#full_name").val(),'email':$('#email_address').val(),'phone':phone,'text':$("#TextArea1").val(),'appointment':aptDate,'weekDay':$("#week_day :selected").text(),'time':$("#time :selected").text(),'flex':$("#flex :selected").text()}, function(data){
                if(data == 'success'){
                    $('#dateForm').html('<br /><br /><div style=\"font-size:15pt;color:red;padding-left:15px;font-weight:bold;border: 1px solid #C0C0C0;\">Thank you for your submission.</div><br /><br />');
                    scroll(0,0);
                    /*alert('The office will contact you shortly.');*/
                }else{
                    alert(data);
                }
            });    
        }else if(form == 'commentForm'){
             //email the information to receptionist
            $.post("mailer.php",{'name':$("#full_name").val(),'email':$('#email_address').val(),'text':$("#TextArea1").val()}, function(data){
                if(data == 'success'){
                    $('#commentForm').html('<div style=\"font-size:15pt;color:red;padding-left:15px;border: 1px solid #C0C0C0;\">Thank you for your submission.</div><br /><br />');
                    /*alert('The office will contact you shortly.'); */
                }else{
                    alert(data);
                }
            });
        }else if(form == 'newsletter'){
            $.post("mailer.php",{'name':$("#newsName").val(),'email':$('#newsEmail').val()}, function(data){
                if(data == 'success'){
                    $('#newsletter').html('<div style=\"font-size:15pt;color:red;padding-left:15px;\">Thank you for your submission.</div><br /><br />');
                    /*alert('The office will contact you shortly.');*/
                }else{
                    alert(data);
                }
            });    
        }
        
    }

}

