
function goHome()
{
    top.location='../../default.aspx';
}

function openTimeSeries()
{
	top.location = "../../code/MasterFrame/MasterFrame.aspx?type=TimeSeries";
}	

function openAnalysisTools()
{
	top.location = "../../code/MasterFrame/MasterFrame.aspx?type=AnalysisTools";
}	

function openDataVisToolsAdv(bool)
{
	top.location = '../../default.aspx';
}	

function StepBackFromProfiler()
{
	top.location = '../../default.aspx';
}

function StepBackFromReportWizard()
{
	top.location = '../../default.aspx';
}

function StepBackFromTimeSeries()
{
	top.location = '../../default.aspx';
}

function StepBackFromBrowseSys()
{
    top.location = '../../default.aspx';
}

function openDataVisToolsStd(bool)
{
	top.location = '../../default.aspx';
}	
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

function openHelp()
{
    top.header.OpenHelpWithAnchor();
	//window.open("../../helpMain.htm", "Help", "toolbar=no,directories=no,scrollbars=yes,location=no,status=no,menubar=no,resizable=yes,width=640,height=480");
}

function openFrontHelp()
{
	window.open("helpMain.htm", "Help", "toolbar=no,directories=no,scrollbars=yes,location=no,status=no,menubar=no,resizable=yes,width=640,height=480");
}

function openPMTHelp(section)
{
	window.open("MonitoringPerformanceToolHelp.htm#" + section, "Help", "toolbar=no,scrollbars=yes,directories=no,location=no,status=no,menubar=no,resizable=yes,width=640,height=480");
}

function openHelp(section)
{
    top.header.OpenHelpWithAnchor();
	//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()
{
    window.open("../../helpMain.htm#_Toc289265076", "Help", "toolbar=no,scrollbars=yes,directories=no,location=no,status=no,menubar=no,resizable=yes,width=640,height=480");
}


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()
{
    if (self.location.toString().indexOf("?") > -1)
    {
	    window.open(self.location + "&printView=true");
	}
	else
	{
	    window.open(self.location + "?printView=true");
	}
}

function openMPTPrintWin()
{
window.open(self.location + "?printView=true");
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/


function openRptWizPrintWin()
{

	window.open("ViewReportDetails.aspx?printerF=true");
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

function downloadDynamicCSV(geogTypeID, layerGroupID, layerItemDate, isRptWizard, isPMTCsvDownload, suggestedFilename, isTemplate, isStaging)
{
    var useStageing = new Boolean(false);
    if(typeof(isStaging) != "undefined" && isStaging != null)
    {
        if(isStaging != "false" && isStaging != "False" && isStaging != "FALSE")
        {
            useStageing = new Boolean(isStaging);
        }
    }

    //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 + "&isStaging=" + useStageing.toString() + "&" + suggestedFilename + ".csv";
    }
    else
    {
        this.location = "../../Code/CsvDownload/DynamicCsvDownload.aspx?isTemplate=true&geogTypeID=" + geogTypeID + "&suggestedFilename=" + suggestedFilename + "&layerGroupID=" + layerGroupID  + "&layerItemDate=" + layerItemDate + "&isRptWizard=" + isRptWizard + "&isPMTCsvDownload=" + isPMTCsvDownload + "&isStaging=" + useStageing.toString() + "&" + 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, reportID)
{
	this.location = "../../Code/ReportArchive/ReportDownload.aspx?ReportName='" + fileName + "'&ReportID=" + reportID + "";
}
function openDownloadFacGWin(tableName, facGroupName)
{	
	
	this.location = "../../Code/CsvDownload/DownloadFacilitiesGroup.aspx?TableName=" + tableName + "&FacilityGroupName=" + facGroupName + "";	
}



/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/



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) 
{
	if (branchNameText == "Administrator Tools")
	{
		top.header.location = "../HeaderFooter/DataAdminHeader.aspx";
	}
	else
	{
		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, isInAdmin) {


		
		//var top = y + 5;
		//var left = 20;

		//var windowWidth = '100%';
		
			
		document.getElementById("metaDataFrame").src = '../MetaData/_metadata.aspx?code=' + code + '&themeID=' + themeID + '&varType=' + type + '&tableType=' + tableType+ '&isInAdmin=' + isInAdmin;


		//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")
		{
		//Right main frame (mapWindow)
		
			//left = 40;
			//windowWidth = '50%';
			
				$.blockUI({ message: $('#metaDataFrame'), css: 
		            {   
		                height:  '60%', 
		                width: '60%',
		                left: '20%',
		                top:'20%'                     
                        
                    }                    
                }); 			
		}
		else if (differentiate == "rightDetailPage")
		{
		//Right (map details) frame
//		    left = 0;
//		    windowWidth = '100%';
				$.blockUI({ message: $('#metaDataFrame'), css: 
		            {   
		                height:  ($(window).height() - 50) + 'px', 
		                width: ($(window).width())  + 'px' ,
                        left: '0px',
                        top: '25px'                        
                    } 
                }); 
		    		
		}	
		else
		{
		    //Normal (left hand) frame
				$.blockUI({ message: $('#metaDataFrame'), css: 
		            {   
		                height:  ($(window).height() - 50) + 'px', 
		                width: ($(window).width() - 40)  + 'px' ,
                        left: '5%',
                        top: '25px'
                        
                    } 
                }); 
		}
		
//		var url =  '../MetaData/_metadata.aspx?code=' + code + '&themeID=' + themeID + '&varType=' + type + '&tableType=' + tableType+ '&isInAdmin=' + isInAdmin;
//        var horizontalPadding = 10;
//        var verticalPadding = 10;
//        $('<iframe id="externalSite" frameborder="0" class="externalSite" src="' + url + '" />').dialog({
//            title: 'Quick Links',
//            autoOpen: true,
//            width: 550,
//            height: 350,
//            modal: true,
//            resizable: false,
//            autoResize: true,
//            position: 'center',
//            close: function(event, ui) { closeMetaData(); },
//            overlay: {
//                opacity: 0.5,
//                background: "black"
//            }
//        }).width(550 - horizontalPadding).height(350 - verticalPadding);
			
		
		//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';
	
	parent.unBlockMetadata();
		
}

function unBlockMetadata()
{
    $.unblockUI();
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+++++++++++++++++++++++
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];
           if(fullString)
           {
               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];
           if(fullString)
           {
               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() {
	top.location="http://www.adobe.com/svg/viewer/install/main.html";
}


    function ShowProcessing() 
    {              
        ShowProcessingBlockUI();
         // $('#dialogProcessing').jqmShow();   
        
        return true;
    }    
    
    
    function CookieCheck()
{
	var cookieEnabled = (navigator.cookieEnabled) ? true : false;

	if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled)
	{ 
		document.cookie="testcookie";
		cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false;
	}

	return (cookieEnabled);
}

function HideProcessingBlockUI(thisFrameOnly)
{
    if (thisFrameOnly)
    {
        HideProcessingBlockUIWithinFrame(true);
    }
    else
    {
        try
        {        
            HideProcessingBlockUIWithinFrame();
        }catch(ex){}
    
        try
        {        
            top.main.HideProcessingBlockUIWithinFrame();
        }catch(ex){}
        
        try
        {        
            top.main.left.HideProcessingBlockUIWithinFrame();
        }catch(ex){}
        
        try
        {        
            top.main.MapWindow.HideProcessingBlockUIWithinFrame();
        }catch(ex){}
        
        try
        {        
            top.main.MapWindow.details.HideProcessingBlockUIWithinFrame();
        }catch(ex){}
    }
}

function HideProcessingBlockUIWithinFrame()
{
    $.unblockUI();
}

  function ShowProcessingBlockUI(thisFrameOnly)
  {
      if (thisFrameOnly)
      {
        ShowProcessingBlockUIWithinFrame(true);
      }
      else
      {
        try
        {        
        top.main.ShowProcessingBlockUIWithinFrame(true);
        }catch(ex){}
        
            try
        {        
        top.main.left.ShowProcessingBlockUIWithinFrame(false);
        }catch(ex){}
        
        try
        {        
        top.main.MapWindow.ShowProcessingBlockUIWithinFrame(true);
        }catch(ex){}
        
            try
        {        
        top.main.MapWindow.details.ShowProcessingBlockUIWithinFrame(false);
        }catch(ex){}
    }
    
  }
    
    function ShowProcessingBlockUIWithinFrame(showMessage, customMessage)
    {    
        try 
        {  
            if (showMessage)
            {
                var customMessageTxt = "Loading...";  
                if (typeof customMessage != "undefined")
                {              
                    customMessageTxt = customMessage;             
                }            
                
                $.blockUI({ message: "<div class='bUIpageloading'>"+ customMessageTxt +"</div><div class='bUIpageloadingImg'></div>",
                    css: { backgroundColor:"#dddddd"  } 
                 }); 
            }
            else
            {
                $.blockUI({message: "", css: { backgroundColor:"#dddddd"  } 
                });                
            }
        }
        catch(er)
        {
        }
        
        return true;     
    }
    
    
    
//PDF download modal dialog
function ShowModalPanelPdf(rootPath)
{   
    $.blockUI({ message: $('#dialogProcessing') , css: {top:'50px',left:'2px', width: '210px', backgroundColor:"#ffffff"}
                });
    unblocked = false;
   
    CheckResponseHide(rootPath);
    
    //Got to return this so that the page will continue
    return true;
}

var maxInterval = 10000
var unblocked = false;

function CheckResponseHide(rootPath)
{       
    //See if the pdf download is complete (wait 1 sec for postback to happen)
    setTimeout("modalSndReq('"+ rootPath +"')", 1000);  
    
    setTimeout('HideModalPanel()', maxInterval);    
}

function HideModalPanel()
{
    if (!unblocked)
    {
        $.unblockUI();   
        unblocked = true;
    }
    
    //Got to return this so that the page will continue
    return true;
}

function modalCreateRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == 'Microsoft Internet Explorer'){
        ro = new ActiveXObject('Microsoft.XMLHTTP');
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

function modalSndReq(rootPath) 
{
       function modalHandleResponse()
       {
             try
             {
                var response = http.responseText;
                 
                if (response != null && response == "finished")
                {
                    HideModalPanel();
                }
             }
             catch(er)
             {                
             }    
       }
     
        var http = null;
        http = modalCreateRequestObject();

        var rand_no = Math.random();     
        
        var urlPoll = "";
        urlPoll = rootPath + "PdfDownloadCompleteCheck.aspx";
      
        http.open("GET", urlPoll + "?tmp=" + rand_no ,true);
                             
        http.onreadystatechange = modalHandleResponse;
        http.send(null);
}


function ResizeFont(percentage)
{
    try 
    {  
        document.body.style.fontSize = "'" + percentage + "%'"; 
        alert();
    }
    catch(er)
    {
   
        
    }
}

function SubscribeStat(aDlLayerID) {
  
  var tReq = null;
  if(typeof XMLHttpRequest == "undefined" || XMLHttpRequest == null)
  {
    tReq = new ActiveXObject('Microsoft.XMLHTTP');
  }
  else
  {
    tReq = new XMLHttpRequest();
  } 
  
  tReq.open("GET","../../Code/Subscription/Subscription.aspx?layerID=" + aDlLayerID, false );
  tReq.send(null);
  
  var tResults = tReq.responseText.split(";");
  var tMessage = "Error";
  var tColour = '#000';
  
  if(tResults.length > 1)
  {
    if(tResults[0] == "true")
    {
        tColour = '#022';
    }
    else
    {
        tColour = '#200';
    }    
  }     

    //var tSubsLink = document.getElementById("subs" + aDlLayerID);
    //tSubsLink.style.display = "none"; //Do not hide button.
    
    if(tResults[0] == "true" || tResults[0] == "false")
    {    
        $.blockUI({ 
            message: tResults[1], 
            fadeIn: 700, 
            fadeOut: 700, 
            timeout: 5000, 
            showOverlay: false, 
            centerY: false, 
            css: { 
                width: '300px',
                height: '140px',
                top: '70%', 
                left: '10px', 
                right: '', 
                border: 'none', 
                padding: '5px', 
                backgroundColor: tColour, 
                '-webkit-border-radius': '10px', 
                '-moz-border-radius': '10px', 
                opacity: .9, 
                color: '#fff' 
            } 
        }); 
    }
    
  
}
