// -*- coding: UTF-8 -*-
// meiden5.js - JavaScript
// Copyright 2005 Sofrosune. All rights reserved.
// Author: Sofrosune; www.sofrosune.net
// No part of this program may be reproduced or transmitted in any form or 
// by any means without permission from the author, Sofrosune.
//
// Date: June 18, 2005.
// Version: 1.00; June 18, 2005.
// Version: 1.10; March 8, 2007.
// Version: 1.11; July 9, 2009 (added meiden5_wmv_put)

// Usage:
/**
<head>
	<script type="text/javascript" src="../scripts/meiden5.js"></script>
	<script type="text/javascript" src="../scripts/meiden5_data.js"></script>
</head>
*/

// Constants:

// search engine
var kMEIDEN5_QUERY_FORM = '\
<form method="get" action="http://www.google.co.jp/search" target="viewSearch">\
<input type="hidden" name="ie" value="UTF-8" />\
<input type="hidden" name="oe" value="UTF-8" />\
<input type="hidden" name="hl" value="ja" />\
<input type="hidden" name="domains" value="meiden5.co.jp" />\
<input type="hidden" name="sitesearch" value="meiden5.co.jp" />\
<input type="text" name="q" size="8" maxlength="255" style="vertical-align:middle; width:120px; height:14px; font-size:12px; color:#000000; background-color:#fffff7; border:1px solid darkgray; padding:1px;" value="" /> \
<!--<input type="image" style="vertical-align:middle;" name="btnG" border="0" width="40" height="18" src="$$$rootdir$$$images/buttons/button-search-40x18.png" />-->\
<input type="submit" name="btnG" style="vertical-align:middle; height:18px; font-size:10px; color:#0000FF; background-color:#e6e6fa; border:1px solid darkgray; padding:1px;" title="$$$search$$$" value="$$$search$$$" />\
</form>\
';

var kMEIDEN5_QUERY_LABEL = "Search";

// flash object
var kFLASH_TMPL = '\
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=$$$version$$$" width="$$$width$$$" height="$$$height$$$" id="$$$id$$$" align="middle">\
<param name="allowScriptAccess" value="$$$access$$$" />\
<param name="movie" value="$$$swfpath$$$" />\
<param name="FlashVars" value="$$$flashvars$$$" />\
<param name="loop" value="$$$loop$$$" />\
<param name="quality" value="high" />\
<param name="bgcolor" value="$$$bgcolor$$$" />\
<embed src="$$$swfpath$$$" FlashVars="$$$flashvars$$$" loop="$$$loop$$$" quality="high" bgcolor="$$$bgcolor$$$" width="$$$width$$$" height="$$$height$$$" name="$$$name$$$" align="middle" allowScriptAccess="$$$access$$$" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\
</object>\
';

var gMEIDEN5_movieID = "";
var gMEIDEN5_movie = null;

var kWMV_TMPL = '\
<object id="$$$id$$$" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112" type="application/x-oleobject" width="$$$width$$$" height="$$$height$$$">\
<param name="AutoStart" value="true" />\
<param name="PlayCount" value="0" />\
<param name="AutoRewind" value="true" />\
<param name="ShowControls" value="false" />\
<param name="FileName" value="$$$path$$$" />\
<embed name="$$$name$$$" src="$$$path$$$" type="application/x-mplayer2" width="$$$width$$$" height="$$$height$$$" AutoStart="true" PlayCount="0" AutoRewind="true" ShowControls="false"> </embed>\
</object>\
';

// askform cgi path
//var kMEIDEN5_ASKFORM_PATH = "$$$rootdir$$$contact/askform.html";
var kMEIDEN5_ASKFORM_PATH = "$$$rootdir$$$contact/contact_edit_meiden5.html";
var kMEIDEN5_CONTACT_LABEL = "CONTACT";

//var kMEIDEN5_ASKFORM_FILEPATH = "../contact/contact_askform.html";
var kMEIDEN5_ASKFORM_FILEPATH = "http://www.meidensha.co.jp/pages/contact/contact_edit_meiden5_e.html";

// copyright
var kMEIDEN5_COPYRIGHT = '<span class="serif">Copyright &copy; $$$year1$$$ - $$$year2$$$ Meidensha Corporation. All Rights Reserved.</span>';

var kMEIDEN5_REFKEY = {
	"/corp03-ir/" : "/download/ir",
	"/csr/" : "/download/csr",
	"/techno_complex/" : "/download/techno",
	"/catalog/" : "/download/catalog",
	".+" : "/download/pdf"
};

// timestamp
var kMEIDEN5_TIMESTAMP = 'updated: $$$date$$$';

// rootdir
kMEIDEN5_MENU = '\
<a title="HOME" href="$$$rootdir$$$index.html">HOME</a>\
<a title="Contact Us" href="$$$rootdir$$$contact/index.html">Contact Us</a>\
';

// Variables:

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// common functions
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// meiden5_cPref
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Usage:
//	var aPref = new meiden5_cPref();
//	aPref.parse();
//	var key = aPref.key;

var gPref = new meiden5_cPref();
gPref.parse();

function meiden5_cPref() {
	this.title = "";
	this.meta = { };
	this.rootdir = ""; // Ex. "/pages-123/abc/xyz/doc.html" --> rootdir="../../../"
	this.path = "";
	this.nodes = new Array();
	this.track = [ ] ; // Ex. ["CORP01","SECT04","*"]  for this.meta.track = "CORP01:SECT04:*"
	this.section = { }; // Ex. {chap:"corp01",sect:"sect04",page:"page03"} for "corp01 sect04 page03"
	this.comet = "";

	// parse
	this.parse = function () {

		// title
		this.title = document.title.replace(/^\s+/,"").replace(/\s+$/,"");

		// path
		// Ex. "/pages-123/abc/xyz/doc.html" --> rootdir="../../../"
		this.path = path = window.location.pathname; // e3/N2
		this.path = this.path.replace(/\\/g,"/");
		this.nodes = meiden_parse_path(this.path);
		for (var k = 0; k < (this.nodes.length - 2); k++) { this.rootdir += "../"; }
		if (this.nodes[0] == "Library") { this.rootdir += "../pages/"; }
	//	window.alert(this.rootdir);

		// parse meta
		this.meta = meiden5_parse_meta();

		// parse mata.track
		// Ex. ["CORP01","SECT04",${TITLE}]  for this.meta.track = "CORP01:SECT04:*"
		var meta_track = this.meta.track;
		if ((meta_track != undefined) && (meta_track != null)) {
			meta_track = meta_track.replace(/^\s+/,"").replace(/\s+$/,"").replace(/\s*:\s*/g,":");
			this.track = meta_track.split(":");
			if ((this.track.length > 0) && (this.track[this.track.length - 1] == "*")) {
				// if the last item is "*" then replace it with title
				this.track[this.track.length - 1] = document.title;
			}
		//	window.alert("track=" + this.track.join("#"));
		}
		// parse mata.section
		// Ex. {chap:"corp01",sect:"sect04",page:"page03"} for "corp01 sect04 page03"
		var section = this.meta.section;
		if ((section != undefined) && (section != null)) {
		//	if (section.search(/((?:corp|prod|tech|info|news|misc)\d+)/) != -1) { this.section.chap = RegExp.$1; }
		//	if (section.search(/(sect\d+)/) != -1) { this.section.sect = RegExp.$1; }
		//	if (section.search(/(page\d+)/) != -1) { this.section.page = RegExp.$1; }
			if (section.search(/((?:corp|prod|tech|info|news|misc)\S+)/) != -1) { this.section.chap = RegExp.$1; }
			if (section.search(/(sect\S+)/) != -1) { this.section.sect = RegExp.$1; }
			if (section.search(/(page\S+)/) != -1) { this.section.page = RegExp.$1; }
		}
	//	var _str = ""; for (var key in this.section) { _str += key+":\""+this.section[key]+"\", "; } window.alert(_str);
		// parse mata.comet
		var comet = this.meta.comet;
		if ((comet != undefined) && (comet != null)) {
			this.comet = comet.replace(/^\s+/,"").replace(/\s+$/,"");
		}
	}

}


// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// meiden5_parse_meta
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Usage:
//	var meta = meiden5_parse_meta();  // returns { name1:value1, name2,value2, ... }
//	var track = meiden5_parse_meta().track; // returns undefined if missing.
//	var track = meiden5_parse_meta()["track"]; // returns undefined if missing.
//	if (meta.track != undefined) { title = meta.track; }

function meiden5_parse_meta() {

	var meta = {};

	// retrieve data from meta tags
	var elems = document.getElementsByTagName("meta");
//	document.writeln("count="+elems.length+"<br>");

	for (var n = 0; n < elems.length; n++) {
		var elem = elems.item(n);
		var key = elem.getAttribute("name");
		if ((key != "") && (key != null)) {
			var value = elem.getAttribute("content");
			key = key.toLowerCase();
			meta[key] = value;
		//	document.writeln("attr=["+key+" | "+value+"]<br>");
		}
	}

	return meta;
}


// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// meiden5_parse_path
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Usage:
//	var path = ".../pages-20041201/prod11/prod11-1a.html"
//	var nodes = meiden5_parse_path(path);
//	returns nodes = ["pages-20041201","prod11","prod11-1a.html"]

function meiden_parse_path(path) {

	if (path == undefined) {
	//	url = document.URL; // e3/N2
		path = window.location.pathname; // e3/N2
	//	href = window.location.href; // e3/N2
	}

	path = path.replace(/\\/g,"/");
//	path = path.replace("\\","/");
//	if (gShownavi_debug) {
//		document.writeln("path="+path+"<br />");
//	}
//	window.alert(path);

	var filename = "";
	var elems = path.split("/");
	var nodes = new Array();
	var n = elems.length;
	for (var k = 0; k < elems.length; k++) {
		var nodeStr = elems[n - k - 1];
		if (nodeStr == "") { break; }
		if (nodeStr.search(/\.(html|htm|php)$/i) != -1) {
			filename = nodeStr;
			nodes[nodes.length] = nodeStr;
			continue; }
		if (nodeStr.search(/^(?:[e]?pages[-\d]*|Library)/) != -1) {
			nodes[nodes.length] = nodeStr;
			break; }
		nodes[nodes.length] = nodeStr;
	}
	nodes.reverse();

//	if (gDebug) {
//		document.writeln("filename="+filename+"<br />");
//		document.writeln("path=["+nodes.join(" , ")+"]<br />");
//	}

	return nodes;
}


// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// meiden5_get_option
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Usage:
//	option = meiden5_get_option(obj,option);
//	var href = option.href;
//	var path = option.path;
//	var target = option.target;
//	var help = option.help;
//	var width = option.width;
//	var height = option.height;
//
//	<a onclick="func(this,{type:'image',width:128,height:96,help:'msg'});">

function meiden5_get_option(obj,option) {
	if (option == undefined) { option = { }; }

	option.href = (option.href != undefined) ? option.href : ((obj.getAttribute("href") != undefined) ? obj.getAttribute("href"): "");

	option.path = (option.path != undefined) ? option.path : ((obj.getAttribute("path") != undefined) ? obj.getAttribute("path"): "");

	option.target = (option.target != undefined) ? option.target : ((obj.getAttribute("target") != undefined) ? obj.getAttribute("target"): "");

	option.help = (option.help != undefined) ? option.help : ((obj.getAttribute("help") != undefined) ? obj.getAttribute("help"): "");
	if (option.help == "") { option.help = obj.title; }

	option.width = (option.width != undefined) ? option.width : ((obj.getAttribute("width") != undefined) ? obj.getAttribute("width"): "0");
	option.width = parseInt(option.width);

	option.height = (option.height != undefined) ? option.height : ((obj.getAttribute("height") != undefined) ? obj.getAttribute("height"): "0");
	option.height = parseInt(option.height);

	var url = (option.path != "" ? option.path : option.href );
	if (url.search(/(\d+)x(\d+)\.(jpg|png|gif|swf|html)$/i) != -1) {
		option.width = parseInt(RegExp.$1);
		option.height = parseInt(RegExp.$2);
	}

	return option;
}


// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// meiden5_query_put
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Usage:
//	<script type="text/javascript">meiden5_query_put();</script>

function meiden5_query_put() {

	var msg = kMEIDEN5_QUERY_FORM;
	msg = msg.replace(/\$\$\$search\$\$\$/g,kMEIDEN5_QUERY_LABEL);

	document.write(msg);
}


// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// meiden5_menu_put
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Usage:
//	<script type="text/javascript">meiden5_menu_put();</script>

function meiden5_menu_put() {

	var rootdir = gPref.rootdir;

	var msg = kMEIDEN5_MENU;
	msg = msg.replace(/\$\$\$rootdir\$\$\$/g,rootdir);
	document.write(msg);
}


// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// meiden5_flash_put
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Usage:
//	var swfpath = "movies/movie-320x240.swf";
//	var swfpath = undefined; // (default) taken from "#" followers of url path
//	var option = { }; // width and height can be taken from the filename
//	var option = { width:320, height:240 };
//	var option = { version:"6" }; // (default) "9"
//	var option = { id:"movie_320x240" }; // (default) taken from filename
//	var option = { flashvars:"var1=data1&var2=data2" }; // (default) ""
//	var option = { access:"always" }; // (default) "sameDomain"
//	var option = { loop:true }; // (default) false
//	var option = { bgcolor:"#000000" }; // (default) "white" or "#ffffff"
//	<script type="text/javascript">meiden5_flash_put(swfpath [,option]);</script>

function meiden5_flash_put(swfpath,option) {

	// get basename
	var basename = swfpath.replace(/\.swf$/gi,"").replace(/^.*\//,"");

	// get width and height to parse swf filename:
	// Ex. "movie-400x200-20070329.swf" will get width=400, height=200
	var width_default = 320;
	var height_default = 240;
	if (basename.search(/-(\d+)x(\d+)/i) != -1) {
		width_default = parseInt(RegExp.$1);
		height_default = parseInt(RegExp.$2);
	}

	if (option == undefined) { option = { }; }
	// make by canonical format; Ex. "movie-320x240.swf" -> "movie_320x240"
	var id = (option.id != undefined) ? option.id : basename.replace(/[%#+=-]/g,"_");
	var name = id;
	var width = (option.width != undefined) ? option.width : width_default;
	var height = (option.height != undefined) ? option.height : height_default;
	var version = (option.version != undefined) ? option.version : "9";
	var flashvars = (option.flashvars != undefined) ? option.flashvars : "";
	var access = (option.access != undefined) ? option.access : "sameDomain";
	var loop = (option.loop != undefined) ? option.loop : "false";
	var bgcolor = (option.bgcolor != undefined) ? option.bgcolor : "#ffffff";

	if (version.search(/^\d+$/) != -1) { version += ".0.0.0"; } // "9.0.0.0"

	var msg = kFLASH_TMPL;
	msg = msg.replace(/\$\$\$id\$\$\$/g,id);
	msg = msg.replace(/\$\$\$name\$\$\$/g,name);
	msg = msg.replace(/\$\$\$version\$\$\$/g,version);
	msg = msg.replace(/\$\$\$swfpath\$\$\$/g,swfpath);
	msg = msg.replace(/\$\$\$width\$\$\$/g,width);
	msg = msg.replace(/\$\$\$height\$\$\$/g,height);
	msg = msg.replace(/\$\$\$flashvars\$\$\$/g,flashvars);
	msg = msg.replace(/\$\$\$access\$\$\$/g,access);
	msg = msg.replace(/\$\$\$loop\$\$\$/g,loop);
	msg = msg.replace(/\$\$\$bgcolor\$\$\$/g,bgcolor);

	gMEIDEN5_movieID = id;

	document.write(msg);
}


// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// meiden5_get_movie
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Usage:
//	var movieID = "movie_320x240";
//	var movie = meiden5_get_movie(movieID);

function meiden5_get_movie(movieID) {

	if ((movieID == undefined) || (movieID == "")) {
		movieID = gMEIDEN5_movieID;
	}

	// get movie
	var appName = navigator.appName.toLowerCase();
	var useragent = navigator.userAgent.toLowerCase();
	var movie = null;
	//	if (useragent.indexOf("gecko") != -1) {
	//		movie = window.parent.document.embeds[0]; // For Firefox, NS6
	//	} else {
	//		movie = window.document[movieID]; // For IE, Opera
	//	}
		var movie = null;
		if (appName.indexOf("microsoft") != -1) {
			movie = window[movieID];
		} else {
			movie = window.document[movieID];
		}

	gMEIDEN5_movie = movie;

	return movie;
}


// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// meiden5_wmv_put
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Usage:
//	<script type="text/javascript">meiden5_wmv_put(PATH);</script>

function meiden5_wmv_put(path,option) {

	if (option == undefined) { option = {}; }

	var name = path.replace(/^.+\//,"");
	name = name.replace(/[%#+=-]/g,"_");
	var id = name;

	var width_default = 320;
	var height_default = 240;
	if (path.search(/-(\d+)x(\d+)/i) != -1) {
		width_default = parseInt(RegExp.$1);
		height_default = parseInt(RegExp.$2);
	}
	var width = (option.width != undefined) ? option.width : width_default;
	var height = (option.height != undefined) ? option.height : height_default;

	var msg = kWMV_TMPL;
	msg = msg.replace(/\$\$\$id\$\$\$/g,id);
	msg = msg.replace(/\$\$\$name\$\$\$/g,name);
	msg = msg.replace(/\$\$\$path\$\$\$/g,path);
	msg = msg.replace(/\$\$\$width\$\$\$/g,width);
	msg = msg.replace(/\$\$\$height\$\$\$/g,height);
	
	document.write(msg);
}

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// meiden5_openTopics
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Usage:
//	<a href="url" onclick="meiden5_openTopics(this); return false;">[CLICK]</a>

function meiden5_openTopics(obj,option) {
	option = meiden5_get_option(obj,option);

	var screenw = window.screen.width;
	var screenh = window.screen.height;
	if (screenh > 640) { screenh -= 200; }

	var href = option.href;
	var target = (option.target != "") ? option.target : "viewTopics";
	var width = (option.width != 0) ? option.width : 544;
	var height = (option.height != 0) ? option.height : screenh;

	openNewHTMLWindowScroll(href,target,width,height);
}

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// meiden5_open_askform
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Usage:
//	<a href="#" onclick="meiden5_open_askform(option); return false;">Click here!</a>
//	user - (1) "abc" (2) "abcATMARKdef" (3) "!616263"
//	if user (or decoded user) does not follow ATMARK, it will be filled by default domain.

function meiden5_open_askform(option) {

	if (option == undefined) { option = { }; }

	// setup params
	var key = (option.key != undefined) ? option.key : gPref.comet; // get meta.comet
	var user = (option.user != undefined) ? option.user : "";
	var name = gPref.track[gPref.track.length - 1]; // get last item of meta.track
	if (name.search(/\?php/,name) != -1) { name = ""; }
	if (name == kMEIDEN5_CONTACT_LABEL) { name = ""; }
//	window.alert("key="+key + " name="+name);

	// open form window
	var query = { key:key, user:user, name:name };
	meiden5_openForm(kMEIDEN5_ASKFORM_PATH,query);
}


// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// meiden5_openForm
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Usage:
//	var query = { key:"KEY", user:"USERNAME", phone:"PHONE" };
//	var url = "../contact/contact_askform.html";
//	meiden5_openForm(url,query);
//	<a href="..." onclick="meiden5_openForm(this.href); return false;">open form/a>

function meiden5_openForm(url,query) {

	if (url == undefined) { url = kMEIDEN5_ASKFORM_PATH; }
	url = url.replace(/\$\$\$rootdir\$\$\$/g,gPref.rootdir);

	// append query if not empty
	if (query == undefined) { query = {}; }
	var query_pairs= new Array();
	for (var key in query) { query_pairs.push(escape(key) + "=" + escape(query[key])); }
	if (query_pairs.length > 0) { url += "?" + query_pairs.join("&"); }
//	window.alert(url);

	var screenw = window.screen.width;
	var screenh = window.screen.height - 100;
	if (screenh <= 0) { screenh = 480; }
	if (screenh > 800) { screenh = 800; }
	var rect = "width=640,height="+screenh; // "width=640,height=640"

	var target = "viewAskForm";
	var feature = "menubar=yes,location=no,status=yes,scrollbars=yes,resizable=yes"+","+rect;
	var win = window.open(url,target,feature);
	win.moveTo(40,60);
	win.focus();
}


// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// meiden5_contactAskForm
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Usage:
//	<a onclick="return meiden_contactAskForm(key,user,fieldname);">Click !</a>
//	user - (1) "abc" (2) "abcATMARKdef" (3) "!616263"
//	if user (or decoded user) does not follow ATMARK, it will be filled by default domain.

function meiden5_contactAskForm(key,user,fieldname) {

	// param:key
	if ((key == undefined) || (key == null)) {
		key = "";
	}

	// param:user
	if ((user == undefined) || (user == null)) {
		user = "";
	}

	// param:adrs
	var adrs = "";
	if ((fieldname != undefined) && (fieldname != "")) {
		var field = eval("document."+fieldname);
		adrs = field.value;
	}

	// open form window
	meiden5_openFormWindow(key,user,"",adrs);

	return false;
}


// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// meiden5_openFormWindow
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Usage:
//	meiden5_openFormWindow(key[,user][,name][,adrs][,phone][,fax]);
//	will call mailform.html?user=user&name=name&...
//	key - a key code
//	user - a user name (optional; default is key)
//	name - a product name (optional)
//	adrs - an address (optional)
//	phone - a phone number (optional)
//	fax - a fax number (optional)

function meiden5_openFormWindow(key,user,name,adrs,phone,fax) {

	var url = kMEIDEN5_ASKFORM_FILEPATH;
	url += "?key="+escape(key);
	if ((user != undefined) && (user != "")) { url += "&user="+escape(user); }
	if ((name != undefined) && (name != "")) { url += "&name="+escape(name); }
	if ((adrs != undefined) && (adrs != "")) { url += "&adrs="+escape(adrs); }
	if ((phone != undefined) && (phone != "")) { url += "&phone="+escape(phone); }
	if ((fax != undefined) && (fax != "")) { url += "&fax="+escape(fax); }
//	url += "&debug="+escape("12 34");

	var screenw = window.screen.width;
	var screenh = window.screen.height - 100;
	if (screenh <= 0) { screenh = 480; }
	if (screenh > 800) { screenh = 800; }
	var rect = "width=640,height="+screenh; // "width=640,height=640"

	var feature = "menubar=yes,location=no,status=yes,scrollbars=yes,resizable=yes"+","+rect;
	var target = "viewAskForm";
	var win = window.open(url,target,feature);
	win.moveTo(40,60);
	win.focus();
}

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// meiden5_copyright_put
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Usage:
//	<script type="text/javascript">meiden5_copyright_put();</script>

function meiden5_copyright_put() {

	var year1 = 1996;
	var year2 = (new Date()).getYear();
	if (year2 < 2000) { year2 += 1900; }

	var msg = kMEIDEN5_COPYRIGHT;
	msg = msg.replace(/\$\$\$year1\$\$\$/g,year1).replace(/\$\$\$year2\$\$\$/g,year2);
	document.write(msg);
}

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// meiden5_attach_pageTracker
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Usage:
//	window.onload = meiden5_attach_pageTracker;
//
//	Using refkey attr: (in prod11-10-{01,02}.html, prod17-03-01.html
//	<a refkey="capa" href=".../catalog/jp/zb/zb1-3032d.pdf">Download</a>

function meiden5_attach_pageTracker() {

	var path = window.location.pathname.replace(/\\/g,"/");
	var task = "";
	if (path.search(/\/prod\d+-(.+?)\//) != -1) {
		task = RegExp.$1; // "energy","kankyo","sangyo","dynamo","itsys",...
	}

	var nodes = document.getElementsByTagName("a");
//	window.alert(nodes.length);
	for (var n = 0; n < nodes.length; n++) {
		var node = nodes.item(n);
		var href = node.href;
		if (href.search(/\.pdf$/i) != -1) {
		//	window.alert(href);
		//	node.onclick = meiden5_attach_pageTracker_callback;
			node.onclick = function () {
				var url = this.href;

				// retrieve refkey
				// first, try refkey attribute
				var refkey = "";
				if (this.refkey != undefined) { refkey = this.refkey; }
				else if (this.getAttribute("refkey") != undefined) { refkey = this.getAttribute("refkey"); }
			//	window.alert(refkey);

				// second, try path pattern if no refkey attribute
				if (refkey == "") {
					refkey = "/download/pdf";
				//	if (url.search(/\/catalog\//) != -1) { refkey = "/download/catalog"; }
				//	else if (url.search(/\/corp03-ir\//) != -1) { refkey = "/download/ir"; }
				//	else if (url.search(/\/csr\//) != -1) { refkey = "/download/csr"; }
					for (var pat in kMEIDEN5_REFKEY) {
					//	window.alert(pat);
						if (url.search(new RegExp(pat)) != -1) {
							refkey = kMEIDEN5_REFKEY[pat];
							break;
						}
					}
					// substitute download to catalog
					if (refkey.search(/\/catalog\//) != -1) {
						refkey = refkey.replace("task",task);
					}
				}
			//	window.alert("["+refkey+"]:"+url);
				pageTracker._trackPageview(refkey);
			};
		}
	}
}

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// meiden5_timestamp_put
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Usage:
//	<script type="text/javascript">meiden5_timestamp_put();</script>

function meiden5_timestamp_put() {
	var modDate = new Date(document.lastModified);
	var y = modDate.getYear(); if (y < 1900) { y += 1900; }
	var m = 1 + modDate.getMonth();
	var d = modDate.getDate();
	var th = modDate.getHours();
	var tm = modDate.getMinutes();
	var ts = modDate.getSeconds();

	var sm = "00" + m; sm = sm.substr(sm.length-2);
	var sd = "00" + d; sd = sd.substr(sd.length-2);
	var sth = "00" + th; sth = sth.substr(sth.length-2);
	var stm = "00" + tm; stm = stm.substr(stm.length-2);
	var sts = "00" + ts; sts = sts.substr(sts.length-2);

//	var ymd = y + "/" + m + "/" + d;
//	var ymd = y + "." + sm + "." + sd;
	var ymd = y + "-" + sm + "-" + sd;
	var hms = sth + ":" + stm ;
//	var datestr = ymd + " " + hms

	var msg = kMEIDEN5_TIMESTAMP;
	msg = msg.replace(/\$\$\$date\$\$\$/g,ymd);

	document.write(msg);
}

// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// meiden5_init
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Usage:
//	<body onload="meiden5_init();">
//	window.onload = meiden5_init;

function meiden5_init() {

	meiden5_attach_pageTracker();

	return;

	var path = window.location.pathname.replace(/\\/g,"/");

	// set window name for index.html
	if (path.search(/20[0-9]{2}-[0-9]{2}.*?\/index\.html$/) != -1) {
		window.name = "home";
	} else if (path.search(/20[0-9]{2}-[0-9]{2}.*?\/print-.+?\.html/) != -1) {
		window.name = "print";
	} else if (path.search(/notes\/.+?\.html/) != -1) {
		if (window.name == "") { window.name = "note"; }
	} else if (path.search(/topics\/news-.+?\.html/) != -1) {
		if (window.name == "") { window.name = "news"; }
	} else {
		window.name = "home";
	}
}


// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// main functions:
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

window.onload = meiden5_init;

// end of javascript

