// JavaScript Document

/* ロールオーバー設定 */
function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_ov'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_ov'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

window.onload = initRollovers;


/* お問合せフォーム必須項目チェック */
function contactCheck() {
	var i = 0;						//カウント変数
	var text;						//入力チェックの戻り値（エラーメッセージ or ""）
	var message = new Array();		//エラーメッセージ
	//▼エラーの確認
	//氏名の入力チェック
	text = ifNull(document.contact.name, "氏名");
	if (text != "") {
		message[i] = text;
		i++;
	}
	//全角カナかチェック
	if (document.contact.kana.value != "") {
		text = em_sizeKana(document.contact.kana, "フリガナ");
		if (text != "") {
			message[i] = text;
			i++;
		}
	}
	//「Eメール」、「TEL」の両方が空欄の場合のメッセージ
	if (document.contact.mail.value == "" && document.contact.tel.value == "") {
		message[i] = "Eメール・TELのどちらか必須です。";
		i++;
	}
	//Eメール
	if (document.contact.mail.value != "") {
		//上記で、エラーがない場合、メールアドレスが正しいかチェックを行う
		text = checkMail(document.contact.mail, "Eメール");
		if (text != "") {
			message[i] = text;
			i++;
		}		
	}
	//TEL
	if (document.contact.tel.value != "") {
		//半角数字、ハイフンかチェック
		text = telFax(document.contact.tel, "TEL");
		if (text != "") {
			message[i] = text;
			i++;
		}
	}	
	//▼エラーメッセージの表示
	var errorText = "";
	if (message.length > 0) {
		for (i = 0;i < message.length;i++) {
			errorText += "・" + message[i] + "\n";
		}
	}
	if (errorText != "") {
		alert(errorText);
	} else {
	//▼送信処理
		document.contact.action='check.html'; 
		document.contact.submit();
	}
}

