Date.prototype.dayArray        = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
Date.prototype.quoteDayArray   = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
Date.prototype.monthArray      = ["January","February","March","April","May","June","July","August","September","October","November","December"];
Date.prototype.quoteMonthArray = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
Date.prototype.short_format    = '';
Date.prototype.long_format     = '';

Date.prototype.getMonthText = function(quote)
{
	return quote ? this.quoteMonthArray[this.getMonth()] : this.monthArray[this.getMonth()];
};

Date.prototype.getDayText = function(quote)
{
	return quote ? this.quoteDayArray[this.getDay()] : this.dayArray[this.getDay()];
};

Date.prototype.getFullUnit = function(func, increase )
{
	var buff = parseInt(this[func]());
	
	increase = parseInt(increase);
	
	if( ! isNaN(increase) )
	{
		buff += increase;
	}
	
	return buff < 10 ? '0' + buff : buff;
};

Date.prototype.getMeridiem = function(lower)
{
	return (this.getHours() > 11 ? 'pm' : 'am')[lower ? 'toLowerCase' : 'toUpperCase' ]();
};

Date.prototype.get12Hours = function()
{
	return this.getHours() > 12 ? this.getHours() - 12 : this.getHours();
};

Date.prototype.parse = function(format)
{
	if( typeof format != 'string' || format == '' )
	{
		format = format ? this.long_format : this.short_format;
	}
	
	format = format.split('');
	
	for( var x = 0; x < format.length; x ++ )
	{
		switch(format[x])
		{
			case 'l':
				format[x] = this.getDayText();
				break;
			case 'D':
				format[x] = this.getDayText(true);
				break;
			case 'd':
				format[x] = this.getFullUnit('getDate');
				break;
			case 'm':
				format[x] = this.getFullUnit('getMonth', 1 );
				break;
			case 'F':
				format[x] = this.getMonthText();
				break;
			case 'M':
				format[x] = this.getMonthText(true);
				break;
			case 'Y':
				format[x] = this.getFullYear();
				break;
			case 'y':
				format[x] = (this.getFullYear() + '').substring(2);
				break;
			case 'h':
				format[x] = this.getFullUnit('get12Hours');
				break;
			case 'H':
				format[x] = this.getFullUnit('getHours');
				break;
			case 'g':
				format[x] = this.get12Hours();
				break;
			case 'G':
				format[x] = this.getHours();
				break;
			case 'i':
				format[x] = this.getFullUnit('getMinutes');
				break;
			case 'A':
				format[x] = this.getMeridiem();
				break;
		}
	}
			
	return format.join('');
};

var sns = {
	ready     : false,
	ua_vers   : null,
	uagent    : null,
	is_safari : null,
	is_ie     : null,
	is_ie4    : null,
	is_moz    : null,
	is_ns     : null,
	is_ns4    : null,
	is_opera  : null,
	is_kon    : null,
	is_webtv  : null,
	is_win    : null,
	is_mac    : null,
	
	timezone  : 0,
	
	WINLOADED : false,
	
	SNSSID    : null,
	HTML       : {},
	lang      : {},
	base_url  : null,
	res_web_server  : null,
	res_root_server : null,
	
	URLParams  : {},
	
	/**
	 * Initialize function
	 */
	
	init : function()
	{		
		sns.ua_vers   = parseInt(navigator.appVersion);
		sns.uagent    = navigator.userAgent.toLowerCase();
		sns.is_opera  = sns.uagent.indexOf('opera') != -1;
		sns.is_kon    = sns.uagent.indexOf('konqueror') != -1;
		sns.is_webtv  = sns.uagent.indexOf('webtv') != -1;
		sns.is_moz    = navigator.product == 'Gecko';
		sns.is_win    = sns.uagent.indexOf('win') != -1 || sns.uagent.indexOf('16bit') !=- 1;
		sns.is_mac    = sns.uagent.indexOf('mac') != -1 || navigator.vendor == 'Apple Computer, Inc.';
		sns.is_safari = sns.uagent.indexOf('safari') != -1 || navigator.vendor == 'Apple Computer, Inc.';
		sns.is_ie     = sns.uagent.indexOf('msie') != -1 && ! sns.is_opera && ! sns.is_safari && ! sns.is_webtv;
		sns.is_ie4    = sns.is_ie && sns.uagent.indexOf('msie 4.') != -1;
		sns.is_ns     = sns.uagent.indexOf('compatible') == -1 && sns.uagent.indexOf('mozilla') != -1 && ! sns.is_opera && ! sns.is_webtv && ! sns.is_safari;
		sns.is_ns4    = sns.is_ns && parseInt(navigator.appVersion) == 4;
		
		sns.addLoadEvent(function(){ sns.WINLOADED = 1; } );

		sns.getURLParams();
	},
	
	getURLParams : function()
	{
		if( document.location.href.indexOf('?') == -1 )
		{
			return false;
		}

		varArray = document.location.href.split('?')[1].split('&');

		for(var x = 0; x < varArray.length; x ++ )
		{
			var tmp = varArray[x].split('=');
			sns.URLParams[unescape(tmp[0])] = unescape(tmp[1]);
		}
	},

	checkWinLoaded : function(p)
	{
		return sns.WINLOADED;
	},

	errorHandle : function(msg,url,l)
	{
		txt = "There was an error on this page.\n\n";
		txt+= "Error: " + msg + "\n";
		txt+= "URL: " + url + "\n";
		txt+= "Line: " + l + "\n\n";
		txt+= "Click OK to continue.\n\n";
		
		alert(txt);

		return true;
	},

	/**
	 * Add action to window.onload EVENT
	 */

	addLoadEvent : function(fn)
	{
		if( sns.WINLOADED )
		{
			fn();
			return;
		}
	
		if( typeof window.addEventListener != "undefined" )
		{
			window.addEventListener("load", fn, false);
		}
		else if( typeof document.addEventListener != "undefined" )
		{
			document.addEventListener("load", fn, false);
		}
		else if( typeof window.attachEvent != "undefined" )
		{
			sns.addListener(window, "onload", fn);
		}
		else if( typeof window.onload == "function" )
		{
			var fnOld = window.onload;
	
			window.onload = function()
			{
				fnOld();
				fn();
			};
		}
		else
		{
			window.onload = fn;
		}
	},
	
	/**
	 * Add action to a event
	 */

	addEvent : function(obj, evt, handler, bindObj )
	{
		handler = handler.charAt ? Function(handler) : handler;
		
		obj = obj.charAt ? sns.get_obj(obj) : obj;
		
		/*
		if( typeof obj.addEventListener != "undefined" )
		{
			obj.addEventListener(evt, handler, false);
			return true;
		}
		else if( typeof obj.attachEvent != "undefined" )
		{
			this.addListener(obj, "on" + evt, handler );
			return true;
		}*/
		
		if( typeof obj.handlers == 'undefined' )
		{
			obj.handlers = new Array();
			obj.bindObjs = new Array();
		}
		
		if( typeof obj.handlers[evt] == 'undefined'  )
		{
			obj.handlers[evt] = new Array();
			obj.bindObjs[evt] = new Array();
			
			if( typeof obj["on" + evt ] == 'function' )
			{
				obj.handlers[evt].unshift(obj["on" + evt ]);
				obj.bindObjs[evt].unshift(null);
			}
			
			obj["on" + evt] = function(e)
							  {
								  for( var i = 0; i < this.handlers[evt].length; i ++ )
								  {
									  this.handlers[evt][i](e, this.bindObjs[evt][i] );
								  }
								  
								  return false;
							  };
		}			
			
		obj.handlers[evt].unshift(handler);
		obj.bindObjs[evt].unshift(bindObj);
	},
	
	/**
	 * Add function to event
	 */

	addListener : function(target, eventType, fn)
	{
		target.attachEvent(eventType, fn);
	},
	
	/**
	 * Get DOM Element by ID
	 */
	
	get_obj : function(id, doc )
	{
		if( ! doc )
		{
			doc = document;
		}
		
		itm = null;

		if( doc.getElementById )
		{
			itm = doc.getElementById(id);
		}
		else if( doc.all )
		{
			itm = doc.all[id];
		}
		else if( doc.layers )
		{
			itm = doc.layers[id];
		}

		return itm;
	},
	
	get_obj_x_pos : function(obj)
	{
		var curleft = 0;

		if( obj.offsetParent )
		{
			while( obj.offsetParent )
			{
				curleft += obj.offsetLeft;
				obj      = obj.offsetParent;
			}
		}
		else if( obj.x )
		{
			curleft += obj.x;
		}

		return curleft;
	},

	get_obj_y_pos : function ( obj )
	{
		var curtop = 0;

		if( obj.offsetParent )
		{
			while( obj.offsetParent )
			{
				curtop += obj.offsetTop;
				obj     = obj.offsetParent;
			}
		}
		else if( obj.y )
		{
			curtop += obj.y;
		}

		return curtop;
	},
	
	menu : {		
		init : function(id, CSSClass, delayTime, isVert, width, divergent )
		{
			if( typeof SNSMenu == 'undefined' )
			{			
				if( typeof sns.menu.reInit == 'undefined' )
				{
					sns.menu.reInit = new Array();
				}
				
				sns.menu.reInit.push({id : id, CSSClass : CSSClass, delayTime : delayTime, isVert : isVert, width : width, divergent : divergent } );
				
				if( ! sns.menu.JSLoading )
				{
					sns.importJS(sns.res_root_server + '/js/global/menu.sns.js');
					
					sns.menu.JSLoading = true;
				}
				
				return false;
			}
			
			SNSMenu.createInstance(id, CSSClass, delayTime, isVert, width, divergent );
			
			return true;
		}
	},
		
	mLib : {
		init : function(config)
		{
			if( typeof SNSMLib == 'undefined' )
			{			
				if( typeof sns.mLib.reInit == 'undefined' )
				{
					sns.mLib.reInit = new Array();
				}
				
				sns.mLib.reInit.push(config);
				
				if( ! sns.mLib.JSLoading )
				{
					sns.importJS(sns.res_root_server + '/js/global/mediaLibrary.sns.js');
					
					sns.mLib.JSLoading = true;
				}
				
				return false;
			}
			
			SNSMLib.set(config);
			
			return true;
		}
	},
    
	toggleMenu : {		
		init : function(config)
		{
			if( typeof SNSToggleMenu == 'undefined' )
			{			
				if( typeof sns.toggleMenu.reInit == 'undefined' )
				{
					sns.toggleMenu.reInit = [];
				}
				
				sns.toggleMenu.reInit.push(config);
				
				if( ! sns.toggleMenu.JSLoading )
				{
					sns.importJS(sns.res_root_server + '/js/global/toggleMenu.sns.js');
					
					sns.toggleMenu.JSLoading = true;
				}
				
				return false;
			}
			
			SNSToggleMenu.createInstance(config);
			
			return true;
		}
	},
	
	dragger : {
		init : function(config)
		{
			if( typeof SNSDragger == 'undefined' )
			{			
				if( typeof sns.dragger.reInit == 'undefined' )
				{
					sns.dragger.reInit = new Array();
				}
				
				sns.dragger.reInit.push(config);
				
				if( ! sns.dragger.JSLoading )
				{
					sns.importJS(sns.res_root_server + '/js/global/dragger.sns.js');
					
					sns.dragger.JSLoading = true;
				}
				
				return false;
			}
			
			SNSDragger.createInstance(config);
			
			return true;
		}
	},
	
	cropper : {
		init : function(config)
		{
			if( typeof SNSCropper == 'undefined' )
			{			
				if( typeof sns.cropper.reInit == 'undefined' )
				{
					sns.cropper.reInit = new Array();
				}
				
				sns.cropper.reInit.push(config);
				
				if( ! sns.cropper.JSLoading )
				{
					sns.importJS(sns.res_root_server + '/js/global/cropper.sns.js');
					
					sns.cropper.JSLoading = true;
				}
				
				return false;
			}
			
			SNSCropper.createInstance(config);
			
			return true;
		}
	},
	
	tooltip : {
		init : function(obj, content, options )
		{
			if( typeof SNSToolTip == 'undefined' )
			{			
				if( typeof sns.tooltip.reInit == 'undefined' )
				{
					sns.tooltip.reInit = new Array();
				}
				
				sns.tooltip.reInit.push({obj : obj, content : content, options : options } );
				
				if( ! sns.tooltip.JSLoading )
				{
					sns.importJS(sns.res_root_server + '/js/global/tooltip.sns.js');
					
					sns.tooltip.JSLoading = true;
				}
				
				return false;
			}
			
			SNSToolTip.createInstance(obj, content, options );
			
			return true;
		}
	},
	
	popupMenu : {
		init : function(config)	
		{
			if( typeof SNSPopupMenu == 'undefined' )
			{			
				if( typeof sns.popupMenu.reInit == 'undefined' )
				{
					sns.popupMenu.reInit = new Array();
				}
				
				sns.popupMenu.reInit.push(config);
				
				if( ! sns.popupMenu.JSLoading )
				{
					sns.importJS(sns.res_root_server + '/js/global/popupMenu.sns.js');
					
					sns.popupMenu.JSLoading = true;
				}
				
				return false;
			}
			
			SNSPopupMenu.createInstance(config);
			
			return true;
		}
	},
	
	popupContent : {
		init : function(config)
		{
			if( typeof SNSPopupContent == 'undefined' )
			{			
				if( typeof sns.popupContent.reInit == 'undefined' )
				{
					sns.popupContent.reInit = new Array();
				}
				
				sns.popupContent.reInit.push(config);
				
				if( ! sns.popupContent.JSLoading )
				{
					sns.importJS(sns.res_root_server + '/js/global/popupContent.sns.js');
					
					sns.popupContent.JSLoading = true;
				}
				
				return false;
			}
			
			SNSPopupContent.createInstance(config);
			
			return true;
		}
	},
	
	tree : {
		init : function(containerID, data, options )
		{
			if( typeof SNSTree == 'undefined' )
			{			
				if( typeof sns.tree.reInit == 'undefined' )
				{
					sns.tree.reInit = new Array();
				}
				
				sns.tree.reInit.push({containerID : containerID, data : data, options : options } );
				
				if( ! sns.tree.JSLoading )
				{
					sns.importJS(sns.res_root_server + '/js/global/tree.sns.js');
					
					sns.tree.JSLoading = true;
				}
				
				return false;
			}
			
			SNSTree.createInstance(containerID, data, options );
			
			return true;
		}
	},
	
	chkSecCode : function(secCode)
	{
		secCode = sns.cleanSecCode(secCode);
		
		if( secCode == '' || secCode.length != 5 )
		{
			return false;
		}
		
		return true;
	},
	
	cleanSecCode : function(secCode)
	{
		return secCode.replace(/[^a-zA-Z]/g, '' ).toUpperCase();		
	},
	
	chkVal : function(val, chkIntMin )
	{
		return typeof val != 'undefined' && val != null && val !== '' && ( typeof chkIntMin != 'undefined' ? val >= chkIntMin : true );
	},
	
	chkXMLNodeVal : function(node, skipChkLen )
	{
		if( ! skipChkLen )
		{
			if( node.length != 1 )
			{
				return false;
			}
			
			node = node[0];
		}
		
		return node.firstChild != null && node.firstChild.nodeValue != '';
	},
	
	getXMLNodeVal : function(node, nullVal, skipChkLen )
	{		
		if( ! skipChkLen )
		{
			if( node.length != 1 )
			{
				return false;
			}
			
			node = node[0];
		}
		
		return sns.chkXMLNodeVal(node, true ) ? node.firstChild.nodeValue : nullVal;
	},
	
	getXMLAttrs : function(XMLNode)
	{
		var attrs = {};
		
		for( var i = 0; i < XMLNode.attributes.length; i ++ )	
	    {
	        attrs[XMLNode.attributes[i].name] = XMLNode.attributes[i].value;
	    }
		
		return attrs;
	},
	
	digitGrouping : function(data)
	{
		data = String(data);
		data = data.split('.');
		
		if( data.length > 2 )
		{
			return false;
		}
		
		var dataFormated = new Array();
		
		for( var i in data )
		{
			var counter = data[i].length;
			
			dataFormated[i] = '';
			
			while( counter > 3 )
			{
				counter -= 3;
				dataFormated[i] = sns.digit_grouping_symbol + data[i].substr(counter, 3 ) + dataFormated[i];
			}
			
			dataFormated[i] = data[i].substr(0, counter ) + dataFormated[i];
		}
		
		dataFormated = dataFormated.join(sns.decimal_symbol);

		return dataFormated;
	},

    importJS : function(path)
	{
		if( typeof sns.js_loaded == 'undefined' )
		{
			sns.js_loaded = new Array();
		}
		
		for( var i = 0; i < sns.js_loaded.length; i ++ )
	    {
	    	if( sns.js_loaded[i] == path )
	    	{
	    		return false;
	    	}
	    }

		sns.js_loaded.push(path);
		
		sns.createElement('script', { type : 'text/javascript',
		                              src  : path }, {}, sns.get_obj('jscript').parentNode );
	},

	createElement : function( tag, attribs, styles, parent )
    {
    	var el = document.createElement(tag);

    	if(attribs){ sns.setAttribs(el, attribs ); }

    	if(styles){ sns.setStyles(el, styles ); }

    	if(parent){ parent.appendChild(el); }

    	return el;
    },

	setAttribs : function( el, attribs )
	{
		for( var x in attribs )
		{
			el[x] = attribs[x];
		}
	},

	setStyles : function( el, styles )
	{
		for( var x in styles )
		{
			try
			{
				el.style[x] = styles[x];
			}
			catch(e)
			{
				// Do nothing
			}
		}
	},

	TXT2XML : function(TXT)
	{
		try
		{
			XML = new ActiveXObject("Microsoft.XMLDOM");
			XML.async = "false";
			XML.loadXML(TXT);
		}
		catch(e)
		{
			try
			{
				parser = new DOMParser();
				XML    = parser.parseFromString(TXT, "text/xml" );
			}
			catch(e){}
		}

		return XML;
	},

	XML2TXT : function(XML)
	{
		try
		{
			TXT = XML.xml;
		}
		catch(e)
		{
			try
			{
				TXT = (new XMLSerializer()).serializeToString(XML);
			}
			catch(e){}
		}

		return TXT;
	},
	
	$with : function(obj, properties )
	{
		for( var i in properties )
		{
			try
			{
				obj[i] = properties[i];
			}
			catch(e)
			{
				alert(i + ':' + properties[i] );
			}
		}
	},
	
	markElement : function(element, sExpandoProperty )
	{
		element['MenuElem'] = 1;

		for( var x = 0, node = null; x < element.childNodes.length; x++ )
		{
			node = element.childNodes[x];

			if( node.tagName )
			{
				sns.markElement( node, sExpandoProperty );
			}
		}
	},
	
	JSON : {
		serialize : function(arr, setDoubleQuoteInKey )
		{
			var parts   = [];
		    var is_list = Object.prototype.toString.apply(arr) === '[object Array]';
	
		    for( var key in arr )
		    {
		    	var value = arr[key];
		    	
	            var str = "";            
	            
	            if ( ! is_list )
	            {
	            	if( (/[^a-zA-Z0-9_]/).test(key) || setDoubleQuoteInKey )
		            {
		            	key = '"' + sns.jsEncode(key) + '"';
		            }
	            	
	            	str = key + ':';
	            }
		    	
		        if( typeof value == "object" )
		        {
		        	str += sns.JSON.serialize(value, setDoubleQuoteInKey );
		        }
		        else if( typeof value == "number" )		        
		        {
		        	str += value; //Numbers		           
		        }
		        else if( typeof value == 'boolean' )		        
		        {		         
		        	str += value ? 'true' : 'false'; //The booleans		        
		        }		        
		        else		        
		        {		            
		        	str += '"' + sns.jsEncode(value) + '"'; //All other things		           
		        }		            
		           
		        // :TODO: Is there any more datatype we should be in the lookout for? (Functions?)
			           
		        parts.push(str);
		    }
		    
		    var json = parts.join(",");
		    
		    if( is_list )
		    {
		    	return '[' + json + ']';//Return numerical JSON
		    }
		    
		    return '{' + json + '}';//Return associative JSON
		},
	
		unserialize : function(s)
		{
			try
			{
				return eval('(' + s + ')');
			}
			catch(ex)
			{
				// Ignore
			}
		}
	},
	
	jsEncode : function(s)
	{
		s = s.replace(new RegExp('\\\\', 'g'), '\\\\');
		s = s.replace(new RegExp('"', 'g'), '\\"');
		s = s.replace(new RegExp("'", 'g'), "\\'");

		return s;
	},
	
	substr_count : function(haystack, needle )
	{
		var count = 0;

		/*
		while( i < haystack.length )
		{
			if( needle == haystack.substr(i,needle.length) )
			{
				count ++;
				i += needle.length;
			}
			else
			{
				i ++;
			}
		}*/
		
		count = haystack.split(needle).length - 1;
		
		return count;
	},
	
	trim : function(str)
	{		
		//return ( str + '' ).replace(/^\s+|\s+$/g, '');
		
		str = str.split('\n');
		
		for( var x = 0; x < str.length; x ++ )
		{
			str[x] = str[x].replace(/^\s+|\s+$/g, '');
			str[x] = str[x].replace(/\s{2,}/g, ' ');
		}
		
		return str.join('\n');
	},
	
	strip_tags : function(txt)
	{
		return txt.replace(/<\S[^><]*>/g, "" );
	},

	displayLoadingForm : function(message, skipDisable )
	{
		if( ! skipDisable )
		{
			sns.disablePage();
		}

		message  = ! message ? 'Please wait for loading' : message;

		sns.get_obj('loading-message').innerHTML = message + '...';

		var obj = sns.get_obj('loading');
		obj.style.display = '';
		sns.move_to_center(obj);
	},

	hideLoadingForm : function(skipAvailable)
	{
		sns.get_obj('loading').style.display = 'none';
				
		if( ! skipAvailable )
		{
			sns.availablePage();
		}
	},

	disablePage : function()
	{
		var obj = sns.get_obj('disable');

		if( obj.style.display != '' )
		{
			obj.style.display = '';
			var documentSize = sns.getDocumentSize();
			obj.style.width = documentSize.w + 'px';
			obj.style.height = documentSize.h + 'px';
		}
	},

	availablePage : function()
	{
		sns.get_obj('disable').style.display     = 'none';
	},

	getDocumentSize : function()
	{
		var mode = document.compatMode;

		var browseSize = sns.getBrowseSize();

		return { w : Math.max( ( mode != 'CSS1Compat' ) ? document.body.scrollWidth : document.documentElement.scrollWidth, browseSize.w ),
		         h : Math.max( ( mode != 'CSS1Compat' ) ? document.body.scrollHeight : document.documentElement.scrollHeight, browseSize.h ) };
	},

	getBrowseSize : function()
	{
		var size = { w : self.innerWidth,
		             h : self.innerHeight };

		var mode = document.compatMode;

		if ( ( mode || sns.is_ie ) && ! sns.is_opera )
		{
			size.w = ( mode == 'CSS1Compat' ) ? document.documentElement.clientWidth : document.body.clientWidth;
			size.h = ( mode == 'CSS1Compat' ) ? document.documentElement.clientHeight : document.body.clientHeight;
		}

		return size;
	},

	getMousePosition : function(e)
	{
		e = e || window.event;

		var cursor = { x : 0, y : 0 };

		if( e.pageX || e.pageY )
		{
			cursor.x = e.pageX;
			cursor.y = e.pageY;
		}
		else
		{
			var iebody = (document.compatMode == 'CSS1Compat') ? document.documentElement : document.body;

			cursor.x = e.clientX + iebody.scrollLeft - iebody.clientLeft;
			cursor.y = e.clientY + iebody.scrollTop  - iebody.clientTop;
		}

		return cursor;
	},
	
	getViewPort : function(win)
	{
		if( ! win )
		{
			win = window;
		}
		
		var CSS1Mode = window.document.compatMode == 'CSS1Compat';
		
		return {
					x : win.pageXOffset || ( CSS1Mode ? win.document.documentElement.scrollLeft   : win.document.body.scrollLeft   ),
					y : win.pageYOffset || ( CSS1Mode ? win.document.documentElement.scrollTop    : win.document.body.scrollTop    ),
					w : win.innerWidth  || ( CSS1Mode ? win.document.documentElement.clientWidth  : win.document.body.clientWidth  ),
					h : win.innerHeight || ( CSS1Mode ? win.document.documentElement.clientHeight : win.document.body.clientHeight )
			   };
	},

	displayScene : function(data)
	{
		var obj = sns.get_obj('scene');

		sns.disablePage();

		obj.style.display = '';

		if( typeof data == 'object' )
		{
			obj.innerHTML = '';
			obj.appendChild(data);
		}
		else
		{
			obj.innerHTML = data;
			sns.execute_js(data);
		}
	},

	closeScene : function()
	{
		var obj = sns.get_obj('scene');

		sns.availablePage();

		obj.innerHTML = '';

		obj.style.display = 'none';
	},

	move_to_center : function(obj)
	{
		var iebody = document.compatMode == 'CSS1Compat' ? document.documentElement : document.body;
    	var stop   = sns.is_ie ? iebody.scrollTop   : window.pageYOffset;
    	var doch   = sns.is_ie ? iebody.clientHeight: window.innerHeight;
    	var docw   = sns.is_ie ? iebody.clientWidth : window.innerWidth;
    	var objh   = obj.offsetHeight;
    	var objw   = obj.offsetWidth;

    	x = docw/2-objw/2;
    	y = stop+doch/2-objh/2;

		if( x < 0 )
		{
			x = 0;
		}
		
		if( y < 0 )
		{
			y = 0;
		}

    	with(obj)
    	{
    		style.left  = x + 'px';
    		style.top   = y + 'px';
    	}
	},
	
	lang_build_string : function()
	{
		if ( ! arguments.length || ! arguments )
		{
			return;
		}

		var string = arguments[0];

		for( var i = 1 ; i < arguments.length ; i++ )
		{
			var match  = new RegExp('<%' + i + '>', 'mgi');
			string = string.replace( match, arguments[i] );
		}

		return string;
	},
	
	execute_js : function(source_code)
    {
    	var i             = 0;
    	var max_iteration = 50;
    	var text_blocks   = new Array();

    	while( _match = source_code.match( new RegExp( "<script\\s+?type=['\"]text/javascript['\"]>([^`]+?)</script>", "i" ) ) )
    	{
    		i ++;

    		if( i >= max_iteration )
    		{
    			break;
    		}
    		else
    		{
    			text_blocks[text_blocks.length] = _match[1];
    			source_code                     = source_code.replace( _match[0], '' );
    		}
    	}

    	try
    	{
    		if( text_blocks.length )
    		{
    			for( i = 0; i < text_blocks.length; i++ )
    			{
    				eval(text_blocks[i]);
    			}
    		}
    	}
    	catch(e)
    	{
    		//Do nothing
    	}
    },
	
	cleanVNMask : function(str)
	{
		var searchArr = [ ['á','à','ả','ạ','ã','â','ấ','ầ','ẩ','ậ','ẫ','ă','ắ','ằ','ẳ','ặ','ẵ'],
			              ['á','À','Ả','Ạ','Ã','Â','Ấ','Ầ','Ẩ','Ậ','Ẫ','Ă','Ắ','Ằ','Ẳ','Ặ','Ẵ'],
			              ['ó','ò','ỏ','ọ','õ','ô','ố','ồ','ổ','ộ','ỗ','ơ','ớ','ờ','ở','ợ','ỡ'],
						  ['Ó','Ò','Ỏ','Ọ','Õ','Ô','Ố','Ồ','Ổ','Ộ','Ỗ','Ơ','Ớ','Ờ','Ở','Ợ','Ỡ'],
						  ['é','è','ẻ','ẹ','ẽ','ê','ế','ề','ể','ệ','ễ'],
						  ['É','È','Ẻ','Ẹ','Ẽ','Ê','Ế','Ề','Ể','Ệ','Ễ'],
						  ['ú','ù','ủ','ụ','ũ','ư','ứ','ừ','ử','ự','ữ'],
						  ['Ú','Ù','Ủ','Ụ','Ũ','Ư','Ứ','Ừ','Ử','Ự','Ữ'],
						  ['í','ì','ỉ','ị','ĩ'],
			              ['í','Ì','Ỉ','Ị','Ĩ'],
			              ['ý','ỳ','ỷ','ỵ','ỹ'],
			              ['Ý','Ỳ','Ỷ','Ỵ','Ỹ'],
			              ['đ'],
			              ['Đ'] ];

		var replaceArr = ['a','A','o','O','e','E','u','U','i','I','y','Y','d','D'];

		for(var k = 0; k < searchArr.length; k ++ )
		{
			eval("str = str.replace(/(" + searchArr[k].join('|') + ")/g, replaceArr[k] );");
		}
		
		return str;
	},
	
	confirmAction : function(message, url )
	{
		var confirmVar = confirm(message);

		if( typeof url == 'undefined' )
		{
			return confirmVar;
		}

		if( confirmVar )
		{
			window.location = url;
		}
	},
	
	cloneObj : function(obj)
	{
		if(obj == null || typeof(obj) != 'object')
		{
			return obj;
		}
	
		var temp = new obj.constructor();
		
		for(var key in obj)
		{
			temp[key] = sns.cloneObj(obj[key]);
		}
	
		return temp;
	},
	
	equals : function(a,b)
	{
		for( var j,o = arguments, i = o.length, c = a instanceof Object; --i; )
		{
			if( a === ( b = o[i] ) )
			{
				continue;
			}
			else if( ! c || ! ( b instanceof Object ) )
			{
				return false;
			}
			else
			{
				for( j in b )
				{
					if( ! this.equals(a[j], b[j] ) )
					{
						return false;
					}
				}
			}
		}
				
    	return true;
	},
	
	setSelectable : function(obj, state )
	{
		if( ! sns.is_ie4 && typeof obj.tagName != 'undefined' )
		{
			if( obj.hasChildNodes() )
			{
				for( var i = 0; i < obj.childNodes.length; i++ )
				{
					sns.setSelectable(obj.childNodes[i], state );
				}
			}

			obj.unselectable = state ? 'off' : 'on';
		}
	},
	
	validEmail : function(email)
    {
    	if( email.length < 6 )
    	{
    		return false;
    	}

		if( ( /^@|^\.|[^a-zA-Z0-9_\-@\.]|\.\.|@@|--|-@|@-|-\.|\.-|\.@|@\.|\.$|@$/g ).test(email) )
		{
			return false;
		}

		if( ! ( /.+@.+\.[a-zA-Z]{2,4}/g ).test(email) )
		{
			return false;
		}

		if( email.indexOf('@') != email.lastIndexOf('@') )
		{
			return false;
		}
		
		if( email.split('@')[1].indexOf('_') != -1 )
		{
			return false;
		}

		return true;
    },
    
    debug : function(mess)
    {
    	alert(mess);
    },
    
    doane : function(eventobj)
	{
		if( ! eventobj || this.is_ie )
		{
			window.event.returnValue  = false;
			window.event.cancelBubble = true;

			return window.event;
		}
		else
		{
			eventobj.stopPropagation();
			eventobj.preventDefault();
			return eventobj;
		}
	},
	
	findTags : function( parentobj, tag )
	{
		if( typeof parentobj.getElementsByTagName != 'undefined' )
		{
			return parentobj.getElementsByTagName(tag);
		}
		else if( parentobj.all && parentobj.all.tags )
		{
			return parentobj.all.tags(tag);
		}
		else
		{
			return null;
		}
	},
	
	strip_tags : function(txt)
	{
		return txt.replace(/<\S[^><]*>/g, "" );
	},

	htmlspecialchars : function(str)
	{
		var f = new Array(
			              this.is_mac && this.is_ie ? new RegExp('&', 'g') : new RegExp('&(?!#[0-9]+;)', 'g'),
			              new RegExp('<', 'g'),
			              new RegExp('>', 'g'),
			              new RegExp('"', 'g')
		                 );

		var r = new Array(
		                  '&amp;',
		                  '&lt;',
		                  '&gt;',
		                  '&quot;'
	                     );

		for( var i = 0; i < f.length; i++ )
		{
			str = str.replace( f[i], r[i] );
		}

		return str;
	},
	
	mb_strlen : function(str)
	{
		return ( sns.is_ie && str.indexOf('\n') != -1 ) ? str.replace(/\r?\n/g, '_').length : str.length;
	},

	str_pad : function( text, length, padstring )
	{
		text      = new String(text);
		padstring = new String(padstring);

		if( text.length < length )
		{
			padtext = new String(padstring);

			while( padtext.length < ( length - text.length ) )
			{
				padtext += padstring;
			}

			text = padtext.substr( 0, length - text.length ) + text;
		}

		return text;
	},
	
	each : function(o, cb, s)
	{
		var n, l;

		if (!o)	return 0;

		s = s || o;

		if( typeof(o.length) != 'undefined' )
		{
			for( n = 0, l = o.length; n < l; n ++ )
			{
				if( cb.call(s, o[n], n, o ) === false )
				{
					return 0;
				}
			}
		}
		else
		{
			for( n in o )
			{
				if( o.hasOwnProperty(n) )
				{
					if( cb.call(s, o[n], n, o ) === false )
					{
						return 0;
					}
				}
			}
		}

		return 1;
	},
	
	round : function( num , dec )
    {
		if( typeof dec == 'undefined' )
		{
			dec = 0
		}
		else
		{
			dec = Math.floor(dec);
		}

		if( isNaN( num + dec ) || dec < 0 || dec > 12 )
		{
			return Math.round(num);
		}

		var n = Math.pow( 10, dec );

		return Math.round( num * n ) / n;
	},
	
	parseStyle : function(st)
	{
		var o = {};

		if( ! st )
		{
			return o;
		}
		
		function compress(p, s, ot)
		{
			var t, r, b, l;

			t = o[p + '-top' + s];
			
			if( ! t ) return;

			r = o[p + '-right' + s];
			
			if( t != r )	return;

			b = o[p + '-bottom' + s];
			
			if( r != b )	return;

			l = o[p + '-left' + s];
			
			if( b != l ) return;

			o[ot] = l;
			
			delete o[p + '-top' + s];
			delete o[p + '-right' + s];
			delete o[p + '-bottom' + s];
			delete o[p + '-left' + s];
		}

		function compress2(ta, a, b, c)
		{
			var t;

			t = o[a];
			
			if( ! t ) return;

			t = o[b];
			
			if( ! t ) return;

			t = o[c];
		
			if( ! t ) return;

			o[ta] = o[a] + ' ' + o[b] + ' ' + o[c];
			
			delete o[a];
			delete o[b];
			delete o[c];
		};

		st = st.replace(/&(#?[a-z0-9]+);/g, '&$1_MCE_SEMI_'); // Protect entities

		sns.each(st.split(';'), function(v)
		{
			var sv, ur = [];

			if(v)
			{
				v = v.replace(/_MCE_SEMI_/g, ';'); // Restore entities
				v = v.replace(/url\([^\)]+\)/g, function(v){ ur.push(v); return 'url(' + ur.length + ')' } );
				v = v.split(':');
				sv = sns.trim(v[1]);
				sv = sv.replace(/url\(([^\)]+)\)/g, function(a, b){ return ur[parseInt(b) - 1] } );

				sv = sv.replace(/(rgb\([^\)]+\))/g, function(a,b)
				{
					return sns.rgbToColor(b);
				});

				o[sns.trim(v[0]).toLowerCase()] = sv;
			}
		});

		compress("border", "", "border");
		compress("border", "-width", "border-width");
		compress("border", "-color", "border-color");
		compress("border", "-style", "border-style");
		compress("padding", "", "padding");
		compress("margin", "", "margin");
		compress2('border', 'border-width', 'border-style', 'border-color');

		if( sns.is_ie )
		{
			if( o.border == 'medium none' )
			{
				o.border = '';
			}
		}

		return o;
	},
	
	serializeStyle : function(o)
	{
		var s = '';

		sns.each(o, function(v, k)
		{
			if (k && v)
			{
				if ( sns.is_moz && k.indexOf('-moz-') === 0) return;

				switch(k)
				{
					case 'color':
					case 'background-color':
						v = v.toLowerCase();
						break;
				}

				s += (s ? ' ' : '') + k + ': ' + v + ';';
			}
		});

		return s;
	},
	
	rgbToColor : function(forecolor)
	{
		if( forecolor == '' || forecolor == null )
		{
			return '';
		}
		
		var matches = forecolor.match(/^rgb\s*\(([0-9]+),\s*([0-9]+),\s*([0-9]+)\)$/i);

		if(matches)
		{
			return sns.rgbhexToColor( ( matches[1] & 0xFF ).toString(16), ( matches[2] & 0xFF ).toString(16), ( matches[3] & 0xFF ).toString(16) );
		}
		else
		{
			return sns.rgbhexToColor( ( forecolor & 0xFF ).toString(16), ( (forecolor >> 8) & 0xFF ).toString(16), ( (forecolor >> 16) & 0xFF ).toString(16));
		}
	},

	rgbhexToColor : function( r, g, b )
	{
		return '#' + ( sns.str_pad( r, 2, 0 ) + sns.str_pad( g, 2, 0 ) + sns.str_pad( b, 2, 0 ) );
	},
	
	setAutoResizeIMG : function(IMGObj, mSize, callBack )
	{
		var wrapper = IMGObj.parentNode.insertBefore(sns.createElement('div'), IMGObj );
		
		wrapper.className = 'IMGAutoResizeWrapper';
		
		wrapper.style.width  = ( mSize.w | mSize.h | 100 ) + 'px';				
		wrapper.style.height = ( mSize.h | mSize.w | 100 ) + 'px';
				
		wrapper.appendChild(IMGObj);
		
		IMGObj.style.display = 'none';
				
		IMGObj.onload = function()
						{
							IMGSize = sns.calSize({ w  : this.getAttribute('width') || this.width || parseInt(this.style.width),
													h  : this.getAttribute('height') || this.height || parseInt(this.style.height),
													mw : mSize.w,
													mh : mSize.h } );
							
							this.style.width  = IMGSize.w + 'px';
							this.style.height = IMGSize.h + 'px';
							
							var wrapper    = this.parentNode;
							var parentNODE = wrapper.parentNode;
							
							parentNODE.insertBefore(this, wrapper );
							
							parentNODE.removeChild(wrapper);
							
							this.style.display = '';
							
							if( typeof callBack == 'function' )
							{
								callBack({ img : this } );
							}
						};
	},
	
	resizeIMG : function(IMGObj, mSize, isHidden )
	{
		if( isHidden )
		{
			IMGObj.style.display = '';
		}
		
		IMGSize = sns.calSize({ w : IMGObj.offsetWidth, h : IMGObj.offsetHeight, mw : mSize.w, mh : mSize.h } );
	
		IMGObj.style.width  = IMGSize.w + 'px';
		IMGObj.style.height = IMGSize.h + 'px';
	},
	
	calSize : function(params)
	{
		if( params.mw || params.mh )
		{
			if(params.mw)
			{
				if( params.mw < params.w )
				{
					params.h = ( params.h / ( params.w / params.mw ) );
					params.w = params.mw;
				}
			}

			if( params.mh )
			{
				if( params.mh < params.h )
				{
					params.w = ( params.w / ( params.h / params.mh ) );
					params.h = params.mh;
				}
			}
		}

		return { h : parseInt(params.h),
				 w : parseInt(params.w) };
	},
	
	cleanTags : function(txt, separate )
	{
		if( ! separate )
		{
			separate = ',';
		}
		
		if( typeof txt != 'string' )
		{
			return '';
		}
		
		txt = sns.cleanVNMask(txt).toLowerCase();
		txt = sns.trim(txt);

		var rx = new RegExp(separate + "{2,}", 'g' );
		
		txt = txt.replace(rx, separate );
		
		rx = new RegExp("^" + separate + "+|" + separate + "+$", 'g' );
		
		txt = txt.replace(rx, '' );
			
		if( txt != '' )
		{			
			var tags = txt.split(separate);
				
			var buff   = new Array();
			var chkTag = new Array();
				
			for( var i = 0; i < tags.length; i ++ )
			{
				tags[i] = sns.trim(tags[i]);
				
				if( tags[i] && tags[i].length > 3 && ! chkTag[tags[i]] )
				{
					buff.push(tags[i]);
					chkTag[tags[i]] = 1;
				}
			}
				
			txt = buff.join(separate);
		
			txt = txt.replace(/\s+/g, '_' );
		}
		
		return txt;
	}
};

//window.onerror = sns.errorHandle;

sns.init();

function snetser()
{
	this.CUR_MENU      = null;
	this.menu          = {};
	this.menuTimeout   = null;

	this.WINLOADED     = 0;

	this.dragger       = {};
	this.CUR_DRAGGER   = null;

	this.cropper       = {};
	this.CUR_CROPPER   = null;
	
	this.menu2           = {};
	
	this.popupMenu       = {};
	this.CUR_POPUPMENU   = null;
	
	this.popupContent    = {};
	
	this.reInit          = {};
	this.timer           = {};

	this.lang          = {};
	this.js_loaded     = new Array();
	this.JSLoading     = new Array();
	this.URLParams     = new Array();
	
	this.html          = { page : {} };

	//document.oncontextmenu =function(){ return false };
	
	this.init_menu = function( menuid, buttonid, toggle_mode, setClickToOpen, delayTime, styles, divergent, setEvent )
	{
		this.menu[buttonid] = new menu( menuid, buttonid, toggle_mode, setClickToOpen, delayTime, styles, divergent, setEvent );
	};

    this.hideMenu = function()
    {
    	this.menu[this.CUR_MENU].hideCurMenu();
    }

    this.resetMenuPosition = function()
    {
    	this.menu[this.CUR_MENU].setPosition();
    }

	this.init_cropper = function(id, callBack, ratioDim, minDim, maxDim, displayOnInit, onLoadCoords )
	{
		this.cropper[id] = null;

		this.cropper[id] = new cropper(id, callBack, ratioDim, minDim, maxDim, displayOnInit, onLoadCoords );
	}
	
	this.initPopupMenu = function(id, drawFunc )
	{
		if( typeof popupMenu != 'function' )
		{			
			if( typeof this.reInit.popupMenu == 'undefined' )
			{
				this.reInit.popupMenu = new Array();
			}
			
			this.reInit.popupMenu[this.reInit.popupMenu.length] = { id : id, drawFunc : drawFunc };
			
			if( ! this.JSLoading.popupMenu )
			{
				this.importJS('{sns.path}/js/.popupMenu.sns.js');
				
				this.JSLoading.popupMenu = true;
			}
			
			return false;
		}
		
		this.popupMenu[id] = new popupMenu(id, drawFunc );
		
		return true;
	}
	
	this.initPopupContent = function(id, eventID, width, callBack )
	{
		if( typeof SNSPopupContent != 'function' )
		{			
			if( typeof this.reInit.popupContent == 'undefined' )
			{
				this.reInit.popupContent = new Array();
			}
			
			this.reInit.popupContent[this.reInit.popupContent.length] = { id : id, eventID : eventID, width : width, callBack : callBack };
			
			if( ! this.JSLoading.popupContent )
			{
				this.importJS('{sns.path}/js/.popupContent.sns.js');
				
				this.JSLoading.popupContent = true;
			}
			
			return false;
		}
		
		this.popupContent[id] = new SNSPopupContent(id, eventID, width, callBack );
		
		return true;
	}

	this.createCheckbox = function( value, sperate, containerID, checked, disable, maxcheck, parentID, js )
	{
		if( typeof disable == 'undefined' )
		{
			disable = 0;
		}

		if( typeof checked == 'undefined' )
		{
			checked = false;
		}

		var container = this.get_obj(containerID);

		if( checked )
		{
			if( container.value == '' )
			{
				var IDs = new Array();
			}
			else
			{
				var IDs = container.value.split(sperate);
			}

		    IDs.push(value);

		    container.value = IDs.join(sperate);
		}

		if( typeof maxcheck == 'undefined' )
		{
			maxcheck = 0;
		}

		var obj = this.createElement('img',{ value        : value,
		                                     src          : "{sns.imgPath}/null.gif",
		                                     checked      : checked ? 2 : 0,
		                                     isDisable    : disable,
		                                     js           : js,
		                                     sperate      : sperate,
		                                     container    : container,
		                                     maxcheck     : maxcheck,
		                                     className    : checked ? ( disable ? 'checkbox-9' : 'checkbox-3' ) : ( disable ? 'checkbox-7' : 'checkbox-1' ),
		                                     onmouseover  : function()
		                                                    {
		                                                        if( this.isDisable ){ return };

		                                                        this.className = this.checked == 2 ? 'checkbox-6' : ( this.checked == 1 ? 'checkbox-5' : 'checkbox-4' );
		                                                    },
		                                     onmouseout   : function()
		                                                    {
		                                                        if( this.isDisable ){ return };

		                                                        this.className = this.checked == 2 ? 'checkbox-3' : ( this.checked == 1 ? 'checkbox-2' : 'checkbox-1' );
		                                                    },
		                                     onmousedown  : function()
		                                                    {
		                                                        if( this.isDisable ){ return };

		                                                        this.checked = this.checked == 0 ? 1 : 0;

		                                                        this.className = this.checked == 0 ? 'checkbox-4' : 'checkbox-5';

		                                                        if( this.container.value == '' )
		                                                        {
		                                                        	var IDs = new Array();
		                                                        }
		                                                        else
		                                                        {
		                                                        	var IDs = this.container.value.split(this.sperate);
		                                                        }

		                                                        if( this.checked == 1 )
		                                                        {
		                                                        	if( this.maxcheck > 0 && IDs.length >= this.maxcheck )
		                                                        	{
		                                                        		alert(sns.lang_build_string(sns.lang.max_check,this.maxcheck));
		                                                        		this.checked = 0;
		                                                       			this.className = 'checkbox-4';
		                                                        		return false;
		                                                        	}

		                                                        	IDs.push(this.value);
		                                                        }
		                                                        else
		                                                        {
		                                                        	var buffer = new Array();

		                                                        	for( var i = 0; i < IDs.length; i ++ )
		                                                        	{
		                                                        		if( IDs[i] != this.value )
		                                                        		{
		                                                        			buffer.push(IDs[i]);
		                                                        		}
		                                                        	}

		                                                        	IDs = buffer;
		                                                        }

		                                                        this.container.value = IDs.join(this.sperate);

		                                                        if( this.js )
		                                                        {
		                                                        	eval(this.js);
		                                                        }

		                                                    } } );

		if( typeof parentID == 'undefined' )
		{
			this.checkboxCount ++;

			document.write("<span id='checkbox-" + this.checkboxCount + "'></span>");

			parentID = 'checkbox-' + this.checkboxCount;
		}

		if( this.get_obj(parentID).childNodes.length > 0 )
		{
			this.get_obj(parentID).insertBefore(obj,this.get_obj(parentID).childNodes[0]);
		}
		else
		{
			this.get_obj(parentID).appendChild(obj);
		}
	};

	this.radioGroup = {};

	this.createRadio = function( value, gID, ID, containerID, checked, disable, parentID, js )
	{
		if( typeof this.radioGroup[gID] == 'undefined' )
		{
			this.radioGroup[gID]           = {};
			this.radioGroup[gID].checkedID = '';
		}

		if( typeof disable == 'undefined' )
		{
			disable = 0;
		}

		if( typeof checked == 'undefined' )
		{
			checked = 0;
		}

		var container = this.get_obj(containerID);

		if( checked )
		{
		    if( this.radioGroup[gID].checkedID != '' && this.radioGroup[gID].checkedID != ( 'radio_' + gID + '__' + ID ) )
		    {
		    	var checkedObj = this.get_obj(this.radioGroup[gID].checkedID);

		    	if( checkedObj.isDisable )
		    	{
		    		checked = 0;
		    	}
		    	else
		    	{
		    		checkedObj.checked   = 0;
		    		checkedObj.className = 'radio-1';
		    	}
		    }

		    if( checked )
		    {
		    	this.radioGroup[gID].checkedID = 'radio_' + gID + '__' + ID;
		    	container.value = value;
		    }
		}

		var obj = this.createElement('img',{ value        : value,
		                                     src          : "{sns.imgPath}/null.gif",
		                                     gID          : gID,
		                                     id           : 'radio_' + gID + '__' + ID,
		                                     js           : js,
		                                     checked      : checked ? 2 : 0,
		                                     isDisable    : disable,
		                                     container    : container,
		                                     className    : checked ? ( disable ? 'radio-9' : 'radio-3' ) : ( disable ? 'radio-7' : 'radio-1' ),
		                                     onmouseover  : function()
		                                                    {
		                                                        if( this.isDisable ){ return };

		                                                        this.className = this.checked == 2 ? 'radio-6' : ( this.checked == 1 ? 'radio-5' : 'radio-4' );
		                                                    },
		                                     onmouseout   : function()
		                                                    {
		                                                        if( this.isDisable ){ return };

		                                                        this.className = this.checked == 2 ? 'radio-3' : ( this.checked == 1 ? 'radio-2' : 'radio-1' );
		                                                    },
		                                     onmousedown  : function()
		                                                    {
		                                                        if( this.isDisable ){ return };

		                                                        if( this.checked ){ return };

		                                                        if( sns.radioGroup[this.gID].checkedID != '' )
		                                                        {
		                                                        	var checkedObj = sns.get_obj(sns.radioGroup[this.gID].checkedID);

		                                                        	if( checkedObj.isDisable )
		                                                        	{
		                                                        		return false;
		                                                        	}
		                                                        	else
		                                                        	{
		                                                        		checkedObj.checked   = 0;
		                                                        		checkedObj.className = 'radio-1';
		                                                        	}
		                                                        }

		                                                        this.checked = 1;

		                                                        this.className = 'radio-5';

		                                                        this.container.value = this.value;
		                                                        sns.radioGroup[this.gID].checkedID = this.id;

		                                                        if( this.js )
		                                                        {
		                                                        	eval(this.js);
		                                                        }

		                                                    } } );

		if( typeof parentID == 'undefined' )
		{
			document.write("<span id='radio-" + gID + "'></span>");

			parentID = 'checkbox-' + gID;
		}

		if( this.get_obj(parentID).childNodes.length > 0 )
		{
			this.get_obj(parentID).insertBefore(obj,this.get_obj(parentID).childNodes[0]);
		}
		else
		{
			this.get_obj(parentID).appendChild(obj);
		}
	};

	this.get_size = function( size, step )
    {
    	switch(step)
    	{
    		case 1:
    			return this.is_kb(size);
    		case 2:
    			return this.is_mb(size);
    		case 3:
    			return this.is_gb(size);
    		default:
    			return this.is_byte(size);
    	}
    }

    //bytes

    this.is_byte = function(size)
    {
    	if( size >= 1024 )
    	{
    		size = this.is_kb( this.round( size / 1024, 2 ) );
    	}
    	else
    	{
    		size += ' Byte';
    	}

    	return size;
    }

    //kilobytes

    this.is_kb = function(size)
    {
    	if( size >= 1024 )
    	{
    		size = this.is_mb( this.round( size / 1024, 2 ) );
    	}
    	else
    	{
    		size += ' KB';
    	}

    	return size;
    }

    //megabytes

    this.is_mb = function(size)
    {
    	if( size >= 1024 )
    	{
    		size = this.is_gb( this.round( size / 1024, 2 ) );
    	}
    	else
    	{
    		size += ' MB';
    	}

    	return size;
    }

    //gigabytes

    this.is_gb = function(size)
    {
    	if( size >= 1024 )
    	{
    		size = this.is_tb( this.round( size / 1024, 2 ) );
    	}
    	else
    	{
    		size += ' GB';
    	}

    	return size;
    }

    //terabytes

    this.is_tb = function(size)
    {
		if( size >= 1024 )
    	{
    		size = this.is_pb( this.round( size / 1024, 2 ) );
    	}
    	else
    	{
    		size += ' TB';
    	}

    	return size;
    }

    //petabytes

    this.is_pb = function(size)
    {
		if( size >= 1024 )
    	{
    		size = this.is_eb( this.round( size / 1024, 2 ) );
    	}
    	else
    	{
    		size += ' PB';
    	}

    	return size;
    }

    //exabytes

    this.is_eb = function(size)
    {
		if( size >= 1024 )
    	{
    		size = this.is_zb( this.round( size / 1024, 2 ) );
    	}
    	else
    	{
    		size += ' EB';
    	}

    	return size;
    }

    //zettabytes

    this.is_zb = function(size)
    {
		if( size >= 1024 )
    	{
    		//yottabytes
    		size = this.round( size / 1024, 2 ) + ' YB';
    	}
    	else
    	{
    		size += ' ZB';
    	}

    	return size;
    }

    this.validateDate = function( m, d, y, maxy, miny )
    {
    	if( d < 1 || d > 31 )
		{
			return false;
		}

		if( m < 1 || m > 12 )
		{
			return false;
		}



		if( typeof maxy != 'undefined' )
		{
			if( y > maxy )
			{
				return false;
			}
		}

		if( typeof miny != 'undefined' )
		{
			if( y < miny )
			{
				return false;
			}
		}

		if( ( y % 4 == 0 ) && ( d > 29 ) && ( m == 2 ) )
		{
			return false;
		}

		if( ( y % 4 != 0 ) && ( d > 28 ) && ( m == 2 ) )
		{
			return false;
		}

		if( ( d > 30 ) && ( m == 4 || m == 6 || m == 0 || m == 11 ) )
		{
			return false;
		}

		return true;
    }

    this.cleanPattern = function(str)
    {
    	str = str.replace( /\\/g, '\\\\' );
    	str = str.replace( /\-/g, '\\-' );
    	str = str.replace( /\[/g, '\\[' );
    	str = str.replace( /\]/g, '\\]' );
    	str = str.replace( /\(/g, '\\)' );
    	str = str.replace( /\(/g, '\\)' );
    	str = str.replace( /\{/g, '\\{' );
    	str = str.replace( /\}/g, '\\}' );
    	str = str.replace( /\./g, '\\.' );
    	str = str.replace( /\//g, '\\/' );
    	str = str.replace( /\?/g, '\\?' );
    	str = str.replace( /\+/g, '\\+' );
    	str = str.replace( /\|/g, '\\|' );

    	return str;
    }

    this.funcCheckEmpty = function(obj, vID, errMessage )
    {
    	eval(vID + ' = 0' );

		obj.value = obj.value.replace(/\s{2,}/g , ' ' );
		obj.value = obj.value.replace(/^\s+|\s+$/ , '' );

		if( obj.value == '' )
		{
			alert(errMessage);
			obj.className = 'form_incorrect';
			return false;
		}

		eval(vID + ' = 1' );
		obj.className = 'form_correct';
		return true;
	}
	
	this.randRange = function(min, max)
	{
		var randomNum = Math.floor(Math.random() * (max - min + 1)) + min;
		return randomNum;
	}

	this.PopUp = function(url, name, width, height, center, resize, scroll, posleft, postop )
	{
		showx = "";
		showy = "";

		if( posleft != 0 ) { X = posleft }
		if( postop  != 0 ) { Y = postop  }

		if( scroll == null ) { scroll = 1 }
		if( resize == null ) { resize = 1 }

		if( parseInt(navigator.appVersion) >= 4 && center )
		{
			X = ( screen.width  - width  ) / 2;
			Y = ( screen.height - height ) / 2;
		}

		if( X > 0 )
		{
			showx = ',left=' + X;
		}

		if( Y > 0 )
		{
			showy = ',top=' + Y;
		}

		if( scroll != 0 ) { scroll = 1 }

		var Win = window.open( url, name, 'width = ' + width + ', height = ' + height + showx + showy + ', resizable = ' + resize + ', scrollbars = ' + scroll + ', location = no, directories = no, status = no, menubar = no, toolbar = no' );
		Win.focus();
	}

	this.slice_title = function(str, maxLen )
	{
		if( str.length > maxLen )
		{
			var strBuffer = '';

			strBuffer  = str.substr(0, maxLen / 2 );
			strBuffer += '...';
			strBuffer += str.substr(( str.length - ( maxLen / 2) ) + 3 );

			str = strBuffer;
		}

		return str;
	}
	
	this.rewriteNavigation = function(navContent)
	{
		this.get_obj('navigation').innerHTML = navContent;
	}

	/**
     * Build up page span links
     *
     * @param $i string  unique ID
     * @param $c integer Current page
     * @param $s integer Section
     * @param $t integer Total result
     * @param $n integer Number result per page
     * @param $e object  onclick EVENT execute object
     *
     * @return String
     */
	 	
	this.page_build = function(i, c, t, e, n, s, params )
	{
    	c = c >= 1 ? c : 1;

    	n = n > 0 ? n : this.result_per_page;
    	s = s > 0 ? s : this.page_section;

		if( t % n == 0 )
		{
		    totalPAGE = parseInt(t/n);
		}
	    else
	    {
		    totalPAGE = parseInt(t/n+1);
	    }

	    if( totalPAGE < 2 )
	    {
	    	return false;
	    }

	    first = '';
	    last  = '';
	    jump  = '';

	    start = c - s;

	    if( start <= 1 )
	    {
	    	start = 1;
	    }
	    else if( start > totalPAGE )
	    {
	    	start = totalPAGE;
	    }
	    else if( totalPAGE > s * 2 + 1 )
	    {
	    	last = this.html.page.last(e,params);
	    }

	    end = start + s * 2;

	    if( end >= totalPAGE )
	    {
	    	end = totalPAGE;

	    	start = end - s * 2;

	    	if( start < 1 )
	    	{
	    		start = 1;
	    	}
	    }
	    else
	    {
	    	first = this.html.page.first(e,totalPAGE,params);
	    }
		
		pages = new Array();

	    for( var p = start; p <= end; p ++ )
	    {
	    	pages[pages.length] = p == c ? this.html.page.current(p,params) :
	    	                               this.html.page.page(e,p,params);
	    }

        next_page     = '';
	   	previous_page = '';

	   	next     = start - ( s + 1 );
	   	previous = end + ( s + 1 );

	   	if( next > s + 1 )
		{
	    	next_page = this.html.page.next(e,next,params);
	   	}

	   	if( previous < totalPAGE - s )
	   	{
	   		previous_page = this.html.page.previous(e,previous,params);
	    }

	    if( totalPAGE > s * 2 + 1 )
	    {
	    	jump = this.html.page.jump(totalPAGE,e,i,params);
	    }

	    return this.html.page.complete(last, next_page, pages, previous_page, first, c, t, totalPAGE );
	}
	
	this.hiddenObj = function(obj)
	{
		if( sns.is_ie )
		{
			obj.style.display = 'none';
		}
		else
		{
			obj.orgCSS         = { width    : obj.style.width,
								   height   : obj.style.height };

			obj.style.visibility = 'hidden';
			obj.style.width      = '0px';
			obj.style.height     = '0px';
		}		
	}
	
	this.showObj = function(obj)
	{
		if( sns.is_ie )
		{
			obj.style.display = '';
		}
		else
		{
			if( ! obj.orgCSS )
			{
				obj.style.visibility = 'visible';
			}
			else
			{										  
				obj.style.visibility = 'visible';
					
				this.setStyles(obj, obj.orgCSS );
				
				obj.orgCSS = null;
			}
		}
	}
	
	this.$with = function(obj, properties )
	{
		for( var i in properties )
		{
			try
			{
				obj[i] = properties[i];
			}
			catch(e)
			{
				alert(i + ':' + properties[i] );
			}
		}
	}

	this.displayLoadingForm = function(message, skipDisable )
	{
		if( ! skipDisable )
		{
			this.disablePage();
		}

		message  = ! message ? 'Please wait for loading' : message;

		this.get_obj('loading-message').innerHTML = message + '...';

		var obj = sns.get_obj('loading');
		obj.style.display = '';
		this.move_to_center(obj);
	}

	this.hideLoadingForm = function(skipAvailable)
	{
		this.get_obj('loading').style.display = 'none';
				
		if( ! skipAvailable )
		{
			this.availablePage();
		}
	}
	
	this.subtractDate = function(d1,d2)
	{
		return Math.ceil( ( d1.getTime() - d2.getTime() ) / ( 1000 * 60 * 60 * 24 ) );
	}
	
	this.checkSecCode = function(id)
	{		
		var obj  = sns.get_obj(id | 'seccode');
		
		obj.value = obj.value.replace(/[^a-zA-Z]/g, '' ).toUpperCase();

		if( ! obj.value || obj.value.length != 5 )
		{			
			obj.className  = 'incorrect';
			return false;
		}
		else
		{
			obj.className  = 'correct';
			return true;
		}
	}
		
	this.each = function(o, cb, s)
	{
		var n, l;

		if (!o)	return 0;

		s = s || o;

		if (typeof(o.length) != 'undefined')
		{
			for (n=0, l = o.length; n<l; n++)
			{
				if (cb.call(s, o[n], n, o) === false)
					return 0;
			}
		}
		else
		{
			for (n in o)
			{
				if (o.hasOwnProperty(n))
				{
					if (cb.call(s, o[n], n, o) === false) return 0;
				}
			}
		}

		return 1;
	}
	
	this.parseStyle = function(st)
	{
		var o = {};

		if( ! st )
		{
			return o;
		}
		
		function compress(p, s, ot)
		{
			var t, r, b, l;

			t = o[p + '-top' + s];
			
			if( ! t ) return;

			r = o[p + '-right' + s];
			
			if( t != r )	return;

			b = o[p + '-bottom' + s];
			
			if( r != b )	return;

			l = o[p + '-left' + s];
			
			if( b != l ) return;

			o[ot] = l;
			
			delete o[p + '-top' + s];
			delete o[p + '-right' + s];
			delete o[p + '-bottom' + s];
			delete o[p + '-left' + s];
		}

		function compress2(ta, a, b, c)
		{
			var t;

			t = o[a];
			
			if( ! t ) return;

			t = o[b];
			
			if( ! t ) return;

			t = o[c];
		
			if( ! t ) return;

			o[ta] = o[a] + ' ' + o[b] + ' ' + o[c];
			
			delete o[a];
			delete o[b];
			delete o[c];
		};

		st = st.replace(/&(#?[a-z0-9]+);/g, '&$1_MCE_SEMI_'); // Protect entities

		this.each(st.split(';'), function(v)
		{
			var sv, ur = [];

			if(v)
			{
				v = v.replace(/_MCE_SEMI_/g, ';'); // Restore entities
				v = v.replace(/url\([^\)]+\)/g, function(v){ ur.push(v); return 'url(' + ur.length + ')' } );
				v = v.split(':');
				sv = sns.trim(v[1]);
				sv = sv.replace(/url\(([^\)]+)\)/g, function(a, b){ return ur[parseInt(b) - 1] } );

				sv = sv.replace(/(rgb\([^\)]+\))/g, function(a,b)
				{
					return sns.rgbToColor(b);
				});

				o[sns.trim(v[0]).toLowerCase()] = sv;
			}
		});

		compress("border", "", "border");
		compress("border", "-width", "border-width");
		compress("border", "-color", "border-color");
		compress("border", "-style", "border-style");
		compress("padding", "", "padding");
		compress("margin", "", "margin");
		compress2('border', 'border-width', 'border-style', 'border-color');

		if( this.is_ie )
		{
			if( o.border == 'medium none' )
			{
				o.border = '';
			}
		}

		return o;
	}
	
	this.serializeStyle = function(o)
	{
		var s = '';

		this.each(o, function(v, k)
		{
			if (k && v)
			{
				if ( sns.is_moz && k.indexOf('-moz-') === 0) return;

				switch(k)
				{
					case 'color':
					case 'background-color':
						v = v.toLowerCase();
						break;
				}

				s += (s ? ' ' : '') + k + ': ' + v + ';';
			}
		});

		return s;
	}
	
	this.rgbToColor = function(forecolor)
	{
		if( forecolor == '' || forecolor == null )
		{
			return '';
		}
		
		var matches = forecolor.match(/^rgb\s*\(([0-9]+),\s*([0-9]+),\s*([0-9]+)\)$/i);

		if(matches)
		{
			return this.rgbhexToColor( ( matches[1] & 0xFF ).toString(16), ( matches[2] & 0xFF ).toString(16), ( matches[3] & 0xFF ).toString(16) );
		}
		else
		{
			return this.rgbhexToColor( ( forecolor & 0xFF ).toString(16), ( (forecolor >> 8) & 0xFF ).toString(16), ( (forecolor >> 16) & 0xFF ).toString(16));
		}
	}

	this.rgbhexToColor = function( r, g, b )
	{
		return '#' + ( sns.str_pad( r, 2, 0 ) + sns.str_pad( g, 2, 0 ) + sns.str_pad( b, 2, 0 ) );
	}
	
	this.cleanTags = function(txt, separate )
	{
		if( ! separate )
		{
			separate = ',';
		}
		
		txt = this.cleanVNMask(txt).toLowerCase();
		txt = this.trim(txt);

		var rx = new RegExp(separate + "{2,}", 'g' );
		
		txt = txt.replace(rx, separate );
		
		rx = new RegExp("^" + separate + "+|" + separate + "+$", 'g' );
		
		txt = txt.replace(rx, '' );
			
		if( txt != '' )
		{			
			var tags = txt.split(separate);
				
			var buff   = new Array();
			var chkTag = new Array();
				
			for( var i = 0; i < tags.length; i ++ )
			{
				tags[i] = this.trim(tags[i]);
				
				if( tags[i] && tags[i].length > 3 && ! chkTag[tags[i]] )
				{
					buff.push(tags[i]);
					chkTag[tags[i]] = 1;
				}
			}
				
			txt = buff.join(separate);
		
			txt = txt.replace(/\s+/g, '_' );
		}
		
		return txt;
	}

	this.init();

	//window.onerror     = this.errorHandle;
}
