function browserDetect() {
    var browser = navigator.appName
    var b_version = navigator.appVersion
    var version = parseFloat(navigator.appVersion.split('MSIE')[1])
    if ((browser == "Microsoft Internet Explorer") && (version < 7)) {
        window.location = "jsp/browserFail.jsp"
    }
}

function validareCNP(s)
{
    var suma = 0;
    var mesaj = "";
    if (s.length == 13)
    {
        suma = parseInt(s.charAt(0)) * 2 + parseInt(s.charAt(1)) * 7 + parseInt(s.charAt(2)) * 9 + parseInt(s.charAt(3))
                + parseInt(s.charAt(4)) * 4 + parseInt(s.charAt(5)) * 6 + parseInt(s.charAt(6)) * 3 + parseInt(s.charAt(7)) * 5
                + parseInt(s.charAt(8)) * 8 + parseInt(s.charAt(9)) * 2 + parseInt(s.charAt(10)) * 7 + parseInt(s.charAt(11)) * 9;
        suma = suma % 11;
        if (suma == 10)
            suma = 1;
        return suma == parseInt(s.charAt(12));
    }
    else {
        return false;
    }
}

function checkUsername() {
    var user = document.getElementById("username");
    var userHidden = document.getElementById("user");
    var userForm = document.getElementById("userForm");
    var div = document.getElementById("userErrorDiv");
    if (user.value.length == 0) {
        div.style.display = "block";
        return false;
    }
    userHidden.value = user.value;
    userForm.submit();
    return true;
}

function verifyCNP(cnp) {
    var constant = new String("279146358279");
    if (cnp.length != 13) return (false);
    var sum = 0;
    for (var i = 0; i < 13; i++) {
        sum = sum + cnp.charAt(i) * constant.charAt(i);
    }
    var mod = sum % 11;
    if ((mod < 10 && mod == cnp.charAt(12)) || (mod == 10 && cnp.charAt(12) == 1)) {
        return(true);
    } else {
        //TODO THIS IS ONLY FOR TESTING . put return(false) to turn on validation
        return(false);
    }
}

function checkAlll() {
    var checkAll = false;
    for (var i = 0; i < document.getElementsByName("checkList").length; i++) {
        if (!document.getElementsByName("checkList")[i].checked) {
            checkAll = true;
            break;
        }
    }
    if (checkAll) {
        checkUncheckAll(true);
    }
    else {
        checkUncheckAll(false);
    }
    return true;
}

function checkUncheckAll(isCheck) {
    for (var i = 0; i < document.getElementsByName("checkList").length; i++) {
        document.getElementsByName("checkList")[i].checked = isCheck;
    }
}
function ValidateForm(errorEmptyString, errorCnpString, cnpId, firstNameId, lastNameId) {
    var cnp = document.getElementById(cnpId);
    var firstName = document.getElementById(firstNameId);
    var lastName = document.getElementById(lastNameId);
    if ((firstName.value == null || firstName.value == "") ||
        (lastName.value == null || lastName.value == "") ||
        (cnp.value == null || cnp.value == "")) {
        alert(errorEmptyString);
        firstName.focus();
        return false;
    }

    if (!validareCNP(cnp.value)) {
            alert(errorCnpString);
            cnp.focus();
            return false;
        }
    return true;
}

function enableUnityElements(thisRadio, enabledId1, enabledId2, enabledId3, disabledId1) {
    if (thisRadio.checked) {
        executeEnableElem(enabledId1);
        executeEnableElem(enabledId2);
        executeEnableElem(enabledId3);
        executeDisableElem(disabledId1);
    }
}
function enableCabinetElements(thisRadio, enabledId1, disabledId1, disabledId2, disabledId3) {
    if (thisRadio.checked) {
        executeEnableElem(enabledId1);
        executeDisableElem(disabledId1);
        executeDisableElem(disabledId2);
        executeDisableElem(disabledId3);
    }
}

function executeEnableElem(enabledId1) {
    var enabledElem1 = document.getElementById(enabledId1);
    enabledElem1.disabled = false;
}

function executeDisableElem(disabledID) {
    var disabledElem = document.getElementById(disabledID);
    disabledElem.disabled = true;
}

function fillCabinets(cabinetsDropDown) {
    var hiddenType = document.getElementById("cabTypeHidden" + cabinetsDropDown.options[cabinetsDropDown.selectedIndex].value);
    var type = document.getElementById("cabType");
    var hiddenSubType = document.getElementById("cabSubTypeHidden" + cabinetsDropDown.options[cabinetsDropDown.selectedIndex].value);
    var subType = document.getElementById("cabSubType");
    type.value = hiddenType.value;
    subType.value = hiddenSubType.value;
}

function generateYears(dropDownId, selectedValue) {
    var dropDown = document.getElementById(dropDownId);
    var currentYear = new Date().getFullYear();
    for (var i = currentYear; i >= 1950; i--) {
        if (i == selectedValue)
            appendOptionLast(i, i, dropDown, true);
        else
            appendOptionLast(i, i, dropDown, false);

    }
}
function extractSubstring(string) {
    return string.substr(string.indexOf('#') + 1, string.length);
}

function appendOptionLast(value, text, dropDownElement, selected) {
    var elOptNew = document.createElement('option');
    elOptNew.text = text;
    elOptNew.value = value;
    elOptNew.selected = selected;
    try {
        dropDownElement.add(elOptNew, null);
        // standards compliant; doesn't work in IE
    }
    catch(ex) {
        dropDownElement.add(elOptNew);
        // IE only
    }
}

function fillQualities(manifestationsDropDown, defaultMessage) {
    var currentValue = manifestationsDropDown.options[manifestationsDropDown.selectedIndex].value;
    var qualitiesForm = document.getElementById("qualitiesForm");
    var qualityDropDown = document.getElementById("qualityDropDown");
    if (manifestationsDropDown.selectedIndex == 0) {
        document.getElementById("creditNr").value = defaultMessage;
    }
    for (var i = qualityDropDown.length - 1; i > 0; i--) {
        qualityDropDown.remove(i);
    }

    for (var i = 0; i < qualitiesForm.getElementsByTagName("input").length; i++) {
        var manifestationQualityID = 0;
        var manifestationQualityName = '';

        if (qualitiesForm.getElementsByTagName("input")[i].id.indexOf('hiddenManifestationQualityID#') >= 0) {
            if (currentValue == extractSubstring(qualitiesForm.getElementsByTagName("input")[i].id)) {
                manifestationQualityID = qualitiesForm.getElementsByTagName("input")[i].value;
            }
        }

        if (manifestationQualityID != 0) {
            for (var j = 0; j < qualitiesForm.getElementsByTagName("input").length; j++) {
                if (qualitiesForm.getElementsByTagName("input")[j].id.indexOf('hiddenManifestationQualityName#') >= 0) {
                    if (manifestationQualityID == extractSubstring(qualitiesForm.getElementsByTagName("input")[j].id)) {
                        manifestationQualityName = qualitiesForm.getElementsByTagName("input")[j].value;
                    }
                }
            }
        }

        if ((manifestationQualityID != 0) && (manifestationQualityName != ''))
            appendOptionLast(manifestationQualityID, manifestationQualityName, qualityDropDown, false);
    }
}

function fillCreditsInput(qualityDropDown, defaultMessage) {
    var creditNr = document.getElementById("creditNr");
    var value = qualityDropDown.options[qualityDropDown.selectedIndex].value;
    if (qualityDropDown.selectedIndex == 0) {
        creditNr.value = defaultMessage;
        return;
    }
    for (var i = 0; i < document.getElementsByTagName("input").length; i++) {
        if (document.getElementsByTagName("input")[i].type);
    }

    var creditNrHidden = document.getElementById("hiddenCredits#" + value);
    creditNr.value = creditNrHidden.value;
}

function fillManifestations(themesDropDown, defaultMessage) {
    var startDateHidden = document.getElementById("startDateHidden" + themesDropDown.options[themesDropDown.selectedIndex].value);
    var startDate = document.getElementById("startDate");
    var cityHidden = document.getElementById("cityHidden" + themesDropDown.options[themesDropDown.selectedIndex].value);
    var city = document.getElementById("city");
    var coordinatorHidden = document.getElementById("coordinatorHidden" + themesDropDown.options[themesDropDown.selectedIndex].value);
    var coordinator = document.getElementById("coordinator");
    if (startDateHidden != null) {
        startDate.value = startDateHidden.value;
        city.value = cityHidden.value;
        coordinator.value = coordinatorHidden.value;
        return;
    }
    startDate.value = defaultMessage;
    city.value = defaultMessage;
    coordinator.value = defaultMessage;
}

function resetDropDowns(dropDownId) {
    var dropDown = document.getElementById(dropDownId);
    dropDown.options.length = 1;
    dropDown.options[1].value = "unknown";
    dropDown.options[1].text = "...";
}
function validateListContest() {
    var completeAllDiv = document.getElementById("completeAllDiv");
    var date = document.getElementById("date");
    var place = document.getElementById("place");
    if ((date.value.length < 1) || (place.value.length < 1)) {
        completeAllDiv.style.display = "block";
        return false;
    }
    return true;
}

function validateListAbroad() {
    var completeAllDiv = document.getElementById("completeAllDiv");
    var place = document.getElementById("place");
    if (place.value.length < 1) {
        completeAllDiv.style.display = "block";
        return false;
    }
    return true;
}

function validateMemberManifestationPage() {
    var qualityDropDown = document.getElementById("qualityDropDown");
    var themeDropDown = document.getElementById("themeDropDown");
    var allFieldsErrorDiv = document.getElementById("allFieldsErrorDiv");
    var selectThemeOrQualityDiv = document.getElementById("selectThemeOrQualityDiv");
    if ((themeDropDown.selectedIndex == 0) || (qualityDropDown.selectedIndex == 0)) {
        if (allFieldsErrorDiv.style.display == "block") {
            allFieldsErrorDiv.style.display = "none";
        }
        selectThemeOrQualityDiv.style.display = "block";
        return false;
    }
    return true;
}
function validateFunctionPage() {
    var functionYearDropDown = document.getElementById("functionYear");
    var specialityDropDown = document.getElementById("functionDropDown");
    var completeAll = document.getElementById("completeAll");
    var selectSpecialityDiv = document.getElementById("selectSpecialityDiv");
    if (functionYearDropDown.selectedIndex == 0) {
        if (selectSpecialityDiv.style.display == "block") {
            selectSpecialityDiv.style.display = "none";
        }
        completeAll.style.display = "block";
        return false;
    }
    if (specialityDropDown.selectedIndex == 0) {
        if (completeAll.style.display == "block") {
            completeAll.style.display = "none";
        }
        selectSpecialityDiv.style.display = "block";
        return false;
    }
    return true;
}
function validateGradePage() {
    var gradeYearDropDown = document.getElementById("gradeYear");
    var specialityDropDown = document.getElementById("specialityDropDown");
    var completeAll = document.getElementById("completeAll");
    var selectSpecialityDiv = document.getElementById("selectSpecialityDiv");
    if (gradeYearDropDown.selectedIndex == 0) {
        if (selectSpecialityDiv.style.display == "block") {
            selectSpecialityDiv.style.display = "none";
        }
        completeAll.style.display = "block";
        return false;
    }
    if (specialityDropDown.selectedIndex == 0) {
        if (completeAll.style.display == "block") {
            completeAll.style.display = "none";
        }
        selectSpecialityDiv.style.display = "block";
        return false;
    }
    return true;
}

function validateInfractionPage() {
    var startDate = document.getElementById("startDate");
    var endDate = document.getElementById("endDate");
    var infractionsDropDown = document.getElementById("infractionsDropDown");
    var selectDatesDiv = document.getElementById("selectDatesDiv");
    var selectInfractionDiv = document.getElementById("selectInfractionDiv");
    if ((startDate.value.length < 1) || (endDate.value.length < 1)) {
        if (selectInfractionDiv.style.display == "block") {
            selectInfractionDiv.style.display = "none";
        }
        selectDatesDiv.style.display = "block";
        return false;
    }
    if (infractionsDropDown.selectedIndex == 0) {
        if (selectDatesDiv.style.display == "block") {
            selectDatesDiv.style.display = "none";
        }
        selectInfractionDiv.style.display = "block";
        return false;
    }
    return true;
}

function validateAuthorizationPage(message) {
    var authorizationBranch = document.getElementById("authorizationBranch");
    var authorizationNr = document.getElementById("authorizationNr");
    var authorizationDate = document.getElementById("authorizationDate");
    var specialityDropDown = document.getElementById("specialityDropDown");
    var selectBranchDiv = document.getElementById("selectBranchDiv");
    var selectSpecialityDiv = document.getElementById("selectSpecialityDiv");
    if ((authorizationNr.value.length < 1) || (authorizationDate.value.length < 1)) {
        alert(message);
        return false;
    }
    if (authorizationBranch.selectedIndex == 0) {
        if (selectSpecialityDiv.style.display == "block") {
            selectSpecialityDiv.style.display = "none";
        }
        selectBranchDiv.style.display = "block";
        return false;
    }
    if (specialityDropDown.selectedIndex == 0) {
        if (selectBranchDiv.style.display == "block") {
            selectBranchDiv.style.display = "none";
        }
        selectSpecialityDiv.style.display = "block";
        return false;
    }
    return true;
}
function validateAddStudyPage() {
    var school = document.getElementById("schoolDropDown");
    var graduationYear = document.getElementById("graduationYear");
    var diplomaSeries = document.getElementById("diplomaSeries");
    var diplomaSerialNR = document.getElementById("diplomaSerialNR");
    var specialityDropDown = document.getElementById("specialityDropDown");
    var selectSchoolDiv = document.getElementById("selectSchoolDiv");
    var selectSpecialityDiv = document.getElementById("selectSpecialityDiv");
    if (school.selectedIndex == 0) {
        if (selectSpecialityDiv.style.display == "block") {
            selectSpecialityDiv.style.display = "none";
        }
        selectSchoolDiv.style.display = "block";
        return false;
    }
    if (specialityDropDown.selectedIndex == 0) {
        if (selectSchoolDiv.style.display == "block") {
            selectSchoolDiv.style.display = "none";
        }
        selectSpecialityDiv.style.display = "block";
        return false;
    }
    return true;
}

function validateAddCompetencePage() {
    var school = document.getElementById("schoolDropDown");
    var selectSchoolDiv = document.getElementById("selectSchoolDiv");
    if (school.selectedIndex == 0) {
        selectSchoolDiv.style.display = "block";
        return false;
    }
    return true;
}
function validateAddUnityPage() {
    var unities = document.getElementById("unitiesDropDown");
    var cabinets = document.getElementById("cabinetNames");
    var unityRadio = document.getElementById("unityRadio");
    var cabinetRadio = document.getElementById("cabinetRadio");

    var selectUnitiesOrCabinetsDiv = document.getElementById("selectUnitiesOrDropDownDiv");
    var selectSpecialityDiv = document.getElementById("selectSpecialityDiv");
    if (unityRadio.checked) {
        if (unities.selectedIndex == 0) {
            if (selectSpecialityDiv.style.display == "block") {
                selectSpecialityDiv.style.display = "none";
            }
            selectUnitiesOrCabinetsDiv.style.display = "block";
            return false;
        }
    }
    if (cabinetRadio.checked) {
        if (cabinets.selectedIndex == 0) {
            if (selectSpecialityDiv.style.display == "block") {
                selectSpecialityDiv.style.display = "none";
            }
            selectUnitiesOrCabinetsDiv.style.display = "block";
            return false;
        }
    }

    var speciality = document.getElementById("specialityDropDown");
    if (speciality.selectedIndex == 0) {
        if (selectUnitiesOrCabinetsDiv.style.display == "block") {
            selectUnitiesOrCabinetsDiv.style.display = "none";
        }
        selectSpecialityDiv.style.display = "block";
        return false;
    }
    return true;
}

function submitDeleteStudies(deleteFormId) {
    var deleteForm = document.getElementById(deleteFormId);
    var ids = document.getElementById("ids");
    ids.value = "#";
    for (var i = 0; i < document.getElementsByName("checkList").length; i++) {
        if (document.getElementsByName("checkList")[i].checked) {
            ids.value += document.getElementsByName("checkList")[i].id + "#";
        }
    }
    deleteForm.submit();
}

function submitAbroadVisas(listForm) {
    var listFormElement = document.getElementById(listForm);
    var ids = document.getElementById("ids");
    ids.value = "#";
    for (var i = 0; i < document.getElementsByName("checkList").length; i++) {
        if (document.getElementsByName("checkList")[i].checked) {
            ids.value += document.getElementsByName("checkList")[i].id + "#";
        }
    }
    listFormElement.submit();
}

function loadIdsForDeletion(id, confirmMessage, pleaseChooseOneMessage) {
    var ids = document.getElementById(id);
    var count = 0;
    ids.value = "#";
    for (var i = 0; i < document.getElementsByName("checkList").length; i++) {
        if (document.getElementsByName("checkList")[i].checked) {
            count++;
            ids.value += document.getElementsByName("checkList")[i].id + "#";
        }
    }
    if (count == 0) {
        alert(pleaseChooseOneMessage);
        return false;
    }
    return true;
}
function showModalWindow(id, confirmMessage, pleaseChooseOneMessage) {
    window.location = "#dialog2";
    return false;
}

function getElementsByName_ie(etag, ename) {
    var el = document.getElementsByTagName(etag);
    var newEl = new Array();
    j = 0;
    for (i = 0; i < el.length; i++) {
        att = el[i].getAttribute("name");
        if (att == ename) {
            newEl[j] = el[i];
            j++;
        }
    }
    return newEl;
}

function loadAllIdsForDeletion(id, confirmMessage, pleaseChooseOneMessage) {
    var ids = document.getElementById(id);
    var count = 0;
    ids.value = "#";
    var inputs = getElementsByName_ie("input", "addedMembersInput");
    for (var i = 0; i < inputs.length; i++) {
        count++;
        ids.value += inputs[i].value + "#";
    }
    if (count == 0) {
        alert(pleaseChooseOneMessage);
        return false;
    }
    return true;
}

function loadIdFromRadio(confirmMessage, pleaseChooseOneMessage) {
    var ids = document.getElementById("ids");
    var count = 0;
    for (var i = 0; i < document.getElementsByName("checkList").length; i++) {
        if (document.getElementsByName("checkList")[i].checked) {
            count++;
            ids.value = document.getElementsByName("checkList")[i].id;
            break;
        }
    }
    if (count == 0) {
        alert(pleaseChooseOneMessage);
        return false;
    }
    if (confirmMessage != '')
        return confirm(confirmMessage);
    else
        return true;

}

function submitFormFromLink(formId) {
    var form = document.getElementById(formId);
    form.submit();
    return false;
}

function clearPersonalDataFields() {
    document.getElementById("lastName").value = "";
    document.getElementById("firstName").value = "";
    document.getElementById("cnp").value = "";
    document.getElementById("address").value = "";
    document.getElementById("county").value = "";
    document.getElementById("city").value = "";
    document.getElementById("hiring").value = "";
    document.getElementById("retirement").value = "";
    document.getElementById("description").value = "";
}

function existsTab(formId, memberID, message) {
    for (var i = 0; i < document.getElementsByName("editTabs").length; i++) {
        if (document.getElementsByName("editTabs")[i].id.substr(6, document.getElementsByName("editTabs")[i].id.length) == memberID) {
            alert(message);
            return false;
        }
    }
    var form = document.getElementById(formId);
    form.submit();
    return false;
}

function validateDate(field, message) {
    var checkstr = "0123456789";
    var DateField = document.getElementById(field);
    var Datevalue = "";
    var DateTemp = "";
    var seperator = "/";
    var day;
    var month;
    var year;
    var leap = 0;
    var err = 0;
    var DateValue = DateField.value;
    /* Delete all chars except 0..9 */
    for (var i = 0; i < DateValue.length; i++) {
        if (checkstr.indexOf(DateValue.substr(i, 1)) >= 0) {
            DateTemp = DateTemp + DateValue.substr(i, 1);
        }
    }
    DateValue = DateTemp;
    /* Always change date to 8 digits - string*/
    /* if year is entered as 2-digit / always assume 20xx */
    if (DateValue.length == 6) {
        DateValue = DateValue.substr(0, 4) + '20' + DateValue.substr(4, 2);
    }
    if (DateValue.length != 8) {
        err = 19;
    }
    /* year is wrong if year = 0000 */
    year = DateValue.substr(4, 4);
    if (year == 0) {
        err = 20;
    }
    /* Validation of month*/
    month = DateValue.substr(2, 2);
    if ((month < 1) || (month > 12)) {
        err = 21;
    }
    /* Validation of day*/
    day = DateValue.substr(0, 2);
    if (day < 1) {
        err = 22;
    }
    /* Validation leap-year / february / day */
    if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
        leap = 1;
    }
    if ((month == 2) && (leap == 1) && (day > 29)) {
        err = 23;
    }
    if ((month == 2) && (leap != 1) && (day > 28)) {
        err = 24;
    }
    /* Validation of other months */
    if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
        err = 25;
    }
    if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
        err = 26;
    }
    /* if 00 ist entered, no error, deleting the entry */
    if ((day == 0) && (month == 0) && (year == 00)) {
        err = 0;
        day = "";
        month = "";
        year = "";
        seperator = "";
    }
    /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
    if (err == 0) {
        DateField.value = day + seperator + month + seperator + year;
    }
        /* Error-message if err != 0 */
    else {
        alert(message);
        DateField.select();
        DateField.focus();
    }
}

function onlyDigits(e, decReq, field) {
    var isIE = document.all;
    var key = (isIE) ? window.event.keyCode : e.which;
    var obj = (isIE) ? event.srcElement : e.target;
    var isNum = (key > 47 && key < 58);
    var dotOK = (key == 46 && decReq == 'decOK' && (obj.value.indexOf(".") < 0 || obj.value.length == 0));
    if (field.value.length > 3) {
        field.value = field.value.substr(0, 4);
        return false;
    }
    if (key < 32)
        return true;
    return (isNum || dotOK);
}

function textCounter(textAreaId, maxLimit) {
    var textArea = document.getElementById(textAreaId);
    if (textArea.value.length > maxLimit) {
        textArea.value = textArea.value.substring(0, maxLimit);
    }
}

function populatePrefs(color, language) {
    if (color != null && color.length > 0) {
        var blueRadio = document.getElementById("blue");
        var greenRadio = document.getElementById("green");
        var redRadio = document.getElementById("red");
        if (color == 'blue') {
            blueRadio.checked = true;
        } else if (color == "green") {
            greenRadio.checked = true;
        } else if (color == "red") {
            redRadio.checked = true;
        }
    }
    if (language != null && language.length > 0) {
        var RORadio = document.getElementById("ro");
        var ENRadio = document.getElementById("en");
        if (language == 'ro') {
            RORadio.checked = true;
        } else if (language == "en") {
            ENRadio.checked = true;
        }
    }
}

function validatePrefs(pwd) {
    var passErrorDiv = document.getElementById("passErrorDiv");
    var oldPassErrorDiv = document.getElementById("oldPassErrorDiv");
    var completeDiv = document.getElementById("complete");
    var oldPwd = document.getElementById("oldPwd");
    var newPwd = document.getElementById("newPwd");
    var reNewPwd = document.getElementById("reNewPwd");
    if (newPwd.value.length > 0 || reNewPwd.value.length > 0) {
        if (newPwd.value == reNewPwd.value) {
            if (oldPwd.value == pwd) {
                return true;
            } else {
                completeDiv.style.display = "none";
                passErrorDiv.style.display = "none";
                oldPassErrorDiv.style.display = "block";
                return false;
            }
        } else {
            completeDiv.style.display = "none";
            oldPassErrorDiv.style.display = "none";
            passErrorDiv.style.display = "block";
            return false;
        }
    }
    var username = document.getElementById("username");
    var email = document.getElementById("email");
    if (username.value.length == 0 || email.value.length == 0) {
        oldPassErrorDiv.style.display = "none";
        passErrorDiv.style.display = "none";
        completeDiv.style.display = "block";
        return false;
    }
    return true;
}

function verifyVisasNumber(visasNumber) {
    if (visasNumber <= 3) {
        return true;
    }
    var visaErrorDiv = document.getElementById("errorDiv");
    visaErrorDiv.style.display = "block";
    return false;
}

var i = 1;
var interval = 0;
function expandCollapse(thisLink, idDiv, height, increment) {
    if (interval != 0) {
        return;
    }
    var containerDiv = document.getElementById(idDiv);
    var collapsed = "false";
    if (containerDiv.style.height == "23px") {
        collapsed = "true";
    }
    var bottomDiv = document.getElementById(idDiv + "_bottom");
    var topDiv = document.getElementById(idDiv + "_top");
    var spanDiv = document.getElementById(idDiv + "_span");
    if (collapsed != "true") {
        topDiv.className = "titlePanelDivCollapsed";
        spanDiv.className = "titlePanelDivCollapsed";
        i = height;
        interval = window.setInterval('decreaseDiv(\'' + idDiv + '\', ' + increment + ')', 0);
        collapsed = "true";
    } else {
        topDiv.className = "titlePanelDivExpanded";
        spanDiv.className = "titlePanelDivExpanded";
        i = 23;
        interval = window.setInterval('increaseDiv(\'' + idDiv + '\', ' + increment + ', \'' + height + '\')', 0)
        collapsed = "false";
    }
}

function increaseDiv(idDiv, increment, height) {
    var containerDiv = document.getElementById(idDiv);
    i += increment;
    if (i > height) {
        clearInterval(interval);
        interval = 0;
        if (height - i + increment > 0) {
            containerDiv.style.height = height + "px";
        }
        return;
    }
    containerDiv.style.height = i + "px";
}
function decreaseDiv(idDiv, increment) {
    var containerDiv = document.getElementById(idDiv);
    i -= increment;
    if (i < 23) {
        clearInterval(interval);
        interval = 0;
        if (i + increment - 23 > 0) {
            containerDiv.style.height = 23 + "px";
        }
        return;
    }
    containerDiv.style.height = i + "px";
}
function checkEmail(emailId) {
    var email = document.getElementById(emailId);
    return /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value);
}
function validateRegister() {
    var username = document.getElementById("username");
    var email = document.getElementById("email");
    var cnp = document.getElementById("cnp");
    var newPwd = document.getElementById("password");
    var reNewPwd = document.getElementById("rePassword");
    var passErrorDiv = document.getElementById("passErrorDiv");
    var emailErrorDiv = document.getElementById("emailErrorDiv");
    var completeAllDiv = document.getElementById("complete");
    if (newPwd.value != reNewPwd.value) {
        emailErrorDiv.style.display = "none";
        completeAllDiv.style.display = "none";
        passErrorDiv.style.display = "block";
        return false;
    }
    if (!checkEmail("email")) {
        completeAllDiv.style.display = "none";
        passErrorDiv.style.display = "none";
        emailErrorDiv.style.display = "block";
        return false;
    }
    if (username.value.length == 0 || newPwd.value.length == 0 || reNewPwd.value.length == 0 || email.value.length == 0) {
        passErrorDiv.style.display = "none";
        emailErrorDiv.style.display = "none";
        completeAllDiv.style.display = "block";
        return false;
    }
    return true;
}
function checkImportanceInput(isChecked, checkboxId) {
    if (isChecked == "checked") {
        var checkbox = document.getElementById(checkboxId);
        checkbox.checked = true;
    }
}
function checkMarking(isChecked) {
    var checkbox = document.getElementById("important");
    var isMarked = document.getElementById("isMarked");
    if (isChecked == "checked" && !checkbox.checked) {
        isMarked.value = "true";
    }
    if (isChecked == "unchecked" && checkbox.checked) {
        isMarked.value = "true";
    }
}
function validateNewAnnouncement() {
    return true;
}


function disableListTag()
{
    //disable paginator buttons if exist
    if (document.getElementById("ahref_first") != null)
    {
        document.getElementById("ahref_first").style.display = "none";
        document.getElementById("ahref_previous").style.display = "none";
        document.getElementById("ahref_last").style.display = "none";
        document.getElementById("ahref_next").style.display = "none";
        document.getElementById("span_first").style.display = "inline";
        document.getElementById("span_previous").style.display = "inline";
        document.getElementById("span_last").style.display = "inline";
        document.getElementById("span_next").style.display = "inline";

        document.getElementById("flt_pageNo").disabled = true;
    }

    //disable all filter textfields
    var txtsFilter = document.getElementsByName("txtFilter");
    for (var i = 0; i < txtsFilter.length; i++)
        txtsFilter[i].disabled = true;
}


function workPlaceCriteria_selectCabinetType_SubType(cabinetsDropDown) {
    var hiddenType = document.getElementById("cabTypeHidden" + cabinetsDropDown.options[cabinetsDropDown.selectedIndex].value);
    var type = document.getElementById("cabinetTypeNames");
    var hiddenSubType = document.getElementById("cabSubTypeHidden" + cabinetsDropDown.options[cabinetsDropDown.selectedIndex].value);
    var subType = document.getElementById("cabinetSubTypeNames");
    var i;
    for (i = 0; i < type.options.length; i++)
        if (type.options[i].value == hiddenType)
            type.selectedIndex = i;
    for (i = 0; i < subType.options.length; i++)
        if (subType.options[i].value == hiddenSubType)
            subType.selectedIndex = i;
}
function workPlaceCriteria_enableCabinetElements(thisRadio, enabledId1, enabledId2, enabledId3, disabledId1, disabledId2, disabledId3) {
    if (thisRadio.checked) {
        executeEnableElem(enabledId1);
        executeEnableElem(enabledId2);
        executeEnableElem(enabledId3);
        executeDisableElem(disabledId1);
        executeDisableElem(disabledId2);
        executeDisableElem(disabledId3);
    }
}
function workPlaceCriteria_enableUnityElements(thisRadio, enabledId1, enabledId2, enabledId3, disabledId1, disabledId2, disabledId3) {
    if (thisRadio.checked) {
        executeEnableElem(enabledId1);
        executeEnableElem(enabledId2);
        executeEnableElem(enabledId3);
        executeDisableElem(disabledId1);
        executeDisableElem(disabledId2)
        executeDisableElem(disabledId3)
    }
}
function workPlaceCriteria_resetCabinet(disableId) {
    var disabledElem = document.getElementById(disableId);
    disabledElem.selectedIndex = 0;
}

function selectManifestationName(name) {
    var type = document.getElementById("name");
    for (var i = 0; i < type.options.length; i++) {
        if (type.options[i].value == name) {
            type.options[i].selected = true;
            break;
        }
    }
}

function IsNumeric(sText) {
    var ValidChars = "0123456789.";
    var IsNumber = true;
    var Char;

    if (sText.length == 0)
        return false;

    for (i = 0; i < sText.length && IsNumber; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;
}

function updateMainNavTable(beanId, firstName, lastName, checkbox) {
    if (this.id != null) {
        beanId = this.id.substring(1);
        firstName = this.getAttribute("id1").substring(1);
        lastName = this.getAttribute("id2").substring(1);
        checkbox = this;
    }
    document.getElementById("addedMembersDiv").style.display = "block";
    var addedMembersTBody = document.getElementById("addedTBody");
    var rowToBeDeleted = document.getElementById("tr" + beanId);
    if (rowToBeDeleted != null) {
        if (!checkbox.checked) {
            deleteAddedRow(beanId);
        }
        return;
    }
    //   for (i = 0; i < document.getElementsByName("addedMembersInput").length; i++) {
    //      if (document.getElementsByName("addedMembersInput")[i].value == beanId) {
    //         if (!checkbox.checked) {
    //            deleteAddedRow(beanId);
    //         }
    //         return;
    //      }
    //   }
    if (!checkbox.checked) {
        return;
    }

    var tr = document.createElement('tr');
    tr.setAttribute("id", "tr" + beanId);
    var span = document.createElement('span');
    span.style.cssText = 'margin-left: 10px;';
    span.setAttribute("style", "margin-left: 10px;");
    var fullName = lastName + " " + firstName;
    if (fullName.length >= 21) {
        fullName = fullName.substring(0, 18) + "...";
    }
    var fullNameElement = document.createTextNode(fullName);
    var td1 = document.createElement('td');
    var td2 = document.createElement('td');
    var input = document.createElement('input');
    input.setAttribute("type", "hidden");
    input.setAttribute("name", "addedMembersInput");
    input.setAttribute("value", beanId);
    var link = document.createElement('a');
    link.setAttribute("href", "#");
    link.setAttribute("class", "remove");
    link.setAttribute("className", "remove");
    link.setAttribute("id", "a" + beanId);
    link.setAttribute("onclick", "deleteAddedRow(" + beanId + ")");
    link.onclick = deleteAddedRow;
    td1.appendChild(link);
    span.appendChild(fullNameElement);
    td2.appendChild(span);
    td2.appendChild(input);
    tr.appendChild(td1);
    tr.appendChild(td2);
    addedMembersTBody.appendChild(tr);
}

function deleteAddedRow(beanId) {
    if (this.id != null) {
        beanId = this.id.substring(1);
    }
    var rowToBeDeleted = document.getElementById("tr" + beanId);
    if (rowToBeDeleted != null) {
        document.getElementById("addedTBody").removeChild(rowToBeDeleted);
    }
}

function changeRowClass(thisRow) {
    if (thisRow.className == 'odd') {
        thisRow.className = 'odd1';
    }
    else {
        thisRow.className = 'even1';
    }
}

function changeBackRowClass(thisRow) {
    thisRow.className = thisRow.className.substr(0, thisRow.className.length - 1);
}

function changeRowClass1() {
    if (this.className == 'odd') {
        this.className = 'odd1';
    }
    else {
        this.className = 'even1';
    }
}

function changeBackRowClass1() {
    this.className = this.className.substr(0, this.className.length - 1);
}

var modalWindow = {
    parent:"body",
    windowId:null,
    content:null,
    width:null,
    height:null,
    close:function()
    {
        $(".modal-window").remove();
        $(".modal-overlay").remove();
    },
    open:function()
    {
        var modal = "";
        modal += "<div class=\"modal-overlay\"></div>";
        modal += "<div id=\"" + this.windowId + "\" class=\"modal-window\" style=\"width:" + this.width + "px; height:" + this.height + "px; margin-top:-" + (this.height / 2) + "px; margin-left:-" + (this.width / 2) + "px;\">";
        modal += this.content;
        modal += "</div>";

        $(this.parent).append(modal);

        $(".modal-window").append("<a class=\"close-window\"></a>");
        $(".close-window").click(function() {
            modalWindow.close();
        });
        $(".modal-overlay").click(function() {
            modalWindow.close();
        });
    }
};
var openMyModal = function(source)
{
    modalWindow.windowId = "myModal";
    modalWindow.width = 480;
    modalWindow.height = 405;
    modalWindow.content = "<iframe width='480' height='405' frameborder='0' scrolling='no' allowtransparency='true' src='" + source + "'></iframe>";
    modalWindow.open();
};
