/*
* File: poncodeapi.js
* Author: Adrian Browne
* Copyright: 2009 PON Technology Limited
* Date: 2009-09-30
* Purpose: To compute an Irish post code (poncode) from Latitude/Longitude or Easting/Northing
* 
* This program is licensed software; you may not redistribute it nor 
* modify it under the terms of the GNU General Public License 
* as published by the Free Software Foundation; either version 2 
* of the License, or (at your option) any later version.
* 
* This program is distributed in the hope that it will be useful, 
* but WITHOUT ANY WARRANTY; without even the implied warranty of 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
* GNU General Public License for more details: 
* http://www.gnu.org/licenses/gpl.html
*
*/

// Public functions to encode / decode Loc8code

    // Object to represent a point
    function poncPoint(){
	this.poncode="";
	this.latitude=0;
	this.longitude=0;
	this.easting=0;
	this.northing=0;
	this.range=0;
    }

    // return: PON code
    function PONCfromLL(latitude,longitude){  // lat, lng as decimal degrees
	pp = new poncPoint;
    	pp.latitude=latitude*1.0; pp.longitude=longitude*1.0;
	return PONCfromLLPoint(pp);
    }
    function PONCfromITM(east,north) {
	pp = new poncPoint;
    	pp.northing=north; pp.easting=east;
	return PONCfromENPoint(pp);
    }
    function PONCfromLLPoint(pp) {
	return PONCfromENPoint(NEfromLatLong(pp));
    }
    function PONCfromENPoint(pp) {
	return gpsi_calcPONC8(pp);
    }

    //return: poncPoint
    function LLfromPONC(ponc) { // ponc:AAA-99CAA
	return LLfromNE(ITMfromPONC(ponc));
    }
    //return: poncPoint
    function ITMfromPONC(ponc) { // ponc:AAA-99CAA
	pp = new poncPoint;
	pp.poncode=ponc;
	return gpsi_calcEN8(pp);
    }

