var gE = function(id) { return document.getElementById(id); }
var windowHandle = null;
function fnCallResetControls() {
    var ConfirmClear = confirm("Do you want to Clear Form?");
    if (ConfirmClear == true) {
        fnResetControls();
    }
}
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 fnEnableControls() {
    for (var i = 0; i < arguments.length; i++) {
        gE(arguments[i]).disabled = false;
    }
}
function fnCreateUser(IsUpdate) {
    var ConfirmSave = confirm(MessageVars.SEC_0047); 
    var retvalue;
    if (ConfirmSave == true) {
        return true;   
    }
    else
        return false;
}
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 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 fnOpenAssignRoles() {   
    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");           
        }
        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 fnValueSaveButtonClick() {
	var himsValidator = [
							 new hims_ctl_val("ctl00_CP_UserRoleDropDownList", "User Role", "T", "", "", "", 20),
									new hims_ctl_val("ctl00_CP_LoginNameTextBox", 'User Name', "T", "", "", "", 20),
									new hims_ctl_val("ctl00_CP_DisplayNameTextBox", MessageVars.SEC_0050, "T", "", "", "", 20),
									new hims_ctl_val("ctl00_CP_NewPasswordTextBox", 'New Password', "T", "", "", "", 20),
									new hims_ctl_val("ctl00_CP_ConfirmPasswordTextBox", 'Confirm Password', "T", "", "", "", 20)
									];
	if (fnDoValidate(himsValidator))
		return true;
	else
		return false;
}
function fnPasswordSpecialCharacters(charCode) {
	if ((charCode == 33)
	|| (charCode >= 35 && charCode <= 37)      
	|| (charCode >= 40 && charCode <= 47)
	|| (charCode >= 58 && charCode <= 64)
	|| (charCode >= 91 && charCode <= 96)
	|| (charCode >= 123 && charCode <= 125))
	{ return true; }
	return false;
}
function fnPasswordStringCharacters(charCode) {
	if ((charCode == 32)
	|| (charCode > 57 && charCode < 59)
	|| (charCode > 64 && charCode < 91)
	|| (charCode > 96 && charCode < 123))
	{ return true; }
	return false;
}     
function fnPasswordNumericCharacters(charCode) {
	if (charCode >= 48 && charCode <= 57)
	{ return true; }
	return false;
}
function fnPaswordChararters(str) {
	var IsSpecialCharIncluded = false;
	var IsNumericCharIncluded = false;
	for (var j = 0; j < str.length; j++) {
		var charParam = str.charAt(j);
		var iChar = charParam.charCodeAt(0);
		var isValid = false;
		isValid = fnPasswordStringCharacters(iChar);
		if (isValid == false) {
			isValid = fnPasswordSpecialCharacters(iChar);
			if (IsSpecialCharIncluded == false) {
				IsSpecialCharIncluded = isValid;
			}
		}
		if (isValid == false) {
			isValid = fnPasswordNumericCharacters(iChar);
			if (IsNumericCharIncluded == false) {
				IsNumericCharIncluded = isValid;
			}
		}
		if (isValid == false) {
			return isValid;
		}
	}
	if (IsSpecialCharIncluded == false
	|| IsNumericCharIncluded == false) {
		return false;
	}
	return true;
}
function fnValidatePassword(textbox, minLength, maxLength) {         
	var str = fnTrim(textbox.value);
	var newStr = "";
	var isValid = true;
	if (str.length == 0) {
		textbox.value = str;
		return true;
	}
	if (str.length < minLength) { isValid = false };
	if (str.length > maxLength) { isValid = false };     
	if (isValid == false) {
		SetMessageBox('Invalid Password: Length should be Min:6 and Max:13', 'Error');
	}
	else {
		ResetMessageBox();
	}
	textbox.value = str;
}  





