// ======================================================================
//    ソースコードのカラー表示
// ======================================================================
window.onload = function() {
    dp.SyntaxHighlighter.ClipboardSwf = 'clipboard.swf';
    dp.SyntaxHighlighter.HighlightAll('code');
}

// ======================================================================
//    ページ上部へ移動
// ======================================================================
function pageup() {
	if (document.all) { posi = document.body.scrollTop; }
	else { posi = window.pageYOffset; }
	moveObje(posi);
}
function moveObje(position) {
	move = position / 10;
	point = parseInt(position - move);
	scrollTo(0,point);
	if (point > 0) { setTimeout("moveObje(point)",1); }
}

// ======================================================================
//    ページ内リンク
// ======================================================================
$(function() {
	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var target = $(this.hash);
			target = target.length && target;
			if (target.length) {
				var sclpos = 30;
				var scldurat = 1200;
				var targetOffset = target.offset().top - sclpos;
				$('html,body')
					.animate({scrollTop: targetOffset}, {duration: scldurat, easing: "easeOutExpo"});
				return false;
			}
		}
	});
});



// ======================================================================
//     QA用display切り替え
// ======================================================================
function changeQADisplay(id) {
	if(document.getElementById("qa" + id).style.display == "block") {
		document.getElementById("qa" + id).style.display = "none";
	} else {
		document.getElementById("qa" + id).style.display = "block";
	}
}

// ======================================================================
//    フォーム送信
// ======================================================================

// エラーチェック
function submit_form() {
	$('#msg').html('');
	var data = get_data();
	data["key"] = "scuderiaweb";
	$.post("/contact/pgm/logic_check.php", data, fin_check);
}

// 入力内容を取得
function get_data() {
	var data = {};

	// contactForm内のinput及びtextareaを取得
	$("#contactForm input, #contactForm textarea").each(function(){
		if($(this).attr("type") == "radio") {
			// ラジオボタンの場合の処理
			var item_val = $("input[@type='radio'][@name='" + $(this).attr("name") + "']:checked").val();
			if(item_val == undefined) {
				item_val = "";
			}
			data[$(this).attr("name")] = item_val;
		} else {
			// ラジオボタン以外の処理
			data[$(this).attr("name")] = $(this).val();
		}
		// フィールドと項目名のエラークラスを外す
		$(this).removeClass("form_error");
		$('#'+$(this).attr("name")+"Text").removeClass("text_error");
	});
	return data;
}

// エラーチェック終了後の処理
function fin_check(data) {
	var json = eval(data);
	if(json.length == 0) {
		if(confirm('送信しますか？')) {
			$.post("/contact/pgm/logic_send.php", get_data(), fin_regist);
		}
	} else {
		var msg = "";
		scrollTo(0,0);
		for (var i = 0; i < json.length; i++) {
			msg += json[i].msg + "<br />";
			$('#' + json[i].id).addClass("form_error");
			$('#' + json[i].id + 'Text').addClass("text_error");
		}
		$('#msg').html('<div id="informationMessage">' + msg + '</div>');
	}
}

// 登録処理終了後の処理
function fin_regist(data) {
	scrollTo(0,0);
	$('#msg').html(data);
	$('#contactFormTb').css('display', 'none'); 
}

// フォームのリセット
function reset_form() {
	$('#contactForm').reset();
}


// ======================================================================
//    画像用ウィンドウ表示
// ======================================================================
function openImageWindow(src, title) {
	// 画像をプリロード
	var i = new Image(); i.src = src;
	// ロード完了してから処理を開始
	i.onload = function() {
	// 画像のサイズに合った空ウィンドウを開く
		var pop_win = window.open(
			"",
			"_blank",
			"width="+i.width+",height="+i.height+",scrollbars=no,resizable=yes"
		);
		// 空ウィンドウに画像を出力するためのHTML
		pop_win.window.document.open();
		pop_win.window.document.write(
			'<html>'
			+'<head><title>ScuderiaWeb | ' + title + '</title></head>'
			+'<body style="margin:0;padding:0;border:0;">'
			+'<img src="'+i.src+'" width="100%" alt="" />'
			+'</body>'
			+'</html>'
		);
		pop_win.window.document.close();
	}
}


// ======================================================================
//    パスワード発行フォーム
// ======================================================================
function dispText() {
	var text = "Mail Address";
	if ($("#seoMail").val() == text)
		$("#seoMail").val("");
}
function hiddenText() {
	var text = "Mail Address";
	if ($("#seoMail").val() == "")
		$("#seoMail").val(text);
}
function send_password() {
	var text = "Mail Address";
	if($("#seoMail").val() == text || $("#seoMail").val() == "") {
		$("#msg").html("<p class=\"text_error\">メールアドレスを入力してください。</p>");
	} else {
		var data = {};
		data["seoMail"] = $("#seoMail").val();
		data["key"] = "scuderiaweb";
		$.post("/seo/cording/pgm/logic_check.php", data, fin_seo_password_check);
	}
}
function fin_seo_password_check(data) {

	var json = eval(data);
	scrollTo(0,0);

	if(json.length == 0) {
		if(confirm('送信しますか？')) {
			var data = {};
			data["seoMail"] = $("#seoMail").val();
			data["key"] = "scuderiaweb";
			$.post("/seo/cording/pgm/logic_send.php", data, fin_seo_password);
		}
	} else {
		var msg = "";
		document.body.scrollTop = 0;
		for (var i = 0; i < json.length; i++) {
			msg += json[i].msg + "<br />";
			$('#' + json[i].id).addClass("form_error");
			$('#' + json[i].id + 'Text').addClass("text_error");
		}
		$("#msg").html("<p class=\"text_error\">" + msg + "</p>");
	}

}

// 登録処理終了後の処理
function fin_seo_password(data) {
	scrollTo(0,0);
	$('#msg').html(data);
}


// ======================================================================
//    テンプレートサンプル表示
// ======================================================================
function sample_window(id) {
	window.open('/service-website/service/template_sample.php?id=' + id, 'ScuderiaWeb', 'width=800, height=450, menubar=no, toolbar=no, scrollbars=no');
}

function sample_load(img) {
	$('img#image').attr("src", img + ".jpg");
}


// ======================================================================
//    お問い合わせフォーム
// ======================================================================
function selectMode(mode) {
	$('#step3Content').inc('inc/' + mode + '.php');
}









$(document).ready(function(){
	$('#serviceListGrid').flexigrid({
		height: 300,
		colModel : [
			{display: "-", width: 80, sortable : false, align: 'center'},
			{display: "<a href=\"/service-website/service/template.php\">テンプレートプラン</a>", width: 95, sortable : false, align: 'center'},
			{display: "<a href=\"/service-website/service/uptosw.php\">おまかせプラン</a>", width: 95, sortable : false, align: 'center'},
			{display: "<a href=\"/service-website/service/standard.php\">こだわりプラン</a>", width: 95, sortable : false, align: 'center'},
			{display: "<a href=\"/service-website/service/industry/\">業種別プラン</a>", width: 95, sortable : false, align: 'center'}
		]
	});
});