function euc_char2byte_pos($str, $pos, $charset) {
		$sjis = ($charset == 'shift_jis');
		$n = 0; // number of characters seen
		$p = abs($pos); // number of characters wanted

		if ($pos >= 0) {
			$i = 0;
			$d = 1;
		} else {
			$i = strlen($str) - 1;
			$d = -1;
		}

		for (; strlen($str{$i}) && $n < $p; $i += $d) {
			$c = ord($str{$i});
			if ($sjis) {
				if (($c >= 0x80 && $c < 0xA0) || ($c >= 0xE0)) {
					$i += $d;
				} // advance a double-byte char
			}
			else {
				if ($c >= 0x80) {
					$i += $d;
				} // advance a double-byte char
			}

			$n++;
		}
		if (!strlen($str{$i})) {
			return FALSE;
		} // offset beyond string length

		if ($pos < 0) {
			$i++;
		} // correct offset

		return $i;
	}