/* 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");

/* FORMS
------------------------------------------------------------------------- */

// refer a friend
function validateFormRefer(){
	var err = "", refs = 0; missed = new Array();
	var reqs = new Array("name","telephone","email","address","madvisor");
	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 = "joanne.bridge@insightms.net,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;
	}
}

// appointment
function validateFormAppt(){
	var err = "", situation = false; missed = new Array();
	var reqs = new Array("title","name","email","address","btime","bdate","bnumber","enquiry");
	for (i=0; i<reqs.length; i++){
		if (document.getElementById(reqs[i]).value == ""){
			missed[missed.length] = document.getElementById(reqs[i]).name;
			}
		}
	for(j=1;j<=6;j++){
		if (document.getElementById("ai"+j).checked) situation = true;
		}
	if (!situation) missed[missed.length] = "Please select the box below which reflects your situation";

	if (!document.getElementById("datapro1").checked) missed[missed.length] = document.getElementById("datapro1").name;

	for(j=1;j<=2;j++){
		if (document.getElementById("future"+j).checked) situation = true;
	}
	if (!situation) missed[missed.length] = "Please state whether or not you are happy to receive future contact from us";

	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 = "joanne.bridge@insightms.net,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;
			}
		}
	}
}
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);
}
