function ValidateEmail(theinput){
    var s=theinput;
    if(s.search)
        return (s.search(new RegExp("^([-!#$%&'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,4}$","gi"))>=0);
    if(s.indexOf)
    {
        at_character=s.indexOf('@');
        if(at_character<=0 || at_character+4>s.length)
            return false;
    }
    if(s.length<6)
        return false;
    else
        return true;
}
 
/************************************************
 bool ValidateName(string input)
 Return true or false
 if the email is valid or not.
**************************************************/
function ValidateName(theinput){
    var s=theinput;
    if(s.search)
        return (s.search(new RegExp("^[^&'^`]+$","gi"))>=0);
    if(s.length<3)
        return false;
    else
        return true;
}
 
/************************************************
 bool ValidatePhone(string input)
 Return true or false
 if the phone number is valid or not.
 acepts - and + symbols
**************************************************/
function ValidatePhone(theinput){
    var s=theinput;
    if(s.search)
        return (s.search(new RegExp("[-+0-9]+","gi"))>=0);
    if(s.length<5)
        return false;
    else
        return true;
}
 

function CheckContactFrm(){
    var error="";
	


    if(!ValidateName(document.ContactFrm.Name.value))
        error+="Full Name\n";
    if(document.ContactFrm.Address.value=="")
        error+="Address\n";
    if(document.ContactFrm.City.value=="")
        error+="City\n";
    if(document.ContactFrm.State.value=="")
        error+="State\n";
    if(document.ContactFrm.Zip.value=="")
        error+="Zip\n";
    if(!ValidateEmail(document.ContactFrm.email.value))
        error+="Email\n";
    if(!ValidatePhone(document.ContactFrm.Phone.value))
        error+="Phone\n";
    if(document.ContactFrm.Comments.value=="")
        error+="Specific Needs\n";


    if(error!="")
        alert("Error! Please check:\n"+error);
    else
        document.ContactFrm.submit();
	
    return;
}

function CheckAppointmentFrm(){
    var error="";
	
    if(document.appointment.Prefered_Date.value=="")
        error+="Prefered Date\n";
    if(document.appointment.finaltod.value=="0")
        error+="Prefered Time of Day\n";
    if(!ValidateName(document.appointment.FirstName.value))
        error+="First Name\n";
    if(!ValidateName(document.appointment.LastName.value))
        error+="Last Name\n";
    if(!ValidateEmail(document.appointment.Email.value))
        error+="Email\n";
    if(!ValidatePhone(document.appointment.Phone.value))
        error+="Phone\n";



    if(error!="")
        alert("Error! Please check:\n"+error);
    else
        document.appointment.submit();
	
    return;
}

function dayhidecore(){
    document.getElementById('time1').style.display='none';
    document.getElementById('time2').style.display='none';
    document.getElementById('time3').style.display='none';
    document.getElementById('time4').style.display='none';
    document.getElementById('time5').style.display='none';
    document.getElementById('time6').style.display='none';
    document.getElementById('time7').style.display='none';
    document.getElementById('time8').style.display='none';
    document.getElementById('time9').style.display='none';
        document.getElementById('time10').style.display='none';
        document.getElementById('time11').style.display='none';
        document.getElementById('time12').style.display='none';
     document.getElementById('time13').style.display='none';
    document.getElementById('time14').style.display='none';

}

function checkLocationSelected(){
    if (!document.appointment.Location[1].checked && !document.appointment.Location[0].checked){
        alert('You must choose a location first');
    }
}

function hidedays(){
    if (document.appointment.Location[0].checked){
        if (document.appointment.Prefered_Date.value.substr(0,3)=='Mon'){
            dayhidecore(1);
            document.getElementById('time1').style.display='block';
        }
        if (document.appointment.Prefered_Date.value.substr(0,3)=='Tue'){
            dayhidecore(2);
            document.getElementById('time2').style.display='block';

        }
        if (document.appointment.Prefered_Date.value.substr(0,3)=='Wed'){
            dayhidecore(3);
            document.getElementById('time3').style.display='block';

        }
        if (document.appointment.Prefered_Date.value.substr(0,3)=='Thu'){
            dayhidecore(4);
            document.getElementById('time4').style.display='block';

        }
        if (document.appointment.Prefered_Date.value.substr(0,3)=='Fri'){
            dayhidecore(5);
            document.getElementById('time5').style.display='block';

        }
        if (document.appointment.Prefered_Date.value.substr(0,3)=='Sat'){
            dayhidecore(6);
            document.getElementById('time6').style.display='block';

        }
        if (document.appointment.Prefered_Date.value.substr(0,3)=='Sun'){
            dayhidecore(7);
            document.getElementById('time7').style.display='block';

        }
    } else if (document.appointment.Location[1].checked){
        if (document.appointment.Prefered_Date.value.substr(0,3)=='Mon'){
            dayhidecore(8);
            document.getElementById('time8').style.display='block';

        }
        if (document.appointment.Prefered_Date.value.substr(0,3)=='Tue'){
            dayhidecore(9);
            document.getElementById('time9').style.display='block';

        }
        if (document.appointment.Prefered_Date.value.substr(0,3)=='Wed'){
            dayhidecore(10);
            document.getElementById('time10').style.display='block';

        }
        if (document.appointment.Prefered_Date.value.substr(0,3)=='Thu'){
            dayhidecore(11);
            document.getElementById('time11').style.display='block';

        }
        if (document.appointment.Prefered_Date.value.substr(0,3)=='Fri'){
            dayhidecore(12);
            document.getElementById('time12').style.display='block';

        }
        if (document.appointment.Prefered_Date.value.substr(0,3)=='Sat'){
            dayhidecore(13);
            document.getElementById('time13').style.display='block';

        }
        if (document.appointment.Prefered_Date.value.substr(0,3)=='Sun'){
            dayhidecore(14);
            document.getElementById('time14').style.display='block';

        }

    }
}