﻿function PhControl()
{
	this.m_oParent			= null;
	this.m_oSibling			= null;	
	this.m_oContainer		= null;
}

PhControl.prototype.AttachToElement = function( parent, insert_after_elm )
{
	if( this.m_oContainer == null )
	{
		alert( 'widget not yet created' );
		return;
	}
	
	this.m_oParent	= (typeof( parent ) == 'string')? document.getElementById( parent ) : parent;
	this.m_oSibling	= (typeof( insert_after_elm ) == 'string')? document.getElementById( insert_after_elm ) : insert_after_elm;
	
	if( this.m_oParent != null )
	{
		if( this.m_oSibling == null || this.m_oSibling.nextSibling == null )
		{
			this.m_oParent.appendChild( this.m_oContainer );
		}
		else
		{
			this.m_oParent.insertBefore( this.m_oContainer, this.m_oSibling.nextSibling );
		}
	}
	else
	{
		alert( 'failed to find parent object ('+parent+')' );
	}
}

PhControl.prototype.SetPosition = function( left, top )
{
	if( this.m_oContainer != null )
	{
		this.m_oContainer.style.position	= 'absolute';
		this.m_oContainer.style.top			= top+'px';
		this.m_oContainer.style.left		= left+'px';
	}
}

PhControl.prototype.SetInlineStyles = function( styles )
{
	var cur_styles = '';
	
	if( this.m_oContainer != null )
	{
		if( g_oClient.GetBrowser() == PhClient.BROWSER_IE )
		{
			cur_style = this.m_oContainer.style.getAttribute( 'cssText' );
			this.m_oContainer.style.setAttribute( 'cssText', cur_style+'; '+styles, 0 );
		}
		else
		{
			cur_style = this.m_oContainer.getAttribute( 'style' );
			this.m_oContainer.setAttribute( 'style', cur_style+'; '+styles );
		}
	}
}