function emailURL (emailName, domain, subjectTxt, displayTxt) {
  var emailTxt;
  if(subjectTxt == "")
    emailTxt = '"mailto:' + emailName + '@' + domain + '"'
  else
    emailTxt = '"mailto:' + emailName + '@' + domain + '?subject=' + subjectTxt + '"'
  document.write('<a href=' + emailTxt + '>');
  document.write(displayTxt + '</a>');
}


function dayAdd(beginDate, numDays) {

    var BeginDate = new Date(beginDate);
    if (BeginDate.getYear() < 100) { BeginDate.setYear(BeginDate.getYear()+2000); }
      
    // Determine the milliseconds in the timespan selected
    // Set the default (1 day)
    var MilliSecondsBase = 86400000 

    // Multiply the millisecons by the period entered 
    MilliSecondsToAdd  = MilliSecondsBase * numDays
    
    var NewDateAsNumber = BeginDate.getTime() + MilliSecondsToAdd;

    // Create the new date object
    var NewDate = new Date(NewDateAsNumber);
      

	return (NewDate.getMonth()+1) + "/" + NewDate.getDate() + "/" + NewDate.getYear();

}

function isValidDate(dateStr) {

    // Checks for the following valid date formats:

    // MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY

 if (dateStr!="") {
	 
	
	
    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/; // requires 4 digit year
    var matchArray =  dateStr.match(datePat); // is the format ok?
    if (matchArray == null) {
        alert(dateStr + " Date is not in a valid format.")
        return false;
    }
    month = matchArray[1]; // parse date into variables
    day = matchArray[3];
    year = matchArray[4];
    if (month < 1 || month > 12) { // check month range
        alert("Month must be between 1 and 12.");
        return false;
    }
    if (day < 1 || day > 31) {
        alert("Day must be between 1 and 31.");
        return false;
    }

    if ((month==4 || month==6 || month==9 || month==11) && day==31) {
        alert("Month "+month+" doesn't have 31 days!")
        return false;
    }

    if (month == 2) { // check for february 29th
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day>29 || (day==29 && !isleap)) {
            alert("February " + year + " doesn't have " + day + " days!");
            return false;
        }
    }

    return true;
  }
  else
  { return false; }

}

 

//pass two date strings to find the difference between and

//a diffPercision (d, m, y) use to determine whether the difference

//should be in Days, Months, or Years

function dateDiff(date1Str, date2Str, diffPercision) {

    var diffInt;
    //Check that dates are valid, then create objects
    if (isValidDate(date1Str) && isValidDate(date2Str)) {
     var   oDate1= new Date(date1Str); 
     var   oDate2= new Date(date2Str); 
    } else
        return null;
   oDate2.setDate(oDate2.getDate()+1);      // Neet to be 0 base  1/1/2001  - 12/31/2001 needs to be 12 months..
    //If percision is day subtract the date objects which gives you the difference in milliseconds
    //convert to days 1000ms * 60s * 60m * 24y    
    if (diffPercision=='d') { 
        diffInt = ((oDate1-oDate2)/(24*60*60*1000)); 
        return diffInt;
    } else {
        var sign= 1;
        //Order the Date objects so that oDate2 is always greater
        if(oDate1.getYear() > oDate2.getYear() || oDate1.getYear() == oDate2.getYear() && oDate1.getMonth() < oDate2.getMonth() ){
            sign = -1;
            var oDateTmp;
            oDateTmp = oDate1;
            oDate1 = oDate2;
            oDate2 = oDateTmp;
        }
        var years;
        //simply subtract the year number of the dates to return the number of whole years between them
        years = oDate2.getYear()-oDate1.getYear() 
        if (diffPercision=='y') { 
            return years;
        } else {
            //Use getMonth+1 since getMonth is 0 based
            //get the number of whole months between date1 and date2
            diffInt= sign * (  (years*12) - (oDate1.getMonth()+1) + (oDate2.getMonth()+1) )
            return diffInt
        }
    }
}
