/***
	funcs.js: Misc. functions for Calcorsa's Home-Page
***/
//-----------------------------------------------------------
// For Rotating Images
//-----------------------------------------------------------
// Modified by T. Hoya: original source: rotateimage.js by
// 伊織舞也 (http://www.losttechnology.jp/)
var fRotate=false;
function rotateImageH(id,org,flow) {
  c=document.getElementById(id);
  //if ((c.width==org)||(c.width<Math.abs(flow)*2)) flow=flow*-1;
  if ((c.width==org)||(c.width<Math.abs(flow)*2)) {
  	if(flow>=0){
  		if(flow<=5) {
  			c.filters.fliph.enabled=false;
  			clearTimeout(rt_id);
  			fRotate=false;
  			return;
  		};
  		else flow-=2;
  	}
  	flow=flow*-1;
  }
  if ((document.all)&&(c.width<Math.abs(flow)*2)) c.filters.fliph.enabled=(!c.filters.fliph.enabled)?true:false;
  c.style.left=parseInt(c.style.left)-flow/5;
  c.width=parseInt(c.width)+flow*2;
  spd=Math.floor(100*(1-(c.width/org))^2);
  rt_id=setTimeout('rotateImageH("'+id+'",'+org+','+flow+');',spd);
}
function initializeRotateImageH(id,px) {
	if(fRotate==true)return;
	fRotate=true;
  if ((document.all)&&(document.getElementById)) {
    c=document.getElementById(id);
    if (document.all) {
      c.style.filter='fliph';
      c.filters.fliph.enabled=false;
    }
    cs=c.style;
    cs.position='relative';
    cs.left='0px';
    cs.top='0px';
    setTimeout('rotateImageH("'+id+'",'+c.width+','+px+');',0);
  }
}
//-----------------------------------------------------------
// For Zooming Dish Images
//-----------------------------------------------------------
var w=0,h=0,dt=0,ratio,fMouseOut=false;
function GetIMGObj(id){
	if(document.all)
		return document.all(id);
	else if(document.getElementById)
		return document.getElementById(id);
}
function ResizeIMG(id,w,h){
	var obj=GetIMGObj(id);
	obj.style.width=w,obj.style.height=h;
	if(obj.width>=obj.endW&&fMouseOut==true)
		setTimeout("ZoomOutIMG('"+id+"')",500);
}
function InitIMG(id,w){
	var obj=GetIMGObj(id);
	obj.endW=obj.width,obj.endH=obj.height;
	obj.ratio=obj.endH/obj.endW;
	obj.startW=w,obj.startH=parseInt(obj.ratio*obj.endW),obj.width=obj.startW;
	obj.style.visibility="visible"
	// set the event handlers
	obj.onmouseover=function(){ 
		//document.title=obj.startW+":"+obj.ratio;
		ZoomInIMG(id); 
	}
	obj.onmouseout=function(){ ZoomOutIMG(id); }
}
function ZoomIMG(id,step,delta_t,sgn){
	var obj=GetIMGObj(id);
	offw=parseInt((obj.endW-obj.startW)/step);
	for(i=0;i<step;i++){
		obj.w+=sgn*offw,obj.h=parseInt(obj.ratio*obj.w),dt+=delta_t;
		setTimeout("ResizeIMG('"+id+"',"+obj.w+","+obj.h+")",dt)
	}
}
function ZoomInIMG(id){
	var obj=GetIMGObj(id);
	fMouseOut=false;
	if(obj.width!=obj.startW) return;
	obj.w=obj.startW,obj.h=obj.startH,dt=0;
	ZoomIMG(id,1,30,1);
	//ZoomIMG(id,60,20,1);
}
function ZoomOutIMG(id){
	var obj=GetIMGObj(id);
	fMouseOut=true;
	if(obj.width!=obj.endW) return;
	obj.w=obj.endW,obj.h=obj.endH,dt=0;
	ZoomIMG(id,1,30,-1);
	//ZoomIMG(id,60,20,-1);
}
//-----------------------------------------------------------
// For Showing Dish Images (old)
//-----------------------------------------------------------
function ShowDish( id, flg, img ){
	if( eval("document.all."+id).innerHTML == "" ){
		str = ' onclick="' + 'eval(\''
				+ id + ".innerHTML"
				+ '=vstr\');"';
		eval("document.all."+id).innerHTML='<CENTER>'
			+ '<IMG SRC="' + dish_path + "/"+ img + dish_ext + '"' + str +'><BR>'
			+ "<INPUT TYPE=button value='隠す (または画像をクリックして隠す)'"
			+ str
			+ '></CENTER>';
	} else {
		if( flg == 1 ) eval("document.all."+id).innerHTML='';
	}
}
function ShowDish_e( id, flg, img ){
	if( eval("document.all."+id).innerHTML == "" ){
		str = ' onclick="' + 'eval(\''
				+ id + ".innerHTML"
				+ '=vstr\');"';
		eval("document.all."+id).innerHTML='<CENTER>'
			+ '<IMG SRC="' + dish_path + "/"+ img + dish_ext + '"' + str +'><BR>'
			+ "<INPUT TYPE=button value='Hide (or Click the Image to Hide)'"
			+ str
			+ '></CENTER>';
	} else {
		if( flg == 1 ) eval("document.all."+id).innerHTML='';
	}
}
//-----------------------------------------------------------
// For booking functions
//-----------------------------------------------------------
var vstr="";
var dish_path="dishimg";
var dish_ext=".jpg";

function CheckForm() {
	if( document.all.Name.value == "" ) {
		alert("お名前を入力してください"); return;
	} else if( document.all.NumPersons.value == "" ) {
		alert("ご予約人数を入力してください"); return;
	}
}

function ConfirmSelect () {
	var sel1=document.all.SelFax.checked;
	var sel2=document.all.SelMail.checked;
	var str_true='(<FONT style="font-weight:bold;" color=green>必須</FONT>) ◆';
	var str_false='■';
	
	if( sel1 == true ) { // Fax
		document.all.C3.innerHTML=str_false;
		document.all.C4.innerHTML=str_true;
	} else if( sel2 == true ) { // E-mail
		document.all.C3.innerHTML=str_true;
		document.all.C4.innerHTML=str_false;
	} else {
		document.all.C3.innerHTML=str_false;
		document.all.C4.innerHTML=str_false;
	}
}

function CourseSelect() {
	var sel=document.all.SelCourse.selectedIndex;
	
	switch(sel) {
		case 0: // \3,000
			document.all.C1.innerHTML="のコースで、ご希望の料理が";
			document.all.C2.innerHTML=
				"魚" +
					'<INPUT size=3 ID=NumFish NAME="num-fish">' +
					'人 <FONT style="font-weight:bold">＋</FONT> '+
				"肉" +
					'<INPUT size=3 ID=NumMeat NAME="num-meat">' +
					"人、　"+
				"オードブル" +
					'<INPUT size=3 ID=NumApp NAME="num-appetizer">' +
					'人 <FONT style="font-weight:bold;">＋</FONT> '+
				"デザート" +
					'<INPUT size=3 ID=NumDes NAME="num-dessert">' +
					"人  ";
			break;
		case 1: // \4,000
			document.all.C1.innerHTML="のコースで、ご希望の料理が";
			document.all.C2.innerHTML=
				"魚" +
					'<INPUT size=3 ID=NumFish NAME="num-fish">' +
					'人 <FONT style="font-weight:bold">＋</FONT> '+
				"肉" +
					'<INPUT size=3 ID=NumMeat NAME="num-meat">' +
					"人　　"+
				'<FONT color=red style="font-weight:bold;">' +
					'（オードブル＆デザート込み）</FONT>';
			break;
		case 2: // \5,000
			document.all.C1.innerHTML="のフルコース";
			document.all.C2.innerHTML="<BR>";
			break;
	}
}
//---------------------------------------------------------------
// Other misc. functions
//---------------------------------------------------------------
function GetTodaysDate() {
	var myDate = new Date();
	return myDate.getDate()-1;
}
function GetTodaysMonth() {
	var myDate = new Date();
	return myDate.getMonth();
}
function InitThisPage() {
	if( document.layers ) {
		document.layers[0].captureEvents(Event.MOUSEOVER);
		document.layers[0].onmouseover=SetFocus;
	} else {
		document.onmouseover=SetFocus;
	}
}
function SetFocus(){ self.focus(); }
// For Debugging
function check_obj(obj) {
	var mstr ="";

	for( i in obj ) {
		mstr += (i + ":" + obj[i] + "\n");
	}
	alert(mstr);
}
