/* SUCKERFISH
------------------------------------------------------------------------- */
sfFocus = function(sfEls) {
	for (var i=0; i<sfEls.length; i++) {
		if (!sfEls[i].className.match(/submit/) && !(sfEls[i].className.match(/mceEditor/))){
			sfEls[i].onfocus=function() {
				this.className+=" sffocus";
			}
			sfEls[i].onblur=function() {
				this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
			}
		}
	}
}
sfHover = function(sfEls) {
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
function suckerfish(type, tag, parentId) {
	if (window.attachEvent) {
		window.attachEvent("onload", function() {
			var sfEls = (parentId==null)?document.getElementsByTagName(tag):document.getElementById(parentId).getElementsByTagName(tag);
			type(sfEls);
		});
	}
}
suckerfish(sfHover, "li", "nav");

// appointment
function validateFormContact(){
	var err = "", missed = new Array();
	var reqs = new Array("name","tel","email","address","postcode");
	for (i=0; i<reqs.length; i++){
		if (document.getElementById(reqs[i]).value == ""){
			missed[missed.length] = document.getElementById(reqs[i]).name;
		}
	}

	if (missed.length > 0){
		err = "Please make sure you have filled in the following items:\n\n";
		for (i=0; i<missed.length; i++){
			err += missed[i] + "\n";
		}
		alert(err);
		return false;
	} else {
		if (!(document.getElementById("pc1").checked || document.getElementById("pc2").checked)){
			err += "Please choose a preferred contact method";
			alert(err);
			return false;
		} else {
			document.getElementById('recipient').value = "info@foresightwills.co.uk,sharon.hollinger@insightifa.com,natasha.howard@insightifa.com";
			document.getElementById('realname').value = document.getElementById('name').value;
			document.getElementById('theform').action = "http://www.datadrum.com/cgi-bin/insight.pl";
			return true;
		}
	}
}

// refer a friend
function validateFormRefer(){
	var err = "", refs = 0; missed = new Array();
	var reqs = new Array("name","telephone","email","address");
	for (i=0; i<reqs.length; i++){
		if (document.getElementById(reqs[i]).value == ""){
			missed[missed.length] = document.getElementById(reqs[i]).name;
			}
		}

	for (i=1; i<=4; i++){
		if (document.getElementById("referral"+i).value != "" && document.getElementById("referral"+i+"tel").value != ""){
			refs++;
			}
		}

	if (!refs) missed[missed.length] = "At least one referral name and telephone number";

	if (missed.length > 0){
		err = "Please make sure you have filled in the following items:\n\n";
		for (i=0; i<missed.length; i++){
			err += missed[i] + "\n";
			}
		alert(err);
		return false;
	} else {
		document.getElementById('recipient').value = "info@foresightwills.co.uk,sharon.hollinger@insightifa.com,natasha.howard@insightifa.com";
		document.getElementById('realname').value = document.getElementById('name').value;
		document.getElementById('theform').action = "http://www.datadrum.com/cgi-bin/insight.pl";
		return true;
	}
}

//make all external links show warning message and open in a new window to comply with FSA
function externalLinks() {
if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external"){
			anchor.target = "_blank";
			anchor.onclick = function (){
				//leave = window.confirm("You are now departing from the regulatory site of Insight Mortgage Solutions. Neither Insight Mortgage Solutions nor Home of Choice Ltd is responsible for the accuracy of information contained within the linked site");
				//if (leave) return true
				//else return false;
				return true;
			}
		}
	}
}
window.onload = externalLinks;

function externalFlashWarning(url){
	//leave = window.confirm("You are now departing from the regulatory site of Insight Mortgage Solutions. Neither Insight Mortgage Solutions nor Home of Choice Ltd is responsible for the accuracy of information contained within the linked site");
	//if (leave) window.open(url);
	window.open(url);
}
