/*
5digistar株式会社 [ActionBrowserサービス] 
Email： support@5digistar.co.jp 
URL： http://www.5digistar.co.jp/ 

Copyright (C) 2004 5digistar Inc. All Rights Reserved.
*/
var ViewerTitle;
var tmp;
var openWnd = null;


var absolutePath = ".";
var wndViewer = absolutePath + "/dhtml/viewer.htm";
var wndFV = absolutePath + "/flash/F_viewer_standard.htm";
var xmlFile = absolutePath + "/data/main.xml";
var xmlFile0 = absolutePath + "/data/link0.xml";
var imgPath = absolutePath + "/data/images/";
var bnkImg = absolutePath + "/dhtml/default/menu/blank.gif";

function setPathValues(arg)
{
	wndViewer = arg + "/dhtml/viewer.htm";
	wndFV = arg + "/flash/F_viewer_standard.htm";
	xmlFile = arg + "/data/main.xml";
	xmlFile0 = arg + "/data/link0.xml";
	imgPath = arg + "/data/images/";
	bnkImg = arg + "/dhtml/default/menu/blank.gif";
}

function ReOpeneBook()
{     
	var vLeft = 0;
	var vWidth = 1014;
	var vHeight= 700;
	var messageBox=null;
	
	vLeft = (screen.width-1024)/2;
	
	if (navigator.appVersion.indexOf("MSIE")<0) 
	{
		alert('DHTMLビューワーはInternet Explorer 6以降のブラウザでご利用頂けます。\nマイクロソフトホームページで最新バージョンをダウンロードして下さい。');
		return;
	}
	else
	{
		var temp=navigator.appVersion.split("MSIE")
		var version=parseFloat(temp[1])
		
		if(version<6.0)
		{
			alert('DHTMLビューワーはInternet Explorer 6以降のブラウザでご利用頂けます。\nマイクロソフトホームページで最新バージョンをダウンロードして下さい。');
			return;
		}	
	}

	if(arguments[0].indexOf("http://")<0)
		absolutePath = ".";
	else
	{		
		setPathValues(arguments[0]);
		importXML();
		importLinkXML();
	}
		
	try
	{
		while(1)
		{
			if(xmlDoc.readyState != 4)
				continue;
			else
				break;
		}
		while(1)
		{
			if(xmlDoc1.readyState != 4)
				continue;
			else
				break;
		}
	}
	catch(err)
	{
		alert("Please refresh this browser.");
	}
	
	if(chkFlag != false)
	{
		if(openWnd != null) openWnd.close();
		if(detectQT() == false) 
			messageBox = "QuickTimeプラグインが必要となります。\nアップルホームページで最新バージョンをダウンロードして下さい。\n\n";
		if(detectWM()<9)
			messageBox = messageBox + "Windows Media Player 9以降が必要となります。\nマイクロソフトホームページで最新バージョンをダウンロードして下さい。\n";
		if(messageBox != null)
			alert(messageBox);
		openWnd = eval("window.open('"+wndViewer+"','Viewer','scrollbars=no,resizable=yes,width="+vWidth+",height="+vHeight+",left="+vLeft+",top=0')");
	}	
}

function openBrWindow() 
{
	eval("window.open('"+wndFV+"','Win1','scrollbars=no,resizable=yes,width=1014,height=700,left=0,top=0')");
}

function selfclose()
{
	self.opener = self;
	self.close();
}

function importXML()
{
	if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.onreadystatechange = function () 
		{			
			if (xmlDoc.readyState == 4)
				setViewerValues();
		};
 	}
	else
	{		
		return;
	}
	xmlDoc.load(xmlFile);
}

function importLinkXML()
{
	if (window.ActiveXObject)
	{
		xmlDoc1 = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc1.onreadystatechange = function () 
		{			
			if (xmlDoc1.readyState == 4)
				setLinkValues();
		};
 	}
	else return;
	
	xmlDoc1.load(xmlFile0);
}

var chkFlag = false;
var tmdId, tmdTitle, tmpAuthor, tmpPublisher, tmpIssueDate, tmpPublishDate, tmpBGM;
var tmpPageCount, tmpImageSizeRatio, tmpImagePath;
var tmpFlipDirection, tmpFlipping;
var tmpPrinting;
var tmpShowPageNum;
var tmpZooming, tmpZoomRatio;
var tmpNavigation;
var tmpPageRatioX, tmpPageRatioY;
var tmpTImageMain, tmpTImageFrame, tmpTImageTool, tmpTImageFunction, tmpTImageLink;
var tmpPageBackgroundImage;
var tmpWindowSizeWidth, tmpWindowSizeHeight;
var aPages = new Array();
var aContentList = new Array();
var aLinks = new Array();
var aMedia = new Array();

function setViewerValues()
{
	tmpId = getXML('BookCode', '',0);
	tmpTitle = getXML('BookInfo', 'title',1);
	tmpURL = getXML('BookInfo', 'url',1);	
	tmpAuthor = getXML('Author', '',0);
	tmpPublisher = getXML('Publisher', '',0);
	tmpIssueDate = getXML('IssueDate', '',0);
	tmpPublishDate = getXML('PublishDate', '',0);
	
	tmpPageCount = parseInt(getXML('ImageInfo', 'count',1),10);
	tmpImageSizeRatio = parseFloat(getXML('ImageInfo', 'ratio',1));
	tmpImagePath = getXML('ImageInfo', 'path',1);
	
	tmpFlipDirection = parseInt(getXML('Flipping', 'direction',1),10);
	tmpFlipping = (getXML('Flipping', 'enable',1)=="1")? true:false;
	
	tmpPrinting = (getXML('Printing','enable',1)=="1")? true:false;
	tmpShowPageNum = (getXML('ShowPageNum','enable',1)=="1")? true:false;
	tmpZooming = (getXML('Zooming', 'enable',1)=="1")? true:false;
	tmpZoomRatio = parseFloat(getXML('Zooming', 'ratio', 1));
	
	tmpNavigation = (getXML('Navigation','enable', 1)=="1")? true:false;
	
	tmpPageRatioX = parseInt(getXML('PageRatio', 'width', 1),10);
	tmpPageRatioY = parseInt(getXML('PageRatio', 'height', 1),10);
	
	tmpTImageMain = getXML('ToolSkin', 'path0', 1);
	tmpTImageFrame = getXML('ToolSkin', 'path1', 1);
	tmpTImageTool = getXML('ToolSkin', 'path2', 1);
	tmpTImageFunction = getXML('ToolSkin', 'path3', 1);
	tmpTImageLink = getXML('ToolSkin', 'path4', 1);
	
	tmpPageBackgroundImage = (getXML('BookInfo', 'background', 1)=="")?(tmpTImageMain + "blank.gif"):getXML('BookInfo', 'background', 1);
	tmpBGM = getXML('BookInfo', 'BGM',1);
	
	getXML('PageInfo', '', 3);
	getXML('MenuInfo', '', 4);
	
	document.title = tmpTitle;
	getTitle();
}

function getTitle()
{
	var xml = xmlDoc.getElementsByTagName('BookInfo');
	/*ViewerTitle = xml[0].getAttribute('title');0519追加*/
	
	if(ViewerTitle != "")
	{
		document.title = ViewerTitle+" :: ActionBrowser";
		/*document.getElementById('tagBookTitle').innerHTML = ViewerTitle;0519追加*/		
	}
	xml = xmlDoc.getElementsByTagName('PageInfo');
	/*var tmp = xml[0].getAttribute('path');0519追加
*/	
	if(tmp!="")
	{
		xml = xmlDoc.getElementsByTagName('ImageInfo');
		tmp = imgPath + tmp;
	}
	else if(xmlDoc.getElementsByTagName('BookInfo')[0].getAttribute('background')!="")
		tmp = xmlDoc.getElementsByTagName('BookInfo')[0].getAttribute('background');
	else
		tmp = bnkImg;
	
	//document.getElementById('coverImg').src = tmp;0519追加	
}

function getXML(argNode, argChild, argSort)
{
	var xml = xmlDoc.getElementsByTagName(argNode);

	switch(argSort)
	{
		case 0:
			try
			{
				return xml[0].firstChild.nodeValue;
			}
			catch(err)
			{
				return null;
			}		
			break;
		/*case 1:
			return (xml[0].getAttribute(argChild)==null)?" ":xml[0].getAttribute(argChild);0519追加*/
		
		/*case 2:
			return (xml[0].getElementsByTagName(argChild)[0].firstChild.nodeValue==null)?" ":xml[0].getElementsByTagName(argChild)[0].firstChild.nodeValue;0519追加*/
			
		case 3:
			for(var i=0; i < xml.length; i++)
				aPages[i] = new Array(xml[i].getAttribute('id'), (xml[i].getAttribute('left')=="")?0:xml[i].getAttribute('left'), 
					(xml[i].getAttribute('top')=="")?0:xml[i].getAttribute('top'), (xml[i].getAttribute('right')=="")?0:xml[i].getAttribute('right'), 
					(xml[i].getAttribute('bottom')=="")?0:xml[i].getAttribute('bottom'), xml[i].getAttribute('path'));
			break;
		case 4:
			for(var i=0; i < xml.length; i++)
				aContentList[i] = new Array(xml[i].getAttribute('no'), xml[i].getAttribute('title'));
			break;
		default:
			break;
	}
}

function setLinkValues()
{
	try
	{
		var xmlHyper = xmlDoc1.documentElement.childNodes.item(0).childNodes;
		var xmlMedia = xmlDoc1.documentElement.childNodes.item(1).childNodes;
				
		aLinks = getHyperLinkXML(xmlHyper);
		aMedia = getMediaLinkXML(xmlMedia);
		
		chkFlag = true;
	}
	catch(err)
	{
		//alert(xmlDoc.parseError.errorCode+":"+ xmlDoc.parseError.reason+":"+ xmlDoc.parseError.line);
		return;
	}	
}

function getHyperLinkXML(Obj)
{
	var xmlIcon, xmlWnd;
	var aCL = new Array();
	
	for(var i=0; i<Obj.length; i++)
	{
		xmlIcon = Obj.item(i).childNodes.item(1);
		xmlWnd = Obj.item(i).childNodes.item(2);
		xmlBdr = Obj.item(i).childNodes.item(0);		
		
		aCL[i] = new Array(parseInt(Obj.item(i).getAttribute('no'),10),
					parseFloat(Obj.item(i).getAttribute('left')),
					parseFloat(Obj.item(i).getAttribute('top')),
					parseFloat(Obj.item(i).getAttribute('right')),
					parseFloat(Obj.item(i).getAttribute('bottom')),
					Obj.item(i).getAttribute('url'),
					xmlIcon.getAttribute('type'),
					xmlIcon.getAttribute('text'),
					xmlWnd.getAttribute('width'),
					xmlWnd.getAttribute('height'),
					xmlWnd.getAttribute('type'),
					xmlBdr.getAttribute('type'),
					xmlBdr.getAttribute('color'));
	}
	return aCL;
}

function getMediaLinkXML(Obj)
{
	var aML = new Array();
	
	for(var i=0; i<Obj.length; i++)
		aML[i] = new Array(parseInt(Obj.item(i).getAttribute('no'),10),
					parseFloat(Obj.item(i).getAttribute('left')),
					parseFloat(Obj.item(i).getAttribute('top')),
					parseFloat(Obj.item(i).getAttribute('right')),
					parseFloat(Obj.item(i).getAttribute('bottom')),
					Obj.item(i).getAttribute('url'),
					parseInt(Obj.item(i).getAttribute('onplay')));

	return aML;
}

function detectQT()
{
	var Obj,activeXFound;
	
	try
	{
		Obj = new ActiveXObject("QuickTimeCheckObject.QuickTimeCheck.1");
		activeXFound = Obj.IsQuickTimeAvailable(0)

		return true;
	}
	catch(e)
	{
		return false;
	}
}

function detectWM()
{
	var Obj,activeXFound;
	
	try
	{
		Obj = new ActiveXObject("WMPlayer.OCX.7");
		activeXFound = Obj.versionInfo;
		activeXFound = parseInt(activeXFound.substring(0,activeXFound.indexOf('.')),10);
		return activeXFound;
	}
	catch(e)
	{
		return false;
	}	
}

if (navigator.appVersion.indexOf("MSIE")>0)
{
	importXML();
	importLinkXML();
}