// Validate Forms

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 validateForm() { 
  var i,p,q,nm,test,num,min,max,errors='',args=validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=findObj(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+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\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+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.returnValue = (errors == '');
}

// Fee Popups
var newwindow='';
function disbursePopup()
{
	var bl=screen.width/3;
	var bt=screen.height/3;
	page="WTdisburse";
	if(!newwindow.closed&&newwindow.location)
	{
		newwindow.location.href=page;
	}
	else
	{
		newwindow=window.open(page,"CTRLWINDOW","help=no,status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,dependent=yes,width=840,height=190,left="+bl+",top="+bt+",");
		if(!newwindow.opener)
			newwindow.opener=self;
	};
	if(window.focus)
	{
		newwindow.focus()
	}
}

function feePopup()
{
	var bl=screen.width/3;
	var bt=screen.height/3;
	page="WTfeephp.thtml";
	if(!newwindow.closed&&newwindow.location)
	{
		newwindow.location.href=page;
	}
	else
	{
		newwindow=window.open(page,"CTRLWINDOW","help=no,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,dependent=yes,width=695,height=280,left="+bl+",top="+bt+",");
		if(!newwindow.opener)
			newwindow.opener=self;
	};
	if(window.focus)
	{
		newwindow.focus()
	}
}

// Swap Images

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 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 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];}
}

// Swap Color Swatch

function togglePwd(RegInfo)
{
if(RegInfo.noPwdCheckBox.checked)
   {
   RegInfo.pwd.value = "";
   RegInfo.pwd.disabled = true;
   RegInfo.pwd.style.backgroundColor = "#999";
   RegInfo.confirmPwd.value = "";
   RegInfo.confirmPwd.disabled = true;
   RegInfo.confirmPwd.style.backgroundColor = "#999";
   }
else
   {
   RegInfo.pwd.value = "";
   RegInfo.pwd.disabled = false;
   RegInfo.pwd.style.backgroundColor = "#fff";
   RegInfo.confirmPwd.value = "";
   RegInfo.confirmPwd.disabled = false;
   RegInfo.confirmPwd.style.backgroundColor = "#fff";
   }
}

function changeSrc(element, newSource, fontColor)
{
  document.getElementById(element).src=newSource;
  
  form1.hdBkgdImg.value = newSource;
  form1.hdFontColor.value = fontColor;
}

function setRedirect(location)
{
	form1.hdLocation.value = location;
}

// Toggle PWD fields

function togglePWD(RegInfo)
{
if(RegInfo.chkCP.checked)
	{
		//enable the pwd fields
		RegInfo.oldPwd.value = "";
   		RegInfo.oldPwd.disabled = false;
   		RegInfo.oldPwd.style.backgroundColor = "#fff";
		
		RegInfo.pwd.value = "";
   		RegInfo.pwd.disabled = false;
   		RegInfo.pwd.style.backgroundColor = "#fff";
		
		RegInfo.vpwd.value = "";
   		RegInfo.vpwd.disabled = false;
   		RegInfo.vpwd.style.backgroundColor = "#fff";
			
	}
else
   	{
		//disable all boxes
   		RegInfo.MemberPassword.value = "";
   		RegInfo.MemberPassword.disabled = true;
   		RegInfo.MemberPassword.style.backgroundColor = "#999";
		
   		RegInfo.pwd.value = "";
   		RegInfo.pwd.disabled = true;
   		RegInfo.pwd.style.backgroundColor = "#999";
		
   		RegInfo.vpwd.value = "";
   		RegInfo.vpwd.disabled = true;
   		RegInfo.vpwd.style.backgroundColor = "#999";
   	}
}

// Blink some nasty shit

		function blink() {
			var elem=document.getElementById("blinker");
			window.setInterval(function() {
				if(elem.style.visibility=="hidden")
					elem.style.visibility="visible";
				else
					elem.style.visibility="hidden";
				} ,500);
			}
		
		function flash() {
			var i=0, opacity, elem=document.getElementById("flasher");
			var debug=document.getElementById("debug");
			window.setInterval(function() {
				opacity=100*Math.abs((Math.sin(3*i++)));
				setOpacity(elem, opacity );
				//debug.innerHTML+=opacity+" ";
				}, 40)
			}
		function setOpacity(elem, value) { //    1 < value < 100
			elem.style.opacity = value/100;
			elem.style.filter = 'alpha(opacity=' + value + ')';
		}
