//Author: Tomislav Curman
//Property of avro software. All Rights Reserved.

Order=function(BOL,ID,customerID,status,pcity,dcity,odate,psdate,padate,dsdate,dadate,level,commentCode,comments)
{
	this.BOL=(BOL=='0')?'('+ ID +')':BOL;
	this.ID=ID;
	this.customerID=customerID;
	this.statusCode=status;
	this.pcity=pcity;
	this.dcity=dcity;
	this.odate=this.decodeDate(jes.fromHex(odate));
	this.psdate=this.decodeDate(jes.fromHex(psdate));
	this.padate=this.decodeDate(jes.fromHex(padate));
	this.dsdate=this.decodeDate(jes.fromHex(dsdate));
	this.dadate=this.decodeDate(jes.fromHex(dadate));
	this.level=level;
	this.commentCode=commentCode;
	this.comments=comments;
	this.lastComment='';
	this.status=this.getStatus();
	
	if(this.comments.length>0)
	{
		this.comments.sort(this.compare());
		this.lastComment=this.comments[0].ID;
	}
	else
		this.lastComment=0;
};
Order.prototype=new window.WebObject();

Order.prototype.getStatus=function()
{
	var temp='not';
	switch(this.statusCode)
	{
		case 0:
			temp='Scheduled';
		case 1:
			temp='Scheduled';
			for(var i=0;i<this.comments.length;i++)
			{
				if(this.comments[i].comment.indexOf('Pickup on')!=-1)
					temp='On Route';
			}
		break;
		case 2:
		case 3:
		case 4:
		case 5:
			temp='Delivered';
		break;
		
	}

	return temp;
};

Order.prototype.getLastComment=function()
{
	if(this.comments.length>0)
		return this.comments[0].comment;
	else
		return 'No Details Available.';
};

Order.prototype.compare=function()
{
	return function compare(a,b)
	{
		if (a.ID<b.ID)
			return 1;
		if (a.ID>b.ID)
			return -1;
		return 0;
	}
}