/******************************************
 *             Verify Date
 ******************************************/

function verifyDate(testDate)
{ var dt=new Array();
  var mm,dd,yy,isLeapYear,tmp;

  if(testDate.value.length!=10)
  { alert('Invalid date format - please use mm/dd/yyyy');
    testDate.focus();
    return(false);
  }
  dt=testDate.value.split("/");
  if(dt.length!=3)
  { alert('Invalid date format - please use mm/dd/yyyy');
    testDate.focus();
    return(false);
  }
  tmp=dt[0];
  if(tmp.charAt(0)=='0') 
    tmp=tmp.substr(1);
  mm=parseInt(tmp);
  if(isNaN(mm) || mm<1 || mm>12)
  { alert('Invalid month');
    testDate.focus();
    return(false);
  }
  tmp=dt[1];
  if(tmp.charAt(0)=='0') 
    tmp=tmp.substr(1);
  dd=parseInt(tmp);
  if(isNaN(dd) || dd<1 || dd>31)
  { alert('Invalid day');
    testDate.focus();
    return(false);
  }
  tmp=dt[2];
  if(tmp.charAt(0)=='0') 
    tmp=tmp.substr(1);
  yy=parseInt(tmp);
  if(isNaN(yy) || yy<1900)
  { alert('Invalid year');
    testDate.focus();
    return(false);
  }
  isLeapYear=(!((yy)%4) && (((yy)%100) || !((yy)%400)));
  if(mm==2 || mm==4 || mm==6 || mm==9 || mm==11)
  { if(mm==2 && ((isLeapYear && dd>29) || (!isLeapYear && dd>28)) || (mm!=2 && dd>30))
    { alert('Invalid day');
      testDate.focus();
      return(false);
    }
  }
  return(true);
}

/******************************************
 *             isBlank
 ******************************************/
function isBlank(field,fieldName)
{
  if(field.value.length==0)
  { alert(fieldName+' cannot be blank');
    return(true);
  }
  return(false);
}

/******************************************
 *             Set Cookie
 ******************************************/
function SetCookie(name,value,expires,path,domain,secure) 
{ if(typeof document.cookie == "string")
  { document.cookie = name + "=" +escape(value) + ( (expires) ? ";expires=" + expires.toGMTString() : "") +
                      ( (path) ? ";path=" + path : "") + ( (domain) ? ";domain=" + domain : "") +
                      ( (secure) ? ";secure" : "");
    return(true);
  }
  else
    return(false);
}

/******************************************
 *             Get Cookie
 ******************************************/
function GetCookie(name) 
{ var start=document.cookie.indexOf(name+"=");
  var len=start+name.length+1;
 
  if((!start) && (name!=document.cookie.substring(0,name.length)))
    return null;
  if(start==-1) 
    return null;
  var end=document.cookie.indexOf(";",len);
  if(end==-1) 
    end=document.cookie.length;
  return unescape(document.cookie.substring(len,end));
}

/******************************************
 *           Delete Cookie
 ******************************************/
function DeleteCookie(name,path,domain) 
{ if(GetCookie(name)) 
    document.cookie=name+"="+((path)?";path="+path:"")+((domain)?";domain="+domain:"")+";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

/******************************************
 *             Logout
 ******************************************/
function Logout()
{ if(GetCookie('Token'))
  { DeleteCookie('Token','','');
    if(GetCookie('USERNAME'))
      DeleteCookie('USERNAME','','');
    if(GetCookie('LOGIN-REDIRECT'))
      DeleteCookie('LOGIN-REDIRECT','','');
    if(GetCookie('fullName'))
      DeleteCookie('fullName','','');
    if(GetCookie('committeeName'))
      DeleteCookie('committeeName','','');
    window.location='/cgi-bin/membership.cgi';
  }
  else
    alert('You are not logged in');
}


/******************************************
 *          Mini Calendar Popup
 ******************************************/
var newwindow='';

function showMiniCalendar(variable)
{ if(!newwindow.closed && newwindow.location)
    newwindow.location.href='/cgi-bin/pcpaaaData/miniCalendar.html?'+variable;
  else
  { newwindow=window.open('/cgi-bin/pcpaaaData/miniCalendar.html?'+variable,'miniCalendar','height=150,width=220,dependent=yes,hotkeys=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no');
    if(!newwindow.opener)
      newwindow.opener=self;
  }
  if(window.focus)
    newwindow.focus();
}

/******************************************
 *          Show / Hide minutes
 ******************************************/
function showHide(id)
{ var _div=document.getElementById(id).style;
  if(_div.display=='block')
    _div.display='none';
  else
    _div.display='block';
}
