try {
	window.addEventListener("load", hover_func, false);
} catch(e) {
	window.attachEvent("onload", hover_func);
}

function hover_func() {
	var elm = document.getElementsByTagName('img');
	for (var i=0; i<elm.length; i++) {
		if (elm[i].className.indexOf('hover') >= 0) {
			elm[i].onmouseover = mouse_over_image;
			elm[i].onmouseout = mouse_out_image;
		}
	}
	var elm = document.getElementsByTagName('input');
	for (var i=0; i<elm.length; i++) {
		if (elm[i].className.indexOf('hover') >= 0) {
			elm[i].onmouseover = mouse_over_image;
			elm[i].onmouseout = mouse_out_image;
		}
	}
}

function mouse_over_image() {
	if (this.src.indexOf('.jpg') > 0)
		this.src = this.src.replace('.jpg', '_o.jpg');
	else if (this.src.indexOf('.gif') > 0)
		this.src = this.src.replace('.gif', '_o.gif');
	else if (this.src.indexOf('.png') > 0)
		this.src = this.src.replace('.png', '_o.png');
}

function mouse_out_image() {
	if (this.src.indexOf('.jpg') > 0)
		this.src = this.src.replace('_o.jpg', '.jpg');
	else if (this.src.indexOf('.gif') > 0)
		this.src = this.src.replace('_o.gif', '.gif');
	else if (this.src.indexOf('.png') > 0)
		this.src = this.src.replace('_o.png', '.png');
}

function flip_fontimage(size, set) {
	imgelm = window.document.getElementById('font_'+size);
	if (size == 'small')
		imgelm.src = set? '/img/btn_fontsd.gif': '/img/btn_fonts.gif';
	else if (size == 'medium')
		imgelm.src = set? '/img/btn_fontmd.gif': '/img/btn_fontm.gif';
	else if (size == 'large')
		imgelm.src = set? '/img/btn_fontld.gif': '/img/btn_fontl.gif';
}
function update_cookie_basefont(size) {
	update_cookie('font='+size);
}
function update_cookie(param) {
	if (window.XMLHttpRequest)
		http = new XMLHttpRequest();
	else if (window.ActiveXObject) {
		http = new ActiveXObject('Msxml2.XMLHTTP');
		if (http == null) http = new ActiveXObject('Microsoft.XMLHTTP');
	}
	if (http != null) {
		http.open('GET', '/_update_cookie.php?'+param, true);
		http.send(null);
	}
}
function update_basefont(size) {
	if (window.document.body.className != size &&
		(size == 'small' || size == 'medium' || size == 'large')) {
		flip_fontimage(document.body.className, false);
		window.document.body.className = size;
		flip_fontimage(size, true);
		update_cookie_basefont(size);
	}
}

function menu_hover(menu, hover) {
	if (hover) {
		var dgif = menu.childNodes[0].src.indexOf("_d.gif", 6);
		if (dgif >= 0) {
			var imgfile = menu.childNodes[0].src.substr(0, dgif) + ".gif";
			menu.childNodes[0].src = imgfile;
		}
	} else {
		var gif = menu.childNodes[0].src.indexOf(".gif", 6);
		if (gif >= 0) {
			var imgfile = menu.childNodes[0].src.substr(0, gif) + "_d.gif";
			menu.childNodes[0].src = imgfile;
		}
	}
}

function add_item( elm, category) {
	var num_items = window.document.getElementById("num_items");
	var checkitems = window.document.getElementById("checkitem_list");
	var checkitems_h3 = checkitems.getElementsByTagName("h3");
	var compares_list = window.document.getElementById("compares_list");
	var checkitems_ul = compares_list.getElementsByTagName("ul");
	var compares_button = window.document.getElementById("compares_button");
	if (checkitems_ul.length > 0)
		var checkitems_li = checkitems_ul[0].getElementsByTagName("li");
	var item_uri = elm.value.substring(0, elm.value.indexOf(':'));
	var item_label = elm.value.substring(elm.value.indexOf(':')+1);
	var ads = window.document.getElementById("google_ads");
	if (ads != null && ads.style.visibility != null) {
		var ads_style_visibility = ads.style.visibility;
		ads.style.visibility = "hidden";
	}
	if (elm.checked) {
		if (num_items.value < 5) {
			update_cookie('in='+escape(elm.value)+'&category='+category);
			if (checkitems_ul.length > 0) {
				checkitems_ul[0].innerHTML += ("<li><a href=\"/" + category + "/" + item_uri + "\">" + item_label +  "</a></li>");
				if (checkitems_li.length == 2) {
					if (compares_button != null) compares_button.innerHTML =
						"<a href=\"javascript:go_check()\"><img src=\"/img/btn_compare.gif\" width=\"130\" height=\"20\" alt=\"スペックを比較\" /></a>"+
						"&nbsp;<a href=\"javascript:clear_check()\"><img src=\"/img/btn_clear.gif\" width=\"130\" height=\"20\" alt=\"リストをクリア\" /></a>";
				}
			} else {
				if (compares_list != null) compares_list.innerHTML = "<ul><li><a href=\"/" + category + "/" + item_uri + "\">" + item_label +  "</a></li></ul>";
				if (compares_button != null) compares_button.innerHTML =
					"<img src=\"/img/btn_compare_d.gif\" width=\"130\" height=\"20\" alt=\"スペックを比較\" />"+
					"&nbsp;<a href=\"javascript:clear_check()\"><img src=\"/img/btn_clear.gif\" width=\"130\" height=\"20\" alt=\"リストをクリア\" /></a>";
			}
			num_items.value = parseInt(num_items.value)+1;
		} else {
			alert("チェックリストに登録できるのは最大5モデルまでです。");
			elm.checked = false;
		}
	} else {
		update_cookie('out='+escape(elm.value)+'&category='+category);
		if (checkitems_ul.length > 0) {
			if (checkitems_li.length == 1) {
				if (compares_list != null) compares_list.innerHTML = "現在、未登録です。";
				if (compares_button != null) compares_button.innerHTML = "<img src=\"/img/btn_compare_d.gif\" width=\"130\" height=\"20\" alt=\"スペックを比較\" />";
			} else {
				liHTML = "";
				for (i=0; i<checkitems_li.length; i++) {
					checkitems_li_a = checkitems_li[i].getElementsByTagName("a");
					trim_item = checkitems_li_a[0].innerHTML.replace(/(^\s*)|(\s*$)/g, "");
					if (trim_item != item_label) liHTML += ("<li>" + checkitems_li[i].innerHTML + "</li>");
				}
				checkitems_ul[0].innerHTML = liHTML;
				if (checkitems_li.length == 1) {
					if (compares_button != null) compares_button.innerHTML =
						"<img src=\"/img/btn_compare_d.gif\" width=\"130\" height=\"20\" alt=\"スペックを比較\" />"+
						"&nbsp;<a href=\"javascript:clear_check()\"><img src=\"/img/btn_clear.gif\" width=\"130\" height=\"20\" alt=\"リストをクリア\" /></a>";
				}
			}
			num_items.value = parseInt(num_items.value)-1;
		}
	}

	if (ads != null && ads.style.visibility != null)
		ads.style.visibility = ads_style_visibility;
	return true;
}
function go_check(url) {
	var checklist_form = window.document.getElementById("checklist_form");
	if (checklist_form )
		checklist_form.submit();
	else
		window.location = url;
}
function clear_check() {
	if (confirm('チェックリストをクリアしてよろしいですか')) {
		update_cookie('out=all&category=notebookpc,aspd');

		var ads = window.document.getElementById("google_ads");
		if (ads != null && ads.style.visibility != null) {
			ads_style_visibility = ads.style.visibility;
			ads.style.visibility = "hidden";
		}

		var checkitems = window.document.getElementById("checkitem_list");
		var compares_list = window.document.getElementById("compares_list");
		if (compares_list != null) compares_list.innerHTML = "現在、未登録です。";
		var compares_button = window.document.getElementById("compares_button");
		if (compares_button != null) compares_button.innerHTML = "<img src=\"/img/btn_compare_d.gif\" width=\"130\" height=\"20\" alt=\"スペックを比較\" />";

		if (window.document.checklist_form != null) {
			var input = window.document.checklist_form.getElementsByTagName("input");
			for (i=0; i<input.length; i++) {
				if (input[i].checked) input[i].checked = false;
			}
			var num_items = window.document.getElementById("num_items");
			if (num_items != null) 	num_items.value = 0;
		}

		if (ads != null && ads.style.visibility != null)
			ads.style.visibility = ads_style_visibility;
	}
}
function popup_photo(src) {
	photo_frame = window.document.getElementById("popup_photo_frame");
	photo_frame.innerHTML = "<div class=\"zoomed_photo\"><a href=\"javascript:close_photo()\" title=\"クリックすると、クローズします\"><img src=\"/img/btn_close.gif\" width=\"20\" height=\"20\" class=\"buttom\" alt=\"クリックすると、クローズします\" /><br /><img src=\""+src+"\" width=\"500\" alt=\"クリックすると、クローズします\" class=\"photo\" /></a></div>";
	photo_frame.style.width = "100%";
	photo_frame.style.top = ((document.documentElement.scrollTop > 0)? document.documentElement.scrollTop : document.body.scrollTop) + "px";
	photo_frame.className = "bg_photo";
	photo_frame.style.visibility = "visible";
}
function close_photo() {
	photo_frame = window.document.getElementById("popup_photo_frame");
	photo_frame.style.visibility = "hidden";
	photo_frame.innerHTML = "&nbsp;";
	photo_frame.style.width = "1px";
	photo_frame.className = "";
}

