var formFlg01 = 0;
var formFlg02 = 0;
var formFlg03 = 0;
var formFlg04 = 0;
var formFlg05 = 0;
var formFlg06 = 0;
var checkFlg = 0;

/* フォームコントロール関数 */
function fc(){

	checkFlg = 0;
	$('#contactForm input').css({'border-color':'#969696'});
	$('#contactForm textarea').css({'border-color':'#969696'});

	if(formFlg01 == 0|$('#contactForm input#q01').attr('value') == ''){
		$('#contactForm input#q01').css({'border-color':'#00CCFF'});
		$('#contactForm p.alert').html('[氏名]必須項目を入力してください。');
		checkFlg = 1;
	}

	if(formFlg02 == 0|$('#contactForm input#q02').attr('value') == ''){
		$('#contactForm input#q02').css({'border-color':'#00CCFF'});
		$('#contactForm p.alert').html('[E-mail]必須項目を入力してください。');
		checkFlg = 1;
	}

	if(formFlg06 == 0){
		$('#contactForm textarea#q06').css({'border-color':'#00CCFF'});
		checkFlg = 1;
	}

	if(checkFlg ==0){
		// メール送信
		Create_Contact();
	}
}



// 2008.12.3 Six ishii
// お問い合わせ送信
function Create_Contact() {
	var xmlhttp = createXmlHttpRequest();

	var cmd = "";
	cmd = cmd + "q01=" + encodeURL(document.contact.q01.value);
	cmd = cmd + "&q02=" + encodeURL(document.contact.q02.value);
	cmd = cmd + "&q03=" + encodeURL(document.contact.q03.value);
	cmd = cmd + "&q04=" + encodeURL(document.contact.q04.value);
	cmd = cmd + "&q05=" + encodeURL(document.contact.q05.value);
	cmd = cmd + "&q06=" + encodeURL(document.contact.q06.value);

	var url = "/contact/contact.php?" + cmd;

	xmlhttp.open('POST', url, true);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var ret = xmlhttp.responseText;
			if (ret == '0') {
				// 正常終了
				$('#contactForm').slideUp(500);
				$('#contactFormCompleate').slideDown(500);
			} else {
				// エラー終了
				$('#contactForm input#q01').css({'border-color':'#00CCFF'});
				$('#contactForm p.alert').html(ret);
			}
		}
	}
	xmlhttp.send(null);
}


function createXmlHttpRequest() {
	var xmlhttp = null;
	if (window.XMLHttpRequest) {		// Firefox,Opera,Safari,IE7
		return new XMLHttpRequest();
	} else if(window.ActiveXObject){	// IE6
		try {
			return new ActiveXObject("Msxml2.XMLHTTP");			// MSXML3
		} catch (e) {
			return new ActiveXObject("Microsoft.XMLHTTP");		// MSXML2まで
		}
	} else {
		return null;
	}
}


// 文字列のエンコード
function encodeURL(str) {
	var character = '';
	var unicode = '';
	var string = '';
	var i = 0;

	for (i = 0; i < str.length; i++) {
		character = str.charAt(i);
		unicode = str.charCodeAt(i);

		if (character == ' ') {
			string += '+';
		} else {
			if (unicode == 0x2a || unicode == 0x2d || unicode == 0x2e || unicode == 0x5f || ((unicode >= 0x30) && (unicode <= 0x39)) || ((unicode >= 0x41) && (unicode <= 0x5a)) || ((unicode >= 0x61) && (unicode <= 0x7a))) {
				string = string + character;
			} else {
				if ((unicode >= 0x0) && (unicode <= 0x7f)) {
					character   = '0' + unicode.toString(16);
					string += '%' + character.substr(character.length - 2);
				} else if (unicode > 0x1fffff) {
					string += '%' + (0xf0 + ((unicode & 0x1c0000) >> 18)).toString(16);
					string += '%' + (0x80 + ((unicode & 0x3f000) >> 12)).toString(16);
					string += '%' + (0x80 + ((unicode & 0xfc0) >> 6)).toString(16);
					string += '%' + (0x80 + (unicode & 0x3f)).toString(16);
				} else if (unicode > 0x7ff) {
					string += '%' + (0xe0 + ((unicode & 0xf000) >> 12)).toString(16);
					string += '%' + (0x80 + ((unicode & 0xfc0) >> 6)).toString(16);
					string += '%' + (0x80 + (unicode & 0x3f)).toString(16);
				} else {
					string += '%' + (0xc0 + ((unicode & 0x7c0) >> 6)).toString(16);
					string += '%' + (0x80 + (unicode & 0x3f)).toString(16);
				}
			}
		}
	}

	return string;
}
