//-----------------------------------------------------------------------------
//Module      :   Common.js
//Created By  :   Vinod Joseph
//Created On  :   18th Dec 2006
//Description :   Common javascript functions
//-----------------------------------------------------------------------------
//Modification History:
//-----------------------------------------------------------------------------
//SNo    Who     Date            Description
//-----------------------------------------------------------------------------
//1		Lucio Mesquita	5 Jan 2007	Changed the dimensions of the window in the openwindow function
//-----------------------------------------------------------------------------

function RedirectThis()
{
	alert('here');
}

function openWindow(url, help) 
{
   popupWin = window.open(url, help, "width = 370, height = 400, top = 100, left = 390, alwaysRaised = yes, toolbar = 0, directories = 0, menubar = 0, status = 1, resizable = yes, location = 0, scrollbars = 1, copyhistory = 0");
}

function openLargeWindow(url, help) 
{
   popupWin = window.open(url, help, "width = 800px, height = 700px, top = 10, left = 10, alwaysRaised = yes, toolbar = 0, directories = 0, menubar = 0, status = 1, resizable = yes, location = 0, scrollbars = 1, copyhistory = 0");
}

function showhide(ctrl) 
{
	if(document.getElementById(ctrl).style.display == "none")
		document.getElementById(ctrl).style.display = "block";
	else
		document.getElementById(ctrl).style.display = "none";
}

function DateValidate(day, monthYear)
{
	//	Checks if date is valid.
	//	Logic: checks if day is valid is by setting day, month and year to date object,
	//	if day, month or year changes then date is invalid.
	//  if invalid, returns last valid day of the month
	monthYear	= new String(monthYear);
	year		= monthYear.substring(0, monthYear.indexOf("-"));
	month		= monthYear.substring(monthYear.indexOf("-") + 1, monthYear.length);
	valDate		= new Date();
	
	valDate.setDate(1);
	valDate.setFullYear(year);
	valDate.setMonth(month-1);
	valDate.setDate(day);
	
	if( (day == valDate.getDate()) && (month == valDate.getMonth() + 1) && (year == valDate.getFullYear()) )
	{
		return 1;
	}
	else if(month <= 12)
	{
		testDate=new Date();
		testDate.setDate(1);
		testDate.setFullYear(year);
		testDate.setMonth(month-1); //months Start From Zero
		for(i = 27;i < 32;i++)
		{
			testDate.setDate(i+1);
			if(month != (testDate.getMonth()+1))
				break;
		}
		return i;
	}
	else
	{
		alert("Validation error");
		return 0;
	}
}

function GetWeekDay(intDay)
{
    var DayArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
    return DayArray[intDay];	 
}

function GetMonthString(intMonth)
{
    var DayArray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    return DayArray[intMonth];
}

function CompareDatesOnly(dtFrom,dtTo)
{
	//	Compare year
	if(dtFrom.getFullYear() < dtTo.getFullYear())
	{
		return -1;
	}
	else if(dtFrom.getFullYear() > dtTo.getFullYear())
	{
		return 1;
	}
	else if(dtFrom.getFullYear() == dtTo.getFullYear())
	{
		//	Compare month
		if(dtFrom.getMonth() < dtTo.getMonth())
		{
			return -1;
		}
		else if(dtFrom.getMonth() > dtTo.getMonth())
		{
			return 1;
		}
		else if(dtFrom.getMonth() == dtTo.getMonth())
		{
			// Compare day
			if(dtFrom.getDate() < dtTo.getDate())
			{
				return -1;
			}
			else if(dtFrom.getDate() > dtTo.getDate())
			{
				return 1;
			}
			else if(dtFrom.getDate() == dtTo.getDate())
			{
				return 0;				
			}
		}
	}
}

function CheckEmailAddress(strEmail)
{
	if(	(strEmail.indexOf("@") == -1) || 
		(strEmail.indexOf("@") == 0)  || 
		(strEmail.indexOf("@") == strEmail.length) ||
		(strEmail.indexOf(".") == -1) || 
		(strEmail.indexOf(".") == 0)  || 
		(strEmail.indexOf(".") == strEmail.length) ||
		(strEmail.indexOf("@",(strEmail.indexOf("@")+1)) != -1) ||
		(strEmail.indexOf("@",(strEmail.indexOf("@")+1)) != -1) ||
		(strEmail.indexOf(" ") != -1) )		return false;	return true;
}