﻿// JScript File

function SummaryRoll()
{
    // find out i
    var div = document.getElementById("ctl00_ContentPlaceHolder1_Vroll");  //dave's building picture (undefined means it's not not on the page)
    if (div == undefined)
    {    
        return;
    }
    
    div.style.display = "none";
}

function PleaseWait()
{ 
    // display a please wait or hour glass because this postback could take a couple of seconds
    if (Page_IsValid)  //check to see if the page is valid on the client side, if it is then we put the busy.gif in
    {
        setTimeout('BusyGif()',50);    
        var div2 = document.getElementById("VrollWait");
        div2.style.display = "inline";
    }
}

function BusyGif()
{
    var img = document.getElementById("imgPleaseWait");
    img.src = 'images/busy.gif';
}

function FNTap(obj1)
{
    if (obj1.value == 'Tap to Begin Typing')
    {
       obj1.value = '';
       obj1.style.background = 'ActiveBorder';
    }
    return;
}

function DTap(obj1)
{
    b = document.getElementById('ctl00_ContentPlaceHolder1_DTapped');
    
    if (b.value == '0')
    {
       b.value = 1
       obj1.value = '';
    }
    return;
}

function YTap(obj1)
{
    b = document.getElementById('ctl00_ContentPlaceHolder1_YTapped');
    
    if (b.value == '0')
    {
       b.value = 1
       obj1.value = '';
    }
    return;
}


function FNReq(sender, arguments)
{
    var str =  arguments.Value;
    
    if (str == 'Tap to Begin Typing')
    {
        arguments.IsValid = false;
    }
    else
    {
        arguments.IsValid = true;
    }
    
    return;
}

function DateEntered(sender, arguments)
{
    b = document.getElementById('ctl00_ContentPlaceHolder1_DTapped');
    bo = document.getElementById('ctl00_ContentPlaceHolder1_YTapped');
    if (b.value == '0' && bo.value == '0')
    {
        arguments.IsValid = false;
        return;
    }
   
    arguments.IsValid = true;
    return;
    
}
function DateValid(sender, arguments)
{
    y = document.getElementById('ctl00_ContentPlaceHolder1_txtYear');
    m = document.getElementById('ctl00_ContentPlaceHolder1_ddlMonth');
    d = arguments.Value
    
    date = m.value + '/' + d + '/' + y.value;
    
    //check to see if the Year is legit
    var currDate = new Date();
    var currYear = currDate.getFullYear();
    
    if (y.value < 1899 || y.value > currYear )
    {
        arguments.IsValid = false;
        return;
    }
    
    //now check the full date
    if (validateUSDate(date))
    {
        arguments.IsValid = true;
    }
    else
    {
        arguments.IsValid = false;
    }
    return;
}



function validateUSDate( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains only
    valid dates with 2 digit month, 2 digit day,
    4 digit year. Date separator can be  /
    Uses combination of regular expressions and
    string parsing to validate date.
    Ex. mm/dd/yyyy 

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS:
   Avoids some of the limitations of the Date.parse()
   method such as the date separator character.
*************************************************/
  var objRegExp = /^\d{1,2}(\/)\d{1,2}\1\d{4}$/

  //check to see if in correct format
  if(!objRegExp.test(strValue))
    return false; //doesn't match pattern, bad date
  else{
    var strSeparator = strValue.substring(2,3) //find date separator
    var arrayDate = strValue.split(strSeparator); //split date into month, day, year
    //create a lookup for months not equal to Feb.
    var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
    var intDay = parseInt(arrayDate[1]);

    //check if month value and day value agree
    if(arrayLookup[arrayDate[0]] != null) {
      if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
        return true; //found in lookup table, good date
    }

    //check for February
    var intYear = parseInt(arrayDate[2]);
    var intMonth = parseInt(arrayDate[0]);
    if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0)
      return true; //Feb. had valid number of days
  }
  return false; //any other values, bad date
}


