var win = null; // Must declare for closeDep to work when win doesn't exist
var clockID = 0;

// *****************************************************
// Functions to save position on page across postbacks
// *****************************************************
function SmartScroller_GetCoords()
   {
      var scrollX, scrollY;
      
      if (document.all)
      {
         if (!document.documentElement.scrollLeft)
            scrollX = document.body.scrollLeft;
         else
            scrollX = document.documentElement.scrollLeft;
               
         if (!document.documentElement.scrollTop)
            scrollY = document.body.scrollTop;
         else
            scrollY = document.documentElement.scrollTop;
      }   
      else
      {
         scrollX = window.pageXOffset;
         scrollY = window.pageYOffset;
      }
     objx= document.getElementById('xCoord');
     objy= document.getElementById('yCoord');
     
      objx.value = scrollX;
      objy.value = scrollY;
   }
   
   function SmartScroller_Scroll()
   {
	  objx= document.getElementById('xCoord');
	  objy= document.getElementById('yCoord');
      var x = objx.value;
      var y = objy.value;
      window.scrollTo(x, y);
   }

// *****************************************************
// Functions to disable non-menu navigation
// *****************************************************


function disableNonmenuNav()
		{
		javascript:window.history.forward(1);
		var nav = window.Event ? true : false; 
		if (nav) { 
		window.captureEvents(Event.KEYDOWN); 
		window.onkeydown = NetscapeEventHandler_KeyDown; 
		} else { 
		document.onkeydown = MicrosoftEventHandler_KeyDown; 
		} 
		}

		function NetscapeEventHandler_KeyDown(e) { 
		if (e.which == 13 && e.target.type != 'textarea' && e.target.type != 'submit') { return false; } 
		return true; 
		} 

		function MicrosoftEventHandler_KeyDown() { 
		if (event.keyCode == 13 && event.srcElement.type != 'textarea' && event.srcElement.type != 'submit') 
		return false; 
		return true; 
		}
// *****************************************************



function launch()
	{
		objPage = document.getElementById('pageString');	
		objPage.value = 'Settings';
		__doPostBack('lbPage','');
	}


function NewObj(url) 
{
	 objPage = document.getElementById('pageString');
	 objPage.value = url;
	 __doPostBack('lbPage','');			  
}


function ConfirmIt(msg2,act)
   {
    if (confirm(msg2)) 
        {
        setAction(act);
        return true;
        }
    else
        return false;
   }
 
function ConfirmDelete(x,msg1,msg2, act) {
		   if (x == -1)
		   alert(msg1);
		   else
		   {
		   if (confirm(msg2)) 
		   {      
			  setAction(act);
			  __doPostBack('lbPage','');		
		   } //end confirmed clause
		  } //end else clause
	}
	
function ConfirmDeleteAction(x) {
	if (confirm('Are you sure?')) 
		   {      
			  setAction(x);
			  __doPostBack('lbPage','');		
		   }
	}
	
function ConfirmDeleteAction2(x,y) {
	if (confirm('Are you sure?')) 		   
			  setAction(x);			  		   
        else
		      setAction(y);	
	}
	
function AreYouSure(arg) {
	objSure = document.getElementById('areyousureValue');
	if (confirm('Are you sure?')) 
	{objSure.value = arg;}
	}
	
function genNew(istr) {
	val = document.getElementById('tbName');
	val2= document.getElementById('newName');
	y = val.value;
	val2.value = y;
	if (y==null) 
		x=0;
	else
		x = y.length ;	
	if (x<3)
		{
		var msg1 = '';
		msg1 += 'Please enter a descriptive name ';
		msg1 += '\nfor the new ' + istr + ' that is between '
		msg1 += '\n3 and 40 characters in length.';
		alert(msg1);
		}
	else
	{setAction(999); //signal create new
	__doPostBack('','');		
	}
}


function popupScen(URL) {
	winvars='toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=850,height=480,left = 60,top = 84, dependent=yes';
	win = window.open(URL, 'scenWindow', winvars); // a window object
	win.focus();
}

function popUpUserHelp() {
	winvars='toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=980,height=620,left = 5,top = 5, dependent=yes';
	win = window.open('help/userman/default.htm', 'helpUser', winvars); // a window object
	win.focus();
}

function popUpReference() {
	winvars='toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=980,height=620,left = 5,top = 5, dependent=yes';
	win = window.open('help/helpref/default.htm', 'helpRef', winvars); // a window object
	win.focus();
}


function popUpAbout() {
	winvars='toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=710,height=200,left=100,top = 150, dependent=yes';
	win = window.open('about.htm', 'aboutWindow', winvars); // a window object
	win.focus();
}

function popUpAbout2() {
	winvars='toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=710,height=200,left=100,top = 150, dependent=yes';
	win = window.open('../about.htm', 'aboutWindow', winvars); // a window object
	win.focus();
}

function popupRes(URL) {
	winvars='toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=900,height=520,left = 60,top = 84, dependent=yes';
	win = window.open(URL, 'resWindow', winvars); // a window object
	win.focus();
}

function popupQuickImport() {
	winvars='toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=900,height=520,left = 60,top = 84, dependent=yes';
	win = window.open('QuickImport.aspx', 'QuickImport', winvars); // a window object
	win.focus();
}

function downloadMe(url,val)
    {                    
    var params = 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=700,height=300,left = 60,top = 84, dependent=1';
    abc=window.open('','Downloader', params);    
    var msg0="<head><title>GradeDec.Net - Federal Railroad Administration</title>";
    msg0 += "<link href='Styles.css' type='text/css' rel='stylesheet'/></head>";
    msg0 += "<body class='yellow'>";
    var msg1 = "<div><h3>GradeDec.Net - Close this window after downloading file</h3></div>";
    var msg3 = "<br /><div>";
    msg3 += "<a href=";
    msg3 += url;
    msg3 += ">Click here</a> to download the file.</div></body>";
    abc.document.write(msg0, msg1,msg3);    
    }
    

function popUpAdmin(URL) {
	winvars='toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=980,height=620,left = 5,top = 5, dependent=yes';
	win = window.open(URL, 'adminWindow', winvars); // a window object
	win.focus();
}

function popUpTrouble() {
	winvars='toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=930,height=620,left = 20,top = 20, dependent=yes';
	win = window.open('Trouble.aspx', 'troubleWindow', winvars); // a window object
	win.focus();
}

function popUpNotice1() {
	winvars='toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=930,height=620,left = 20,top = 20, dependent=yes';
	win = window.open('FRAapp.htm', 'pp1Window', winvars); // a window object
	win.focus();
}

function popUpState(url) {
	winvars='toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=930,height=620,left = 20,top = 20, dependent=yes';
	win = window.open('FRAapp.htm', 'pp1Window', winvars); // a window object
	win.focus();	
}


function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=750,height=570,left = 112,top = 84');");
}

function ShowChart1() {
	winvars='toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=520,left = 60,top = 84, dependent=yes';
	win = window.open('chartAcc.aspx', 'chart1Window', winvars); // a window object
	win.focus();
}

function popUpHelpDir() {
	winvars='toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=930,height=620,left = 20,top = 20, dependent=yes';
	win = window.open('help', 'helpWindow', winvars); // a window object
	win.focus();
}
	
function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=750,height=570,left = 112,top = 84');");
}

function popUpPDF(qval) {
	winvars='titlebar=0,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=600,left = 50,top = 50, dependent=yes';
	eval("win = window.open('pdfView.aspx?v=" + qval + "','pdfWindow', winvars);");	
	// win = window.open('pdfView.aspx?v=1', 'pdfWindow', winvars); // a window object
	win.focus();
}

function popUpPDF2(url) {
	winvars='titlebar=0,toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=750,height=520,left = 112,top = 84, dependent=yes';
	eval("win = window.open('pdfView.aspx?u=" + url + "','pdfWindow', winvars);");	
	// win = window.open('pdfView.aspx?v=1', 'pdfWindow', winvars); // a window object
	win.focus();
}

function CancelSim() {
	 objPage = document.getElementById('pageString');
	 objPage.value = 'Simul';
	 __doPostBack('lbPage','');			  
}


function InitSim() {
	var s = document.getElementById('divSim');
	s.className = 'hideDiv';
    var td = document.getElementById("tdCancel");
    var d = td.getElementsByTagName("div").item(0);
	td.className = 'MainTDx0';
	d.className = 'showDiv';	
	StartClock();
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function KillClock() {
   if(clockID) {
      clearTimeout(clockID);
      obj = document.getElementById('lbTime');
      obj.value="";
	  clockID  = 0;
   }
}


function initClock() {
var clockID = 0;
var zDate = new Date();
var h = zDate.getHours();
var min = zDate.getMinutes();
var sec = zDate.getSeconds();
}

function UpdateClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
   var tDate = new Date();
   var clh = tDate.getHours();
   var clm = tDate.getMinutes();
   var cls = tDate.getSeconds();
   var sinc = 0
   var minc = 0
   var msinc = 0
   var hinc = 0
   var hminc = 0
   var tsec = ""
   if (cls>=sec) {
		sinc = -sec;
	}
		else   {
		sinc = 60-sec;
		msinc = 1;
	}
	
	if (clm>=min) {
		minc = -min - msinc;
	}
		else   {
		minc = 60 - min - msinc;
		hminc = 1;
	}
	
	if (clh>=h) {
		hinc = -h - hminc;
	}
		else   {
		hinc = 60 - h - hminc;
	}
		
	if  ((cls + sinc)<10) {
		tsec = "0" + (cls + sinc);
	}	
		else    {
		tsec = (cls + sinc);
	}

			objx = document.getElementById('lbTime');			   
			objx.value = "SIMULATION IN PROGRESS.  TIME ELAPSED: " 
                                   + (clm + minc) + ":" 
                                   + tsec ;
   
   clockID = setTimeout("UpdateClock()", 1000);
	}
	
function StartClock() {
		zDate = new Date();
		h = zDate.getHours();
		min = zDate.getMinutes();
		sec = zDate.getSeconds();
		//document.simView.lbTime.value = "";
		clockID = setTimeout("UpdateClock()", 500);
}

function enableControls(arg0,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12,arg13,arg14,arg15,arg16,arg17,arg18,arg19,arg20) {
//Enable the first control (i.e., go button) and disable the rest
        obj = document.getElementById(arg0);
	    obj.disabled = false;
	    turnOff(arg1); turnOff(arg2); turnOff(arg3); turnOff(arg4);
	    turnOff(arg5); turnOff(arg6); turnOff(arg7); turnOff(arg8);	    	    
	    turnOff(arg9); turnOff(arg10); turnOff(arg11); turnOff(arg12);	    	    
	    turnOff(arg13); turnOff(arg14); turnOff(arg15); turnOff(arg16);	    	    
	    turnOff(arg17); turnOff(arg18); turnOff(arg19); turnOff(arg20);	    	    	    
	    }

function turnOff(arg) {
    if (arg !== ''){
         objx = document.getElementById(arg);
            if (objx !== null){objx.disabled = true;}         
         }
}

function setValue(arg,x) {
    arg.value = x ;
}
