﻿/*
 * author : 이주용
 * version : 09.03.23
 * comment : 자바스크립트의 공통 사용 규칙을 위한 프레임웍
 */
var fx = {};
fx.Delegate = {};

fx.Delegate.createDelegate = function(delegateInstance,pointingMethod){
	return function(){
		return pointingMethod.apply(delegateInstance, arguments);
	};
};

fx.PageLifeCycle = {};
fx.PageLifeCycle.OnLoadHandler = function(){
	if(window.Page_Load)window.Page_Load();
};

fx.PageLifeCycle.OnUnLoadHandler = function(){
	if(window.Page_UnLoad)window.Page_UnLoad();
};

fx.DTOFactory = {};

fx.DTOFactory.CreateDTO = function()
{
	return 	{
		AddProperty : function(PropertyName)
		{
			this[PropertyName] = null;
		},
		
		DeleteProperty : function(PropertyName)
		{
			if(typeof(this[PropertyName]) != "function")
				delete this[PropertyName];
		},
		
		DeleteAllProperty : function()
		{
			for(var PropertyName in this)
				if(typeof(this[PropertyName])!= "function")
					delete this[PropertyName];
		},
		
		GetPropertyCount : function()
		{
			var count = 0;
			
			for(var PropertyName in this)
				if(typeof(this[PropertyName]) != "function")
					count++;
			
			return count;
		}
	};
};

fx.DomPicker = {};

var returnObj = null
fx.DomPicker.$	= function( element ) 
{
	
	
	var arguments = fx.DomPicker.$.arguments;	
	
	if(arguments.length == 1 && typeof(element).toLowerCase() == "string")
		return document.getElementById( element );
	else if(arguments.length == 2 && typeof(element) == "object")
	{	
		 returnObj = null;
		 findChildReculsive(element.childNodes,arguments[1],0);
		 return returnObj;		 
	}
}

function findChildReculsive(elements,id)
{   
	var length = (elements.length) ? elements.length : (elements.childNodes) ? elements.childNodes.length : 0;
	for(var i=0; i < length; i++)
	{	
		var child = elements[i];
		
		if(typeof(child) == "undefined")
			child = elements.childNodes[i];

		if(child.id && child.id == id)
		{
			returnObj = child
			return child;
		}
		
		
		if(typeof(child) == 'object' && child.childNodes && child.childNodes.length > 0)
		{		
			
			 findChildReculsive(child,id);
		}
		
	}
}

fx.DomPicker.$s	= function( ElementName ) 
{
	return document.getElementsByName( ElementName );
}

fx.init = function(){
	window.onload = OnLoadCallBack;
	window.onunload = OnUnLoadCallBack;
};


OnLoadCallBack = fx.Delegate.createDelegate(this, fx.PageLifeCycle.OnLoadHandler);
OnUnLoadCallBack = fx.Delegate.createDelegate(this, fx.PageLifeCycle.OnUnLoadHandler);

$ = fx.Delegate.createDelegate(this, fx.DomPicker.$);
$s = fx.Delegate.createDelegate(this, fx.DomPicker.$s);

fx.init();