/*******************************************************|    
|	//TABLE OF CONTENTS:                                  |
|	//1.FUNCTIONS TO SWITCH BETWEEN _on AND _off IMAGES  	|
|	//2.FUNCTION TO OPEN A NEW WINDOW  									  |
|																												|								
|*******************************************************/

//1.FUNCTIONS TO SWITCH BETWEEN _on AND _off IMAGES

//NOTE: For these imageOn() and imageOff() fuctions to work properly, the images have to be in a 
//folder called "images". Both the _on and _off states have to be in the same images folder.
//There also must only be one "images" folder in a particulr branch of the
//directory structure. For instance, it is fine to have ROOT/common/images, ROOT/images, 
//and ROOT/about/images. It is NOT okay to have ROOT/common/images/about/images. 
//Images MUST be named as: imagename_on.xxx and imagename_off.xxx where imagename is the name of the
//image (may use letters, numbers and underscores) and xxx is the file extension (gif, jpg, etc.)
//NOTE: Image extensions must only have 3 letters. (gif, jpg, etc.) (NOT jpeg)

var imgSource;
var reg_exp = /(images\/)/; //regular expression to pass to match() >>Looks for "images/"

function imageOn(imgName){ //This function swtiches the image to the ON state.
if(imgName && document.images[imgName]){
	imgSource = document.images[imgName].src; //imgSource is the source of the image
	
	//Define the directory of the image and store in a vaiable called "dir".
	//Define the extension of the image (usually ".gif" or ".jpg") and store in 
	//a variable called "ext".
	var result = imgSource.match(reg_exp); //result is the result of the match()
	var index = result.index;
	var imgLength = imgName.length;
	if(result != null){ //if there is a result to the reg_exp
		var dir = imgSource.substring(0,(index)+7); //define dir
		var ext = imgSource.substring((index)+7+imgLength+4,imgSource.length); //define ext
		//substring for ext is the result of matching "images/" + 7 for the length of "images/" (7 characters)
		// plus the length of the image name (imgName) + 4 for the length of "_off" (4 characters).
		
		//check to make sure the extension begins with a '.'
		if(ext.charAt(0)!= '.'){
			ext = ext.substring(ext.indexOf('.'),ext.length);
		}
	//finally, switch the images	
	document.images[imgName].src = dir + imgName + "_on" + ext;	
	}			
}	
}

function imageOff(imgName){ //This function swtiches the image to the OFF state. (see above function for comments)
if(imgName && document.images[imgName]){
	imgSource = document.images[imgName].src;
	var result = imgSource.match(reg_exp);
	var index = result.index;
	var imgLength = imgName.length;
	if(result != null){
		var dir = imgSource.substring(0,(index)+7);
		var ext = imgSource.substring((index)+7+imgLength+3,imgSource.length);
		//substring for ext is the result of matching "images/" + 7 for the length of "images/" (7 characters)
		// plus the length of the image name (imgName) + 3 for the length of "_on" (3 characters).
		
		if(ext.charAt(0)!= '.'){
			ext = ext.substring(ext.indexOf('.'),ext.length);
		}
	document.images[imgName].src = dir + imgName + "_off" + ext;	
	}
}
}

//2.FUNCTIONS TO OPEN A NEW WINDOW (for popup on-site popup windows)

//NOTE: HREF should be set to URL of page. TARGET should be set to 'popup'.
//The function should be called like this: onClick="popUp('URL');"
//(Where URL is the URL of the page to populate the popup window)
//So the whole thing looks like this: HREF="URL" onclick="popUp('URL');" TARGET="popup"

//This function pops up a new window that is 656 in width (added 16 pixels to width for scrollbar) and 550 in height. 
//Used for Client List page and Contact Page
function popUp(){
	popup = window.open('', 'popup', 'width=656,height=550,scrollbars=1,menubar=0,toolbar=0,status=0,resizable=0,top=0,left=0,screenX=0,screenY=0');
popup.focus(); //makes sure new window has focus
} 

//This opens up a large window that is 816 in width (added 16 pixels to width for scrollbar) and 550 in height. 
//Used for News section and ViewBoard section. Set TARGET="popup_large".
function popUpLarge(){
	popup_large = window.open('', 'popup_large', 'width=816,height=550,scrollbars=1,menubar=0,toolbar=0,status=1,resizable=1,top=0,left=0,screenX=0,screenY=0');
popup_large.focus(); //makes sure new window has focus
} 


//This opens up a large window that is 816 in width (added 16 pixels to width for scrollbar) and 550 in height. 
//Same as popUpLarge() but has toolbars, etc. Used for News section and ViewBoard section. Set TARGET="popup_big".
function popUpBig(){
	popup_big = window.open('', 'popup_big', 'width=816,height=550,scrollbars=1,menubar=1,toolbar=1,location=1,status=1,resizable=1,top=0,left=0,screenX=0,screenY=0');
popup_big.focus(); //makes sure new window has focus
}
