var kikan = 60 * 60 * 24 * 365 * 5;
var isLink = false;

var rows;

var isHide = false;

var addresses = new Array();

function changeExp() {
	var explanation = document.getElementById("explanation");
	if(explanation.style.display == "none") {
		explanation.style.display = "block";
		var bbb = document.getElementById("expbtn");
		bbb.setAttribute("value", "説明を隠す");
		setCookie("exp", "1", kikan);
	} else {
		explanation.style.display = "none";
		var bbb = document.getElementById("expbtn");
		bbb.setAttribute("value", "説明を見る");
		setCookie("exp", "0", kikan);
	}
}

function changeTable() {
	if(haishin2.style.display == "none") {
		haishin1.style.display = "none";
		haishin2.style.display = "block";
		var bbb = document.getElementById("kirikae");
		bbb.setAttribute("value", "1段組に変更");
		setCookie("seldan", "2", kikan);
	} else {
		haishin1.style.display = "block";
		haishin2.style.display = "none";
		var bbb = document.getElementById("kirikae");
		bbb.setAttribute("value", "2段組に変更");
		setCookie("seldan", "1", kikan);
	}
}

//var checks = new Array();
var checks2 = new Array();

//function changeOff() {
//	var num;
//	var tables = document.getElementsByTagName("table");
//	for(var i = 0; i < tables.length; i++) {
//		if(tables[i].getAttribute("id") == "haishinsha1") {
//			var trs = tables[i].getElementsByTagName("tr");
//			num = trs.length - 1;
//		}
//	}
//	for(var j = 1; j <= num; j++) {
//		checks[j-1] = "1";
//		var check = document.getElementById("check" + j);
//		var checkd = document.getElementById("check" + j + "d");
//		check.checked = true;
//		checkd.checked = true;
//	}
//	setCookie("check", checks, kikan);
//}
//function changeOn() {
//	var num;
//	var tables = document.getElementsByTagName("table");
//	for(var i = 0; i < tables.length; i++) {
//		if(tables[i].getAttribute("id") == "haishinsha1") {
//			var trs = tables[i].getElementsByTagName("tr");
//			num = trs.length - 1;
//		}
//	}
//	for(var j = 1; j <= num; j++) {
//		checks[j-1] = "0";
//		var check = document.getElementById("check" + j);
//		var checkd = document.getElementById("check" + j + "d");
//		check.checked = false;
//		checkd.checked = false;
//	}
//	setCookie("check", checks, kikan);
//}

var s;
function changeOff2() {
	var num;
	var tables = document.getElementsByTagName("table");
	for(var i = 0; i < tables.length; i++) {
		if(tables[i].getAttribute("id") == "haishinsha1") {
			var trs = tables[i].getElementsByTagName("tr");
			num = trs.length - 1;
		}
	}
	for(var j = 1; j <= num; j++) {
		checks2[j-1] = "1";
		var check = document.getElementById("check_2" + j);
		var checkd = document.getElementById("check_2" + j + "d");
		check.checked = true;
		checkd.checked = true;
	}
	setCookie("check_2", checks2, kikan);
}
function changeOn2() {
	var num;
	var tables = document.getElementsByTagName("table");
	for(var i = 0; i < tables.length; i++) {
		if(tables[i].getAttribute("id") == "haishinsha1") {
			var trs = tables[i].getElementsByTagName("tr");
			num = trs.length - 1;
		}
	}
	for(var j = 1; j <= num; j++) {
		checks2[j-1] = "0";
		var check = document.getElementById("check_2" + j);
		var checkd = document.getElementById("check_2" + j + "d");
		check.checked = false;
		checkd.checked = false;
	}
	setCookie("check_2", checks2, kikan);
}

function getOnOffCookies() {
//	var ccccc = getCookie("check");
//	if(ccccc == "" || ccccc == null) {
//		changeOn();
//	} else {
//		checks = ccccc.split(",");
//		for(var i = 0; i < checks.length; i++) {
//			var check = document.getElementById("check" + (i + 1));
//			var checkd = document.getElementById("check" + (i + 1) + "d");
//			if(checks[i] == "1") {
//				check.checked = true;
//				checkd.checked = true;
//			} else {
//				check.checked = false;
//				checkd.checked = false;
//			}
//		}
//	}
	var onCheck = getCookie("check_2");
	if(onCheck == "" || onCheck == null) {
		changeOn2();
	} else {
		checks2 = onCheck.split(",");
		for(var i = 0; i < checks2.length; i++) {
			var check = document.getElementById("check_2" + (i + 1));
			var checkd = document.getElementById("check_2" + (i + 1) + "d");
			if(checks2[i] == "1") {
				check.checked = true;
				checkd.checked = true;
			} else {
				check.checked = false;
				checkd.checked = false;
			}
		}
	}
}


function setCheck(check) {
	var checkid = check.getAttribute("id");
	var checkval = parseInt(check.getAttribute("value"));
	if(checkid.charAt(checkid.length - 1) != "d") {
		var idd = checkid + "d";
		if(check.checked) {
			var checkd = document.getElementById(idd);
			checkd.checked = true;

			checks[checkval] = "1";
			setCookie("check", checks, kikan);
		} else {
			var checkd = document.getElementById(idd);
			checkd.checked = false;

			checks[checkval] = "0";
			setCookie("check", checks, kikan);
		}
	} else {
		var id = checkid.substring(0, checkid.length - 1);
		if(check.checked) {
			var checkk = document.getElementById(id);
			checkk.checked = true;

			checks[checkval] = "1";
			setCookie("check", checks, kikan);
		} else {
			var checkk = document.getElementById(id);
			checkk.checked = false;

			checks[checkval] = "0";
			setCookie("check", checks, kikan);
		}
	}
}
function setCheck2(check) {
	var checkid = check.getAttribute("id");
	var checkval = parseInt(check.getAttribute("value"));
	if(checkid.charAt(checkid.length - 1) != "d") {
		var idd = checkid + "d";
		if(check.checked) {
			var checkd = document.getElementById(idd);
			checkd.checked = true;

			checks2[checkval] = "1";
			setCookie("check_2", checks2, kikan);
		} else {
			var checkd = document.getElementById(idd);
			checkd.checked = false;

			checks2[checkval] = "0";
			setCookie("check_2", checks2, kikan);
		}
	} else {
		var id = checkid.substring(0, checkid.length - 1);
		if(check.checked) {
			var checkk = document.getElementById(id);
			checkk.checked = true;

			checks2[checkval] = "1";
			setCookie("check_2", checks2, kikan);
		} else {
			var checkk = document.getElementById(id);
			checkk.checked = false;

			checks2[checkval] = "0";
			setCookie("check_2", checks2, kikan);
		}
	}
}

function setVisit0() {
	setCookie("visit", "0");
}


function initOnLoad() {
    if (!document.getElementsByTagName) {
    	alert("ブラウザが対応していません。");
    	return;
    }

	if(!navigator.cookieEnabled) {
		alert("クッキーを有効にしてください。");
		return;
	}

	var visit = getCookie("visit");
	if(visit == "" || visit == "0") {
		visit = "1";
		setCookie("visit", visit, 15);
	} else if(visit == "1") {
	    haishin1 = document.getElementById("haishin1");
	    haishin1.style.display = "none";
	    haishin2 = document.getElementById("haishin2");
	    haishin2.style.display = "none";
		alert("更新ボタンは30秒以上待ってください。");
		return;
	} else {
	    haishin1 = document.getElementById("haishin1");
	    haishin1.style.display = "none";
	    haishin2 = document.getElementById("haishin2");
	    haishin2.style.display = "none";
		alert("更新ボタンは30秒以上待ってください。");
		return;
	}

    var kirikaeBtn = document.getElementById("kirikae");
    setListener(kirikaeBtn, "click", changeTable);
//    var offBtn = document.getElementById("zenoff");
//    setListener(offBtn, "click", changeOff)
//    var onBtn = document.getElementById("zenon");
//    setListener(onBtn, "click", changeOn)
    var offBtn2 = document.getElementById("zenoff2");
    setListener(offBtn2, "click", changeOff2);
    var onBtn2 = document.getElementById("zenon2");
    setListener(onBtn2, "click", changeOn2);
    var expBtn = document.getElementById("expbtn");
    setListener(expBtn, "click", changeExp);
    var linkbtn = document.getElementById("linkbtn");
    setListener(linkbtn, "click", hide);

    var sd = getCookie("seldan");
    if(sd != "1" && sd != "2") {
    	sd = "1";
    	setCookie("seldan", sd, kikan);
        haishin1 = document.getElementById("haishin1");
        haishin1.style.display = "block";
        haishin2 = document.getElementById("haishin2");
        haishin2.style.display = "none";
		var bbb = document.getElementById("kirikae");
		bbb.setAttribute("value", "2段組に変更");
    } else if(sd == "1") {
    	setCookie("seldan", sd, kikan);
        haishin1 = document.getElementById("haishin1");
        haishin1.style.display = "block";
        haishin2 = document.getElementById("haishin2");
        haishin2.style.display = "none";
		var bbb = document.getElementById("kirikae");
		bbb.setAttribute("value", "2段組に変更");
    } else if(sd == "2") {
    	setCookie("seldan", sd, kikan);
        haishin1 = document.getElementById("haishin1");
        haishin1.style.display = "none";
        haishin2 = document.getElementById("haishin2");
        haishin2.style.display = "block";
		var bbb = document.getElementById("kirikae");
		bbb.setAttribute("value", "1段組に変更");
    }

    var ex = getCookie("exp");
    if(ex == "" || ex == "1") {
    	ex = "1";
    	setCookie("exp", ex, kikan);
    	var explanation = document.getElementById("explanation");
    	explanation.style.display = "block";
    } else if(ex == "0") {
    	setCookie("exp", ex, kikan);
		var bbb = document.getElementById("expbtn");
		bbb.setAttribute("value", "説明を見る");
    	var explanation = document.getElementById("explanation");
    	explanation.style.display = "none";
    }

    var ujlink = getCookie("ujlink");
    if(ujlink == "" || ujlink == "1") {
    	setCookie("ujlink", ujlink, kikan);
    } else {
    	setCookie("ujlink", "0", kikan);
//    	isHide = true;
    	hide();
    }

    var ustwidth = getCookie("ustwidth");
    var ustheight = getCookie("ustheight");
    var juswidth = getCookie("juswidth");
    var jusheight = getCookie("jusheight");
    var btvwidth = getCookie("btvwidth");
    var btvheight = getCookie("btvheight");
    if(ustwidth == "" || ustheight == "" || juswidth == "" || jusheight == "" || btvwidth == "" || btvheight == "") {
        document.getElementById("ustwidth").value = 480;
        document.getElementById("ustheight").value = 384;
        document.getElementById("juswidth").value = 630;
        document.getElementById("jusheight").value = 354;
        document.getElementById("btvwidth").value = 480;
        document.getElementById("btvheight").value = 460;
    } else {
        document.getElementById("ustwidth").value = ustwidth;
        document.getElementById("ustheight").value = ustheight;
        document.getElementById("juswidth").value = juswidth;
        document.getElementById("jusheight").value = jusheight;
        document.getElementById("btvwidth").value = btvwidth;
        document.getElementById("btvheight").value = btvheight;
    }

//    var spVersion = getCookie("spversion");
//    if(spVersion == "" || spVersion == "α") {
//    	setCookie("spversion", spVersion, kikan);
//    } else if(spVersion == "β") {
//    	setCookie("spvertion", "β", kikan);
//    	changeSpVersion("β");
//    }

//    var lin = getCookie("lin");
//    if(lin != "1") {
//    	lin = "0";
//    	setCookie("lin", lin, kikan);
//    } else {
//    	setCookie("lin", lin, kikan);
////    	var ul = document.getElementById("ustlink");
////    	ul.checked = true;
//    }


    var zebraTables = document.getElementsByTagName("table");

    for (var i = 0; i < zebraTables.length; i++) {
        if (zebraTables[i].className.match("haishinsha")) {
            var zr;
            var zebraRows = zebraTables[i].getElementsByTagName("tr");
            zebraRows[0].className = "trcolor1";


        	if(zebraTables[i].getAttribute("id") == "haishinsha1") {
                rows = zebraRows.length - 1;
	            for (var k=1; k < zebraRows.length; k++) {
	            	var zebraTds = zebraRows[k].getElementsByTagName("td");
            		var zebraA = zebraTds[0].getElementsByTagName("a");
            		zebraTds[0].setAttribute("id", "names" + k);
            		zebraA[0].setAttribute("id", "name" + k);
//            		zebraA[1].setAttribute("id", "namej" + k);
            		zebraTds[1].setAttribute("id", "status" + k);
            		zebraTds[2].setAttribute("id", "statusj" + k);
            		zebraTds[3].setAttribute("id", "statusb" + k);
//					var check = zebraTds[3].getElementsByTagName("input");
//					check[0].setAttribute("id", "check" + k);
//					check[0].setAttribute("value", String(k - 1));
					var check = zebraTds[4].getElementsByTagName("input");
					check[0].setAttribute("id", "check_2" + k);
					check[0].setAttribute("value", String(k - 1));
					var btn = zebraTds[5].getElementsByTagName("input");
//            		btn[0].setAttribute("id", "btn" + k);
            		btn[0].setAttribute("id", "btn_2" + k);
					var links1 = zebraTds[6].getElementsByTagName("a");
					links1[0].setAttribute("id", "ustlink" + k);
					var links2 = zebraTds[7].getElementsByTagName("a");
					links2[0].setAttribute("id", "juslink" + k);
					var links3 = zebraTds[8].getElementsByTagName("a");
					links3[0].setAttribute("id", "btvlink" + k);

					var img1 = zebraTds[6].getElementsByTagName("img");
					img1[0].setAttribute("id", "ustimg" + k);
					var img2 = zebraTds[7].getElementsByTagName("img");
					img2[0].setAttribute("id", "jusimg" + k);
					var img3 = zebraTds[8].getElementsByTagName("img");
					img3[0].setAttribute("id", "btvimg" + k);

					var btns = zebraTds[9].getElementsByTagName("input");
					btns[0].setAttribute("id", "ustpop" + k);
					btns[1].setAttribute("id", "juspop" + k);
					btns[2].setAttribute("id", "btvpop" + k);

	                if (k%2) {
	                    zebraRows[k].className = "trcolor2";
	                } else {
	                    zebraRows[k].className = "trcolor3";
	                }
	            }
        	} else if(zebraTables[i].getAttribute("id") == "haishinsha2") {
	            zr = zebraRows.length;

	            for (var k=1; k < zebraRows.length; k++) {
	            	var zebraTds = zebraRows[k].getElementsByTagName("td");
            		var zebraA = zebraTds[0].getElementsByTagName("a");
            		zebraTds[0].setAttribute("id", "names" + k + "d");
            		zebraA[0].setAttribute("id", "name" + k + "d");
//            		zebraA[1].setAttribute("id", "namej" + k + "d");
            		zebraTds[1].setAttribute("id", "status" + k + "d");
            		zebraTds[2].setAttribute("id", "statusj" + k + "d");
            		zebraTds[3].setAttribute("id", "statusb" + k + "d");
//					var check = zebraTds[3].getElementsByTagName("input");
//					check[0].setAttribute("id", "check" + k + "d");
//					check[0].setAttribute("value", String(k - 1));
					var check = zebraTds[4].getElementsByTagName("input");
					check[0].setAttribute("id", "check_2" + k + "d");
					check[0].setAttribute("value", String(k - 1));
					var btn = zebraTds[5].getElementsByTagName("input");
//            		btn[0].setAttribute("id", "btn" + k + "d");
            		btn[0].setAttribute("id", "btn_2" + k + "d");
					var links1 = zebraTds[6].getElementsByTagName("a");
					links1[0].setAttribute("id", "ustlink" + k + "d");
					var links2 = zebraTds[7].getElementsByTagName("a");
					links2[0].setAttribute("id", "juslink" + k + "d");
					var links3 = zebraTds[8].getElementsByTagName("a");
					links3[0].setAttribute("id", "btvlink" + k + "d");

					var img1 = zebraTds[6].getElementsByTagName("img");
					img1[0].setAttribute("id", "ustimg" + k + "d");
					var img2 = zebraTds[7].getElementsByTagName("img");
					img2[0].setAttribute("id", "jusimg" + k + "d");
					var img3 = zebraTds[8].getElementsByTagName("img");
					img3[0].setAttribute("id", "btvimg" + k + "d");

					var btns = zebraTds[9].getElementsByTagName("input");
					btns[0].setAttribute("id", "ustpop" + k + "d");
					btns[1].setAttribute("id", "juspop" + k + "d");
					btns[2].setAttribute("id", "btvpop" + k + "d");

	                if (k%2) {
	                    zebraRows[k].className = "trcolor2";
	                } else {
	                    zebraRows[k].className = "trcolor3";
	                }
	            }
        	} else if(zebraTables[i].getAttribute("id") == "haishinsha3") {

	            for (var k=1; k < zebraRows.length; k++) {
	            	var zebraTds = zebraRows[k].getElementsByTagName("td");
            		var zebraA = zebraTds[0].getElementsByTagName("a");
            		zebraTds[0].setAttribute("id", "names" + (k + zr - 1) + "d");
            		zebraA[0].setAttribute("id", "name" + (k + zr - 1) + "d");
//            		zebraA[1].setAttribute("id", "namej" + (k + zr - 1) + "d");
            		zebraTds[1].setAttribute("id", "status" + (k + zr - 1) + "d");
            		zebraTds[2].setAttribute("id", "statusj" + (k + zr - 1) + "d");
            		zebraTds[3].setAttribute("id", "statusb" + (k + zr - 1) + "d");
//					var check = zebraTds[3].getElementsByTagName("input");
//					check[0].setAttribute("id", "check" + (k + zr - 1) + "d");
//					check[0].setAttribute("value", String(k + zr - 2));
					var check = zebraTds[4].getElementsByTagName("input");
					check[0].setAttribute("id", "check_2" + (k + zr - 1) + "d");
					check[0].setAttribute("value", String(k + zr - 2));
					var btn = zebraTds[5].getElementsByTagName("input");
//            		btn[0].setAttribute("id", "btn" + (k + zr - 1) + "d");
            		btn[0].setAttribute("id", "btn_2" + (k + zr - 1) + "d");
					var links1 = zebraTds[6].getElementsByTagName("a");
					links1[0].setAttribute("id", "ustlink" + (k + zr - 1) + "d");
					var links2 = zebraTds[7].getElementsByTagName("a");
					links2[0].setAttribute("id", "juslink" + (k + zr - 1) + "d");
					var links3 = zebraTds[8].getElementsByTagName("a");
					links3[0].setAttribute("id", "btvlink" + (k + zr - 1) + "d");

					var img1 = zebraTds[6].getElementsByTagName("img");
					img1[0].setAttribute("id", "ustimg" + (k + zr - 1) + "d");
					var img2 = zebraTds[7].getElementsByTagName("img");
					img2[0].setAttribute("id", "jusimg" + (k + zr - 1) + "d");
					var img3 = zebraTds[8].getElementsByTagName("img");
					img3[0].setAttribute("id", "btvimg" + (k + zr - 1) + "d");

					var btns = zebraTds[9].getElementsByTagName("input");
					btns[0].setAttribute("id", "ustpop" + (k + zr - 1) + "d");
					btns[1].setAttribute("id", "juspop" + (k + zr - 1) + "d");
					btns[2].setAttribute("id", "btvpop" + (k + zr - 1) + "d");

	                if (k%2) {
	                    zebraRows[k].className = "trcolor2";
	                } else {
	                    zebraRows[k].className = "trcolor3";
	                }
	            }
        	}
        }
    }
	dwr.engine.setActiveReverseAjax(true);
	UstAnnouncer.startCheck();

	var bar = getCookie("version");
	if(bar == "" || bar == null) {
		getOnOffCookies();
		setCookie("version", version, kikan);
	} else {
		if(parseInt(bar) <= 200906280014) {
//			var c1 = getCookie("check");
			var c2 = getCookie("check_2");
//			checks = c1.split(",");
			checks2 = c2.split(",");
			for(var i = 0; i < checks2.length; i++) {
//				if(checks[i] != "1") {
//					checks[i] = "0";
//				}
				if(checks2[i] != "1") {
					checks2[i] = "0";
				}
			}
//			setCookie("check", checks, kikan);
			setCookie("check_2", checks2, kikan);
		}
		if(bar != version && parseInt(bar) >= 200906280014) {
//			var ccccc1 = getCookie("check");
			var ccccc2 = getCookie("check_2");
			if(ccccc2 == "" || ccccc2 == null) {
				getOnOffCookies();
			} else {
				UstAnnouncer.checkUpdate(ccccc2, bar);
			}
			setCookie("version", version, kikan);
		} else {
			getOnOffCookies();
		}
	}

//	setCookie("version", version, kikan);
//	getOnOffCookies();
	setInterval(timer, 60000);
}

function updateCheck(chs2) {
//	checks = chs1.split(",");
	checks2 = chs2.split(",");
//	setCookie("check", checks, kikan);
	setCookie("check_2", checks2, kikan);
	getOnOffCookies();
}

function getCookie(key) {
    tmp = document.cookie+";";
    tmp1 = tmp.indexOf(key, 0);
    if(tmp1 != -1){
        tmp = tmp.substring(tmp1, tmp.length);
        start = tmp.indexOf("=", 0);
        end = tmp.indexOf(";", start);
        return(unescape(tmp.substring(start+1, end)));
    }
    return("");
}
function setCookie(key, value, time) {
	var date = new Date();
	var date2;
	date.setTime(date.getTime() + 1000 * time);
	date2 = date.toGMTString();
	document.cookie = key + "=" + escape(value) + ";expires=" + date2;
}
function deleteCookie(key) {
  document.cookie = key + "=;expires=Thu,01-Jan-70 00:00:01 GMT";
}

function changeStatusColor(status, val) {
	if(val == "ON AIR") {
		var e = document.getElementById(status);
		var ed = document.getElementById(status + "d");
		if(navigator.appName == 'Microsoft Internet Explorer') {
			e.setAttribute("className", "onair");
			ed.setAttribute("className", "onair");
		} else {
			e.setAttribute("class", "onair");
			ed.setAttribute("class", "onair");
		}
	} else if(val == "S"){
		var e = document.getElementById(status);
		var ed = document.getElementById(status + "d");
		if(navigator.appName == 'Microsoft Internet Explorer') {
			e.setAttribute("className", "standby");
			ed.setAttribute("className", "standby");
		} else {
			e.setAttribute("class", "standby");
			ed.setAttribute("class", "standby");
		}
	} else {
		var e = document.getElementById(status);
		var ed = document.getElementById(status + "d");
		if(navigator.appName == 'Microsoft Internet Explorer') {
			e.setAttribute("className", "offair");
			ed.setAttribute("className", "offair");
		} else {
			e.setAttribute("class", "offair");
			ed.setAttribute("class", "offair");
		}
	}
}

function setNowChange(num) {
	var names = document.getElementById("names" + num);
	var namesd = document.getElementById("names" + num + "d");
	if(navigator.appName == 'Microsoft Internet Explorer') {
		names.setAttribute("className", "nowchange");
		namesd.setAttribute("className", "nowchange");
	} else {
		names.setAttribute("class", "nowchange");
		namesd.setAttribute("class", "nowchange");
	}
	setTimeout("setNotNowChange('" + num + "')", 60000);
}
function setNotNowChange(num) {
	var half = Math.ceil(Number(rows) / 2);
	if(half % 2) {

		var names = document.getElementById("names" + num);
		var namesd = document.getElementById("names" + num + "d");
		if(Number(num) % 2) {
			if(navigator.appName == 'Microsoft Internet Explorer') {
				names.setAttribute("className", "trcolor2");
				if(Number(num) > half) {
					namesd.setAttribute("className", "trcolor3");
				} else {
					namesd.setAttribute("className", "trcolor2");
				}
			} else {
				names.setAttribute("class", "trcolor2");
				if(num > half) {
					namesd.setAttribute("class", "trcolor3");
				} else {
					namesd.setAttribute("class", "trcolor2");
				}
			}
		} else {
			if(navigator.appName == 'Microsoft Internet Explorer') {
				names.setAttribute("className", "trcolor3");
				if(Number(num) > half) {
					namesd.setAttribute("className", "trcolor2");
				} else {
					namesd.setAttribute("className", "trcolor3");
				}
			} else {
				names.setAttribute("class", "trcolor3");
				if(Number(num) > half) {
					namesd.setAttribute("class", "trcolor2");
				} else {
					namesd.setAttribute("class", "trcolor3");
				}
			}
		}
	} else {
		var names = document.getElementById("names" + num);
		var namesd = document.getElementById("names" + num + "d");
		if(Number(num) % 2) {
			if(navigator.appName == 'Microsoft Internet Explorer') {
				names.setAttribute("className", "trcolor2");
				namesd.setAttribute("className", "trcolor2");
			} else {
				names.setAttribute("class", "trcolor2");
				namesd.setAttribute("class", "trcolor2");
			}
		} else {
			if(navigator.appName == 'Microsoft Internet Explorer') {
				names.setAttribute("className", "trcolor3");
				namesd.setAttribute("className", "trcolor3");
			} else {
				names.setAttribute("class", "trcolor3");
				namesd.setAttribute("class", "trcolor3");
			}
		}
	}
}

function addButtonListener(btn, val, num) {
	var button = document.getElementById(btn);
	var buttond = document.getElementById(btn + "d");
	setListener(button, "click", function() { sound2Play(val, num); });
	setListener(buttond, "click", function() { sound2Play(val, num); });
}
function addButtonListener2(btn, val, num) {
	var button = document.getElementById(btn);
	var buttond = document.getElementById(btn + "d");
	setListener(button, "click", function() { sound2Play2(val, num); });
	setListener(buttond, "click", function() { sound2Play2(val, num); });
}

function setVideoListener(name, channel) {
   	var chlink = null;
   	var chlinkd = null;
   	if(!chlink) {
   		chlink = document.getElementById(name);
    	chlinkd = document.getElementById(name + "d");
    	chlink.setAttribute("href", "http://lonsdaleite.jp/stream_player/" + channel);
    	chlinkd.setAttribute("href", "http://lonsdaleite.jp/stream_player/" + channel);
   	}
}
//function setJVideoListener(name, channel) {
//   	var chlink = null;
//   	var chlinkd = null;
//   	if(!chlink) {
//    	chlink = document.getElementById(name);
//    	chlinkd = document.getElementById(name + "d");
//    	chlink.setAttribute("href", "http://lonsdaleite.jp/stream_player/alpha.html" + channel);
//    	chlinkd.setAttribute("href", "http://lonsdaleite.jp/stream_player/alpha.html" + channel);
//    	chlink.setAttribute("target", "_blank");
//		chlinkd.setAttribute("target", "_blank");
//    	setListener(chlink, "click", function() { getJEmbed(channel); } );
//    	setListener(chlinkd, "click", function() { getJEmbed(channel); } );
//   	}
//}

//Ustreamだよ
function setULink(id, address) {
	var ustlink = null;
	var ustlinkd = null;
	if(!ustlink) {
		if(address != "") {
			ustlink = document.getElementById("ustlink" + id);
			ustlinkd = document.getElementById("ustlink" + id + "d");
			ustlink.setAttribute("href", "http://www.ustream.tv/channel/" + address);
			ustlinkd.setAttribute("href", "http://www.ustream.tv/channel/" + address);
			document.getElementById("ustimg" + id).setAttribute("src", "u.gif");
			document.getElementById("ustimg" + id + "d").setAttribute("src", "u.gif");
		} else {
			document.getElementById("ustimg" + id).setAttribute("src", "blank.gif");
			document.getElementById("ustimg" + id + "d").setAttribute("src", "blank.gif");
		}

		var ustPopOutFunc = function(){
			var ustwidth = document.getElementById("ustwidth");
			var ustheight = document.getElementById("ustheight");

			var ust_w = ustwidth.value;
			var ust_h = ustheight.value;

			if(ust_w == "" || ust_h == "" || isNaN(ust_w) || isNaN(ust_h)) {
				ust_w = getCookie("ustwidth");
				ust_h = getCookie("ustheight");
				if(ust_w == null || ust_w == "" || isNaN(ust_w)) {
					ust_w = 480;
					ustwidth.value = 480;
				} else {
					ustwidth.value = ust_w;
				}
				if(ust_h == null || ust_h == "" || isNaN(ust_h)) {
					ust_h = 384;
					ustheight.value = 384;
				} else {
					ustheight.value = ust_h;
				}
			}
			window.open('http://www.ustream.tv/flash/live/' + address, address, 'width=' + ust_w + ',height=' + ust_h);
			void(0);
		};

		var ustpop = document.getElementById("ustpop" + id);
		var ustpopd = document.getElementById("ustpop" + id + "d");
//		ustpop.onclick = ustPopOutFunc;
//		ustpopd.onclick = ustPopOutFunc;
		setListener(ustpop, "click", ustPopOutFunc);
		setListener(ustpopd, "click", ustPopOutFunc);
//		ustpop.setAttribute("alt", address);
//		ustpopd.setAttribute("alt", address);
	}
}
//Justinだよ
function setJLink(id, address) {
	var juslink = null;
	var juslinkd = null;
	if(!juslink) {
		if(address != "") {
			juslink = document.getElementById("juslink" + id);
			juslinkd = document.getElementById("juslink" + id + "d");
			juslink.setAttribute("href", "http://www.justin.tv/" + address);
			juslinkd.setAttribute("href", "http://www.justin.tv/" + address);
			document.getElementById("jusimg" + id).setAttribute("src", "j.gif");
			document.getElementById("jusimg" + id + "d").setAttribute("src", "j.gif");
		} else {
			document.getElementById("jusimg" + id).setAttribute("src", "blank.gif");
			document.getElementById("jusimg" + id + "d").setAttribute("src", "blank.gif");
		}

		var jusPopOutFunc = function(){
			var juswidth = document.getElementById("juswidth");
			var jusheight = document.getElementById("jusheight");

			var jus_w = juswidth.value;
			var jus_h = jusheight.value;

			if(jus_w == "" || jus_h == "" || isNaN(jus_w) || isNaN(jus_h)) {
				jus_w = getCookie("juswidth");
				jus_h = getCookie("jusheight");
				if(jus_w == null || jus_w == "" || isNaN(jus_w)) {
					jus_w = 630;
					juswidth.value = 630;
				} else {
					juswidth.value = jus_w;
				}
				if(jus_h == null || jus_h == "" || isNaN(jus_h)) {
					jus_h = 354;
					jusheight.value = 354;
				} else {
					jusheight.value = jus_h;
				}
			}

			window.open('http://www.justin.tv/widgets/live_embed_player.swf?channel=' + address, address, 'width=' + jus_w + ',height=' + jus_h);
			void(0);
		};

		var juspop = document.getElementById("juspop" + id);
		var juspopd = document.getElementById("juspop" + id + "d");
//		juspop.onclick = jusPopOutFunc;
//		juspopd.onclick = jusPopOutFunc;
		setListener(juspop, "click", jusPopOutFunc);
		setListener(juspopd, "click", jusPopOutFunc);
//		juspop.setAttribute("alt", address);
//		juspopd.setAttribute("alt", address);
	}
}
//blogTVだよ
function setBLink(id, address1, address2, userId, progId) {
	var btvlink = null;
	var btvlinkd = null;
	if(!btvlink) {
		if(address1 != "") {
			btvlink = document.getElementById("btvlink" + id);
			btvlinkd = document.getElementById("btvlink" + id + "d");
			btvlink.setAttribute("href", "http://www.blogtv.com/People/" + address1);
			btvlinkd.setAttribute("href", "http://www.blogtv.com/People/" + address1);
			document.getElementById("btvimg" + id).setAttribute("src", "b.gif");
			document.getElementById("btvimg" + id + "d").setAttribute("src", "b.gif");
		} else {
			document.getElementById("btvimg" + id).setAttribute("src", "blank.gif");
			document.getElementById("btvimg" + id + "d").setAttribute("src", "blank.gif");
		}

		var btvPopOutFunc = function(){
			var btvwidth = document.getElementById("btvwidth");
			var btvheight = document.getElementById("btvheight");

			var btv_w = btvwidth.value;
			var btv_h = btvheight.value;

			if(btv_w == "" || btv_h == "" || isNaN(btv_w) || isNaN(btv_h)) {
				btv_w = getCookie("btvwidth");
				btv_h = getCookie("btvheight");
				if(btv_w == null || btv_w == "" || isNaN(btv_w)) {
					btv_w = 480;
					btvwidth.value = 480;
				} else {
					btvwidth.value = btv_w;
				}
				if(btv_h == null || btv_h == "" || isNaN(btv_h)) {
					btv_h = 460;
					btvheight.value = 460;
				} else {
					btvheight.value = btv_h;
				}
			}

//			window.open('http://www.blogtv.com/livesdk/' + address2, address2, 'width=' + btv_w + ',height=' + btv_h);
			window.open('http://www.blogtv.com/Flash/BTP.swf?extAd=adaptv&iniLocation=http://www.blogtv.com/en/FXml/&liveEnc=' + address2 + '&showTitle=' + address1 + '%20Live&ApplicationName=BlogTV&ServerName=fms180.blogtv.com&EdgeServerName=edge.fms180.blogtv.com&BroadCasterUserid=' + userId + '&ProgId=' + progId + '&PlayerName=' + address1 + '&channelId=1&linkad=&chNameAd=Entertainment&chDescUrlAd=http://www.blogtv.com/people/' + address1 + '&durationAd=2700&tagsAd=Entertainment,&keyId=&ps=0&ut=0&extAddress=&extStream=&ts=0&fme=1', address1, 'width=' + btv_w + ',height=' + btv_h);
			void(0);
		};

		var btvpop = document.getElementById("btvpop" + id);
		var btvpopd = document.getElementById("btvpop" + id + "d");
//		btvpop.onclick = btvPopOutFunc;
//		btvpopd.onclick = btvPopOutFunc;
		setListener(btvpop, "click", btvPopOutFunc);
		setListener(btvpopd, "click", btvPopOutFunc);
//		juspop.setAttribute("alt", address);
//		juspopd.setAttribute("alt", address);
	}
}

function changePopOutSize() {
	var ustwidth = document.getElementById("ustwidth");
	var ustheight = document.getElementById("ustheight");
	var juswidth = document.getElementById("juswidth");
	var jusheight = document.getElementById("jusheight");

	var btvwidth = document.getElementById("btvwidth");
	var btvheight = document.getElementById("btvheight");

	if(ustwidth.value == "" || ustheight.value == "" || juswidth.value == "" || jusheight.value == "" || btvwidth.value == "" || btvheight.value == "" ||
			isNaN(ustwidth.value) || isNaN(ustheight.value) || isNaN(juswidth.value) || isNaN(jusheight.value) || isNaN(btvwidth.value) || isNaN(btvheight.value)) {
		dwr.util.setValue("message", "(´･ω･｀)失敗…");
	} else {
		setCookie("ustwidth", ustwidth.value, kikan);
		setCookie("ustheight", ustheight.value, kikan);
		setCookie("juswidth", juswidth.value, kikan);
		setCookie("jusheight", jusheight.value, kikan);

		setCookie("btvwidth", btvwidth.value, kikan);
		setCookie("btvheight", btvheight.value, kikan);

		dwr.util.setValue("message", "(≧ω≦)b");
	}

	setTimeout("dwr.util.setValue('message', '')", 2000);
}
function changeDefaultPopOutSize() {
	var ustwidth = document.getElementById("ustwidth");
	var ustheight = document.getElementById("ustheight");
	var juswidth = document.getElementById("juswidth");
	var jusheight = document.getElementById("jusheight");

	var btvwidth = document.getElementById("btvwidth");
	var btvheight = document.getElementById("btvheight");

	ustwidth.value = 480;
	ustheight.value = 384;
	juswidth.value = 630;
	jusheight.value = 354;

	btvwidth.value = 480;
	btvheight.value = 460;

	setCookie("ustwidth", ustwidth.value, kikan);
	setCookie("ustheight", ustheight.value, kikan);
	setCookie("juswidth", juswidth.value, kikan);
	setCookie("jusheight", jusheight.value, kikan);

	setCookie("btvwidth", btvwidth.value, kikan);
	setCookie("btvheight", btvheight.value, kikan);

	dwr.util.setValue("message", "(≧ω≦)b");
	setTimeout("dwr.util.setValue('message', '')", 2000);
}

var currentobject;
//function getUEmbed(channel) {
//	var ul = document.getElementById("ustlink");
//	if(ul.checked) {
//		window.open("http://lonsdaleite.jp/stream_player/alpha.html" + channel);
//	} else {
//		UstAnnouncer.sendEmbed(channel);
//	}
//}
//function getJEmbed(channel) {
//	window.open("http://www.justin.tv/" + channel);
//}
//function setEmbed(object, name) {
//	var video = document.getElementById("video");
//   	if(currentobject == object) {
//   	   	currentobject = null;
//   	   	video.innerHTML = "";
//   	   	dwr.util.setValue("video_name", "");
//   	} else {
//   	   	currentobject = object;
//   	   	video.innerHTML = object;
//   	   	dwr.util.setValue("video_name", name);
//   	}
//}

var scripttime;
var sa;
function setAccessTime(time) {
	sa = new Date().getTime() - time;
	scripttime = time;
}
function setTime(time) {
	dwr.util.setValue("time", "取得：" + time);
//	dwr.util.setValue("announce4", "");
}
function setName(id, name) {
	dwr.util.setValue(id, name);
	dwr.util.setValue(id + "d", name);
}
function setStatus(id, status) {
	dwr.util.setValue("status" + id, status);
	dwr.util.setValue("status" + id + "d", status);
}

function setNotice() {
	dwr.util.setValue("announce4", "サーバを再起動しました。そのまましばらくお待ちください。");
}

var error = false;
function timer() {
	var d = new Date().getTime() - sa;
	if((d - scripttime) > 600000) {
		reload(1000);
		error = true;
	} else {
		if(error) {
			error = false;
		}
	}
}
function icanfly() {
	window.location.replace("http://moryo34.blog16.fc2.com/");
}
function reload(tt) {
	setTimeout(reload2, tt);
}
function reload2() {
	setCookie("visit", "0", 15);
	window.location.reload();
}


function hide(){
	var popconf = document.getElementById("popoutConfig");
	if(isHide == true) {
		setCookie("ujlink", "1", kikan);
		var linkbtn = document.getElementById('linkbtn');
		linkbtn.setAttribute("value", "リンク･ポップアウトを隠す");
		var tables = document.getElementsByTagName('table');

		for (var i = 0; i < tables.length; i++) {
			if (tables[i].className.match("haishinsha")) {
//	            var zr;
//	            var zebraRows = zebraTables[i].getElementsByTagName("tr");
				var trs = tables[i].getElementsByTagName("tr");
				for(var j = 0; j < trs.length; j++) {
					var tds = trs[j].getElementsByTagName("td");
//					if(j == 0) {
//						tds[4].style.display = "table-cell";
//						tds[5].style.display = "table-cell";
//					} else {
//						tds[5].style.display = "table-cell";
//						tds[6].style.display = "table-cell";
//						tds[7].style.display = "table-cell";
//					}
					if(j == 0) {
						tds[4].style.display = "";
						tds[5].style.display = "";
					} else {
						tds[6].style.display = "";
						tds[7].style.display = "";
						tds[8].style.display = "";
						tds[9].style.display = "";
					}
				}
			}
		}
		popconf.style.display = "table-cell";
		isHide = false;
	} else {
		setCookie("ujlink", "0", kikan);
		var linkbtn = document.getElementById('linkbtn');
		linkbtn.setAttribute("value", "リンク･ポップアウトを出す");
		var tables = document.getElementsByTagName('table');

		for (var i = 0; i < tables.length; i++) {
			if (tables[i].className.match("haishinsha")) {
				var trs = tables[i].getElementsByTagName("tr");
				for(var j = 0; j < trs.length; j++) {
					var tds = trs[j].getElementsByTagName("td");
					if(j == 0) {
						tds[4].style.display = "none";
						tds[5].style.display = "none";
					} else {
						tds[6].style.display = "none";
						tds[7].style.display = "none";
						tds[8].style.display = "none";
						tds[9].style.display = "none";
					}
				}
			}
		}
		popconf.style.display = "none";
		isHide = true;
	}
}

var broadcasterHide = false;

//function changeBroadcaster() {
//	var tables = document.getElementsByTagName('table');
//
//	for (var i = 0; i < tables.length; i++) {
//		if (tables[i].className.match("haishinsha")) {
//			var trs = tables[i].getElementsByTagName("tr");
//			for(var j = 0; j < trs.length; j++) {
//				if(j != 0) {
//					if(broadcasterHide) {
//						var check = document.getElementById("check" + j);
//						if(check.checked) {
//							trs[j].style.display = "none";
//						}
//						broadcasterHide = true;
//					} else {
//						trs[j].style.display = "";
//						broadcasterHide = false;
//					}
//				}
//			}
//		}
//	}
//}

function setTopMessage(topMessage) {
	dwr.util.setValue("annouce4", topMessage);
}