// 11 Jan 2008 created by Michael Chasse
//
// Portions of this code came from The JavaScript Source!! http://javascript.internet.com 
//	Place this between the <head> tag of html or aspx 
//	<script language="javascript" type="text/javascript" src="SpecialFunctions.js"></script>
//	Functions DECLARATIONS

//Creates a pop up window with the specified url as a parameter.
// i.e. <a href="javascript:NewWindow('AnyUrl.aspx')">click here<a>
function NewWindow(URL)
{
	newWindow = new Date();
	id = newWindow.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'width=400,height=350,left = 440,top = 312');");
}

//Creates a pop up window with the specified image.
// i.e. <a href="images/image.jpg" target="_blank" onclick="imagePop('images/image.jpg',750,450,100,50); return false;" >image</a>
function imagePop(myImage,myWidth,myHeight,origLeft,origTop) 
{
	myHeight += 28;
	myWidth += 28;
	TheImgWin = window.open(myImage,'image','height=' + myHeight + ',width=' + myWidth +',toolbar=no,directories=no,status=no,' + 'menubar=no,scrollbars=no,resizable=no');
	TheImgWin.resizeTo(myWidth+2,myHeight+30);
	TheImgWin.moveTo(origLeft,origTop);
	TheImgWin.focus();
}


function grayOut(vis, options) 
{  
	// Pass true to gray out screen, false to ungray  
	// options are optional.  This is a JSON object with the following (optional) properties  
	// opacity:0-100         // Lower number = less grayout higher = more of a blackout   
	// zindex: #             // HTML elements with a higher zindex appear on top of the gray out  
	// bgcolor: (#xxxxxx)    // Standard RGB Hex color code  
	// grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});  
	// Because options is JSON opacity/zindex/bgcolor are all optional and can appear  
	// in any order.  Pass only the properties you need to set.  
	var options = options || {};   
	var zindex = options.zindex || 50;  
	var opacity = options.opacity || 70;  
	var opaque = (opacity / 100);  
	var bgcolor = options.bgcolor || '#000000';  
	var dark=document.getElementById('darkenScreenObject');  

	if (!dark) 
	{   
		// The dark layer doesn't exist, it's never been created.  So we'll    
		// create it here and apply some basic styles.    
		// If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917    
		var tbody = document.getElementsByTagName("body")[0];    
		var tnode = document.createElement('div');           // Create the layer.        
		tnode.style.position='absolute';                 // Position absolutely        
		tnode.style.top='0px';                           // In the top        
		tnode.style.left='0px';                          // Left corner of the page        
		tnode.style.overflow='hidden';                   // Try to avoid making scroll bars                    
		tnode.style.display='none';                      // Start out Hidden        
		tnode.id='darkenScreenObject';                   // Name it so we can find it later    
		tbody.appendChild(tnode);                            // Add it to the web page    
		dark=document.getElementById('darkenScreenObject');  // Get the object.  
	}  
	if (vis) 
	{    
		// Calculate the page width and height     
		if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) 
		{       
			 var pageWidth = document.body.scrollWidth+'px';       
			 var pageHeight = document.body.scrollHeight+'px';    
		} 
		else if( document.body.offsetWidth ) 
		{
			var pageWidth = document.body.offsetWidth+'px';
			var pageHeight = document.body.offsetHeight+'px';    
		} 
		else 
		{       
			var pageWidth='100%';      
			var pageHeight='100%';    
		}       
		//set the shader to cover the entire page and make it visible.   
		 dark.style.opacity=opaque;                          
		 dark.style.MozOpacity=opaque;                     
		 dark.style.filter='alpha(opacity='+opacity+')';   
		 dark.style.zIndex=zindex;            
		 dark.style.backgroundColor=bgcolor;      
		 dark.style.width= pageWidth;   
		 dark.style.height= pageHeight;    
		 dark.style.display='block';                            
	} 
	else 
	{    
		dark.style.display='none';  
	}
}

//Date Time output with image swap on mouse hover
function OutputDateTime()
{
					
	// Toggle time output
	var useTime = false;
					
	var arrMonths = new Array(13);
		arrMonths[0] = "January";
		arrMonths[1] = "February";
		arrMonths[2] = "March";
		arrMonths[3] = "April";
		arrMonths[4] = "May";
		arrMonths[5] = "June";
		arrMonths[6] = "July";
		arrMonths[7] = "August";
		arrMonths[8] = "September";
		arrMonths[9] = "October";
		arrMonths[10] = "November";
		arrMonths[11] = "December";
					
	var arrDays = new Array( 7 );
		arrDays[0] = "Sunday";
		arrDays[1] = "Monday";
		arrDays[2] = "Tuesday";
		arrDays[3] = "Wednesday";
		arrDays[4] = "Thursday";
		arrDays[5] = "Friday";
		arrDays[6] = "Saturday";
					
	var dateTimeString = "";
					
	var now = new Date();
					
	var day = now.getDate();
	var dayOfWeek = now.getDay();
	var month = now.getMonth();
	var year = now.getYear();
					
	if( year < 2000 ) 
	{ 
		year = year + 1900;
	}
					
	if( useTime )
	{
					
		var hours = now.getHours();
		var minutes = now.getMinutes();
		var seconds = now.getSeconds();
		var ampm = "AM";
						
		if( hours > 12 )
		{
			hours -= 12;
			ampm = "PM";
		}
						
		if( minutes < 10 )
		{
			minutes = "0" + minutes;
		}
							
		if( seconds < 10 )
		{
			seconds = "0" + seconds;
		}
							
	}
					
	//Format 1: January 1, 2006:
	dateTimeString += arrMonths[ month ] + "&nbsp;" + day + ", " + year;
					
	//Format 2: Monday, January 2006: dateTimeString += arrDays[ ( dayOfWeek ) ] + ", " + arrMonths[ month ] + " " + year;
					
	if( useTime )
	{
		//Time Format: - 11:23 AM
		dateTimeString += " - " + hours + ":" + minutes + " " + ampm;
	}
					
	var elem = document.getElementById( "DateTime" );
		elem.innerHTML = dateTimeString;
					
	// Use to refresh time on page: window.setTimeout( 'OutputDateTime()', 1000 );
					
}
			
// Fix issue where page has not rendered yet	
				
function MM_preloadImages()
{ //v3.0
	var d = document;
	if( d.images )
	{
		if( !d.MM_p ) d.MM_p = new Array();
		var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
		for( i = 0; i < a.length; i++ )
		if( a[i].indexOf( "#" ) != 0 )
		{
			d.MM_p[j] = new Image; d.MM_p[j++].src = a[i];
		}
	}
}

function MM_swapImgRestore()
{ //v3.0
	var i, x, a = document.MM_sr;
	for( i = 0; a && i < a.length && ( x = a[i] ) && x.oSrc; i++ )
		x.src = x.oSrc;
}

function MM_findObj( n, d )
{ //v4.0
	var p, i, x; 
	if( !d )
		d = document;
	if( ( p = n.indexOf( "?" ) ) > 0 && parent.frames.length )
	{
		d = parent.frames[n.substring( p + 1 )].document;
		n = n.substring( 0, p );
	}
	if( !( x = d[n] ) && d.all )
		x = d.all[n];
	for( i = 0; !x && i < d.forms.length; i++ )
		x = d.forms[i][n];
	for( i = 0; !x && d.layers && i < d.layers.length; i++ )
		x = MM_findObj( n , d.layers[i].document );
	if( !x && document.getElementById)
		x = document.getElementById( n );
		return x;
}

function MM_swapImage() { //v3.0
	var i, j = 0, x, a = MM_swapImage.arguments;
		document.MM_sr = new Array;
	for( i = 0; i < ( a.length - 2 ); i += 3 )
	if( ( x = MM_findObj( a[i] ) ) != null )
	{
		document.MM_sr[j++] = x;
		if( !x.oSrc )
			x.oSrc = x.src;
			x.src = a[i+2];
	}
}

