// zoomsightlaunch.js  Version 2.4
// All rights reserved, Copyright (C)2007
// Hitachi Government & Public Corporation System Engineering, Ltd.

function loadCookie(dataname){ 
	if(dataname){
		cookieData = document.cookie + ";";
		dataname = escape(dataname);
		startPoint1 = cookieData.indexOf(dataname);
		startPoint2 = cookieData.indexOf("=", startPoint1) + 1;
		endPoint = cookieData.indexOf(";", startPoint1);
		if(startPoint2 < endPoint && startPoint1 > -1 && startPoint2 - startPoint1 == dataname.length + 1){
			cookieData = cookieData.substring(startPoint2, endPoint);
			cookieData = unescape(cookieData);
			return cookieData;
		}
	}
	return false;
}

function chkBrowser(){
	// check browser - Windows IE5.5 or IE6.0 or IE7.0
	var agent = navigator.userAgent;
	var appve = navigator.appVersion;
	var appna = navigator.appName;
	if(agent.indexOf("Win") != -1 && !(agent.indexOf("95") != -1) && !(agent.indexOf("NT 6.0") != -1)){
		if(appna  == "Microsoft Internet Explorer"){
			version = agent.substring((agent.indexOf('MSIE') + 5), (agent.indexOf('MSIE') + 8)) ;
			ver = parseFloat(version);
			if(ver >= 5.5 && ver <= 7.0){
				return true;
			}else{
				return false; // not IE5.5 or IE6.0 or 7.0
			}
		}else{
			return false; // not Internet Explorer
		}
	}else{
		return false; // not Windows
	}
}

function OpenZoomSight(){
	if(chkBrowser()){		// launch controller if browser is supported
		var IsFirstUse = false;
		var node = LaunchSettings.XMLDocument.selectSingleNode("LaunchSettings/Launch");
 		var launchType = node.attributes.getNamedItem("type").value;
		if(launchType != "FirstNavi" && launchType != "Navigate"){
			launchType = "FirstNavi";
		}
		
		if(launchType == "FirstNavi"){
			if(loadCookie("USED_ZSMD") == false){
				IsFirstUse = true;
			}else{
			    IsFirstUse = false;
			}
		}else{
		   IsFirstUse = false;
		}
		
		if(launchType == "Navigate" || IsFirstUse){	// through explanation page
			var naviPage = LaunchSettings.XMLDocument.selectSingleNode("LaunchSettings/Launch/NaviPage").text;
			document.location = naviPage; 
			return;
		}else{
			var DLPageNode = LaunchSettings.XMLDocument.selectSingleNode("LaunchSettings/Launch/InstallPath");
			var DLPage = DLPageNode.text + "bin/download.html";
			document.location = DLPage;
		}
	}else{	// not supported browser
			var naviPage = LaunchSettings.XMLDocument.selectSingleNode("LaunchSettings/Lunch/NaviPage").text;
			document.location = naviPage; 
			return;
	}
}

function writeZoomSightButton(instPath){
	if(chkBrowser()){
		if(document.getElementById("LaunchSettings") == null){
			document.write('<xml id="LaunchSettings" src="' + instPath + 'launchsetting.xml" charset="Shift_JIS"></xml>');
		}
		
		document.write('<a href="javascript:OpenZoomSight();"><img src="' + instPath + 'zoomsightlaunch.gif" alt="ズームサイト起動ボタン" border=0 /></a>');
	}else{
		document.write('<a href="' + instPath + 'html/index.html"><img src="' + instPath + 'zoomsightlaunch.gif" alt="ズームサイト起動ボタン" border=0 /></a>');
	}
}

function writeExpPageButton(){
	if(chkBrowser()){
		if(document.getElementById("LaunchSettings") == null){
			document.write('<xml id="LaunchSettings" src="../launchsetting.xml" charset="Shift_JIS"></xml>');
		}
		
		document.writeln('<h3>●下のボタンをクリックすると「ZoomSight」が起動します。</h3><div class="button" align="center"><a href="../bin/download.html"><img src="../zoomsightlaunch.gif" alt="ズームサイト起動ボタン" border="0" width="112" height="52" /></a></div>');
	}else{
		document.writeln('<div class="error"><img src="img/error.gif" width="48" height="44" align="left" alt="エラー" />お使いの環境が前提動作環境と異なる為<br>「ZoomSight」はご利用いただけません。</div>');
	}
}