/*####################################################################################################

	Title:			Dioceseny Application Global Rollover 
	Author:			Adam Sharp - asharp@andera.com
	Date:			8-24-2001
	
	Purpose:		To serve as a global Image Rollover / Preloader function.
	
	How-To-Config:
		Simply define the 2 variables below...Off_Indicator & Over_Indicator
		"Off_Indicator" should reflect how your "off-state" images are named.  For example, if your
		off-state images are suffixed with "_off", such as "AboutUs_off.gif", than _off would be your
		Off_Indicator.  Over_Indicator should reflect how your "over-state" images are named.
		And that's it!  It's that simple!  Now you can start calling this .js file into your HTML.
		
	Rollover-HTML-Usage:
		<a href="#" onMouseOver="SwapOver('Image1')" onMouseOut="SwapOut('Image1')">
			<img border="0" src="MyImage_off.gif" name="Image1">
		</a>
		
	Preloader-HTML-Usage:
		You need to call the "PreloadImgs()" function onLoad in your <body> tag.  (See below)
					
----------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------
  :-: Define Vars :-:
----------------------------------------------------------------------------------------------------*/

Off_Indicator = "_off";
Over_Indicator = "_over";

/*					**DO NOT EDIT BELOW THIS LINE**
####################################################################################################*/
/*--------------------------------------------------------------------------------------------------
	Create the necessary Variables & Structures
----------------------------------------------------------------------------------------------------*/
var PreloadIndex = 0;
ImgNames = new Array();
LoadImgs = new Array();
OffExpression = "/"+Off_Indicator+"/gi";
OverExpression = "/"+Over_Indicator+"/gi";




/*--------------------------------------------------------------------------------------------------
	MouseOver & MouseOut functions
----------------------------------------------------------------------------------------------------*/

function SwapOver() {
	if (arguments[1]){ if(arguments[1]==1) OnArgs(); }
	ImageName = SwapOver.arguments[0];
	if (document.layers && SwapOver.arguments.length > 1) {
		if (arguments[1] != 1){
			LayerName = SwapOver.arguments[1];
			document[LayerName].document.images[ImageName].src = document[LayerName].document.images[ImageName].src.replace(eval(OffExpression), Over_Indicator);
		}
	} else {
		document.images[ImageName].src = document.images[ImageName].src.replace(eval(OffExpression), Over_Indicator);
	}
	if (arguments[1]){ if(arguments[1]==1) OffArgs(); }
}

function SwapOut() {
	if (arguments[1]){ if(arguments[1]==1) OnArgs(); }
	ImageName = SwapOut.arguments[0];
	if (document.layers && SwapOut.arguments.length > 1) {
		if (arguments[1] != 1){
			LayerName = SwapOut.arguments[1];
			document[LayerName].document.images[ImageName].src = document[LayerName].document.images[ImageName].src.replace(eval(OverExpression), Off_Indicator);
		}
	} else {
		document.images[ImageName].src = document.images[ImageName].src.replace(eval(OverExpression), Off_Indicator);
	}
	if (arguments[1]){ if(arguments[1]==1) OffArgs(); }
}

function OnArgs() {
	Off_Indicator = "_on";
	Over_Indicator = "_onover";
	OffExpression = "/"+Off_Indicator+"/gi";
	OverExpression = "/"+Over_Indicator+"/gi";
}

function OffArgs() {
	Off_Indicator = "_off";
	Over_Indicator = "_over";
	OffExpression = "/"+Off_Indicator+"/gi";
	OverExpression = "/"+Over_Indicator+"/gi";
}

/*--------------------------------------------------------------------------------------------------

	The Preload Function
	How it Works:
		This function will iterate through all of the images in the document. While doing that..for each 
		image, it will check if the image contains your Off_Indicator. If it does, it will create a string identical to 
		that image's name, replacing your Off_Indicator with your Over_Indicator. That string is then added to an array 
		called "ImgNames."  When the function is done building the "ImgNames" array, it will loop
		through ImgNames...Pre-Loading all of the contained images into the Browser-Cache.
	
	Usage:
		You must call the PreloadImgs() function onLoad.
	Example:
		<body onLoad="PreloadImgs()">
		
----------------------------------------------------------------------------------------------------*/

function PreloadImgs() {

	// Build the "ImgNames" Array
	
	if (document.layers) {
		for (y=0; y<document.layers.length; y++) {
			for(i=0; i < document.layers[y].document.images.length; i++) {
				if (document.layers[y].document.images[i].src.search(eval(OffExpression)) > -1) {
					ImgNames[PreloadIndex] = document.layers[y].document.images[i].src.replace(eval(OffExpression), Over_Indicator);
					PreloadIndex++;
				}
			}
		}
		
	}else{
		for(i=0; i < document.images.length; i++) {
			
			if (document.images[i].src.search(eval(OffExpression)) > -1) {
				ImgNames[PreloadIndex] = document.images[i].src.replace(eval(OffExpression), Over_Indicator);
				PreloadIndex++;
			}
		}
	}
	
	
	
	// Lock & Load!
	for(i = 0; i < ImgNames.length; i++) {
	  	LoadImgs[i] = new Image;
	  	LoadImgs[i].src = ImgNames[i];
	}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
	document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


// Character Counter for Page Heading
function CharacterCounter() 
	{
	    	var remaincharacters
		maxlength = 80;
	if ( ( document.sectionForm.page.value  == "" ) || ( document.sectionForm.page.value.length == 0 )  ) {
		//Set remaincharacters        	
		remaincharacters= maxlength;
		document.sectionForm.remainchar.value = maxlength;
      	} 
	else 
	{
        	remaincharacters  = maxlength - (document.sectionForm.page.value.length);
        	document.sectionForm.remainchar.value = remaincharacters;
      	}
      	
      	if ( ( document.sectionForm.remainchar.value < 0 ) ) {
        	document.sectionForm.page.value = document.sectionForm.page.value.substring(0,maxlength);
        	document.sectionForm.remainchar.value = 0;
        	alert("Page heading cannot exceed " + maxlength + " characters.");
      	}
    }
	
	
function openWindow(HREF, Name) {
	var CenteredX = (screen.width - 436) / 2;
	var CenteredY = (screen.height - 368) / 3;
	window.open(HREF,Name,'top='+CenteredY+',left='+CenteredX+',height=368,width=452,scrollbars=yes,menubar=no,status=no,toolbar=no,resizable=no');
}

function openHelpWindow(HREF, Name) {
	var CenteredX = (screen.width - 436) / 2;
	var CenteredY = (screen.height - 368) / 3;
	window.open(HREF,Name,'top='+CenteredY+',left='+CenteredX+',height=550,width=767,scrollbars=yes,menubar=no,status=no,toolbar=no,resizable=no');
}

function openHelpPrintWindow(HREF, Name) {
	var CenteredX = (screen.width - 100) / 2;
	var CenteredY = (screen.height - 200) / 3;
	window.open(HREF,Name,'top='+CenteredY+',left='+CenteredX+',height=550,width=767,scrollbars=yes,menubar=no,status=no,toolbar=no,resizable=no');
}

function checkIfValidImage(fieldName){
	fieldToCheck=document.getElementById(fieldName);
	regExp = /.(jpg|gif|jpeg)/gi;
	if(fieldToCheck.value.length){
		if(fieldToCheck.value.search(regExp) == -1 ){
			alert("Please select a valid image to upload.  Only files with the extention \".jpg\", \".jpeg\", or \".gif\" are accepted."); 
			return false;
		}
	}
	return true;
}

function checkIfValidCSV(fieldName){
	fieldToCheck=document.getElementById(fieldName);
	regExp = /.(txt|csv|tab|asc)/gi;
	if(fieldToCheck.value.length){
		if(fieldToCheck.value.search(regExp) == -1 ){
			alert("Please select a valid csv file to upload.  Only files with the extention \".txt\", \".csv\", \".tab\", or \".asc\" are accepted."); 
			return false;
		}
	}
	return true;
}

function nsDetect(){
	with (navigator){
		if ((appName=="Netscape")&&(parseInt(appVersion)==4)) { return true; }
		else{ return false; }
	}
}

function printCss(){
	var i=0;
	var cssFiles = new Array();
	cssFiles[0]="css/GlobalStyles.css";
	cssFiles[1]="css/Banner.css";
	cssFiles[2]="css/Content.css";
	cssFiles[3]="css/LeftBar.css";
	cssFiles[4]="css/RightBar.css";
	cssFiles[5]="css/Footer.css";
	for(i=0;i<cssFiles.length;i++) printLinkRel(cssFiles[i]);
}

function printLinkRel(file){
	document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\""+file+"\" />");
}

function confirmNewPage() { 
	return confirm("You are now being directed to a new browser."); 
}

function confirmDelete(obj) { 
	return confirm("Are you sure you want to delete this "+obj+"."); 
}