/*********************************************/
/*                                           */
/* Common.js                                 */
/* 共通Javascript関数                        */
/* 外部ファイルとして共通化                  */
/*                                           */
/* 2011/01/25 和泉                           */
/*                                           */
/*********************************************/

/******************Javascript******************/
//Imageフォルダパス（絶対パス）
var CommonImgPath  = "http://www.mahoujin.co.jp/images/";
var CommonImgPPath = "http://www.mahoujin.co.jp/products/images_p/";
var CommonImgSPath = "http://www.mahoujin.co.jp/images_s/";
var preloadFlag = false;

/* デバックフラグ */
var debug = false;

/* 選択 */
var e_taxSelect = "0";

/******************************************************/
/* newImage
/*
/*
/*  
/******************************************************/
function newImage(arg) 
{
	if (document.images) 
	{
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

/******************************************************/
/* changeImages
/*
/*
/*  
/******************************************************/
function changeImages() 
{
	if (document.images && (preloadFlag == true)) 
	{
		for (var i=0; i<changeImages.arguments.length; i+=2) 
		{
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

/******************************************************/
/* onoffImgGet
/*
/*　imgsrc:
/*　name:
/*　flg:
/*
/*  
/******************************************************/
function onoffImgGet(imgsrc, name, flg)
{

	var Return = imgsrc;	
	var split  = imgsrc.split('/');
	
	if(split.length > 0)
	{
		
		var split1 = split[split.length - 1].split('_');
		var imgname = "";
		
		if(split1.length == 2)
		{
			imgname = split1[0];
		}
		else
		{
			for(var i=0;i <= split1.length - 2;i++)
			{
				if(i != split1.length - 2)
				{
					imgname += split1[i] + '_';
				}
				else
				{
					imgname += split1[i];
				}
			}
		}
		switch(flg)
		{
			case 1:
				Return = CommonImgPath + imgname + "_on" + ".gif";
			break;
			case 2:
				Return = CommonImgPath + imgname + "_off" + ".gif";
			break;
		}
	}
		
	return Return;
	
}

/******************************************************/
/* changeSub
/*
/*
/*  
/******************************************************/
function changeSub() 
{
	if (document.images && (preloadFlag == true)) 
	{
		for (var i=0; i<changeSub.arguments.length; i+=3) 
		{
			if (document.layers)
			{
				document.layers[changeSub.arguments[i]].document.images[changeSub.arguments[i+1]].src = changeSub.arguments[i+2];
			}
			else
			{
				changeImages(changeSub.arguments[i+1], changeSub.arguments[i+2]);
			}
		}
	}
}

/******************************************************/
/* preloadImages
/*
/*
/*  画像をロードしているけども何のためかわからん。
/******************************************************/
function preloadImages() 
{
	//SSL判定
	if (location.protocol == 'https:')
	{
		CommonImgPath  = "https://www.mahoujin.co.jp/images/";
		CommonImgPPath = "https://www.mahoujin.co.jp/products/images_p/";
		CommonImgSPath = "https://www.mahoujin.co.jp/images_s/";
	}
	if (document.images) 
	{
		utiwake_gab01_on   = newImage(CommonImgPPath + "utiwake_gab01_on.gif");
		utiwake_gab02_on   = newImage(CommonImgPPath + "utiwake_gab02_on.gif");
		utiwake_gab03_on   = newImage(CommonImgPPath + "utiwake_gab03_on.gif");
		tri_b_on           = newImage(CommonImgPath + "tri_b_on.gif");
		tri_sb_equal_on    = newImage(CommonImgPath + "tri_sb_equal_on.gif");
		tri_sb_houjin_on   = newImage(CommonImgPath + "tri_sb_houjin_on.gif");
		tri_sb_utiwake_on  = newImage(CommonImgPath + "tri_sb_utiwake_on.gif");
		tri_sb_shotoku_on  = newImage(CommonImgPath + "tri_sb_shotoku_on.gif");
		tri_sb_souzoku_on  = newImage(CommonImgPath + "tri_sb_souzoku_on.gif");
		tri_sb_houtei_on   = newImage(CommonImgPath + "tri_sb_houtei_on.gif");
		tri_sb_shouhi_on   = newImage(CommonImgPath + "tri_sb_shouhi_on.gif");
		tri_sb_genka_on    = newImage(CommonImgPath + "tri_sb_genka_on.gif");
		tri_sb_oldkeiji_on = newImage(CommonImgPath + "tri_sb_oldkeijiban_on.gif");
		tri_sb_keiji_on    = newImage(CommonImgPath + "tri_sb_keijiban_on.gif");
		home_on            = newImage(CommonImgPath + "home_on.gif");
		news_on            = newImage(CommonImgPath + "news_on.gif");
		product_on         = newImage(CommonImgPath + "product_on.gif");
		e_tax_on           = newImage(CommonImgPath + "e_tax_on.gif");
		price_on           = newImage(CommonImgPath + "price_on.gif");
		support_on         = newImage(CommonImgPath + "support_on.gif");
		keiji_on           = newImage(CommonImgPath + "keiji_on.gif");
		company_on         = newImage(CommonImgPath + "company_on.gif");
		contact_on         = newImage(CommonImgPath + "contact_on.gif");
		preloadFlag        = true;
	}
}

/******************************************************/
/* checkObject
/*
/*
/*  
/******************************************************/
function checkObject(object_name) 
{
	var obj;
	if (document.all) 
	{
		obj = document.all[object_name].style;
	}
	else if(document.getElementById)
	{
		 obj = document.getElementById(object_name).style;
	}
	else if(document.layers)
	{
		 obj = document.layers[object_name];
	}
	else return null;
	return obj;
}

//BUTTON SIDE MENUの表示非表示
var last_show="";

/******************************************************/
/* floatMenu
/*
/*  name:
/*  fla:
/*
/*  
/******************************************************/
function floatMenu(name,fla)
{
	if(name!="")
	{

		var obj = checkObject(name);

		if(fla==true){
			if(last_show!=""){
				floatMenu(last_show,false);
			}
			last_show=name;
			obj.visibility="visible";
		} 
		else 
		{
			obj.visibility = "hidden";
		}
	}
}

/******************************************************/
/* openWindow
/*
/*  url:ＵＲＬ
/*
/*  サブウィンドウを表示する
/******************************************************/
function openWindow(url)
{
	var w = window.open(url,"equal", 'toolbar=0,menubar=0,scrollbars=1,status=1,resizable=1,width=645,height=450');
	w.focus();
}

/******************************************************/
/* openWindow1
/*
/*  url:ＵＲＬ
/*
/*  サブウィンドウを表示する（電子用）
/******************************************************/
function openWindow1(url)
{
	var w = window.open(url,"e_taxselect", 'toolbar=0,menubar=0,scrollbars=1,status=0,resizable=0,width=645,height=550');
	w.focus();
}

/******************************************************/
/* openWindow_full
/*
/*  url:ＵＲＬ
/*
/*  サブウィンドウを表示する（フル表示）
/******************************************************/
function openWindow_full(url)
{
	var w = window.open(url,"e_taxbuy", 'toolbar=0,menubar=0,scrollbars=1,status=0,resizable=0,fullscreen=yes');
	w.focus();
}

/******************************************************/
/* popUp
/*
/*  url:ＵＲＬ
/*
/*  サブウィンドウを表示する
/******************************************************/
function popUp(url) 
{ 
	sealWin=window.open(url,"win",'toolbar=0,location=1,directories=0,status=1,menubar=1, scrollbars=1,resizable=1,width=500,height=450'); 
	self.name = "mainWin"; 
}

/******************************************************/
/* popUpLogin
/*
/*  url:ＵＲＬ
/*
/*  ログイン用ウインドウ表示する
/******************************************************/
function popUpLogin(flg)
{
	var w = window.open("https://www.mahoujin.co.jp/verup/login/login.html?Target=" + flg, "MahojinLogin", "width=500,height=420,directories=no,menubar=no,resizable=no");
	w.focus();
}

/******************************************************/
/* showSub
/*
/*  flag:サブメニューの値
/*
/*  サブメニューの表示切り替え処理
/******************************************************/
function showSub(flag) 
{
	floatMenu(last_show, flag);
	if (last_show == "pro") 
	{
		changeImages("product", CommonImgPath + "product_" + ((flag) ? "on": "off") + ".gif");
	}
	else if(last_show == "pro2") 
	{
		changeImages("support", CommonImgPath + "support_" + ((flag) ? "on": "off") + ".gif");
	}
	else if(last_show == "pro3") 
	{
		changeImages("keiji",   CommonImgPath + "keiji_" + ((flag) ? "on": "off") + ".gif");
	}
}

/******************************************************/
/* onVerupClick
/*
/*  flag:税法値
/*
/*  バージョンアップボタン押下時処理
/******************************************************/
function onVerupClick(flag)
{
		
	switch(flag)
	{
		/* 法人税 */
		case 1:
			if(HojinSelect == true)
			{
				openWindow("../verup/houjinselect.html");
			}
			else
			{
				popUpLogin(flag);
			}
		break;
		
		/* 内訳書・概況書 */
		case 2:
			if(UchiwakeSelect == true)
			{
				openWindow("../verup/uchiselect.html");
			}
			else
			{
				popUpLogin(flag);
			}
		break;
		
		/* 所得税 */
		case 3:
			if(ShotokuEnd == true)
			{
				alert("当サイトからの 所得税 平成" + TargetNendoShotoku + "年度版 バージョンアップ申込み受付は終了致しました。");
			}
			else
			{
				popUpLogin(flag);
			}
		break;
		
		/* 相続税 */
		case 4:
			if(SozokuSelect == true)
			{
				openWindow('../verup/sozokselect.html');
			}
			else
			{
				popUpLogin(flag);
			}
		break;
		
		/* 法定調書・年末調整 */
		case 5:
			if(HoteiEnd == true)
			{
				alert("当サイトからの 法定調書・年末調整 平成" + TargetNendoHotei + "年改訂版バージョンアップ申込み受付は終了致しました。");
			}
			else
			{
				popUpLogin(flag);
			}
		break;
		
		/* 消費税 */
		case 6:
			if(ShohiSelect == true)
			{
				openWindow('../verup/shohiselect.html');
			}
			else
			{
				popUpLogin(flag);
			}
		break;
		
		/* 減価償却 */
		case 7:
			if(GenkaSelect == true)
			{
				openWindow('../verup/genkaselect.html');
			}
			else
			{
				popUpLogin(flag);
			}
		break;
	
	}

}

/***********************************/
/* on_Close                        */
/* 終了処理                        */
/***********************************/
function on_Close()
{
	try
	{
		close();
	}
	catch(e)
	{
	}
}

/***********************************/
/* on_SelectChange                 */
/* オプションボタン変更時          */
/***********************************/
function on_SelectChange(ValueData)
{
	try
	{
		e_taxSelect = ValueData;
		if(document.getElementById("Next").disabled)document.getElementById("Next").disabled = false;
	}
	catch(e)
	{
	}
}

/***********************************/
/* on_ShowETax                     */
/* 次へボタン押下時                */
/***********************************/
function on_ShowETax()
{
		
	try
	{
								
		switch(e_taxSelect)
		{
			//今回初めて申し込む又
			case "1":
				if(window.opener && !window.opener.closed)
				{
					window.opener.location.href = "https://www.mahoujin.co.jp/e_tax/denshi_buy.html?Target=1";
					this.close();
				}
				else
				{
					openWindow_full("https://www.mahoujin.co.jp/e_tax/denshi_buy.html?Target=1");
					this.close();
				}
				break;
			//ライセンス追加
			case "2":
				if(window.opener && !window.opener.closed)
				{
					window.opener.location.href = "https://www.mahoujin.co.jp/e_tax/denshi_buy.html?Target=2";
					this.close();
				}
				else
				{
					openWindow_full("https://www.mahoujin.co.jp/e_tax/denshi_buy.html?Target=2");
					this.close();
				}
			break;
			case "3":
				this.location.href="e_tax_ng.html";
			break;
		}

	}
	catch(e)
	{
	}
}


