//****************************************************************
// DCYF Common Java Scripts Utility Library
// This file includes all java functions that could be used by any 
// dcyf web page. 
// 
// Date: 11-Apr-2005
// Comments: Original
//****************************************************************

//set date to default to today's date.
function dt(){
 now= new Date();
 now= [now.getMonth() < 10 ? '0' + (now.getMonth()+1) : (now.getMonth()+1), now.getDate() < 10 ? '0' + now.getDate() : now.getDate(), now.getFullYear()].join('/')
 return now
}

// function to check the start date and return focus to calling field if invlaid date.
function isSdate(strDate,objfocus) {
   checkdate(strDate,objfocus)
}

// function to check the end date and return focus to calling field if invlaid date.
function isEdate(strDate,objfocus) {
   checkdate(strDate,objfocus)
}

// Check to make sure it's a valid date.
function checkdate(strDate,objfocus) {
if (strDate != "") {
	var err=0;
	var intIndex;
	var intIndex2;
	var intIndex3;
	var shortyr;
	intIndex = strDate.indexOf("/");
	strMonth = strDate.substring(0, intIndex);// month
	intIndex2 = strDate.indexOf("/", intIndex + 1);
	strDay = strDate.substring(intIndex + 1, intIndex2);// day
	strYear = strDate.substring(intIndex2 + 1, strDate.length);// year
	
	if (strMonth < 1 || strMonth > 12) err = 1
	if (strDay<1 || strDay>31) err = 1
	intYear=parseInt(strYear)
	if (intYear>=0 && intYear<=99) intYear = intYear + 2000
	if (intYear<1999 || intYear>2100) err = 1
	if (isNaN(strMonth) || isNaN(strDay) || isNaN(intYear)) err = 1
	
	if (strDate.length==0) err = 1
        //Added this test to make sure of a 4 digit year. 23-Mar-2005
	if (strYear.length<4){ 
             shortyr='4 digit year required'
             err = 1}
	
	if (strMonth==4 || strMonth==6 || strMonth==9 || strMonth==11){
		if (strDay==31) err=1
	}
	if (strMonth==2){
		var strLeapYear=parseInt(intYear/4)
		if (isNaN(strLeapYear)) {
			err=1
		}
		if (strDay>29) err=1
		if (strDay==29 && ((intYear/4)!=parseInt(intYear/4))) err=1
	}	
	
	if (err != 1){
		//get today's date as of midnight so that it can be compared to today
		var today = new Date(new  Date().getFullYear(), new  Date().getMonth(), new Date().getDate() );
		var deldate = new Date(intYear,(strMonth-1),strDay) //javascript months start with 0
		
		if (today > deldate ){
			var displaydate = deldate.toString();
			//orig line of code. I changed message. 23-Mar-2005 
                        //strMessage = "Date entered must be greater than or equal to current date. You have entered a date of " + displaydate
			strMessage = "Date entered must be greater than or equal to current date. "
			alert(strMessage);
        		objfocus.focus();
			return strMessage;
		}
	}
	if (err==1) {
		strMessage = 'Please enter a valid date.' + shortyr;
		alert(strMessage);
        	objfocus.focus();
		return strMessage
	}else {
		//alert("Valid!");
		return true;
	}
}else
	alert("Please enter a date");
        objfocus.focus();
	return false;
} 

// Open a new window to disply file.
function popupWindow(url)
{
   newwindow=window.open(url,'name','height=400,width=600,resizable=1,scrollbars=1');
   if (window.focus)
      {newwindow.focus();}
}

function providerWindow(url)
{
   newwindow=window.open(url,'provider','height=500,width=700,resizable=0,scrollbars=0');
   if (window.focus)
      {newwindow.focus();}
}
// OrgCharts Pop-up Window
function orgPopup(url) { 
		var newwindow;
		
		newwindow=window.open(url,'popwindow','height=400,width=375,resizable=1,scrollbars=1');
		if (window.focus)
		{
			newwindow.focus();
		}
}