/*
// ##########################################################################
//                                                                          #
//   Name        : applibraryJava.asp                                       #
//   Date        : 01/12/00                                                 #
//   Created By  : Lucy Han												    #
//   Description : This file contains Java functions used					#
//                 in the main page(s) of MMCCIS.						    #
//                                                                          #
//   Copyright (c) 2000 Compuware Corporation                               #
//   All rights reserved.                                                   #
//                                                                          #
//   Change History:                                                        #
//   Name		Date		Description                                     #
//   Ram A     1/12/00      Created the function checkFormData_Date( )      #
//   Lucy H	2/16/00			Refined the checkFormData_Date( ),				#
//							and added features of feature of giving month   #
//							specific day prompt and preventing future day   #
//							search.  								        #
// ##########################################################################
*/


function SetFocus()
{
	var tmp = '<%=Request.ServerVariables("Script_Name")%>';
	if (tmp=='/CaseSearchByName.asp')
	{
		document.searchbyname.df_last_nm.focus();
		return true;
	}
}	
//
// 

function checkFormData_Location() 
{
	//Street Name validation
	var strTemp = document.searchbylocation.muc_loc_str_nm.value;
        // remove all whitespace and wildcards before checking its length
        var temp = (strTemp.replace(/^\W+/,'')).replace(/\W+$/,'').replace(/\*/,'').replace(/\%/,'');
        if (temp.length < 1)
           {
	   alert("Please enter at least the first character of the Street Name.");
	   return false;
           }
}

function checkFormData_Date()	
{	
	//******Test*********
	//alert ("inside function");
	//*******************
	
	//LastName validation
	var strTemp = document.searchbyname.df_last_nm.value;
        // remove all whitespace and wildcards before checking its length
        var temp = (strTemp.replace(/^\W+/,'')).replace(/\W+$/,'').replace(/\*/,'').replace(/\%/,'');
        if (temp.length < 2)
           {
	   alert("Please enter at least the first 2 characters of the Last Name or Business Name.");
	   return false;
           }
		
	//Birthdate validation
	var today = new Date ()
	var strMonth = document.searchbyname.df_birth_month.value;
	var strDay = document.searchbyname.df_birth_day.value;
	var strYear = document.searchbyname.df_birth_year.value;

	//****no long needed***************
	//if (strMonth.charAt(0) == "0")
	//	{
	//	strMonth=strMonth.charAt(1);
	//	}
	//if (strDay.charAt(0) == "0")
	//	{
	//	strDay=strDay.charAt(1);
	//	}
	//********************************
	
	if (strMonth.length > 0 || strDay.length > 0 || strYear.length > 0)
	{
		//******Test*********
		//alert("<1: " + ( (strMonth)<1) );
		//var abc = (parseInt(strYear)<1800);
		//		alert("Please: " + abc);
		//*******************
		if ( (parseInt(strMonth,10) < 1) || (parseInt(strMonth,10) > 12) || (isNaN(parseInt(strMonth,10))) || (isNaN(strMonth)) )
		{	
			//******Test*********
			//alert (parseInt(strMonth,10));
			//*******************
			alert("Please enter a valid month (1 to 12).");
			return false;
		}
		else if (parseInt(strMonth,10) == 1 || parseInt(strMonth,10) == 3 || parseInt(strMonth,10) == 5 || parseInt(strMonth,10) == 7 || parseInt(strMonth,10) == 8 || parseInt(strMonth,10) == 10 || parseInt(strMonth,10) == 12)
		{	
			if (parseInt(strDay,10) < 1 || parseInt(strDay,10) > 31 || isNaN(parseInt(strDay,10)) || isNaN((strDay)))
			{
				alert("Please enter a valid day (1 to 31).");
				return false;	
			}
		}
		else if (parseInt(strMonth,10) == 4 || parseInt(strMonth,10) == 6 || parseInt(strMonth,10) == 9 || parseInt(strMonth,10) == 11 )
		{	
			if (parseInt(strDay,10) < 1 || parseInt(strDay,10) > 30 || isNaN(parseInt(strDay,10)) || isNaN((strDay)))
			{
				alert("Please enter a valid day (1 to 30).");
				return false;	
			}
		}	
		//else if (parseInt(strYear,10)<1800 || parseInt(strYear,10)>today.getFullYear() || isNaN(parseInt(strYear,10)) || isNaN(strYear))
	    if (parseInt(strYear,10)<1800 || parseInt(strYear,10)>today.getFullYear() || isNaN(parseInt(strYear,10)) || isNaN(strYear))
	    {
			alert("Please enter a 4-digit valid year (1800 to " + today.getFullYear() + ").");
			return false;
		}
		else if (parseInt(strMonth,10) == 2)
		{	
			var lastFeb = 29;
			var FebDate = new Date(parseInt(strYear,10), 1, 29, 0,0,0,0);
			if (FebDate.getMonth() == 2 )
			{
			lastFeb = 28;
			}
			if ( parseInt(strDay,10)<1 || parseInt(strDay,10)>lastFeb || isNaN(parseInt(strDay,10)) || isNaN(strDay) )
			{
			alert("Please enter a valid day (1 to " + lastFeb + ").");
			return false;
			}
		}	
		var inDate = new Date(parseInt(strYear,10), parseInt(strMonth,10)-1, parseInt(strDay,10), 0,0,0,0);
		if (today.getTime() <= inDate.getTime())
		{		
		alert ("A future day is not a valid day for this search.");
		return false;
		}
	}
	
	return true;
}   

