function goHome()
{
    top.location='../../default.aspx';
}


function openNearest(fromTop)
{
    url = "";
    
    if (fromTop == "false")
    {
        url += "../../";
    }
	
	top.location = url + "code/MasterFrame/MasterFrame.aspx?type=Nearest";

}

function openWhatInfo(fromTop)
{
    url = "";
    
    if (fromTop == "false")
    {
        url += "../../";
    }
	
	top.location = url + "code/MasterFrame/MasterFrame.aspx?type=WhatInfo";

}

function openWhatsNew()
{
	top.location = "code/MasterFrame/MasterFrame.aspx?type=WhatsNew";
}

function openWhatsNewFromCode()
{
	top.location = "../../code/MasterFrame/MasterFrame.aspx?type=WhatsNew";
}


function openHitCounter()
{
	top.location = "code/MasterFrame/MasterFrame.aspx?type=HitStats";
}

function openProfiler(fromTop)
{
    url = "";
    
    if (fromTop == "false")
    {
        url += "../../";
    }
	
	top.location = url + "code/MasterFrame/MasterFrame.aspx?type=Profiler";

}


function openBrowseSystem(fromTop)
{
    url = "";
    
    if (fromTop == "false")
    {
        url += "../../";
    }
	
	top.location = url + "code/MasterFrame/MasterFrame.aspx?type=BrowseSys";
}

function openReportArchive(fromTop)
{
    url = "";
    
    if (fromTop == "false")
    {
        url += "../../";
    }
	
	top.location = url + "code/MasterFrame/MasterFrame.aspx?type=ReportArchive";
}

function openRptWiz(fromTop)
{
    
    url = "";
    
    if (fromTop == "false")
    {
        url += "../../";
    }
	
	top.location = url + "code/MasterFrame/MasterFrame.aspx?type=ReportWizard";
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function openGettingStarted()
{
    //alert("This feature is coming soon...");
	window.open("GettingStarted.htm", "Help", "toolbar=no,directories=no,scrollbars=yes,location=no,status=no,menubar=no,resizable=yes,width=640,height=480");

}

function openHelp()
{
    //alert("This feature is coming soon...");
	window.open("../../helpMain.htm", "Help", "toolbar=no,directories=no,scrollbars=yes,location=no,status=no,menubar=no,resizable=yes,width=640,height=480");
}

function openHelpMain()
{
    //alert("This feature is coming soon...");
	window.open("helpMain.htm", "Help", "toolbar=no,directories=no,scrollbars=yes,location=no,status=no,menubar=no,resizable=yes,width=640,height=480");
}


function openHelp(section)
{
    //alert("This feature is coming soon...");
	window.open("../../helpMain.htm#" + section, "Help", "toolbar=no,scrollbars=yes,directories=no,location=no,status=no,menubar=no,resizable=yes,width=640,height=480");
}

function OpenMapHelp()
{
    openHelp('helpAnchor30');
}

function wopen(url, name, w, h)
{
w += 32;
h += 96;
 var win = window.open(url,
  name, 
  'width=' + w + ', height=' + h + ', ' +
  'location=no, menubar=no, ' +
  'status=no, toolbar=no, scrollbars=yes, resizable=yes');
 win.resizeTo(w, h);
 win.focus();
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

function openPrintWin()
{
	window.open(self.location + "&printWin=true");
}

function openMPTPrintWin()
{
window.open(self.location + "?printView=true");
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/


function openRptWizPrintWin()
{

	window.open("ViewReportDetails.aspx?printWin=true");
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

function downloadDynamicCSV(geogTypeID, layerGroupID, layerItemDate, isRptWizard, isPMTCsvDownload, suggestedFilename, isTemplate)
{
    //If is template is null then this has been called from the open csv link
    // rather than the download template link
    if (!isTemplate)
    {      
        this.location = "../../Code/CsvDownload/DynamicCsvDownload.aspx?geogTypeID=" + geogTypeID + "&suggestedFilename=" + suggestedFilename + "&layerGroupID=" + layerGroupID  + "&layerItemDate=" + layerItemDate + "&isRptWizard=" + isRptWizard + "&isPMTCsvDownload=" + isPMTCsvDownload + "&" + suggestedFilename + ".csv";
    }
    else
    {
        this.location = "../../Code/CsvDownload/DynamicCsvDownload.aspx?isTemplate=true&geogTypeID=" + geogTypeID + "&suggestedFilename=" + suggestedFilename + "&layerGroupID=" + layerGroupID  + "&layerItemDate=" + layerItemDate + "&isRptWizard=" + isRptWizard + "&isPMTCsvDownload=" + isPMTCsvDownload + "&" + suggestedFilename + ".csv";
    }
}

function downloadCSV(csvFileName, isTemplate)
{
    //If is template is null then this has been called from the open csv link
    // rather than the download template link
    if (!isTemplate)
    {      
        this.location = "../../Code/CsvDownload/CsvDownload.aspx?csvFileName=" + csvFileName;
    }
    else
    {
        this.location = "../../Code/CsvDownload/CsvDownload.aspx?isTemplate=true&csvFileName=" + csvFileName;
    }
    
}

function downloadReport(fileName)
{
	this.location = "../../Code/ReportArchive/ReportDownload.aspx?ReportName='" + fileName + "'";
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/



function hideAllImages()
{
	for (var i=0;i<document.images.length;i++)
	{
		document.images[i].style.display = 'none';
	}
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/


function hideAllTableSortRows()
{
	// Find all table rows with class 'mglResultsTableSortHeader' and make the sort row hidden
    if (!document.getElementsByTagName) return;
    tbls = document.getElementsByTagName("tr");
    for (ti=0;ti<tbls.length;ti++) {
        thisTblRow = tbls[ti];
        if (((' '+thisTblRow.className+' ').indexOf("mglResultsTableSortHeader") != -1)) {
            thisTblRow.style.display = 'none';      
        }
    }
}




/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Header steps text is updated here
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/


function updateHeaderSteps (branchNameText, stepNameText, branchImg, stepImg)
{	
	    top.header.location = "../HeaderFooter/header.aspx?branchName="+branchNameText+"&stepName="+stepNameText+"&branchImg="+branchImg+"&stepImg="+stepImg;	
}


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	metaData functions

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

var browserName = navigator.appName.substring ( 0, 9 );


// The click point - this will be refreshed each time the mouse is clicked
var x = 0;
var y = 0;

// Get the coordinates of a mouse click
document.onmousedown = getCoordinates;

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Get the coordinates of an event and disable the right click
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function getCoordinates( e ) {

	if (!e) var e = window.event;
	
	if (e.pageX || e.pageY) 	
	{
		x = e.pageX;
		y = e.pageY;
	}
	else if (e.clientX || e.clientY) 	
	{
		x = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		y = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}

//   x = document.body.scrollLeft + event.clientX;
//   y = document.body.scrollTop + event.clientY;   

}




/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Open the metaData iframe

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

function metaData(code, themeID, type, tableType, differentiate) {


		
		var top = y + 5;
		var left = 20;

		var windowWidth = '100%';

		//If differentiate the call to view metadata is from the right hand window (i.e in profiler section)
		// therefore use the x coordinate of the mouse click to locate the metadata window
		if (differentiate == "right")
		{
			left = 40;
			windowWidth = '50%';
		}
		else if (differentiate == "rightDetailPage")
		{
		    left = 0;
		    windowWidth = '100%';		
		}	
			
		document.getElementById("metaDataFrame").src = '../MetaData/_metadata.aspx?code=' + code + '&themeID=' + themeID + '&varType=' + type + '&tableType=' + tableType;
		
		document.getElementById("metaDataDiv").style.display = '';
		document.getElementById("metaDataDiv").style.width = windowWidth;
		document.getElementById("metaDataDiv").style.height = '500';
		document.getElementById("metaDataDiv").style.left = left;
		document.getElementById("metaDataDiv").style.top = top;
		

}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	closes the MetaData iframe

	Version History:
	5 February 2003 (EKS) - Added the Status variable, so that the metadata will load in the same window for the text only version
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function closeMetaData( ) {
	// the Text Only or not status

	var ie5=document.all&&document.getElementById;
	var ns6=document.getElementById&&!document.all;
	
	

	if ( ! ie5 && ! ns6 ) {
		window.close();
	} else {
		parent.document.getElementById("metaDataDiv").style.display="none";
	}
	
	//Wipe out the previously displayed version of the metadata. So when it next loads it 
	// wont be showing the wrong data as its loading
	parent.document.getElementById("metaDataFrame").src = '../../Blank.htm';
		
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+++++++++++++++++++++++
Image Hover functions (used in conjunction with the class MGLHoverImageLink.cs....if ya want!)
+++++++++++++++++++++++
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/


function img_on(imgName)
{
   if (document.images)
   {
   	imgOn = eval(imgName + "on.src");
	document [imgName].src = imgOn;
   }
}
function img_off(imgName)
{
   if (document.images)
   {
	imgOff = eval(imgName + "off.src");
	document [imgName].src = imgOff;
   }
}


var imgList = new Object();

function imgMOn(imgID, theImg)
{     	    
   if (document.images)
   {      
       if (imgList != null)
       {
           fullString = imgList[imgID];
           var splitArr = fullString.split("$%,");           
           theImg.src = splitArr[0];
           theImg.alt = splitArr[2];
       }
   }
}

function imgMOff(imgID, theImg)
{     	    
   if (document.images)
   {      
       if (imgList != null)
       {
           fullString = imgList[imgID];
           var splitArr = fullString.split("$%,");           
           theImg.src = splitArr[1];
           theImg.alt = splitArr[2];
       }
   }
}

function getElementsByClassName(clsName) 
{ 
	var arr = new Array(); 
	var elems = document.getElementsByTagName("*");
	for ( var cls, i = 0; ( elem = elems[i] ); i++ )
	{
		if ( elem.className == clsName )
		{
			arr[arr.length] = elem;
		}
	}
	return arr;
}

//window.onload = initialiseImages;
//function initialiseImages()
//{  	 
//    //For each img id in the imgOffList get all the 
//    // images in the document with that id and 
//    //  add their content in    
//    for (var i in imgList)
//	{
//	     
//	    //Get all the elements with a tag name 'img'
//	    var imgs = getElementsByClassName(i);
//       
//        for (ti=0;ti<imgs.length;ti++) 
//        { 
//            thisImg = imgs[ti];
//            
//            fullString = imgList[i]; 
//            
//            var splitArr = fullString.split("$%,");
//            
//            thisImg.src = splitArr[1];
//            thisImg.alt = splitArr[2];
//            thisImg.border = 0;
//            
//         //  thisImg.onmouseover = new function(e) {imgChange(splitArr[0],this);}
//         //  thisImg.onmouseout = new function(e) {imgChange(splitArr[1],this);}                  
//        }
//    }    
//}

function addImg(inpOnName, inpOffName, inpOnImgSrc, inpOffImgSrc, inpAltText)
{    
//alert(inpOnName + "," +inpOffName+ "," +inpOnImgSrc+ "," +inpOffImgSrc);	
    if (document.images)
    {                
        if (imgList[inpOffName] == null)
        {          
            imgList[inpOffName] = inpOnImgSrc + "$%," + inpOffImgSrc + "$%," + inpAltText;
        }
    }
}




/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+++++++++++++++++++++++
ADDITIONAL FUNCTIONS
+++++++++++++++++++++++
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
	var _oldColor;
	var _oldFontStyle;
	var _oldFontColor;
	var _oldFontWeight;
	var _oldForegroundColor;

	function SetNewColor(source)

    {

        _oldColor = source.style.backgroundColor;
        _oldFontStyle = source.style.fontStyle;
	    _oldForegroundColor= source.style.color;
	    _oldFontWeight= source.style.fontWeight;
        source.style.backgroundColor = '#F5F5F5';
        source.style.color = '#ffaa00';

 }

    function SetOldColor(source)

    {
        source.style.fontStyle = _oldFontStyle;
        source.style.backgroundColor = _oldColor;
        source.style.color = _oldForegroundColor;
        source.style.fontWeight = _oldFontWeight;


    }


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TRIM
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
		return "";
	} else {
		return TRIM_VALUE;
	}
} //End Function

function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		} else {
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	} //End While
	return strTemp;
} //End Function

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		} else {
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function


function DownloadPlugin() {
	window.open("http://www.adobe.com/svg/viewer/install/main.html");
}
