//preloads
N1=new Image();
N1.src="../images/nav_products.gif";
N1On=new Image();
N1On.src="../images/nav_products_over.gif";
N2=new Image();
N2.src="../images/nav_benefits.gif";
N2On=new Image();
N2On.src="../images/nav_benefits_on.gif";
N3=new Image();
N3.src="../images/nav_contact.gif";
N3On=new Image();
N3On.src="../images/nav_contact_on.gif";

N4=new Image();
N4.src="../images/nav_what.gif";
N4On=new Image();
N4On.src="../images/nav_what_on.gif";
N5=new Image();
N5.src="../images/nav_which.gif";
N5On=new Image();
N5On.src="../images/nav_which_on.gif";
N6=new Image();
N6.src="../images/nav_where.gif";
N6On=new Image();
N6On.src="../images/nav_where_on.gif";
N7=new Image();
N7.src="../images/nav_faq.gif";
N7On=new Image();
N7On.src="../images/nav_faq_on.gif";
N8=new Image();
N8.src="../images/nav_faq2.gif";
N8On=new Image();
N8On.src="../images/nav_faq2_on.gif";
N9=new Image();
N9.src="../images/nav_branch-locator.gif";
N9On=new Image();
N9On.src="../images/nav_branch-locator_on.gif";
N10=new Image();
N10.src="../images/nav_pay-a-bill-now.gif";
N10On=new Image();
N10On.src="../images/nav_pay-a-bill-now_on.gif";
N11=new Image();
N11.src="../images/nav_login.gif";
N11On=new Image();
N11On.src="../images/nav_login_on.gif";

S1=new Image();
S1.src="../images/sub_person.gif";
S1On=new Image();
S1On.src="../images/sub_person_on.gif";
S2=new Image();
S2.src="../images/sub_direct-debit.gif";
S2On=new Image();
S2On.src="../images/sub_direct-debit_on.gif";
S3=new Image();
S3.src="../images/sub_internet.gif";
S3On=new Image();
S3On.src="../images/sub_internet_on.gif";
S4=new Image();
S4.src="../images/sub_phone.gif";
S4On=new Image();
S4On.src="../images/sub_phone_on.gif";
S5=new Image();
S5.src="../images/sub_mail.gif";
S5On=new Image();
S5On.src="../images/sub_mail_on.gif";
S6=new Image();
S6.src="../images/sub_merchant.gif";
S6On=new Image();
S6On.src="../images/sub_merchant_on.gif";

M1=new Image();
M1.src="../images/menu_person.gif";
M1On=new Image();
M1On.src="../images/menu_person_on.gif";
M3=new Image();
M3.src="../images/menu_direct-debit.gif";
M3On=new Image();
M3On.src="../images/menu_direct-debit_on.gif";
M4=new Image();
M4.src="../images/menu_internet.gif";
M4On=new Image();
M4On.src="../images/menu_internet_on.gif";
M5=new Image();
M5.src="../images/menu_phone.gif";
M5On=new Image();
M5On.src="../images/menu_phone_on.gif";
M6=new Image();
M6.src="../images/menu_mail.gif";
M6On=new Image();
M6On.src="../images/menu_mail_on.gif";
M2=new Image();
M2.src="../images/menu_merchant.gif";
M2On=new Image();
M2On.src="../images/menu_merchant_on.gif";

var active="";
var activeimgID="";
var activeimg="";
var kill="";
var kill2="";
var activesub="";
	
function TestEmail(e) {
	if(e) {
	p = e.indexOf('@');
	s = e.indexOf(';');
	d = e.lastIndexOf('.');
		if (p<1 || p==(e.length-1) || d<p || d==(e.length-1) || s>-1) {
		return false;
		}
	return true;
	}
return false;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function Swap(imageID,imageName) {
	if(MM_findObj(imageID)){
	 MM_findObj(imageID).src = eval(imageName + ".src");
	}
}

function PlaceSubMenu() {
	var _b=document.body,_w,_x,_left,_top;
	_w = (self.innerWidthh!=null)? self.innerWidth : _b.clientWidth;
	_x = Math.floor((_w-355)/2);
	_left = (_w<722)? 0 : _x;
return _left;
}

function GenerateSubMenu() {
	_left = PlaceSubMenu();
	document.write('<table id="SubMenu" border="0" cellpadding="0" cellspacing="0" width="144" style="position:absolute;top:199px;left:'+ _left +'px;visibility:hidden;">');
	document.write('<tr>');
	document.write('<td><a href="bpoint-in-person.html" onmouseover="Swap(\'s1\',\'S1On\');killtimer();" onmouseout="Swap(\'s1\',\'S1\');timer();"><img id="s1" name="s1" src="../images/sub_person.gif" border="0" alt="" /></a></td>');
	document.write('</tr>');
	document.write('<tr>');
	document.write('<td><a href="bpoint-direct-debit.html" onmouseover="Swap(\'s2\',\'S2On\');killtimer();" onmouseout="Swap(\'s2\',\'S2\');timer();"><img id="s2" name="s2" src="../images/sub_direct-debit.gif" border="0" alt="" /></a></td>');
	document.write('</tr>');
	document.write('<tr>');
	document.write('<td><a href="bpoint-internet.html" onmouseover="Swap(\'s3\',\'S3On\');killtimer();" onmouseout="Swap(\'s3\',\'S3\');timer();"><img id="s3" name="s3" src="../images/sub_internet.gif" border="0" alt="" /></a></td>');
	document.write('</tr>');
	document.write('<tr>');
	document.write('<td><a href="bpoint-phone.html" onmouseover="Swap(\'s4\',\'S4On\');killtimer();" onmouseout="Swap(\'s4\',\'S4\');timer();"><img id="s4" name="s4" src="../images/sub_phone.gif" border="0" alt="" /></a></td>');
	document.write('</tr>');
	//document.write('<tr>');
	//document.write('<td><a href="bpoint-mail.html" onmouseover="Swap(\'s5\',\'S5On\');killtimer();" onmouseout="Swap(\'s5\',\'S5\');timer();"><img id="s5" name="s5" src="../images/sub_mail.gif" border="0" alt="" /></a></td>');
	//document.write('</tr>');
	document.write('</table>');
}

function PositionSubMenu() {
	var _left=PlaceSubMenu();
	MM_findObj("SubMenu").style.left=_left + 'px';
}

function toggle(which,imgID,imgName) {
	if(active != "") {
	killtimer();
	hidelayer();
	if(imgID) {
	imgoff();
	imgon(imgID,imgName);
	}
		if(which !="") {
		showlayer(which,imgID,imgName);
		}
	}
	else {
	if(imgID) {
	imgon(imgID,imgName);
	}	
		if(which !="") {
		showlayer(which,imgID,imgName);
		}
	}
}

function imgoff() {
	MM_findObj(activeimgID).src = eval(activeimg + ".src");
}

function imgon(imageID,imageName) {
	MM_findObj(imageID).src = eval(imageName + ".src");
	activeimgID = imageID;
	strlen = imageName.length -2;
	activeimg = imageName.substring(0,strlen);
}

function showlayer(which,imgID,imgName) {
	MM_findObj("SubMenu").style.visibility = "visible";
	active = which;
}

function hidelayer() {
	MM_findObj("SubMenu").style.visibility = "hidden";
}

function timer() {
kill = setTimeout("hidelayer();",800);
kill2 = setTimeout("imgoff();",800);
}

function killtimer() {
clearTimeout(kill);
clearTimeout(kill2);
}

function addEvent(obj, evType, fn){ 
	if (obj.addEventListener){ 
	obj.addEventListener(evType, fn, false); 
	return true; 
	}
	else if (obj.attachEvent){ 
	var r = obj.attachEvent("on"+evType, fn); 
	return r; 
	} else { 
	return false; 
	} 
}

function CheckSurveyForm(daForm) {
	var MissingFields=0;
	var ManFieldValue=daForm.mandatory.value;
	var ManFields=ManFieldValue.split(",");
	for(x=0;x<ManFields.length;x++) {
	FieldName=ManFields[x];
		// go through validation options	
		if(FieldName.indexOf("{email}")>1) {
			FieldName=FieldName.replace("{email}","");
			if(!TestEmail(daForm.elements(FieldName).value)) {
			var MissingFields=MissingFields+1;
			}
		}
		else if(FieldName.indexOf("{number}")>1) {
			FieldName=FieldName.replace("{number}","");			
			if(isNaN(daForm.elements(FieldName).value)) {
			var MissingFields=MissingFields+1;
			}
		}
		else if(FieldName.indexOf("{len=")>1) {
			var TmpFieldName=FieldName.replace("}","");
			var StrPos=TmpFieldName.indexOf("=");
			var Limiter=FieldName.charAt((StrPos+1));
			FieldName=FieldName.replace("{len="+ Limiter +"}","");
			if(daForm.elements(FieldName).value.length != Limiter) {
			//var MissingFields=MissingFields+1;
			}
		}
		else if(FieldName.indexOf("{amount}")>1) {
			FieldName=FieldName.replace("{amount}","");			
			FieldValue=daForm.elements(FieldName).value.replace("$","");
			if(isNaN(FieldValue) || daForm.elements(FieldName).value=="") {
			var MissingFields=MissingFields+1;
			}
		}
		else if(FieldName.indexOf("[]")>1) {
			FieldName=FieldName.replace("[]","");
			//alert(FieldName);
		}
		else {
			if(daForm.elements(FieldName).length>1) {
				if(daForm.elements(FieldName)[0].type=="radio" || daForm.elements(FieldName)[0].type=="checkbox") {
					var MissingFields=MissingFields+1;
					for(y=0;y<daForm.elements(FieldName).length;y++) {
						if(daForm.elements(FieldName)[y].checked==true) {
						var MissingFields=MissingFields-1;
						}
					}
				}
			}
			else {
				if(daForm.elements(FieldName).value.value=="") {
				var MissingFields=MissingFields+1;
				}
			}
		}
	}
		
	if(ManFields.length > 0) {
		if(document.SurveyForm.receipt_number.value.length != 6) {
		alert("Please check that you have entered a valid BPOINT receipt number");
		return false;
		}
		else {
			if(MissingFields>0) {
			alert("Please fill out all fields marked with an asterisk.");
			return false;
			}
			else {
			return true;
			}
		}
	}
	
	else {
	return true;
	}
}
