function checkFinancialPlanningForm() {
	theForm=document.FinancialPlanningForm;
	if(ValidateEmailAddress(theForm.Email.value)) {
		if(theForm.Email.value != theForm.EmailConfirm.value) {
			alert("Please confirm your email address");
			theForm.Email.focus();
			return false;
		}
		if(theForm.FirstName.value=="") {
			alert("Please enter your first name");
			theForm.FirstName.focus();
			return false;
		}
		if(theForm.LastName.value=="") {
			alert("Please enter your last name");
			theForm.LastName.focus();
			return false;
		}
		if(theForm.Phone.value=="") {
			alert("Please enter your phone number");
			theForm.Phone.focus();
			return false;
		}
	} else {
		theForm.Email.focus();
		return false;
	}
	theForm.submit();
}

function checkMortgageForm() {
	theForm=document.MortgageForm;
	if(ValidateEmailAddress(theForm.Email.value)) {
		if(theForm.Email.value != theForm.EmailConfirm.value) {
			alert("Please confirm your email address");
			theForm.Email.focus();
			return false;
		}
		if(theForm.FirstName.value=="") {
			alert("Please enter your first name");
			theForm.FirstName.focus();
			return false;
		}
		if(theForm.LastName.value=="") {
			alert("Please enter your last name");
			theForm.LastName.focus();
			return false;
		}
		if(theForm.Phone.value=="") {
			alert("Please enter your phone number");
			theForm.Phone.focus();
			return false;
		}
		if($("#mfc option:selected").val()=="") {
			alert("Please choose your area of interest");
			theForm.Country.focus();
			return false;
		}
	} else {
		theForm.Email.focus();
		return false;
	}
	theForm.submit();
}

function checkApplyForm() {
	if($("#cb91").attr("checked")==false || $("#cb92").attr("checked")==false || $("#cb93").attr("checked")==false || $("#cb94").attr("checked")==false) {
		alert("Please confirm you agree with these statements and then click Continue");
		return false;
	} else {
		$("#applyform").submit();
	}
}

function checkFXApplyForm() {
	if($("#cb91").attr("checked")==false || $("#cb92").attr("checked")==false || $("#cb93").attr("checked")==false || $("#cb94").attr("checked")==false) {
		alert("Please confirm you agree with these statements and then click Continue");
		return false;
	} else {
		$("#applyform").submit();
	}
}

function checkQuickSubForm(theForm) {
	if(ValidateEmailAddress(theForm.Email.value)) {
		if(theForm.Email.value != theForm.EmailConfirm.value) {
			alert("Please confirm your email address");
			theForm.Email.focus();
			return false;
		}
		if(theForm.FirstName.value=="") {
			alert("Please enter your first name");
			theForm.FirstName.focus();
			return false;
		}
		if(theForm.LastName.value=="") {
			alert("Please enter your last name");
			theForm.LastName.focus();
			return false;
		}
	} else {
		theForm.Email.focus();
		return false;
	}
	theForm.submit();
}

function largerText(){
	var currentFontSize = $("#contentcontainer").css("font-size");
 	var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum*1.125;
	$("#contentcontainer").css("font-size", newFontSize);
	$.get("/ajax-font_size.cfm?s="+newFontSize);
}
	
function smallerText(){
	var currentFontSize = $("#contentcontainer").css("font-size");
 	var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum/1.125;
	$("#contentcontainer").css("font-size", newFontSize);
	$.get("/ajax-font_size.cfm?s="+newFontSize);
}

function convertCurrency(which,what) {
	what=what.replace(/[^0-9]/g,"");
	if(parseInt(what)>0) {
		if(which=="gbp") {
			what=parseInt(what)*$("#cctrade").val();
			what += "";
			tmp=what.split(".");
			$("#aud").val(tmp[0]);
		} else {
			what=parseInt(what)/$("#cctrade").val();
			what += "";
			tmp=what.split(".");
			$("#gbp").val(tmp[0]);
		}
	}
}

// Window opening
function winOpenCenter(url,name,statbar,scroll,locate,resize,xWidth,yWidth)	{
var adjustedleft = 8//optional
var adjustedheight = 30//adjust height because of windows taskbar
var screenwidthremainder = screen.availWidth%2//really not needed, but won't hurt
var screenheightremainder = screen.availHeight%2
var screenwidth = screen.availWidth - screenwidthremainder
var screenheight = screen.availHeight - screenheightremainder
var winheight = yWidth //set new window height properties
var winwidth = xWidth //set new window width properties
var winleft = parseInt(screenwidth/2) - (winwidth/2) - adjustedleft//optional
var wintop = parseInt(screenheight/2) - (winheight/2) - adjustedheight

var win = window.open(url,name,'width=' +winwidth+ ',height=' +winheight+',status=' +statbar+',resizable='+resize+',scrollbars='+scroll+',location='+locate+',top='+wintop+',left='+winleft);
return win;
}

// Email checker
function ValidateEmailAddress(emailStr) {
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		alert("Please enter a valid email address.")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	if (user.match(userPat)==null) {
	    alert("Email address username is not valid.")
	    return false
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		  for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
		        alert("Email address destination IP is invalid.")
			return false
		    }
	    }
	    return true
	}
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("Email address domain name doesn't seem to be valid.")
	    return false
	}
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>6) {
		alert("Email address must end in a three or four-letter domain, or two letter country.")
		return false
	}
	if (len<2) {
		var errStr="Email address is missing a hostname."
		alert(errStr)
		return false
	}
	return true;
}
