//######################################
// Navigation Bars
//########################################

function FPchangeProp() {//v1.0 (/*id*/'btcat0',0,'style.visibility','hidden')
 var args=arguments,d=document,i,j,id=args[0],o=FPgetObjectByID(id),s,ao,v,x;
 if(o) for(i=2; i<args.length; i+=2) { v=args[i+1]; s="o"; ao=args[i].split(".");
 for(j=0; j<ao.length; j++) { s+="."+ao[j]; if(null==eval(s)) { s=null; break; } }
 if(!d.$cpe) d.$cpe=new Array(); x=new Object; x.o=o; x.n=new Array(); x.v=new Array();
 x.n[x.n.length]=s; eval("x.v[x.v.length]="+s); d.$cpe[d.$cpe.length]=x;
 if(s) eval(s+"=v"); }
}

function FPgetObjectByID(id,o) {//v1.0
 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 for(n=0; n<c.length; n++) { el=FPgetObjectByID(id,c[n]); if(el) return el; }
 f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
 for(m=0; m<els.length; m++){ el=FPgetObjectByID(id,els[n]); if(el) return el; } }
 return null;
}

function preloadImgs() {//v1.0
  var d=document,a=arguments;
  if(!d.FPimgs) d.FPimgs=new Array();
  for(var i=0; i<a.length; i++) {
    d.FPimgs[i]=new Image;
    d.FPimgs[i].src="/images/buttons/button" + a[i] + ".gif";
  }
}

function FPswapImgRestore() {//v1.0
  var doc=document,i;
  if(doc.$imgSwaps) {
    for(i=0;i<doc.$imgSwaps.length;i++) {
      var elm=doc.$imgSwaps[i];
      if(elm) { elm.src=elm.$src; elm.$src=null; }
    }
    doc.$imgSwaps=null;
  }
}
//FPswapImg(1,1,/*id*/'img4','50.gif')
function FPswapImg() {//v1.0
  var doc=document,args=arguments,elm;
  for(var n=2; n<args.length; n+=2) {
    elm=FPgetObjectByID(args[n]);
    if(elm) {
      if(!doc.$imgSwaps)doc.$imgSwaps=new Array();
      doc.$imgSwaps[doc.$imgSwaps.length]=elm;
      elm.$src=elm.src;
      elm.src="/images/buttons/button" + args[n+1] + ".gif";
    }
  }
}


//FPcp(0,'style.visibility','hidden','sub2','sub3','sub4','sub5')
//FPcp(1,'style.visibility','visible','sub1','closer');
function FPcp() {
  var args=arguments,i,vb="visibility",sh="show";
  for (i=3; i<args.length; i++) {
    if (args[1] == "style.visibility") {
      if (args[2] == "hidden") sh = "hide";
      FPchangeProp(args[i],args[0],args[1],args[2],vb,sh);
    }
    else {
      FPchangeProp(args[i],args[0],args[1],args[2]);
    }
  }
}


//######################################
// Common Form Validation Routines
//######################################
// Search String
//##############
// parameters:
// checkStr = field to check
// theName = Display Name
// alp = Alpha characters: 1 - allowed; 0 - invalid
// num = Numeric Alpha characters: 1 - allowed; 0 - invalid
// wht = White Space characters: 1 - allowed; 0 - invalid
// addchar = Additional Character list
// mnl = minimum length
// mxl = maximum length

function SrchValid(checkStr,theName,alp,num,wht,addchar,mnl,mxl) {
var allValid = true;
var chrtyp = ""
if (theName == "") {
theName = "Search Value"
}
var checkOK = "";
if (alp == 1) {
checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
chrtyp = "letter";
}
if (num == 1) {
checkOK = checkOK + "0123456789";
chrtyp = chrtyp + "or digit"
}
if (wht == 1) {
checkOK = checkOK + " ";
chrtyp = chrtyp + "or space"
}
if (addchar.length > 0) {
checkOK = checkOK + addchar;
chrtyp = chrtyp + " or \'" + addchar + "\'";
}

if (mxl > 0) {
if (checkStr.length > mxl) {
alert("Please enter at most " + mxl + " characters in the \"" + theName + "\" field.");
return (false);
}
}

if (mnl > 0) {
if (checkStr.length < mnl) {
alert("Please enter at least " + mnl + " characters in the \"" + theName + "\" field.");
return (false);
}
}

if (checkStr == "") {
alert("Please enter a value in the \"" + theName + "\" field.");
return (false);
}

for (i = 0;i < checkStr.length;i++) {
ch = checkStr.charAt(i);
for (j = 0;j < checkOK.length;j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length) {
allValid = false;
break;
}
}
if (!allValid) {
alert("Please enter only " + chrtyp + " characters in the \"" + theName + "\" field.");
return (false);
}
return (true);
}
//################
// Search Field
//################
function FldValid(chkVal) {
if (chkVal < 0) {
alert("Please select one of the \"Field\" options.");
return (false);
}
if (chkVal == 0) {
alert("The first \"Field\" option is not a valid selection.Please choose one of the other options.");
return (false);
}
return true;
}

//####################
// bannerG search form
//####################
function BannerGS_Validator(theForm) {
var nm = 1;
if (isNaN(theForm.terms.value)) {nm = 3;}
if (!SrchValid(theForm.terms.value,"",1,1,1,"().\"&-_?*#\\/",nm,254)) {
theForm.terms.focus();
return false;
}
return true;
}

//####################################
//write to us
//####################################

function writeus(theForm) {
if (theForm.to.selectedIndex == 4) {
if (!SrchValid(theForm.recipient.value,"Other Recipient",1,1,1,"-.",1,0)) {
theForm.recipient.focus();
return false;
}
}
if (theForm.comment.value == "") {
alert("Please enter something in the \"Comments\" field.");
theForm.comment.focus();
return false;
}
if (!SrchValid(theForm.subject.value,"Subject",1,1,1,"&-_?#\\/!*=.():,\"",1,0)) {
theForm.subject.focus();
return false;
}
return formgen(theForm);
}
//#####################################
// form general
//#####################################
function formgen(theForm) {
theForm.jvalid.value = "0";
var tmp = isEmail(theForm.replyto.value)
if ( tmp == 0) {
alert("Please enter a valid email address.");
theForm.replyto.focus();
return false;
}
if ( tmp == 1 ) {
theForm.jvalid.value = "1";
}
return true;
}
//####################
// Topic Search Form
//####################
function Topic_Validator(theForm) {
if (!FldValid(theForm.topic.selectedIndex)) {
return false;
}
var nm = 1;
if (isNaN(theForm.terms.value)) {nm = 3;}
if (!SrchValid(theForm.terms.value,"",1,1,1,".\"&-_?#*\\/",3,254)) {
theForm.terms.focus();
return false;
}
return true;
}

function isEmail(string) {

var regex = /^\w+([\.\-]\w+)*\@([a-z0-9]+[\.\-])*[a-z0-9]+\.[a-z]{2,}$/i

//if (string.search(/^\w+([\.\-]\w+)*\@([a-z0-9]+[\.\-])*[a-z0-9]+\.[a-z]{2,}$/i) != -1)

if (regex.test(string)) { return 1; }
else { return 0; }
}

function isProper(string) {
if (!string) return false;
var iChars = "!£^+=~:;?/\`\¬\¦\*|,\":<>[]{}`\';()&$#%";

for (var i = 0; i < string.length; i++) {
if (iChars.indexOf(string.charAt(i)) != -1)
 return false;
}
return true;
}

function isReady(theForm,nopt,eopt) {
theForm.jvalid.value = "0";
var tmp;
var tmp2;

tmp = theForm.name.value;

if ((nopt != 0) || (tmp.length != 0)) {
if (isProper(theForm.name.value) == false) {
alert("Please enter a valid name.");
theForm.name.focus();
return false;
}
}
tmp = theForm.replyto.value;
if ((eopt != 0) || (tmp.length != 0)) {
tmp2 = isEmail(tmp);
if ( tmp2 == 0) {
alert("Please enter a valid email address.");
theForm.replyto.focus();
return false;
}
if ( tmp2 == 1 ) {
theForm.jvalid.value = "1";
}
}
return true;
}
