//  ValidationContainer [NT 01/05/2008]
function ValidationContainer()
{
  try{
	
  this.inheritFrom = TemplateBase;

	this.inheritFrom();			

  /* PRIVATE PROPERTIES */
  var control = null;
  
  var h3 = null;

  var featuresAdded = false;
  
  var properties = null;
  


  /* PUBLIC METHODS */

    // Appends the control to a container element
    this.AppendTo = function(ContainerElement)
    {
        try{
        
          $(ContainerElement).append(control);
					
					this.BaseLoad(control);
          
          if(Editor.IsEnabled())
            this.EditMode();
            
        } catch(err){ Log.Add("ValidationContainer.AppendTo", err, LogType.Error);}
    };
    
    this.Create = function()
    {
      try{
        
          control = $("<div condition='' class='component ValidationContainer' ref='ValidationContainer'><h3 class='handle'>Validation Errors</h3></div>");
          
          h3 = $(control.find(">h3"));
          
          //Log.Add("ValidationContainer.Create", "Created", LogType.Info);
      
      } catch(err){ Log.Add("ValidationContainer.Create", err, LogType.Error);}

    };
    
    this.DefaultMode = function()
    {
      try{
      
        RemoveFeatures();
        
        Helper.RemoveComponentID(control);
        
      } catch(err){ Log.Add("ValidationContainer.DefaultMode", err, LogType.Error);}
    };


    this.EditMode = function()
    {
      try{
      
        AddFeatures();
        
      } catch(err){ Log.Add("ValidationContainer.EditMode", err, LogType.Error);}
    };


    this.GetProperties = function()
    {
       try{

          var properties = this.GetBaseProperties();
          
          properties[properties.length] = new PropertiesEditor.Property(PropertyFields.GetProperty("ID"), this.GetID, this.SetID);
       
          properties[properties.length] = new PropertiesEditor.Property(PropertyFields.GetProperty("Caption"), this.GetCaption, this.SetCaption);
          
          return properties;
          
       } catch(err){ Log.Add("ValidationContainer.GetProperties", err, LogType.Error);}
    };
    

    this.Load = function(ControlElement)
    {
       try{
       
          control = $(ControlElement);
					
					this.BaseLoad(control);
          
          h3 = $(control.find(">h3"));

          //Log.Add("ValidationContainer.Load", "", LogType.Info);
          
       } catch(err){ Log.Add("ValidationContainer.Load", err, LogType.Error);}
    };
		
		this.Show = function(table)
		{
		  control.css("display", "block");	
			control.html(table);	
		}
		
		this.Hide = function()
		{
		  control.html("");
		  control.css("display", "none");
		}


    this.GetCaption = function(){try{ return h3.text(); } catch(err){ Log.Add("ValidationContainer.GetCaption", err, LogType.Error);}};

    this.GetControl = function(){ try{ return control; } catch(err){ Log.Add("ValidationContainer.GetControl", err, LogType.Error);} };
    
    this.GetID = function(){try{  return  control.attr("id"); } catch(err){ Log.Add("ValidationContainer.GetID", err, LogType.Error); }};

    this.SetCaption = function(newCaption){ try{ h3.text(newCaption);} catch(err){ Log.Add("ValidationContainer.SetCaption", err, LogType.Error);}};
    
    this.SetID = function(newID){try{ control.attr("id", newID);} catch(err){ Log.Add("ValidationContainer.SetID", err, LogType.Error); }};
    
    
    /* PUBLIC PROPERTIES */    
    this.NameRequired = false;
    
    this.Ref = "ValidationContainer";
    


  



  /* PRIVATE METHODS */

  // adds features to the control based on the rules specified for this type of control
  function AddFeatures()
  {
     try{
     
        if(featuresAdded)
          return;
        
        $(control).sortable({ items: '> .component' });
				
				$(control).css("display", "block");
         
        control.bind("dblclick.ValidationContainer", function(event){event.stopPropagation(); Editor.ShowProperties(control); });
        
        h3.attr("unselectable", "on");
				
        featuresAdded = true;
        
     } catch(err){ Log.Add("ValidationContainer.AddFeatures", err, LogType.Error);}
        
  }
  
  // removes features from the control that were previously added 
  function RemoveFeatures()
  {
     try{ 
       
        if(!featuresAdded)
          return;
        
        control.unbind("dblclick.ValidationContainer");
        
        $(control).sortable("disable");
				
				$(control).css("display", "none");				
        
        h3.removeAttr("unselectable");
          
        featuresAdded = false;
        
     } catch(err){ Log.Add("ValidationContainer.RemoveFeatures", err, LogType.Error);}
  }


} catch(err){ Log.Add("ValidationContainer", err, LogType.Error); }
}
