﻿//<Snippet5>
// Register the namespace for the control.
Type.registerNamespace('Intrafinity.Web.Presentation.Controls');

//
// Define the control properties.
//
Intrafinity.Web.Presentation.Controls.DateTimePicker = function(element) { 
    Intrafinity.Web.Presentation.Controls.DateTimePicker.initializeBase(this, [element]);
    this._ce = null;
    this._ddlHour = null;
    this._ddlMinute = null;
    this._ddlAmPm = null;    
    this._datetime = null; 
    this._showTime = null; 
    this._phTimeArea = null; 
}

//
// Create the prototype for the control.
//

Intrafinity.Web.Presentation.Controls.DateTimePicker.prototype = {

   get_ce:function(){
        return this._ce;
    },
   set_ce:function(value){
    if(value!=this._ce){
        this._ce = value;
        this.raisePropertyChanged("ce");
    }
   },       
   
   get_ddlHour:function(){
        return this._ddlHour;
   },
   set_ddlHour:function(value){
        if(value!=this._ddlHour){
            this._ddlHour= value;
            this.raisePropertyChanged("ddlHour");
        }
   }, 
   
   get_ddlMinute:function(){
        return this._ddlMinute;
   },
   set_ddlMinute:function(value){
        if(value!=this._ddlMinute){
            this._ddlMinute= value;
            this.raisePropertyChanged("ddlMinute");
        }
   }, 
   
   get_ddlAmPm:function(){
        return this._ddlAmPm;
   },
   set_ddlAmPm:function(value){
        if(value!=this._ddlAmPm){
            this._ddlAmPm= value;
            this.raisePropertyChanged("ddlAmPm");
        }
   }, 
   get_datetime:function(){
        var date = this._ce.get_selectedDate();
        var month = date.getMonth()+1;
        var dateString = date.getFullYear() + "-" + month + "-" + date.getDate();
        var timeString = "";
        if(this._showTime)
            timeString = this._ddlHour.options[this._ddlHour.selectedIndex].text + ":" + this._ddlMinute.options[this._ddlMinute.selectedIndex].text + ":" + "00 " + this._ddlAmPm.options[this._ddlAmPm.selectedIndex].text;                
        this._datetime = dateString + " " + timeString;
        return this._datetime;
   },
   
   get_phTimeArea : function(){
        return this._phTimeArea;
   },
   set_phTimeArea : function(value){
        this._phTimeArea = value;
   },
   
   setHour : function(hour){                
        if(hour==0){
            this._ddlHour.selectedIndex = 11;
            this._ddlAmPm.selectedIndex = 0;
        }    
        else if(hour >12){
            this._ddlHour.selectedIndex = hour-13;
            this._ddlAmPm.selectedIndex = 1;
        }    
        else{
            this._ddlHour.selectedIndex = hour -1;            
            this._ddlAmPm.selectedIndex = 0;
        }    
   },
   
   setMinute : function(minute){
        this._ddlMinute.selectedIndex = minute;
   },
   
   get_showTime:function(){
        return this._showTime;
   },
   
   set_showTime:function(value){
            this._showTime = value;
            if(this._phTimeArea){
                this._phTimeArea.style.display = this._showTime ? "":"none";
            }             
   },
    
    initialize : function() {
        Intrafinity.Web.Presentation.Controls.DateTimePicker.callBaseMethod(this, 'initialize');
    },

    dispose : function() {
        Intrafinity.Web.Presentation.Controls.DateTimePicker.callBaseMethod(this, 'dispose');
    }
}


// Register the class as a type that inherits from Sys.UI.Control.
Intrafinity.Web.Presentation.Controls.DateTimePicker.registerClass('Intrafinity.Web.Presentation.Controls.DateTimePicker', Sys.UI.Control);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

