﻿var nameElem = null;
var emailElem = null;
var commentsElem = null;
function ValidateAndSubmit(pgnum) {
    nameElem = document.form1.tbName;
    emailElem = document.form1.tbEmail;
    nameElem.value = trim(nameElem.value);
    emailElem.value = trim(emailElem.value);
    commentsElem = document.form1.tbComments;
    commentsElem.value = trim(commentsElem.value);
    if (nameElem.value == "") {
        alert("Please provide your name");
        nameElem.focus();
        return false;
    }
    if (emailElem.value == "") {
        alert("Please provide your email address so that we may contact you back");
        emailElem.focus();
        return false;
    }

    if (emailElem.value != "" && !isValidEmail(emailElem.value)) {
        alert("Please provide a valid email address.");
        emailElem.select();
        return false;
    }

    document.form1.btnSubmit.disabled = true;
    if (pgnum == "1") {
        Products_AzureDiagnosticsManager_Default.SaveComments(document.form1.uid.value, commentsElem.value, true, nameElem.value, emailElem.value, SaveComments_CallBack)
    }
    else {
        Products_AzureDiagnosticsManager_Details.SaveComments(document.form1.uid.value, commentsElem.value, true, nameElem.value, emailElem.value, SaveComments_CallBack)
    }
    alert("Thank you for your interest in Azure Diagnostics Manager. We will get back to you in 24-48 hours.");
    ResetForm();
    return false;
}

function SaveComments_CallBack(resp) {
    respVal = resp.value;
    return false;
}

function ResetForm() {
    document.form1.reset();
    document.form1.btnSubmit.disabled = false;
    return false;
}