// JavaScript Document

function swapClass(id, newClass) 
{
	if(document.getElementById(id))
	{
		var idObject = document.getElementById(id);
		idObject.className = newClass;
	}  
}

function enableBox(isChecked, toDisplay)
{
	 if(document.getElementById)//check if browser understands getElementById
	 {
	 	if(document.getElementById(isChecked) && document.getElementById(toDisplay))//check if isChecked and toDisplay are valid
		{			
			//local variable
			var isChecked = document.getElementById(isChecked).checked; 
			
			//set bool isChecked according to isChecked object
			if(isChecked)//if isChecked enable the toDisplay button
				document.getElementById(toDisplay).disabled = false;
			else
				document.getElementById(toDisplay).disabled = true;
		 	
		}//end inner if
	}//end outer if
}//end enable box function


function leave(URL)
{
	if(confirm('You are now leaving Bank of Bourbonnais website. Bank of Bourbonnais is not endorsing or guaranteeing the products, information, or recommendations provided by linked sites and we are not liable for any failure of products and services advertised on those sites'))	
	{
		window.open(URL);	
	}
	
}

function openPopup(URL,width,height)
{
	var variableString = "location=0,status=0,scrollbars=0,resizable=0,toolbar=0,width=";
	variableString += width;
	variableString += ",height=";
	variableString += height;
	
	window.open(URL,"",variableString);
}



/**************************************************************/
/**************************************************************/
/*   THIS SECTION SHOULD BE THE ONLY AREA THAT NEEDS EDITING  */
/**************************************************************/
/**************************************************************/
	//Requirements
	//1. The form that is submitted must be called "frmMain"
	//2. The span tag that will be used to display error message must be named
	//exactly the same as its corresponding input box's name preceeded by "error_"
	//for example the required input box's name is "address" the span that will be used
	//to display the error message must have the ID value "error_address".
	
	
	function getRequiredArray()
	{
		var required = ["required_email"]
				
		return required;
	}
	
	function getWriteError()
	{
		var error = "*Enter Email Address";
		return error;
	}
	function getInvalidError()
	{
		var error = "*Invalid Email Address";
		return error;
	}
	function getClearRequired()
	{
		var clear = "";
		return clear;
	}
	function getClearReset()
	{
		var required = "*Required";
		return required;
	}

/**************************************************************/
/**************************************************************/
/**************************************************************/
/**************************************************************/
	
	function gotoSubmit(email,form)
	{

		var formHandle = document[form];
		var errorFound = false;
		
		//Clear the current Inner HTML
		clearRequiredFieldsInnerHTML();
			
		//Get the required Array
		var requiredArray = getRequiredArray();
		
		var temp;
		for(var x=0; x<requiredArray.length; x++)
		{ 
			if(!(general_check_required(formHandle, requiredArray[x])))
			{ 
				var arrayItem = "error_" + requiredArray[x];
				document.getElementById(arrayItem).innerHTML = getWriteError();		
				if(!errorFound && document.getElementById(requiredArray[x]))
					document.getElementById(requiredArray[x]).focus();
				errorFound = true;
			}//end if 
		}//end for
			
		/*	End required field check */	
		if(errorFound){
			return;
		}
		
		if(!(isEmailValid(formHandle, email)))
			{ 
				var arrayItem = "error_" + email;
				document.getElementById(arrayItem).innerHTML = getInvalidError();		
				if(!errorFound && document.getElementById(requiredArray[x]))
					document.getElementById(email).focus();
				errorFound = true;
			}//end if 
		
		if(errorFound){
			return;
		}
		
		//submit form
		formHandle.submit();
	
	}//end gotoSubmit
	
	function clearRequiredFieldsInnerHTML() 
	{
		
		var requiredArray = getRequiredArray();
		
		for(var x=0; x<requiredArray.length; x++)
		{ 
			var arrayItem = "error_" + requiredArray[x];
			document.getElementById(arrayItem).innerHTML = getClearRequired();
		}//end for
		
	}
			
	function general_check_required(formHandle, transferType)
	{	
		//text fields only
		var stringHandler = formHandle[transferType].value;
				
		if( stringHandler == "" || stringHandler == null)
			return false;
		return true;
	}		


	function isEmailValid(formHandle, email)
	{
		var reg = new RegExp(/^.+([\.-]?\.+)*@{1}.+\.{1}.{2,4}$/);	
		var emailValue = formHandle[email].value;
		
		if (reg.test(emailValue))
			return true;
		return false;
	}	
	
	function writeReset()
	{
		
		var requiredArray = getRequiredArray();
		
		for(var x=0; x<requiredArray.length; x++)
		{ 
			var arrayItem = "error_" + requiredArray[x];
			document.getElementById(arrayItem).innerHTML = getClearReset();
		}//end for
		
		
	}
  	
// END CONTACT US FORM SECTION
// **********************************************
// **********************************************
// **********************************************
// **********************************************
// **********************************************
// **********************************************

//******************************************
//********************************************************************************************
//***********      ROTATE IMAGES                               *******************************
var ID = "imageRotate"; //id of the span or div in the HTML
var POS = 0; //position of the item to display in the IMAGEARRAY
var firstCase = true; //is this the first image being loaded
var IMAGEARRAY = new Array('main_home_equity.jpg','main_home_equity2.jpg');
var IMAGEARRAYLENGTH = IMAGEARRAY.length - 1; //Length of array in terms of array positioning

function rotateImage()
{	
	//This can be removed this is only optional
	//If this is the first time the code is loaded we will randomly start the 
	//image rotation with a random image in the array. If this section is omitted
	//the images will just be displayed in the order they appear in the IMAGEARRAY
	if(firstCase)
	{
		POS = randomStart();
		firstCase = false;
	}
	//**************************************************//
	//**************************************************//
	
	document.getElementById(ID).innerHTML = generateImageString(IMAGEARRAY[POS]);
	
	if(POS == IMAGEARRAYLENGTH)
		POS = 0;
	else
		POS++;

	setTimeout("rotateImage()",12000);
}

function generateImageString(imageName)
{
	var imageString = '';	
	
	imageString +='<a href="conLoan.html#heloc"><img src="images\/';
	imageString += imageName;
	imageString += '" border="0" alt="Home Equity Loans"></a>';
		
	return imageString;
}//end function generateImageString

function randomStart()
{
	if(IMAGEARRAYLENGTH == null || IMAGEARRAYLENGTH == 0)
		return 0;
	
	//generate the random number	
	var randomnumber = Math.floor(Math.random()*(IMAGEARRAYLENGTH + 1));
	
	//additional validation that the number is a valid array position
	if(randomnumber >= 0 && randomnumber <= IMAGEARRAYLENGTH)
		return randomnumber;
	else 
		return 0;
}
//********************************************************************************************
//***********     END ROTATE IMAGES                            *******************************
//********************************************************************************************












