// created 020309 cy
// functions.js contains the global functions to be used in more than one page

function mouseOver(imageName) {
	document.images[imageName].src = "images/"+imageName+"-on.gif";
}


function mouseOut(imageName) {
	document.images[imageName].src = "images/"+imageName+"-off.gif";
}


// shows a message before closing and/or redirecting the user
function ExitHOA() {
	if (!window.opener || window.opener.closed) {
		URLcontent = window.location.search.replace("?","");
		if (URLcontent.indexOf("hs=yes") > -1 || URLcontent.indexOf("hs%3Dyes") > -1) {
			// if user came from homeownership.ca, go back there
			alert("Thank you for using the Homeowner Assistance Evaluator. You will now be redirected to Homeownership.ca.");
			location.href = "http://www.genworth.ca/homeownership/index.html";
		} else {
			// just redirect to Genworth
			alert("Thank you for using the Homeowner Assistance Evaluator. You will now be redirected to Genworth's Homeowner Assistance section.");
			location.href = "http://www.genworth.ca/content/genworth/ca/en/services/for_lenders/hoa.html";		
		}
	} else {
		// close pop-up
		self.close();
	}
}


function Footer() {
	footerCode = "";
	footerCode += "<div id='footer'>";
	footerCode += "<p class='footer_buttons'>";
	footerCode += "<a href='http://genworth.ca/mi/eng/misc_pages/privacy.html' onMouseOver=\"mouseOver('privacy')\" onMouseOut=\"mouseOut('privacy')\" target='_new'><img src='images/privacy-off.gif' width='40' height='7' name='privacy' alt='Privacy'></a>&nbsp;&nbsp;&nbsp;&nbsp;";
	footerCode += "<a href='http://genworth.ca/mi/eng/misc_pages/terms.html' onMouseOver=\"mouseOver('legal')\" onMouseOut=\"mouseOut('legal')\" target='_new'><img src='images/legal-off.gif' width='31' height='7' name='legal' alt='Legal'></a></p>";
	footerCode += "<p style='float:right; margin:13px 20px 0px 0px;'><img src='images/copyright.gif' width='249' height='10'></p>";
	footerCode += "</div>";
	return footerCode;
}


// Search and Replace
function searchAndReplace(holder, searchfor, replacement) {
	temparray = holder.split(searchfor);
	holder = temparray.join(replacement);
	return (holder);
}


// printPage()
// results is the processed information located in the URL
function PrintPage(results) {
	// need to pass info from URL
	window.open('print.html?'+results,'New','menubar=yes,scrollbars=yes,toolbars=no,resizable=no,location=no,width=700,height=600');
}


// ProceedToPage()
function ProceedToPage() {
	questionValue = "";
	errorMessage = "";
	formName="hardship";
	
	questionValue = RadioCheck(formName,0);
	if (questionValue == "") {
		errorMessage = "You have not answered the question.";
	} else if (questionValue == "no") {
		errorMessage = "If you are not experiencing nor anticipating financial hardship but are interested in learning more about the Homeowner Assistance Program, call 1-800-511-8888 or speak to a Genworth Account Manager.";
	}
	
	if (errorMessage == "") {
		if (typeof hs == "undefined" || hs == "") {
			location.href = "page.html";
		} else {
			location.href = "page.html?hs=yes";
		}
	} else {
		alert(errorMessage);
	}
}


// RadioCheck() checks which radio button is checked and returns the value of the checked button
// formName is the name of the form
// arrayQuestionNum is the current question number; numbering index starts at 0
// returns the value of the checked radio button, if any have been checked
function RadioCheck(formName,arrayQuestionNum) {
	questionAnswer = "";
	x = "q"+arrayQuestionNum;
	for(i=0; i<document[formName][x].length; i++) {
		if(document[formName][x][i].checked) {
			questionAnswer = document[formName][x][i].value;
		}
	}
	return questionAnswer;
}