﻿//Global Variables for following functions

var txtUserCodeGLobal;


/*
Description : used for set state name.used on signup.aspx page
Created on 11 / 08/ 2009
Author Amrik


*/




/*
Description : To check whether there is duplicate Username or Emergency Code
Created on 11 / 09/ 2009
Author Amrik
*/
function checkduplicacy() {
    if (Page_ClientValidate()) {
        if (document.getElementById('DivMessage') != null) {
            if (document.getElementById('DivMessage').style.display == 'block') {
                return false;
            }
        }
        if (document.getElementById('DivEmergencyCode') != null) {
            if (document.getElementById('DivEmergencyCode').style.display == 'block') {
                return false;
            }
        }

        return true;
    }
}

/*
Description : used for set country used on signup.aspx page
Created on 11 / 08/ 2009
Author Amrik


*/


        function setTextSignup(tbStateName,HDFTBSttNme) {
        
            document.getElementById(HDFTBSttNme).value = document.getElementById(tbStateName.id).value;
        }

        function OnChangeSignup(ddcountry,dropdown,tbStateName,HDFTBSttNme) {
            var myindex = ddcountry.selectedIndex
            var SelValue = ddcountry.options[myindex].value
            // alert('Index :- '+ myindex);


            if (SelValue != "US") {

                // dropdown.style.display = 'none';
                document.getElementById(dropdown).selectedIndex = 5;
                document.getElementById(dropdown).style.display = 'none';
                document.getElementById(tbStateName).style.display = 'block';
                document.getElementById(tbStateName).value = '';
                document.getElementById(HDFTBSttNme).value = '';



            }
            else {
                document.getElementById(dropdown).selectedIndex = 0;
                document.getElementById(dropdown).style.display = 'block';
                document.getElementById(tbStateName).style.display = 'none';
                document.getElementById(tbStateName).value = 'CA';
                document.getElementById(HDFTBSttNme).value = 'CA';

            }

            return true;
        }




/// <summary>
/// java script for calling web service method for user avaibality
/// </summary>
/// <param name="userCode"></param>
/// <returns><param name="userCode"></param> </returns>
function CheckUserAvailability(txtUserCode) {
     
     txtUserCodeGLobal = txtUserCode.id;
    try {

        if (typeof (txtUserCode) != 'undefined') {
         if(txtUserCode.value != '')
         {
            EMDMCWebService.CheckUserAvailability(txtUserCode.value, onUserAvailabilitySuccess, onUserAvailablityfailure);
         }

        }
    }
    catch (e) {


    }


}

/// <summary>
/// java script for calling web service method for user avaibality
/// </summary>
/// <param name="userCode"></param>
/// <returns><param name="userCode"></param> </returns>
function CheckEmergencyCodeAvailability(txtUserCode) {
     
    try {
    

        if (typeof (txtUserCode) != 'undefined') {
             if(txtUserCode.value != '')
             {
              EMDMCWebService.CheckEmergencyCodeAvailability(txtUserCode.value, onEmergencyCodeAvailability, onEmergencyCodefailure);
             }

        }
    }
    catch (e) {


    }


}

/// <summary>
/// java script for calling web service method for update user name from admin panel
/// </summary>
/// <param name="newUserCode"></param>
/// <param name="oldUserCode"></param>
/// <returns><param name="userCode"></param> </returns>
function UpdateUserCode(txtUserCode, oldUserCode) {
   
    var oldValue = document.getElementById('' + oldUserCode + '').value;
   
    try {

        if (typeof (txtUserCode) != 'undefined') {

            if (oldValue != txtUserCode.value) {

                EMDMCWebService.CheckUserAvailability(txtUserCode.value, onUserAvailabilitySuccess, onUserAvailablityfailure);
            }
            else {
                document.getElementById('DivMessage').style.display = 'none';
            }

        }
    }
    catch (e) {


    }


}

/// <summary>
/// java script for function for user avaibality
/// </summary>
/// <param name="userCode"></param>
/// <returns><param name="userCode"></param> </returns>
function onEmergencyCodeAvailability(result) {

    try {
      
        if (typeof (result) != 'undefined') {
            if (result) //Case Where User Exists
            {

                //Step 1: Show Error Message in Div
                //document.getElementById('DivMessage').innerHTML = 'User Name Already Exist Choose Other';
                //document.getElementById('ctl00_ContentPlaceHolder1_TextBoxUserId').value = '';
               // document.getElementById('ctl00_ContentPlaceHolder1_TextBoxEmergencyCode').focus();
                document.getElementById('DivEmergencyCode').style.display = 'block';

            }
            else { document.getElementById('DivEmergencyCode').style.display = 'none'; }

        }

    }
    catch (e) {


    }


}
function onEmergencyCodefailure(result) {
    //alert(result);
}

/// <summary>
/// java script for function for user avaibality
/// </summary>
/// <param name="userCode"></param>
/// <returns><param name="userCode"></param> </returns>
function onUserAvailabilitySuccess(result) {


    try {
        
        if (typeof (result) != 'undefined') {
            if (result) //Case Where User Exists
            {
// txtUserCodeGLobal Used as ctl00_ContentPlaceHolder1_TextBoxUserId
                //Step 1: Show Error Message in Div
                //document.getElementById('DivMessage').innerHTML = 'User Name Already Exist Choose Other';
                //document.getElementById('ctl00_ContentPlaceHolder1_TextBoxUserId').value = '';
                document.getElementById('' + txtUserCodeGLobal + '').focus();
                document.getElementById('DivMessage').style.display = 'block';

            }
            else { document.getElementById('DivMessage').style.display = 'none'; }

        }

    }
    catch (e) {


    }


}
function onUserAvailablityfailure(result) {
    //alert(result);
}

/// <summary>
/// java script for open div on clinician checkbox checked on user registration page
/// </summary>
/// 
function ShowDivOnRegistrationNotUSed(Result) {
    try {
        
        //alert('hi');



        //Step 1: Show Div on clinician checkbox checked
        if (document.getElementById('ctl00_ContentPlaceHolder1_RadioButtonClinician').checked) {
            document.getElementById('ctl00_ContentPlaceHolder1_DivClinician').style.display = 'block'
            var textBox = document.getElementById('ctl00_ContentPlaceHolder1_TextBoxLicense');
            //alert( textBox.value );
            var dropdownbox = document.getElementById('ctl00_ContentPlaceHolder1_DropDownListQualification');
            textBox.value = '';
            dropdownbox.selectedIndex = 0;
        }

        else {
            document.getElementById('ctl00_ContentPlaceHolder1_DivClinician').style.display = 'none';
        }



    }
    catch (e) {


    }

}
//javascript for Hide Div

function HideDivOnRegistration(NotUSedResult) {
    try {
        



        //Step 1: Show Div on clinician checkbox checked
        if (document.getElementById('ctl00_ContentPlaceHolder1_RadioButtonPatient').checked) {
            document.getElementById('ctl00_ContentPlaceHolder1_DivClinician').style.display = 'none'


        }

        else {
            document.getElementById('ctl00_ContentPlaceHolder1_DivClinician').style.display = 'block';
        }



    }
    catch (e) {


    }





}



//javascript for tabindex for go to next tab

function clickButton(e, buttonid) {
    var evt = e ? e : window.event;
    var bt = document.getElementById(buttonid);
    if (bt) {
        if (evt.keyCode == 13) {
            bt.click();
            return false;
        }
    }
}

//for aggrement page check  term & condition

function validate(checkAgree, roleId) {


    if (document.getElementById(checkAgree).checked == false) {
         alert('Please select option');
        return false;

    }
    else {
        
        window.location = "SignUp.aspx";
        return true;
    }
}

