//Event Action

onload=onloadAction;
onresize=onresizeAction;

function onloadAction(){
	doRectangleControl();
	initFrameHeight();
}

function onresizeAction(){
	resizeFrameHeight();
}


//PreloadImages
function preloadImages(){
	var imgDir="/diet/img/";
	var imgFileName=new Array();
	var imgArray=new Array();
	for(i=0;i<imgFileName.length;i++){
		imgArray[i]=new Image();
		imgArray[i].src=imgDir+imgFileName[i];
	}
}

//ChangeImages
function changeImages(){
	if (document.images){
		for(i=0;i<changeImages.arguments.length;i+=2){
			document[changeImages.arguments[i]].src=changeImages.arguments[i+1];
		}
	}
}

function changeThisImage(){
	if (document.images){
		changeThisImage.arguments[0].src=changeThisImage.arguments[1];
	}
}

//ChangeMenuBtn
function changeMenuBtn1(id,type){
	if(id=="M1" || id=="M2" || id=="H1" || id=="H2" || id=="Estate"){
		var btnType="btn1";
	}
	if(document.images){
		document["btn"+id].src="/img/"+btnType+"_"+id+type+".gif";
	}
	if(browserType.IE){
		document.all["btn"+id+"Bg1"].style.backgroundImage="url(/img/"+btnType+"_bg1"+type+".gif)";
		document.all["btn"+id+"Bg2"].style.backgroundImage="url(/img/"+btnType+"_bg2"+type+".gif)";
	}
	else{
		document.getElementById("btn"+id+"Bg1").style.backgroundImage="url(/img/"+btnType+"_bg1"+type+".gif)";
		document.getElementById("btn"+id+"Bg2").style.backgroundImage="url(/img/"+btnType+"_bg2"+type+".gif)";
	}
}

//AdSense for text
google_ad_client='nifty_js';
google_ad_output='js';
google_max_num_ads=5;
google_language='ja';
google_encoding='sjis';
google_safe='medium';
google_adtest='on';
google_ad_channel='travel';

function google_ad_request_done(){
	if(google_ads.length>0){
		var str="";
		str+='<div class="titleEx"><img src="/diet/img/title_adsense.gif" width="300" height="18" alt="Ads by Google"></div>';
		str+='<div class="tab60">';
		for(i=0;i<google_ads.length;i++){
			str+='<div class="item"><a href="'+google_ads[i].url+'"><img src="/diet/img/item_mark.gif" width="10" height="10" border="0" alt=" ">'+google_ads[i].line1+'</a>　<span class="s"><span class="darkGray">'+google_ads[i].visible_url+'</span></span><br>'+google_ads[i].line2+"&nbsp;"+google_ads[i].line3+'</div>';
		}
		str+='</div>';
		str+='<br><br><br>';
		document.write(str);
	}
}

//RectangleControl
rectangleFlg=0;

function rectangleControl(){
	rectangleFlg=1;
}

function doRectangleControl(){
	if(rectangleFlg){
		if(browserType.IE){
			if(document.all["rectangle"].scrollHeight<10){
				document.all["rectangle"].style.display="none";
			}
		}
		else{
			if(document.getElementById("rectangle").scrollHeight<10){
				document.getElementById("rectangle").style.display="none";
			}
		}
	}
}

//FrameSizeControl
frameFlg=false;

function initFrameHeight(){
	if(frameFlg){
		var frameHeight=getFrameHeight("mainFrame");
		var documentHeight=getDocumentHeight();
		frameDif=documentHeight-frameHeight;
		resizeFrameHeight();
	}
}

function resizeFrameHeight(){
	if(frameFlg){
		var windowHeight=getWindowHeight();
		if(browserType.IE){
			document.all["mainFrame"].style.height=windowHeight-frameDif;
		}
		else{
			document.getElementById("mainFrame").style.height=windowHeight-frameDif;
		}
	}
}

function getFrameHeight(id){
	if(browserType.IE){
		var frameHeight=document.all[id].offsetHeight;
	}
	else{
		var frameHeight=document.getElementById(id).offsetHeight;
	}
	return frameHeight;
}

function getDocumentHeight(){
	if(browserType.IE && osType.Mac){
		var documentHeight=document.body.offsetHeight;
	}
	else{
		var documentHeight=document.body.scrollHeight;
	}
	return documentHeight;
}

function getWindowHeight(){
	if(browserType.IE){
		var windowHeight=document.body.clientHeight;
	}
	else{
		var windowHeight=window.innerHeight;
	}
	return windowHeight;
}

//SearchForm
function checkPrefGroup(groupid){
	if (document.forms["searchOption"].elements[groupid+"top"].checked==true){
		for(i=0;i<document.forms["searchOption"].elements.length;i++){
			if(document.forms["searchOption"].elements[i].id.indexOf(groupid+"_")!=-1){
				document.forms["searchOption"].elements[i].checked = true;
			}
		}
	}
	if (document.forms["searchOption"].elements[groupid+"top"].checked==false){
		for (i = 0; i <document.forms["searchOption"].elements.length; i++){
			if(document.forms["searchOption"].elements[i].id.indexOf(groupid+"_")!=-1){
				document.forms["searchOption"].elements[i].checked = false;
			}
		}
	}
}


//WriteCopy
function writeCopy(){
	var copyNum=Math.floor(Math.random()*copyArray.length);
	var str="";
	str+='';
	str+='<div class="topTitle" style="background-image:url(\''+copyArray[copyNum][0]+'\');"><div style="background-image:url(\''+copyArray[copyNum][4]+'\'); background-repeat:no-repeat;"><a href="'+copyArray[copyNum][3]+'" onmouseover="startOpenAnimation();" onmouseout="startCloseAnimation();"><img src="/img/s.gif" width="100%" height="70" border="0" alt="'+copyArray[copyNum][1]+'"></a></div><div id="copyPalette" class="lh125" onmouseover="startOpenAnimation();" onmouseout="startCloseAnimation();">'+copyArray[copyNum][2]+'</div></div>';
	document.write(str);
}

//CopyPalette
var copyPaletteOffsetX=-600;
var copyPaletteOffsetY=145;
var fadeTimer=0;
var fadeCounter=0;

function startOpenAnimation(){
	showCopyPalette();
	clearTimeout(fadeTimer);
	if(browserType.IE && osType.Win){
		document.all["copyPalette"].filters.alpha.opacity=0;
		fadeinCopyPalette();
	}
}

function startCloseAnimation(){
	clearTimeout(fadeTimer);
	if(browserType.IE && osType.Win){
		fadeoutCopyPalette();
	}
	else{
		hideCopyPalette();
	}
}

function fadeinCopyPalette(){
	fadeCounter+=1;
	document.all["copyPalette"].filters.alpha.opacity=fadeCounter*10;
	document.all["copyPalette"].style.left=copyPaletteX-Math.round(Math.pow(10-fadeCounter,2)*0.2);
	if(fadeCounter<10){
		fadeTimer=setTimeout("fadeinCopyPalette()",10);
	}
}

function fadeoutCopyPalette(){
	fadeCounter-=1;
	document.all["copyPalette"].filters.alpha.opacity=fadeCounter*10;
	document.all["copyPalette"].style.left=copyPaletteX-Math.round(Math.pow(10-fadeCounter,2)*0.2);
	if(fadeCounter>0){
		fadeTimer=setTimeout("fadeoutCopyPalette()",10);
	}
}

function showCopyPalette(){
	//PalettePositionSet
	var WindowWidth=document.body.clientWidth;
	if(WindowWidth<980 && WindowWidth>780){
		copyPaletteX=WindowWidth+copyPaletteOffsetX;
	}
	else if(WindowWidth<780){
		copyPaletteX=780+copyPaletteOffsetX;
	}
	else{
		copyPaletteX=Math.floor((WindowWidth+980)/2)+copyPaletteOffsetX;
	}
	copyPaletteY=copyPaletteOffsetY;

	if(browserType.IE){
		document.all["copyPalette"].style.visibility="visible";
		document.all["copyPalette"].style.left=copyPaletteX;
		document.all["copyPalette"].style.top=copyPaletteY;
	}
	else{
		document.getElementById("copyPalette").style.visibility="visible";
		document.getElementById("copyPalette").style.left=copyPaletteX;
		document.getElementById("copyPalette").style.top=copyPaletteY;
	}
}

function hideCopyPalette(){
	if(browserType.IE){
		document.all["copyPalette"].style.visibility="hidden";
		document.all["copyPalette"].style.left=0;
	}
	else{
		document.getElementById("copyPalette").style.visibility="hidden";
		document.getElementById("copyPalette").style.left=0;
	}
}


//SelectArea
function popJump(selOBJ)
{
        n = selOBJ.selectedIndex;
        location.href = selOBJ.options[n].value;
}



// bpref = tab body prefix, hpref = tab header prefix
function seltab(bpref, hpref, id_max, selected) {
  if (! document.getElementById) return;
  for (i = 0; i <= id_max; i++) {
    if (! document.getElementById(bpref + i)) continue;
    if (i == selected) {
      document.getElementById(bpref + i).style.visibility = "visible";
      document.getElementById(bpref + i).style.position = "";
      document.getElementById(hpref + i).className = "open";
    } else {
      document.getElementById(bpref + i).style.visibility = "hidden";
      document.getElementById(bpref + i).style.position = "absolute";
      document.getElementById(hpref + i).className = "off";
    }
  }
}