/* 	Copyright 2008 Maximum Processing Inc
	
	ABOUT THIS SCRIPT

	
	Change Log
 	Created 11/26/2008 Nathan Townsend
*/


function BaseComponent(){
    
    var _node = null;
		
		var _icon = null;
    
    this.Type = null;
    
    this.Icon = null;
		
		this.OldEntry = null
		
		this.OldExit = null;
		
    
    this.BaseCreate = function()
    {
		  try{
			
        _node = $(RuleXML.GetNewElement('c'));
        
        _node.append(RuleXML.GetNewElement('n'));
        
        _node.append(RuleXML.GetNewElement('t'));
        
        _node.append(RuleXML.GetNewElement('values'));
        
        _node.append(RuleXML.GetNewElement('j'));
        
        _node.append(RuleXML.GetNewElement('j'));
        
				var x = $(RuleXML.GetNewElement('x'));
				
				x.text("0");
				
        _node.append(x);
        
				var y = $(RuleXML.GetNewElement('y'));
				
				y.text("0");

        _node.append(y);
				
				_node.append(RuleXML.GetNewElement('c'));
				
        var _id = RuleXML.GetNextComponentNumber();
				
        _node.find(">n").text(_id);

  		} catch(err){Log.Add("BaseComponent.BaseCreate", err, LogType.Error);}      
    }
    
    
    this.BaseLoad = function(xmlNode)
    {
      try{

			  _node = $(xmlNode);
      
        this.Type = _node.find(">t").text();
				
				// check for non-existing comment node
				if(_node.find(">c").length == 0)
				  _node.append(RuleXML.GetNewElement('c'));

  		} catch(err){Log.Add("BaseComponent.BaseLoad", err, LogType.Error);}			
    }
		
		// performs cleanup for when the component is deleted
		this.Delete = function()
		{
		  var Icon = this.GetIcon();
			
			Icon.Delete();
			
			Icon = null;
		}
		
		this.GetBaseProperties = function()
		{
		  var properties = new Array();

      properties[properties.length] = new PropertiesEditor.Property(PropertyFields.GetProperty("ID"), this.GetID, null);
      properties[properties.length] = new PropertiesEditor.Property(PropertyFields.GetProperty("Comment"), this.GetComment, this.SetComment);			
											
			return properties;
		}

    this.GetComment = function(){
		  try{
        return _node.find(">c").text();
  		} catch(err){Log.Add("BaseComponent.GetComment", err, LogType.Error);}				
    }			

    this.GetID = function(){
		  try{
        return _node.find(">n").text();
  		} catch(err){Log.Add("BaseComponent.GetID", err, LogType.Error);}				
    }		
		
		this.GetIcon = function()
		{
		  try{
        return this.Icon;
  		} catch(err){Log.Add("BaseComponent.GetIcon", err, LogType.Error);}		 
		}
		
    this.GetJ1 = function(){
		  try{
        return $(_node.find(">j")[0]).text();
  		} catch(err){Log.Add("BaseComponent.GetJ1", err, LogType.Error);}				
    }

    this.GetNode = function(){
		  try{
        return _node;
  		} catch(err){Log.Add("BaseComponent.GetNode", err, LogType.Error);}				
    }
    
    this.GetX = function()
    {
		  try{
        return _node.find(">x").text();
  		} catch(err){Log.Add("BaseComponent.GetX", err, LogType.Error);}				
    }

    this.GetY = function()
    {
		  try{		

        return _node.find(">y").text();

  		} catch(err){Log.Add("BaseComponent.GetY", err, LogType.Error);}				
    }
		
    this.SetComment = function(newValue){
		  try{

        $(_node.find(">c")[0]).text(newValue);
				
				_icon.ShowComment(newValue);
			
  		} catch(err){Log.Add("BaseComponent.SetComment", err, LogType.Error);}				
    }		
		
		this.SetIcon = function(newIcon)
		{
		  try{

        this.Icon = newIcon;
				
				_icon = newIcon;

  		} catch(err){Log.Add("BaseComponent.SetIcon", err, LogType.Error);}		 
		}		
    
    this.SetJ1 = function(newValue){
		  try{
        $(_node.find(">j")[0]).text(newValue);
  		} catch(err){Log.Add("BaseComponent.SetJ1", err, LogType.Error);}				
    }
		
    this.SetType = function(newValue){
		  try{
        $(_node.find(">t")[0]).text(newValue);
  		} catch(err){Log.Add("BaseComponent.SetJ2", err, LogType.Error);}				
    }		
    
    this.SetX = function(newValue){
		  try{
        $(_node.find(">x")[0]).text(newValue);
  		} catch(err){Log.Add("BaseComponent.SetX", err, LogType.Error);}				
    }

    this.SetY = function(newValue){
 			try{
        $(_node.find(">y")[0]).text(newValue);
  		} catch(err){Log.Add("BaseComponent.SetY", err, LogType.Error);}				
    }
}



