function BrowserDetect()
{
	if (navigator.userAgent.indexOf("MSIE") != -1)
	{
		return 'MSIE';
	}
	else if (navigator.userAgent.indexOf("Firefox") != -1)
	{
		return 'Firefox';
	}
	else if (navigator.userAgent.indexOf("Opera") != -1)
	{
		return 'Opera';
	}
	else if (navigator.userAgent.indexOf("Netscape") != -1)
	{
		return 'Netscape';
	}
	else
	{
		return 'MSIE';
	}
}

function SetFocus(ctrl)
// Sets focus to the control passed in (ctrl)
{
	document.getElementById(ctrl).focus();
	return false;
}


function SubmitOnEnter(btn)
// Fires the Click() event of the Button passed in (btn).  This is intended to be attached 
// to the Login.aspx page so that users can press 'Enter' to Log-In 
// Tested only on IE and Firefox browsers
// - 12/18/2007 - Changed the Login control on Login.aspx to a button
{

	if (event.which || event.keyCode)
	{
		if ((event.which == 13) || (event.keyCode == 13))
		{	
			document.getElementById(btn).click();
			return false;
		}
	}
	else
	{
		return true;
	}
	
}


function TextAreaMaxLength(inputControl, maxLength, counterControl)
// Verifies that the TEXTAREA field does not allow input beyond the 
// specifed max number of characters (in param list).  MaxLength property
// of the ASP Control does not apply to TEXTAREAS.
{
	if (document.getElementById(inputControl).value.length > maxLength)
	{	
		// Don't allow input of any characters over maxLength
		document.getElementById(inputControl).value = document.getElementById(inputControl).value.substring(0, maxLength);
	}
	else
	{
		// Update field counter with how many characters remaining
		document.getElementById(counterControl).innerHTML = maxLength - document.getElementById(inputControl).value.length;

	}
}


function SetTextAreaRemainingChars(maxLength, counterControl, usedchars)
{
	document.getElementById(counterControl).innerHTML = maxLength - usedchars
}


function setFileName(fileName)
{
	document.all.hdnFileName.value = fileName;
}

function setFileStatus(action)
{

	switch (action)
	{
		case 'AddFile':
		{
			document.all.addFile.style.display =  'block';
			document.all.changeFile.style.display =  'none';
			
			document.all.hdnFileStatus.value = "AddFile";
			break;
		}
		case 'FileExists':
		{
			document.all.addFile.style.display =  'none';
			document.all.changeFile.style.display =  'block';
			
			document.all.hdnFileStatus.value = "FileExists";
			break;
		}
		case 'ChangeFile':
		{
			document.all.addFile.style.display =  'block';
			document.all.changeFile.style.display =  'none';
			
			document.all.hdnFileStatus.value = "ChangeFile";
			break;
		}
		default:
		{
			document.all.hdnFileStatus.value = "FileExists";
		}
	}	
}

function ShowCompanyMeetingFreq()
{
	if (document.all.rdoScheduledMeetings_0.selected == true)
	{
				return true
	}
	else if (document.all.rdoScheduledMeetings_1.selected == true)
	{
		
		return true
	}
	
}


function checkAgree()
// Checks if the chkAgree checkbox on the CEOLetter.aspx page is checked.  We cannot
// allow the user to move on until it is.
{
	if (document.all.chkAgree.checked == false)
	{
		alert("If you have read, understand and agree to abide by the information on this page, please check the checkbox."); 
		
		return false
	}
	
	return true
}

function setFileNameJudgement(fileName)
{
	document.all.hdnFileNameJudgement.value = fileName;
}

function setFileStatusJudgement(action)
{
	switch (action)
	{
		case 'AddFile':
		{
			document.all.addFileJudgement.style.display =  'block';
			document.all.changeFileJudgement.style.display =  'none';
			
			document.all.hdnFileStatusJudgement.value = "AddFile";
			break;
		}
		case 'FileExists':
		{
			document.all.addFileJudgement.style.display =  'none';
			document.all.changeFileJudgement.style.display =  'block';
			
			document.all.hdnFileStatusJudgement.value = "FileExists";
			break;
		}
		case 'ChangeFile':
		{
			document.all.addFileJudgement.style.display =  'block';
			document.all.changeFileJudgement.style.display =  'none';
			
			document.all.hdnFileStatusJudgement.value = "ChangeFile";
			break;
		}
		default:
		{
			document.all.hdnFileStatusJudgement.value = "FileExists";
		}
	}	
	
}

function setFileNameBankruptcy(fileName)
{
	document.all.hdnFileNameBankruptcy.value = fileName;
}

function setFileStatusBankruptcy(action)
{
	switch (action)
	{
		case 'AddFile':
		{
			document.all.addFileBankruptcy.style.display =  'block';
			document.all.changeFileBankruptcy.style.display =  'none';
			
			document.all.hdnFileStatusBankruptcy.value = "AddFile";
			break;
		}
		case 'FileExists':
		{
			document.all.addFileBankruptcy.style.display =  'none';
			document.all.changeFileBankruptcy.style.display =  'block';
			
			document.all.hdnFileStatusBankruptcy.value = "FileExists";
			break;
		}
		case 'ChangeFile':
		{
			document.all.addFileBankruptcy.style.display =  'block';
			document.all.changeFileBankruptcy.style.display =  'none';
			
			document.all.hdnFileStatusBankruptcy.value = "ChangeFile";
			break;
		}
		default:
		{
			document.all.hdnFileStatusBankruptcy.value = "FileExists";
		}
	}	
}

function NoBadInput3()
// Used for Change password page
{
	if (IsBadChars(document.all.txtNewPassword.value))
	{
		alert("Your new password contains invalid characters.");
		return false;
	}
	else if (IsBadChars(document.all.txtReEnterNewPassword.value))
	{
		alert("Your new password contains invalid characters.");
		return false;
	}
	
	return true;
}

function NoBadInput2()
// Used for Login page
{
	if (IsBadChars(document.all.txtLoginID.value))
	{
		alert("One or more fields contain invalid characters.");
		return false;
	}
	else if (IsBadChars(document.all.txtPassword.value))
	{
		alert("One or more fields contain invalid characters.");
		return false;
	}
	
	return true;
}


function NoBadInput()
// Used for Contact Us page
{
	// Look for malicious characters on input fields	
	if (IsBadChars(document.all.txtName.value))
	{
		alert("One or more fields contain invalid characters.");
		return false;
	}
	else if (IsBadChars(document.all.txtEmail.value))
	{
		alert("One or more fields contain invalid characters.");
		return false;
	}
	else if (IsBadChars(document.all.txtTelephone.value))
	{
		alert("One or more fields contain invalid characters.");
		return false;
	}
	else if (IsBadChars(document.all.txtQuestion.value))
	{
		alert("One or more fields contain invalid characters.");
		return false;
	}
	else if (IsBadChars(document.all.txtCompany.value))
	{
		alert("One or more fields contain invalid characters.");
		return false;
	}
	
	// Validate a valid e-mail address
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	if (emailPattern.test(document.all.txtEmail.value) != true )
	{
		alert(document.all.txtEmail.value + " is an invalid e-mail address. Please re-enter your e-mail address.");
		return false;
	}
	 
	
	
	/*
	var email = document.all.txtEmail.value.toLowerCase();
	var first_at = email.indexOf("@")+1;
	
	if ((email.indexOf("@")<1) || (email.indexOf("@", first_at)!=-1) || (email.indexOf(" ")!=-1) || (email.length == first_at)) 
	{
       alert(document.all.txtEmail.value + " is an invalid e-mail address. Please re-enter your e-mail address.");
       return false;
	}
	*/
	
	
	return true;
}


function IsBadChars(value)
{
	/*
	var regex = new RegExp("http|ftp|mailto|href|script|htm|<|>|\/\/|\+", "gi");
	if (value.search(regex) != -1)
	{
		return true;
	}
	*/	

	if (value.search(/http/gi) != -1)
			return true;
	else if (value.search(/ftp/gi) != -1)
			return true;
	else if (value.search(/mailto/gi) != -1)
			return true;
	else if (value.search(/href/gi) != -1)
			return true;
	else if (value.search(/script/gi) != -1)
			return true;
	else if (value.search(/.html/gi) != -1)
			return true;
	else if (value.search(/</gi) != -1)
			return true;
	else if (value.search(/>/gi) != -1)
			return true;
	else if (value.search(/\\\\/gi) != -1)
			return true;
	else if (value.search(/\/\//gi) != -1)
			return true;
	else if (value.search(/\+/gi) != -1)
			return true;

}

