second part of answer (because of 800 character limit error, my text was only 2843 characters).
if($newpointsafterupvote<0){
// only hide upvoting button
if (strpos($voteview, '-uponly-level')) {
$fields['vote_state']='disabled';
$fields['vote_down_tags']='TITLE="'.qa_lang_html('main/vote_disabled_down').'"';
$fields['vote_up_tags']='TITLE="'.qa_lang_html('main/vote_disabled_level').'"';
} else {
// vote_state 'down_only' does not exist. Therfore use disabled state.
$fields['vote_state']='disabled';
$fields['vote_down_tags']='TITLE="'.qa_lang_html('main/vote_disabled_down').'"';
$fields['vote_up_tags']='TITLE="'.qa_lang_html('main/vote_disabled_level').'"';
}
}else{
// after click on either up or downvote button, points will be >0
if (strpos($voteview, '-uponly-level')) {
$fields['vote_state']='up_only';
$fields['vote_down_tags']='TITLE="'.qa_lang_html('main/vote_disabled_down').'"';
} else {
$fields['vote_state']='enabled';
$fields['vote_down_tags']='TITLE="'.qa_lang_html('main/vote_down_popup').'" NAME="'.qa_html('vote_'.$postid.'_-1_'.$elementid).'" '.$onclick;
}
}
}