// JavaScript Document

function writeDate()
{
  today = new Date();
  caDay = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
  caMon = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

  iDate = today.getDate();
  iDay  = today.getDay();
  iMon  = today.getMonth();
  iYear = today.getFullYear();

  document.write( caDay[iDay] + '  ' + caMon[iMon] + ' ' + iDate + ', ' + iYear );
}

function writeBanner()
{
	document.write("<MAP name=\"map1\">\n");
	document.write("<AREA shape=RECT alt=\"Organization Chart of the Utah Department of Health\" coords=573,3,662,14 href=\"http://health.utah.gov/html/div_offices.html\">\n");
	document.write("<AREA shape=RECT alt=\"General information about the Utah Department of Health\" coords=482,3,561,14 href=\"http://health.utah.gov/html/utah_doh.html\">\n");
	document.write("<AREA shape=RECT alt=\"List of important contacts in the Utah Department of Health\" coords=379,3,471,14 href=\"http://health.utah.gov/html/contact_us.html\">\n");
	document.write("<AREA shape=RECT alt=\"Alphabetical list of services, programs, and related links\" coords=283,3,372,15 href=\"http://health.utah.gov/alphalist.html\">\n");
	document.write("<AREA shape=RECT alt=\"Links to public health data sites\" coords=192,3,269,15 href=\"http://health.utah.gov/html/health_data.html\">\n");
	document.write("<AREA shape=RECT alt=\"News releases, media, marketing and public information\" coords=141,2,182,15 href=\"http://health.utah.gov/html/press_releases.html\">\n");
	document.write("<AREA shape=RECT alt=\"Utah Department of Health Internet site Home page\" coords=2,3,130,33 href=\"http://health.utah.gov/\">\n");
	document.write("<AREA shape=RECT alt=\"General Mailing Address: PO Box 141010, Salt Lake City, Utah, 84114-1010\" coords=148,22,466,31>\n");
	document.write("<AREA shape=RECT alt=\"General Phone Number: 801/538/6101\" coords=493,22,661,31>\n");
	document.write("</MAP>\n");
	document.write("<IMG src=\"http://health.utah.gov/UDOHbanner.gif\" alt=\"Internet Site navigation banner\" width=755 height=35 border=0 useMap=../Admin/include/%22#map1/%22>\n");
}

function writeModified()
{
	date = document.lastModified;
	//iDay = date.getDay();
	document.write("<br>Page last modified:"+date+" \n");
}

function writeFooter()
{
  now = new Date();
  iYear = now.getFullYear();
  document.write( '<strong>© Copyright '+ iYear + ', Utah Department of Health</strong>. All rights reserved.<br>\n');
}

function writeFooter2(comp, email)
{
  now = new Date();
  iYear = now.getFullYear();

  //document.write( '<strong>© Copyright '+ iYear + ', '+comp+'</strong>. All material found on this site are copyrighted.<BR>No material may be reproduced or reused without explicit permission from <strong>'+comp+'</strong>.');
  document.write( '<strong>© Copyright '+ iYear + ', '+comp+'</strong>. All rights reserved.<br>\n');
  if(email != undefined)
  	document.write( '<a href='+email+' onMouseOut=\"window.status=\' \';return true\" onMouseOver=\"window.status=\'Comments or Questions?!! Send me an E-mail\'; return true\">'+email+'</a>' );
}

function OpenImg(pic)                                                       
{                    
	var pics = true;                                      
    pics=window.open( '', 'pics', "width=384,height=288,toolbar=no,location=no,menubar=no,scrollbars=no,resizable=no,maximize=no,titlebar=no");
    pics.moveTo(0,0);
	pics.document.write("<html><head><title>SonicFuzion</title></head>\n");
    pics.document.write("<body bgcolor='#FFFFFF' text=#FFFFFF link=#FFCC33 vlink=#CCCCCC vspace=0 hspace=0 marginheight=0 marginwidth=0 leftmargin=0 topmargin=0 onLoad=\"setTimeout('window.close()',10000)\">\n");
    pics.document.write("<script language=JavaScript>setTimeout('document.close()',1000)</script>\n");
    pics.document.write("<center><img src='../Admin/include/images/%22%2Bpic%2B%22' alt='Expanded View' border='0' width='384' height='288'></center>\n");
    pics.document.write("</body></html>");
}

function openWin(content)
{
	wins=window.open('','wins',"width=800,height=600,toolbar=no,location=no,menubar=no,scrollbars=yes,resizable=no,maximize=no,titlebar=no");
	wins.document.write("<html><head><style>body{font-size:12px; font-family: arial,verdana,helvetica,geneva; color:#000000; background: white; margin:0; padding:0;}</style></head><body>");
	wins.document.write(content);
	wins.document.write("</body></html>");
}

function openPage(url)
{
	wins=window.open(url,'wins',"width=800,height=600,toolbar=no,location=no,menubar=no,scrollbars=yes,resizable=no,maximize=no,titlebar=no");
}

function printPage() { 
	print(document); 
}


function ClearAll()
{
	var ml = document.form1;
	var len = ml.elements.length;
	for (var i = 0; i < len; i++) {
	    var e = ml.elements[i];
	    if (e.name == "delItem") {
		e.checked = false;
	    }
	}
	ml.toggleAll.checked = false;
}

function Delete()
{        
	ml = document.form1;
	len = ml.elements.length;

	x = 0;
	for(var i = 0 ; i < len ; i++) {
	    if (ml.elements[i].name == "delItem" && ml.elements[i].checked) {
		x++;
	    }
	}
	if (x) {
	    if (!confirm("Are you sure you want to delete "+x+" rows?")) {
		ClearAll();
		return;
	    }
	}
	var ml=document.form1;
	ml.submit();
}

function showMsg(layerName) {
	newsLayer = document.getElementById(layerName).style;
	if( newsLayer.visibility == "hidden")	
		newsLayer.visibility = "visible";
	else
		newsLayer.visibility = "hidden";
		
	if( newsLayer.display == "none")	
		newsLayer.display = "block";
	else
		newsLayer.display = "none";
	
	return true;
}

function preloadImages()
{
  if(document.images)
  {
    if(!document.imageArray) document.imageArray = new Array();
    var i,j = document.imageArray.length, args = preloadImages.arguments;
    
    for(i=0; i<args.length; i++)
    {
      if (args[i].indexOf("#")!=0)
      {
        document.imageArray[j] = new Image;
        document.imageArray[j++].src = args[i];
      }
    }
  }
}


//Dynamic Select functions
// updates the content of secondary drop down list by selecting an option in the first drop down list.
function dynamicSelect(id1, id2) {
	
	if(document.getElementById && document.getElementsByTagName) {
		var sel1 = document.getElementById(id1);
		var sel2 = document.getElementById(id2);
		
		var clone = sel2.cloneNode(true)
		var clonedOptions = clone.getElementsByTagName("option");
		refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
		sel1.onchange = function() {
			refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
		};
	}
}

function refreshDynamicSelectOptions(sel1, sel2, clonedOptions) {
		
	while(sel2.options.length) {
		sel2.remove(0);
	}
	
	var pattern1 = /( |^)()( |$)/;
	var pattern2 = new RegExp("( |^)(" + sel1.options[sel1.selectedIndex].value + ")( |$)");
	for( var i = 0; i<clonedOptions.length; i++) {
		if(clonedOptions[i].className.match(pattern1) || clonedOptions[i].className.match(pattern2) ) {
			sel2.appendChild(clonedOptions[i].cloneNode(true));
		}
	}
}



//Add rows to a table... (This can be modified)
function addRowToMemberTable(){
	var tbl = document.getElementById('fileUpload');
	var lr = tbl.rows.length-1;
	
	if(lr > 7) 
		return;
	
	var iteration = lr;
	var row = tbl.insertRow(lr);
	
	var cellOne = row.insertCell(0);
	var sel = document.createElement('input');
	sel.name = 'fileUpload[]';
	sel.options[0] = new Option('Committee Member', 'Committee Member');
	sel.options[1] = new Option('Historian', 'Historian');
	sel.options[2] = new Option('Mayor', 'Mayor');
	sel.options[3] = new Option('Publicity Officer', 'Publicity Officer');
	sel.options[4] = new Option('Secretary', 'Secretary');
	cellOne.appendChild(sel);
	
	var cellTwo = row.insertCell(1);
	var el = document.createElement('input');
	el.type = 'text';
	el.name = 'memName[]';
	el.id = 'Name';
	el.size = 40;
	cellTwo.appendChild(el);
	
	var cellThree = row.insertCell(2);
	var el = document.createElement('input');
	el.type = 'text';
	el.name = 'memGrade[]';
	el.id = 'Grade' ;
	el.size = 20;
	cellThree.appendChild(el);
}

function removeRowFromMemberTable() {
		var tbl = document.getElementById('MemberTables');
		var lr = tbl.rows.length-1;
		if (lr > 4) 
			tbl.deleteRow(lr - 1);
}

function addRowToFileTable() {
	var tbl = document.getElementById('fileUpload');
	var lr = tbl.rows.length-1;
	if(lr >= 5) return;
	var iteration = lr;
	var row = tbl.insertRow(lr);
	
	var cellOne = row.insertCell(0);
	var el = document.createTextNode('File '+(lr+1)+': ');
	cellOne.appendChild(el);
	
	var cellTwo = row.insertCell(1);
	var el = document.createElement('input');
	el.type = 'file';
	el.name = 'fileUpload[]';
	el.id = 'fileupload' ;
	el.size = 40;
	cellTwo.appendChild(el);
}

function removeRowFromFileTable() {
		var tbl = document.getElementById('fileUpload');
		var lr = tbl.rows.length-1;
		if (lr > 1) tbl.deleteRow(lr - 1);
}

function checkboxStatus( ) {
	args = checkboxStatus.arguments;
	if( args[0] ) {
		btnID = args[0];
		btn = document.getElementById(btnID);	
		text = document.getElementById(btnID+'txt');
		if( text ) {
			if( (btn.checked == true) )
				text.disabled = false;
			else
				text.disabled = true;
		}
	}
}

function showDiv( div, elem ) {
	var d1 = document.getElementById(div).style;
	
	if( (d1.visibility == "visible") && (elem.value=="No") ) {
		d1.visibility = "hidden";
		d1.display = "none";
	}
	
	if( (d1.visibility == "hidden") && (elem.value=="Yes") ) {
		d1.visibility = "visible";
		d1.display = "block";
	}
}


//Roll Over Images
function domRollover() {
	if (navigator.userAgent.match(/Opera (\S+)/)) {
		var operaVersion = parseInt(navigator.userAgent.match(/Opera (\S+)/)[1]);
	}
	if (!document.getElementById||operaVersion <7) return;
	var imgarr=document.getElementsByTagName('img');
	var imgPreload=new Array();
	var imgSrc=new Array();
	var imgClass=new Array();
	for (i=0;i<imgarr.length;i++){
		if (imgarr[i].className.indexOf('domroll')!=-1){
			imgSrc[i]=imgarr[i].getAttribute('src');
			imgClass[i]=imgarr[i].className;
			imgPreload[i]=new Image();
			if (imgClass[i].match(/domroll (\S+)/)) {
				imgPreload[i].src = imgClass[i].match(/domroll (\S+)/)[1]
			}
			imgarr[i].setAttribute('xsrc', imgSrc[i]);
			imgarr[i].onmouseover=function(){
				this.setAttribute('src',this.className.match(/domroll (\S+)/)[1])
			}
			imgarr[i].onmouseout=function(){
				this.setAttribute('src',this.getAttribute('xsrc'))
			}
		}
	}
}
domRollover();

/*

USAGE: <img src="original.jpg" class="domroll hover.jpg" />
Here, the original image is original.jpg. As you can see, simply insert 
the class attribute inside the image tag, where "domroll" doesn't change, 
and "hover.jpg" is the image you wish to rollover to when the mouse moves 
over the image. You need the space in between the two values.

*/
