// ajaxScript.js
// is a JavaScript containging the functions that query the server
// and retrieve the new events in form of a string
// in which every line is a separate event
// with the properties: ActivityType, Latitude, Longitude, EventTime
// example : "1,47.40000000,-122.24000000,11:21:04 PM"
// This file also contains the functions & methods to transform the incoming string into JTVEvents


function JTVEvent(setActivityType, setLatitude, setLongitude)
        {        
            this.ActivityType = setActivityType;
            this.Latitude = setLatitude;
            this.Longitude = setLongitude;                       
        }
        
function CreateEvents(responseStr)
        {
            var myArray0 = responseStr.split('|');
            cacheDuration = (parseFloat(myArray0[1]) * 60000); // gets the cache duration in milliseconds
            maxPinDisplay = (parseFloat(myArray0[2])); // sets the max number of pins displayed on the map at the same time
            maxDisplayTime = (parseFloat(myArray0[3])); // sets the max display Time of a pin
            var myArray1 = myArray0[0].split(';');
            var myArray2 = new Array();
            var EventArray = new Array();
            
            for (i = 0 ; i < myArray1.length ; i++)
            {
                myArray2[i] = myArray1[i].split(',');
                EventArray[i] = new JTVEvent(myArray2[i][0], parseFloat(myArray2[i][1]), parseFloat(myArray2[i][2]));                
            }
            
            return EventArray;
         }

function GetXMLHttpObject()
        {
            var xmlHttp;
            
            try
            {
                // Firefox, Opera 8.0+, Safari
                xmlHttp=new XMLHttpRequest();
            }
            catch (e)
            {
                // Internet Explorer
                try
                {
                    // newer IE version 6.0+
                    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e)
                {                    
                        // older IE version 5.5+
                        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                }                   
            }
            
            return xmlHttp;            
        }
        
function RetrieveEvents()
        {          
            
            var xmlHTTP = GetXMLHttpObject();
            
            if (xmlHTTP == null)
            {
                //document.write('Your browser is not compatible!</br>We recommend :</br><a href="http://www.mozilla.com">Mozilla Firefox</a>');
                return;
            }
            
            xmlHTTP.onreadystatechange=function()
            {
                if (xmlHTTP.readyState == 4)
                {
                    if (xmlHTTP.status == 200)
                    {                           
                        LoadApp(xmlHTTP.responseText);
                    }
                    else
                    {                     
                        document.write("Error code : " + xmlHTTP.status);
                        return;
                    }
                }
            }
            
            xmlHTTP.open("GET", "JottTV.ashx", true);
            xmlHTTP.send(null);            
        }
        

   

        




 
