<!--

//共通JavaScript

function submit_func(){
	if(!now_submit){
		selected_cats_info = "";sel_count = 0;
		var checkbox = document.getElementsByName("add_search");
		for(i=0;i<checkbox.length;i++){
			if(checkbox[i].checked){
				if(selected_cats_info){selected_cats_info += "_";}
				selected_cats_info += "0"+checkbox[i].value;
			}
		}
		if($('cho_cat2').checked){
			for(i=0;i<cats.length;i++){
				if($("cat_"+cats[i]).checked){
					if(selected_cats_info){selected_cats_info += "_";}
					selected_cats_info += cats[i];
					sel_count++;
				}
			}
			if(!sel_count){alert("最低カテゴリを1つ選択してください。");return false;}
		}
		$('selected_cats').value = selected_cats_info;
		now_submit = 1;
		return true;
	}else{
		return false;
	}
}

function select_cat(selflag){
	var this_visibility = "";
	if(selflag){
		this_visibility = "visible";
	}else{
		this_visibility = "hidden";
	}
	
	for(i=0;i<cats.length;i++){
		$("cat_"+cats[i]).style.visibility = this_visibility;
	}
}
function drop_mouseover(pos){
	try{window.clearTimeout(timer);}catch(e){}
}
function drop_mouseout(pos){
	var posSel=$(pos+"Sel").style.display;
	if(posSel=="block"){
		timer = setTimeout("drop_hide('"+pos+"')", 1000);
	}
}
function drop_hide(pos){
	$(pos+"Sel").style.display="none";
}

//1st Guggest-------------------------------------
return_li = [];
save_li = [];
first_suggest = "";
now_suggest = "";
function suggest_ajax(){
	headq=encodeURI($('headq').value);
	javascript:var d=document;var s=d.createElement('script');s.charset='UTF-8';s.src='http://suggestqueries.google.com/complete/search?hl=ja&client=youtube&hjson=t&ds=yt&jsonp=suggest_callback&cp=1&q='+headq;d.getElementsByTagName('head')[0].appendChild(s);void(0);
}
function suggest_callback(tmparray){
	return_li = [];
	for(sc=0;sc<tmparray[1].length;sc++){
		if(sc==0){first_suggest = tmparray[1][sc][0];suggest_related_word();}
		return_li[sc] = "<li><a href='javascript:suggest_click(\""+tmparray[1][sc][0]+"\")'>"+tmparray[1][sc][0]+"</a></li>";
	}
	make_li();
}
function make_li(){
	return_suggest_html = "<ul class='selSuggest' id='headSuggest'>";
	for(sw=0;sw<save_li.length;sw++){
		return_suggest_html += save_li[sw];
	}
	for(sw=0;sw<return_li.length;sw++){
		return_suggest_html += return_li[sw];
	}
	return_suggest_html += "</ul>";
	$('suggest').innerHTML = return_suggest_html;
}
function suggest_click(cwords){
	$('suggest').style.display = "none";
	$('headq').value = cwords;
	$('sb').click();
}

//2nd Suggest-------------------------------------

function suggest_related_word(){
	if(!first_suggest){return;}
	if(first_suggest == now_suggest){return;}
	now_suggest = first_suggest;

	httpObjs2 = createXMLHttpRequest(res_suggest_related_word);
	if(httpObjs2){
		httpObjs2.open("GET","http://ytu.be/ytube_getrelatedwords_server.php?q="+encodeURI(now_suggest),true);
		httpObjs2.send(null);
	}
}
function res_suggest_related_word(){
	if((httpObjs2.readyState == 4) && (httpObjs2.status == 200)){
		save_li = [];
		get_realted_words = httpObjs2.responseText.split("<>");
		for(gr=0;gr<get_realted_words.length;gr++){
			if(!get_realted_words[gr]){continue;}
			save_li[save_li.length] = "<li><a href='javascript:suggest_click(\""+get_realted_words[gr]+"\")'>"+get_realted_words[gr]+"</a></li>";
		}
		make_li();
	}
}


//Autopagerize------------------------------------
now_apg_loading = 0;
now_apg_wait_flag = 0;//初期値：1ページ目のみ読み込み待ち時間を変更する場合は数値を記入
if(document.URL.indexOf("http://ytu.be/cat/") != -1){
	apg_url = document.URL;
	autotimer = setInterval(apg,1000);
}
function apg(){
	scrollTop  = document.body.scrollTop || document.documentElement.scrollTop;
	if(document.documentElement && document.documentElement.clientWidth){
		clientHeight = document.documentElement.clientHeight;
	}else if(document.body && document.body.clientWidth){
		clientHeight = document.body.clientHeight;
	}
	scrollHeight = document.body.scrollHeight;
	re_px = scrollHeight - clientHeight - scrollTop;
	if(re_px < 100){
		if(now_apg_wait_flag < 4){
			now_apg_wait_flag++;
		}else{
			now_apg_wait_flag = 0;
			apg_ajax();
		}
	}else{
		now_apg_wait_flag = 0;
	}
}
function apg_ajax(){
	if(now_apg_loading){return;}
	now_apg_loading = 1;
	apg_next_url();
	httpObj_apg = createXMLHttpRequest(res_apg_ajax);
	if(httpObj_apg){
		httpObj_apg.open("GET",remake_url+"json=1",true);
		httpObj_apg.send(null);
	}
}
function res_apg_ajax(){
	if((httpObj_apg.readyState == 4) && (httpObj_apg.status == 200)){
		$('vdiv').innerHTML += httpObj_apg.responseText;
		if(httpObj_apg.responseText.length > 1000){now_apg_loading = 0;}
	}
}
function apg_next_url(){
	//現在ページ数解析と増加
	urls = apg_url.split("/");
	tmp_op = "";
	if(urls[urls.length-1].match(/[^0-9\-_]/) || urls[urls.length-1] == ""){
		tmp_op = urls.pop();
	}
	
	if(urls.length < 6){
		get_now_pg = 2;
		urls[urls.length] = get_now_pg;
	}else{
		try{get_now_pg = urls[urls.length-1];}catch(e){get_now_pg = 1;}
		get_now_pg++;
		urls[urls.length-1] = get_now_pg;
	}
	remake_url = "";
	for(u=0;u<urls.length;u++){
		if(remake_url){remake_url += "/";}
		remake_url += urls[u];
	}
	remake_url += "/";
	if(tmp_op){remake_url += tmp_op;}
	apg_url = remake_url;
	if(tmp_op){remake_url += "&";}
}

-->