function disable_input(input_id) {
	var obj = document.getElementById(input_id)
	if (obj) {
		obj.value="";
		obj.disabled=true;
	}
}

function clear_input (input_id) {
	var obj = document.getElementById(input_id)
	if (obj) {
		obj.value="";
	}
}

function enable_input(input_id) {
	var obj = document.getElementById(input_id)
	if (obj) {
		obj.value="";
		obj.disabled=false;
	}
}

function getCheckedValue(radioObj) {
    if(!radioObj)
        return "";
    var radioLength = radioObj.length;
    if(radioLength == undefined)
        if(radioObj.checked)
            return radioObj.value;
        else
            return "";
    for(var i = 0; i < radioLength; i++) {
        if(radioObj[i].checked) {
            return radioObj[i].value;
        }
    }
    return "";
}

function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

function setDropDownValue(ddObj, newValue) {
	if(!ddObj)
		return;
	var ddLength = ddObj.length;

	for(var i=0; i < ddLength; i++) {
		if(ddObj.options[i].value == newValue.toString()) {
			ddObj.options[i].selected = true;
		}
	}
}

function dd_clearTextboxIfNotOther(ddObj,tbOther) {
	if(!ddObj) return;
    if (ddObj.options[ddObj.selectedIndex].text.toLowerCase()!="other") {
        other=document.getElementById(tbOther);
        if (other) other.value="";
    }
}

function cb_clearTextboxIfNotOther(ddObj,tbOther) {
	if(!ddObj) return;

    if (!ddObj.checked) {
        other=document.getElementById(tbOther);
        if (other) other.value="";
    }
}

function checkMinMaxAnswers_checkbox(cb_name, min, max, callingObj, silent, intendedState) {
    if(!cb_name)  return "";

    var num_checked = 0;
    if (callingObj) callingObj.checked=(intendedState!=null)?intendedState:callingObj.checked;

    cb_name=document.getElementsByName(cb_name);

    for(var i = 0; i < cb_name.length; i++) {
        if(cb_name[i].checked) {
        	num_checked++;
            //alert(i+" "+num_checked)
        }
    }

    var ret=0;
    if (min+max>0) {
        if (num_checked>max) {
            if (!silent) alert('You have already chosen the maximum number of answers.');
            ret=2;
        } else if (num_checked<min) {
            if (!silent) alert('Please choose '+(min-num_checked)+' more answers for this question');
            ret=-2;
        } else if (num_checked==max) {
            ret=1;
        } else if (num_checked==min) {
            ret=-1;
        }
        //alert(num_checked);
        //alert(ret);
    }

    if (callingObj) {
    	if (max>0 && num_checked>max) callingObj.checked=(intendedState!=null)?!intendedState:false;
        //alert(callingObj.checked + " " + ret);
    } else {
    }

    return ret;
}


function checkMinMaxAnswers_listbox(lb, min, max, silent, tbOther) {
    if(!lb)  return "";

    var num_checked = 0;
    var has_other=false;
    for(var i = 0; i < lb.length; i++) {
        if(lb.options[i].selected) {
        	num_checked++;
            if ((min+max)>0 && num_checked>max) lb.options[i].selected=false;
            if (lb.options[i].selected && lb.options[i].text.toLowerCase()=='other') has_other=true;
        }
    }

    //alert(num_checked);

    if (!has_other) {
        other=document.getElementById(tbOther);
        if (other) other.value="";
    }

    var ret=0;
    if (min+max>0) {
        if (num_checked>max) {
            if (!silent) alert('You have already chosen the maximum number of answers.');
            ret=2;
        } else if (num_checked<min) {
            if (!silent) alert('Please choose '+(min-num_checked)+' more answers for this question');
            ret=-2;
        } else if (num_checked==max) {
            ret=1;
        } else if (num_checked==min) {
            ret=-1;
        }
    }

    return ret;
}


