$(document).ready(function(){
	//表の切り替え
	$("#table-style02-disp").css("display", "none");
	$("#tab_basic").click(function(){
		$("#tab_basic").attr("src", "../images/serp_pro/basic_tab_img.gif");
		$("#tab_analyze").attr("src", "../images/serp_pro/analyze_notab_img.gif");
		$("#table-style01-disp").css("display", "inline");
		$("#table-style02-disp").css("display", "none");
	});

	$("#tab_analyze").click(function(){
		$("#tab_basic").attr("src", "../images/serp_pro/basic_notab_img.gif");
		$("#tab_analyze").attr("src", "../images/serp_pro/analyze_tab_img.gif");
		$("#table-style01-disp").css("display", "none");
		$("#table-style02-disp").css("display", "inline");
	});

	//テーブル行ハイライト処理
	$('tr.tr_site').each(function(){
		$(this).mouseover(function(){
			$(this).css("background-color", "#ffeeee");
		});
		$(this).mouseout(function(){
			$(this).css("background-color", "#ffffff");
		});
	});

});

function loadMessage(frm){
	if (navigator.userAgent.indexOf("Firefox") > -1) {
		var msg = '<div class="loading"><img src="http://talabagani.jp/images/common/load.gif" style="position: absolute;left: 4px;top: 15px;" />情報を取得中です。<br />しばらくお待ちください...</div>';
	} else {
		var msg = '<div class="loading">情報を取得中です。<br />しばらくお待ちください...</div>';
	}
	$.blockUI({ message: msg, css: { width: '180px', left: '40%' }, overlayCSS: { backgroundColor: '#fff', opacity: 0.6 } });
	frm.submit();
}

function funcCSV(expStr) {

	var exp_title_input = '"入力情報"\n"キーワード","検索結果数"';
	var exp_title_basic = '\n\n"基本情報"\n"No.","タイトル","URL","Meta description","Meta keywords","h1タグ"';
	var exp_title_analyze_top = '\n\n"解析情報"\n"No.","内部発リンク","外部発リンク","キーワード出現数","キーワード出現率","総単語数","キーワード出現数上位３"';
	var exp_title_analyze_bottom = '"","","","","","","1位","出現数","出現率","2位","出現数","出現率","3位","出現数","出現率"';
	var exp_basic = [];
	var exp_analyze = [];
	var exp_input = '"'+expStr.keyword+'","'+expStr.total+'"';

	for(var i in expStr.site){
		if(i != "target") {
			no = parseInt(i);
		} else {
			no = "マイサイト";
		}
		if(expStr.site[i].meta_desc == undefined) {
			expStr.site[i].meta_desc = "";
		}
		if(expStr.site[i].meta_kw == undefined) {
			expStr.site[i].meta_kw = "";
		}

		exp_basic.push('"'+no+'","'+expStr.site[i].title+'","'+expStr.site[i].url+'","'+expStr.site[i].meta_desc+'","'+expStr.site[i].meta_kw+'","'+expStr.site[i].h1+'"');
		exp_analyze.push('"'+no+'","'+expStr.site[i].n_in+'","'+expStr.site[i].n_out+'","'+expStr.site[i].kw_count+'","'+expStr.site[i].kw_ratio+'","'+expStr.site[i].totalwords+'","'+expStr.site[i].top_kw["1"]["word"]+'","'+expStr.site[i].top_kw["1"]["count"]+'","'+expStr.site[i].top_kw["1"]["ratio"]+'","'+expStr.site[i].top_kw["2"]["word"]+'","'+expStr.site[i].top_kw["2"]["count"]+'","'+expStr.site[i].top_kw["2"]["ratio"]+'","'+expStr.site[i].top_kw["3"]["word"]+'","'+expStr.site[i].top_kw["3"]["count"]+'","'+expStr.site[i].top_kw["3"]["ratio"]+'"');
	}

	var objBody = document.getElementsByTagName("body")[0];
	var frmObj = document.createElement("form");
	frmObj.method = "post";
	frmObj.name = "exdata";
	frmObj.action = "export.php";
	var input = document.createElement("input");
		input.setAttribute('type', "hidden");
		input.setAttribute('name', "exp_title_input");
		input.setAttribute('value', exp_title_input);
	frmObj.appendChild(input);
	input = document.createElement("input");
		input.setAttribute('type', "hidden");
		input.setAttribute('name', "exp_input");
		input.setAttribute('value', exp_input);
	frmObj.appendChild(input);
	input = document.createElement("input");
		input.setAttribute('type', "hidden");
		input.setAttribute('name', "exp_title_basic");
		input.setAttribute('value', exp_title_basic);
	frmObj.appendChild(input);
	input = document.createElement("input");
		input.setAttribute('type', "hidden");
		input.setAttribute('name', "exp_basic");
		input.setAttribute('value', exp_basic.join("\n"));
	frmObj.appendChild(input);
	input = document.createElement("input");
		input.setAttribute('type', "hidden");
		input.setAttribute('name', "exp_title_analyze_top");
		input.setAttribute('value', exp_title_analyze_top);
	frmObj.appendChild(input);
	input = document.createElement("input");
		input.setAttribute('type', "hidden");
		input.setAttribute('name', "exp_title_analyze_bottom");
		input.setAttribute('value', exp_title_analyze_bottom);
	frmObj.appendChild(input);
	input = document.createElement("input");
		input.setAttribute('type', "hidden");
		input.setAttribute('name', "exp_analyze");
		input.setAttribute('value', exp_analyze.join("\n"));
	frmObj.appendChild(input);
	objBody.appendChild(frmObj);
	frmObj.submit();
}
