﻿/*
		global.js
		Copyright(c)2007 Total Solutions, Inc.
		http://www.totalsolutions.jp
		
		This script is under BSD license.
*/

var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

var _scripts = null;

var getFlashVer = function() {
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;			
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
			var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	} else if (isIE && isWin && !isOpera ) {
		flashVer = getFlashVerIE();
	}
	return flashVer;
}
var getFlashVerIE = function() {
	var version;
	var swfObject;
	var e;
	
	try {
		swfObject = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.1" );
		version = swfObject.GetVariable("$version");
	} catch (e) {
		version = -1;
	}
	return version;
}
var getFlashMajorVer = function() {
	versionStr = getFlashVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			tempArray         = versionStr.split(" ");
			tempString        = tempArray[1];
			versionArray      = tempString.split(",");
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		return versionMajor;
	}
}
var include = function(src) {
	var reg = new RegExp('[^/]+\.js$');
	if(!src.match(reg)) return false;
	if(_scripts) {
		for (var i=0; i<_scripts.length; i++) {
			if(src == _scripts[i]) {
				alert(src);
				return true;
			}
		}
	} else {
		_scripts = new Array();
	}
	var req = null;
	var msHTTP = 'Microsoft.XMLHTTP';
	var method = 'GET';
	var dir = 'js';
	if(window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (typeof ActiveXObject != 'undefined') {
		req = new ActiveXObject(msHTTP);
	}
	req.open(method, dir +'/_' + src, false);
	req.send('');
	eval(req.responseText);
	_scripts.push(src);
	return true;			
}
var getByTag = function(id, tag) {
	var ta = document.getElementById(id);
	if(ta) return ta.getElementsByTagName(tag)
}
var getByName = function(id, tag, name) {
	var el = getByTag(id, tag);
	if(!el.length) return null;
	var ar = new Array();
	for(var i=0; i<el.length; i++) {
		if(el[i] && el[i].className == name) {
			ar.push(el[i]);
		}
	}
	return ar;
}
var getStr = function(el) {
	if(!el || !el.length) return null;
	var ar = new Array();
	for(var i=0; i<el.length; i++) {
		var str = '';
		var j = 0;
		while(el[i].childNodes[j]) {
			if(el[i].childNodes[j].nodeType == 3) {
				str += el[i].childNodes[j].nodeValue;
			}
			j++;
		}
		ar.push(str.replace(/[\n\r]/, ""));
	}
	return ar;
}
