/**************************************

hirosfactory.net
written by Hiroshi Konnai
2009.11.11

***************************************/
function smartRollover() {
	if(document.getElementsByTagName) {
		var images = document.getElementsByTagName("img");
		for(var i=0; i < images.length; i++) {
			if(images[i].getAttribute("src").match("_up."))
			{
				images[i].onmouseover = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_up.", "_over."));
				}
				images[i].onmouseout = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_over.", "_up."));
				}
			}
		}
	}
}
if(window.addEventListener) {
	window.addEventListener("load", smartRollover, false);
}
else if(window.attachEvent) {
	window.attachEvent("onload", smartRollover);
}
//画像の差し替えファンクション
function gazou(mySrc){
    document.myimg.src=mySrc;
}

//フラッシュ出力用
var movieName;//フラッシュ本体
var movieWidth;//幅
var movieHeight;//高さ
var movieBgcolor;//背景色
var movieID;//ID
function WriteFlash(movieName,movieWidth,movieHeight,movieBgcolor,movieID){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+movieWidth+'" height="'+movieHeight+'" id="'+movieID+'" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="allowFullScreen" value="false" />');
	document.write('<param name="movie" value="'+movieName+'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="bgcolor" value="'+movieBgcolor+'" />');
	document.write('<embed src="'+movieName+'" quality="high" bgcolor="'+movieBgcolor+'" width="'+movieWidth+'" height="'+movieHeight+'" name="'+movieID+'" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

function PrintPage(){
    if(document.getElementById || document.layers){
        window.print();        //印刷をします
    }
}

/*
window.open機能拡張 020828版 + 030329fix
script written by Mugi (mugi@mugi.cc)
*/
_wopen=window.open
function wopen(url,name,opt){
var w,h,c=false,g=null,l,t,o,x=-1,i=0,a=["left","top","width","height","resizable","scrollbars","status","menubar","toolbar","location","directories"]
if(!name)name="";if(!opt)opt=""
if(opt.match(/^(\d+|\*)(,(\d+|\*))+$/)){
do opt=opt.substring(0,x+1)+a[i]+"="+opt.substring(x+1);while((x=opt.indexOf(',',x+a[i++].length))!=-1)
opt=opt.replace(/[^=]+=\*,/g,"")
}
if(opt.match(/image=(true|1)/)){
g=new Image();g.src=url;url="";opt+=",resizable=1"
if(g.width>0&&g.height>0)
opt+=",width="+(w=g.width)+",height="+(h=g.height)
}
if(
(w=opt.match(/width=(\d+)/))&&(w=RegExp.$1)&&
(h=opt.match(/height=(\d+)/))&&(h=RegExp.$1)&&
opt.match(/center=(true|1)/)&&!!(c=true)
)
opt+=",left="+(l=(screen.width-w)/2)+",top="+(t=(screen.height-h)/2)
o=_wopen(url,name,opt)
if(c&&navigator.platform.indexOf("Mac")!=-1)o.moveTo(l,t)
if(g){
o.document.open()
o.document.write(
'<html><head><title>'+g.src.substring(g.src.lastIndexOf('/')+1)+'</title><head><body style=overflow:hidden leftmargin=0 topmargin=0 marginwidth=0 marginheight=0><center><img src="'+g.src+'"'+(w>0&&h>0?' width='+w+' height='+h:
' onload="if(self.innerWidth){self.innerWidth=this.width;self.innerHeight=this.height}else{self.resizeBy(this.width-document.body.clientWidth,this.height-document.body.clientHeight)}"')+'></center></body></html>')
o.document.close()
}
return o
}
window.open=wopen

function newopen(imgname){
	pwin=window.open(imgname,'img1','left=100,top=100,image=1');
	pwin.print();
	pwin.close();
	return false;
}

//OS判別用スクリプト
function OsFixfunc(movieUrl1,movieUrl2,movieUrl3,movieUrl4){
    if(navigator.platform.indexOf("Win") != -1){
    //Windows用
        document.write('<a href="../movies/win/'+movieUrl1+'.wmv" target="_blank">');
        document.write('<img src="../img/common/btn_broad.jpg" width="255" height="45" />');
        document.write('</a>');
        document.write('<a href="../movies/win/'+movieUrl2+'.wmv" target="_blank">');
        document.write('<img src="../img/common/btn_narrow.jpg" width="255" height="45" />');
        document.write('</a>');
    }else{
    //Mac用
        document.write('<a href="../movies/mac/'+movieUrl3+'.mov" target="_blank">');
        document.write('<img src="../img/common/btn_broad.jpg" width="255" height="45" />');
        document.write('</a>');
        document.write('<a href="../movies/mac/'+movieUrl4+'.mov" target="_blank">');
        document.write('<img src="../img/common/btn_narrow.jpg" width="255" height="45" />');
        document.write('</a>');
    }
}

//フォーム項目選択ファンクション
function changeForm(){
	var selectForm1 = document.forms.resform.utitle; //変数selectForm1を宣言
	
	if (selectForm1.options[selectForm1.selectedIndex].value == "資料請求"){
		document.getElementById("inq1").style.display = "block";
		document.getElementById("inq2").style.display = "none";
		document.getElementById("inq3").style.display = "none";
		document.getElementById("inqtxt1").style.display = "block";
		document.getElementById("inqtxt2").style.display = "none";
	}else if(selectForm1.options[selectForm1.selectedIndex].value == "体験入学申込み"){
		document.getElementById("inq1").style.display = "none";
		document.getElementById("inq2").style.display = "block";
		document.getElementById("inq3").style.display = "none";
		document.getElementById("inqtxt1").style.display = "none";
		document.getElementById("inqtxt2").style.display = "block";
	}else if(selectForm1.options[selectForm1.selectedIndex].value == "その他お問い合わせ"){
		document.getElementById("inq1").style.display = "none";
		document.getElementById("inq2").style.display = "none";
		document.getElementById("inq3").style.display = "block";
		document.getElementById("inqtxt1").style.display = "none";
		document.getElementById("inqtxt2").style.display = "none";
	}
}
//フォームエラーチェックのファンクション
function checkForm(){
	if(document.resform.utitle.value==""){
		alert("お問い合わせ内容をお選びください");
        return false;
	}
	if(document.resform.uname.value==""){
		alert("お名前をご記入ください");
        return false;
	}
	if(document.resform.ufuri.value==""){
		alert("ふりがなをご記入ください");
        return false;
	}
	//else if(!document.resform.ufuri.value.match(/[^\u30A1-\u30FC\u3000\u0020]/g) || !document.resform.ufuri.value.match(/^[0x30A1-0x30f60x30fc]*$/)){
		//alert("ふりがなを正確にご記入ください");
        //return false;
	//}
	if(document.resform.usex[0].checked=="" && document.resform.usex[1].checked==""){
		alert("性別をお選びください");
        return false;
	}
	if(document.resform.uage.value==""){
		alert("年齢をご記入ください");
        return false;
	}else if(document.resform.uage.value.match(/[^0-9]/)){
		alert("年齢を半角数字でご記入ください");
        return false;
	}
	if(document.resform.uzip.value==""){
		alert("郵便番号をご記入ください");
        return false;
	}else if(document.resform.uzip.value.match(/[^0-9\s\+\-]+/)){
		alert("郵便番号を正確にご記入ください");
        return false;
	}
	if(document.resform.upref.value==""){
		alert("都道府県をお選びください");
        return false;
	}
	if(document.resform.uaddress1.value==""){
		alert("区市郡をご記入ください");
        return false;
	}
	if(document.resform.utitle.value=="資料請求"){
		if(document.resform.uaddress2.value==""){
			alert("住所1（番地等）をご記入ください");
			return false;
		}
		//if(document.resform.uaddress3.value==""){
			//alert("住所2（マンション名等）をご記入ください");
			//return false;
		//}
		if(document.resform.utel.value==""){
			alert("電話番号をご記入ください");
			return false;
		}else if(document.resform.utel.value.match(/[^0-9\s\+\-]+/)){
			alert("電話番号を正確にご記入ください");
			return false;
		}
		if(!document.resform.umail.value==""){
			if(!document.resform.umail.value.match(/.+@.+\..+/)){
				alert("ご連絡先のメールアドレスを正しくご記入ください");
				return false;
			}
		}
	}else if(document.resform.utitle.value=="体験入学申込み"){
		if(document.resform.vaddress2.value==""){
			alert("住所1（番地等）をご記入ください");
			return false;
		}
		if(document.resform.vaddress3.value==""){
			alert("住所2（マンション名等）をご記入ください");
			return false;
		}
		if(document.resform.vtel.value==""){
			alert("電話番号をご記入ください");
			return false;
		}else if(document.resform.vtel.value.match(/[^0-9\s\+\-]+/)){
			alert("電話番号を正確にご記入ください");
			return false;
		}
		if(!document.resform.vmail.value==""){
			if(!document.resform.vmail.value.match(/.+@.+\..+/)){
				alert("ご連絡先のメールアドレスを正しくご記入ください");
				return false;
			}
		}
		if(document.resform.vexper.value==""){
			alert("体験入学年月日を選択してください");
			return false;
		}
	}else{
		if(!document.resform.wtel.value==""){
			if(document.resform.wtel.value.match(/[^0-9\s\+\-]+/)){
				alert("電話番号を正確にご記入ください");
				return false;
			}
		}
		if(!document.resform.wmail.value==""){
			if(!document.resform.wmail.value.match(/.+@.+\..+/)){
				alert("ご連絡先のメールアドレスを正しくご記入ください");
				return false;
			}
		}
		if(document.resform.wcomment.value==""){
			alert("お問い合わせ内容をご記入ください");
			return false;
		}		
	}
}
