/// <reference path="OwcControlCommon.js" />
/// <reference path="OwcDataBound.js" />
/*=========================================================================
 File    : OwcPublicationDatetime.js
 Created : 10-05-2007
 Summary : Data-bound controls that present data about existing publications, years and months
=========================================================================*/
if (typeof(JScript) == "undefined")
	throw DHTML.newError(0, "JavaScript OOP API is not included.  Add JScriptCore.js to your file");

if (typeof(Olive) == "undefined" || !Olive.Controls)
	throw DHTML.newError(0, "Olive Web SDK core classes are not included.  Add OwcControl.js to your file");

// -------------------------- Constants -------------------------

// Control types
Olive.Controls.controlTypeNames.PublicationList = "publicationlist";
Olive.Controls.controlTypeNames.YearList = "yearlist";
Olive.Controls.controlTypeNames.MonthList = "monthlist";

/*=============================================================================
 Class   : Olive.Controls.PublicationList
 Summary : Control that is responsible in sending request and receiving list
           of publications
=============================================================================*/
if (!Olive.Controls.PublicationList)
{
	Olive.Controls.PublicationList = function OwcControlPublicationList()
	{
	} // Olive.Controls.PublicationList()

	Olive.Controls.PublicationList.DefaultValue = "";

	Olive.Controls.PublicationList.DeclareType = function OwcControlPublicationList_DeclareType()
	{
	    //Fields
		this.DeclareField("m_sPublication", Olive.Controls.PublicationList.DefaultValue);
	    
	    // Overriden functions
	    this.OverrideMethod("parseControlHtmlAttr", OwcPublicationList_parseControlHtmlAttr);
	    this.OverrideMethod("contentCanLoad", OwcPublicationList_contentCanLoad);
	    this.OverrideMethod("getHtmlValueElement", OwcPublicationList_getHtmlValueElement);
		this.OverrideMethod("postHtmlContentPaste", OwcPublicationList_postHtmlContentPaste);
		
		// Methods
        this.DeclareMethod("createContentItem", OwcPublicationList_createContentItem);
    } // Olive.Controls.PublicationList.DeclareType()
	
	//------------------------------- Implementation -------------------------------
	function OwcPublicationList_parseControlHtmlAttr()
	{
		// Call base class
		if (this.BaseClassMethod)
			this.BaseClassMethod.apply(this, arguments);

		if (this.m_oValue)
			this.m_sPublication = this.m_oValue;
	} // Olive.Controls.PublicationList.parseControlHtmlAttr()
	
	function OwcPublicationList_contentCanLoad()
	{
		return true;
	} // Olive.Controls.PublicationList.contentCanLoad()

	function OwcPublicationList_getHtmlValueElement()
	{
		var oSelect = getChildObjectByTag(this.HtmlElement, "select", 0);
		if (oSelect)
			return oSelect;
		return this.HtmlElement;
	} // Olive.Controls.PublicationList.getHtmlValueElement()
	
	function OwcPublicationList_postHtmlContentPaste()
	{
		oHtmlElement = this.getHtmlValueElement();
		if (oHtmlElement)
		{
		    this.attachBehavior(oHtmlElement);
		    if (this.m_sPublication)
		    {
		        this.setValue(this.m_sPublication);
		        this.m_sPublication = null;
		    }
		    else
		        this.updateData();
		}
	} // Olive.Controls.PublicationList.postHtmlContentPaste()
	
	function OwcPublicationList_createContentItem()
	{
	    return null;
	}
    
    JScript.Type.RegisterClass("Olive.Controls.PublicationList", Olive.Controls.PublicationList, Olive.Controls.Value, [Olive.Controls.IDataBound, Olive.Controls.IValue]);
	Olive.Controls.RegisterControlType(Olive.Controls.controlTypeNames.PublicationList, Olive.Controls.PublicationList);
} // Define Olive.Controls.PublicationList class

/*=============================================================================
 Class   : Olive.Controls.YearList
 Summary : Control that is responsible in sending request and receiving list of years for publication
=============================================================================*/
if (!Olive.Controls.YearList)
{
	Olive.Controls.YearList = function OwcControlYearList()
	{
	} // Olive.Controls.YearList()

    Olive.Controls.YearList.DefaultValue = "";

	Olive.Controls.YearList.DeclareType = function OwcControlYearList_DeclareType()
	{
	    //Fields
		this.DeclareField("m_sYear", Olive.Controls.YearList.DefaultValue);

	    // Overrides
	    this.OverrideMethod("parseControlHtmlAttr", OwcYearList_parseControlHtmlAttr);
	    this.OverrideMethod("parseValue", OwcYearList_parseValue);
        this.OverrideMethod("validateValue", OwcYearList_validateValue);
		this.OverrideMethod("getHtmlValueElement", OwcYearList_getHtmlValueElement);
		this.OverrideMethod("postHtmlContentPaste", OwcYearList_postHtmlContentPaste);

        // Methods
        this.DeclareMethod("createContentItem", OwcYearList_createContentItem); 
	} // Olive.Controls.YearList.DeclareType()
	
	//------------------------------- Implementation -------------------------------
	function OwcYearList_parseControlHtmlAttr()
	{
		// Call base class
		if (this.BaseClassMethod)
			this.BaseClassMethod.apply(this, arguments);

		if (this.m_oValue)
			this.m_sYear = this.m_oValue;
	} // Olive.Controls.YearList.parseControlHtmlAttr()
	
	function OwcYearList_parseValue(oValue)
	{
		if (typeof(oValue) == "string" && oValue.toLowerCase() == "")
		    return oValue;
		else
		{
		    // Call base class
		    if (this.BaseClassMethod)
			    return this.BaseClassMethod.apply(this, arguments);
	    }
    } // Olive.Controls.YearList.parseValue()
	
	function OwcYearList_validateValue(oValue)
	{
	    if (typeof(oValue) == "string" && oValue.toLowerCase() == "")
		    return true;
		else
		{
		    // Call base class
		    if (this.BaseClassMethod)
			    return this.BaseClassMethod.apply(this, arguments);
	    }
    } // Olive.Controls.YearList.validateValue()
    
    function OwcYearList_getHtmlValueElement()
	{
		var oSelect = getChildObjectByTag(this.HtmlElement, "select", 0);
		if (oSelect)
			return oSelect;
		return this.HtmlElement;
	} // Olive.Controls.YearList.getHtmlValueElement()

	function OwcYearList_postHtmlContentPaste()
	{
		oHtmlElement = this.getHtmlValueElement();
		if (oHtmlElement)
		{
		    this.attachBehavior(oHtmlElement);
		    if (this.m_sYear)
		    {
		        this.setValue(this.m_sYear);
		        this.m_sYear = null;
		    }
		    else
		        this.updateData();
		}
    } // Olive.Controls.YearList.postHtmlContentPaste()
	
    function OwcYearList_createContentItem(oContentItem, sPublication)
	{
	    if (!this.m_oContentItem)
	        this.m_oContentItem = new Olive.ContentItem.YearRange();
	    this.m_oContentItem.m_sPublication = sPublication;
	    return this.m_oContentItem;
	}
	
	JScript.Type.RegisterClass("Olive.Controls.YearList", Olive.Controls.YearList, Olive.Controls.Year, [Olive.Controls.IDataBound]);
	Olive.Controls.RegisterControlType(Olive.Controls.controlTypeNames.YearList, Olive.Controls.YearList);
} // Define Olive.Controls.YearList class

/*=============================================================================
 Class   : Olive.Controls.MonthList
 Summary : Control that is responsible in sending request and receiving list
           of monthes for chosen year of publication
=============================================================================*/
if (!Olive.Controls.MonthList)
{
	Olive.Controls.MonthList = function OwcControlMonthList()
	{
	} // Olive.Controls.MonthList()

	Olive.Controls.MonthList.DefaultValue = "";

	Olive.Controls.MonthList.DeclareType = function OwcControlMonthList_DeclareType()
	{
	    // Fields
		this.DeclareField("m_sMonth", Olive.Controls.MonthList.DefaultValue);

	    // Overrides
	    this.OverrideMethod("parseControlHtmlAttr", OwcMonthList_parseControlHtmlAttr);
	    this.OverrideMethod("parseValue", OwcMonthList_parseValue);
        this.OverrideMethod("validateValue", OwcMonthList_validateValue);
	    this.OverrideMethod("getHtmlValueElement", OwcMonthList_getHtmlValueElement);
		this.OverrideMethod("postHtmlContentPaste", OwcMonthList_postHtmlContentPaste);

        // Methods
        this.DeclareMethod("createContentItem", OwcMonthList_createContentItem); 
    } // Olive.Controls.YearList.DeclareType()
	
	//------------------------------- Implementation -------------------------------
	function OwcMonthList_parseControlHtmlAttr()
	{
		// Call base class
		if (this.BaseClassMethod)
			this.BaseClassMethod.apply(this, arguments);

		if (this.m_oValue)
			this.m_sMonth = this.parseValue(this.m_oValue);
	} // Olive.Controls.MonthList.parseControlHtmlAttr()
	
	function OwcMonthList_parseValue(oValue)
	{
		if (typeof(oValue) == "string" && oValue.toLowerCase() == "")
		    return oValue;
		else
		{
		    // Call base class
		    if (this.BaseClassMethod)
			    return this.BaseClassMethod.apply(this, arguments);
	    }
    } // Olive.Controls.MonthList.parseValue()
	
	function OwcMonthList_validateValue(oValue)
	{
	    if (typeof(oValue) == "string" && oValue.toLowerCase() == "")
		    return true;
		else
		{
		    // Call base class
		    if (this.BaseClassMethod)
			    return this.BaseClassMethod.apply(this, arguments);
	    }
    } // Olive.Controls.MonthList.validateValue()
	
	function OwcMonthList_getHtmlValueElement()
	{
		var oSelect = getChildObjectByTag(this.HtmlElement, "select", 0);
		if (oSelect)
			return oSelect;
		return this.HtmlElement;
	} // Olive.Controls.MonthList.getHtmlValueElement()
		
	function OwcMonthList_postHtmlContentPaste()
	{
		oHtmlElement = this.getHtmlValueElement();
		if (oHtmlElement)
		{
		    this.attachBehavior(oHtmlElement);
		    if (this.m_sMonth)
		    {
		        this.setValue(this.m_sMonth);
		        this.m_sMonth = null;
		    }
		    else
		        this.updateData();
		}
    } // Olive.Controls.MonthList.postHtmlContentPaste()
	
	function OwcMonthList_loadContent(oContentItem)
	{
	    if (oContentItem)
	        this.m_oContentItem = oContentItem;
		this.contentLoad();
	} // Olive.Controls.MonthList.refreshMonthData()
	
	function OwcMonthList_createContentItem(oContentItem, sYear)
	{
	    if (!this.m_oContentItem)
	        this.m_oContentItem = new Olive.ContentItem.MonthRange();
	    if (oContentItem && oContentItem.getPublication)
	        this.m_oContentItem.m_sPublication = oContentItem.getPublication();
	    this.m_oContentItem.m_sYear = sYear;
	    return this.m_oContentItem;
	}
	
    JScript.Type.RegisterClass("Olive.Controls.MonthList", Olive.Controls.MonthList, Olive.Controls.Month, [Olive.Controls.IDataBound]);
	Olive.Controls.RegisterControlType(Olive.Controls.controlTypeNames.MonthList, Olive.Controls.MonthList);
} // Define Olive.Controls.MonthList class