function preloadImages() { 
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function findObj(n, d) {
  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=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImgRestore() {
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function swapImage() { 
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function addToFavorites() {
if (window.sidebar) window.sidebar.addPanel('Healthy Living','http://www.northreviews.com/healthyliving', "");
else if(document.all) window.external.AddFavorite('http://www.northreviews.com/healthyliving','Healthy Living');
}

function validateContract() {
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',adr,args=validateContract.arguments; 
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- E-mail field must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- Please enter a numerical amount of pounds.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- You must enter a positive number of pounds.\n';
      } } } else if (test.charAt(0) == 'R') {
		  	if (nm == 'FName') errors += '- First Name is required.\n'; 
			if (nm == 'LName') errors += '- Last Name is required.\n'; 
			if (nm == 'Pnds') errors += '- Number of pounds is required.\n'; }}
    } if (errors) alert('The following error(s) occurred:\n'+errors); else 
	{ 
	var FN=document.forms['contract'].elements[0].value, LN=document.forms['contract'].elements[1].value, P=document.forms['contract'].elements[2].value, M=document.forms['contract'].elements[3].value, D=document.forms['contract'].elements[4].value, Y=document.forms['contract'].elements[5].value, settings;
	var lft=(screen.width)?(screen.width-649)/2:100, tp=(screen.height)?(screen.height-840)/2:100;
	adr='contract-generator.php?f='+FN+'&l='+LN+'&p='+P+'&m='+M+'&d='+D+'&y='+Y+'&c='; 
	for (i=0; i<=28; i++) { if (document.forms['contract'].checkbx[i].checked) adr=adr+'1'; else adr=adr+'0'; }
	for (i=36; i<=38; i++) { if (document.forms['contract'].elements[i].value!="") adr=adr+'&o'+i+'='+document.forms['contract'].elements[i].value+','; }
	settings='width=649,height=840,top='+tp+',left='+lft+',scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=yes,resizable=no'; 
	window.open(adr, 'Contract', settings); }
    document.returnValue = (errors == '');
} }

function openWindow(url, name, w, h) {
   LeftR=(screen.width)?(screen.width-w)/2:100;
   TopR=(screen.height)?(screen.height-h)/2:100;
   settings='width='+w+',height='+h+',top='+TopR+',left='+LeftR+',scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
   win=window.open(url,name,settings); 
}
		
function CheckForm(f) {
	var q, p, errors = '';
	if ((f.elements[0].value == "")||(f.elements[0].value==null)) { errors += 'Please enter your first name.\n'; f.elements[0].focus(); }
	if ((f.email.value=="")||(f.email.value==null)) { errors += 'Please enter your e-mail address.\n'; f.email.focus(); } else { p=f.email.value.indexOf('@'); q=f.email.value.indexOf('.', p+1); if ((q==-1) || (p==-1)) { errors += 'Please enter a valid e-mail address.\n'; f.email.focus(); }}
	if (errors) { alert('The following error(s) occurred:\n'+errors); return false;} else {return true;}
}