function DisplayWait(blnDontHideButtons)
{
	if (window.event.returnValue != false) {
		var iLeft = 370;
		var iTop = 570;
		var I;
		
		iLeft = (document.body.clientWidth - 341)/2;
		iTop = (document.body.clientHeight - 61)/2;
	
		//We don't manually Hide the buttons, since the Print
		// window does not cause a postback that would re-build the screen   
		if (blnDontHideButtons != true)
		{
			//This hides all the buttons on the form.
			for ( I = 0; I < document.forms[0].length; I++)
			{	
				if (document.forms[0].elements[I].tagName == "INPUT")
				{					
					if (document.forms[0].elements[I].type == "submit")
					{
						document.forms[0].elements[I].style.display ='none';					
					}
				}      
			}   
		}
		if (document.getElementById("msgPleaseWait") == null)
		{			
			var newDocumentField = document.createElement('<DIV id="msgPleaseWait" style="BORDER-RIGHT: black thin solid; BORDER-TOP: black thin solid;  LEFT: ' + iLeft.toString() + '; BORDER-LEFT: black thin solid; WIDTH: 341px; BORDER-BOTTOM: black thin solid; POSITION: absolute; TOP: ' + iTop.toString() + '; HEIGHT: 61px; BACKGROUND-COLOR: #87cefa" align="center"><BR><font color=black><b>Please wait processing...</b></font></DIV>');
			newDocumentField.innerHTML = "<font color='black'><b><br>Processing please wait...</b></font>";			
			document.forms[0].insertBefore(newDocumentField);	
		}
		else
		{
			document.getElementById("msgPleaseWait").style.display = '';
		}
	}
}

function isNumeric(formField, fieldName) 
{ 
	var formFieldValue = formField.value; 
	var valueMatch = formFieldValue.match(/\D/); 
	if (valueMatch != null) 
	{
		alert(fieldName + " must be a numeric value.");
		formField.focus(); 
		formField.select(); 
		return false; 
	}         
} 

function isNumericOrDecimal(formField, fieldName) 
{ 
	var formFieldValue = formField.value; 
	var valueMatch = formFieldValue.match(/\D\./); 
	if (valueMatch != null) 
	{
		alert(fieldName + " must be a numeric value.");
		formField.focus(); 
		formField.select(); 
		return false; 
	}         
} 

function validMoney(formField)
{
	var formFieldValue = formField.value;
	var fieldStatus = "passed";
	
    //Remove leading zeros
    if (formFieldValue != "0")
		{formFieldValue = formFieldValue.replace(/^0+/, "");
			}		

	//Replace spaces with nothing
	formFieldValue = formFieldValue.replace(/\s+/g, "");
	
	if (formFieldValue.match(/[^0-9.]/))
		{alert(formFieldValue + " is not a valid dollar amount.");
			fieldStatus = "failed";
				}
		else
			{
			//Starts with a decimal
			if (formFieldValue.match(/^\./))
				{formFieldValue = "0" + formFieldValue;
					}
			//Ends with a decimal
			if (formFieldValue.match(/\.$/))
				{formFieldValue = formFieldValue + "00";
					}
			//No decimal
			var valueNoDecimal = formFieldValue.match(/[.]/)
			if (valueNoDecimal == null && formFieldValue != "")
				{formFieldValue = formFieldValue + ".00";
					}
			//Ends with a decimal and one number
			if (formFieldValue.match(/\.\d$/))
				{formFieldValue = formFieldValue + "0";
					}
			formField.value = formFieldValue;
				
			var valueMultipleDecimals = formFieldValue.split(/\./)
			if (valueMultipleDecimals.length > 2)
				{alert(formFieldValue + " can not have more than one decimal.");
					fieldStatus = "failed";
					}
			else if (formFieldValue.match(/\.{2,}/))
				{alert(formFieldValue + " can not have more than one decimal.");
					fieldStatus = "failed";
					}
			else if (formFieldValue.match(/\.\d{3,}$/))
				{alert(formFieldValue + " can not have more than two numbers after the decimal.");
					fieldStatus = "failed";
					}
			}
								
	if (fieldStatus == "failed")
			{formField.focus();
			formField.select();
			return false;
			}
}

//Pass in a table name and this will hide or show it.
function HideShowTable(buttonId, tdId)
{
	//First make sure the table exists
	if(document.getElementById(tdId) != null)
	{
		if (document.getElementById(tdId).style.display == '')
		{
			buttonId.src = "images/plus.gif"
			document.getElementById(tdId).style.display = 'none';
			
			//This is an indicator on the form to let us know whether we are keeping the
			// our table collapsed or expanded on a post back
			var tdTableInd = tdId + "Ind";	
			if (document.getElementById(tdTableInd) != null)
			{
				document.getElementById(tdTableInd).value = 'none';							
			}
			
			//This checks to see if there is a table we want to show when we hide the
			//  main table.  It needs to be named the same with the text "Hidden" appended 
			//  on the end.  Used to display text when a table is hidden.
			var tdHiddenTable = tdId + "Hidden";		
			if (document.getElementById(tdHiddenTable) != null)
			{
				document.getElementById(tdHiddenTable).style.display = '';							
			}
		}
		else
		{
	 		buttonId.src = "images/minus.gif"
			document.getElementById(tdId).style.display = '';	
			
			//This is an indicator on the form to let us know whether we are keeping the
			// our table collapsed or expanded on a post back				
			var tdTableInd = tdId + "Ind";	
			if (document.getElementById(tdTableInd) != null)
			{
				document.getElementById(tdTableInd).value = '';							
			}		
			
			//This checks to see if there is a table we want to show when we hide the
			//  main table.  It needs to be named the same with the text "Hidden" appended 
			//  on the end.  Used to display text when a table is hidden.
			var tdHiddenTable = tdId + "Hidden";		
			if (document.getElementById(tdHiddenTable) != null)
			{
				document.getElementById(tdHiddenTable).style.display = 'none';							
			}			
		}	    	
	}
}

//When we exectuted HideShowTable to hide a table, we set a hidden
// asp:textbox equal to the display value of our table.  This allows
// Viewstate to keep track of whether our table was hidden or not so
// that we can make it the same after a postback.
function KeepTableStatus(tblIndicatorName, tblTableName, tblHiddenName, imgShowHideName)
{
	var tblIndicator = document.getElementById(tblIndicatorName)
	if (tblIndicator != null)
	{
		//Set the tables display equal to the indicator
		document.getElementById(tblTableName).style.display = tblIndicator.value
		//If it's to be hidden, then we need to reset these fields
		if (tblIndicator.value == 'none')
		{
			var tblHidden = document.getElementById(tblHiddenName);
			if (tblHidden != null)
			{
				tblHidden.style.display = ''
			}
			var imgShowHide = document.getElementById(imgShowHideName);
			if (imgShowHide != null)
			{			
				imgShowHide.src = "images/plus.gif"
			}
		}
	}
}

//This is to open up a date pop-up
function DatePicker(ctl)
{
	var txtDate = document.getElementById(ctl);
	if (txtDate != null) 
	{
		var strDate = window.showModalDialog("DatePicker.aspx?Ctl=" + txtDate.value,"Date Picker","center:yes;help:off;edge:sunken;status:no;dialogWidth:11;dialogHeight:14");
		
		if (strDate != undefined)
		{
			txtDate.value = strDate
		}
		txtDate.focus();
		txtDate.scrollIntoView();
	}
}

function validateEmail(formField) {
	var formFieldValue = formField.value;
	okChars = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

	for(i=0; i < formFieldValue.length ;i++)
		{if(okChars.indexOf(formFieldValue.charAt(i)) < 0)
			{alert("Invalid characters detected in email address.");
			formField.focus();
			return false;
			}	
	} 
	invalidCharSets = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
	validForm = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	if (formFieldValue.match(invalidCharSets) || !formFieldValue.match(validForm))
		{if (formFieldValue != "")
			{alert("Invalid email detected.");
				formField.focus();
				return false;
				}
			}
}

function validateZip(formField){
	var formFieldValue = formField.value;
	var valueMatch = formFieldValue.match(/\D/);
	if (formFieldValue.length > 0 && formFieldValue.length < 5)
		{alert(formFieldValue + " is not a valid zip code.");
			formField.focus();
			formField.select();
			return false;
			}
	if (valueMatch != null)
		{alert(formFieldValue + " is not a valid zip code.");
			formField.focus();
			formField.select();
			return false;
			}	

}

/**************************************************************************************************************
This function validates fields, used for EmailFax UI and some Time fields in the form
***************************************************************************************************************/
function ValidateField(PatternType)
{
	var sPatternTin = /^(?=.{9})[a-zA-Z0-9]*$/
	var sPatternIntWithCommas = /^([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)?$/
	var sPatternZip = /^(\?(\d{5})|(\d{5}(|\d{4})))$/
	var sPatternEmail  = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/
	var sPatternDate =/^(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/
	var sPatternPercent = /^([0-9]|[1-9]\d|100)$/
	var sPatternPhone = /^([\(]{1}[0-9]{3}[\)]{1}[ |\-]{0,1}|^[0-9]{3}[\-| ]){1}[0-9]{3}(\-| ){1}[0-9]{4}$/
	var sPatternShortname = /^\w{1,8}$/
	//Multiple Shortnames seperated by commas.
	var sPatternShortnames = /^\w{1,8}(,\w{1,8})*$/
	//optional 1, optional .-, optional (, 3 digits, optional ).-, optional space, 
	// 3 digits, optional -., 4 digits, $ means to the end
	var sPatternFax = /^[1]?[\(\.\-]?\d{3}[\)\.\-]?\s?\d{3}[\.\-]?\d{4}$/
	var sPatternTime = /^([0-1][0-9][\:][0-5][0-9])$|([2][0-3][\:][0-5][0-9])$/
		
	var sPattern
	var msg 
	switch (PatternType)
	{
		case "TIN":
			sPattern  = sPatternTin
   			msg ="Tin is invalid: \nMust be 9 characters long, letters and numbers only."
			break;
		case "ZIP":
			sPattern  = sPatternZip
			msg = "Zip Code is invalid: \nMust be 5 or 9 numbers."
			break;
		case "EMAIL":
			sPattern  = sPatternEmail
			msg = "Email address is invalid: \nex.jsmith@website.com"
			break;
		case "DATE":
			sPattern  = sPatternDate
			msg = "Date entered is not valid: \nPlease use mm/dd/yyyy format."
			break;
		case "PERCENT":
			sPattern  = sPatternPercent
			msg = "Percentage entered is not valid: \nPlease use 0 to 100."
			break;
		case "PHONE":
			sPattern  = sPatternPhone
			msg = "Phone entered is not valid: \nPlease use format (860)954-5555 - area code is required."
			break;
		case "SHORTNAME":
			sPattern  = sPatternShortname
			msg = "Shortname entered is invalid: \nPlease use similar to JXSMITH"
			break;	
		case "SHORTNAMES":
			sPattern  = sPatternShortnames
			msg = "Shortnames entered are invalid: \nPlease use similar to JXSMITH,JXJONES for multiple recipients."
			break;				
		case "INTEGERWITHCOMMAS":	
			sPattern  = sPatternIntWithCommas
			msg = "Subtotal entered is not valid: \nPlease use 0 to 9,999,999 (no decimal)"
			break;
		case "FAX":
			sPattern  = sPatternFax
			msg = "Fax entered is not valid or is formatted incorrectly:\nMust be at least 10 digits, please make sure you include the area code."
			break;			
		case "TIME":
			sPattern  = sPatternTime
			msg = "Time entered is not valid or is formatted incorrectly:\nMust be hh:mm"
			break;	
	}
	
	if (event.srcElement.value != "")
	{
		if (!sPattern.test(event.srcElement.value))	
			{
				alert(msg);
				event.srcElement.focus();
				event.srcElement.select();
				window.event.returnValue = false;
				return false
			}
		else
			return true;	
	}
	else
	{
		//If user leaves a numeric field blank, set to zero
		if (PatternType == "INTEGERWITHCOMMAS") 
			event.srcElement.value = 0;
			return true;	
	}
} 

//This function is added to all Text and Totaling Text boxes that
// allow 2 decimal places, this is to keep them formatted with the .nn
function formatDecimal(field, decimalLength)
{
	if (window.event.returnValue != false) {
		if (field.value != "")
		{
			var decimalValue = parseFloat(field.value.replace(/,/g,""));
			field.value = decimalValue.toFixed(decimalLength);
		}
	}
}

function turnOn(imageName) {

	var image = document.getElementById(imageName);
	
	if (image != null)
	{			
		image.src = "images/" + imageName + "_on.gif"
	}
}

function turnOff(imageName) {
	
	var image = document.getElementById(imageName);
	
	if (image != null)
	{			
		image.src = "images/" + imageName + "_off.gif"
	}
}

/***********************************************
* Auto Maximize Window Script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for this script and 100's more.
***********************************************/
function MaximizeWindow()
{
	top.window.moveTo(0,0);
	if (document.all) 
	{
		top.window.resizeTo(screen.availWidth,screen.availHeight);
	}
	else if (document.layers||document.getElementById) 
	{
		if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth)
		{
			top.window.outerHeight = screen.availHeight;
			top.window.outerWidth = screen.availWidth;
		}
	}
}

function querystringGetField(getField)
{
    var theField = getField.toUpperCase()
    var inpt=location.search.substring(1);
    var dataName = new Array(10);
    var dataValue = new Array(10);
    var formData = inpt.split('&');
    for(var i = 0; i<formData.length; i++)
    {
	    var middle = formData[i].indexOf('=');
	    if (middle == -1)
		    continue;
		    dataName[i] = formData[i].substring(0,middle);
		    var dval = formData[i].substring(middle+1);
		    dataValue[i] = unescape(dval);
		    var dataNameTest = dataName[i].toUpperCase()
		    if (dataNameTest == theField)
		    {
			    return dataValue[i]
		    }
    }
    return ""
} 

function ConfirmDelete(message)
{
	//makeMsgBox is a VBscript function that we must use
	// in order to have different icons and buttons then the
	// standard Javascript confirm box.
	var retVal = makeMsgBox("Confirm Delete",message,48,4,256,0);

	if (retVal == 6)
	{	
		DisplayWait(false);	
		return true;
	}
	else
	{
		return false;
	}
}