// -------------------------------------------------------------------
// 　共通javascript関数
// 　1.ポップアップウインドウ
// 　2.本文折りたたみ
// 　3.ボタンロールオーバー
// 　4.検索フィールドの文字制御
// 　5.フォームの入力チェック
// -------------------------------------------------------------------

// 1. ポップアップウインドウ（class使用) -----------------------------
// 書式：<a href="URL" rel="width,height" class="popup">LINK</a>
// メモ：relにウインドウサイズ、 classにpopupを指定

window.onload = function (){
	var node_a = document.getElementsByTagName('a');
		for (var i in node_a) {
			if(node_a[i].className == 'popup'){
				node_a[i].onclick = function() {
					return winOpen(this.href, this.rel)
				};
			}
		}
} ;
function winOpen(url, rel) {
	var split = rel.split(',') ;
	window.open(
	url,'popup',
	'width='+ split[0] +',height='+ split[1] +',toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
	return false;
};

// 1. ポップアップウインドウ（onclick使用) -----------------------------
// 書式：<a href="javaScript:void(0)" onclick="openPopWindow('xxx.html','subwin','toolbar=no,status=yes,menubar=no'); return false;">
// winName= windowname 
// features=toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes

function openPopWindow(theURL,winName,features) {
	window.open(theURL,winName,features);
}

// 2. 本文折りたたみ ---------------------------------------------
function expBox(id) {
	if(document.getElementById) {
		if(document.getElementById(id).style.display == 'none') {
			document.getElementById(id).style.display = 'block';
			document.getElementById(id + "_f").innerHTML = '<img src="images/icon_set01_close.gif" width="16" height="16" alt="閉じる" title="" />閉じる';
		} else {
			document.getElementById(id).style.display = 'none';
			document.getElementById(id + "_f").innerHTML = '<img src="images/icon_set01_down.gif" width="16" height="16" alt="開く" title="" />開く';
		}
	}
}
function expText(id,type) {
	if( type == 0 ) {
		if(document.getElementById) {
			if(document.getElementById(id).style.display == 'none') {
				document.getElementById(id).style.display = 'block';
				document.getElementById(id + "_f").innerHTML = '<img src="images/icon_set01_up.gif" width="16" height="16" alt="詳細を閉じる" title="" />詳細を閉じる';
			} else {
				document.getElementById(id).style.display = 'none';
				document.getElementById(id + "_f").innerHTML = '<img src="images/icon_set01_down.gif" width="16" height="16" alt="詳細を見る" title="" />詳細を見る';
			}
		}
	} else {
		document.getElementById(id).style.display = 'none';
		document.getElementById(id + "_f").innerHTML = '<img src="images/icon_set01_down.gif" width="16" height="16" alt="詳細を見る" title="" />詳細を見る';
	}
}


// 3.ボタンロールオーバー ---------------------------------------------
// 書式：<img>に「class="imgover"」を指定する。
// メモ：xxx.gif（off画像）、xxx_on.gif（on画像）とする

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, '_on'+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('_on'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}
try{
	window.addEventListener("load",initRollovers,false);
}catch(e){
	window.attachEvent("onload",initRollovers);
}

// 4.検索フィールドの文字制御 ---------------------------------------------

var input_flg=0;
var srchstr = "検索";

function clearSrchtext() {
  if(input_flg==0) {
    document.getElementById("q").value = "";
    document.getElementById("q").style.color = "#000000";
  }
}
function checkSrchtext() {
  if(document.getElementById("q").value=="") {
    input_flg = 0;
    document.getElementById("q").style.color = "#777777";
    document.getElementById("q").value = srchstr;
  } else {
    input_flg = 1;
    document.getElementById("q").style.color = "#000000";
  }
}

// 5.フォームチェック ---------------------------------------------
function checkform() {
    // 氏名
    if(document.contact.uname.value =='' ){
        alert("「氏名」を入力してください。");
        document.contact.uname.focus();
        return(false);
    }
    // パスワード
    if(document.contact.upass.value =='' ){
        alert("「パスワード」を入力してください。");
        document.contact.upass.focus();
        return(false);
    }
    if(document.contact.repass.value =='' ){
        alert("「パスワード（確認用）」を入力してください。");
        document.contact.repass.focus();
        return(false);
    }
    // メールアドレス
    var atmark = 0;
    var piriod = 0;
    if(document.contact.email.value =='' ){
        alert("メールアドレスを入力してください。");
        document.contact.email.focus();
        return(false);
    }
    cc = document.contact.email.value.charAt(0);
    if (((cc < "0") || ("9" < cc)) && ((cc < "a") || ("z" < cc)) && ((cc < "A") || ("Z" < cc))) {
        alert("メールアドレスに不正があります。");
        document.contact.email.focus();
        return(false);
    }
    cc = document.contact.email.value.charAt(document.contact.email.value.length - 1);
    if (((cc < "0") || ("9" < cc)) && ((cc < "a") || ("z" < cc)) && ((cc < "A") || ("Z" < cc))) {
        alert("メールアドレスに不正があります。");
        document.contact.email.focus();
        return(false);
    }
    for (i = 1;i < document.contact.email.value.length;i++) {
        cc = document.contact.email.value.charAt(i);
        if (((cc < "0") || ("9" < cc)) &&
        ((cc < "a") || ("z" < cc)) &&
        ((cc < "A") || ("Z" < cc)) &&
        ("@" != cc) &&
        ("." != cc) &&
        ("_" != cc) &&
        ("-" != cc)) {
        alert("メールアドレスに不正があります。")
        document.contact.email.focus();
        return(false);
        }
        else if (cc == "@") atmark++;
        else if (cc == ".") piriod++;
    }
    if (atmark < 1) {
        alert("メールアドレスに@が含まれていません。");
        document.contact.email.focus();
        return(false);
    }
    else if (atmark > 1) {
        alert("メールアドレスに@が多すぎます。");
        document.contact.email.focus();
        return(false);
    }
    if (piriod < 1) {
        alert("メールアドレスにピリオドが含まれていません。");
        document.contact.email.focus();
        return(false);
    }
    // テキストエリア
    if(document.contact.memo.value =='' ){
        alert("「テキストエリア」を入力してください。");
        document.contact.memo.focus();
        return(false);
    }
    // 電話番号
    if(document.contact.telno.value =='' ){
        alert("電話番号を半角数字で入力してください。");
        document.contact.telno.focus();
        return(false);
    }
    var str_telno = document.contact.telno.value;
    if( str_telno.match( /^\d{10}$/ ) ) {
         alert("電話番号は半角数字のみで入力して下さい。");
        return(false);
    }
    // 郵便番号
    var str_zipcode = document.contact.zipcode.value;
    if( str_zipcode.match( /^\d{3}-\d{4}$/ ) ) {
         alert("正しい郵便番号を半角数字とハイフンで入力して下さい。");
        return(false);
    }
    // 住所
    if(document.contact.uaddress.value =='' ){
        alert("住所を入力してください。");
        document.contact.uaddress.focus();
        return(false);
    }
    return(true);
}

// 6. 全選択・全解除 ---------------------------------------------
function allchecked(result){
	for( var count=0; count<document.form.checkbox.length; count++ ) {
		document.form.checkbox[count].checked = result;
	}
}
// 7. 魂の系譜 ---------------------------------------------
function WindowMaxOpen(url){
	objw =window.open(url,"tamashinokeihu","width="+screen.availWidth+",height="+screen.availHeight+",scrollbars=0,resizable=1,toolbar=0,menubar=0,location=0,status=0");
	objw.moveTo(0,0);
}

