﻿/*Sayfadaki objelerin kontrol edildiği fonksiyonlar başladı*/
//------------------------------------------------------------------------
function ObjectManager(){
    
}

ObjectManager.prototype.getSelectedRadioButtonListValue = function (objId){
    var rbList = document.getElementsByName(objId); 
    var val = '';
    
    for(var i=0; i<rbList.length; i++){
        if(rbList[i].checked)val = rbList[i].value;
    } 
    
    return val;
};

ObjectManager.prototype.getTextBoxValue = function (objId){
    var txtObj = document.getElementById(objId); 
    
    return txtObj.value;
};

ObjectManager.prototype.getDdlSelectedValue = function (objId){
    var ddlObj = document.getElementById(objId); 
    var val = '';
    
    if(ddlObj.options.length > 0 && ddlObj.selectedIndex > -1){//ddlObj.selectedIndex > 0
        if(ddlObj.options[ddlObj.selectedIndex].value != null)
            val = ddlObj.options[ddlObj.selectedIndex].value;
    }
    
    return val;
};

ObjectManager.prototype.getDdlSelectedText = function (objId){
    var ddlObj = document.getElementById(objId); 
    var text = '';
    
    if(ddlObj.options.length > 0){
        if(ddlObj.options[ddlObj.selectedIndex].text != null)
            text = ddlObj.options[ddlObj.selectedIndex].text;
    }
    
    return text;
};

ObjectManager.prototype.getCheckBoxValue = function (objId){
    var chkObj = document.getElementById(objId); 
    var val = '';
    
    if(chkObj.checked)
        val = chkObj.value;
        
    return val;
};

ObjectManager.prototype.setSelectedRadioButtonListValue = function (objId, _value){
    var rbList = document.getElementsByName(objId); 
    var val = '';
    
    for(var i=0; i<rbList.length; i++){
        if(rbList[i].value == _value)rbList[i].checked = true;
    } 
};

ObjectManager.prototype.setTextBoxValue = function (objId, _value){
    var txtObj = document.getElementById(objId); 
    
    txtObj.value = _value;
};

ObjectManager.prototype.setDdlSelectedValue = function (objId, _value){
    var ddlObj = document.getElementById(objId); 
    
    if(ddlObj.options.length > 0){
        for(var i=0; i<ddlObj.options.length; i++){
            if(ddlObj.options[i].value == _value)
                ddlObj.options[i].selected = true;
        }
    }
};

ObjectManager.prototype.setCheckBoxChecked = function (objId){
    var chkObj = document.getElementById(objId); 
    chkObj.checked = true;
};

/*Sayfadaki objelerin kontrol edildiği fonksiyonlar bitti*/
//------------------------------------------------------------------------

function setListBox(sourceListBoxId, destListBoxId, isInsert){
    var sourceListBox = document.getElementById(sourceListBoxId);
    var destListBox = document.getElementById(destListBoxId);
    
    if(isInsert){
        for(var i=0; i<sourceListBox.options.length; i++){
            if(sourceListBox.options[i].selected){
                var selectedValue = sourceListBox.options[i].value;
                var count = 0;
                
                if(selectedValue != '0'){
                    for(var j=0; j<destListBox.options.length; j++){
                        if(destListBox.options[j].value == selectedValue)break;
                        else count = count + 1;
                    }
                    
                    if(count == destListBox.options.length){
                        var optn = document.createElement('OPTION');
                        optn.text=sourceListBox.options[i].text;
                        optn.value=sourceListBox.options[i].value;
                        destListBox.options.add(optn);
                    }
                }
            }
        }
    }
    else{
        for(var i=destListBox.options.length-1; i>=0; i--){
            if(destListBox.options[i].selected){
                destListBox.removeChild(destListBox.options[i]);
            }
        }
    }
}
