/* ============================================================================================================
    Script Name:		web_pep_fin.js
    Description:			This script contains the javascript functions used within WEB-PEP-Fin
    Date Created:		February 6, 2004 - Qunara Inc.
    Date Modified:		May 12, 2004 - Qunara Inc. - modified to include functions required for Registered Associations
								May 31, 2004 - Qunara Inc. - removed some changes implemented on May 12th
								June 14, 2004 - Qunara Inc. - added functions for displaying and closing the progress bar form
    =============================================================================================================
*/
function handleKeyUp(e)
{
	var keynum;
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
	
	if (browser=="Microsoft Internet Explorer")  // IE
	{
		if(!e)
			var e = window.event;
			
		keynum = e.keyCode;
		if (e.type=="click")
			keynum = 13;
	}
	else // Netscape/Firefox/Opera
		keynum = e.which;
 	
	if (keynum == 13) 
		ShowIDList();
}
/* ===========================================================================================
    Function Name:	setCookie
    Description:	This function sets the value of a cookie.
	Arguments:		name - name of the cookie
					value - value of the cookie
					[expires] - expiration date of the cookie
								(defaults to end of current session)
					[path] - path for which the cookie is valid
								(defaults to path of calling document)
					[domain] - domain for which the cookie is valid
								(defaults to domain of calling document)
					[secure] - Boolean value indicating if the cookie transmission requires a secure transmission

					* an argument defaults when it is assigned null as a placeholder
					* a null placeholder is not required for trailing omitted arguments

    Date Created:		Jun 10, 2007 - IBM(T.E.S)
	==============================================================================================							
*/
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}


/* ===========================================================================================
    Function Name:	getCookie
    Description:	This function returns the string containing value of specified cookie 
					or null if cookie does not exist
    Arguments:		name - name of the desired cookie

    Date Created:		Jun 10, 2007 - IBM(T.E.S)
   ===========================================================================================
*/
function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
	}
	return null;
}


/* ===========================================================================================
    Function Name:	deleteCookie
    Description:	This function returns the string containing value of specified cookie 
					or null if cookie does not exist
    Arguments:		name - name of the cookie
					[path] - path of the cookie (must be same as path used to create cookie)
					[domain] - domain of the cookie (must be same as domain used to create cookie)

					path and domain default if assigned null or omitted if no explicit argument proceeds

    Date Created:	Jun 10, 2007 - IBM(T.E.S)
   ===========================================================================================
*/
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

/* ===========================================================================================
    Function Name:	fixDate
    Description:	hand all instances of the Date object to this function for "repairs"
    Arguments:		date - any instance of the Date object

    Date Created:		Jun 10, 2007 - IBM(T.E.S)
   ===========================================================================================
*/
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}
function EnableRemove()
{
	var frmCurrentForm = document.forms[0];
	var lstReturnList = frmCurrentForm["ctlSearchResults_lstSearchResults"];
	
		if(lstReturnList.options.length > 0) 
		{
			frmCurrentForm['ctlSearchResults_lnkSearch'].disabled = 0;
			if (frmCurrentForm['ctlSearchResults_btnClear'] != null)
				frmCurrentForm['ctlSearchResults_btnClear'].disabled = 0;
		}
}

function EnableCandButton()
{
var frmCurrentForm = document.forms[0];
var txtName = frmCurrentForm["txtCandidateName"].value;
var txtdistrict = frmCurrentForm["cboDistrict"].value;
var txtProv = frmCurrentForm["cboProvince"].value;
var txtParty = frmCurrentForm["cboParty"].value;

if (txtdistrict == -1 && txtProv == -1 && txtParty == -1 && txtName.length < 1)
	frmCurrentForm['ctlSearchResultsFooter_btnSearchfoot'].disabled = 1;	
else
	frmCurrentForm['ctlSearchResultsFooter_btnSearchfoot'].disabled = 0;	
}

function EnableNomButton()
{
var frmCurrentForm = document.forms[0];
var txtName = frmCurrentForm["txtContestantName"].value;
var txtFrom = frmCurrentForm["txtDateFrom"].value;
var txtTo = frmCurrentForm["txtDateTo"].value;
var txtdistrict = frmCurrentForm["cboDistrict"].value;
var txtProv = frmCurrentForm["cboProvince"].value;
var txtParty = frmCurrentForm["cboParty"].value;

if (txtdistrict == -1 && txtProv == -1 && txtParty == -1 && txtFrom.length < 1 && txtTo.length < 1 && txtName.length < 1)
	frmCurrentForm['ctlSearchResultsFooter_btnSearchfoot'].disabled = 1;	
else
	frmCurrentForm['ctlSearchResultsFooter_btnSearchfoot'].disabled = 0;	
}

/* ===========================================================================================
    Function Name:	EnableFindButton
    Description:	This function enables/diasables the 'Find Contributor' button based on 
					whether any of the fields have specified criteria.
	HV ID: 28212	Title: 	C2: WPF Staging CAND C2 - Search by contributor 
	Date Created:	Jul 21 , 2009 - T.E.S
	==============================================================================================							
*/
function EnableFindButton()
{
	var frmCurrentForm = document.forms[0];
	var strContributorName;
	var lbSelected = false;
	var intRange; // the range selected by the user
	var intProvince; // the province selected by the user
	var intDistrict; // the electoral district selected by the user
	var intParty;	 // the political party selected by the user
	
	if (frmCurrentForm["txtContributorName"])
	{
		strContributorName = frmCurrentForm["txtContributorName"].value;
		
		if (frmCurrentForm["cboRange"])
		{
			intRange = frmCurrentForm["cboRange"].value;
		}
		else	
		{
			intRange = -1;
		}
	
		// only retrieve province, electoral district and party criteria if it is available
		if (frmCurrentForm["cboProvince"])
		{
			intProvince = frmCurrentForm["cboProvince"].value;
			intDistrict = frmCurrentForm["cboDistrict"].value;
			intParty = frmCurrentForm["cboParty"].value;
		}
		else
		{
			intProvince = -1;
			intDistrict= -1;
			intParty = -1;
		}
	
		// determine if any contributor classes selected by the user
		if (frmCurrentForm["lstContribClass"])
		{
			for (intLoopCounter = 0; intLoopCounter < frmCurrentForm["lstContribClass"].length; intLoopCounter++)
			{
				if (frmCurrentForm["lstContribClass"].options[intLoopCounter].selected)
				{
					lbSelected = true;
				}	
			}
		}
	
	if (strContributorName == "" && lbSelected == false && intRange == -1 && intProvince == -1 && intRange == -1 && intDistrict == -1 && intParty == -1)
		frmCurrentForm['lnkSearch'].disabled = 1;	
	else
		frmCurrentForm['lnkSearch'].disabled = 0;	
	}
}

/* ===========================================================================================
    Function Name:	CheckContributionCriteria
    Description:			This function validates the search criteria for the contribution report to ensure that at least one search criteria item has been selected/entered
								If at least one search criteria item is selected/entered - the form is posted to display the contribution report
								If no search criteria items are selected/entered (i.e., at their default values) - the form is posted back to display the appropriate error message
    Date Created:		February 12, 2003 - Qunara Inc.
	==============================================================================================							
*/
function CheckContributionCriteria()
{
	var frmCurrentForm = document.forms["frmSelectContributions"];			// a reference to the form containing the contribution search criteria	
	var strContributorName = frmCurrentForm["txtContributorName"].value;	// the contributor name entered by the user
	var strContributorClass = new String("");												// the contributor classes selected by the user
	var intRange = frmCurrentForm["cboRange"].value;								// the contribution range selected by the user
	var lbVisible = true;
	
	// only retrieve province, electoral district and party criteria if it is available
	if (frmCurrentForm["cboProvince"])
	{
		var intProvince = frmCurrentForm["cboProvince"].value;							// the province selected by the user
		var intDistrict = frmCurrentForm["cboDistrict"].value;								// the electoral district selected by the user
		var intParty = frmCurrentForm["cboParty"].value;									// the political party selected by the user
	}
	else
	{
		intProvince = -1;
		intDistrict= -1;
		intParty = -1;
	}
	
	// determine the contributor classes selected by the user
	if (frmCurrentForm["lstContribClass"])
	{
		for (intLoopCounter = 0; intLoopCounter < frmCurrentForm["lstContribClass"].length; intLoopCounter++)
		{
			if (frmCurrentForm["lstContribClass"].options[intLoopCounter].selected)
			{
				if (strContributorClass > "")
				{
					strContributorClass += "|";
				}
			
				strContributorClass += frmCurrentForm["lstContribClass"].options[intLoopCounter].value;
			}	
		}
	}
	else
	{
		strContributorClass = "1|6|12";
		lbVisible = false;
	}
	
	// determine if the user has selected at least one search criteria item (i.e., the search criteria are not at their default values)
	if (strContributorName == "" && lbVisible == false && intProvince == -1 && intRange == -1 && intDistrict == -1 && intParty == -1)
	{
		// the user has not selected any search criteria - do a post back to display the appropriate error message
		SetCriteriaError("SEARCH_ERROR");		
	}
	else if (strContributorName == "" && strContributorClass == "" && intProvince == -1 && intRange == -1 && intDistrict == -1 && intParty == -1)
	{
		// the user has not selected any search criteria - do a post back to display the appropriate error message
		SetCriteriaError("SEARCH_ERROR");		
	}
	else
	{
		// the user has selected search criteria - post the form to display the contributor report
		PostForm("detail_report.aspx", "contribname,contribclass,contribprov,contribrange,contribed,contribpp", strContributorName + "," + strContributorClass + "," + intProvince + "," + intRange + "," + intDistrict + "," + intParty);
	}		
}   
/* ===========================================================================================
    Function Name:	CheckAllContributionCriteria
    Description:			This function validates the search criteria for the contribution report to ensure that at least one search criteria item has been selected/entered
								If at least one search criteria item is selected/entered - the form is posted to display the contribution report
								If no search criteria items are selected/entered (i.e., at their default values) - the form is posted back to display the appropriate error message
    Date Created:		February 12, 2003 - Qunara Inc.
	==============================================================================================							
*/
function CheckAllContributionCriteria()
{
	var frmCurrentForm = document.forms["frmSelectContributions"];			// a reference to the form containing the contribution search criteria	
	var strPoliticalEntity = frmCurrentForm["cboEntity"].value;						// the political entity selected by the user
	var strContributorName = frmCurrentForm["txtContributorName"].value;	// the contributor name entered by the user
	var strContributorClass = new String("");								// the contributor classes selected by the user
	var intFiscalFrom = frmCurrentForm["cboFiscalYearFrom"].value;			// the fiscal year from selected by the user
	var intFiscalTo = frmCurrentForm["cboFiscalYearTo"].value;				// the fiscal year to selected by the user
	var intRange = frmCurrentForm["cboRange"].value;						// the contribution range selected by the user
	var strContributorParty = new String("");								// the political party selected by the user
	var intLoopCounter;
	var boolYear = true;
	var frmForm = document.forms[0];
		
	// determine the contributor classes selected by the user
	if (! frmCurrentForm["chkSelectAllClasses"].checked)
	{
		for (intLoopCounter = 0; intLoopCounter < frmCurrentForm["lstContribClass"].length; intLoopCounter++)
		{
			if (frmCurrentForm["lstContribClass"].options[intLoopCounter].selected)
			{
				if (strContributorClass > "")
				{
					strContributorClass += "|";
				}
				strContributorClass += frmCurrentForm["lstContribClass"].options[intLoopCounter].value;
			}
		}
	}
	
	// determine the contributor classes selected by the user
	if (! frmCurrentForm["chkSelectAllParties"].checked)
	{
		for (intLoopCounter = 0; intLoopCounter < frmCurrentForm["lstContribParty"].length; intLoopCounter++)
		{
			if (frmCurrentForm["lstContribParty"].options[intLoopCounter].selected)
			{
				if (strContributorParty > "")
				{
					strContributorParty += "|";
				}
				strContributorParty += frmCurrentForm["lstContribParty"].options[intLoopCounter].value;
			}
		}
	}	
	
	// determine if the user has selected at least one search criteria item (i.e., the search criteria are not at their default values)
	if (strPoliticalEntity == -1 && strContributorName == "" && strContributorClass == "" && intFiscalFrom == -1 && intFiscalTo == -1 && intRange == -1 && strContributorParty == "")
	{
		// the user has not selected any search criteria - do a post back to display the appropriate error message
		SetCriteriaError("SEARCH_ERROR");		
	}
	else
	{
		if (intFiscalFrom != -1 && intFiscalTo != -1)
		{
			if (intFiscalTo < intFiscalFrom)
			{
					boolYear = false;
			}
		}
		
		if (boolYear)
		{
			// the user has selected search criteria - post the form to display the contributor report
			PostForm("detail_report.aspx", "searchentity,contribname,contribclass,contribfiscalfrom,contribfiscalto,contribrange,contribpp,option", strPoliticalEntity + "," + strContributorName + "," + strContributorClass + "," + intFiscalFrom + "," + intFiscalTo + "," + intRange + "," + strContributorParty + ",4");
		}
		else
		{
			SetCriteriaError("YEAR_ERROR");
		}
	}		
}
/* ===========================================================================================
	Function Name:	ClosePopup
	Description:			This function closes a pop-up window
	Date Created:		May 14, 2004 - Qunara Inc.
	============================================================================================
*/
function ClosePopup()
{
	window.close();
}   
/* ===========================================================================================
    Function Name:	chkSelectAllClasses_OnChange
    Description:			This function clears all selections in the contributor class list box when the 'select all classes' check box is checked
    Arguments:			chkSelectAllClasses is a reference to the check box used to indicate that all contributor classes will be used in the search		
								frmCurrentForm is a reference to the form containing the contributor class list box and check box							
	Date Created:		February 12, 2003 - Qunara Inc.
	==============================================================================================							
*/     
function chkSelectAllClasses_OnChange(chkSelectAllClasses, frmCurrentForm)
{	
	if (chkSelectAllClasses.checked)
	{
		// clear all selections made in the contributor class list box
		frmCurrentForm["lstContribClass"].selectedIndex = -1;
	}	
}

/* ===========================================================================================
    Function Name:	chkSelectAllParties_OnChange
    Description:	This function clears all selections in the contributor party list box when the 'select all parties' check box is checked
    Arguments:		chkSelectAllParties is a reference to the check box used to indicate that all contributor parties will be used in the search		
					frmCurrentForm is a reference to the form containing the contributor party list box and check box							
	Date Created:	February 12, 2003 - Qunara Inc.
	==============================================================================================							
*/     
function chkSelectAllParties_OnChange(chkSelectAllParties, frmCurrentForm)
{	
	if (chkSelectAllParties.checked)
	{
		// clear all selections made in the contributor class list box
		frmCurrentForm["lstContribParty"].selectedIndex = -1;
	}	
}
 /* =============================================================================================
      Procedure Name:	CloseProgressBar
      Description:			This procedure closes the progress bar when the import is completed
      Argument:				intTaskType identifies the type of task for which the progress bar is displayed:
									0 (default) - importing data
									1 - deleting data
									2 - consolidating contributions
      Date Created:		March 5, 2004 - Qunara Inc.
      =============================================================================================
    */
    function CloseProgressBar(intTaskType)
    {
		var objProgressBar;			// a reference to the pop-up window used to display the progress bar
	
		// ensure that the task type is valid
		if (isNaN(intTaskType))
		{
			intTaskType = 0;
		}
		else if (intTaskType < 0 || intTaskType > 2)
		{
			intTaskType = 0;
		}
	
		// display the progress bar pop-up window
		objProgressBar = window.open("progress_bar.aspx?intTask=" + intTaskType, "progress_bar", "history=no,toolbar=no,location=no,directories=no,status=0,left=275,top=200,menubar=0,scrollbars=auto,resizable=no,width=410,height=150;");
		objProgressBar.close();
	}
/* ===========================================================================================
    Function Name:	lstContribClass_OnChange
    Description:			This function checks or unchecks the 'select all classes' check box when a contributor class is selected or deselected
    Arguments:			lstContribClass is a reference to the list box containing the contributor classes
								frmCurrentForm is a reference to the form containing the contributor class list box and check box								
	Date Created:		February 12, 2003 - Qunara Inc.
	==============================================================================================							
*/     
function lstContribClass_OnChange(lstContribClass, frmCurrentForm)
{
	// check or uncheck the select all classes check box based on whether or not a contributor class is selected in the list
	frmCurrentForm["chkSelectAllClasses"].checked = (lstContribClass.selectedIndex == -1);
}

/* ===========================================================================================
    Function Name:	lstContribParty_OnChange
    Description:	This function checks or unchecks the 'select all parties' check box when a contributor class is selected or deselected
    Arguments:		lstContribParty is a reference to the list box containing the contributor parties
					frmCurrentForm is a reference to the form containing the contributor parties list box and check box								
	Date Created:	February 12, 2003 - Qunara Inc.
	==============================================================================================							
*/     
function lstContribParty_OnChange(lstContribParty, frmCurrentForm)
{
	// check or uncheck the select all classes check box based on whether or not a contributor class is selected in the list
	frmCurrentForm["chkSelectAllParties"].checked = (lstContribParty.selectedIndex == -1);
}
/* ===========================================================================================
    Function Name:	PopUp
    Description:			This function displays a pop-up window
    Arguments:			strUrl is the URL for the pop-up window to be displayed
								intHeight is the height for the pop-up window to be displayed
								intWidth is the width for the pop-up window to be displayed
	Date Created:		February 11, 2003 - Qunara Inc.
	==============================================================================================							
*/     
function PopUp(strUrl, intHeight, intWidth)
{
	var strWindowOptions = new String("");					// used to specify the options for the pop-up window
	var objPopupWindow;												// a reference to the pop-up window
    var strDate;
    
    if (strUrl.indexOf('txtDateFrom') > 0)
    {
		strDate = document.forms[0]["txtDateFrom"].value;
		strUrl = strUrl + '&txtDate=' + strDate;
			if (document.forms[0]['ctlSearchResultsFooter_btnSearchfoot'] != undefined)
				document.forms[0]['ctlSearchResultsFooter_btnSearchfoot'].disabled = 0;	
		
    }
    else if (strUrl.indexOf('txtDateTo') > 0 )
		{
			strDate = document.forms[0]["txtDateTo"].value;
			strUrl = strUrl + '&txtDate=' + strDate;
			if (document.forms[0]['ctlSearchResultsFooter_btnSearchfoot'] != undefined)
				document.forms[0]['ctlSearchResultsFooter_btnSearchfoot'].disabled = 0;	
		}
		
	// set the options for the pop-up window and apply the specified height and width
	strWindowOptions = "'history=no,toolbar=0,location=0,directories=0,status=0,left=100,top=100,menubar=0,resizable=yes,scrollbars=yes,width=" + intWidth + ",height=" + intHeight + "'";

	// display the pop-up window and set it as the active window
	objPopupWindow = window.open(strUrl, "", strWindowOptions);
	objPopupWindow.focus();	
}
/* ===========================================================================================
    Function Name:	PostForm
    Description:	This function posts form information to a different web form 
    Arguments:		strActionPage is the name of the page to which the information is posted
					strFieldNames is a comma-delimited list of the names of the fields whose values will be updated before posting the form
					strFieldValues is a comma-delimited list of the updated field values
	Date Created:	February 6, 2003 - Qunara Inc.
	Date Modified:	May 3, 2007 - IBM (T.E.S) - HV ID: 23605 "Previous 4 contestants" link appears incorrectly
	==============================================================================================							
*/    
function PostForm(strActionPage, strFieldNames, strFieldValues)
{
	var frmCurrentForm = document.forms["frmClientPost"];		// a reference to the HTML form used to post information to a different web form
	var intPrevRet = strFieldNames.indexOf("PrevReturn");
	var ctlItem = document.getElementById("ctlReportBar_cboItem")
	var strValues = new String(strFieldValues);
	
	if (frmCurrentForm) {
	// determine if the action page needs to be changed
	if (strActionPage > "")
	{
		// ------------------------------------------------------------
		// If the form is switching between summary and detail, reset the
		// page number
		// ------------------------------------------------------------
		if (document.forms[0]["page"] && frmCurrentForm.action != strActionPage) 
		{
			frmCurrentForm["page"].value = 1; 
		}
		
		// set the name of the page to which information will be posted
		frmCurrentForm.action = strActionPage;		
	}
	
	/* EXCEPTION: the following if block is used to set the appropriate item when viewing reports if the user changes the language */
	if (ctlItem && strFieldNames == "lang")
	{
		frmCurrentForm["id"].value = ctlItem.value;
	}
	
	// determine if any field values need to be updated before posting the form
	if (strFieldNames > "" && strValues.length > 0 )
	{		
		var strFieldNameArray = strFieldNames.split(",");	
		var strFieldValueArray = strValues.split(",");
		
		// update the specified hidden fields
		for (intLoopCounter=0; intLoopCounter < strFieldNameArray.length; intLoopCounter++)
		{
			frmCurrentForm[strFieldNameArray[intLoopCounter]].value = strFieldValueArray[intLoopCounter];
		}		
	}	
	
	if (intPrevRet < 0) 
	{
		frmCurrentForm["PrevReturn"].value = "0";	
	}
	
	// submit the form
	frmCurrentForm.submit();
 }
}
/* ============================================================================================================
	Function Name:	SelectReturns
	Description:			This function selects or de-selects all returns when the user clicks the "select all returns" check box or makes a selection in the list box
	Arguments:			ctlCurrentControl is a reference to the control raising this event
								chkSelectAllReturns is a reference to the check box used to select or de-select returns
								lstReturnList is a reference to the list box containing the returns to be selected or de-selected
	Date Created:		May 12, 2004 - Qunara Inc.
	=============================================================================================================
*/								
function SelectReturns(ctlCurrentControl, chkSelectReturns, lstReturnList)
{
	// determine which control initiated the event
	if (ctlCurrentControl == chkSelectReturns)
	{
		// the user clicked on one of the "select all returns" check boxes
		if (chkSelectReturns.checked)
		{
			// select all returns in the list
			for (intReturnCounter=0; intReturnCounter < lstReturnList.options.length; intReturnCounter++)
			{
				lstReturnList.options[intReturnCounter].selected=true;
			}
		}
		else
		{
			// clear all list selections
			lstReturnList.selectedIndex = -1;
		}		
	}
	else
	{
		//HV ID: 39338 - Check 'Select All' checkbox if all in list is selected
		li_NumSelected = 0;
		// select all returns in the list
		for (intReturnCounter=0; intReturnCounter < lstReturnList.options.length; intReturnCounter++)
		{
			if (lstReturnList.options[intReturnCounter].selected) li_NumSelected++ ;
		}

		if (chkSelectReturns!=undefined)
		if (li_NumSelected >= lstReturnList.options.length) 
			// the user selected all in the list - check the "select all returns" check box
			chkSelectReturns.checked = true;	
		else
			// the user made a selection in the list - uncheck the "select all returns" check box
			chkSelectReturns.checked = false;		
	}
	EnableFindButton();
}
/* =============================================================================================
    Function Name:		SetCriteriaError
    Description:				This function sets the error value when an error condition exists on the page
    Argument:				strErrorValue is the error value used to indicate the specific error condition existing on the page
    Date Created:			March 16, 2004 - Qunara Inc.
    ==============================================================================================
*/
function SetCriteriaError(strErrorValue)
{
	// set the EVENTARGUMENT field to the specified error value to indicate an error condition with the page
	document.forms[0]["EVENTARGUMENT"].value = strErrorValue;
	document.forms[0].submit();
}
/* ===========================================================================================
    Function Name:	SetIDList
    Description:	This function sets the selected ids to be posted to the next page when the list of ids can be lengthy
    Arguments:		strPage is the page to be displayed when the form is posted
					strFieldName is the name of the field whose value will be updated with the list of IDs
					frmMainForm is the form containing the list of IDS to be posted with the form
	Date Created:	February 12, 2004 - Qunara Inc.
	Date Modified:	May 12, 2004 - Qunara Inc. - modified to specify more than one field name (required for Registered Associations)
					May 31, 2004 - Qunara Inc. - removed change implemented on May 12th as it was no longer required
	==============================================================================================							
*/     
function SetIDList(strPage, strFieldName, frmMainForm)
{
	var frmPostForm = document.forms["frmClientPost"];				// a reference to the form used to post information to the next page
		
	// update the specified field with the value of the hidden id list field on the form
	frmPostForm[strFieldName].value = frmMainForm["ctlSearchResults$hidIDList"].value;
			
	// post the form
	PostForm(strPage, "","");
}
/* ===========================================================================================
    Function Name:	SetLCWKIDList
    Description:			This function sets the selected ids to be posted to the next page when the list of ids can be lengthy
    Arguments:			strPage is the page to be displayed when the form is posted
								strFieldName is the name of the field whose value will be updated with the list of IDs
								frmMainForm is the form containing the list of IDS to be posted with the form
	Date Created:		February 12, 2004 - Qunara Inc.
	Date Modified:		May 12, 2004 - Qunara Inc. - modified to specify more than one field name (required for Registered Associations)
								May 31, 2004 - Qunara Inc. - removed change implemented on May 12th as it was no longer required
	==============================================================================================							
*/     
function SetLCWKIDList(strPage, strOption, frmMainForm)
{
	var frmPostForm = document.forms["frmClientPost"];				// a reference to the form used to post information to the next page
		
	// update the specified field with the value of the hidden id list field on the form
	frmPostForm["option"].value = strOption;
	frmPostForm["ids"].value = frmMainForm["ids"].value;
			
	// post the form
	PostForm(strPage, "","");
}
/* ===========================================================================================
    Function Name:	ShowItem
    Description:			This function displays the report for the selected item
    Arguments:			cboItem is a reference to the item drop down list on the page
								intOffset is the offset to add (or subtract) from the selected index for the item drop down list to retrieve the identifier for the item to be displayed
	Date Created:		May 12, 2004 - Qunara Inc.	
	==============================================================================================							
*/     
function ShowItem(cboItem, intOffset)
{
	PostForm('', "id", cboItem.options[cboItem.selectedIndex - intOffset].value);
}
/* ===========================================================================================
    Function Name:	ShowPage
    Description:			This function displays the report page when paging is used for a report
    Arguments:			intOffset is the offset to add (or subtract) from the current page number in order to determine the page to be displayed								
	Date Created:		May 12, 2004 - Qunara Inc.	
	==============================================================================================							
*/     
function ShowPage(intOffset)
{
	var cboPart;
	var strSelectedPartValue; 
	var strPartInfo;
	var strPartNumber;
	var strReportPage="";
	var strFieldNames;
	var strFieldValues;
	var intCurrentPage = document.forms[0]["page"].value;		// the current page number
	var intCurrentSort = document.forms[0]["sort"].value;		// the current page number

	if (document.forms[0]["ctlReportBar_cboPart"])
	{
		cboPart = document.forms[0]["ctlReportBar_cboPart"];
		strSelectedPartValue = cboPart.options[cboPart.selectedIndex].value; // the value for the financial return part to be displayed
		strPartInfo = strSelectedPartValue.split("|");			// an array used to split the value for the selected financial return part
		strPartNumber = strPartInfo[0];			// the part number for the financial return part to be displayed
		strReportPage = strPartInfo[1];				// the page used to display the selected financial return part
	}
	if (isNaN(intCurrentPage) || intCurrentPage < 0)
	{
		// default to page 1 if the current page number cannot be determined
		intCurrentPage = 1;
	}
	
	if (isNaN(intCurrentSort) || intCurrentSort < 0)
	{
		// default to page 1 if the current page number cannot be determined
		intCurrentSort = 0;
	}
	
	if (strReportPage.length > 0)
	{
		strFieldNames = "page,part,sort";
		strFieldValues = new String(intCurrentPage - intOffset);
		strFieldValues = strFieldValues + "," + strPartNumber + "," + intCurrentSort ;
	}
	else
	{
		strFieldNames = "page";
		strFieldValues = new String(intCurrentPage - intOffset);
	}

	PostForm(strReportPage, strFieldNames, strFieldValues);
}

/* ===========================================================================================
    Function Name:	ReSetPageNumber
    Description:		This function resets the page number for the report
	Date Created:		July 26, 2005 - BNair@EC.	
	==============================================================================================							
*/     
function ReSetPageNumber()
{
	document.forms[0]["page"].value = 1;
	var intCurrentPage = document.forms[0]["page"].value;
	PostForm("", "page", new String(intCurrentPage));
}
/* ===========================================================================================
    Function Name:	ShowPart
    Description:			This function displays the selected financial return part report
    Arguments:			cboItem is a reference to the part drop down list on the page
								intOffset is the offset to add (or subtract) from the selected index for the part drop down list to retrieve the identifier for the financial return part to be displayed
	Date Created:		May 12, 2004 - Qunara Inc.	
	==============================================================================================							
*/     
function ShowPart(cboPart, intOffset)
{
	var intNewIndex = cboPart.selectedIndex - intOffset; // the value of the newly selected index
	var intDDLen = cboPart.length - 1; // The number of item in the DropDownList
	var strSelectedPartValue ;		// the value for the financial return part to be displayed
	var strPartInfo; 				// an array used to split the value for the selected financial return part
	var strPartNumber; 				// the part number for the financial return part to be displayed
	var strReportPage; 				// the page used to display the selected financial return part
	var frmCurrentForm = document.forms["frmClientPost"];		// a reference to the HTML form 
	var strPage, strVal;
	var i=0;

	// ----------------------------------------
	// Ensure the newly selected index is not 
	// greater than the number of items in the list
	// ----------------------------------------
	if (intNewIndex > intDDLen)
		intNewIndex = 0;

	// ----------------------------------------
	// Get the Partnumber and URL for the page
	// ----------------------------------------
	strSelectedPartValue = cboPart.options[intNewIndex].value;	
	strPartInfo = strSelectedPartValue.split("|");
	strPartNumber = strPartInfo[0];
	strReportPage = strPartInfo[1];
	
	if (strPartNumber.substring(0,2) == "AR" || strPartNumber.substring(0,1) == "9" )
	{
		if (frmCurrentForm) 
		{
			strVal = frmCurrentForm["part"].value ;
			strVal = strVal.toLowerCase() ;
		
			// -------------------------------------------------------
			// This code segment is required to satisfy the condition
			// when the 'Back' button is pressed in the browser.
			// Since the "AR" report and "Part 9" navigate
			// away from the page, we must change the selected
			// item in the dropdownlist to the last selected 
			// part, to keep the data on the page in sync with
			// the part number selected in the dropdown.
			// -------------------------------------------------------
			for (i=0;i<=intDDLen;i++) 
			{
				strSelectedPartValue = cboPart.options[i].value;	
				strPartInfo = strSelectedPartValue.split("|");
				strPartNumber = strPartInfo[0].toLowerCase();
				if (strPartNumber.substring(0,2) == strVal)
					cboPart.selectedIndex = i;
			}
		}
		// ----------------------------------------
		// Navigate away from page
		// ----------------------------------------
		self.location = strReportPage;
	}
	else
	{
		// ----------------------------------------
		// Navigate to next part
		// ----------------------------------------
		PostForm(strReportPage, "part,sort", strPartNumber + ",0");	
	}	
}

/* ===========================================================================================
    Function Name:	ShowIDList
    Description:	This function sets the selected ids to be posted to the next page
    Arguments:		
	Date Created:	Nov 12, 2008 - T.E.S
	==============================================================================================							
*/     
function ShowIDList()
{
	var frmPostForm = document.forms["frmClientPost"];	// a reference to the form used to post information to the next page
	var frmMain = document.forms[0]; // a reference to the form used to post information to the next page
	var poption = frmMain["option"].value; 
	var listBox = document.getElementById("ctlSearchResults_lstSearchResults");
	//var listBox = frmMain["ctlSearchResults:lstSearchResults"]; 
	var btnSearch = document.getElementById("ctlSearchResults_lnkSearch");
	//var btnSearch = frmMain["ctlSearchResults:lnkSearch"]; 
	var elements = " "; 
    var intCount = listBox.options.length; 

	//alert("listBox.options.length = " + intCount); 		
	
	if (btnSearch.disabled == false)
	if (intCount > 0 ) 
	{
		//store the elements in a hidden input that we can get server side 
	    for (i = 0; i < intCount; i++) 
	    {
			if (listBox.options[i].selected ) 
			{
				elements = elements + listBox.options[i].value + "|"; 
			}
		} 
	
		if (elements.length > 1) 
		{
			elements = elements.substr(0,(elements.length - 1));
			switch (poption) 
			{
				case "0": strFieldName = "filter"; strUrl = "select_search_option.aspx"; break;
				case "1": strFieldName = "ids"; strUrl = "summary_report.aspx"; break;
				case "2": strFieldName = "ids"; strUrl = "select_part.aspx"; break;
				case "3": strFieldName = "ids"; strUrl = "summary_report.aspx"; break;
				case "4": strFieldName = "ids"; strUrl = "detail_report.aspx"; break;
				case "5": strFieldName = "ids"; strUrl = "detail_report.aspx"; break;
				case "11": strFieldName = "filter"; strUrl = "summary_report.aspx"; break;
				default: strFieldName = "filter"; strUrl = "select_search_option.aspx";
			}

			// update the specified field with the value of the hidden id list field on the form
			frmPostForm[strFieldName].value = elements;

			// post the form
			PostForm(strUrl, "","");
		} 
		else
		{
		SetCriteriaError("SEARCH_ERROR");
		}
	}
	else
	{
		SetCriteriaError("SEARCH_ERROR");
	}
		
}

/* ===============================================================================================
	Function Name:	ShowProgressBar
	Description:			This procedure displays the progress bar pop-up window for a lengthy administrative task
	Argument:			intTaskType identifies the type of task for which the progress bar is displayed:
									0 (default) - importing data
									1 - deleting data
									2 - consolidating contributions
	Date Created:		March 5, 2004 - Qunara Inc.
	===============================================================================================
*/
function ShowProgressBar(intTaskType)
{
	var objProgressBar;			// a reference to the pop-up window used to display the progress bar
		
	// ensure that the task type is valid
	if (isNaN(intTaskType))
	{
		intTaskType = 0;
	}
	else if (intTaskType < 0 || intTaskType > 2)
	{
		intTaskType = 0;
	}
	
	// display the progress bar pop-up window
	objProgressBar = window.open("progress_bar.aspx?intTask=" + intTaskType, "progress_bar", "history=no,toolbar=no,location=no,directories=no,status=0,left=275,top=200,menubar=0,scrollbars=auto,resizable=no,width=410,height=150;");
	objProgressBar.focus();
	
}
/* ===========================================================================================
    Function Name:	chkSelectAllContestants_OnChange
    Description:	This function clears any entry in the Contestant Name text box when the 'select all contestants' check box is checked
    Arguments:		chkSelectAllContestants is a reference to the check box used to indicate that all contestants will be used in the search		
					frmCurrentForm is a reference to the form containing the contestant name text box and check box							
	Date Created:	March 11, 2004 - Qunara Inc.
	==============================================================================================							
*/     
function chkSelectAllContestants_OnChange(chkSelectAllContestants, frmCurrentForm)
{	
	if (chkSelectAllContestants.checked)
	{
		// clear all selections made in the contributor class list box
		frmCurrentForm["txtContestantName"].value = "";
	}	
}
/* ===========================================================================================
    Function Name:	txtContestantName_OnChange
    Description:	This function checks or unchecks the 'select all contestants' check box when a contestant name is entered or removed
    Arguments:		txtContestantName is a reference to the list box containing the contributor classes
					frmCurrentForm is a reference to the form containing the contributor class list box and check box								
	Date Created:	February 12, 2003 - Qunara Inc.
	==============================================================================================							
*/     
function txtContestantName_OnChange(txtContestantName, frmCurrentForm)
{
	// check or uncheck the select all classes check box based on whether or not a contributor class is selected in the list
	frmCurrentForm["chkSelectAllContestants"].checked = (txtContestantName.value == "");
}

/* ===========================================================================================
    Function Name:	ReloadWithEntitySelected
    Description:	This function checks or unchecks the 'select all contestants' check box when a contestant name is entered or removed
    Arguments:		strEntity is the entity selected by the user from the entity drop down list
   	Date Created:	Jan 11, 2007 - Gyot Solutions/Saadi Gebara
	==============================================================================================							
*/
function ReloadWithEntitySelected(strEntity) {
	alert("TEST");
	window.location="refresh.aspx?entity=1&step=1&selEntity="+strEntity;
}

/* ===========================================================================================
    Function Name:	DoRefreshSubmit
    Description:	This function checks or unchecks the 'select all contestants' check box when a contestant name is entered or removed
    Arguments:		url to go to
					strEntity is the entity selected by the user from the entity drop down list
   	Date Created:	Jan 11, 2007 - Gyot Solutions/Saadi Gebara
	==============================================================================================							
*/
function DoRefreshSubmit(url, frm ){
	var strDE	= frm.chkDE.value;
	var strAUDT = frm.chkAUDT.value;
	//alert(document.frmRefresh.chkAUDT.value);
	//alert(strDE);
	//alert(strAUDT);

}

/*
==================================================================================
	Function Name:	GetSelEventIDs
	Description:	Sets the new url with the selected checkboxes into what will
					be grabbed byt the server as the queryString variable (SelDE_IDs, SelAUDT_IDs)
	Date Created:	Jan 23, 2007	Gyto Solutions/Saadi Gebara
==================================================================================
*/
function GetSelEventIDs(selEntity) {
    var tbl = document.getElementById('tabname');
	var lastRow = tbl.rows.length;
	var tblLen  = document.frmRefreshClient.chkDE.length;
	var strDE_nIDs = "";//document.frmRefreshClient.nonchk.value;
	var strDE_IDs = "";//document.frmRefreshClient.chkDE.value;
	var strAUDT_IDs = "";//document.frmRefreshClient.chkAUDT.value;
	var strAUDT_nIDs = "";//document.frmRefreshClient.nonchk.value;
	var chkbox, ll_Len;
	
	if(typeof(tblLen)=="undefined" || typeof(tblLen)==null)
	{ 
		if (document.frmRefreshClient.chkDE.checked)
		{
			if (document.frmRefreshClient.chkAUDT.checked)
			{
				//  -- Y --
				strDE_IDs = strDE_IDs + document.frmRefreshClient.chkDE.value + ",";
			}
			else
			{
				//  -- D --
				strDE_nIDs = strDE_nIDs + document.frmRefreshClient.chkDE.value + ",";
			}
		}
		else
		{
			if (document.frmRefreshClient.chkAUDT.checked)
			{
				//  -- A --
				strAUDT_IDs = strAUDT_IDs + document.frmRefreshClient.chkAUDT.value + ",";
			}
			else
			{
				//  -- N --
				strAUDT_nIDs = strAUDT_nIDs + document.frmRefreshClient.chkAUDT.value + ",";
			}
		}
	}

	// --------------------------------------------------------
	// Set DE checkboxes
	// --------------------------------------------------------
	for (var i=0; i<tblLen; i++)
	{
		if (document.frmRefreshClient.chkDE[i].checked)
		{
			if (document.frmRefreshClient.chkAUDT[i].checked)
			{
				//  -- Y --
				strDE_IDs = strDE_IDs + document.frmRefreshClient.chkDE[i].value + ",";
			}
			else
			{
				//  -- D --
				strDE_nIDs = strDE_nIDs + document.frmRefreshClient.chkDE[i].value + ",";
			}
		}
		else
		{
			if (document.frmRefreshClient.chkAUDT[i].checked)
			{
				//  -- A --
				strAUDT_IDs = strAUDT_IDs + document.frmRefreshClient.chkAUDT[i].value + ",";
			}
			else
			{
				//  -- N --
				strAUDT_nIDs = strAUDT_nIDs + document.frmRefreshClient.chkAUDT[i].value + ",";
			}
		}
	}

	// --------------------------------------------------------
	// Delete rows
	// --------------------------------------------------------
	for (var i=tbl.rows.length-2; i>0; i--)
	   {
		tbl.deleteRow(i);   
		}
  
	// --------------------------------------------------------
	// Set cookies
	// --------------------------------------------------------
	ll_Len = strDE_IDs.length - 1;
	setCookie("chkDE", strDE_IDs.substr(0,(strDE_IDs.length - 1)));
	setCookie("nonchkDE", strDE_nIDs.substr(0,(strDE_nIDs.length - 1)));
	setCookie("chkAUDT", strAUDT_IDs.substr(0,(strAUDT_IDs.length - 1)));
	setCookie("nonchkAUDT", strAUDT_nIDs.substr(0,(strAUDT_nIDs.length - 1)));

   document.frmRefreshClient.btnSubmitFrmR1.action = "?refresh.aspx?selEntity="+selEntity;
   document.frmRefreshClient.btnSubmitFrmR1.submit;
}

/*
==================================================================================
	Function Name:	StartRefresh2
	Description:	Sets the new url with the selected checkboxes into what will
					be grabbed byt the server as the queryString variable (SelDE_IDs, SelAUDT_IDs)
	Date Created:	Jan 23, 2007	Gyto Solutions/Saadi Gebara
==================================================================================
*/
function StartRefresh2(selEntity) {
   document.frmRefreshClient.btnSubmitFrmR2.action = "?refresh.aspx?selEntity="+selEntity;
   document.frmRefreshClient.btnSubmitFrmR2.submit;
}

/*
==================================================================================
	Function Name:	StartRefresh3
	Description:	Sets the new url with the selected checkboxes into what will
					be grabbed byt the server as the queryString variable (SelDE_IDs, SelAUDT_IDs)
	Date Created:	Feb 15th, 2007	Gyto Solutions/Saadi Gebara
==================================================================================
*/
function StartRefresh3(selEntity) {
   document.frmRefreshClient.btnSubmitFrmR2.action = "refresh.aspx?entity=1&step=3&selEntity="+selEntity;
   document.frmRefreshClient.btnSubmitFrmR2.submit;
}

/*
==================================================================================
	Function Name:	confirmDelete
	Description:	Prompts user to confim deletion of refresh
	Used by:		Admin/refresh.aspx
	Date Created:	Aug 15th, 2008	T.E.S/Greg Garvey
==================================================================================
*/
function confirmDelete(checkVal) {
	var lb_Delete=new Boolean(checkVal);
	if (lb_Delete == false) {
		return window.confirm("Unchecking this box will remove all the data. Are you sure this is ok?");
	}
}

/*
==================================================================================
	Function Name:	CheckAllDataGridCheckBoxes
	Description:	checks all DataGrid CheckBoxes with the given name with the given value
	Used by:		Admin/refresh.aspx
	Date Created:	Aug 15th, 2008	T.E.S/Greg Garvey
==================================================================================
*/
    function CheckAllDataGridCheckBoxes(aspCheckBoxID, checkVal) {
		var lb_Delete=new Boolean(checkVal);
		var l_RegExp;
		var l_Element

        l_RegExp = new RegExp(':' + aspCheckBoxID + '$')  //generated control name starts with a colon
		
		if (lb_Delete == false) {
			lb_Delete = confirmDelete(checkVal);
			if (lb_Delete == false) {
				if (aspCheckBoxID == 'chkDE') {
					document.forms[0].chkAllItemsDE.checked = true;
				}
				else {
					document.forms[0].chkAllItemsAUDT.checked = true;
				}
				return;
			}
		}
        for(i = 0; i < document.forms[0].elements.length; i++) {
            l_Element = document.forms[0].elements[i]
            if (l_Element.type == 'checkbox') {
                if (l_RegExp.test(l_Element.name)) {
                    l_Element.checked = checkVal
                }
            }
        }
    }

