function frameImage(blockType, imgName, imgWidth, imgHeight, tM, rM, bM, lM, alignLCR, figCap, frameType, iLink){
  var tWidth=imgWidth+20;
  var tHeight=imgHeight+20;
  if (blockType == "div") {tailBreak="<br clear=all>"} else {tailBreak=""};
  if (frameType == "noborder") {fT="photos"} else {fT="images"};
  if (iLink != "") {linkStart="<A href=\""+iLink+"\">"; linkEnd="</A>"} else {linkStart=""; linkEnd=""};
  document.writeln("<"+blockType+"><table align=\""+alignLCR+"\"width="+tWidth+" height="+tHeight+" border=0 cellpadding=0 cellspacing=0 style=\"margin: 0px; margin-right:"+rM+"px; margin-left:"+lM+"px; margin-top:"+tM+"px; margin-bottom:"+bM+"px;\">");
  document.writeln("	<tr>");
  document.writeln("		<td width= 10 valign=\"top\" align=\"left\" style=\"background: url('images/"+fT+"/t11.gif');\"><img src=\"images/"+fT+"/t11.gif\" width= \"10\" height=\"10\" hspace=\"0\" vspace=\"0\" border=\"0\" alt=\"\"></td>");
  document.writeln("		<td width= 10 valign=\"top\" align=\"left\" style=\"background: url('images/"+fT+"/t12.gif');\"><img src=\"images/"+fT+"/t12.gif\" width=\"1\" height=\"10\" hspace=\"0\" vspace=\"0\" border=\"0\" alt=\"\"></td>");
  document.writeln("		<td width= 10 valign=\"top\" align=\"left\" style=\"background: url('images/"+fT+"/t13.gif');\"><img src=\"images/"+fT+"/t13.gif\" width= \"10\" height=\"10\" hspace=\"0\" vspace=\"0\" border=\"0\" alt=\"\"></td>");
  document.writeln("	</tr>");
  document.writeln("	<tr>");
  document.writeln("		<td width= 10 valign=\"top\" align=\"left\" style=\"background: url('images/"+fT+"/t21.gif');\"><img src=\"images/"+fT+"/t21.gif\" width=\"10\" height=\"1\" hspace=\"0\" vspace=\"0\" border=\"0\" alt=\"\"></td>");
  document.writeln("		<td width= 10 valign=\"top\" align=\"left\">"+linkStart+"<img src=\"images/images/"+imgName+"\" width="+imgWidth+" height="+imgHeight+" hspace=\"0\" vspace=\"0\" border=\"0\" alt=\"\">"+linkEnd+"</td>");
  document.writeln("		<td width= 10 valign=\"top\" align=\"left\" style=\"background: url('images/"+fT+"/t23.gif');\"><img src=\"images/"+fT+"/t23.gif\" width=\"10\" height=\"1\" hspace=\"0\" vspace=\"0\" border=\"0\" alt=\"\"></td>");
  document.writeln("	</tr>");
  document.writeln("	<tr>");
  document.writeln("		<td width= 10 valign=\"top\" align=\"left\" style=\"background: url('images/"+fT+"/t31.gif');\"><img src=\"images/"+fT+"/t31.gif\" width= \"10\" height=\"10\" hspace=\"0\" vspace=\"0\" border=\"0\" alt=\"\"></td>");
  document.writeln("		<td width= 10 valign=\"top\" align=\"left\" style=\"background: url('images/"+fT+"/t32.gif');\"><img src=\"images/"+fT+"/t32.gif\" width=\"1\" height=\"10\" hspace=\"0\" vspace=\"0\" border=\"0\" alt=\"\"></td>");
  document.writeln("		<td width= 10 valign=\"top\" align=\"left\" style=\"background: url('images/"+fT+"/t33.gif');\"><img src=\"images/"+fT+"/t33.gif\" width= \"10\" height=\"10\" hspace=\"0\" vspace=\"0\" border=\"0\" alt=\"\"></td>");
  document.writeln("	</tr>");
  document.writeln("	<tr>");
  document.writeln("		<td colspan=3 style=\"padding: 8px; padding-top: 0px; padding-bottom: 10px;\"><span class=\"figcaption\">"+figCap+"</span></td>");
  document.writeln("	</tr>");
  document.writeln("</table></"+blockType+">"+tailBreak);
};

function switchLanguage(newLang, isSecure) {
	if (isSecure == 'on') {
		myURL = "https://" + window.location.hostname + "/" + newLang + window.location.pathname.substring(3,window.location.pathname.length);
	} else {
		myURL = "http://" + window.location.hostname + "/" + newLang + window.location.pathname.substring(3,window.location.pathname.length);
	}
	window.location.href=myURL;
}

function writeQuotes() {
    for (var i=0; i<myQuotes.length; i+=1) {
      document.writeln("<li class=\"liquote\"><span class=\"squotel\">&#8220;</span>"+myQuotes[i].quotation+"<span class=\"squoter\">&#8221;</span><br><span class=\"authorcite\">"+myQuotes[i].author+"<br></span>");
    }
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document.getElementById(changeImages.arguments[i]).src = changeImages.arguments[i+1];
		}
	}
}
function changeButton(imgSrc, overState) {
	if (document.images && (preloadFlag == true)) {
		if ((overState == "On") || (overState == "Over") || (overState == "Off")){
			document.getElementById(imgSrc).src = eval(imgSrc+'B'+overState).src;
		} else {
			document.getElementById(imgSrc).src = eval(imgSrc+'B').src;
		}
	}
}
function changeTop(imgSrc, overState) {
	if (document.images && (preloadFlag == true)) {
		if ((overState == "On") || (overState == "Off")){
			document.getElementById(imgSrc).src = eval('upB'+overState).src;
		} else {
			document.getElementById(imgSrc).src = eval('upBOff').src;
		}
	}
}
if (document.images) {
	spacerLoad = newImage("images/spacer.gif");
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function dummyF() {
}

function goBackClear() {
  history.back();
}

function getCookie(name){
	var cname = name + "=";
	var dc = document.cookie;
	if (dc.length > 0) {
		begin = dc.indexOf(cname);
		if (begin != -1) {
			begin += cname.length;
			end = dc.indexOf(";", begin);
			if (end == -1) end = dc.length;
			return unescape(dc.substring(begin, end));
		}
	}
	return null;
}

function setCookie(cookieName,cookieValue,nDays) {
	var today = new Date();
	var expire = new Date();
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue) + "; path=/; expires="+expire.toGMTString();
}

function getIndex(optionValue, checkString) {
	defaultIndex = 0;
	if (document.getElementById(optionValue)) {
		for (var i=0; i < document.getElementById(optionValue).options.length; i++) {
			if (document.getElementById(optionValue).options[i].value == checkString) {
				return i;
			}
		}
	}
	return defaultIndex;
};


function submitApplication(currentLanguage) {
	captureForm(currentLanguage);
	document.getElementById('onlineapplication').submit();
};

function clearApplication() {
	setCookie('fieldKeys', "--", 1);
	setCookie('fieldValues', "--", 1);

	for (var i=0; i < document.getElementById('onlineapplication').elements.length; i++) {
		document.getElementById('onlineapplication').elements[i].style.backgroundColor = '#ffffff';
	}
	document.getElementById('onlineapplication').reset();
};

enToFr = new Array (0,1,3,4,10,11,5,6,7, 2, 8,9,12);
frToEn = new Array (0,1,9,2, 3, 6,7,8,10,11,4,5,12);

function fillOutForm(agentChosen) {
	if (getCookie('fieldKeys')) {
		if (getCookie('fieldKeys') != "--") {
			fieldKeys = new Array();
			fieldKeys = getCookie('fieldKeys').split("_-_");

			fieldValues = new Array();
			fieldValues = getCookie('fieldValues').split("_-_");

			for (var i=0; i < document.getElementById('onlineapplication').elements.length; i++) {
			
				if (!((fieldKeys[i].indexOf("_0_0000") > 0) && (agentChosen != 0))) {
					if (document.getElementById('onlineapplication').elements[i].type == "select-one") {
						document.getElementById('onlineapplication').elements[i].selectedIndex = fieldValues[i];
						if ((fieldKeys[i].indexOf("-2001") > 0) || (fieldKeys[i].indexOf("-2002") > 0)) {
							if (getCookie('formLanguage') != getCookie('myLanguage')) {
								if (getCookie('formLanguage') == 'en')  {
									document.getElementById('onlineapplication').elements[i].selectedIndex = enToFr[fieldValues[i]];
								} else {
									document.getElementById('onlineapplication').elements[i].selectedIndex = frToEn[fieldValues[i]];
								}
							}
						}
					}
					if (document.getElementById('onlineapplication').elements[i].type == "text") {
						document.getElementById('onlineapplication').elements[i].value = fieldValues[i];
					}
				}
			}
		}
	}
};

function captureForm(currentLanguage) {
	fieldKeys = "";
	fieldValues = "";
	fieldElements = document.getElementById('onlineapplication').elements;
	
	for (var i=0; i < fieldElements.length; i++) {
		fieldKeys = fieldKeys + fieldElements[i].name + "_-_";
		if (fieldElements[i].type == "select-one") {
			fieldValues = fieldValues + fieldElements[i].selectedIndex + "_-_";
		}
		if (fieldElements[i].type == "text") {
			fieldValues = fieldValues + fieldElements[i].value + "_-_";
		}
	}
	setCookie('fieldKeys', fieldKeys, 0.02);
	setCookie('fieldValues', fieldValues, 0.02);
	setCookie('formLanguage', currentLanguage, 7);
};

function numOnly (field, evt) {
	var keyCode = document.layers ? evt.which : document.all ? evt.keyCode : evt.keyCode;
	return (keyCode <= 57 || keyCode >= 91);
}
// onKeyDown='return numOnly(this, event);'


