﻿var $theValue = "Y";
var SubmitS = { "AjaxS": false, "ButtomS": false };
$(function() {
    $("#ctl00_ContentPlaceHolder1_UserEmail").focus(function() {
        SubmitS.AjaxS = false;
        SubmitS.ButtomS = false;
    })
})
function SignUp_Client(oSrc, args) {
    $(".vali").css("color", "#000000");
    $("input[@type!=image]").attr("style", "");
    var temp, formelement;
    var a = 0;
    var ErrMsg = "";
    $("#ctl00_ContentPlaceHolder1_SignUpErr").html("&nbsp;");
    for (var i = 0; i < Page_Validators.length; i++) {
        if (Page_Validators[i].validationGroup == "SignUp" && Page_Validators[i].controltovalidate != undefined) {
            formelement = Page_Validators[i].controltovalidate;
            temp = formelement.replace("ctl00_ContentPlaceHolder1_", "f");
            if (!Page_Validators[i].isvalid && $("#" + formelement).val() != "Select Answer") {
                $("#" + temp).css("color", "#C82D4B");
                if (ErrMsg == "") {
                    ErrMsg = Page_Validators[i].errormessage;
                }
                $("#" + Page_Validators[i].controltovalidate).attr("style", "border-color:#C82D4B");
                a++;
            }
        }
        $("#ctl00_ContentPlaceHolder1_SignUpErr").html(ErrMsg);
        return false;
    }
}

function SignUpStep2_Client(oSrc, args) {
    var temp;
    $(".vali").css("color", "#000000");
    $("input[@type!=image]").attr("style", "");
    $(".error").html("&nbsp;");
    var temp, formelement;
    for (var i = 0; i < Page_Validators.length; i++) {
        if (Page_Validators[i].validationGroup == "SignUp" && Page_Validators[i].controltovalidate != undefined) {
            formelement = Page_Validators[i].controltovalidate;
            temp = formelement.replace("ctl00_ContentPlaceHolder1_", "f");
            if (!Page_Validators[i].isvalid || $("#" + formelement).value() != "Select Answer") {
                $("#" + temp).css("color", "#C82D4B");
                $(".error").html("Please answer all required fields.");
            }
        }
    }
}

function Check_UserEmail(oSrc, args) {
    var myreg = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    if (myreg.test(args.Value) && !SubmitS.AjaxS) {
        var mydate = new Date().toLocaleString();
        $.get("common/CheckEmail.ashx?UserEmail=" + args.Value + "&date=" + mydate, function(data) {
            if (data == "N") {
                SubmitS.AjaxS = true;
                if (SubmitS.ButtomS) {
                    $("#ctl00_ContentPlaceHolder1_ContinueB").click();
                }
            }
            else {
                SubmitS.AjaxS = false;
                if ($("#ctl00_ContentPlaceHolder1_SignUpErr").html().length > 5) {
                    $("#ctl00_ContentPlaceHolder1_SignUpErr").html("An account with this email address already exists");
                    $("#ctl00_ContentPlaceHolder1_UserEmail").attr("style", "border-color:#C82D4B");
                    $("#fForgotEmail").css("color", "#C82D4B");
                }
            }
        });
        if (SubmitS.AjaxS) {
            args.IsValid = true;
        }
        else {
            args.IsValid = false;
        }

    }
}

$(function() {
    $("#ctl00_ContentPlaceHolder1_ContinueB").click(function() {
        SubmitS.ButtomS = true;
        //alert("a");
        if (SubmitS.AjaxS) {
            return true;
        }
        return false;
    });
})

var ShowErr = function(id) {
    $("#" + id).attr("style", "border:1px #C82D4B solid;");
    $("#" + id + "_Err").attr("style", "color:#C82D4B");
    $("#f" + id.replace("ctl00_ContentPlaceHolder1_", "")).attr("style", "color:#C82D4B");
}
var HideErr = function(id) {
    $("#" + id).attr("style", "");
    $("#" + id + "_Err").attr("style", "");
    $("#f" + id.replace("ctl00_ContentPlaceHolder1_", "")).attr("style", "");
}
$(function() {
    $("#ctl00_ContentPlaceHolder1_IsSeeDoctor").change(function() {
        if ($(this).val() == "3" || $(this).val() == "4") {
            $("#ctl00_ContentPlaceHolder1_TypeOfPhysician").attr("disabled", "");
            $("#ctl00_ContentPlaceHolder1_DoctorFirstName").attr("disabled", "");
            $("#ctl00_ContentPlaceHolder1_DoctorLastName").attr("disabled", "");
            $("#ctl00_ContentPlaceHolder1_PracticeName").attr("disabled", "");
        }
        else {
            $("#ctl00_ContentPlaceHolder1_TypeOfPhysician").attr("disabled", "disabled");
            $("#ctl00_ContentPlaceHolder1_DoctorFirstName").attr("disabled", "disabled");
            $("#ctl00_ContentPlaceHolder1_DoctorLastName").attr("disabled", "disabled");
            $("#ctl00_ContentPlaceHolder1_PracticeName").attr("disabled", "disabled");
            $("#ctl00_ContentPlaceHolder1_DoctorFirstName").val("");
            $("#ctl00_ContentPlaceHolder1_DoctorLastName").val("");
            $("#ctl00_ContentPlaceHolder1_PracticeName").val("");
        }
    });
})

function valiPhoneNumber(o,nextInput) {
    o.value = o.value.replace(/\D/g, '');
    if (o.value.length == 3 && nextInput != undefined) {
        document.getElementById(nextInput).focus();
        document.getElementById(nextInput).select();
    }
}