//==================================================================================================
// Revision History:
//		v1.0 - 03/31/2006 GJM: Page created
//      v1.1 - 05/31/2006 MG: dataUrl() function added to convert relative url to absolute urls.
//==================================================================================================

//***********************************************************************************************************
//  dataUrl(url, redirect)
//     Description: This method is used to create absolute url for the given relative url. When a relative
//                  URL is given for a page that is in another virtual directory then an absolute path is
//                  required. This method adds the beginning of absolute path to make relative path an
//                  absolute path.
//     Parameters : url = Relative URL of a page that has to be converted to absolute URL
//                  redirect = true if redirect to new URL, false to return the new absolute URL
//     Sample Use : dataUrl('contactus.aspx', true)
//     Where Used : In hyperlinks to pages that are in another virtual folder
//***********************************************************************************************************
function dataUrl(url, redirect){
    url = "https://www.cpiqpc.com/Data/" + url;
    if(redirect)
    { 
        window.location = url;
    }
    else
    {
        return url;
    }
}

function markChange(form, ChangeID)
{
	eval("form." + ChangeID + ".value='Y'")
}

function validateEmail(EmailAddress) {
	sEmailFormat = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-|_)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	return sEmailFormat.test(EmailAddress)
}

//*************************************************************************************************************
//	Need to define new window on every page for WindowPopUp and ClosePopUps to work properly.
//*************************************************************************************************************
var newWindow;

//*************************************************************************************************************
//	WindowPopUp(url, width, height)
//		Description: Opens a new window with the URL that is passed
//		Parameters:	url=URL that you wish to open.
// 					width=Width of the popup window
// 					height=Height of the popup window
//		Sample Use: WindowPopUp('www.yankeeinfo.com', '600', '800')
//		Where Used:
//*************************************************************************************************************
function WindowPopUp(url, toolbar, location, menubars, scrollbars, width, height, left, top) {
	ClosePopUps()
	eval("window.open('" + url + "', 'fund', 'toolbar=" + toolbar + ", location=" + location + ", locationbar=0, personalbar=0, directories=0, status=1, menubar=" + menubars + ", scrollbars=" + scrollbars + ", resizable=1, width=" + width + ", height=" + height + ", top=" + top + ", left=" + left + "')");
}

//*************************************************************************************************************
//	ClosePopUps()
//		Description: Opens a new window with the URL that is passed
//		Parameters:	none
//		Sample Use: ClosePopUps()
//		Where Used:
//*************************************************************************************************************
function ClosePopUps() {
	if (newWindow) {
		if (newWindow.closed == false) {
			newWindow.close();
		}
	}
}

//*************************************************************************************************************
//	function blocking(i)
//		Description: Hides or show the Paragraph according to the number passed
//		Parameters:	i=Number of the Paragraph to hide or show
//		Sample Use: blocking(5)
//		Where Used: TransactionDetail, PendingTransactions
//*************************************************************************************************************
function blocking(i)
{
	shown[i] = (shown[i]) ? false : true;
	current = (shown[i]) ? 'block' : 'none';

	if (shown[i]) {
		eval("document.arrow_" + i + ".src='images/arrow_down_on.gif'")
		eval("document.arrow_" + i + ".alt='Click to Hide Detail'")
	}
	else {
		eval("document.arrow_" + i + ".src='images/arrow_right_off.gif'")
		eval("document.arrow_" + i + ".alt='Click to Show Detail'")
	}
	
	if (document.getElementById)
	{
		document.getElementById(i).style.display = current;
	}
	else if (document.all)
	{
		document.all[i].style.display = current;
	}
}

//*************************************************************************************************************
//	function arrow_onmouseover(i)
//		Description: Show the proper mouseover image depending on if the Paragraph is hidded or visible
//		Parameters:	i=Number of arrow image on the page
//		Sample Use: arrow_onmouseover(2)
//		Where Used: TransactionDetail, PendingTransactions
//*************************************************************************************************************
function arrow_onmouseover(i)
{
	if (shown[i]) {
		eval("document.arrow_" + i + ".src='images/arrow_down_on.gif'")
	}
	else {
		eval("document.arrow_" + i + ".src='images/arrow_right_on.gif'")
	}
}

//*************************************************************************************************************
//	function arrow_onmouseout(i)
//		Description: Show the proper mouseout image depending on if the Paragraph is hidded or visible
//		Parameters:	i=Number of arrow image on the page
//		Sample Use: arrow_onmouseout(2)
//		Where Used: TransactionDetail, PendingTransactions
//*************************************************************************************************************
function arrow_onmouseout(i)
{
	if (shown[i]) {
		eval("document.arrow_" + i + ".src='images/arrow_down_off.gif'")
	}
	else {
		eval("document.arrow_" + i + ".src='images/arrow_right_off.gif'")
	}
}


//*************************************************************************************************************
//	ValidateDate(DateValue)
//		Description: Validate that the date passed acutally exists
//		Parameters:	DateValue=Date passed.
//		Sample Use: ValidateDate('12/31/2002')
//		Where Used: DeferralPercentage.xsl
//*************************************************************************************************************
var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

function ValidateDate(DateValue)
{
	monthLength[1] = 28; // Resetting it back to its original value in case the function needs to change it for leap year
//	var correctformat = /^\d{1,2}\/\d{1,2}\/\d{4}$/
	var correctformat = /^\d{2}\/\d{2}\/\d{4}$/

	if (correctformat.test(DateValue)) // Check for the right format first
	{
		var month = parseInt(DateValue.substr(0,2),10);
		var day = parseInt(DateValue.substr(3,2),10);
		var year = parseInt(DateValue.substr(6,4),10);

		if (month > 12 || month < 1)
		{
			return false;
		}

		//A year is a leap year if it is divisble by 4 and not divisible 100, or also divisible by 400:
		if ((year/4 == parseInt(year/4)) && (year/100 != parseInt(year/100) || year/400 == parseInt(year/400)))
		{
			monthLength[1] = 29;
		}

		if (day > monthLength[month-1])
		{
			return false;
		}

		return true;
	}
	else
	{
		return false;
	}
}