// JScript File

var gE = function(id) { return document.getElementById(id); }
var windowHandle = null;

/****************************************************************************************
Function/Procedure  Name            :- fnCallResetControls
functionality                       :- To Call Function to Clear Controls		
****************************************************************************************/
function fnCallResetControls() {

    var ConfirmClear = confirm("Do you want to Clear Form?");
    if (ConfirmClear == true) {
        fnResetControls();
    }
}

/****************************************************************************************
Function/Procedure  Name            :- fnResetControls
functionality                       :- To Clear Controls 		
****************************************************************************************/
function fnResetControls() {

    fnDisableFields('ctl00_CP_AssignRoleLinkButton', 'ctl00_EditButton');
    fnEnableControls('ctl00_CP_UserProfileLoginTitleTextBox', 'ctl00_CP_UserProfileLoginPasswordTextBox', 'ctl00_CP_ConfirmLoginPasswordTextBox');

    document.getElementById('ctl00_CP_UserProfileCityDropDownList').selectedIndex = 0;

    document.getElementById('ctl00_CP_ConditionDropDownList').selectedIndex = 0;

    ResetMessageBox();

    for (i = 0; i < document.forms[0].length; i++) {
        doc = document.forms[0].elements[i];
        switch (doc.type) {
            case "text":
                doc.value = "";
                break;
            case "checkbox":
                doc.value = "";
                break;

            default:
                break;
        }
    }
    return true;
}

/****************************************************************************************
Function/Procedure  Name            :- fnEnableControls
functionality                       :- Function to call Enable Fields		
****************************************************************************************/
function fnEnableControls() {
    for (var i = 0; i < arguments.length; i++) {
        gE(arguments[i]).disabled = false;

    }
}

/****************************************************************************************
Function/Procedure  Name            :- fnCreateUser
functionality                       :- Function to Validate on Save	
****************************************************************************************/
function fnCreateUser(IsUpdate) {

    var ConfirmSave = confirm(MessageVars.SEC_0047); //("Do you want to Create/Update User?");
    var retvalue;
    if (ConfirmSave == true) {
        return true;
        //        if ((document.getElementById('ctl00_CP_UserProfileLoginPasswordTextBox').value=="")&& document.getElementById('ctl00_CP_ConfirmLoginPasswordTextBox').value=="")
        //        {
        //        var himsValidator = [new hims_ctl_val("ctl00_CP_UserProfileLoginTitleTextBox","Mandatory Field","T","AN","","",20),                              
        //                             new hims_ctl_val("ctl00_CP_UserProfileTitleTextBox","Mandatory Field","T","AN","","",20),                            
        //                             new hims_ctl_val("ctl00_CP_UserProfileFirstNameTextBox","Mandatory Field","T","AN","","",20),
        //                             new hims_ctl_val("ctl00_CP_PrimaryEmailTextBox","Mandatory Field","T","AN","","",20)]; 
        //        
        //        } 
        //        else
        //        {
        //        var himsValidator = [new hims_ctl_val("ctl00_CP_UserProfileLoginTitleTextBox","Mandatory Field","T","AN","","",20),                              
        //                             new hims_ctl_val("ctl00_CP_UserProfileTitleTextBox","Mandatory Field","T","AN","","",20),
        //                             new hims_ctl_val("ctl00_CP_UserProfileLoginPasswordTextBox","Mandatory Field","T","AN","","",20),
        //                             new hims_ctl_val("ctl00_CP_ConfirmLoginPasswordTextBox","Mandatory Field","T","AN","","",20), 
        //                             new hims_ctl_val("ctl00_CP_UserProfileFirstNameTextBox","Mandatory Field","T","AN","","",20),
        //                             new hims_ctl_val("ctl00_CP_PrimaryEmailTextBox","Mandatory Field","T","AN","","",20)]; 
        //         }                    
        //                
        //        if (fnDoValidate(himsValidator))
        //        {
        //            return true;
        //        }
        //        else
        //        {
        //            SetMessageBox('Please enter data correctly!','info');    
        //            return false;
        //        }      

    }
    else
        return false;
}
/****************************************************************************************
Function/Procedure  Name            :- fnValidateUpdateUser
functionality                       :- Function to Validate Update User
****************************************************************************************/
function fnValidateUpdateUser() {

    fnEnableControls('ctl00_CP_UserProfileTitleTextBox', 'ctl00_CP_UserProfileFirstNameTextBox',
                        'ctl00_CP_UserProfileMiddleNameTextBox', 'ctl00_CP_UserProfileLastNameTextBox', 'ctl00_CP_UserProfileStreet1TextBox',
                        'ctl00_CP_UserProfileStreet2TextBox', 'ctl00_CP_UserProfileStreet3TextBox',
                        'ctl00_CP_UserProfileStreet4TextBox', 'ctl00_CP_UserProfileCityDropDownList',
                        'ctl00_CP_ZipCodeTextBox', 'ctl00_CP_HomePhoneNoTextBox',
                        'ctl00_CP_OfficePhoneNoTextBox', 'ctl00_CP_MobileNoTextBox',
                        'ctl00_CP_PrimaryEmailTextBox', 'ctl00_CP_AlternativeEmailTextBox',
                        'ctl00_CP_ObsoleteCheckBox', 'ctl00_CP_AssignRoleLinkButton'

                       );

    fnDisableFields('ctl00_CP_UserProfileLoginTitleTextBox', 'ctl00_CP_UserProfileLoginPasswordTextBox',
                    'ctl00_CP_ConfirmLoginPasswordTextBox',
                    'ctl00_CP_UPLoginPasswordRequiredFieldValidator', 'ctl00_CP_ConfirmLoginPasswordRequiredFieldValidator',
                    'ctl00_CP_PasswordCompareValidator', 'ctl00_SaveButton'
                    );



    gE('ctl00_CP_UPLoginPasswordRequiredFieldValidator').value = " ";
    gE('ctl00_CP_ConfirmLoginPasswordRequiredFieldValidator').value = " ";
    gE('ctl00_CP_PasswordCompareValidator').value = " ";

    return;
}

/****************************************************************************************
Function/Procedure  Name            :- fnValidatePhoneNumber
functionality                       :- Function to Validate Phone Number
****************************************************************************************/
function fnValidatePhoneNumber(ctlID) {
    var retvalue;
    var ctlvalue = gE(ctlID).value
    if (ctlvalue != null) {
        retvalue = fnIsValidPhone(ctlvalue);
        if (retvalue == false) {
            SetMessageBox("Please enter valid Phone Number", 'info');
            document.getElementById(ctlID).value = "";
        }

    }
}

/****************************************************************************************
Function/Procedure  Name            :- fnOpenAssignRoles
functionality                       :- Function to Pass Selected User to Assign Roles Form
****************************************************************************************/
function fnOpenAssignRoles() {

    //    var client=gE('<%=UserProfileTitleTextBox.ClientID %>').value; 
    //    alert(client)
    if (gE('ctl00_CP_AssignRoleLinkButton').disabled == false) {
        var userName = gE('ctl00_CP_DisplayNameTextBox').value;
        var userID = gE('ctl00_CP_UserIdHiddenField').value;

        if (window.showModalDialog) {
            window.showModalDialog("UserRole.aspx?UserName=" + userName + "&UserID=" + userID + "&MasterPage=Dialog", " ", "dialogWidth:580px;dialogHeight:580px");
            //window.open("UserRole.aspx?UserName=" + userName + "&UserID=" + userID, '', 'toolbar=no,status=1,scrollbars=no,location=no,resizable =yes width=400,height=250,modal=yes');
        }
        else {
            window.open("UserRole.aspx?UserName=" + userName + "&UserID=" + userID, '', 'toolbar=no,status=1,scrollbars=no,location=no,resizable =yes width=800,height=500,modal=yes');
        }
        return true;
    }
    return true;
}


/****************************************************************************************
Function/Procedure  Name            :- fnConfirmPassword
functionality                       :- Function to Verify Password
****************************************************************************************/
//function fnConfirmPassword()
//{
//    var retvalue;
//    var passwordValue=gE('ctl00_CP_UserProfileLoginPasswordTextBox').value;
//    var confirpasswordValue=gE('ctl00_CP_ConfirmLoginPasswordTextBox').value;
//    
//    if(passwordValue!=confirpasswordValue)
//    {
//        SetMessageBox('Please verify password.!','info');     
//        retvalue= false;
//    }
//    else
//    {
//        retvalue= true;
//    }
//    return retvalue;

//}

/****************************************************************************************
Function/Procedure  Name            :- fnValidateEmailFields
functionality                       :- Function to Validate Primary Email
****************************************************************************************/
//function fnValidateEmailFields()
//{
//        
//    var retvalue;
//    var ctlValue=gE('ctl00_CP_PrimaryEmailTextBox').value
//      retvalue = fnCheckEmail(ctlValue);
//        if(retvalue == false) 
//            { 
//                SetMessageBox("Please enter valid Email ID.", 'info')
//                //return retvalue
//            }; 
//          return false;
//            
//}

/****************************************************************************************
Function/Procedure  Name            :- fnValidateAlternativeEmailFields
functionality                       :- Function to Validate Alternative Email
****************************************************************************************/
//function fnValidateAlternativeEmailFields()
//{
//    
//    var retvalue;
//    var ctlValue=gE('ctl00_CP_AlternativeEmailTextBox').value
//    if (ctlValue != null)
//    {
//      retvalue = fnCheckEmail(ctlValue);
//        if(retvalue == false) 
//            { 
//                SetMessageBox("Please enter valid Email ID.", 'info')
//                return retvalue
//            }; 
//    }
//    
//}

/****************************************************************************************
Function/Procedure  Name            :- fnValidateSameEmail
functionality                       :- Function to Validate if Email Id are not the same
****************************************************************************************/
//function fnValidateSameEmail()
//{
//    var retvalue;
//    var primaryEmail=gE('ctl00_CP_PrimaryEmailTextBox').value;
//    var alternativeEmail=gE('ctl00_CP_AlternativeEmailTextBox').value;
//    
//    if (primaryEmail==alternativeEmail)
//    {
//        SetMessageBox("Alternative Email cannot be the same as Primary Email.", 'info');
//        retvalue=false;
//    }
//    else
//    {retvalue= true;}
//    return retvalue;  
//}







