    var map = null;
    var pinID = 0;
    var postcode = "SK6 3AH";
    var zoomLevel = 17;
    var postcodeField = "";
    var latField = "";
    var lonField = "";
    var xmlDoc;

    var helptip = function () {
        var id = 'helptip';
        var top = 3;
        var left = 3;
        var maxw = 300;
        var speed = 10;
        var timer = 20;
        var endalpha = 95;
        var alpha = 0;
        var tt, t, c, b, h;
        var ie = document.all ? true : false;
        return {
            show: function (v, w) {
                if (tt == null) {
                    tt = document.createElement('div');
                    tt.setAttribute('id', id);
                    t = document.createElement('div');
                    t.setAttribute('id', id + 'top');
                    c = document.createElement('div');
                    c.setAttribute('id', id + 'cont');
                    b = document.createElement('div');
                    b.setAttribute('id', id + 'bot');
                    tt.appendChild(t);
                    tt.appendChild(c);
                    tt.appendChild(b);
                    document.body.appendChild(tt);
                    tt.style.opacity = 0;
                    tt.style.filter = 'alpha(opacity=0)';
                    document.onmousemove = this.pos;
                }
                tt.style.display = 'block';
                c.innerHTML = v;
                tt.style.width = w ? w + 'px' : 'auto';
                if (!w && ie) {
                    t.style.display = 'none';
                    b.style.display = 'none';
                    tt.style.width = tt.offsetWidth;
                    t.style.display = 'block';
                    b.style.display = 'block';
                }
                if (tt.offsetWidth > maxw) { tt.style.width = maxw + 'px' }
                h = parseInt(tt.offsetHeight) + top;
                clearInterval(tt.timer);
                tt.timer = setInterval(function () { tooltip.fade(1) }, timer);
            },
            pos: function (e) {
                var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
                var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
                tt.style.top = (u - h) + 'px';
                tt.style.left = (l + left) + 'px';
            },
            fade: function (d) {
                var a = alpha;
                if ((a != endalpha && d == 1) || (a != 0 && d == -1)) {
                    var i = speed;
                    if (endalpha - a < speed && d == 1) {
                        i = endalpha - a;
                    } else if (alpha < speed && d == -1) {
                        i = a;
                    }
                    alpha = a + (i * d);
                    tt.style.opacity = alpha * .01;
                    tt.style.filter = 'alpha(opacity=' + alpha + ')';
                } else {
                    clearInterval(tt.timer);
                    if (d == -1) { tt.style.display = 'none' }
                }
            },
            hide: function () {
                clearInterval(tt.timer);
                tt.timer = setInterval(function () { tooltip.fade(-1) }, timer);
            }
        };
    } ();

    var tooltip = function () {
        var id = 'tt';
        var top = 3;
        var left = 3;
        var maxw = 300;
        var speed = 10;
        var timer = 20;
        var endalpha = 95;
        var alpha = 0;
        var tt, t, c, b, h;
        var ie = document.all ? true : false;
        return {
            show: function (v, w) {
                if (tt == null) {
                    tt = document.createElement('div');
                    tt.setAttribute('id', id);
                    t = document.createElement('div');
                    t.setAttribute('id', id + 'top');
                    c = document.createElement('div');
                    c.setAttribute('id', id + 'cont');
                    b = document.createElement('div');
                    b.setAttribute('id', id + 'bot');
                    tt.appendChild(t);
                    tt.appendChild(c);
                    tt.appendChild(b);
                    document.body.appendChild(tt);
                    tt.style.opacity = 0;
                    tt.style.filter = 'alpha(opacity=0)';
                    document.onmousemove = this.pos;
                }
                tt.style.display = 'block';
                c.innerHTML = v;
                tt.style.width = w ? w + 'px' : 'auto';
                if (!w && ie) {
                    t.style.display = 'none';
                    b.style.display = 'none';
                    tt.style.width = tt.offsetWidth;
                    t.style.display = 'block';
                    b.style.display = 'block';
                }
                if (tt.offsetWidth > maxw) { tt.style.width = maxw + 'px' }
                h = parseInt(tt.offsetHeight) + top;
                clearInterval(tt.timer);
                tt.timer = setInterval(function () { tooltip.fade(1) }, timer);
            },
            pos: function (e) {
                var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
                var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
                tt.style.top = (u - h) + 'px';
                tt.style.left = (l + left) + 'px';
            },
            fade: function (d) {
                var a = alpha;
                if ((a != endalpha && d == 1) || (a != 0 && d == -1)) {
                    var i = speed;
                    if (endalpha - a < speed && d == 1) {
                        i = endalpha - a;
                    } else if (alpha < speed && d == -1) {
                        i = a;
                    }
                    alpha = a + (i * d);
                    tt.style.opacity = alpha * .01;
                    tt.style.filter = 'alpha(opacity=' + alpha + ')';
                } else {
                    clearInterval(tt.timer);
                    if (d == -1) { tt.style.display = 'none' }
                }
            },
            hide: function () {
                clearInterval(tt.timer);
                tt.timer = setInterval(function () { tooltip.fade(-1) }, timer);
            }
        };
    } ();

    function checkByParent(aId, aChecked) {
        var collection = document.getElementById(aId).getElementsByTagName('INPUT');
        for (var x = 0; x < collection.length; x++) {
            if (collection[x].type.toUpperCase() == 'CHECKBOX')
                collection[x].checked = aChecked;
        }
    }

    function expandPanels() {
        //alert('test');
        //try {
        //    $find('ccExpandPanel1').expandPanel;
         //   $find('ccExpandPanel2').expandPanel;
         //   $find('ccExpandPanel3').expandPanel;
         //   $find('ccExpandPanel4').expandPanel;
         //   $find('ccExpandPanel5').expandPanel;
         //   $find('ccExpandPanel6').expandPanel;
        //}
        //    catch (err) {
        //}

    }

    function pendingCount(oForm, ss) {
        var aElems = oForm.elements;
        var prepayCount = 0;
        var voucherCount = 0;

        for (var iI = 0; iI < aElems.length; iI++) {
            if (aElems[iI].type == 'checkbox') {
                if (aElems[iI].name.toString().match("chkIncludePrepay") == "chkIncludePrepay") {
                    if (aElems[iI].checked)
                        prepayCount++;
                }
                if (aElems[iI].name.toString().match("chkIncludeVoucher") == "chkIncludeVoucher") {
                    if (aElems[iI].checked)
                        voucherCount++;
                }
            }
        }
        if (prepayCount == 0 && voucherCount == 0) {
            for (var iI = 0; iI < aElems.length; iI++) {
                if (aElems[iI].type == 'hidden') {
                    if (aElems[iI].name.toString().match("hidPrepayCount") == "hidPrepayCount") {
                        prepayCount = aElems[iI].value;
                    }
                    if (aElems[iI].name.toString().match("hidVoucherCount") == "hidVoucherCount") {
                        voucherCount = aElems[iI].value;
                    }
                }
            }
        }

        var appendString = "";
        if (ss.toString() == "1")
            appendString = "\n\nThere are requests on this invoice from employees who do not have a signed salary amendment letter marked on their account";
            
        if (prepayCount == 0 && voucherCount == 0)
            return "You are about to approve all highlighted requests. Are you sure?" + appendString;
            
        return "You are about to request an invoice for " + voucherCount.toString() + " vouchers and " + prepayCount.toString() + " prepayments. Are you sure?" + appendString;
        
    }

    function previewTemplates() {
        window.open(unescape("/management/company/companyEmailList.aspx"), 'previewWin', 'width=550,height=700,left=0,top=0,toolbar=No,location=No,scrollbars=Yes,status=No,resizable=No,fullscreen=No');
    }

    function previewPending(companyId) {
        window.open(unescape("/management/company/pendingList.aspx?companyId=" + companyId), 'previewWin', 'width=550,height=700,left=0,top=0,toolbar=No,location=No,scrollbars=Yes,status=No,resizable=No,fullscreen=No');
    }

    function previewCreditNote(creditNoteId, companyId) {
        window.open(unescape("/management/shared/preview_creditnote.aspx?creditNoteId=" + creditNoteId + "&companyId=" + companyId), 'previewWin', 'width=950,height=600,left=0,top=0,toolbar=No,location=No,scrollbars=Yes,status=No,resizable=No,fullscreen=No');
    }    
    
    function previewInvoice(invoiceId)
    {
        window.open(unescape("/management/shared/preview_invoice.aspx?invoiceNumber=" + invoiceId),'previewWin','width=950,height=600,left=0,top=0,toolbar=No,location=No,scrollbars=Yes,status=No,resizable=No,fullscreen=No');
    }

    function previewInvoiceWithCompany(invoiceId, companyId) {
        window.open(unescape("/management/shared/preview_invoice.aspx?invoiceNumber=" + invoiceId + "&companyId=" + companyId), 'previewWin', 'width=950,height=600,left=0,top=0,toolbar=No,location=No,scrollbars=Yes,status=No,resizable=No,fullscreen=No');
    }

    function previewInvoiceRegen(invoiceId)
    {
        window.open(unescape("/management/shared/preview_invoice.aspx?regen=true&invoiceNumber=" + invoiceId), 'previewWin', 'width=950,height=600,left=0,top=0,toolbar=No,location=No,scrollbars=Yes,status=No,resizable=No,fullscreen=No');   
    }

    function previewPayroll(invoiceId, companyId)
    {
        window.open(unescape("/management/shared/preview_payroll.aspx?invoiceNumber=" + invoiceId + "&companyId=" + companyId), 'previewWin', 'width=950,height=600,left=0,top=0,toolbar=No,location=No,scrollbars=Yes,status=No,resizable=No,fullscreen=No');
    }

    function previewPayrollRegen(invoiceId, companyId)
    {
        window.open(unescape("/management/shared/preview_payroll.aspx?regen=true&invoiceNumber=" + invoiceId + "&companyId=" + companyId), 'previewWin', 'width=950,height=600,left=0,top=0,toolbar=No,location=No,scrollbars=Yes,status=No,resizable=No,fullscreen=No');
    }

    function previewPreInvoicePayrollRegen(companyId)
    {
        window.open(unescape("/management/shared/preview_payroll.aspx?regen=true&companyId=" + companyId), 'previewWin', 'width=950,height=600,left=0,top=0,toolbar=No,location=No,scrollbars=Yes,status=No,resizable=No,fullscreen=No');
    }

    function resetFormElements(oForm, sType)
    {
	    var aElems = oForm.elements;

	    for (var iI=0;iI<aElems.length;iI++)
	    {
		    if (aElems[iI].type == sType)
			    aElems[iI].checked = false;
	    }
    }
	
	function clearData(thisBox, value)
	{
	    if(thisBox.value ==(value))
	    {
            thisBox.value = ("");	    
	    }

	}
	
	function resetData(thisBox, value)
	{
		if(thisBox.value == (""))
	    {
            thisBox.value = value;
	    }
	}
    
    function previewVoucher(voucherId, companyId)
    {
        window.open(unescape("/management/shared/preview_voucher.aspx?voucherId=" + voucherId + "&companyId=" + companyId),'previewWin','width=950,height=600,left=0,top=0,toolbar=No,location=No,scrollbars=Yes,status=No,resizable=No,fullscreen=No');   
    }

    function FTGetRoute(routeStart, routeEnd)
    {  
        map = new VEMap('myMap');
        map.LoadMap();      
        map.GetRoute(routeStart,routeEnd,null,null,onGotRoute);
    }
    
    function FTLoadXML()
    {
        xmlDocLoc = document.getElementById('mapXML').innerHTML;
        if (window.ActiveXObject)
        {
            var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async="false";
            xmlDoc.loadXML(xmlDocLoc);
        
        } else {
        
        var parser=new DOMParser();
        var xmlDoc=parser.parseFromString(xmlDocLoc,"text/xml");
        
        }
        return(xmlDoc);
    }
     
    function FTGetMap()
    {
        var xmlDoc = FTLoadXML();
        var locs = new Array; 
        
        map = new VEMap('myMap'); map.LoadMap();
               
        var tracking = xmlDoc.documentElement;
                       
        for (var iNode = 0; iNode < tracking.childNodes.length; iNode++)
        {
               var thisPID = tracking.childNodes[iNode].childNodes[0].childNodes[0].nodeValue;
               var thisNme = tracking.childNodes[iNode].childNodes[1].childNodes[0].nodeValue;
               var thisLat = tracking.childNodes[iNode].childNodes[2].childNodes[0].nodeValue;
               var thisLon = tracking.childNodes[iNode].childNodes[3].childNodes[0].nodeValue;
               var thisAdd = tracking.childNodes[iNode].childNodes[5].childNodes[0].nodeValue;
               var thisLoc = new VELatLong(thisLat,thisLon);
               
               locs.push(thisLoc);
               
               var pin = new VEPushpin(thisPID, thisLoc, null, thisNme, thisAdd);
               map.AddPushpin(pin);              
        }            
            map.SetMapView(locs);
    }
    
    function zoomToPin(lat,lon)
    {
        var loc = new VELatLong(lat, lon);
        map.SetCenterAndZoom(loc, 16);
    }
    

//------------------------------------------------------------------------------------------------------------------------
// Form Map Controls -----------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------

    function GetMap(postcodeSource,latDest,lonDest)
    
    // This function takes 3 input IDs, so we know which input boxes on the screen to address.
    
    {  
        try
        {   
            map = new VEMap('myMap');
            
            // Initialise global input IDs
            
            postcodeField = document.getElementById(postcodeSource);
            latField = document.getElementById(latDest);
            lonField = document.getElementById(lonDest);
            
            if(postcodeField.value.length > 0)
            {
                postcode = postcodeField.value;
            } else {
                zoomLevel = 5;
            }
            
            map.Find('', postcode, 1, zoomMap);
            map.LoadMap();
            map.HideDashboard();
            map.AttachEvent("onclick", mapClick);
        }
        catch(err)
        {

        }
    }

    function updateMapFromPostcode()
    {
        if(postcodeField.value.length > 0)
        {
            zoomLevel = 17;
            postcode = postcodeField.value;
            map.Find('', postcode, 1, markNewLocation);
        }
    }
    
    function markNewLocation()
    {
        latField.value = map.GetCenter().Latitude;
        lonField.value = map.GetCenter().Longitude;
        zoomMap();
    }
    
    function zoomMap()
    {
        map.SetZoomLevel(zoomLevel);
        map.DeleteAllPushpins(); 
        AddPin(lonField.value, latField.value, '', '')       
    }
    
     function mapClick(e)
     {
        lonField.value = e.view.LatLong.Latitude;
        latField.value = e.view.LatLong.Longitude;
        map.SetCenter(e.view.LatLong);
        map.DeleteAllPushpins();      
        AddPin(e.view.LatLong.Longitude, e.view.LatLong.Latitude, '', '')
     }
     
//------------------------------------------------------------------------------------------------------------------------
// End Form Map Controls -------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------
   
    function loadPoiArray()
    {

    }

    function AddPin(thisLat, thisLong, thisTitle, thisDesc)
    {   
        var pin = new VEPushpin(pinID, new VELatLong(thisLong, thisLat), null, thisTitle, thisDesc);
        map.AddPushpin(pin);
        pinID++;
    }  

    function onGotRoute(route)
    {
        map.ZoomOut(3);
        var routeinfo="";
        var bg = 0;
        //routeinfo += "<p>Total distance: ";
        //routeinfo += route.Itinerary.Distance+" ";
        //routeinfo += route.Itinerary.DistanceUnit+"\n";
        
        routeinfo += "<table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" style=\"color:Black;background-color:White;width:355px;border-collapse:collapse;\">";

        var len = route.Itinerary.Segments.length;
        for(var i = 0; i<len ;i++)
        {
            routeinfo += "<tr><td style=\"background-color:";
            if ( bg == 0 ) { routeinfo += "#FFFFFF"; } else {routeinfo += "#F0F0F0"; }
            routeinfo += "\"><p>";
            if ( i == 0 || i == len - 1 ) { routeinfo += "<strong>"; } 
            routeinfo += route.Itinerary.Segments[i].Instruction+" ";
            if ( i == 0 || i == len - 1 ) { routeinfo += "</strong>"; } 
            routeinfo += "</p></td><td style=\"background-color:";
            if ( bg == 0 ) { routeinfo += "#FFFFFF"; } else {routeinfo += "#EEEEEE"; }
            routeinfo += "\"><p>";
            routeinfo += route.Itinerary.Segments[i].Distance;           
            routeinfo += " " + route.Itinerary.DistanceUnit;
            routeinfo += "</p></td></tr>";
            bg = bg + 1;
            if ( bg == 2 ){ bg = 0; }
        }
        
        routeinfo += "<table>";
        
        if(document.getElementById("routeDirections")){
        document.getElementById("routeDirections").innerHTML = routeinfo;
        }
    }   

