//- _gel -//
function _gel(o) {
   return (document.getElementById ? document.getElementById(o) : null);
}

//- Kernel -//
var Kernel = {Version:1, DebugPane:null, ItemKeyEnum:[], Item:new Object(), State:new Object(), m_eventHash:[], IsBrowserFlash:false, IsBrowserXml:false, BrowserPlatform:"", BrowserType:"", BrowserVersion:0.0
, ScanExecute:null, ScanTimeoutId:0, ScanSet:null, DefaultScanSet:null
, Callback:function(object, method) {
	return function() {
		return object[method].apply(object, arguments);
	}
}, CollectElement:function(container, elementName, classText) {
	var elementArray = ((elementName == '*') && (container.all) ? container.all : container.getElementsByTagName(elementName));
	var collectArray = [];
	var classText = classText.replace(/\-/g, '\\-');
	var regExp = new RegExp('(^|\\s)' + classText + '(\\s|$)');
	for (var elementIndex = 0; elementIndex < elementArray.length; elementIndex++) {
		var element = elementArray[elementIndex];
		if (regExp.test(element.className) == true) {
			collectArray.push(element);
		}
	}
	return collectArray;
}, ExecuteEventPostBack:function(url, target, eventTarget, eventArgument) {
	var array = [theForm.action, theForm.target, theForm.__VIEWSTATE.value];
	theForm.action = url;
	theForm.target = target;
	theForm.__VIEWSTATE.value = '';
	__doPostBack(eventTarget, eventArgument);
	theForm.action = array[0];
	theForm.target = array[1];
	theForm.__VIEWSTATE.value = array[2];
}, Init:function() {
	Kernel.AddEvent(window, 'unload', Kernel.Dispose);
	//+ browser detection
	var appText = navigator.appVersion.toLowerCase();
	var agentText = navigator.userAgent.toLowerCase();
	Kernel.BrowserPlatform = (appText.indexOf('windows') > -1 ? 'Windows' : (agentText.indexOf('mac') > -1 ? 'Macintosh' : 'Unknown'));
	var appTextIndex;
	if ((navigator.product) && (navigator.product.toLowerCase() == 'gecko')) {
		Kernel.BrowserType = 'GKx';
	} else if (appText.indexOf('opera') > -1) {
		Kernel.BrowserType = 'Opera';
		Kernel.BrowserVersion = new Number(agentText.match(/.*opera(\s|\/)(\d+\.\d+)/)[2]);
	} else if ((appText.indexOf('safari') > -1) || (appText.indexOf('konqueror') > -1) || (appText.indexOf('omniweb') > -1)) {
		Kernel.BrowserType = 'Khtml';
	} else if ((appTextIndex = appText.indexOf('msie')) > -1) {
		Kernel.BrowserType = 'IEx';
		Kernel.BrowserVersion = parseFloat(appText.substr(appTextIndex + 5, 3));
	}
	Kernel.IsBrowserXml = ((document.contentType) && (document.contentType.indexOf('xml') > -1));	
	//+ test
//	Kernel.DetectBrowserFlash(6);
//	alert('Version: ' + Kernel.Version + '\n'
//	+ 'BrowserPlatform: ' + Kernel.BrowserPlatform + '\n'
//	+ 'BrowserType: ' + Kernel.BrowserType + '\n'
//	+ 'BrowserVersion: ' + Kernel.BrowserVersion + '\n'
//	+ 'IsBrowserXml: ' + Kernel.IsBrowserXml + '\n'
//	+ 'IsBrowserFlash: ' + Kernel.IsBrowserFlash + '\n');
}, Write:function(text) {
	document.write(text);
}, Dispose:function() {
	//+ manually delete all events
	if (Kernel.ItemKeyEnum != undefined) {
		for (var itemKey = 0; itemKey < Kernel.ItemKeyEnum.length; itemKey++) {
			var o = Kernel.Item[Kernel.ItemKeyEnum[itemKey]]; o = null;
		}
	}
	if (Kernel.m_eventHash != undefined) {
		for (var eventKey = 0; eventKey < Kernel.m_eventHash.length; eventKey++) {
		   Kernel.RemoveEvent.apply(Kernel, Kernel.m_eventHash[eventKey]);
		   Kernel.m_eventHash[eventKey][0] = null;
		}
		Kernel.m_eventHash = null;
	}
}, DetectBrowserFlash:function(minVersion) {
	if (document.IsDetectBrowserFlash == true) {
		return;
	}
	document.IsDetectBrowserFlash = true;
	if ((Kernel.BrowserType == 'IEx') && (Kernel.BrowserPlatform = 'Windows')) {
		document.write('<script type="text/vbscript">\n');
		document.write('on error resume next\n');
		document.write('Kernel.IsBrowserFlash = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & ' + minVersion + '))\n'); 
		document.write('<' + '/script\>\n');
	}
	if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {
		var description = (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description;
		var version = parseInt(description.charAt(description.indexOf(".") - 1));
		Kernel.IsBrowserFlash = (version >= minVersion);
	}
}, CreateElement:function(tagName) {
	//+ opera and mozilla require a namespace when creating elements in an xml page
	if ((!document.createElementNS) || (Kernel.BrowserType == 'Opera')) {
		return document.createElement(tagName);
	}
	return document.createElementNS("http://www.w3.org/1999/xhtml", tagName);	
}, FixPng:function(elementIdSet) {
	var versionArray = navigator.appVersion.split("MSIE");
	var version = parseFloat(versionArray[1]);
	if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
		if (elementIdSet instanceof Array) {
			for (var elementIdIndex = 0; elementIdIndex < elementIdSet.length; elementIdIndex++) {
				Kernel.FixPng(elementIdSet[elementIdIndex]);
			}
		} else {
			var element;
			if ((element = _gel(elementIdSet)) == null) {
				return;
			}
			var className = element.className;
			element.className = (className.length > 0 ? className + ' fixPng' : 'fixPng');
			element = null;
		}
	}
}, FlipBlockDisplay:function(elementIdSet) {
	if (elementIdSet instanceof Array) {
		for (var elementIdIndex = 0; elementIdIndex < elementIdSet.length; elementIdIndex++) {
			Kernel.FlipBlockDisplay(elementIdSet[elementIdIndex]);
		}
	}
	var element;
	if ((element = _gel(elementIdSet)) == null) {
		return;
	}
	element.style.display = (element.style.display != 'none' ? 'none' : 'block');
}, InternalCalcBlockDisplay:function(showBlockHash, hideBlockHash, blockElementIdSet, elementId, expression) {
	var element = document.getElementById(elementId);
	if (element == null) {
		element = document.forms.aspnetForm.elements[elementId];
	}
	if (element == null) {
		return;
	}
	var value = ((element.type == 'checkbox') || (element.type == 'radio') ? element.checked.toString() : element.value);
	element = null;
	var isDisplay = eval(expression);
	if (blockElementIdSet instanceof Array) {
		for (var blockElementIdIndex = 0; blockElementIdIndex < blockElementIdSet.length; blockElementIdIndex++) {
			var id = blockElementIdSet[blockElementIdIndex];
			element = document.getElementById(id);
			if (element != null) {
				if (isDisplay == true) {
					if (hideBlockHash.IsExist(id) == true) {
						hideBlockHash.Remove(id);
					}
					showBlockHash.SetItem(id, element);
				} else if (showBlockHash.IsExist(id) == false) {
					hideBlockHash.SetItem(id, element);
				}
				element = null;
			} else {
				Kernel.Debug('Kernel.InternalCalcBlockDisplay - Unable to find {' + blockElementIdSet[blockElementIdIndex] + '}');
			}
		}
	} else {
		var id = blockElementIdSet;
		element = document.getElementById(id)
		if (element != null) {
			if (isDisplay == true) {
				if (hideBlockHash.IsExist(id) == true) {
					hideBlockHash.Remove(id);
				}
				showBlockHash.SetItem(id, element);
			} else if (showBlockHash.IsExist(id) == false) {
				hideBlockHash.SetItem(id, element);
			}
			element = null;
		} else {
			Kernel.Debug('Kernel.InternalCalcBlockDisplay - Unable to find {' + blockElementIdSet + '}');
		}
	}
}, SetBlockDisplay:function(elementId, array) {
	var showBlockHash = new KernelHash();
	var hideBlockHash = new KernelHash();
	for (var index = 0; index < array.length; index += 2) {
		Kernel.InternalCalcBlockDisplay(showBlockHash, hideBlockHash, array[index + 1], elementId, array[index]);
	}
	//+ hide
	for (var key in hideBlockHash.KeyEnum()) {
		hideBlockHash.GetItem(key).style.display = 'none';
	}
	hideBlockHash.Dispose(); hideBlockHash = null;
	//+ show
	for (var key in showBlockHash.KeyEnum()) {
		showBlockHash.GetItem(key).style.display = '';
	}
	showBlockHash.Dispose(); showBlockHash = null;
}, Add:function(key, o) {
	Kernel.ItemKeyEnum.push(key);
	Kernel.Item[key] = o;
}, Debug:function(text, o) {
	if (Kernel.State.IsDebugPaneCheck == undefined) {
		Kernel.State.IsDebugPaneCheck = true;
		Kernel.State.DebugPane = document.getElementById('debugPane');
		Kernel.DebugClear();
	}
	var debugPane = Kernel.State.DebugPane;
	if (debugPane != null) {
		if (o != null) {
			text += ', object: ' + typeof(o) + '<br />';
			for (attribute in o) {
				text += '<li>' + attribute + ': [' + o[attribute] + ']</li>';
			}
		}
		debugPane.innerHTML = text + '<br />' + debugPane.innerHTML;
	}
}, DebugClear:function() {
	var debugPane = Kernel.State.DebugPane;
	if (debugPane != null) {
		debugPane.innerHTML = '<div style="text-align: right"><a href="#" onclick="Kernel.DebugClear();"/>clear</a></div>';
	}
}, GetKeyCode:function(e) {
	return ((e) && (e.which) ? e.which : event.keyCode);
}, GetQueryString:function(url) {
	url = new String(url);
	var o = new Object();
	var query = url.substring(url.indexOf('?') + 1, url.length);
	var queryArray = querystring.split('&');
	for (var queryKey = 0; queryKey < queryArray.length; queryKey++){
		var pair = queryArray[queryKey].split('=');
		var name = pair[0];
		var value = pair[1];
		o[name] = value;
	}
	return o;
}, HtmlEncode:function(text) {
	if (typeof(text) != "string") {
		text = text.toString();
	}
	text = text.replace(/&/g, "&amp;");
	text = text.replace(/"/g, "&quot;");
	text = text.replace(/</g, "&lt;");
	text = text.replace(/>/g, "&gt;");
	text = text.replace(/'/g, "&#146;");
	return text;
}, IsEnterKeyCode:function(e) {
	var keyCode = Kernel.GetKeyCode(e);
	if ((keyCode == 13) || (keyCode == 3)) {
		return true;
	}
	return false;
}, GetUrl:function(url, delagate) {
	var o = null;
	if (window.ActiveXObject) {
		if ((o = new ActiveXObject("Msxml2.XMLHTTP")) == null) {
			o = new ActiveXObject("Microsoft.XMLHTTP");
		}
	} else if (window.XMLHttpRequest) {
		o = new XMLHttpRequest();
	}
	o.open("GET", url, true);
	if ((delagate != undefined) && (delagate != null)) {
		o.onreadystatechange = function() {
			if (o.readyState == 4) {
				delagate(o.responseText, o);
			}
		}
	}
	o.send(null);
}, PostUrl:function(url, data, delagate) {
	var o = null;
	if (window.ActiveXObject) {
		if ((o = new ActiveXObject("Msxml2.XMLHTTP")) == null) {
			o = new ActiveXObject("Microsoft.XMLHTTP");
		}
	} else if (window.XMLHttpRequest) {
		o = new XMLHttpRequest();
	}
	o.open("POST", url, true);
	if ((delagate != undefined) && (delagate != null)) {
		o.onreadystatechange = function() {
			if (o.readyState == 4) {
				delagate(o.responseText, o);
			}
		}
	}
	o.setRequestHeader("CONTENT-TYPE", "application/x-www-form-urlencoded");
	o.send(data);
}, ScanKeypress:function(key, scanSet) {
	if (Kernel.ScanTimeoutId > 0) {
		window.clearTimeout(Kernel.ScanTimeoutId);
	}
	if (key == undefined) {
		key = '';
	}
	if (scanSet == undefined) {
		scanSet = Kernel.DefaultScanSet;
	}
	Kernel.ScanSet = scanSet;
	Kernel.ScanTimeoutId = window.setTimeout("Kernel.ScanMethod('" + key + "')", 250);
}, ScanMethod:function(key) {
	var scanExecute = Kernel.ScanExecute;
	if (scanExecute == undefined) {
		alert('Kernel.ScanMethod is undefined.');
		return;
	}
	var scanSet = Kernel.ScanSet; //- [{Id:'ScanName',Key:'Name'}]
	if (scanSet == null) {
		scanExecute();
		return;
	}
	var url = '';
	var isEmpty = true;
	for (var scanIndex = 0; scanIndex < scanSet.length; scanIndex++) {
		var scan = scanSet[scanIndex];
		scan.Id = _gel(scan.Id);
		if ((scan.Id == undefined) || (scan.Id == null)) {
			return;
		}
		var value = scan.Id.value;
		if (value.length > 0) {
			isEmpty = false;
			url += '&' + scan.Key + '=' + encodeURIComponent(value);
		}
	}
	if (isEmpty == true) {
		scanExecute();
		return;
	}
	scanExecute(url);
}, ParseUnit:function(styleText) {
	var unit = new Object();
	unit.value = 0;
	unit.unitType = '';
	for (var key = 0; key < styleText.length; key++) {
		if (isNaN(styleText.charAt(key))) {
			unit.unitType += styleText.charAt(key);
		} else {
			unit.value = parseInt(unit.value.toString() + styleText.charAt(key));
		}
	}
	return unit;
}, PrintDocument:function() {
	var userAgent = navigator.userAgent.toLowerCase();
	if (userAgent.indexOf('mac') > 0) {
		alert('To print:\n\nUse Command + P. on your keyboard\n');
	} else {
		print();
	}
}, SetDropDropListValue:function(o, value) {
	for (var optionIndex = 0; optionIndex < o.options.length; optionIndex++) {
		if (o.options[optionIndex].value == value) {
			o.selectedIndex = optionIndex;
			return;
		}
	}
	o.selectedIndex = -1;
}, SetListValue:function(o, value, isCheckText) {
	isCheckText = (isCheckText || false);
	value = String(value).toLowerCase();
	for (var optionIndex = 0; optionIndex < o.options.length; optionIndex++) {
		if ((o.options[optionIndex].value.toLowerCase() == value) || ((isCheckText == true) && (o.options[optionIndex].text.toLowerCase() == value))) {
			o.selectedIndex = optionIndex;
			return;
		}
	}
	o.selectedIndex = -1;
}, ConvertDecToHex:function(dec) {
	return parseInt(dec).toString(16); 
}, ConvertRgbToHex:function(r, g, b) {
	return "#" + Kernel_IntToHex(r) + Kernel_IntToHex(g) + Kernel_IntToHex(b);
}, ConvertIntToHexColor:function(intColor) {
	if (!intColor) {
		return null;
	}
	intColor = intColor.toString(16).toUpperCase();
	while (intColor.length < 6) {
		intColor = "0" + intColor;
	}
	return "#" + intColor.substring(4, 6) + intColor.substring(2, 4) + intColor.substring(0, 2);
}, ConvertRgbTextToHex:function(rgbText) {
	rgbText = rgbText.toString().toLowerCase();
	if ((rgbText.indexOf("rgb(") == -1) || (rgbText.indexOf(")") == -1)) {
		return rgbText;
	}
	rgbText = rgbText.substring(rgbText.indexOf("(") + 1, rgbText.indexOf(")") - 1);
	rgb = rgbText.split(',');
	var r = rgb[0];
	var g = rgb[1];
	var b = (rgb.length == 2 ? rbg[2] : 0);
	return Kernel.ConvertRgbToHex(r, g, b);
}, ConvertIntToHex:function(dec){
	var result = (parseInt(dec).toString(16));
	if (result.length == 1) {
		result = ("0" + result);
	}
	return result.toUpperCase();
}, LoadObject:function(object, source) {
   for (var key in source) {
      object[key] = source[key];
   }
}, DumpObject:function(object) {
	var textBuilder = new Kernel.TextBuilder();
   for (var key in object) {
		textBuilder.Append(key);
		textBuilder.Append(' - ');
		textBuilder.Append(new String(object[key]).substring(0, 50));
		textBuilder.Append('\n');
   }
   return textBuilder.ToString();
}, TextBuilder:function(text) {
	this.length = 0;
	this.Append = function (text) {
		this.length += (this.TextArray[this.TextLength++] = String(text)).length;
		this.TextCache = null;
		return this;
	};
	this.Set = function(text) {
		this.TextArray = [text];
		this.TextLength = 1;
		this.length = text.length;
		return this.TextCache = text;
	}
	this.ToString = function () {
		if (this.TextCache != null) {
			return this.TextCache;
		}
		return this.Set(this.TextArray.join(''));
	};
	this.Clear = function () {
	   this.TextLength = 0;
	   this.TextArray = [];
	   this.TextCache = null;
	};
	this.TextLength = 0;
	this.TextArray = [];
	this.TextCache = null;
	if (text != null) {
		this.Append(text);
	}
} //- Event -//
, AddEventSet:function(o, eventTypeArray, fn) {
   for (var eventTypeKey = 0; eventTypeKey < eventTypeArray.length; eventTypeKey++) {
      Kernel.AddEvent(o, eventTypeArray[eventTypeKey], fn);
   }
}, AddEvent:function(o, eventType, fn) {
   if (o.addEventListener) {
      o.addEventListener(eventType, fn, true);
   } else if (o.attachEvent) {
      o.attachEvent('on' + eventType, fn);
   }
   Kernel.m_eventHash.push([o, eventType, fn]);
}, CancelEvent:function(e) {
	if (Kernel.BrowserType == 'IEx') {
		e.cancelBubble = true;
		e.returnValue = false;
	} else {
		e.preventDefault();
		e.stopPropagation();
	}
}, GetEventSource:function(e) {
	if (e == null) {
		e = window.event;
	}
	//+
	var eventSource;
	if (e.target) {
		eventSource = e.target;
	} else if (e.srcElement) {
		eventSource = e.srcElement;
	}
	//+ defeat Safari bug
	if ((eventSource != null) && (eventSource.nodeType == 3)) {
		eventSource = eventSource.parentNode;
	}
	return eventSource;
}, RemoveEvent:function(o, eventType, fn, isCapture) {
	try {
		if (o.removeEventListener) {		
			o.removeEventListener(eventType, fn, true);
	   } else if (o.detachEvent) {
		   o.detachEvent('on' + eventType, fn);
		}
   } catch (e) {
   }
} //- Timeout -//
, Timeout:{m_pendingCallHash:{}
   , AddMethod:function(key, o, method, delay, v, v2) {
	   Kernel.Timeout.ClearMethod(key);
	   var state = new Object();
	   state.Object = o;
	   state.Method = method;
	   state.V = v;
	   state.V2 = v2;
	   state.Timeout = setTimeout('Kernel.Timeout.ExecuteMethod("' + key + '");', delay);
	   Kernel.Timeout.m_pendingCallHash[key] = state;
   }, ExecuteMethod:function(key) {
      var state = Kernel.Timeout.m_pendingCallHash[key];
      if (state != null) {
         state.Object[state.Method](state.V, state.V2);
         Kernel.Timeout.ClearMethod(key);
      }
   }, ClearMethod:function(key) {
      var state = Kernel.Timeout.m_pendingCallHash[key];
      if (state != null) {
			clearTimeout(state.Timeout);
         delete Kernel.Timeout.m_pendingCallHash[key];
      }
   }
}};
//- KernelHash -//
function KernelHash() {
	var hash = new Object();
	//+ purge all attributes on object
	for (var attrib in hash) {
		delete hash[attrib];
	}
	//+ load hash
	var length = 0;
	if (arguments.length > 0) {
		if (arguments.length == 1) {
			var hash2 = arguments[0];
			for (var key in hash2.m_hash) {
				hash[key] = hash2.m_hash[key];
			}
			length = hash2.m_count;
			hash2 = null;
		} else {
			for (var argumentIndex = 0; argumentIndex < arguments.length - 1; argumentIndex += 2) {
				hash[arguments[argumentIndex]] = arguments[argumentIndex + 1];
				length++;
			}
		}
	}
	//+ initialize
	this.m_count = length;
	this.m_hash = hash;
	//+ clean-up
	hash = null;
}
KernelHash.prototype.Dispose = function() {
	this.Clear();
}
KernelHash.prototype.Clear = function() {
	for (var key in this.m_hash) {
		this.m_hash[key] = null;
		delete this.m_hash[key];
	}
	this.m_count = 0;
}
KernelHash.prototype.Count = function() {
	return this.m_count;
}
KernelHash.prototype.GetItem = function(key) {
	return this.m_hash[key];
}
KernelHash.prototype.IsExist = function(key) {
	return (typeof(this.m_hash[key]) != 'undefined' ? true : false);
}
KernelHash.prototype.KeyEnum = function() {
	return this.m_hash;
}
KernelHash.prototype.Remove = function(key) {
	if (typeof(this.m_hash[key]) != 'undefined') {
		this.m_hash[key] = null;
		delete this.m_hash[key];
		this.m_count--;
	}
}
KernelHash.prototype.SetItem = function(key, value) {
	if (typeof(this.m_hash[key]) != 'undefined') {
		this.m_hash[key] = value;
	} else {
		this.m_hash[key] = value;
		this.m_count++;
	}
}
//+ upgrades
String.prototype.normalize = function() {
	return this.replace(/\s+/g, " ");
};
if (Array.prototype.push == null) {
	Array.prototype.push = function() {
		for (var index = 0; index < arguments.length; index++){
			this[this.length] = arguments[index];
		}
		return this.length;
	};
}
if (Function.prototype.apply == null) {
	Function.prototype.apply = function(scope, args) {
		scope = (scope?scope:window);
		args = (args?args:[]);
		var sarg = [];
		for (var index = 0; index < args.length; index++) {
			sarg[index] = "args[" + index + "]";
		}
		scope.__applyTemp__ = this;
		var o = eval("scope.__applyTemp__(" + sarg.join(",") + ");");
		scope.__applyTemp__ = null;
		return o;
	};
}
//+ init
Kernel.Init();

//- InitHierarchy -//
//TODO: move into Kernel
function InitHierarchy(data, isBindOnly) {
	this.HierarchyArray = data;
		//+
	if (isBindOnly == false) {
		var currentValue = this.value;
		this.options.length = 1;
		if (data == null) {
			return;
		}
		var selectedIndex = 0;
		for (var key = 0; key < data[0].length; key += 2) {
			var newOption;
			newOption = new Option(data[0][key + 1], data[0][key], false, false);
			this.options[this.length] = newOption;
			if (currentValue == data[0][key]) {
				selectedIndex = this.options.length - 1;
			}
			newOption = null;
		}
		this.options.selectedIndex = selectedIndex;
	}
	//+
	if (this.PropagateHierarchy) {
		this.PropagateHierarchy(isBindOnly);
	}
	if (this.onhierarchyupdate) {
		this.onhierarchyupdate();
	}
}