function CountWords (f)
 {
 var fullStr = f.value + " ";
 var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
 var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
 var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
 var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
 var splitString = cleanedStr.split(" ");
 var word_count = splitString.length -1;
 if (fullStr.length <2) { word_count = 0; }
 if (word_count > 200)
  {
  alert ("Your comments have " + word_count + " words\nPlease limit your comments to 200 words.");
  return false;
  }
 }

function qualEval(v)
 {
 document.getElementById('qual').style.display='none';
 if(v=='1') { document.getElementById('rate').style.display='block'; }
 else { document.getElementById('unqual').style.display='block'; }
 }

 var isIE = navigator.appName.indexOf("Microsoft") != -1;
var rDisp = (isIE)?'block':'table-row';
function showFieldsSub(c)
 {
 switch (c)
  {
  case 'Sports': var opts = ['','NBA', 'NFL', 'MLB', 'MLS', 'NHL', 'NCAA Div. I Basketball', 'NCAA Div. I Football']; break;
  case 'Political': var opts = ['','Federal', 'State', 'Municipal']; break;
  case 'Corporate': document.getElementById('Subcategory').style.display='none'; showMore(c,''); return; break;
  default: return; break;
  }
 document.getElementById('Subcategory').style.display=rDisp;
 document.form.Subcategory.length = 0;
 for (var i=0; i<opts.length; i++)
  {
  optShow = (opts[i])?opts[i]:'Any';
  document.form.Subcategory.options[i] = new Option(optShow, opts[i]);
  }
 showMore(c,'');
 return;
 }

function showMore(c,s)
 {
 document.getElementById('State').style.display='none';
 document.getElementById('Government_Category').style.display='none';
 document.getElementById('City').style.display='none';
 document.getElementById('Entity').style.display='none';
 document.getElementById('Party').style.display='none';
 if (c=='Political')
  {
  document.getElementById('State').style.display=rDisp;
  document.getElementById('Party').style.display=rDisp;
  if (s=='Federal') { document.getElementById('Government_Category').style.display=rDisp; }
  if (s=='Municipal')
   {
   document.getElementById('City').style.display=rDisp;
   document.getElementById('Party').style.display='none';
   }
  }
 else { document.getElementById('Entity').style.display=rDisp; }
 if (c=='Sports') { document.getElementById('EntLbl').innerHTML = 'Team Name:'; }
 if (c=='Corporate') { document.getElementById('EntLbl').innerHTML = 'Corporation Name:'; }
 }

function doSearchNavSubmit(f)
 {
 document.form.first.value=f; 
 setTimeout ('document.form.submit()',100);
 return true;
 }

function doSearchFilterUnset()
 {
 var f = document.form;
 if (f.Name) { f.Name.value = ''; }
 if (f.State) { f.State.value = ''; }
 if (f.Entity) { f.Entity.value = ''; }
 if (f.City) { f.City.value = ''; }
 }

function invalidChars (val,re)
 {
 if (val.match(re)) { return false; }
 return true;
 }

function validateForm ()
 {
 var errs = '';
 var f = document.form;
 if (f.Screen_Name.length < 6 || f.Screen_Name.length > 20) { errs += 'Your screen name must be between 6 and 20 characters in length.\n\n'; }
 var re = /^[a-zA-Z0-9-_ ]+$/;
 if (invalidChars(f.Screen_Name.value,re)) { errs += 'You screen name may ONLY contain the characters\nA-Z, a-z, 0-9, space, dash or underscore.\n\n'; }
 if (!f.Email.value) { errs += 'Email address is a required field.\n\n'; }
 if (f.Email.value != f.EmailC.value) { errs += 'Your emails do not match!\n\n'; }
 if (f.Password.value != f.PasswordC.value) { errs += 'Your passwords do not match!\n\n'; }
 if (f.Password.value.length < 6 || f.Password.value.length > 12) { errs += 'Your password must be between 6 and 12 characters in length.\n\n'; }
 var re = /^[a-zA-Z0-9-_@]+$/;
 if (invalidChars(f.Password.value,re)) { errs += 'Your password may ONLY contain the characters\nA-Z, a-z, 0-9, dash or underscore.\n\n'; }
 if (f.tos.checked == false){ errs += 'You must accept the Terms of Service to register!'; }
 if (errs != '') { alert (errs); return false; }
 return true;
 }

function validateUpdate ()
 {
 var errs = '';
 var f = document.form;
 if (f.Email.value && !f.EmailC.value) { errs += 'You must confirm your Email address to update it.\n\n'; }
 if (f.Email.value && (f.Email.value != f.EmailC.value)) { errs += 'Your emails do not match!\n\n'; }
 if (f.Password.value && !f.PasswordC.value) { errs += 'Your must confirm your new password to update it!\n\n'; }
 if (f.Password.value && (f.Password.value != f.PasswordC.value)) { errs += 'Your passwords do not match!\n\n'; }
 if (f.Password.value && (f.Password.value.length < 6 || f.Password.value.length > 12)) { errs += 'Your password must be between 6 and 12 characters in length.\n\n'; }
 var re = /^[a-zA-Z0-9-_@]+$/;
 if (invalidChars(f.Password.value,re)) { errs += 'Your password may ONLY contain the characters\nA-Z, a-z, 0-9, dash or underscore.\n\n'; }
 if (errs != '') { alert (errs); return false; }
 return true;
 }

function validateCaptcha(s,obj)
 {
 s = s.toUpperCase();
 s = s.replace (/0/g,'O');
 s = s.replace (/1/g,'L');
 obj.value = s;
 return true;
 }

/* COOKIE FUNCTIONS */
/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}


/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

