//--内寸取得
function getScreenSize() {
	var w, h;
	if(window.opera || document.layers) {
		w = window.innerWidth;
		h = window.innerHeight;
	} else if(document.all) {
		w = window.document.body.clientWidth;
		h = window.document.body.clientHeight;
	} else if(document.getElementById) {
		w = window.innerWidth;
		h = window.innerHeight;
	}
	return {w:w, h:h};
}

//--サイズ変更
//id - element id
//w, h - 設定したいサイズ(px or %)
//w_min, w_max - 横最低、最大サイズ。%指定時のみ適用(option)
//h_min, h_max - 縦最低、最大サイズ。%指定時のみ適用(option)
function setObjSize(id, w, w_min, w_max, h, h_min, h_max) {
	//%指定だった場合、指定範囲内でpxに変換
	if(typeof(w) == "string") {
		if(w.indexOf("%") != -1)	w = getPerToPx("width", replaceStr(w, "%", "") / 100, w_min, w_max);
	}
	if(typeof(h) == "string") {
		if(h.indexOf("%") != -1)	h = getPerToPx("height", replaceStr(h, "%", "") / 100, h_min, h_max);
	}
	
	setSize();
	
	function setSize() {
		if(window.opera){
			document.getElementById(id).style.pixelWidth = w;
			document.getElementById(id).style.pixelHeight = h;
		} else if(document.getElementById){
			document.getElementById(id).style.width = w + 'px';
			document.getElementById(id).style.height = h + 'px';
		} else if(document.all){
			document.all(id).style.pixelWidth = w;
			document.all(id).style.pixelHeight = h;
		} else if(document.layers)	document.layers[id].resizeTo(w ,h);
	}
}

//%指定をpxに変換
//dir - 縦横の指定("width" or "height")
//per - %(100%=1)
//min - 許容最低値(px)(option)
//max - 許容最高値(px)(option)
function getPerToPx(dir, per, min, max) {
	var px;
	
	if(dir == "width")	px = getScreenSize().w * per;
	else if(dir == "height")	px = getScreenSize().h * per;
	
	//補正
	if(min && px < min)	px = min;
	else if(max && px > max)	px = max;
	
	return px;
}

//--add listener
function addListener(elm, type, func) {
	if(! elm)	return false;
	if(elm.addEventListener) {
		elm.addEventListener(type, func, false);
	} else if(elm.attachEvent) {
		elm.attachEvent('on'+type, func);
	} else {
		return false;
	}
	return true;
}

//--文字の置換す
//str - 置換対象文字列
//b - 置換する文字列
//a - 変更する文字列
function replaceStr(str, b, a){
	var text;
	text = str;
	text = text.split(b);
	text = text.join(a);
	return text;
}
