// JavaScript Document (a tag attribute rel="external") - this is required for opening links in a new window... for XHTML target="_blank" (or whatever... is no longer a supported attribute)
// Open External Links as Blank Targets via Unobtrusive JavaScript
// http://perishablepress.com/press/2007/11/20/open-external-links-as-blank-targets-via-unobtrusive-javascript/

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (
			anchor.getAttribute("href") && (
			anchor.getAttribute("rel") == "external" || 
			anchor.getAttribute("rel") == "external nofollow" ||
			anchor.getAttribute("rel") == "nofollow external" )
			)
		anchor.target = "_blank";
	}
}
//window.onload = function() {
//	externalLinks();
//}

// map size settings
var resizeTimer;
var currentWidth;
function setDivSize() {
    if (browser.isLessThanIE6) {
         document.getElementById('unsupportedBrowserMessageDiv').style.display = '';
    } else if (browser.isIE6x) {
        clearTimeout(resizeTimer);
        resizeTimer = window.setTimeout(doSetDivSize,0);
    } else {
        doSetDivSize();
    }
}

function doSetDivSize() {
    clearTimeout(resizeTimer);
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        var theNum = 20;
        if (!browser.isWin || !browser.isWin32) {
            theNum = 30;
        } else if (browser.isFirefox) {
            theNum = 16;
        } else if (browser.isOpera) {
            theNum = 17;
        }
            myWidth = window.innerWidth-theNum;
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth-4;    //-18
        myHeight = document.documentElement.clientHeight;
        try {
            if(myWidth == currentWidth) {
                return;
            } else {
                currentWidth = myWidth;
            }
        } catch(err) {
        }
    }
    document.getElementById('map').style.width = myWidth-212+"px";
    try {
        document.getElementById('noMapLayer').style.width = myWidth-212+"px";
    } catch(err) { // div might not have been created yet
    }
    document.getElementById('messageContainer').style.width = myWidth-212+2+"px";
    if (myHeight < 580) {
        document.getElementById('map').style.height = 365+"px";
        try {
            document.getElementById('noMapLayer').style.height = 365+"px";
        } catch(err) { // div might not have been created yet
        }
    } else {
        document.getElementById('map').style.height = myHeight-145+"px"; //-235
        try {
            document.getElementById('noMapLayer').style.height = myHeight-145+"px"; //-235
        } catch(err) { // div might not have been created yet
        }
    }
    if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        document.getElementById('corporate-links').style.display = 'none';
        document.getElementById('corporate-links').style.display = '';
    }
}

// set body size in IE6 & IE5up
function setIE6BodyWidth() {
    if (browser.isIE6x) {
        if (document.getElementById('map') == null){
            var bodyWidth = document.documentElement.clientWidth;
            if (bodyWidth > 990) {
                document.getElementById('template-9').style.width = (bodyWidth) + "px";
            } else {
                document.getElementById('template-9').style.width = "990px";
            }
        } else {
            document.getElementById('template-9').style.width = "";
        }
    }
}

// legend
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function showHideLegend() {
    if (browser.isLessThanIE6) {
        location.href = 'help#Key-to-Symbols';
    } else {
        if (document.getElementById('DHTMLlegend').style.display == 'none') {
            document.getElementById('DHTMLlegend').innerHTML = '<table><thead><tr><th colspan="2">Roadworks status</th></tr></thead><tbody><tr><td><img height="34" alt="Works in progress" src="/pr_static/images/legend/wip.gif" width="34" /></td><td>Works in progress</td></tr><tr><td><img height="34" alt="Works proposed" src="/pr_static/images/legend/wp.gif" width="34" /></td><td>Works proposed</td></tr><tr><td><img height="34" alt="Works completed" src="/pr_static/images/legend/wc.gif" width="34" /></td><td>Works completed</td></tr><tr><td><img height="34" alt="Works cancelled" src="/pr_static/images/legend/cancelled.gif" width="34" /></td><td>Works cancelled</td></tr></tbody></table><table><thead><tr><th colspan="2">Roadworks owner type</th></tr></thead><tbody><tr><td><img height="34" alt="Works owner type borough" src="/pr_static/images/legend/proBor.gif" width="34" /></td><td>Borough</td></tr><tr><td><img height="34" alt="Works owner type communications company" src="/pr_static/images/legend/procom.gif" width="34" /></td><td>Communications</td></tr><tr><td><img height="34" alt="Works owner type electricity company" src="/pr_static/images/legend/proElec.gif" width="34" /></td><td>Electricity</td></tr><tr><td><img height="34" alt="Works owner type gas company" src="/pr_static/images/legend/proGas.gif" width="34" /></td><td>Gas</td></tr><tr><td><img height="34" alt="Works owner type Highways Agency" src="/pr_static/images/legend/proHA.gif" width="34" /></td><td>Highways Agency</td></tr><tr><td><img height="34" alt="Works owner type Network Rail" src="/pr_static/images/legend/proNR.gif" width="34" /></td><td>Network Rail</td></tr><tr><td><img height="34" alt="Works owner type other" src="/pr_static/images/legend/proOth.gif" width="34" /></td><td>Other</td></tr><tr><td><img height="34" alt="Works owner type Transport for London" src="/pr_static/images/legend/proTFL.gif" width="34" /></td><td>Transport for London</td></tr><tr><td><img height="34" alt="Works owner type unknown" src="/pr_static/images/legend/proUnk.gif" width="34" /></td><td>Unknown</td></tr><tr><td><img height="34" alt="Works owner type water company" src="/pr_static/images/legend/proWat.gif" width="34" /></td><td>Water</td></tr></tbody></table><table><thead><tr><th colspan="2">Event type</th></tr></thead><tbody><tr><td><img height="34" alt="Event active" src="/pr_static/images/legend/eventActive.gif" width="34" /></td><td>Active</td></tr><tr><td><img height="34" alt="Event timetabled" src="/pr_static/images/legend/eventScheduled.gif" width="34" /></td><td>Timetabled</td></tr></tbody></table>';
            document.getElementById('DHTMLlegend').style.display = '';
            document.getElementById('KTSText').innerHTML = 'Key to symbols (<strong>hide</strong>)';
        } else if (document.getElementById('DHTMLlegend').style.display == '') {
            document.getElementById('DHTMLlegend').style.display = 'none';
            document.getElementById('DHTMLlegend').innerHTML = '';
            document.getElementById('KTSText').innerHTML = 'Key to symbols';
        }
    }
}