
	/* ﾘﾌｧﾗ{root / ref / utm_source}の取得 */
	function parameter(){
		// URLの「?」以降のパラメータを変数paramに代入(「?」が付かない)
		var param = window.location.search.substring(1,window.location.search.length);
		// root=* のみ取得（ないときは nullを返す）
		param = param.match(/root=[a-z0-9]*/)
		// 式を文字列に変換
		param += "";

		// a8 対応
		if ( param == "null" || param == "root=" ) {
			param = window.location.search.substring(1,window.location.search.length);
			param = param.match(/ref=[a-z0-9]*/)
			// 式を文字列に変換
			param += "";
			if ( param ) {
				param = param.replace( /ref/ , "root" );
			}
		}

		// utm_source 対応
		if ( param == "null" || param == "root=" ) {
			param = window.location.search.substring(1,window.location.search.length);
			param = param.match(/utm_source=[a-z0-9]{1}/)
			// 式を文字列に変換
			param += "";
			if ( param ) {
				param = param.replace( /utm_source/ , "root" );
			}
		}

		// リンク元が見つかるサイトの場合
		if ( document.referrer.indexOf( "mitsukaru-site.jp" ) != -1 ) {
			param = "root=mitsukaru";
		}

		// リンク元が関連サイトの場合
		if ( document.referrer.indexOf( "apli-kaihatu.jp" ) != -1 || document.referrer.indexOf( "seisou-navi.jp" ) != -1 || document.referrer.indexOf( "seo.tai-saku.jp" ) != -1 ) {
			param = "root=sp";
		}

		// param が null の場合、空白にする
		param = ( param == "null" || param == "root=null" || param == "root=" )? "" : param;
		
		return param;
	}


	/* GET処理(result.php) */
	function get_send(){
		var site_type = "";
		var create_contents = "";
		var budget = "";
		var area = "";

		// サイトタイプ (checkbox)
		site_type = ( document.getElementsByName("site")[0].checked )? document.getElementsByName("site")[0].value : document.getElementsByName("site")[1].value;

		// 制作内容 (checkbox)
		create_contents = ( document.getElementsByName("work")[0].checked )? document.getElementsByName("work")[0].value : document.getElementsByName("work")[1].value;

		// 予算 (selectbox)
		budget = document.getElementsByName("budget").item(document.getElementsByName("budget").selectedIndex).value;

		// エリア (selectbox)
		area = document.getElementsByName("area").item(1).value;

		// URLの「?」以降のパラメータを変数paramに代入(「?」が付かない)
		var param = parameter();

		// param の値がある場合とない場合
		param += ( param )? "&site=" + site_type + "&work=" + create_contents + "&budget=" + budget + "&area=" + area : "site=" + site_type + "&work=" + create_contents + "&budget=" + budget + "&area=" + area;

		// アドレスにパラメータを付加してリダイレクト
		location.href = "http://www.homepage-seisaku.jp/result.php?" + param;
		return false;
	}


	/* GET処理(side) */
	function get_send_side(){
		var site_type = "";
		var create_contents = "";
		var budget = "";
		var area = "";

		// サイトタイプ (checkbox)
		site_type = ( document.getElementsByName("site")[0].checked )? document.getElementsByName("site")[0].value : document.getElementsByName("site")[1].value;

		// 制作内容 (checkbox)
		create_contents = ( document.getElementsByName("work")[0].checked )? document.getElementsByName("work")[0].value : document.getElementsByName("work")[1].value;

		// 予算 (selectbox)
		budget = document.getElementsByName("budget").item(document.getElementsByName("budget").selectedIndex).value;

		// エリア (selectbox)
		area = document.getElementsByName("area").item(document.getElementsByName("area").selectedIndex).value;

		// URLの「?」以降のパラメータを変数paramに代入(「?」が付かない)
		var param = parameter();

		// param の値がある場合とない場合
		param += ( param )? "&site=" + site_type + "&work=" + create_contents + "&budget=" + budget + "&area=" + area + "&side=1" : "site=" + site_type + "&work=" + create_contents + "&budget=" + budget + "&area=" + area + "&side=1";

		// アドレスにパラメータを付加してリダイレクト
		location.href = "http://www.homepage-seisaku.jp/result.php?" + param;
		return false;
	}


	function get_param(){
		// ルートパラメータの取得
		var param = parameter();
		// "root=" の削除
		param = param.replace(/root=/,"");
		// param が "null" の場合、空白にする
		param = ( param == "null" )? "" : param;
		return param;
	}


	function get_ref(){
	var ref = "";
		return ref;
	}


	/* GETパラメータの引継ぎ */
	function getdata(){
		if( window.location.search || document.referrer.indexOf( "mitsukaru-site.jp" ) != -1 || document.referrer.indexOf( "apli-kaihatu.jp" ) != -1 || document.referrer.indexOf( "seisou-navi.jp" ) != -1 || document.referrer.indexOf( "seo.tai-saku.jp" ) != -1 ){
			// URLの「?」以降のパラメータを変数paramに代入(「?」が付かない)
			var param = parameter();

			if ( param ) {
				// aタグ
				var tag_a = document.getElementsByTagName("a");
				for ( i = 0; i < tag_a.length; i++ ) {
					// ｢#｣（アンカーリンク）の取り出し
					var anchor = tag_a[i].href.match(/#[a-zA-Z0-9-]*/) + "";
					// href に ｢mailto:｣と｢#｣が含まれる場合は処理を飛ばす
					if ( tag_a[i].href.indexOf("mailto:") == -1 && tag_a[i].href.indexOf("javascript:") == -1 && anchor == "null" ) {
						if ( tag_a[i].href.indexOf("root=sp") == -1 ) {
							if ( tag_a[i].href.indexOf("?") == -1 ) {
								tag_a[i].href += "?" + param;
							} else {
								tag_a[i].href += "&" + param;
							}
						}
					}
				}
				// areaタグ
				var tag_area = document.getElementsByTagName("area");
				for ( i = 0; i < tag_area.length; i++ ) {
					if ( tag_area[i].href.indexOf("root=sp") == -1 ) {
						if ( tag_area[i].href.indexOf("?") == -1 ) {
							tag_area[i].href += "?" + param;
						} else {
							tag_area[i].href += "&" + param;
						}
					}
				}
				// formタグ
				var tag_form = document.getElementsByTagName("form");
				for ( i = 0; i < tag_form.length; i++ ) {
					if ( tag_form[i].action.indexOf("?") == -1 ) {
						tag_form[i].action += "?" + param;
					} else {
						tag_form[i].action += "&" + param;
					}
				}
			}
		}
	}
	// オンロード時に実行
	window.onload=getdata;


