// JavaScript Document
$(function(){
    $('.menu #navigation li.menu_box').mouseover(function() {
       $(this).children(':first').css({"background-image":"url(skins/images/nav_tab_over.png)"});
    }).mouseout(function() {
       if($(this).hasClass('active') === true){
        $(this).children(':first').css({"background-image":"url(skins/images/nav_tab_on.gif)"});
       } else {
        $(this).children(':first').css({"background-image":"url(skins/images/nav_tab_standard.gif)"});
       }

    });
   
    $('.slideshow').cycle({
        fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
        timeout: 5000 
    });
});

function submit_hospital_finder(value){
    document.location.href = value;
}

function send_contact_back_form(){

    if(document.getElementById('callback_name').value == '' || document.getElementById('callback_name').value == ' Your name'){
        alert("Enter your contact name.");
    } else if(document.getElementById('callback_telephone').value == '' || document.getElementById('callback_telephone').value == ' Your Telephone Number'){
        alert("Enter your contact telephone number.");
    } else{
        document.contact_back_form.submit();
    }

}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function check_contact_form(){
 
    if(document.contact_form.name.value == ''){
        alert("Enter your name.");
    } else if(document.contact_form.email.value == '') {
        alert("Enter your email address.");
    } else if(checkemail(document.contact_form.email.value) == false) {
        alert("Enter valid email address.");
    } else if(document.contact_form.subject.value == '') {
        alert("Enter subject of your message.");
    } else if(document.contact_form.message.value == '') {
        alert("Enter your message.");
    } else {
        document.contact_form.submit();
    }

}

function checkemail(str){
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if (filter.test(str))
        return true;
    else{
        return false;
    }
}

function validate_contact_us_form() {
    if (document.contact_us_form.firstname.value == '') {
        alert("You have not entered first name.");
        return;
    } else if (document.contact_us_form.lastname.value == '') {
        alert("You have not entered last name.");
        return;
    } else if (checkemail(document.contact_us_form.email.value) == false) {
        alert("You have not entered valid email.");
        return;
    } else if (document.contact_us_form.phone.value == '') {
        alert("You have not entered phone.");
        return;
    } else {
        document.contact_us_form.submit();
    }
}

function validate_free_consultation_form() {
    if (document.free_consultation_form.firstname.value == '') {
        alert("You have not entered first name.");
        return;
    } else if (document.free_consultation_form.lastname.value == '') {
        alert("You have not entered last name.");
        return;
    } else if (checkemail(document.free_consultation_form.email.value) == false) {
        alert("You have not entered valid email.");
        return;
    } else if (document.free_consultation_form.phone.value == '') {
        alert("You have not entered phone.");
        return;
    } else if (document.free_consultation_form.hospital.value == '') {
        alert("You have not entered hospital.");
        return;
    } else if (document.free_consultation_form.preferred_date.value == '') {
        alert("You have not entered preferred date.");
        return;
    } else {
        document.contact_us_form.submit();
    }
} 

function validate_finance_contact_us_form() {
    if (document.finance_contact_us_form.name.value == '') {
        alert("You have not entered name.");
        return;
    } else if (document.finance_contact_us_form.phone.value == '') {
        alert("You have not entered phone.");
        return;
    } else if (checkemail(document.finance_contact_us_form.email.value) == false) {
        alert("You have not entered valid email.");
        return;
    } else {
        document.finance_contact_us_form.submit();
    }
}

function validate_form121process() {

    if (document.form121process.firstname.value == '') {
        alert("You have not entered first name.");
        return;
    } else if (document.form121process.lastname.value == '') {
        alert("You have not entered last name.");
        return;
    } else if (checkemail(document.form121process.email.value) == false) {
        alert("You have not entered valid email.");
        return;
    } else if (document.form121process.phone.value == '') {
        alert("You have not entered phone.");
        return;
    } else if (document.form121process.hospital.value == '') {
        alert("You have not entered hospital name.");
        return;
    } else if (document.form121process.date.value == '') {
        alert("You have not entered preferred date.");
        return;
    } else {
        document.form121process.submit();
    }

}

function validate_newsletter_signup() {

    if (document.newsletter_signup.newsletter_name.value == '') {
        alert("You have not entered your name.");
        return;
    } else if (checkemail(document.newsletter_signup.newsletter_email.value) == false) {
        alert("You have not entered valid email.");
        return;
    } else {
        document.newsletter_signup.submit();
    }

}

function validate_gp_referral_form() {

    if (document.gp_referral_form.gp_name.value == '') {
        alert("You have not entered GP name.");
        return;
    } else if (checkemail(document.gp_referral_form.patient_email.value) == false) {
        alert("You have not entered valid patients email.");
        return;
    } else {
        document.gp_referral_form.submit();
    }

}

function validate_video_comment_form() {

    if (document.video_comment_form.name.value == '') {
        alert("You have not entered your name.");
        return;
    } else if (checkemail(document.video_comment_form.email.value) == false) {
        alert("You have not entered valid email.");
        return;
    } else if (document.video_comment_form.message.value == '') {
        alert("You have not entered your comment.");
        return;
    } else {
        document.video_comment_form.submit();
    }

}

function validate_podcast_comment_form(){

    if (document.podcast_comment_form.name.value == '') {
        alert("You have not entered your name.");
        return;
    } else if (checkemail(document.podcast_comment_form.email.value) == false) {
        alert("You have not entered valid email.");
        return;
    } else if (document.podcast_comment_form.message.value == '') {
        alert("You have not entered your comment.");
        return;
    } else {
        document.podcast_comment_form.submit();
    }

}

function validate_news_comment_form(){

    if (document.news_comment_form.name.value == '') {
        alert("You have not entered your name.");
        return;
    } else if (checkemail(document.news_comment_form.email.value) == false) {
        alert("You have not entered valid email.");
        return;
    } else if (document.news_comment_form.message.value == '') {
        alert("You have not entered your comment.");
        return;
    } else {
        document.news_comment_form.submit();
    }

}

function validate_tell_your_story_form(){

    if (document.tell_your_story_form.name.value == '') {
        alert("You have not entered your name.");
        return;
    } else if (checkemail(document.tell_your_story_form.email.value) == false) {
        alert("You have not entered valid email.");
        return;
    } else if (document.tell_your_story_form.story.value == '') {
        alert("You have not entered your story.");
        return;
    } else {
        document.tell_your_story_form.submit();
    }

}

function set_delivery_info(svalue){
    if(svalue == "By post"){
        $('#delivery_address').show();
        $('#delivery_postcode').show();
    } else {
        $('#delivery_address').hide();
        $('#delivery_address').val('');
        $('#delivery_postcode').hide();
        $('#delivery_postcode').val('');
    }
}

function validate_request_pack_form() {
    if (document.request_pack_form.firstname.value == '') {
        alert("You have not entered first name.");
        return;
    } else if (document.request_pack_form.lastname.value == '') {
        alert("You have not entered last name.");
        return;
    } else if (checkemail(document.request_pack_form.email.value) == false) {
        alert("You have not entered valid email.");
        return;
    } else if (document.request_pack_form.phone.value == '') {
        alert("You have not entered phone.");
        return;
    } else {

        if (document.request_pack_form.how_to_send_pack.value == 'By post') {
            if (document.request_pack_form.address.value == '') {
                alert("Enter delivery address.");
                return;
            } else if (document.request_pack_form.postcode.value == '') {
                alert("Enter delivery postcode.");
                return;
            }
        }

        document.request_pack_form.submit();
    }
}
function side_nav_change(id, image){
    $("#"+id).css("background-image", "url("+image+")");
}
