Ti::TiValue Ti::TiViewProxy::remove(Ti::TiValue value)
{
	Ti::TiValue val;
	val.setUndefined();

	Ti::TiViewProxy *childProxy = static_cast<Ti::TiViewProxy*>(value.toProxy());
	if(!_childViewsProxies.contains(childProxy)) return val;

	Ti::TiView* childView = childProxy->getView();
	Ti::TiView* thisView = getView();
	childProxy->makeWeak();
	thisView->remove(childView);
	_childViewsProxies.removeOne(childProxy);

	childProxy->_parentProxy = NULL;
    Local<Value> children = _jsObject->Get(String::New("children"));
    if(!children.IsEmpty() && !children->IsUndefined())
    {
    	Local<Array> array = Local<Array>::Cast(children);
    	for(int i = 0, len = array->Length(); i < len; i++) {
    		if(array->Get(i) == value.toJSValue())
    		{
    	    	array->Delete(i);
    	    	break;
    		}
    	}
    }

	return val;
}
Ti::TiValue Ti::TiProxy::applyProperties(Ti::TiValue value)
{
	if(value.isMap())
	{
		initWithObject(value.toJSValue()->ToObject());
	}
	Ti::TiValue val;
	val.setUndefined();
	return val;
}
Ti::TiValue Ti::TiProxy::removeEventListener(Ti::TiValue value)
{
	Ti::TiValue nameValue = value.toList().at(0);
	QString eventName = nameValue.toString();

	Ti::TiValue functionValue = value.toList().at(1);
	Handle<Function> func = Handle<Function>::Cast(functionValue.toJSValue());

	Ti::TiEvent::RemoveEventFromObject(_jsObject, eventName, func);
	Ti::TiValue res;
	res.setUndefined();
	return res;
}
Ti::TiValue Ti::TiViewProxy::add(Ti::TiValue value)
{
	if(value.isProxy())
	{
		Ti::TiViewProxy *childProxy = static_cast<Ti::TiViewProxy*>(value.toProxy());
		childProxy->clearWeak();
		_childViewsProxies.append(childProxy);
		Ti::TiView* childView = childProxy->getView();
		Ti::TiView* thisView = getView();
		thisView->add(childView);
		childProxy->_parentProxy = this;
	}
	else
	{
        TiObject* addObj = TiObject::getTiObjectFromJsObject(value.toJSValue());
        TiUIBase* uiObj = (TiUIBase*) addObj;
        NativeObject* childNO = uiObj->getNativeObject();
        getView()->addOldObject(childNO);

       Local<Value> children = _jsObject->Get(String::New("children"));
       Local<Array> array;
       if(children.IsEmpty() || children->IsUndefined())
       {
    	   array = Array::New();
    	   _jsObject->Set(String::New("children"), array);
       }
       else
       {
    	   array = Local<Array>::Cast(children);
       }
       array->Set(array->Length(), value.toJSValue());
       childNO->release();

	}

	Ti::TiValue val;
	val.setUndefined();
	return val;
}
Ti::TiValue Ti::TiProxy::addEventListener(Ti::TiValue value)
{
	QString eventName;

	Ti::TiValue nameValue = value.toList().at(0);
	Ti::TiValue functionValue = value.toList().at(1);

	eventName = nameValue.toString();

	onEventAdded(eventName);

	Ti::TiEvent::AddEventToObject(_jsObject, eventName, Handle<Function>::Cast(functionValue.toJSValue()));

	Ti::TiValue res;
	res.setUndefined();
	return res;
}
Ti::TiValue TiUITableViewSectionProxy::add(Ti::TiValue value)
{
	TiUITableViewRowProxy* row = NULL;
	if(value.isMap())
	{
		row = TiUITableViewRowProxy::CreateProxy();
		row->initWithObject(value.toJSValue()->ToObject());
	}
	else
	if(value.isProxy())
	{
		row = static_cast<TiUITableViewRowProxy*>(value.toProxy());
	}
	row->setRowHeader("");
	row->clearWeak();

	_tableViewRows.append(row);

	Ti::TiValue val;
	val.setUndefined();
	return val;
}
void Ti::TiProxy::setTiValueForKey(Ti::TiValue value, QString key)
{
	_jsObject->Set(TiHelper::ValueFromQString(key), value.toJSValue());
}