// JavaScript Document


		function init_Url(){
			var a=init_Url.arguments;
			var theUrl="http://www.tmc.state.ri.us/";
			if(a.length=="2") 
			{theUrl=theUrl + "Camera%20Images/" + a[1] + a[0] + ".asp";}
			else 
			{theUrl="../Library/CamWins/" + a[0] + ".htm";}
			return theUrl
		}
		
		
		function JJ_openWindow(){
		    var a=JJ_openWindow.arguments;
		    if(a.length=="3"){
		    var theWin=window.open(init_Url(a[0],a[1]),a[0],a[2]);
		    }
		    else{
		    var theWin=window.open(init_Url(a[0]),a[0],a[1]);
		    }
		    theWin.focus()
		    }
		
		//the counter is incremented to signify that the 'delete' button has been pressed.
		//this will be usefull when the 'refresh' button is clicked
		function checkRefresh()
		{
			var count = parseInt(document.getElementById("txtCount").value);
			count = count + 1;
			document.getElementById("txtCount").value = count;
		}
		
		
		function setReload(camCount)
		{
			if(navigator.userAgent.indexOf("Safari") != -1)
			{
				setTimeout("loadImagesSaf('"+camCount+"');", 20000)
			}
			else
			{
				setTimeout("loadImages('"+camCount+"');",20000)
			}
		}
		
		function loadImages(camCount)
		{
			if (document.images)
			{
				img = new Image();
				arrImg = new Array();
				var i = 0;
				
				var today = new Date();
				var time = today.getSeconds();
				var to_day = today.getDate();
				var to_mon = today.getMonth() + 1;
				var to_year = today.getFullYear();
				var tDate =  to_mon + "/" + to_day + "/" + to_year
						
						//set images
						for(i=0; i<=camCount; i++) 
						{
						    if(i < 10)
						        i = "0"+i;
						        
						       
							var camId = "camList_ctl"+i+"_lblCamNum";
							var imgName = "camList_ctl"+i+"_camImage";
							var img = document.images[imgName];
							var dateMod = "camList_ctl"+i+"_date";													

							if(img != null)
							{
								//document.getElementById(imgName).onError = checkImage(i);
								//get & set date
								var curDate;
								
								if(navigator.userAgent.indexOf("Firefox") != -1 || navigator.userAgent.indexOf("Netscape") != -1)
								{
									curDate = document.getElementById(dateMod).textContent;
								}
								else
								{
									curDate = document.getElementById(dateMod).innerText;
								}
								
								if(navigator.userAgent.indexOf("Mac") != -1)
								{
									curDate = curDate.substring(0, 10);
									var curTime = curDate.substring(10, 19);
									
									var shrtDate = new Date(curDate); 
									var utcDate = shrtDate.toUTCString().substring(0, 16);
									var imgDate = new Date(utcDate+curTime);
								}
								else
								{
									var imgDate = new Date(curDate); 
								}
								
								
									imgDate.setSeconds(imgDate.getSeconds() + 20);
									
									var cur_day = imgDate.getDate();
								    var cur_mon = imgDate.getMonth() + 1;
								    var cur_year = imgDate.getFullYear();
								    var iDate =  cur_mon + "/" + cur_day + "/" + cur_year
									
									if(navigator.userAgent.indexOf("Firefox") != -1 || navigator.userAgent.indexOf("Netscape") != -1)
									{
										document.getElementById(dateMod).textContent= iDate +" "+ imgDate.toLocaleTimeString();	
										camId = document.getElementById(camId).textContent;
									}
									else
									{
										document.getElementById(dateMod).innerText = iDate +" "+ imgDate.toLocaleTimeString();	
										camId = document.getElementById(camId).innerText;
									}
									
									img.src = "camImage.aspx?camId="+camId+"&"+Math.random();

									
							}
						}
			
					
				imgWait = setTimeout("loadImages('"+camCount+"');", 20000);
				
			}
		}
					
		
		function loadImagesSaf(camCount)
		{
		if (document.images)
			{
				img = new Image();
				arrImg = new Array();
				var i = 0;
				
				var today = new Date();
				var time = today.getSeconds();
				var to_day = today.getDate();
				var to_mon = today.getMonth() + 1;
				var to_year = today.getFullYear();
				var tDate =  to_mon + "/" + to_day + "/" + to_year;
						
			//set images
			for(i=0; i<=camCount; i++) 
			{
			    if(i < 10)
					i = "0"+i;
						
				var camId = "camList_ctl"+i+"_lblCamNum";
				var imgName = "camList_ctl"+i+"_camImage";
				var img = document.images[imgName];
				var dateMod = "camList_ctl"+i+"_date";														
				
				if(img != null)
				{
					var curDate;
					curDate = document.getElementById(dateMod).innerText;
					curDateN = curDate.substring(0, 10);
					curTime = curDate.substring(10, 19);

					var imgDate = new Date(curDateN); 
					
					var cur_day = imgDate.getDate();
					
					if(cur_day == today.getDate())
					{
						img.src = document.getElementById(imgName).src;
					}
				}
			}
					
			imgWait = setTimeout("loadImagesSaf('"+camCount+"');", 20000);
		  }
		}

		function checkImage(imgId)
		{
			var today = new Date();
			var time = today.getSeconds();
			var imgName = "camList__ctl"+imgId+"_camImage";
			document.getElementById(imgName).src = "/images/blank.jpg";
		}
		


