
function fnOpenClubDownloadInExcel()
{
	var w = screen.availWidth;
	var h = screen.availHeight;
	var popW = 800;
	var popH = 600;
	var leftPos = (w-popW)/2;
	var topPos = (h-popH)/2;
	var strSettings = "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0," + 
					   "width=" + popW + 
					   ",height=" + popH + 
					   ",left = " + leftPos + 
					   ",top = "+ topPos;
					   
	popUp = window.open("ClubDownloadInExcel.aspx", "clubPopup", strSettings);
}

function fnOpenClubFinanceDownloadInExcel()
{
	var w = screen.availWidth;
	var h = screen.availHeight;
	var popW = 800;
	var popH = 600;
	var leftPos = (w-popW)/2;
	var topPos = (h-popH)/2;
	var strSettings = "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0," + 
					   "width=" + popW + 
					   ",height=" + popH + 
					   ",left = " + leftPos + 
					   ",top = "+ topPos;
					   
	popUp = window.open("ClubFinanceDownloadInExcel.aspx", "clubPopup",strSettings);
}

function fnOpenDetailedClubFinanceBreakdownInExcel(clubId)
{
	var w = screen.availWidth;
	var h = screen.availHeight;
	var popW = 800;
	var popH = 600;
	var leftPos = (w-popW)/2;
	var topPos = (h-popH)/2;
	var strSettings = "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0," + 
					   "width=" + popW + 
					   ",height=" + popH + 
					   ",left = " + leftPos + 
					   ",top = "+ topPos;
					   
	popUp = window.open("DetailedClubFinanceBreakdownInExcel.aspx?ClubId=" + clubId, "financePopup",strSettings);
}

function fnBack()
{
	history.go(-1);
}

function fnShowClubLeaderFAQ()
{
	document.getElementById("trBTVolunteerFAQ").style.display = 'none';
	document.getElementById("trClubLeaderFAQ").style.display = 'block';
	
	document.getElementById("lnkBTVolunteerFAQs").className = 'LinkClass';
	document.getElementById("lnkClubLeaderFAQs").className = 'SelectedLinkClass';
}

function fnShowBTVolunteerFAQ()
{
	document.getElementById("trBTVolunteerFAQ").style.display = 'block';
	document.getElementById("trClubLeaderFAQ").style.display = 'none';
	
	document.getElementById("lnkBTVolunteerFAQs").className = 'SelectedLinkClass';
	document.getElementById("lnkClubLeaderFAQs").className = 'LinkClass';
}

function fnUpdateFAQs(id,faqId)
{
	var quesTextAreaId = "txtQuestion_" + id;
	var ansTextAreaId = "txtAnswer_" + id;
	
	var question = document.getElementById(quesTextAreaId).value;
	var answer = document.getElementById(ansTextAreaId).value;
	
	//check if question field is left blank
	if(question == "")
	{
		fnThrowErrorBTVJavascript("Please enter a question.");
		document.getElementById(quesTextAreaId).focus()
		return;
	}

	//check if answer field is left blank
	if(answer == "")
	{
		fnThrowErrorBTVJavascript("Please enter an answer.");
		document.getElementById(ansTextAreaId).focus()
		return;
	}
	
	document.getElementById("hdnValueForUpdate").value = faqId + "~" + question.toString() + "~" + answer.toString();
	
	document.Form1.submit();
}

function fnDeleteFAQs(faqId)
{
	if(confirm('Are you sure?'))
	{
		document.getElementById("hdnValueForDelete").value = faqId;
		document.Form1.submit();
	}
}

function fnShowNewBTVolunteerFAQ()
{
	document.getElementById("trNewBTVolunteerFAQ").style.display = 'block';
}

function fnConfirmNewsDelete(newsId)
{
	if(confirm('Do you really want to delete the news?'))
	{
		document.getElementById("hdnNewsId").value = newsId;
		document.Form1.submit();
	}
}

function fnShowNewNotes()
{
	document.getElementById("trAddNotes").style.display = 'block';
}

function fnNotesDelete()
{
	if(confirm('Do you really want to delete the notes?'))
	{
		document.getElementById("hdnNotesId").value = '1';
		document.Form1.submit();
	}
}

function checkAllCheckBox ()
{
	var frm = document.Form1;
	for (i=0; i<frm.length; i++) 
	{
		elem=frm.elements[i];
		if(elem.type=='checkbox' && elem.name.indexOf('chkSelect') != -1)
			{
				elem.checked = true;
			}
	}
	return true;
}

function clearAllCheckBox ()
{
	var frm = document.Form1;
	for (i=0; i<frm.length; i++) 
	{
		elem=frm.elements[i];
		if(elem.type=='checkbox' && elem.name.indexOf('chkSelect') != -1)
			{
				elem.checked = false;
			}
	}
	return true;
}

function getResult()
{
	var strResult = "";                                   
	var count = 0 ;
	chk=document.forms[0].chkSelect
	
	//added for Roles Admin page -- start
	if(document.getElementById("cmbAdmins") != null)
	{
		if(document.getElementById("cmbAdmins").value == "")
		{
			fnThrowErrorBTVJavascript("Please select an admin to allocate.");
			document.getElementById("cmbAdmins").focus();
			return;
		}
	}
	//added for Roles Admin page -- end
	
	if(typeof(chk)=="undefined")
		return;				
                                                      
	if(typeof(chk.checked)=="undefined")
	{                                               
		for (i=0; i<chk.length; i++)                                   
		{                                               
			if(chk[i].checked == true)
			{
				strResult = strResult + chk[i].value + "~";
				count= count + 1 ;
			}
		}   
		
		if(count>0)
		{
			document.getElementById("hdnClubId").value = strResult;
			document.Form1.submit();
		}
		else
		{
			fnThrowErrorBTVJavascript("No club selected.");
		}
	}
	else
	{
		if(chk.checked==true)
		{
			strResult = strResult + chk.value + "~"; 
			document.getElementById("hdnClubId").value = strResult;
			document.Form1.submit();
		}
		else
		{
			fnThrowErrorBTVJavascript("No club selected.");
		}
	}
}

function checkAllCheckBoxClubs ()
{
	var frm = document.Form1;
	for (i=0; i<frm.length; i++) 
	{
		elem=frm.elements[i];
		if(elem.type=='checkbox' && elem.name.indexOf('chkSelectClubs') != -1)
			{
				elem.checked = true;
			}
	}
	return true;
}

function clearAllCheckBoxClubs ()
{
	var frm = document.Form1;
	for (i=0; i<frm.length; i++) 
	{
		elem=frm.elements[i];
		if(elem.type=='checkbox' && elem.name.indexOf('chkSelectClubs') != -1)
			{
				elem.checked = false;
			}
	}
	return true;
}

function getResultClubs()
{
	var strResult = "";                                  
	var count = 0 ;
	chk=document.forms[0].chkSelectClubs
	
	if(document.getElementById("cmbRole") != null)
	{
		if(document.getElementById("cmbRole").value == "")
		{
			fnThrowErrorBTVJavascript("Please select a role");
			document.getElementById("cmbRole").focus();
			return;
		}
	}
	
	if(typeof(chk)=="undefined")
		return;				
                                                      
	if(typeof(chk.checked)=="undefined")
	{                                               
		for (i=0; i<chk.length; i++)                                   
		{                                               
			if(chk[i].checked == true)
			{
				strResult = strResult + chk[i].value + "~";
				count= count + 1 ;
			}
		}   
		
		if(count>0)
		{
			
			document.getElementById("hdnClubId").value = strResult;
			
			//for multiple selection Club Leader or Delegate role can not be selected.
			if(count>1)
			{
				if(document.getElementById("cmbRole").value == "2" || document.getElementById("cmbRole").value == "4")
				{
					fnThrowErrorBTVJavascript("A club can not have more than one Club Leader or Delegate Club Leader");
					document.getElementById("cmbRole").focus(); 
					return;
				}
			}
			/////
			
			document.Form1.submit();
		}
		else
		{
			fnThrowErrorBTVJavascript("No club selected.");
		}
	}
	else
	{
		
		if(chk.checked==true)
		{
			strResult = strResult + chk.value + "~"; 
			document.getElementById("hdnClubId").value = strResult;
			
			//////
			var tempStrResult = strResult.substring(strResult.indexOf('~')+1, strResult.length)
			if(tempStrResult.length > 0)
			{
				if(document.getElementById("cmbRole").value == "2" || document.getElementById("cmbRole").value == "4")
				{
					fnThrowErrorBTVJavascript("A club can not have more than one Club Leader or Delegate Club Leader");
					document.getElementById("cmbRole").focus();
					return;
				}
			}
			//////
			
			document.Form1.submit();
		}
		else
		{
			fnThrowErrorBTVJavascript("No club selected.");
		}
	}
}

function getResultVolunteers()
{
	var strResult = "";                                   
	var count = 0 ;
	chk=document.forms[0].chkSelect
	
	if(document.getElementById("cmbRole") != null)
	{
		if(document.getElementById("cmbRole").value == "")
		{
			fnThrowErrorBTVJavascript("Please select a role");
			document.getElementById("cmbRole").focus();
			return;
		}
	}
	
	if(typeof(chk)=="undefined")
		return;				
                                                      
	if(typeof(chk.checked)=="undefined")
	{                                               
		for (i=0; i<chk.length; i++)                                   
		{                                               
			if(chk[i].checked == true)
			{
				strResult = strResult + chk[i].value + "~";
				count= count + 1 ;
			}
		}   
		
		if(count>0)
		{
			document.getElementById("hdnClubId").value = strResult;
			
			//for multiple selection Club Leader or Delegate role can not be selected.
			if(count>1)
			{
				if(document.getElementById("cmbRole").value == "2" || document.getElementById("cmbRole").value == "4")
				{
					fnThrowErrorBTVJavascript("A club can not have more than one Club Leader or Delegate Club Leader");
					document.getElementById("cmbRole").focus();
					return;
				}
			}
			/////
			
			document.Form1.submit();
		}
		else
		{
			fnThrowErrorBTVJavascript("No volunteer selected.");
		}
	}
	else
	{
		if(chk.checked==true)
		{
			strResult = strResult + chk.value + "~"; 
			document.getElementById("hdnClubId").value = strResult;
			
			//////
			var tempStrResult = strResult.substring(strResult.indexOf('~')+1, strResult.length)
			if(tempStrResult.length > 0)
			{
				if(document.getElementById("cmbRole").value == "2" || document.getElementById("cmbRole").value == "4")
				{
					fnThrowErrorBTVJavascript("A club can not have more than one Club Leader or Delegate Club Leader");
					document.getElementById("cmbRole").focus();
					return;
				}
			}
			//////
			
			document.Form1.submit();
		}
		else
		{
			fnThrowErrorBTVJavascript("No volunteer selected.");
		}
	}
}

function getResultEstablishment(itemName)
{
	var strResult = "";                                   
	var count = 0 ;
	chk=document.forms[0].chkSelect

	if(document.getElementById("cmbClubs").value == "")
	{
		fnThrowErrorBTVJavascript("Please select a club to transfer");
		document.getElementById("cmbClubs").focus();
		return;
	}
	
	if(typeof(chk)=="undefined")
		return;				
                                                      
	if(typeof(chk.checked)=="undefined")
	{                                               
		for (i=0; i<chk.length; i++)                                   
		{                                               
			if(chk[i].checked == true)
			{
				strResult = strResult + chk[i].value + "~";
				count= count + 1 ;
			}
		}   
		
		if(count>0)
		{
			document.getElementById("hdnEstablishmentId").value = strResult;
			document.Form1.submit();
		}
		else
		{
			fnThrowErrorBTVJavascript("No " + itemName + " selected.");
		}
	}
	else
	{
		if(chk.checked==true)
		{
			strResult = strResult + chk.value + "~"; 
			document.getElementById("hdnEstablishmentId").value = strResult;
			document.Form1.submit();
		}
		else
		{
			fnThrowErrorBTVJavascript("No " + itemName + " selected.");
		}
	}
}

function fnOpenVolunteersDownloadInExcel(downloadType)
{
	var w = screen.availWidth;
	var h = screen.availHeight;
	var popW = 800;
	var popH = 600;
	var leftPos = (w-popW)/2;
	var topPos = (h-popH)/2;
	var strSettings = "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0," + 
					   "width=" + popW + 
					   ",height=" + popH + 
					   ",left = " + leftPos + 
					   ",top = "+ topPos;
					   
	popUp = window.open("VolunteersDownloadInExcel.aspx?DownloadType=" + downloadType, "volunteerPopup",strSettings);
}

function fnOpenPublicPages()
{
	var width = 500;
	var height = 400;
	
	//set hidden variable to set Session["Admin"]
	document.getElementById("hdnCMValue").value = "1";
	document.Form1.submit();
	
	var publicPopUp = window.showModalDialog("PublicPagesHolder.htm","publicPagesPopup","center:yes;help:off;resizable:no;dialogHeight:600px;dialogWidth:1000px;");
	
	//set hidden variable to clear Session["Admin"]
	document.getElementById("hdnCMValue").value = "0";
	document.Form1.submit();
}

function validateXML()
{
	var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc.async="false";
	//root tag added as a valid XML requires a root
	var xmlDocWithRoot = "<xmlRootTag>" + document.getElementById("txtContent").value + "</xmlRootTag>";
	xmlDoc.loadXML(xmlDocWithRoot);
	

	if(xmlDoc.parseError.errorCode!=0)
	{
		txt="Start tag doesn't match with end tag. Please try again." + "\n";
		txt=txt+"Error Line: " + xmlDoc.parseError.line;
		fnThrowErrorBTVJavascript(txt);
		return false;
	}
	else
	{
		xmlDoc.Close;
		return true;
	}
}

//set value of hidden variable so that we can catch the saved status.
var hdnJavaScriptOnLoad = document.getElementById("hdnJavaScriptOnLoad");
if (hdnJavaScriptOnLoad != null)
{
	if (document.getElementById("hdnJavaScriptOnLoad").value!='')
	{
		fnShowSavedStatus(document.getElementById("hdnJavaScriptOnLoad").value);
		document.getElementById("hdnJavaScriptOnLoad").value = '';
	}
}
//show the saved status.
function fnShowSavedStatus(savedStatus)
{
	fnThrowErrorBTVJavascript(savedStatus);
}

function fnConfirmTrainingPackageDelete()
{
	if(confirm('Are you sure?'))
	{
		document.getElementById("hdnTrainingPackageValue").value = "1";
		document.Form1.submit();
	}
}

//set value of hidden variable so that we can catch the saved status. this will be used for popup transaction page
var hdnDeleteUpdateStatus = document.getElementById("hdnDeleteUpdateStatus");
if (hdnDeleteUpdateStatus != null)
{
	if (document.getElementById("hdnDeleteUpdateStatus").value!='')
	{
		fnShowSavedStatusForPopup(document.getElementById("hdnDeleteUpdateStatus").value);
		document.getElementById("hdnDeleteUpdateStatus").value = '';
	}
}

//show the saved status and close the popup
function fnShowSavedStatusForPopup(savedStatus)
{
	fnThrowErrorBTVJavascript(savedStatus);
}


function fnDisableF5() 
{
	// keycode for F5 function
	if (window.event && window.event.keyCode == 116) 
	{
		window.event.returnValue = false;
		window.event.keyCode = 0 ;		
	}
} 

function fnConfirmClsCatDelete(clsOrCat)
{
	if (confirm('Do you really want to delete the ' + clsOrCat + '?'))
		return true;
	else
		return false;
}

//shows the area to add a new classification in update activities page.
function fnShowAddClassificationArea()
{
	document.getElementById("trNewClassification").style.display = 'block';
	document.getElementById("trNewClassificationAdd").style.display = 'block';
	document.getElementById("trNewClassificationBlank").style.display = 'block';
}

//shows the area to add a new material category in update material page.
function fnShowAddMaterialCategoryArea()
{
	document.getElementById("trNewCategory").style.display = 'block';
	document.getElementById("trNewCategoryBlank").style.display = 'block';
	document.getElementById("trNewCategoryAdd").style.display = 'block';
	document.getElementById("trNewCategoryName").style.display = 'block';
	document.getElementById("trNewCategoryNameBlank").style.display = 'block';
}

//allows to browse new image in Update Materials page.
function fnChangeImage()
{
	document.getElementById("trOldImage").style.display = 'none';
	document.getElementById("trNewImage").style.display = 'block';
	document.getElementById("hdnImage").value = 'NewImage';
}
//allows to keep the old image in Update Materials page.
function fnDontChangeImage()
{
	document.getElementById("trOldImage").style.display = 'block';
	document.getElementById("trNewImage").style.display = 'none';
	document.getElementById("hdnImage").value = 'OldImage';
}

/////////////////////////////////////
function checkSpecial(strUsername)
{
	
	var iChars = "!#$%^&amp;*()+=-[]\\\';,/{}|\":&lt;&gt;?";
	for (var i = 0; i < strUsername.length; i++) 
	{
		if (iChars.indexOf(strUsername.charAt(i)) != -1)
		{
  			fnThrowErrorBTVJavascript("Invalid username or password.");
  			return false;
  		}	
  		else
  		{
  			return true;
  		}
  	}

}

function fnBtnGoOnClick()
{
	var varClub = document.getElementById('ddlClub').value;
	var varRole = document.getElementById('ddlRole').value;
	if(varClub == "")
	{
		fnThrowErrorBTVJavascript('Please select a club.');
		return false;
	}
	if(varRole == "")
	{
		fnThrowErrorBTVJavascript('Please select a role.');
		return false;
	}
	return true;
}
function ComparePassword()
{
	var OldPassword = document.getElementById('OldPassword').value;
	var NewPassword = document.getElementById('NewPassword').value;
	var ConfirmPassword = document.getElementById('ConfirmPassword').value;
	if(OldPassword == "")
	{
		fnThrowErrorBTVJavascript('Please enter Old Password.');
		document.getElementById('OldPassword').focus();
		return false;
	}
	if(NewPassword== "")
	{
		fnThrowErrorBTVJavascript('Please enter New Password.');
		document.getElementById('NewPassword').focus();
		return false;
	}
	if(ConfirmPassword == "")
	{
		fnThrowErrorBTVJavascript('Please enter Confirm Password.');
		document.getElementById('ConfirmPassword').focus();
		return false;
	}
	
	if(NewPassword != ConfirmPassword)
	{
		
			fnThrowErrorBTVJavascript('New Password and Confirm Password should same.');
			document.getElementById('ConfirmPassword').value = "";
			document.getElementById('ConfirmPassword').focus();
			return false;
			
	}
	return true;
}
function setfocus(strField)
{
    	document.getElementById(strField).focus();
    	
}


var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);

function addOption(theSel, theText, theValue)
{
	var newOpt = new Option(theText, theValue);
	var selLength = theSel.length;
	theSel.options[selLength] = newOpt;
}

function deleteOption(theSel, theIndex)
{ 
	var selLength = theSel.length;
	if(selLength>0)
	{
	theSel.options[theIndex] = null;
	}
}

function moveOptions(theSelFrom, theSelTo)
{
	
	var selLength = theSelFrom.length;
	var selectedText = new Array();
	var selectedValues = new Array();
	var selectedCount = 0;
	
	var i;
	
	// Find the selected Options  inreverse order
	// and delete them from the 'from' Select.
	for(i=selLength-1; i>=0; i--)
	{
		if(theSelFrom.options[i].selected)
		{
		selectedText[selectedCount] = theSelFrom.options[i].text;
		selectedValues[selectedCount] = theSelFrom.options[i].value;
		deleteOption(theSelFrom, i);
		selectedCount++;									 
		}
		
	}
	if(1*selectedCount == 0 && (1*selLength) != 0)
	{
			fnThrowErrorBTVJavascript('No item selected.');
	}
	
	// Add the selected text/values in reverse order.
	// This will add the Options to the 'to' Select
	// in the same order as they were in the 'from' Select.
	for(i=selectedCount-1; i>=0; i--)
	{
	addOption(theSelTo, selectedText[i], selectedValues[i]);
	
	}
	
	if(NS4) history.go(0);
}


//set the hidden value when update button in Amend Records is clicked, so that we can catch the selected partners
//var hdnSelectedPartner = document.getElementById("hdnSelectedPartner");

function fnGetSelectedPartners(lstPartner, lstSelectedPartner)
{
	var lstLeftControl = document.getElementById(lstPartner);
	var lstRightControl = document.getElementById(lstSelectedPartner);
	var hdnRight = document.getElementById("hdnRight");
	var hdnLeft = document.getElementById("hdnLeft");
	hdnRight.value = '';
	hdnLeft.value = '';
	for (var i = 0; i< lstLeftControl.length; i++)
	{
		if (hdnLeft.value != '')
			hdnLeft.value += '~'
			
		hdnLeft.value += lstLeftControl.options[i].value;
	}
	
	for (var i = 0; i< lstRightControl.length; i++)
	{
		if (hdnRight.value != '')
			hdnRight.value += '~'
			
		hdnRight.value += lstRightControl.options[i].value;
	}
}



function fntoggleReturnDateVisibility()
{
	if(document.getElementById("chkReturnVisit").checked == true)
	{
		document.getElementById("txtReturnDate").disabled = false;
	}
	else
	{
		document.getElementById("txtReturnDate").disabled = true;
		document.getElementById("txtReturnDate").value = '';
	}
	
}

function fnConfirmFailedCRB(controlName)
{
	if(document.getElementById(controlName).checked == true)
	{
		if (!confirm('Are you sure that the Volunteer has failed CRB Check?'))
        {
			document.getElementById(controlName).checked = false;
        }
	}
}

function fnThrowErrorBTVJavascript(errorMessage)
{
	try
	{
		var errorLabel = document.getElementById("lblErrorOnPage");
		errorLabel.innerText = errorMessage;
		errorLabel.style.display = "";
	}
	catch(e)
	{
        document.write(e.message + "<br/>")
	}
	finally
	{
            //document.write("This is the finally message.")
	}
}