//divDisplay Function
//This function has two variables 'divName' which is a string name of 
//a div elements id name. 'displayContent is a string name of a div element
//id name nested within 'divName'. 
//This function will search within a page for a div element with id "divName"
//once the "divName" is found the function will then loop through all the 
//div elements nested within "divName". Within the element "divName" every
//nested div will be hidden except for the div with id equal to 'displayContent" 
function divDisplay(divName, displayContent)
	{
	 
	 if( document.getElementById )//check if the browers understands 'getElementById'
	 {
	 	 if( document.getElementById(divName) ) //check if there is a element with id 'divName'
		 {
		 	var displayDiv = document.getElementById(divName); //get the div element with the name 'divName'
		 	
			if( displayDiv.getElementsByTagName('div') ) // check if valid getElementsByTagName  
		 	{
				
				var divCollection = displayDiv.getElementsByTagName('div'); //get the collection of div's inside 'displayDiv'
				
				 for(var x=0; x < divCollection.length; x++)//loop through the 'divCollection' 
				 {
					if(divCollection[x].getAttribute("id") == displayContent)//check if the 'div' element has id equal to 'displayContent' 
						{
							divCollection[x].style.display = "block"; //display the div equal to 'displayContent'
							divCollection[x].style.visibility = "visible";
						}//end if
						else
						{	
							divCollection[x].style.display = "none"; //hide all div's not equal to 'displayContent'
							divCollection[x].style.visibility = "hidden";
						}//end else
				 }// end for loop
			
			
			}// end check if valid getElementsByTagName 
		
		 }// end check if there is a element with id 'divName'
	 }// end check if the browers understands 'getElementById'
	 
	}//end divDisplay
	
	
	function openPDF(pdf)
	{
		var windowName = "DefinitionWindow";
	    var params  = "";
	    params += "toolbar=0,";
	    params += "location=0,";
	    params += "directories=0,";
	    params += "status=0,";
	    params += "menubar=0,";
	    params += "scrollbars=0,";
	    params += "resizable=1,";
	    params += "width=800,";
	    params += "height=600";

	   window.open(pdf, windowName, params);	
	}
	
	function openContactUs(contact)
	{
		var windowName = "DefinitionWindow";
	    var params  = "";
	    params += "toolbar=0,";
	    params += "location=0,";
	    params += "directories=0,";
	    params += "status=0,";
	    params += "menubar=0,";
	    params += "scrollbars=0,";
	    params += "resizable=1,";
	    params += "width=505,";
	    params += "height=595";

	   window.open(contact, windowName, params);	
	}
	
// **********************************************
// **********************************************
// **********************************************
// **********************************************
// **********************************************
// **********************************************
//CONTACT US FORM SECTION//
	

/**************************************************************/
/**************************************************************/
/*   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()
	{
		order = ["email"]
				
		return order;
	}
	
	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)
	{

		var formHandle = document.frmMain;
		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
		document.frmMain.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(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/);
		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
// **********************************************
// **********************************************
// **********************************************
// **********************************************
// **********************************************
// **********************************************

	function writeApplet(writeWhat)
	{
		
		switch (writeWhat) {
			case "mortgageInner":
				writeMortgage('mortgageInner');
				break;
			case "loanInner":
				writeLoan('loanInner');
				break;
			case "investInner":
				writeInvest('investInner');
				break;
			case "retireInner":
				writeRetire('retireInner');
				break;
			case "savingsInner":
				writeSavings('savingsInner');
				break;
		}
		
	}//end writeApplet
		
		
	function writeMortgage(writeWhat)
	{
		if(document.getElementById(writeWhat)){
			document.getElementById(writeWhat).innerHTML = 
			'<iframe src="calculators\/Applet_MortgageCompare.html" height="475" width="550" frameborder="0"><\/iframe>' ;   
		}//then
	}//writeMortgage
	
	function writeLoan(writeWhat)
	{
		if(document.getElementById(writeWhat)){
			document.getElementById(writeWhat).innerHTML = 
			'<iframe src="calculators\/Applet_CompareLoan.html" height="475" width="550" frameborder="0"><\/iframe>' ;   
		}//then
	}//writeLoan
		
	function writeInvest(writeWhat)
	{
		if(document.getElementById(writeWhat)){
			document.getElementById(writeWhat).innerHTML = 
			'<iframe src="calculators\/Applet_InvestmentReturn.html" height="475" width="550" frameborder="0"><\/iframe>' ;   
		}//then
	}//writeInvest
	
	function writeRetire(writeWhat)
	{
		if(document.getElementById(writeWhat)){
			document.getElementById(writeWhat).innerHTML = 
			'<iframe src="calculators\/Applet_RetirementPlan.html" height="475" width="550" frameborder="0"><\/iframe>' ;   
		}//then
	}//writeRetire
	
	function writeSavings(writeWhat)
	{
		if(document.getElementById(writeWhat)){
			document.getElementById(writeWhat).innerHTML = 
			'<iframe src="calculators\/Applet_CompareSavings.html" height="475" width="550" frameborder="0"><\/iframe>' ;   
		}//then
	}//writeSavings
	
	function openSA(url)
	{
		
		var windowName = "DefinitionWindow";
	    var params  = "";
	    params += "toolbar=0,";
	    params += "location=0,";
	    params += "directories=0,";
	    params += "status=0,";
	    params += "menubar=0,";
	    params += "scrollbars=0,";
	    params += "resizable=1,";
	    params += "width=895,";
	    params += "height=525";

	   window.open(url, windowName, params);	
	}//end openVideo
	
