if(navigator.appName=="Microsoft Internet Explorer") {
    var isIE = true;
}

function closeAllSelectBoxes(parFiredElement){
    //alert(parFiredElement.id)
    var allDivs=document.getElementsByName("divSelectBoxContent");
    //alert(allDivs);
    for(var i=0;i<allDivs.length;i++){
        if(isChildOf(allDivs[i].parentNode,parFiredElement)){
            if(parFiredElement.parentNode.id=="divSelectBoxItem"){
                selectItem(parFiredElement.parentNode);
            }
            toggleSelectBox(allDivs[i].parentNode);
        }else{
            allDivs[i].style.display = "none"
        }    
        //allDivs[i].style.display = "none";
    }
}
function isChildOf(parMotherObject, parChildObject){
    if(parChildObject.parentNode!=undefined){
        if(parMotherObject==parChildObject.parentNode){
            return true;
        }else{
            return isChildOf(parMotherObject, parChildObject.parentNode)
        }
    }else{
        return false
    }    
}

function toggleSelectBox(parSelectBox){
    if(isIE){selectBoxContent = parSelectBox.childNodes[1];}
    else{selectBoxContent = parSelectBox.childNodes[3];}
    if(selectBoxContent.style.display=="block"){
        selectBoxContent.style.display="none";
    }else{
        selectBoxContent.style.display="block";
        //selectBoxContent.style.z-index="3";
    }
}

function wijzigCssAttribuut(parClassName,parElement,parValue) {
    var rules;
    var rules = (isIE ? 'rules' : 'cssRules');  
    for (var i = 0; i < document.styleSheets.length; i++){
        for (var j = 0; j < document.styleSheets[i][rules].length; j++) {
            if (document.styleSheets[i][rules][j].selectorText == parClassName) {
                document.styleSheets[i][rules][j].style[parElement] = parValue;
            }
        }
    }    
}


function selectItem(parItem)
{
    var selectBoxTextItem = (isIE ? parItem.parentNode.parentNode.childNodes[0].childNodes[0]: parItem.parentNode.parentNode.childNodes[1].childNodes[1]);   
    
    //alert(parItem.parentNode.parentNode.childNodes[0].id)
    //alert(selectBoxTextItem.id)
    //var newText = trimAll(parItem.innerHTML);  
    var newText=""
    //newText = parItem.childNodes[0].innerHTML
    newText = parItem.innerHTML

    newText = newText.replace('&nbsp;',' ');
    selectBoxTextItem.value = newText.split("(",1)[0];
    selectBoxTextItem.id = parItem.id;     
    //alert(selectBoxTextItem.id+'-'+selectBoxTextItem.value);
    //hiddenAjaxRequest("xml/updateAantal.php?id="+parItem.parentNode.parentNode.parentNode.parentNode.id+"&aantal="+parItem.innerHTML)
}

function trimAll(sString){
    while (sString.charCodeAt(0) == 10||sString.charCodeAt(0) == 32){
        sString = sString.substring(1, sString.length);
    }
    //while (sString.substring(sString.length-1, sString.length) == ' '){
    while (sString.charCodeAt(sString.length-1) == 10||sString.charCodeAt(sString.length-1) == 32) {
        sString = sString.substring(0,sString.length-2);
    }
    return sString;
}

