/**
 *	System Extention Object; v.0.0.8;
 */
var Util = new Object();

/** getAgentType
 *	windows: ms5_win,ms4_win,stnrd_win,nn4x_win,opera_win
 *	    mac: ms5_mac,ms4_mac,stnrd_mac,nn4x_mac,opera_mac
 *	 others: stnrd,nn4x,opera,else
 */

Util.getAgentType = function() { 
	var result = "";
	if ( window.opera ) {
		if (navigator.appVersion.indexOf("Win") != -1) result = "opera_win";
		else if (navigator.appVersion.indexOf("Mac") != -1) result = "opera_mac";
		else result = "opera";
	} else if ( document.all && document.getElementById ) {
		if (navigator.appVersion.indexOf("Win") != -1) result = "ms5_win";
		else result = "ms5_mac";
	} else if ( document.all && !document.getElementById ) {
		if (navigator.appVersion.indexOf("Win") != -1) result = "ms4_win";
		else result = "ms4_mac";
	} else if ( document.getElementById && !document.all ) {
		if (navigator.appVersion.indexOf("Win") != -1) result = "stnrd_win";
		else if (navigator.appVersion.indexOf("Mac") != -1) result = "stnrd_mac";
		else result = "stnrd";
	} else if ( document.layers ) {
		if (navigator.appVersion.indexOf("Win") != -1) result = "nn4x_win";
		else if (navigator.appVersion.indexOf("Mac") != -1) result = "nn4x_mac";
		else result = "nn4x";
	} else {
		result = "else";
	}
	(!!arguments[0])? ( (arguments[0] == result)? result = true : result = false ) : void(0) ;
	return result;
}

/** getSystemType
 *	windows:win
 *	    mac:mac
 *	 others:els
 */
Util.getPlatform = function() {
	var result = "";
	if (navigator.platform.indexOf("Win") != -1) {
		result = "win";
	} else if (navigator.platform.indexOf("Mac") != -1) {
		result = "mac";
	} else {
		result = "els";
	}
	if (!!arguments[0]) {
		result = (arguments[0] == result)? true : false;
	}
	return result;
}

/** setLinkElement
 *  export: link element
 */

Util.setLinkElement = function(rel,href) {
	var result = "";
	result = (rel=="stylesheet")? "<link rel=\"stylesheet\" type=\"text/css\"" : "<lin rel=\""+ rel +"\"";
	result = (!!href)? result +" href=\""+ href +"\" />" : "" ;
	(result!="")? document.write(result) : void(0) ;
}
Util.setStyleSheet = function(URL) {
	if (Util.getPlatform("mac")) Util.setLinkElement("stylesheet", URL) ;
}

/** setLocation
 *  getURL();
 */
Util.setLocation = function(URL,TARGET) {
	TARGET = (!!!TARGET)? "top" : TARGET ;
	if (!!URL) eval(TARGET).location = eval(TARGET).location.protocol + "//" + eval(TARGET).location.host + URL;
}
Util.getURL = function() {
	Util.setLocation(arguments[0], arguments[1]);
}

/** hasValue
 *  anytype of value
 */
Util.hasValue = function() {
	return (typeof(arguments[0]) != "undefined")? true : false ;
}

/** toString
 *  type:string
 */
Util.toString = function() {
	if (Util.hasValue(arguments[0])) {
		return (typeof(arguments[0]) == "string")? arguments[0] : ((Util.hasValue(arguments[0]))? ("" + arguments[0]) : "" ) ;
	}
}





/** getCollectionObject
 *  document.getElementById, document.all, document.layers;
 */
Util.getCollectionObject = function() {
	if (!!arguments) { //arguments : String
		if (!!document.getElementById) {
			return document.getElementById(arguments[0]);
		} else if (!!document.all) {
			return document.all(arguments[0]);
		} else if (!!document.layers) {
			if (arguments.length == 1) {
				return document.layers[arguments[0]];
			} else {
				var result = "document";
				for (var i=0;i<arguments.length;i++) {
					result = result + ".layers[" + arguments[i] + "]"
				}
				return eval(result);
			}
		}
	}
}


/** setEventReceivers
 *  onload, onUnload
 */
Util.onLoadReceivers = new Array();
Util.onUnloadReceivers = new Array();
Util.onResizeReceivers = new Array();

Util.pushOnLoadReceiver = function() {
	if (!!arguments[0]) {
		this.onLoadReceivers[this.onLoadReceivers.length] = arguments[0];
	}
}
Util.pushOnUnloadReceiver = function() {
	if (!!arguments[0]) {
		this.onUnloadReceivers[this.onUnloadReceivers.length] = arguments[0];
	}
}
Util.pushOnResizeReceiver = function() {
	if (!!arguments[0]) {
		this.onUnloadReceivers[this.onResizeReceivers.length] = arguments[0];
	}
}


/**
 *  resize-reload
 */
Util.setInitWindowSize = function() {
	if (document.layers) {
		Util.initWidth = window.innerWidth; 
		Util.initHeight = window.innerHeight; 
	}
}
Util.pushOnLoadReceiver(Util.setInitWindowSize);

/** eventReceivers;
 *  onLoad, onUnload
 */
function onLoadReceiver() {
	if (Util.onLoadReceivers.length > 0) {
		for (var i=0; i<Util.onLoadReceivers.length; i++) {
			Util.onLoadReceivers[i]();
		}
	}
}
function onUnloadReceiver() {
	if (Util.onUnloadReceivers.length > 0) {
		for (var i=0; i<Util.onUnloadReceivers.length; i++) {
			Util.onUnloadReceivers[i]();
		}
	}
}
function onResizeReceiver() {
	if (Util.onResizeReceivers.length > 0) {
		for (var i=0; i<Util.onResizeReceivers.length; i++) {
			Util.onResizeReceivers[i]();
		}
	}
}
window.onload = onLoadReceiver;
window.onunload = onUnloadReceiver;

