
function OPML()
{
	var head = new OPMLHead();
	var body = new OPMLBody();

	this.Head = head;
	this.Body = body;

	this.Output = Output;

	function Load(inText)
	{

	}

	function Save()
	{
		var output = Output();
	}

	function Output()
	{
		var output = "";

		output = "<opml>";

		output += head.Output();
		output += body.Output();

		output += "</opml>";

		return output;
	}
}

function OPMLHead()
{
	this.Title = "";
	this.DateCreated = "";
	this.DateModified= ""; 
	this.OwnerName= "";
	this.OwnerEmail= "";
	this.ExpansionState= 0;
	this.VertScrollState= 0;
	this.WindowTop=0;
	this.WindowLeft= 0;
	this.WindowBottom= 0;
	this.WindowRight= 0;

	this.Output = Output;

	// Public Properties
	this.Title = this.title;

	function Output()
	{
		var output = "";

		output += "<head>";
		output += "<title>" + this.Title + "</title>";
		output += "<ownerName>" + this.OwnerName + "</ownerName>";
		output += "<ownerEmail>" + this.OwnerEmail + "</ownerEmail>";
		output += "</head>";
		return output;
	}


}

function OPMLBody()
{
	var outLines = new Array();

	this.Output = Output;
	this.AddOutline = AddOutline;
	this.AddNewOutline = AddNewOutline;

	function AddOutline(inOutline)
	{
		if(instanceOf(inOutline, OPMLOutline))
		{
			outLines.push(inOutline);
		}	
	}

	function AddNewOutline()
	{
		var newOutline = new OPMLOutline();

		//Add in any attribute objects
		for (var i = 0; i < arguments.length; i++) {
			
			if(instanceOf(arguments[i], OPMLOutlineAttribute))
			{
				newOutline.AddAttribute(arguments[i]);
			}
		}

		outLines.push(newOutline);
	}

	function Output()
	{
		var output = "<body>";
		if(outLines.length > 0)
		{
			for(var i = 0; i < outLines.length; i++)
			{
				output += outLines[i].Output();
			}
			
		}		
		output += "</body>";

		return output;
	}
}

function OPMLOutlineAttribute(inName, inValue)
{
	this.Name = inName;
	this.Value = inValue;
}

function OPMLOutline()
{
	var outLines = new Array();
	var attributes = new Array();
	var isCommented = false;
	var isBreakpoint = false;

	this.Output = Output;
	this.AddOutline = AddOutline;
	this.AddNewOutline = AddNewOutline;
	this.AddAttribute = AddAttribute;

	this.Attributes = attributes;

	function AddOutline(inOutline)
	{
		if(instanceOf(inOutline, OPMLOutline))
		{
			outLines.push(inOutline);
		}		
	}

	function AddAttribute()
	{
		for (var i = 0; i < arguments.length; i++) {
			if(instanceOf(arguments[i], OPMLOutlineAttribute))
			{
				attributes.push(arguments[i]);
			}			
		}
	}


	function AddNewOutline()
	{
		var newOutline = new OPMLOutline();

		//Add in any attribute objects
		for (var i = 0; i < arguments.length; i++) {
			if(instanceOf(arguments[i], OPMLOutlineAttribute))
			{
				newOutline.AddAttribute(arguments[i]);
			}
		}

		outLines.push(newOutline);
	}

	function Output()
	{
		var output = "";
		
		if(outLines.length > 0)
		{
			output += "<outline ";
			

			for (var i = 0; i < attributes.length; i++) {
				output += attributes[i].Name + "='" + attributes[i].Value + "' ";			
			}	
			output +=">";

			for(var i = 0; i < outLines.length; i++)
			{
				output += outLines[i].Output();
			}

			output += "</outline>";
		}
		else
		{
			output += "<outline ";
			for (var i = 0; i < attributes.length; i++) {
				output += attributes[i].Name + "='" + attributes[i].Value + "' ";			
			}	
			output +="/>";
		}

		return output;
	}
}

function instanceOf(object, c) {    
	
	return (c == object.constructor) ;
}

/*function instanceOf(object, constructor) {    
	while (object != null) {       
		if (object == constructor.prototype)          
			return true;       
		object = object.__proto__;   
	}   
	return false;
}*/