// overwrite the default JS round() function.
// Default Math.round() only rounds up to the whole number
function round(number,X) { // rounds number to X decimal places, defaults to 2
	X = (!X ? 2 : X);
	return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

/* Usage
	<input type=text name=test length=15 onKeyPress="return(currencyFormat(this,',','.',event))">
*/
function currencyFormat(fld, milSep, decSep, e) {
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	
	if (whichCode == 13) return true;  // Enter
	key = String.fromCharCode(whichCode);  // Get key value from key code
	
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	len = fld.value.length;
	
	for(i = 0; i < len; i++)
		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
	
	aux = '';
	
	for(; i < len; i++)
		if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
	
	aux += key;
	len = aux.length;
	if (len == 0) fld.value = '';
	if (len == 1) fld.value = '0'+ decSep + '0' + aux;
	if (len == 2) fld.value = '0'+ decSep + aux;
	if (len > 2) {
		aux2 = '';
		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += milSep;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
	
		fld.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
		fld.value += aux2.charAt(i);
		fld.value += decSep + aux.substr(len - 2, len);
	}
	return false;
}

 /*******
  * Copyright (C) BPSUSA.COM
  * INPUTS: any Text field
  * This function trims all white spaces in the text field!
  */
function TrimAll(strField){
	while(''+strField.value.charAt(strField.value.length-1)==' ')
		strField.value=strField.value.substring(0,strField.value.length-1); 
	while(''+strField.value.charAt(0)==' ')
		strField.value=strField.value.substring(1,strField.value.length);
}

/* used for Social Security Verification */
function checkSSN(strField){
	if (isNaN(strField.value) || (strField.value.length != 9) && (strField.value.length > 0)) {
		alert("Employee SSN must be a nine digit number...");
		document.forms[0].NewEmpSSN.focus();
	}
	else {
		//alert ("Number is valid");
	}
}

/* used for Social Security Verification */
/* USAGE:
   onBlur="TrimAll(this); checkSSN(this);" onKeypress="CheckIfNumber(event, this);"
   */
function CheckIfNumber(event, fld){
	if (event.keyCode > 57 || event.keyCode < 48) {
		event.returnValue = false;
	}
	else { 
		if (fld.value.length > 8) {
			fld.value = fld.value.substring(0, 8);
		}
	}
}

function SelectThisTab(TabCount) {

	var maxTabs=4;

	eval("document.all.Td_0"+TabCount+".className='KioskTabPaddingOn'"); 
	eval("document.all.Tab_0"+TabCount+".className='KioskTabsOn'"); 
	eval("document.all.Text_0"+TabCount+".className='KioskTextOn'");
	eval("document.all.Kiosk_0"+TabCount+".style.visibility='visible'");
	
	for(i=1; i<=maxTabs; i++){
		if (i != TabCount) {
			eval("document.all.Td_0"+i+".className='KioskTabPaddingOff'"); 
			eval("document.all.Tab_0"+i+".className='KioskTabsOff'"); 
			eval("document.all.Text_0"+i+".className='KioskTextOff'");
			eval("document.all.Kiosk_0"+i+".style.visibility='hidden'");
		}
	}
}
function HoverCell(ElementID) {
	eval("document.all."+ElementID+".className='TDHeader1 HandCursor'");	
}
function RollBackCell(ElementID) {
	eval("document.all."+ElementID+".className='TDHeader'");	
}

function HoverThisElement(ElementID) {
	eval("document.all."+ElementID+".style.color='#113366'");
	eval("document.all."+ElementID+".style.background='#C6C6C6'");
	eval("document.all."+ElementID+".className='SearchFieldHeader GrayText bordered_1px HandCursor'");	
}
function RollBackThisElement(ElementID) {
	eval("document.all."+ElementID+".style.color=''");
	eval("document.all."+ElementID+".style.background='#D6D6D6'");
	eval("document.all."+ElementID+".className='SearchFieldHeader GrayText bordered_1px'");	
}

function HoverThisTab(TabCount) {
	if (eval("document.all.Td_0"+TabCount+".className=='KioskTabPaddingOff'")) {
		eval("document.all.Text_0"+TabCount+".style.color='#777777'");
	}
}

function RollBackThisTab(TabCount) {
	eval("document.all.Text_0"+TabCount+".style.color=''");
}
	
function ShowHide(){
	document.all.SearchDetails.style.display= document.all.SearchDetails.style.display=='none' ? 'block' : 'none';
	document.all.ShowHideLink.innerHTML= document.all.ShowHideLink.innerHTML.indexOf("Show")== -1 ? 'Show<img border=0 vspace=0 hspace=2 src=Images/ErrowDown.gif>' : 'Hide<img border=0 vspace=2 hspace=6 src=Images/ErrowUp.gif>';
}
function ShowHideDetails(DivID){
	var TargetDisplay = "document.all."+DivID+".style.display";
	eval(TargetDisplay +"="+ TargetDisplay +"=='none' ? 'block' : 'none'");
}
function ChangeOverflow(DivID){
	var TargetDisplay = eval(DivID+".style.overflow");
	if (TargetDisplay == "auto") eval(DivID+".style.overflow = 'visible'");
	else eval(DivID+".style.overflow = 'auto'");
}

/* Random Password functions */
function getRandomNum(lbound, ubound) {
	return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}
/* Random Password functions */
function getRandomChar(number, lower, upper, other, extra) {
	var numberChars = "0123456789";
	var lowerChars = "abcdefghijklmnopqrstuvwxyz";
	var upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var otherChars = "`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/? ";
	var charSet = extra;
	if (number == true) charSet += numberChars;
	if (lower == true)  charSet += lowerChars;
	if (upper == true)  charSet += upperChars;
	if (other == true)  charSet += otherChars;
	return charSet.charAt(getRandomNum(0, charSet.length));
}
/* Random Password functions */
function getFirstChar(strWord) {
	return strWord.charAt(0);
}
/* Random Password functions */
/* This one was the original function used in HTML code */
function getPassword(length, extraChars, firstNumber, firstLower, firstUpper, firstOther,latterNumber, latterLower, latterUpper, latterOther) {
	var rc = "";
	if (length > 0)	rc = rc + getRandomChar(firstNumber, firstLower, firstUpper, firstOther, extraChars);
	for (var idx = 1; idx < length; ++idx) {
		rc = rc + getRandomChar(latterNumber, latterLower, latterUpper, latterOther, extraChars);
	}
	return rc;
}
/* This is a modified version of the above to reflect the changes in the password rules. */
function makePassword(Fname, Lname, length, extraChars, firstNumber, firstLower, firstUpper, firstOther,latterNumber, latterLower, latterUpper, latterOther) {
	var rc = "";
	if (length > 0)	rc = rc + getRandomChar(firstNumber, firstLower, firstUpper, firstOther, extraChars);
	for (var idx = 1; idx < length; ++idx) {
		rc = rc + getRandomChar(latterNumber, latterLower, latterUpper, latterOther, extraChars);
	}
	rc = getFirstChar(Fname) + getFirstChar(Lname) + rc; 
	rc = rc.toUpperCase();
	//alert("function makePassword: " + rc);
	document.all.RandomPassword.value = rc;
	return rc;
}

function PlusMinusClick(){
	document.all.RandPassOptions.style.visibility= document.all.RandPassOptions.style.visibility=='hidden' ? '' : 'hidden'; 
	document.all.PlusMinus.innerHTML= document.all.PlusMinus.innerHTML=='&nbsp;[-]' ? '&nbsp;[+]' : '&nbsp;[-]';
}

function voidClick() {
}

function pdfWindow(strURL){
	myWindow = window.open(strURL, "pdfWindow", 'resizable,scrollbars,toolbar,width=668,height=450');
	//myWindow.moveTo(0, 0);
	myWindow.focus();
}

function PetersEmergency(){
	myWindow = window.open("Include/EmergencyPeters.html", "Peters", 'resizable=0,scrollbars=0,toolbar=0,width=600,height=466');
	//myWindow.moveTo(0, 0);
	myWindow.focus();
}

function mapWindow1(strURL) {
	targetPage = strURL;
	//alert(targetPage);
	myWindow = window.open(targetPage, "MapWindow", 'resizable=0,scrollbars=0,status=1,toolbar=0,width=780,height=750');
	myWindow.moveTo(0, 0);
	myWindow.focus();
}

function mapWindow(url) {
	if (typeof(popupWin) != "object"){
		popupWin = window.open(url, "mapWindow", 'resizable,scrollbars,toolbar,width=795,height=750');
	} 
	else {
		if (!popupWin.closed){ 
			popupWin.location.href = url;
		} 
		else {
			popupWin = window.open(url, "mapWindow", 'resizable,scrollbars,toolbar,width=795,height=750');
		}
	}
	//popupWin.moveTo(0, 0); //apperantly it doesn't work due to security restrictions in Javascript (redirection to another website ???)
	popupWin.focus();
}

function AddNewFormVerify() {
	objForm = eval("document.forms[0]");
	if (objForm.NewFirstName.value == "") { 
		alert ("First name is required!");
		objForm.NewFirstName.focus();
	}
	else if (objForm.NewLastName.value == "") { 
		alert ("Last name is required!");
		objForm.NewLastName.focus();
	}
	else if (objForm.NewEmail.value == "") { 
		alert ("E-mail address is required for most of the Intranet tools!");
		objForm.NewEmail.focus();
	}
	else { objForm.submit(); }
}

function AutoModifyForm(obj) {
	if (document.forms[0].AutoModify.checked) document.forms[0].submit();
}

// This function is used in
// AdminPhoneBook_AddNew.asp and
// AdminPhoneBook_Modify.asp
// Default e-mail format: FirstName.LastName@bpsusa.com
function BuildDefaultEmail() {
	if ((document.all.NewFirstName.value != "") &&  (document.all.NewLastName.value != "")) {
		document.all.NewEmail.value = document.all.NewFirstName.value + "." + document.all.NewLastName.value + "@bpsusa.com"
	}
}

function VerifySecurityForm() {
	objForm = document.forms[0];
	TrimAll(objForm.NewUserID);
	if ( objForm.NewUserID.value == "" ) { 
		alert ("Login ID cannot be blank!"); 
		objForm.NewUserID.focus();
	}
	else if (objForm.NewUserPass.value != objForm.NewUserPass2.value) {
		alert ("New passwords do not match!");
		objForm.NewUserPass.value = "";
		objForm.NewUserPass2.value = "";
		objForm.NewUserPass.focus();
	}
	else {
		//alert ("LoginID: -<"+objForm.NewUserID.value+">-  Passwords match!");
		objForm.submit();
	}
}

// This function if used on the body onLoad() in the
// AdminPhoneBook_List.asp and AdminPhoneBook_AddNew.asp
// This is used to prevent a user from viewing certain pages alone.
// They should be viewed in the context of AdminPhoneBook.asp
function ReloadPhoneBook(){
  if (top.location == location) {
    top.location.href = "AdminPhoneBook.asp" ;
  }
}
function ReloadSchedule(){
  if (top.location == location) {
    top.location.href = "Schedule.asp" ;
  }
}
function ReloadAdminMenu(){
  if (top.location == location) {
    top.location.href = "AdminMenuButtons.asp" ;
  }
}

// Useful code.
// Can be used for prompting input from the user
// BTW Escape function is used to encode charaters for TCP, i.e. space = %20
function AddFolder()
{
	var nn = window.prompt("Please enter a name for your folder.","");
	var nn_len = nn.length;
	var nn_escaped = "";
	if (nn != null && nn != "null" && nn != "")
	{
		for (i = 0 ; i < nn_len ; i++) 
		{
			var nn_asc = nn.charCodeAt(i);
			if (nn_asc > 128) 
			{
				nn_escaped += nn.charAt(i);
			}
			else
			{
				nn_escaped += escape(nn.charAt(i));
			}
		}
		var str = "/ym/Folders?ADD=1&Name=" + nn_escaped + "&.crumb=/ttLeFDbekx&.done=" + escape(document.URL) + "&YY=77381";
		window.open(str, "_top");
	}
}

/********
 * This function Enables and Disables all form elements.
 * If button named Toggler is used, then the last line
 * must be uncommented, to make the button ALWAYS
 * enabled, so that all elements can be enabled again.
 * Otherwise, use <a> tag to call this function.
 * So far, only AdminMenuButtons_Modify.asp is using it.
 */
function EnableDisableForm() {
	MyForm = document.forms[0];
	FormLength = MyForm.elements.length;
	//alert (FormLength);
	var i=0;
	for ( i=0; i<FormLength; i++) {
		MyForm.elements[i].disabled = MyForm.elements[i].disabled == 1 ? 0 : 1;
	}
	MyForm.Toggler.disabled=0;
}

function DisableForm() {
	MyForm = document.forms[0];
	FormLength = MyForm.elements.length;
	for ( i=0; i<FormLength; i++) {
		MyForm.elements[i].disabled = 1;
	}
}

function EnableForm() {
	MyForm = document.forms[0];
	FormLength = MyForm.elements.length;
	for ( i=0; i<FormLength; i++) {
		MyForm.elements[i].disabled = 0;
	}
}

function ToggleFormElementVisibility (FormName, ElementName) {
	FormElement = eval(FormName + "." + ElementName);
	FormElement.style.visibility = FormElement.style.visibility=='visible' ? 'hidden' : 'visible';
}

// The following few functions are For use with several BPSSupport pages

function DeleteProjectTask(ProjTaskID) {
	//alert (ProjTaskID);
	if (confirm("Are you sure you want to Delete this TASK?")) {
		document.forms[0].hiddenCommand.value = "DeleteTask";
		document.forms[0].hiddenTaskID.value = ProjTaskID;
		document.forms[0].submit();
	}
}
function EditProjectTask(ProjTaskID,CLID,strGoTo)  {
	window.location = "ManageClients_EditProjectTask.asp?ProjTaskID=" + ProjTaskID + "&CLID=" + CLID + "&strGoTo=" + strGoTo;
}


function OpenPSWWindow(strGoTo) {
	targetPage = strGoTo;
	myWindow = window.open(targetPage, "NewBrowserWindow", 'resizable=1,scrollbars=1,status=1,toolbar=1,width=770,height=750');
	myWindow.moveTo(0, 0);
	myWindow.focus();
}
function AddNewClient() {
	targetPage = "ManageClients_AddNewClient.asp";
	myWindow = window.open(targetPage, "AddNewClient", 'resizable=0,scrollbars=0,status=1,toolbar=0,width=580,height=571');
	myWindow.moveTo(0, 0);
	myWindow.focus();
}
function AddNewContact(CLID,strGoTo) {
	targetPage = "ManageClients_AddNewContact.asp?CLID="+CLID+"&strGoTo="+strGoTo;
	myWindow = window.open(targetPage, "AddNewContact", 'resizable=0,scrollbars=0,status=1,toolbar=0,width=500,height=254');
	myWindow.moveTo(0, 0);
	myWindow.focus();
}
function AddNewLocation(CLID,strGoTo) {
	targetPage = "ManageClients_AddNewLocation.asp?CLID="+CLID+"&strGoTo="+strGoTo;
	myWindow = window.open(targetPage, "AddNewLocation", 'resizable=0,scrollbars=0,status=1,toolbar=0,width=500,height=239');
	myWindow.moveTo(0, 0);
	myWindow.focus();
}
function AddNewItem(CLID,strGoTo) {
	targetPage = "ManageClients_AddNewItem.asp?CLID="+CLID+"&strGoTo="+strGoTo;
	myWindow = window.open(targetPage, "AddNewItem", 'resizable=0,scrollbars=0,status=1,toolbar=0,width=500,height=252');
	myWindow.moveTo(0, 0);
	myWindow.focus();
}
function AddNewSoftwareItem(CLID,strGoTo) {
	targetPage = "ManageClients_AddNewSoftwareItem.asp?CLID="+CLID+"&strGoTo="+strGoTo;
	myWindow = window.open(targetPage, "AddNewSoftwareItem", 'resizable=0,scrollbars=0,status=1,toolbar=0,width=500,height=211');
	myWindow.moveTo(0, 0);
	myWindow.focus();
}
function AddNewProjectItem(CLID,strGoTo) {
	targetPage = "ManageClients_AddNewProject.asp?CLID="+CLID+"&strGoTo="+strGoTo;
	myWindow = window.open(targetPage, "AddNewProject", 'resizable=1,scrollbars=1,status=1,toolbar=0,width=770,height=750');
	myWindow.moveTo(0, 0);
	myWindow.focus();
}
function EditContact(ContactID,CLID,strGoTo) {
	targetPage = "ManageClients_EditContact.asp?ContactID="+ContactID+"&CLID="+CLID+"&strGoTo="+strGoTo;
	myWindow = window.open(targetPage, "EditContact", 'resizable=0,scrollbars=0,status=1,toolbar=0,width=500,height=254');
	myWindow.moveTo(0, 0);
	myWindow.focus();
}
function EditItem(ItemID,CLID,strGoTo) {
	targetPage = "ManageClients_EditItem.asp?ItemID="+ItemID+"&CLID="+CLID+"&strGoTo="+strGoTo;
	myWindow = window.open(targetPage, "EditItem", 'resizable=0,scrollbars=0,status=1,toolbar=0,width=500,height=252');
	myWindow.moveTo(0, 0);
	myWindow.focus();
}
function EditSoftwareItem(ItemID,CLID,strGoTo) {
	targetPage = "ManageClients_EditSoftwareItem.asp?ItemID="+ItemID+"&CLID="+CLID+"&strGoTo="+strGoTo;
	myWindow = window.open(targetPage, "EditSoftwareItem", 'resizable=0,scrollbars=0,status=1,toolbar=0,width=500,height=211');
	myWindow.moveTo(0, 0);
	myWindow.focus();
}
function EditProject(ProjID,CLID,strGoTo) {
	targetPage = "ManageClients_EditProject.asp?ProjID="+ProjID+"&CLID="+CLID+"&strGoTo="+strGoTo;
	myWindow = window.open(targetPage, "EditProject", 'resizable=1,scrollbars=1,status=1,toolbar=0,width=770,height=750');
	myWindow.moveTo(0, 0);
	myWindow.focus();
}
function EditClientID(CLID,strGoTo) {
	targetPage = "ManageClients_EditClientID.asp?CLID="+CLID+"&strGoTo="+strGoTo;
	myWindow = window.open(targetPage, "EditClientID", 'resizable=0,scrollbars=0,status=1,toolbar=0,width=500,height=184');
	myWindow.moveTo(0, 0);
	myWindow.focus();
}
function EditLocation(LocationID,CLID,strGoTo) {
	targetPage = "ManageClients_EditLocation.asp?LocationID="+LocationID+"&CLID="+CLID+"&strGoTo="+strGoTo;
	myWindow = window.open(targetPage, "EditLocation", 'resizable=0,scrollbars=0,status=1,toolbar=0,width=500,height=239');
	myWindow.moveTo(0, 0);
	myWindow.focus();
}
function OpenSensitiveData(CLID) {
	targetPage = "ManageClients_SensitiveData.asp?CLID=" + CLID ;
	myWindow = window.open(targetPage, "SensitiveData", 'resizable=0,scrollbars=0,status=1,toolbar=0,width=500,height=285');
	myWindow.moveTo(0, 0);
	myWindow.focus();
}
function OpenInternalNotes(IncidentID) {
	//alert(IncidentID);
	targetPage = "Support_InternalNotes.asp?IncidentID=" + IncidentID ;
	myWindow = window.open(targetPage, "InternalNotes", 'resizable=0,scrollbars=0,status=1,toolbar=0,width=500,height=285');
	myWindow.moveTo(0, 0);
	myWindow.focus();
}
function OpenChangePasswordWindow() {
	myWindow = window.open("ChangePassword.asp", "ChangePassword", 'resizable=0,scrollbars=0,status=0,toolbar=0,width=500,height=246');
	MoveToX = ((screen.availWidth - 500) / 2);
	MoveToY = ((screen.availHeight - 246) / 2);
	myWindow.moveTo(MoveToX, MoveToY);
	myWindow.focus();
}
function OpenChangePasswordDialog() {
	myWindow = window.showModelessDialog("ChangePassword.asp", "ChangePassword", "help:0;resizable:0;status:0;scrollbars:0;dialogWidth:506px;dialogHeight:271px");
	MoveToX = ((screen.availWidth - 500) / 2);
	MoveToY = ((screen.availHeight - 246) / 2);
	myWindow.moveTo(MoveToX, MoveToY);
	myWindow.focus();
}
function CenterWindow() { /* doesn't work right. */
alert ("\
Available Height   : " + screen.availHeight + " \n\
Available Width    : " + screen.availWidth  + " \n\
Window OuterHeight : " + top.window.outerHeight + " \n\
Window OuterWidth  : " + window.outerwidth );
}

function OpenHardwareHelpWindow() {
	myWindow = window.open("HardwareLegend.asp", "HardwareLegend", 'resizable=0,scrollbars=0,status=0,toolbar=0,width=280,height=480');
	myWindow.moveTo(0, 0);
	myWindow.focus();
}
function OpenCrystalHelpWindow() {
	myWindow = window.open("CrystalSupportInfo.asp", "CrystalInfo", 'resizable=1,scrollbars=1,status=1,toolbar=1,width=600,height=450');
	myWindow.moveTo(0, 0);
	myWindow.focus();
}

function ToggleIncidentView() {
	Ef = document.all.Effect.className;
	PlMn = document.all.PlusMinus.innerHTML;
	document.all.Effect.className = Ef == 'NoEffect' ? 'TextAreaEffect' : 'NoEffect';
	document.all.PlusMinus.innerHTML = PlMn == '+' ? '-' : '+';
}

// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
function autoComplete (field, select, property, forcematch) {
var found = false;
for (var i = 0; i < select.options.length; i++) {
if (select.options[i][property].toUpperCase().indexOf(field.value.toUpperCase()) == 0) {
	found=true; break;
	}
}
if (found) { select.selectedIndex = i; }
else { select.selectedIndex = -1; }
if (field.createTextRange) {
	if (forcematch && !found) {
		field.value=field.value.substring(0,field.value.length-1); 
		return;
		}
	var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";
	if (cursorKeys.indexOf(event.keyCode+";") == -1) {
		var r1 = field.createTextRange();
		var oldValue = r1.text;
		var newValue = found ? select.options[i][property] : oldValue;
		if (newValue != field.value) {
			field.value = newValue;
			var rNew = field.createTextRange();
			rNew.moveStart('character', oldValue.length) ;
			rNew.select();
			}
		}
	}
}


		
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- V1.1.3: Sandeep V. Tamhankar (stamhankar@hotmail.com) -->
<!-- Original:  Sandeep V. Tamhankar (stamhankar@hotmail.com) -->

function emailCheck (emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|us|ws)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("This Email username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("This Email domain name contains invalid characters.");
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

alert("The Email username doesn't seem to be valid.");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Email: Destination IP address is invalid!");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The Email domain name does not seem to be valid.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The Email address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
alert("This Email address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}
// End function


// Format a SSN number - 999-99-9999
function formatSSN(theField){ 
     var oLen = theField.value.length; //Field length
    if(oLen == 3 || oLen == 6){ //When the field reaches the 3rd and 6th character
         theField.value += "-" //We add - 123-45-6789
         }
    }
// Format a Zip code - 12345-6789
function formatZIP(theField){
    var oLen = theField.value.length; //Field length
    if(oLen == 5){ //When the length reaches 5 character
         theField.value += "-" //We will add the - and finish the field 12345-6780
         }
    }
// Format a Date 03/03/03
function formatDate(theField){ 
     var oLen = theField.value.length; //Field length
    if(oLen == 2 || oLen == 5){ //When the field reaches the 2nd and 5th character
         theField.value += "/" //We add / - 03/03/03
         }
    }
// Format a Phone or Fax number - (999) 999-9999
// If you do not want to have a space after the ) then take 
//out the space in the function below
function formatPhoneFax(theField){
    var oLen = theField.value.length; //Field length
    if(oLen == 0){ //First character
         theField.value += "("; //Lets add the first (
         }
    if(oLen == 4){ //When the length is 4
         theField.value += ") ";  //We add ) plus a space
         }
    if(oLen == 9){ //When the length is 9
         theField.value += "-"; //We add the - and finish the field (123) 456-7890
         }
}
function CheckIfNumberValue(event, fld){
	if (event.keyCode > 57 || event.keyCode < 48) { event.returnValue = false; }
}
function ASCIITester(event, fld){
	if (fld.name == 'ASCII_test') {	alert (event.keyCode); }
}

function IE55Check(){
	agt = navigator.userAgent.toLowerCase();
	appVer = navigator.appVersion.toLowerCase();
	is_minor = parseFloat(appVer);
	is_major = parseInt(is_minor);
	iePos  = appVer.indexOf('msie');
    if (iePos !=-1) {
       is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
       is_major = parseInt(is_minor);
    }
	is_ie		= (iePos!=-1);
	is_ie5_5up	= (is_ie && is_minor >= 5.5); 
	return (is_ie5_5up);
}





/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}
function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}


