/*
function dateCompare()
parameters: dateString1, dateString2, dateType
returns: integer (-1, 0, 1)
  
dateString1 and dateString2 is a date passed as a string in the following formats:

type 1 : 19970529
type 2 : 970529
type 3 : 29/05/1997
type 4 : 29/05/97
type 5 : 05/29/1997 *most common for Centennial Hotels*
type 6 : 05291997
type 7 : 052997
  
dateType is a numeric integer from 1 to 7, representing
the type of dateString passed, as defined above.

Returns -1 if the dateString1 is behind dateString2
Returns 0 if the dateString1 is equal to dateString2
or if dateType is not 1 to 7
Returns 1 if the dateString1 is ahead of dateString2
  
Added Y2K checking.  (Works for any century cross over)
*/

//var now = new Date();
//var today = new Date(now.getYear(),now.getMonth(),now.getDate());
//var century = parseInt(now.getYear()/100)*100;
        
//Javascript New Date syntax
//1. dateObjectName = new Date()
//2. dateObjectName = new Date("month day, year hours:minutes:seconds")
//3. dateObjectName = new Date(year, month, day)
//4. dateObjectName = new Date(year, month, day, hours, minutes, seconds)

//The way JavaScript handles dates is very similar to the way Java handles dates: 
//both languages have many of the same date methods, and both store dates internally 
//as the number of milliseconds since January 1, 1970 00:00:00. 
//Dates prior to 1970 are not allowed.
	
function dateCompare(dateString1,dateString2,dateType)
{
	//type 1 : 19970529
	if (dateType == 1)
	{
		var date1 = new Date(dateString1.substring(0,4), dateString1.substring(4,6)-1, dateString1.substring(6,8));
		var date2 = new Date(dateString2.substring(0,4), dateString2.substring(4,6)-1, dateString2.substring(6,8));
	}
	
	//type 2 : 970529
	else if (dateType == 2)
	{
		if ((now.getYear()%100)>=parseInt(dateString2.substring(0,2)))
	  {
	  	var date = new Date(century+parseInt(dateString2.substring(4,6)), parseInt(dateString2.substring(2,4)-1), dateString2.substring(4,6));
		}
		else
		{
			var date = new Date(century-100+parseInt(dateString2.substring(0,2)), parseInt(dateString2.substring(2,4)-1), dateString2.substring(4,6));
		}
	}
	
	//type 3 : 29/05/1997
	else if (dateType == 3)
	{
		var date = new Date(dateString2.substring(6,10), dateString2.substring(3,5)-1, dateString2.substring(0,2));
	}
	
	//type 4 : 29/05/97
	else if (dateType == 4)
	{
		if ((now.getYear()%100)>=parseInt(dateString2.substring(6,8)))
		{
			//document.write(century+parseInt(dateString2.substring(6,8)),'<P>'); 
			var date = new Date(century+parseInt(dateString2.substring(4,6)), parseInt(dateString2.substring(3,5)-1), dateString2.substring(0,2));
		}
		else
		{
			//document.write(century-100+parseInt(dateString2.substring(6,8)),'<P>');
			var date = new Date(century-100+parseInt(dateString2.substring(4,6)), parseInt(dateString2.substring(3,5)-1), dateString2.substring(0,2));
		}
	}
	
	//type 5 : 05/29/1997
	else if (dateType == 5)
	{
		//var date1 = new Date(dateString1.substring(6,10), dateString1.substring(0,2)-1, dateString1.substring(3,5));
		//var date2 = new Date(dateString2.substring(6,10), dateString2.substring(0,2)-1, dateString2.substring(3,5));
		
		//it hards to use substring when a date may be passed as 5/1/1997
		var myArray = dateString1.split("/");
		var date1 = new Date(myArray[2], myArray[0], myArray[1]);
		myArray = dateString2.split("/");
		var date2 = new Date(myArray[2], myArray[0], myArray[1]);
	}
	
	//type 6 : 05291997
	else if (dateType == 6)
	{
		var date = new Date(dateString2.substring(4,8), dateString2.substring(0,2)-1, dateString2.substring(2,4));
	}
	
	//type 7 : 052997
	else if (dateType == 7)
	{
		if ((now.getYear()%100)>=parseInt(dateString2.substring(4,6)))
		{
			//document.write('dateString2 Century:',century+parseInt(dateString2.substring(4,6)),'<P>');
			var date = new Date(century+parseInt(dateString2.substring(4,6)), parseInt(dateString2.substring(0,2)-1), dateString2.substring(2,4));
		}
		else
		{
			//document.write('dateString2 Century:',century-100+parseInt(dateString2.substring(4,6)),'<P>');
			var date = new Date(century-100+parseInt(dateString2.substring(4,6)), parseInt(dateString2.substring(0,2)-1), dateString2.substring(2,4));
		}
	}
	
	else
	{
		alert("invalid date type.");
		return false;
		
	}
	
	//if date1 is less than date 2
	if (date1 < date2)
	{
		return -1;
	}
	//if datw1 is greater than date 2
	else if (date1 > date2)
	{
		return 1;
	}
	//if date1 is the same as date2
	else
	{
		return 0;
	}
}

