/**
 * 年齢セレクトボックス（optionのみ）
 */
function selectAge( default_select, first_age, last_age, viewFlg ){

	if( !first_age ) first_age = "0";
	if( !last_age ) last_age = "80";

	if ( viewFlg == true ) {
		document.write( '<option value="">年齢</option>' );
	}

	for ( i = first_age; i <= last_age; i++ ) {
		if ( i == default_select ) {
			document.write( '<option value="' + i + '" selected>' + i +' 歳</option>' );
		} else {
			document.write( '<option value="' + i + '">' + i +' 歳</option>' );
		}
	}

}

/**
 * 性別セレクトボックス（optionのみ）
 */
function selectSex( default_select, viewFlg ){

	if ( viewFlg == true ) {
		document.write( '<option value="">性別</option>');
	}
	
	if ( default_select == 1 ) {
		document.write( '<option value="1" selected>男性</option>');
		document.write( '<option value="2">女性</option>');
	} else if( default_select == 2 ) {
		document.write( '<option value="1">男性</option>');
		document.write( '<option value="2" selected>女性</option>');
	} else {
		document.write( '<option value="1">男性</option>');
		document.write( '<option value="2">女性</option>');
	}

}

/**
 * 年齢セレクトボックス
 */
function selectAgeTag(default_select){

	document.write('<select class="select-nenrei" name="newnenrei">');
	selectAge(default_select,"","",true);
	document.write('</select>');

}

/**
 * 年齢セレクトボックス
 */
function selectSexTag(default_select){

	document.write('<select class="select-seibetsu" name="newseibetsu">');
	selectSex(default_select,true);
	document.write('</select>');

}

/**
 * ブックマーク登録
 */
function addBookMark(){
	var bookmark_url = location.href;
	var bookmark_title = document.title;
	if(location.href.match("hokende.com/hokende2/")) {
		bookmark_url = "http://www.hokende.com/";
		bookmark_title = "保険比較の保険市場｜アドバンスクリエイト｜生命保険-保険見直し-保険相談";
	}
	if(document.all){ //Internet Explorer
		window.external.AddFavorite(bookmark_url,bookmark_title);
	}
	else if(window.sidebar){ //Firefox
		window.sidebar.addPanel(bookmark_title,bookmark_url,"");
	}
	else {
		void(0);
	}
}

/*------------------------------------------------------------
	リスナー登録をする処理
------------------------------------------------------------*/
function addListener (elem, eventType, func, cap) {
	if(elem.addEventListener) {
		elem.addEventListener(eventType, func, cap);
	} else if(elem.attachEvent) {
		elem.attachEvent("on" + eventType, func);
	} else {
		return false;
	}
}

/*------------------------------------------------------------
	simple_rollover
	build 2009.01.28.
	使用法
	置換させたい画像のclass名に"rollover-image"
	置換後の画像は元のファイル名の最後に"_over"を付加
------------------------------------------------------------*/
function simple_rollover() {
	if(document.getElementsByTagName) {
		var images = new Array();
		for(var i=0; i < document.getElementsByTagName("img").length; i++) {
			images.push(document.getElementsByTagName("img")[i]);
		}
		for(var i=0; i < document.getElementsByTagName("input").length; i++) {
			images.push(document.getElementsByTagName("input")[i]);
		}
		var ext;
		var imgPath;
		var overImages = new Array();
		for(var i=0; i < images.length; i++) {
			if(images[i].className.match("rollover-image")) {
				imgPath = images[i].getAttribute("src");
				//プリロード
				ext = imgPath.substring(imgPath.lastIndexOf('.'),imgPath.length);
				overImages[i] = new Image();
				overImages[i].src = imgPath.replace(ext, "_over"+ext);
				//マウスオーバーで画像を置換
				images[i].onmouseover = function() {
					imgPath = this.getAttribute("src");
					ext = imgPath.substring(imgPath.lastIndexOf('.'),imgPath.length);
					this.setAttribute("src", this.getAttribute("src").replace(ext, "_over"+ext));
				}
				//マウスアウトで復帰
				images[i].onmouseout = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_over.", "."));
				}
				//クリックでも復帰(ページ遷移後戻るとロールオーバー後の画像が残っているFirefoxバグ対応)
				images[i].onclick = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_over.", "."));
				}
			}
		}
	}
}
addListener(window, "load", simple_rollover, false);
/*-------------------- simple_rollover end ---------------------*/

/*------------------------------------------------------------
	fade_change
	build   2008.11.18.
	rebuild 2009. 4.22. / 複数設置に対応
	使用法：フェードさせたいタグの親のID名に"change_division"
------------------------------------------------------------*/
fade_start_opacity = new Array;
fade_display_time = new Array;
fade_change_time = new Array;
fade_change_elements = new Array;
fade_targetID = new Array;
var target_counts = 0;

var fade_change_fps = 20;
fade_value_opacity = new Array;
fade_target_element = new Array;
fade_change_division = new Array;

function setupFadeChangeVar(targetID,start_opacity,display_time,change_time) {
	fade_targetID.push(targetID);
	fade_start_opacity.push(start_opacity);//透明度初期値 0～100(整数)
	fade_display_time.push(display_time);//表示時間
	fade_change_time.push(change_time);//フェード時間
	fade_change_elements.push(target_counts);
	target_counts += 1;
}
function startFadeChange() {
	for(k=0; k < fade_change_elements.length; k++){
		setupFadeChange(k);
	}
}
function setupFadeChange(target_count) {
	fade_change_division[target_count] = new Array;

	fade_value_opacity[target_count] = fade_start_opacity[target_count];
	if (document.getElementById(fade_targetID[target_count]) != null) {
		for (i=0;i<document.getElementById(fade_targetID[target_count]).childNodes.length;i++){
			if (document.getElementById(fade_targetID[target_count]).childNodes.item(i).nodeType == 1){
				fade_change_division[target_count].push(document.getElementById(fade_targetID[target_count]).childNodes.item(i));

				// Flashの場合、最初に停止させる（IEのみ動作）
				if (window.attachEvent){
					if (document.getElementById(fade_targetID[target_count]).childNodes.item(i).getElementsByTagName("object")[0]){
						document.getElementById(fade_targetID[target_count]).childNodes.item(i).getElementsByTagName("object")[0].StopPlay();
					}
				}

			}
		}
		fade_change_division[target_count][0].parentNode.style.position = "relative";
		var rand = Math.floor((Math.random() * fade_change_division[target_count].length));
		for(i=0; i < fade_change_division[target_count].length; i++){
			fade_change_division[target_count][i].style.display = "none";
			fade_change_division[target_count][i].style.position = "absolute";
			fade_change_division[target_count][i].style.top = "0";
			fade_change_division[target_count][i].style.left = "0";
		}
		fadeChange(rand,target_count);
	}
}
function fadeChange(count,target_count) {
	fade_target_element[target_count] = fade_change_division[target_count][count];
	fade_target_element[target_count].style.display = "block";
	if (count == fade_change_division[target_count].length - 1) {
		count = 0;
	} else {
		count += 1;
	}

	// Flashの場合、1フレーム目に戻って再生させる（IEのみ動作）
	if (window.attachEvent){
		if (fade_target_element[target_count].getElementsByTagName("object")[0]){
			fade_target_element[target_count].getElementsByTagName("object")[0].GotoFrame(1);
			fade_target_element[target_count].getElementsByTagName("object")[0].Play();
		}
	}

	setFadeIn(target_count);
	setTimeout("setFadeOut("+target_count+")", fade_change_time[target_count] + fade_display_time[target_count]);
	setTimeout("setDisplayNone("+target_count+")", (fade_change_time[target_count] * 2) + fade_display_time[target_count] + (fade_change_time[target_count] * 0.1));
	setTimeout("fadeChange("+count+","+target_count+")", (fade_change_time[target_count] * 2) + fade_display_time[target_count] + (fade_change_time[target_count] * 0.3));
}
//非表示に
function setDisplayNone(target_count) {
	fade_target_element[target_count].style.display = "none";
}
// フェードイン
function setFadeIn(target_count) {
	if(fade_value_opacity[target_count] < 100){
		fade_value_opacity[target_count] += 100 / (fade_change_time[target_count]*1.2 / (1000 / fade_change_fps));
		setOpacity(target_count);
		setTimeout("setFadeIn("+target_count+")", 1000 / fade_change_fps);
	}
}
// フェードアウト
function setFadeOut(target_count) {
	if(fade_value_opacity[target_count] > 0){
		fade_value_opacity[target_count] -= 100 / (fade_change_time[target_count] / (1000 / fade_change_fps));
		setOpacity(target_count);
		setTimeout("setFadeOut("+target_count+")", 1000 / fade_change_fps);
	}
}
// 透明度をセットする処理
function setOpacity (target_count) {
	fade_target_element[target_count].style.filter = "alpha(opacity=" + fade_value_opacity[target_count] + ")";//IE
	fade_target_element[target_count].style.MozOpacity = fade_value_opacity[target_count] / 100;//Firefox2
	fade_target_element[target_count].style.opacity = fade_value_opacity [target_count]/ 100;//Firefox3,Safari,Opera
}

function A_Li1(){
	i = document.Link.parta.selectedIndex;
	j = document.Link.partb.selectedIndex;
	window.open(document.Link.parta.options[i].value + document.Link.partb.options[j].value,"");
}

//バイクパパット2（フォーム名とドメイン名を引数に）
//備考ドメイン名のセットは任意です
function A_Li2(frm,domainName){
	if (domainName != null) {
		domainName = 'http://' + domainName;
	}else{
		domainName = "";
	}

	i = eval('document.' + frm + '.parta.selectedIndex');
	j = eval('document.' + frm + '.partb.selectedIndex');
	window.open( domainName + eval('document.' + frm + '.parta.options[' + i + '].value') + eval('document.' + frm + '.partb.options[' + j + '].value'),"");
}

/**
 * キーワード検索シミュレーション実行
 */
function goSearchSimulation(prmKeyword, prmFormName, prmGenreId, prmls){

	if (prmFormName == null || prmFormName == "") {
		prmFormName = "baseForm";
	}

	var form = document.getElementsByName(prmFormName).item(0);
	
	var hidden_keyword = document.createElement("input");
	hidden_keyword.setAttribute("type", "hidden");
	hidden_keyword.setAttribute("name", "newkeyword");
	hidden_keyword.setAttribute("value", prmKeyword);
	form.appendChild(hidden_keyword);

	var hidden_charset = document.createElement("input");
	hidden_charset.setAttribute("type", "hidden");
	hidden_charset.setAttribute("name", "charset");
	hidden_charset.setAttribute("value", "utf-8");
	form.appendChild(hidden_charset);
	
	if (prmGenreId != null && prmGenreId != "") {
		var hidden_genreid = document.createElement("input");
		hidden_genreid.setAttribute("type", "hidden");
		hidden_genreid.setAttribute("name", "newgenreid");
		hidden_genreid.setAttribute("value", prmGenreId);
		form.appendChild(hidden_genreid);
	}
	if (prmls != null && prmls != "") {
		var hidden_ls = document.createElement("input");
		hidden_ls.setAttribute("type", "hidden");
		hidden_ls.setAttribute("name", "ls");
		hidden_ls.setAttribute("value", prmls);
		form.appendChild(hidden_ls);
	}
	
	form.submit();
}

// 保険会社別シミュレーション
function submitFormCP(cp){
	document.baseForm.cp.value = cp;
	document.baseForm.newgenreid.value = 'cp';
	document.baseForm.submit();
}

// 保険料シミュレーション 複数設置対応型
function submit_form_multitype(count_number,action_url,form_target,form_method,search_keyword,form_name) {
	if(form_name == null) {
		form_name = "baseForm";
	}
	var form_element;
	form_element = eval('document.' + form_name);

	if(action_url != null && action_url != "") {
		document.getElementById(form_name).action = action_url;
	}
	if(form_target != null && form_target != "") {
		document.getElementById(form_name).target = form_target;
	}
	if(form_method != null && form_method != "") {
		document.getElementById(form_name).method = form_method;
	}
	if(search_keyword != null && search_keyword != "") {
		form_element.newkeyword.value = search_keyword;
	}
	// ジャンル
	if(form_element.newgenreid) {
		if(!count_number) {
			count_number = "";
		}
		if(document.getElementById("g03" + count_number)) {//生命保険
			if(document.getElementById("g02" + count_number).checked) {//医療保険
				form_element.newgenreid.value = document.getElementById("g02" + count_number).value;
			} else if(document.getElementById("g03" + count_number).checked) {//生命保険
				form_element.newgenreid.value = document.getElementById("g03" + count_number).value;
			} else if(document.getElementById("g11" + count_number).checked) {//女性保険
				form_element.newgenreid.value = document.getElementById("g11" + count_number).value;
			} else if(document.getElementById("g06" + count_number).checked) {//学資保険
				form_element.newgenreid.value = document.getElementById("g06" + count_number).value;
			} else if(document.getElementById("g01" + count_number).checked) {//がん保険
				form_element.newgenreid.value = document.getElementById("g01" + count_number).value;
			} else if(document.getElementById("g14" + count_number).checked) {//年金保険
				form_element.newgenreid.value = document.getElementById("g14" + count_number).value;
			} else if(document.getElementById("g04" + count_number).checked) {//シニア保険
				form_element.newgenreid.value = document.getElementById("g04" + count_number).value;
			} else {
				form_element.newgenreid.value = "";
			}
		} else if(document.getElementById("newgenreid" + count_number)) {
			form_element.newgenreid.value = document.getElementById("newgenreid" + count_number).value;
		}
		if (form_element.newgenreid.value == ""){
			form_element.newgenreid.value = "2";
		}
		//alert(form_element.newgenreid.value);
	}

	// 年齢
	if(form_element.newnenrei && document.getElementById("newnenrei" + count_number)) {
		form_element.newnenrei.value = document.getElementById("newnenrei" + count_number).value;
		//alert(form_element.newnenrei.value);
	}

	// 性別
	if(form_element.newseibetsu && document.getElementById("newseibetsu" + count_number)) {
		form_element.newseibetsu.value = document.getElementById("newseibetsu" + count_number).value;
		//alert(form_element.newseibetsu.value);
	}

	// 並び替え(henko) radioボタンを想定
	if(form_element.henko && document.getElementsByName("henko" + count_number)) {
		for(i = 0; i < document.getElementsByName("henko" + count_number).length; i++) //全てのラジオボタンをスキャン
		if(document.getElementsByName("henko" + count_number)[i].checked) {        //チェックされていたら
			form_element.henko.value = document.getElementsByName("henko" + count_number)[i].value;  //それが値
			break;
		}
		//alert(form_element.henko.value);
	}

	form_element.submit();
}

function popJumpSW(selOBJ){
	/*n = selOBJ.selectedIndex;*/
	/*if (n == "") alert("都道府県を選択して下さい");*/
	n = selOBJ.selectedIndex;
	x = selOBJ.options[n].value;
	if (x == "") alert("都道府県を選択して下さい");
	else window.open(selOBJ.options[n].value,"_blank");
}

function select_todofuken(){
	document.write('<select onChange="popJumpSW(this)" class="select-todofuken" id="hoken-ichiba-guide">');
	document.write('<option value="">都道府県を選択</option>');
	document.write('<option value="">【北海道・東北】---</option>');
	document.write('<option value="http://hokkaido.hoken-ichiba.com/">北海道</option>');
	document.write('<option value="http://aomori.hoken-ichiba.com/">青森県</option>');
	document.write('<option value="http://miyagi.hoken-ichiba.com/">宮城県</option>');
	document.write('<option value="http://akita.hoken-ichiba.com/">秋田県</option>');
	document.write('<option value="http://yamagata.hoken-ichiba.com/">山形県</option>');
	document.write('<option value="http://fukushima.hoken-ichiba.com/">福島県</option>');
	document.write('<option value="">【関東】-----------</option>');
	document.write('<option value="http://ibaraki.hoken-ichiba.com/">茨城県</option>');
	document.write('<option value="http://tochigi.hoken-ichiba.com/">栃木県</option>');
	document.write('<option value="http://gunma.hoken-ichiba.com/">群馬県</option>');
	document.write('<option value="http://saitama.hoken-ichiba.com/">埼玉県</option>');
	document.write('<option value="http://chiba.hoken-ichiba.com/">千葉県</option>');
	document.write('<option value="http://tokyo.hoken-ichiba.com/">東京都</option>');
	document.write('<option value="http://kanagawa.hoken-ichiba.com/">神奈川県</option>');
	document.write('<option value="">【信越・北陸】-----</option>');
	document.write('<option value="http://niigata.hoken-ichiba.com/">新潟県</option>');
	document.write('<option value="http://toyama.hoken-ichiba.com/">富山県</option>');
	document.write('<option value="http://ishikawa.hoken-ichiba.com/">石川県</option>');
	document.write('<option value="http://fukui.hoken-ichiba.com/">福井県</option>');
	document.write('<option value="http://nagano.hoken-ichiba.com/">長野県</option>');
	document.write('<option value="">【東海】-----------</option>');
	document.write('<option value="http://gifu.hoken-ichiba.com/">岐阜県</option>');
	document.write('<option value="http://shizuoka.hoken-ichiba.com/">静岡県</option>');
	document.write('<option value="http://aichi.hoken-ichiba.com/">愛知県</option>');
	document.write('<option value="http://mie.hoken-ichiba.com/">三重県</option>');
	document.write('<option value="">【近畿】-----------</option>');
	document.write('<option value="http://shiga.hoken-ichiba.com/">滋賀県</option>');
	document.write('<option value="http://kyoto.hoken-ichiba.com/">京都府</option>');
	document.write('<option value="http://osaka.hoken-ichiba.com/">大阪府</option>');
	document.write('<option value="http://hyogo.hoken-ichiba.com/">兵庫県</option>');
	document.write('<option value="http://nara.hoken-ichiba.com/">奈良県</option>');
	document.write('<option value="http://wakayama.hoken-ichiba.com/">和歌山県</option>');
	document.write('<option value="">【中国】-----------</option>');
	document.write('<option value="http://tottori.hoken-ichiba.com/">鳥取県</option>');
	document.write('<option value="http://shimane.hoken-ichiba.com/">島根県</option>');
	document.write('<option value="http://okayama.hoken-ichiba.com/">岡山県</option>');
	document.write('<option value="http://hiroshima.hoken-ichiba.com/">広島県</option>');
	document.write('<option value="http://yamaguchi.hoken-ichiba.com/">山口県</option>');
	document.write('<option value="">【四国】-----------</option>');
	document.write('<option value="http://tokushima.hoken-ichiba.com/">徳島県</option>');
	document.write('<option value="http://ehime.hoken-ichiba.com/">愛媛県</option>');
	document.write('<option value="">【九州・沖縄】-----</option>');
	document.write('<option value="http://fukuoka.hoken-ichiba.com/">福岡県</option>');
	document.write('<option value="http://saga.hoken-ichiba.com/">佐賀県</option>');
	document.write('<option value="http://nagasaki.hoken-ichiba.com/">長崎県</option>');
	document.write('<option value="http://kumamoto.hoken-ichiba.com/">熊本県</option>');
	document.write('<option value="http://oita.hoken-ichiba.com/">大分県</option>');
	document.write('<option value="http://miyazaki.hoken-ichiba.com/">宮崎県</option>');
	document.write('<option value="http://kagoshima.hoken-ichiba.com/">鹿児島県</option>');
	document.write('<option value="http://okinawa.hoken-ichiba.com/">沖縄県</option>');
	document.write('</select>');
}
