﻿// testimonials javascript file
function tm_PreReg() 
{
    jQuery("#tb_testimonialPre").hide();
    jQuery("#tb_testimonialFRM").show();
}


function tm_ValidatePage() {
    var errors = "";
    var form = document.forms[0];
    
    // Hide any existing errors
    jQuery("#testimonial_errors").hide();
    
    // Name
    if (jQuery("#ctl00_PHMainContent_tbName").val() == "") errors = errors + "* Please enter your name.<br/>";
    // Email
    if (jQuery("#ctl00_PHMainContent_tbEmail").val() == "") {
        errors = errors + "* Please enter your email address.<br/>";
    } else if (!validateEmail(jQuery("#ctl00_PHMainContent_tbEmail").val())) {
        errors = errors + "* Please enter a valid email address.<br/>";
    }
    // Product
    if (jQuery("#ctl00_PHMainContent_ddProduct").val() == "0") {
        errors = errors + "* Please select the product used.<br/>";
    }
    // Comments
    if (jQuery("#ctl00_PHMainContent_tbComments").val() == "") {
        errors = errors + "* Please enter your comments.<br/>";
    }
    // T and C
    if (jQuery("input[@name='ctl00$PHMainContent$tandc']:checked").val() == "tandc_no") errors = errors + "* You must accept the Terms &amp; Conditions.";
        
    // Any errors to show?
    if (errors.length > 0)
        jQuery("#testimonial_errors").html(errors).show();
    else
        DoPost();
}

function DoPost() {
    cr_content = jQuery("#testimonial_button").hide();
    // Show wait message...
    jQuery("#testimonial_wait").html("<span class='err'>Submitting your testimonial.... please wait!</span>").show();
    // Do the search...
    DoAjaxRequest("/testimonials/default.aspx?op=1&ts="
        +(encodeURI(jQuery("#ctl00_PHMainContent_cboTerms").val()))
        +"&nm="+(encodeURI(jQuery("#ctl00_PHMainContent_tbName").val()))
        +"&em="+(encodeURI(jQuery("#ctl00_PHMainContent_tbEmail").val()))
        +"&pr="+(encodeURI(jQuery("#ctl00_PHMainContent_ddProduct").val()))
        +"&cm="+(encodeURI(jQuery("#ctl00_PHMainContent_tbComments").val())), "", "EndRequest_DoPost");
}

// End of AJAX postcode lookup request returns here...
function EndRequest_DoPost(result) {
    jQuery("#testimonial_button").show();
    jQuery("#testimonial_wait").hide();
    // Execute any javascript returned..
    Ajax_CheckScriptTags(result);
}
