//*************************************************************************//
//  ModuleName  : OpenFlashEBook.js                                        //
//                                                                         //
//  Last Update : 2006_04_13 by Sevennet                                   //
//*************************************************************************//
//*************************************************************************//
//  2007/08/22                                                             //
//  SelfOpen Update                                                        //
//*************************************************************************//
function FlashEBookOpener() {
	this.winLimitWidth				=	1024;
	this.winLimitHeight				=	725;
//---<<< Default Window Size >>>---//
	this.winWidth					=	1024;
	this.winHeight					=	725;

	this.winCustomHeight			=	0;
	this.winCustomWidth				=	0;
	this.winStyleCode				=	"0";
	this.winStyle					=	null;
	this.winStyleName				=	null;
	this.FlashEBookClient			=	null;

	this.eBookHost
	=	"http://ebook.webcatalog.jp/fb/fb.dll/getviewer?";
//	=	"http://main.sevennet.jp/fb/fb.dll/getviewer?";

	this.ParameterList
	=	new Array("bc", "co", "separate" , "viewer" , "gp", "sbp", "sep", "ui", "ct");
	this.ViewerStyleList
	=	new Array("eBookFlashDefault", "eBookFlashCustomer");

	this.OpenFBook					=	OpenFBook;
	this.GetQueryForFlash			=	GetQueryForFlash;
	this.GetWinStyleForFlash		=	GetWinStyleForFlash;
	this.funcSetWinStyleForFlash	=	funcSetWinStyleForFlash;
	this.FBookSelfOpen				=	FBookSelfOpen;
	this.sWinResize					=	sWinResize;
	this.sGetBrowserType			=	sGetBrowserType;
	this.sGetBorderSize				=	sGetBorderSize;
}


//////////////////////////////////
//                              //
//   <<< Open EBook Flash >>>   //
//                              //
//////////////////////////////////
// Parameter                    //
// [0]bc       :BookCode        //
// [1]co       :Corporate       //
// [2]separate :ShadeType       //
// [3]viewer   :ViewerName      //
// [4]gp       :GotoPage        //
// [5]sbp      :StartPage       //
// [6]sep      :EndPage         //
// [7]ui       :UserLanguage    //
// [8]ct       :
//////////////////////////////////
function OpenFBook() {
	var	sQuery		=	this.GetQueryForFlash(arguments);
	var	sFBookURL	=	this.eBookHost			+
						sQuery;

	if(!sQuery) {
		alert("service fail!!");
		return false;
	}

	this.GetWinStyleForFlash();

	this.FlashEBookClient
	=	window.open(sFBookURL,
					this.winStyleName			+
					"_"							+
					Math.round(Math.random()	*	100),
					this.winStyle);
}


/////////////////////////////////////
//                                 //
//   <<< Get Query For Flash >>>   //
//       Parameter Edit            //
//                                 //
/////////////////////////////////////
function GetQueryForFlash(arg_Param) {
	var	sParam		=	"";
	if(arg_Param.length) {
		for(var i=0;i<arg_Param.length;i++) {
			if(arg_Param[i] != "") {
// Section Confuse Error Process
				switch (this.ParameterList[i]) {
				case	"gp"	:
				case	"sbp"	:	if(arg_Param[i] % 2 != 0) {
										arg_Param[i]
										=	parseInt(arg_Param[i]) - 1;
									}
									break;
				case	"sep"	:	if(arg_Param[i] % 2 == 0) {
										arg_Param[i]
										=	parseInt(arg_Param[i]) + 1;
									}
									break;
				}
				sParam	+=	this.ParameterList[i]	+
							"="						+
							arg_Param[i]			+
							"&";
			}
		}
		sParam	+=	"ul=ja";
		return	sParam;
	}else{
		return false;
	}
}


/////////////////////////////////////////
//                                     //
//   <<< Get Win Style For Flash >>>   //
//   Window Style Set For EBookFlash   //
//                                     //
/////////////////////////////////////////
function GetWinStyleForFlash() {

	switch ( this.winStyleCode ){
	case	"0"	: // Digitomi Default window 
					this.winStyleName	=	this.ViewerStyleList[0];
					this.winTop			=	0;
					this.winLeft		=	0;
					this.winWidth		=	this.winLimitWidth;
					this.winHeight		=	this.winLimitHeight;
					break;
	case	"1"	: // corporation customer window 
					this.winStyleName	=	this.ViewerStyleList[1];
					if(this.winCustomWidth	<	this.winLimitWidth){
						this.winWidth		=	this.winLimitWidth;
					}else{
						this.winWidth		=	this.winCustomWidth;
					}
					if(this.winCustomHeight	<	this.winLimitHeight){
						this.winHeight		=	this.winLimitHeight;
					}else{
						this.winHeight		=	this.winCustomHeight;
					}
					this.winLeft
					=	(screen.width	-	this.winWidth)	/	2;
					this.winTop
					=	(screen.height	-	this.winHeight)	/	2;
					break;
	default		:	;
	}

	this.winStyle	=	"top="				+
						this.winTop			+
						", screenY="		+
						this.winTop			+
						", left="			+
						this.winLeft		+
						", screenX="		+
						this.winLeft		+
						", width="			+
						this.winWidth		+
						", height="			+
						this.winHeight		+
						", directories=no"	+
						", location=no"		+
						", menubar=no"		+
						", resizable=no"	+
						", scrollbars=no"	+
						", status=no"		+
						", toolbar=no";
}


/////////////////////////////////////////
//                                     //
//   <<< Set Win Style For Flash >>>   //
//   Window Style Code Set             //
//                For EBookFlash       //
//                                     //
/////////////////////////////////////////
function funcSetWinStyleForFlash(pWinStyleCode,pWidth,pHeight){
//---<<< Param Check >>>---//
	switch(pWinStyleCode){
	case	"0"	:	this.winStyleCode			=	pWinStyleCode;
					break;
	case	"1"	:	this.winStyleCode			=	pWinStyleCode;
					if	(pWidth		==	""){
						this.winCustomWidth		=	this.winLimitWidth;
					}else if	(isNaN(pWidth)){
						this.winCustomWidth		=	this.winLimitWidth;
					}else{
						this.winCustomWidth		=	pWidth;
					}

					if	(pHeight	==	""){
						this.winCustomHeight	=	this.winLimitHeight;
					}else if	(isNaN(pHeight)){
						this.winCustomHeight	=	this.winLimitHeight;
					}else{
						this.winCustomHeight	=	pHeight;
					}

					break;
	default		:	this.winStyleCode		=	"0";
					this.winCustomHeight	=	this.winLimitHeight;
					this.winCustomWidth		=	this.winLimitWidth;
	}
}


///////////////////////////////////////
//                                   //
//   <<< EBook Flash Self Open >>>   //
//                                   //
///////////////////////////////////////
// Parameter                         //
// [0]bc       :BookCode             //
// [1]co       :Corporate            //
// [2]separate :ShadeType            //
// [3]viewer   :ViewerName           //
// [4]gp       :GotoPage             //
// [5]sbp      :StartPage            //
// [6]sep      :EndPage              //
// [7]ui       :UserLanguage         //
// [8]ct       :
///////////////////////////////////////
function FBookSelfOpen() {
	var	iRemovePosTop	=	0;
	var	iRemovePosLeft	=	0;
	var	sQuery			=	this.GetQueryForFlash(arguments);
	var	sFBookURL		=	this.eBookHost			+
							sQuery;

	if(!sQuery) {
		alert("service fail!!");
		return false;
	}

	this.GetWinStyleForFlash();

//---<<< Window Resize >>>---//
	this.sWinResize();

//---<<< Window Move >>>---//
	if	((screen.availWidth		<=	1024)
		||
		(screen.availHeight		<=	768)){
		iRemovePosLeft		=	0;
		iRemovePosTop		=	0;
	}else{
		var iRemovePosLeft	=	(screen.availWidth	-	this.winWidth)	/	2;
		var iRemovePosTop	=	(screen.availHeight	-	this.winHeight)	/	2;
		if(iRemovePosLeft	<	0){
			iRemovePosLeft	=	0;
		}
		if(iRemovePosTop	<	0){
			iRemovePosTop	=	0;
		}
	}

	moveTo(iRemovePosLeft, iRemovePosTop);

	this.FlashEBookClient
	=	window.open(sFBookURL,"_self");

	window.name			=	this.winStyleName		+
							"_"						+
							Math.round(Math.random()	*	100);

}
///////////////////////////////
//                           //
//   <<< Window Resize >>>   //
//                           //
///////////////////////////////
function sWinResize(){
	var	iWidth			=	0;
	var	iHeight			=	0;
	var	iWidthGap		=	0;
	var	iHeightGap		=	0;
	var	sBrowserType	=	this.sGetBrowserType();

//---<<< Window Move >>>---//
	moveTo(0,0);

	if	((sBrowserType		==	'IE7')
		||
		(sBrowserType		==	'IE')){

		var	aBorderInfo	=	this.sGetBorderSize();
		iWidth			=	eval(this.winWidth)
							+	aBorderInfo[0];
		iHeight			=	eval(this.winHeight)
							+	aBorderInfo[1];

	} else {
		iWidth		=	eval((window.outerWidth
							-	window.innerWidth)
							+	this.winWidth);
		iHeight		=	eval((window.outerHeight
							-	window.innerHeight)
							+	this.winHeight);
	}

//---<<< Screen Size & Window Size Gap >>>---//
	if	((screen.availWidth		<=	1024)
		||
		(screen.availHeight		<=	768)){
		if(sBrowserType			==	'Safari'){
			iWidthGap			=	0;
			iHeightGap			=	0;
			iWidth				=	screen.availWidth;
			iHeight				=	screen.availHeight;
		}else{
			iWidthGap		=	iWidth		-	screen.availWidth;
			iHeightGap		=	iHeight		-	screen.availHeight;
		}
	}

	resizeTo(iWidth	-	iWidthGap,iHeight	-	iHeightGap);

}

//////////////////////////////////
//                              //
//   <<< Get Browser Type >>>   //
//                              //
//////////////////////////////////
// ReturnValue                  //
//   IE                         //
//   Firefox                    //
//   Opera                      //
//   NN                         //
//   Safari                     //
//   Mozilla                    //
//   Unknows                    //
//////////////////////////////////
function sGetBrowserType() {
	var	ua	=	navigator.userAgent;

	if		(ua.indexOf("Opera")		>= 0)	return	"Opera";
	else if (ua.indexOf("MSIE 7")		>= 0)	return	"IE7";
	else if (ua.indexOf("MSIE")			>= 0)	return	"IE";
	else if (ua.indexOf("Netscape")		>= 0)	return	"NN";
	else if (ua.indexOf("Firefox")		>= 0)	return	"Firefox";
	else if (ua.indexOf("Safari")		>= 0)	return	"Safari";
	else if (ua.indexOf("Gecko")		>= 0)	return	"Mozilla";
	else if (ua.indexOf("Mozilla/4")	>= 0)	return	"NN";
	else										return	"Unknown";
}


/////////////////////////////////
//                             //
//   <<< Get Border Size >>>   //
//                             //
/////////////////////////////////
function sGetBorderSize(){
	var	aBorderInfo		=	new Array();
	var	iInnerWidth		=	0;
	var	iInnerHeight	=	0;

	resizeTo(screen.availWidth,screen.availHeight);

	if	(document.compatMode	==	"CSS1Compat"){
		iInnerWidth		=	document.documentElement.clientWidth;
		iInnerHeight	=	document.documentElement.clientHeight;
	}else{
		iInnerWidth		=	document.body.clientWidth;
		iInnerHeight	=	document.body.clientHeight;
	}

	aBorderInfo[0]		=	screen.availWidth
							-	iInnerWidth;
	aBorderInfo[1]		=	screen.availHeight
							-	iInnerHeight;

	return aBorderInfo;
}


OpenFlashEBook	=	new FlashEBookOpener();
