// JavaScript Document
//------------------------------------------ Multi Offer Model --------------------------------
function ApplicationOfferModel(aDom)
{
  if (!aDom)
  {
    alert("Offer root not defined!");
  }
  this.mapping = {
      'offerid':'offerId',
      'flight':'flight',
      'offerer':'offerer',
      
      'airline':'airline',
      'airlineShort':'airlineShort',
      'price':'price',
      'taxes':'taxes',
      'netto':'netto',
      'to':'to',
      'from':'from',
      'fromIataCode':'fromIataCode',
      'toIataCode':'toIataCode',
      'time':'time',
      'date':'date',
      'arrivalTime':'arrivalTime'};

  this.reader=new ReaderFactory().createXmlReader(aDom);
  
  this.requestData=null;
  //this.getTopOfferNodes=getMultiTopOfferNodes;
  
  this.topOfferNodes=null;
  this.topofferIds=new Array();
  this.optimumNodes=new Array();
  this.dayOffers=new Array();
  //standard call 
  this.highestPrice=0;  
  this.highestOfferPrice=0;
  this.lowestOfferPrice=999999; //fantastisch hoch
  this.firstDate=null;
  this.offerNodes=null;
  this.cal = new GregorianCalendar();
  
  this.xStat=new StatisticFactory().createStatistic('ApplicationOfferModel');
  
  this.initTopOfferModel();
  this.extractHighestPrice();  
}

ApplicationOfferModel.prototype.extractHighestPrice=function()
{
	var theNode = this['reader'].getFirstNodeByPath('flightRequestResponse.listStatistics');
  	this.highestPrice = this['reader'].getText(this['reader'].getFirstChildNode(theNode,"highestPrice"));
}

ApplicationOfferModel.prototype.getHighestPrice=function()
{
	return this.higestPrice;
}

ApplicationOfferModel.prototype.getRequestData=function()
{
  return this.requestData;
}

ApplicationOfferModel.prototype.getDayOffers=function()
{
  return this.dayOffers;
}

ApplicationOfferModel.prototype.getBestDayOffer=function(aDate, aEarlierOrLater)
{
  this.xStat.incCall('getBestDayOffer');
  var theDate;
  var theOffer =null;
  for (var i=0;i<this.dayOffers.length && theOffer==null;i++)
  {
    if (aEarlier=='earlier')
    {
      if (this.cal.before(this.dayOffers[i].getDate(), aDate))
      {
        theOffer = this.dayOffers[i].getBestOffer();
      }
    }
    else
    {
      if (this.cal.after(this.dayOffers[i].getDate(), aDate))
      {
        theOffer = this.dayOffers[i].getBestOffer();
      }
    }
  }
  this.xStat.endCall('getBestDayOffer');
  return theOffer;
}

ApplicationOfferModel.prototype.getFlightOffer=function(anId)
{
  return this.offerNodes[anId];
}

ApplicationOfferModel.prototype.getHighestOfferPrice=function()
{
  return this.highestOfferPrice;
}

ApplicationOfferModel.prototype.getFirstDate=function()
{
  return this.firstDate;
}

ApplicationOfferModel.prototype.getTopOfferById=function(anId)
{
  return this.topofferIds[anId];
}

ApplicationOfferModel.prototype.getLocationImage=function(aTopOfferNo)
{
  return null;
}

ApplicationOfferModel.prototype.getTopOfferNodes=function()
{
  
  if (this.topOfferNodes == null)
  {
    this.xStat.incCall('getTopOfferNodes');
    this.topOfferNodes = new Array();
    var theNode = this['reader'].getFirstNodeByPath('flightRequestResponse.topOfferList');
    var theNodeList = this['reader'].getChildNodes(theNode,"topoffer");
    var theNext; 
    var theOfferList= this.getAllOfferNodes();
    if(theNodeList!=null)
    {
      for (var i = 0; i<theNodeList.length; i++)
      {
        theNext =  new TopOfferObject();
        this.fillTopOfferNode(theNext, theNodeList[i], theOfferList);
        this.topOfferNodes[this.topOfferNodes.length] = theNext;
      } 
      if (this.topOfferNodes)
      {
        //alert("Number of topOffers:"+this.topOfferNodes.length);
      }
    }
    else {
    //alert("No TopOffer nodes in XML:\n "+this['reader'].printNodeList(this['reader'].getRootNode()));
    }
    this.xStat.endCall('getTopOfferNodes');
  }
  return this.topOfferNodes;
}

ApplicationOfferModel.prototype.fillTopOfferNode=function(aTopOffer, aNode, aOfferList)
{
  this.xStat.incCall('fillTopOfferNode');
  var theNodes = new Array();
  theNodes[0] = this['reader'].getNode(aNode,'topoffer.sevendays');
  theNodes[1] = this['reader'].getNode(aNode,'topoffer.thirtydays');
  theNodes[2] = this['reader'].getNode(aNode,'topoffer.ninetydays');
  var theImg = this['reader'].getText(this['reader'].getFirstChildNode(aNode,"imgUrl")); 
  var theId = null;
  for (var i=0; i<3;i++)
  {
    if (theNodes[i])
    { 
      theId=this['reader'].getNodeAttributeValue(theNodes[i],"offerid");
      if (theId)
      {
        aTopOffer.setOffer(i,aOfferList[theId]);
      }
    }
  }
  var theTopId = this['reader'].getNodeAttributeValue(aNode, 'id');
  aTopOffer.setId(theTopId);
  aTopOffer.imgUrl=theImg;
  this.topofferIds[theTopId]=aTopOffer;
  this.xStat.endCall('fillTopOfferNode');
}

ApplicationOfferModel.prototype.initTopOfferModel=function()
{
  this.xStat.incCall('initTopOfferModel');
  var theOffers = this.getAllOfferNodes();
  var theNodes=this.getTopOfferNodes();
  if(theNodes != null)
  {
    var i;
    var theNode;
    var thePrice=0;
    for (i=0;i<theNodes.length;i++)
    {
      theNode = theNodes[i];
      thePrice = this.calculateMaxOfferPrice(theNode);
      if(Math.abs(thePrice)>Math.abs(this.highestPrice))
      {
        this.highestPrice=thePrice;
        
      }	  
    }
  }
  this.xStat.endCall('initTopOfferModel');
  //alert("highest price:"+this.highestPrice);
}


ApplicationOfferModel.prototype.createOfferNodeList=function()
{
  this.xStat.incCall('getAllOfferNodes');
  var theRoot=this['reader'].getFirstNodeByPath("flightRequestResponse");
  var theOfferNodes=this['reader'].getChildNodes(theRoot, "offer" );
  //var theDateDebug='';
  if (theOfferNodes != null)
  {
    var i;
    var theArray= new Array();
    var theL = theOfferNodes.length;
    for (i=0;i<theL;i++)
    { 
      var theOffer = new FlightOffer();
      var theOfferId = this['reader'].getNodeAttributeValue(theOfferNodes[i],"offerid");
      theArray[theOfferId]=theOffer;
      theOffer['offerId']=theOfferId;

      var theChildren = theOfferNodes[i]['childNodes'];
      var theCL=theChildren.length;
      var theValue;
      var theNode;
      var j=0;
      var theStartDate=null;
      //alert(this.reader.printNodeList(theOfferNodes[i]));
      
      for (j=0; j<theCL;j++)
      {
        
        
        if (theChildren[j]!=null)
        { 
          //alert(j+' not defined - '+theChildren+' nodeValue:'+theValue+" length:"+theCL)
          
          theNode = theChildren[j]['nodeName'];
          theValue = this['reader'].getText(theChildren[j]);
          alert (theNode+'='+theValue);
          if (theNode=='taxes' || theNode == 'netto')
          {    
            theValue = this.round(theValue);
          }
          else if (theNode == "date")
          {
            theOffer['dateString']=theValue;
            if (theValue == null)
            {
              //alert(j+' not defined - '+theChildren+' node:'+theNode+" length:"+theCL);
            }
            theStartDate=theValue;
            theValue = this.getDate(theValue);
          }
          if (this.mapping[theNode])
          {
            theOffer[this.mapping[theNode]]=theValue;
          }
        }
      }
      if (this.firstDate == null)
      {
        this.firstDate=theOffer.date;
      }
      else if (this.cal.before(theOffer['date'], this.firstDate))
      {
        this.firstDate =theOffer['date'];
      }
      if (Math.abs(theOffer.price)>Math.abs(this.highestOfferPrice))
      {
        this.highestOfferPrice=Math.abs(theOffer.price);
      }
	  if (Math.abs(theOffer.price)< Math.abs(this.lowestOfferPrice))
      {
        this.lowestOfferPrice=Math.abs(theOffer.price);
      }
      this.addToDayOffer(theOffer['dateString'], theOffer);
      
    }
    this.xStat.endCall('getAllOfferNodes');
    return theArray;
  }
  return null;
}


ApplicationOfferModel.prototype.getAllOfferNodes=function()
{
  if (this.offerNodes==null)
  {
    //this.offerNodes = this.createOfferNodeList();
    this.offerNodes = this._getAllOfferNodes();
  }
  return this.offerNodes;
}
 
ApplicationOfferModel.prototype._getAllOfferNodes=function()
{ 
  this.xStat.incCall('getAllOfferNodes');
  var theRoot=this['reader'].getFirstNodeByPath("flightRequestResponse");
  var theOfferNodes=this['reader'].getChildNodes(theRoot, "offer" );  
  if (theOfferNodes != null)
  {
    var i;
    var theArray= new Array();
    var theL = theOfferNodes.length;
    for (i=0;i<theL;i++)
    { 
      var theOfferId = this['reader'].getNodeAttributeValue(theOfferNodes[i],"offerid");
      var theOffer = new FlightOffer();
      
      theArray[theOfferId]=theOffer;
      theOffer['offerId']=theOfferId;
      theOffer['flight']=this['reader'].getText(this['reader'].getFirstChildNode(theOfferNodes[i],"flight"));
      theOffer['offerer']=this['reader'].getText(this['reader'].getFirstChildNode(theOfferNodes[i],"offerer"));
      theOffer['airline']=this['reader'].getText(this['reader'].getFirstChildNode(theOfferNodes[i],"airline"));
      theOffer['airlineShort']=this['reader'].getText(this['reader'].getFirstChildNode(theOfferNodes[i],"airlineShort"));
      theOffer['price']=this['reader'].getText(this['reader'].getFirstChildNode(theOfferNodes[i],"price"));
      var theTaxes = this.round(this['reader'].getText(this['reader'].getFirstChildNode(theOfferNodes[i],"taxes")));
      theOffer['taxes']=theTaxes;
      var theNetto=this.round(this['reader'].getText(this['reader'].getFirstChildNode(theOfferNodes[i],"netto")));
      theOffer['netto']=theNetto;
      theOffer['to']=this['reader'].getText(this['reader'].getFirstChildNode(theOfferNodes[i],"to"));
      theOffer['from']=this['reader'].getText(this['reader'].getFirstChildNode(theOfferNodes[i],"from"));

      theOffer['fromIataCode']=this['reader'].getText(this['reader'].getFirstChildNode(theOfferNodes[i],"fromIataCode"));
      theOffer['toIataCode']=this['reader'].getText(this['reader'].getFirstChildNode(theOfferNodes[i],"toIataCode"));
      theOffer['time']=this['reader'].getText(this['reader'].getFirstChildNode(theOfferNodes[i],"time"));
      var theStartDate=this['reader'].getText(this['reader'].getFirstChildNode(theOfferNodes[i],"date"));
      theOffer['date']=this.getDate(theStartDate);
      //theDateDebug+=' '+theStartDate+':'+this.cal.print(theOffer.date)+'\n';
      theOffer['dateString']=theStartDate;
      theOffer['arrivalTime']=this['reader'].getText(this['reader'].getFirstChildNode(theOfferNodes[i],"arrivalTime"));
      //theOfferNodes[i];
      if (this.firstDate == null)
      {
        this.firstDate=theOffer.date;
      }
      else if (this.cal.before(theOffer['date'], this.firstDate))
      {
        this.firstDate =theOffer['date'];
      }
      if (Math.abs(theOffer.price)>Math.abs(this.highestOfferPrice))
      {
        this.highestOfferPrice=Math.abs(theOffer.price);
      }
	  if (Math.abs(theOffer.price)< Math.abs(this.lowestOfferPrice))
      {
        this.lowestOfferPrice=Math.abs(theOffer.price);
      }
      this.addToDayOffer(theStartDate, theOffer);
    }
    
    this.xStat.endCall('getAllOfferNodes');   
    return theArray;
  }
 return null;
}

ApplicationOfferModel.prototype.round=function(aValue)
{
  var theValue = Math.abs(aValue)/100;
  return theValue;
}

ApplicationOfferModel.prototype.addToDayOffer=function(aDate, aOffer)
{ 
  
  var theDayOffer = null;
  if (!this.dayOffers[aDate])
  {
    theDayOffer = new DayOfferContainer();
    theDayOffer.date=this.getDate(aDate);
    this.dayOffers[aDate]=theDayOffer;  
  }
  this.dayOffers[aDate].addOffer(aOffer);
}

ApplicationOfferModel.prototype.getDate=function(aDateString)
{
  this.xStat.incCall('getDate');
  var thePos = aDateString.indexOf('-');
  var theSubstring = aDateString;
  var theLength=0;
  var theYear = theSubstring.substring(0,thePos);
  theLength=theSubstring.length;
  theSubstring = theSubstring.substring(thePos+1,theLength);
  thePos=theSubstring.indexOf('-');
  theLength=theSubstring.length;
  
  var theMonth = theSubstring.substring(0, thePos);
  if (theMonth.indexOf('0')==0)
  {
    theMonth=theMonth.substr(1,1);
  }
  theSubstring = theSubstring.substring(thePos+1,theLength);
  var theDay = theSubstring;
  
  if (theDay.indexOf('0')==0)
  {
    theDay=theDay.substr(1,1);
  }
 
  var theDD = Math.abs(theDay);
  var theMM = Math.abs(theMonth)-1;
  var theYYYY  = Math.abs(theYear);
  
  if (theDay == '1')
  {
    //alert(theDD+' - '+theMM+' - '+theYYYY);
  }
    
  
  var theDate = new Date(theYYYY, theMM, theDD, 12, 1, 1);
  
  //theDate.setDate();
  //theDate.setMonth();
  //theDate.setFullYear(Math.abs(theYear));
  //alert("Day="+Math.abs(theDay)+" Month="+Math.abs(theMonth)+" year="+Math.abs(theYear)+" Date = "+(theDate.getDate()+1)+"."+(theDate.getMonth()+1)+"."+theDate.getFullYear());
  this.xStat.endCall('getDate');
  return theDate;
}

ApplicationOfferModel.prototype.getPriceText=function(aTopListNo, aCount)
{
  var theNode = this.getTopOffer(aTopListNo);
  var theOffer = theNode.getOffer(aCount);
  if (theOffer)
   return theOffer.price;
  else
   return '0';
}

ApplicationOfferModel.prototype.getOfferPrice=function(anOfferId)
{
  var thePriceNode = this['reader'].getFirstChildNode(this.getAllOfferNodes()[anOfferId],"price");
  if (!thePriceNode)
  {
    return '0';
  }
  return this['reader'].getText(thePriceNode);
}


ApplicationOfferModel.prototype.calculateMaxOfferPrice=function(aTopOfferObject)
{
  this.xStat.incCall('calculateMaxOfferPrice');
  var theNodeValue = new Array();
  var theOffer;
  for (var i = 0;i<3; i++)
  { 
    
    theOffer = aTopOfferObject.getOffer(i);
    if (theOffer)
      theNodeValue[i] = theOffer.price;
  }
  
  var theValue = theNodeValue[0];
  for (var i=1;i<3;i++)
  {
    if(Math.abs(theNodeValue[i]) > Math.abs(theNodeValue[i-1]))
    {
      theValue=theNodeValue[i];
    }
  }
  this.xStat.endCall('calculateMaxOfferPrice');
  //alert("MaxOfferPrice:"+theValue);
  return theValue;
}

function getMultiNormalPriceText(aTopNum, aSub)
{
  var theNode = this.getTopOffer(aTopNum);
  if(theNode.getOffer(aSub))
    return theNode.getOffer(aSub).price;
  else
    return '0';
}


ApplicationOfferModel.prototype.getOfferId=function(aTopNum, aSub)
{
  var theNode = this.getTopOffer(aTopNum);
  if(theNode.getOffer(aSub))
    return theNode.getOffer(aSub).offerId;
  else
    return null;
}


ApplicationOfferModel.prototype.getTopListLength=function()
{
  if (this.getTopOfferNodes() != null)
    return this.getTopOfferNodes().length;
  else
    return 0;
}

ApplicationOfferModel.prototype.getTopOffer=function (aNumber)
{
  return this.getTopOfferNodes()[aNumber];
}





ApplicationOfferModel.prototype.getTopOfferDestName=function(anIndex)
{
  var theNode = this.getTopOfferNodes()[anIndex];
  
  if (theNode.getOffer(0))
    return theNode.getOffer(0).to;
  return '';
}

ApplicationOfferModel.prototype.getHighestPrice=function()
{
  return this.highestPrice;
}

ApplicationOfferModel.prototype.getLowestOfferPrice=function()
{
  return this.lowestOfferPrice;
}

ApplicationOfferModel.prototype.calculateOptimumNode=function(aTopOfferNumber)
{
  if(this.optimumNodes.length>aTopOfferNumber && this.optimumNodes[aTopOfferNumber]!= null)
  {
    return this.optimumNodes[aTopOfferNumber];
  }
  this.xStat.incCall('calculateOptimumNode');
  var theNode = this.getTopOffer(aTopOfferNumber);
  var theNodeValue = new Array();
  
  try {
    theNodeValue[0] = theNode.getOffer(0).price;
    theNodeValue[1] = theNode.getOffer(1).price;
    theNodeValue[2] = theNode.getOffer(2).price;
    }
  catch (anExc)
  {
    //GetValues(theNode);
    return null;
  }

  var i=0;
  var theNo=0;
  for (i=1;i<3;i++)
  {
    if(theNodeValue[i] < theNodeValue[i-1])
    {
      theNo=i;
    }
  }
  
  this.optimumNodes[aTopOfferNumber] = theNode.getOffer(theNo);
  if (!this.optimumNodes[aTopOfferNumber])
  {
    this.xStat.endCall('calculateOptimumNode');
    //alert("No optimum node found for id "+theIds[theNo]+" for topoffer"+this['reader'].getNodeAttributeValue(theNode,"id"));
    return null;
  }
  //else
  // alert("alert Optimum Node is: "+this.optimumNodes[aTopOfferNumber].nodeName+" "+theReader.getNodeAttributeValue(this.optimumNodes[aTopOfferNumber],"offerid"));
  this.xStat.endCall('calculateOptimumNode');
  return this.optimumNodes[aTopOfferNumber];
  
}

ApplicationOfferModel.prototype.getOptimumOfferId=function(aNumber)
{
  var theOptimumNode = this.calculateOptimumNode(aNumber);
  //7alert("The offer id node:"+theOfferNode.nodeName);
  if (theOptimumNode != null)
    return theOptimumNode.offerId;
  else
    return '';
}

ApplicationOfferModel.prototype.getOptimumPriceText=function(aNumber)
{
  var theOptimumNode = this.calculateOptimumNode(aNumber);
  if (theOptimumNode != null)
    return theOptimumNode.price;
  return '';
}


function TopOfferObject()
{
  this.topOfferId=null;
  this.destination = null;
  this.departure = null;
  this.offers = new Array();
  this.imgUrl=null;
}

TopOfferObject.prototype.getImgUrl=function()
{
  return this.imgUrl;
}

TopOfferObject.prototype.getId=function()
{
  return this.topOfferId;
}

TopOfferObject.prototype.setId=function(anId)
{
  this.topOfferId = anId;
}

TopOfferObject.prototype.getOffer=function(aNumber)
{
  return this.offers[aNumber];
}
/*
TopOfferObject.prototype.getOffer=function(aNumber)
{
  return this.offers[aNumber];
}
*/

TopOfferObject.prototype.setOffer=function(i, anOffer)
{
  this.offers[i] = anOffer;
}

TopOfferObject.prototype.getPrice=function(aNumber)
{ 
  return this.offer[aNumber].price;
}

/**
 *
 * FlightOffer Object - contains all flight relevant data
 */   

function FlightOffer()
{
  this.offerId='';
  this.flight='';
  this.offerer='';
  this.airline='';
  this.airlineShort='';
  this.price='';
  this.to='';
  this.from='';
  this.netto='';
  this.taxes='';
  this.fromIataCode='';
  this.toIataCode='';
  this.time='';
  this.date='';
  this.arrivalTime='';
  this.stop='';
  this.dateString='';
  this.dayOfferContainer=null;
}

FlightOffer.prototype.getDateString=function()
{
  return this.dateString;
}

FlightOffer.prototype.getNetto=function()
{
  return this.netto;
}

FlightOffer.prototype.getTaxes=function()
{
  return this.taxes;
}

FlightOffer.prototype.getStop=function()
{
  return this.stop;
}

FlightOffer.prototype.getAirline=function()
{
  return this.airline;
}

FlightOffer.prototype.getFlight=function()
{
  return this.flight;
}

FlightOffer.prototype.getAirlineShort=function()
{
  return this.airlineShort;
}

FlightOffer.prototype.getFrom=function()
{
  return this.from;
}

FlightOffer.prototype.getTo=function()
{
  return this.to;
}

FlightOffer.prototype.getFromIataCode=function()
{
  return this.fromIataCode;
}

FlightOffer.prototype.getToIataCode=function()
{
  return this.toIataCode;
}

FlightOffer.prototype.getTime=function()
{
  return this.time;
}

FlightOffer.prototype.getArrivalTime=function()
{
  return this.arrivalTime;
}

FlightOffer.prototype.getPrice=function()
{
  return this.price;
}

FlightOffer.prototype.getOfferId=function()
{
  return this.offerId;
}


FlightOffer.prototype.getDate=function()
{
  return this.date;
}

FlightOffer.prototype.isBefore=function(aOffer)
{
  var theFlag = (this.date.getYear()<aOffer.getYear()
                 &&this.date.getMonth()<aOffer.getMonth()
                 &&this.date.getDay()<aOffer.getDay());
  return theFlag;
}

FlightOffer.prototype.isAfter=function(aOffer)
{
  var theFlag = (this.date.getYear()>aOffer.getYear()
                 &&this.date.getMonth()>aOffer.getMonth()
                 &&this.date.getDay()>aOffer.getDay());
  return theFlag;
}

FlightOffer.prototype.setDayOfferList=function(aContainer)
{
  this.dayOfferContainer= aContainer;
}

FlightOffer.prototype.getDayOfferList=function()
{
  return this.dayOfferContainer;
}

function DayOfferContainer()
{
  this.minPrice=null;
  this.offers=new Array();
  this.date=null;
  this.bestOffer=null;
}


DayOfferContainer.prototype.addOffer=function(aOffer)
{
  if (aOffer)
  {
    this.offers[this.offers.length]=aOffer;
    aOffer.setDayOfferList(this);
    if (this.minPrice == null)
    {
      this.minPrice=aOffer.getPrice();
      this.bestOffer=aOffer;
      //alert("Best Offer set:" + this.date);
    }
    else
    {
      if (Math.round(this.minPrice)>Math.round(aOffer.getPrice()))
      {
        this.minPrice=aOffer.getPrice();
        this.bestOffer=aOffer;
        //alert("Best Offer replaced:" + this.date);
      }
    }
    
  }
  else
  {
    alert("No offer added");
  }
  
}

DayOfferContainer.prototype.getBestOffer=function()
{
  return this.bestOffer;
}

DayOfferContainer.prototype.getOffers=function()
{
  return this.offers;
}

DayOfferContainer.prototype.getDate=function()
{
  return this.date;
}



function AppStatisticElement()
{
/**
 *
 *>>>> <listStatistics>
>>>> <count/>
>>>> <highestPrice>633</highestPrice>
>>>> <maxPrice>633</maxPrice>
>>>> <monthName>Januar</monthName>
>>>> <monthInt id="01"/>
>>>> <monthDays id="31"/>
>>>> <from>Koeln</from>
>>>> <to>Dubrovnik</to>
>>>> <fromIataCode>CGN</fromIataCode>
>>>> <toIataCode>CDG</toIataCode>
>>>> </listStatistics> 
 */   
  this.highestPrice=null;
  this.maxPrice=null;
  this.fromIataCode=null;
  this.toIataCode=null;
  this.from=null;   
}

AppStatisticElement.prototype.getHighestPrice=function()
{
  return this.highestPrice;
}

AppStatisticElement.prototype.getMaxPrice=function()
{
  return this.maxPrice;
}

AppStatisticElement.prototype.getFromIataCode=function()
{
  return this.fromIataCode;
}

AppStatisticElement.prototype.getToIataCode=function()
{
  return this.ToIataCode;
}


AppStatisticElement.prototype.getFrom=function()
{
  return this.from;
}
