function rollover(btnId, btnState) 
{
var element = window.document.getElementById(btnId); //grab the element direcly so we can modify attributes etc..
	switch(btnState) //select button state e.g. mouseover, mousedown etc...
	{ 
		case "mouseover": 
		//execute this code if mousedown
		
			element.src = "/images/" + btnId + "_over.gif"; 
			//set the source of the element
			
			break; 
			//end switch
			
		case "mouseout": 
		//execute this code if mousedown
		
			element.src = "/images/" + btnId + "_out.gif"; 
			//set the source of the element
			
			break; 
			//end switch
			
		case "mousedown": 
		//execute this code if mousedown
		
			element.src = "/images/" + btnId + "_down.gif"; 
			//set the source of the element
			
			break; 
			//end switch
			
		default:
			element.src = "/images/" + btnId + "_out.gif"; 
			//if btnState is not found above, use normal as default
	}
}

function swapCaseStudy(newCaseStudy) {
//function to swap case studies on case study page

	for (x in caseStudyNames) {
	//iterate through case study names
	
		if (window.document.getElementById(caseStudyNames[x]).id != newCaseStudy) { 
		//if the current case study is not the new one
		
			window.document.getElementById(caseStudyNames[x]).style.display = "none"; 
			//hide the case study
		}
		
		else {
			
			window.document.getElementById(caseStudyNames[x]).style.display = "block"; 
			// show the case study
			
		}
	}
		
}

function openLink(url1,url2) {
//function to open a link in a new window

	window.open(url1 + url2);
	//open a new window
}


function validateForm(theForm) {
//validate form
	
	for (var i=0; i < theForm.elements.length-1; i++) {
	//loop through all form elements, except the last element (the button)
	
		if (theForm.elements[i].id == "required") {
		//check if the field is required
		
			if (theForm.elements[i].name == "email") {
			//if its the email field
				
				var emailFilter=/^.+@.+\..{2,3}$/;
				//regular expression filter
				//	-	/^.					- matches any character at the beginning
				//	-	/^.+				- Atleast 1 or more characters before the @
				//	-	/^.+@.+ 			- must have atleast 1 @
				//	-	/^.+@.+\.			- must include a "."
				//	-	/^.+@.+\..{2,3}		- must include a minimum of 2 and maximum of 3 characters after the "."
				//	-	/^.+@.+\..{2,3}$/	- matches the end of the string/email address
					
				if (!emailFilter.test(theForm.elements[i].value)) {
				//test for regular expression match	
									
					alert("Please enter a valid email address!");
					//warn the user their email is invalid
					
					theForm.elements[i].focus(); 
					//set the uers cursor on the element
					
					return;
					//exit the code
					
				} 
				//end if (regular expression)
													
			}
			//end if (check if == email)
		
			if (theForm.elements[i].value.length <= 0) {
			//if the elements length is <= then prompt the user to enter text
			
				alert("Please enter text in the " + theForm.elements[i].name + " field.");
				//alert the user that the form has not been completed properly
				
				theForm.elements[i].focus(); 
				//set the uers cursor on the element
				
				
				return;
				//exit the code
				
			}
			//end if (check length <= 0)
	
		}
		//end if (check if 'required field')

	}
	//end loop
	
	theForm.submit();
	//submit the form
		
}
//end function
