﻿function PhWidget()
{
	this.m_oParent			= null;
	this.m_oSibling			= null;
	
	this.m_oContainer		= null;
	
	this.m_strStyleSheet	= '';
}

PhWidget.prototype.Create = function()
{
	this.m_oContainer	= null;
}

PhWidget.prototype.AttachToElement = function( parent, insert_before_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_before_elm ) == 'string')? document.getElementById( insert_before_elm ) : insert_before_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 );
		}
	}
	else
	{
		alert( 'failed to find parent object ('+parent+')' );
	}
}

PhWidget.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', styles+' '+cur_style );
		}
	}
}
