/*
 * $Name:  $
 */



var detect = navigator.userAgent.toLowerCase();
var OS,browser2,version,total,thestring;

if (checkIt('konqueror'))
{
	browser2 = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser2 = "Safari"
else if (checkIt('omniweb')) browser2 = "OmniWeb"
else if (checkIt('opera')) browser2 = "Opera"
else if (checkIt('webtv')) browser2 = "WebTV";
else if (checkIt('icab')) browser2 = "iCab"
else if (checkIt('msie')) browser2 = "Internet Explorer"
else if (!checkIt('compatible'))
{
	browser2 = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser2 = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}





/*
 * Browser detection code
 */
function Browser ()
{


    var name = navigator.appName;
    
	//window.console.log(name);
			        
			            
    if (name == "Netscape")
        this.name = "ns";
    else if (name == "Microsoft Internet Explorer")
        this.name = "ie";

    this.version = navigator.appVersion;
    this.vMajor  = parseInt(this.version);
    this.isNS    = (this.name =="ns" && this.vMajor >= 4);
    this.isNS4   = (this.name =="ns" && this.vMajor == 4);
    this.isNS6   = (this.name =="ns" && this.vMajor == 5);
    this.isIE    = (this.name =="ie" && this.vMajor >= 4);
    this.isIE4   = (this.version.indexOf ('MSIE 4')   >0);
    this.isIE5   = (this.version.indexOf ('MSIE 5')   >0);
    
    this.isSafari = (this.name =="safari");
    this.isDOM   = (document.createElement
                    && document.appendChild
                    && document.getElementsByTagName) ? true : false;

    var ua = navigator.userAgent.toLowerCase();
    if (ua.indexOf ("win") > - 1)
        this.platform = "win";
    else if (ua.indexOf("mac") > -1)
        this.platform = "mac";
    else
        this.platform="other";
}
var browser = new Browser;

/*
 * Map control code
 */
function Map (id, level, sessionId)
{
    this.id        = id;
    this.level     = level;
    this.sessionId = sessionId;
    this.element   = document.getElementById (id);
    this.offset_x  = 0;
    this.offset_y  = 0;

    if (this.element) {
        var el = this.element;
        this.url = el.src;
        if (browser.isDOM && !browser.isIE) {
            while (el.offsetParent) {
                this.offset_x += el.offsetLeft;
                this.offset_y += el.offsetTop;
                el = el.offsetParent;
            }
        }
    }

    this.recenter = function (x, y)
    {
        if (this.element) {
            this.element.src = this.url + "&mapbrowse=center&x=" + (x - this.offset_x) + "&y=" + (y - this.offset_y) + "&rand=" + Math.random ();
        }
    };
    this.zoom = function (level)
    {
        if (this.element) {
            this.element.src = this.url + "&mapbrowse=zoom_" + level + "&rand=" + Math.random ();
            this.level = level;
        }
    };

    this.pan = function (dir)
    {
        if (this.element) {
            this.element.src = this.url + "&mapbrowse=pan_" + dir + "&rand=" + Math.random();
        }
    };

    this.recenterzoom = function (x, y)
    {
        if (this.element) {
           this.element.src = this.url + "&mapbrowse=center_zoom&x=" + (x - this.offset_x) + "&y=" + (y - this.offset_y) + "&rand=" + Math.random ();
            if (map.level < 10) {
                ++this.level;
                showZoomState ();
                showVendor ();
            }
        }
    };

    this.identify = function (x, y)
    {
        url = window.location.protocol + "//"
            + window.location.host
            
			//+ '/travel-tools/directions/bubble/index.aspx'
			//+ '?id='
			
			//+ '/visitpa/tripgenerator/advantage.jsp'
            + '/TripGenerator.aspx'
			+ '?template=identify&transaction=locMap&identifyIcon='
			+ this.sessionId
            + '&x=' + (x - this.offset_x) + '&y=' + (y - this.offset_y);

        var width  = 280;
        var height = 280;
        //infoWindow = window.open (url,
                   //Math.floor (Math.random () * 100000),
                   //"height=" + height + ",width=" + width + ",toolbar=no,scrollbars=yes,resize=yes");
        //infoWindow.moveTo ((screen.width - width) / 2, (screen.height - height) / 2);
    };
}

var map;



function mqaMapClick2 (e)
{
    var x, y;
    	if (!e) var e = window.event;
    	
    if (browser.isIE) {
        if (!(event.button == 1 || (browser.platform == "mac" && event.button == 0))) return;
        x = event.offsetX;
        y = event.offsetY;
        //window.console.log("browser isIE true");
    } 

	else if (e.clientX || e.clientY)
	{
			       // window.console.log("doing document.body.scrollLeft");
		x = e.clientX + document.body.scrollLeft;
		y = e.clientY + document.body.scrollTop;
	}
	
    else if (e.pageX || e.pageY)
	{
		x = e.pageX;
		y = e.pageY;
		        //window.console.log("doing pagex, pagey");
	}

			        //window.console.log("e.clientX " + e.clientX);
			        //window.console.log("e.clientY " + e.clientY);
			        		
			        //window.console.log("e.pageX " + e.pageX);
			        //window.console.log("e.pageY " + e.pageY);
			        			        		    
			        //window.console.log("document.body.scrollLeft " + document.body.scrollLeft);
			        //window.console.log("document.body.scrollTop " + document.body.scrollTop);
			        
			        
    if (document.mapClick.clickAction[0].checked) {
        // Zoom
        mqaMapZoomIn ();
    } else if (document.mapClick.clickAction[1].checked) {
        // Recenter
        map.recenter (x, y)
    } else if (document.mapClick.clickAction[2].checked) {
        // Identify Icon
        if (document.mapClick.clickAction[2].value == 'identify') {
            //map.identify (x, y);
        } else {
            map.recenterzoom (x, y);
        }
        
	/*
	*    PCR, added additional else if to test for identify clicks 
	*/        
    } else if (document.mapClick.clickAction[3].checked) {
        // Identify Icon

            //map.identify (x, y);

    }
}



function doSomething(e)
{
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		posx = e.clientX + document.body.scrollLeft;
		posy = e.clientY + document.body.scrollTop;
	}
	// posx and posy contain the mouse position relative to the document
	// Do something with this information
}

function mqaMapClick (e)
{
    var x, y;
    if (browser.isIE) {
        if (!(event.button == 1 || (browser.platform == "mac" && event.button == 0))) return;
        x = event.offsetX;
        y = event.offsetY;
        
    } else if (browser2 == 'Safari')  {
    			        window.console.log("in safari!");
            if (e.which != 1) return;
        x = e.pageX + 3;
        y = e.pageY - 24;
    } else if (browser.isDOM) {
        if (e.which != 1) return;
        x = e.pageX + 3;
        y = e.pageY;
    }
    	//window.console.log("x " + x);
    if (document.mapClick.clickAction[0].checked) {
        // Zoom
        mqaMapZoomIn ();
    } else if (document.mapClick.clickAction[1].checked) {
        // Recenter
        map.recenter (x, y)
    } else if (document.mapClick.clickAction[2].checked) {
        // Identify Icon
        if (document.mapClick.clickAction[2].value == 'identify') {
            //map.identify (x, y);
        } else {
            map.recenterzoom (x, y);
        }
        
	/*
	*    PCR, added additional else if to test for identify clicks 
	*/        
    } else if (document.mapClick.clickAction[3].checked) {
        // Identify Icon

            //map.identify (x, y);

    }
}
function mqaMapInit (id, level, sessionId)
{
    map = new Map (id, level, sessionId);
    if (map.element) {
        if (browser.isIE) {
            map.element.onmouseup = mqaMapClick;
        } else if (browser.isDOM) {
            map.element.addEventListener ("mouseup", mqaMapClick, true);
        }
        showZoomState ();
        showVendor ();
    }
}

function mqaMapZoom (level)
{
    if (! map) {
        alert ('you must call mqaMapInit(mapurl) before you can call this function');
    } else {
        map.zoom (level);
        showZoomState ();
        showVendor ();
    }
}

function mqaMapZoomIn (name)
{
    if (map.level < 10)
        mqaMapZoom (map.level + 1);
}
function mqaMapZoomOut (name)
{
    if (map.level > 1)
        mqaMapZoom (map.level - 1);
}

function showZoomState ()
{
    for (var i = 1; i <= 10; ++i) {
        var image = i == map.level ? 'zoom_on.gif' : 'zoom.gif';
        eval ("document.zoom" + i + ".src='/mqimages/" + image + "'");
    }
}

function showVendor ()
{
    if (! document.vendor) return;

    if ((map.level <= 10) && (map.level >= 6))
    {
      var vendImage = 'navteq.gif';
    } else {
      var vendImage = 't.gif';
    }
    eval ("document.vendor.src='/mqimages/" + vendImage + "'");
}

function mqaMapPan (dir)
{
    if (! map) {
        alert ('you must call mqaMapInit(mapurl) before you can call this function');
    } else {
        map.pan (dir);
    }
}

