//  The following is the implementation for the Basic.js library
//  ============================================================
//  <SCRIPT LANGUAGE="JavaScript" SRC="http://william/ScriptLibrary/Basic.js"></SCRIPT>
//
//
//  The following is a list of the functions contained in Basic.htm
//  ==============================================================
//  1)  filter
//  2)  trim
//
//
//*****************************************************************
//*****************************************************************
//			filter
//*****************************************************************
//  The filter function scrubs form elements for unwanted key
//  strokes.  This prevents the user from entering improper
//  characters in an input field.  An alert is given to the user
//  and the offending character(s) are scrubbed from the input element.
//*****************************************************************
//
//  The following is an implementation example for the filter function
//  ==================================================================
//  ==================================================================
//
//  HTML function call from inside the input tag.
//  =============================================
//  <form name="frmTest">
//	<textarea name="test" onkeyup="filterlist('frmTest','test')" rows="3" cols="32"></textarea>
//  </form>
//
//  Javascript function call of 'filter', this must appear inside the script area
//  on the page using the filter function.
//  ================================================
//  function filterlist(form,element)
//  {
//	//List the characters to be filtered out of the referenced elements.
//	//==================================================================
//	var chrs=[34,13,10]		//The usual offenders
//	
//	//Call the filter function.
//	//=========================
//	filter(chrs,form,element)
//  }
//
//  The filter function Code
//  ==================================================
function filter(chrs,form,element)
{
	var strTarget=document.forms(form).elements(element).value
	var Scrub=0
	//Check for things to scrub
	//=========================
	chrCount=chrs.length
	var i=0
	while (i<chrCount)
	{
		if (strTarget.indexOf(String.fromCharCode(chrs[i]))!=-1)
		{
			Scrub=1
		}
		i=i+1
	}
	//Do Scrub on target characters
	//===============================================
	if (Scrub==1)
	{
		alert("The Character you just entered is not permitted it this input area.")
		var temp=strTarget
		var tempstrTarget=""
		while (temp.length>0)
		{
			//Does this character get Scrubbed?
			//=================================
			var strChar=temp.substring(0,1)
			Scrub=0
			chrCount=chrs.length
			var i=0
			while (i<chrCount)
			{
				if (strChar==String.fromCharCode(chrs[i]))
				{
					Scrub=1
				}
				i=i+1
			}
			//Build the string without the offending characters
			//=================================================
			if (Scrub==0)
			{
				tempstrTarget=tempstrTarget + strChar
			}
			//Set temp = to the remainder of the string
			//=========================================
			if (temp.length==1)
			{
				temp=""
			}
			else
			{
				temp=temp.substring(1,temp.length)
			}
		}
		document.forms(form).elements(element).value=tempstrTarget
	}
}
//*****************************************************************
//*****************************************************************
//				trim
//*****************************************************************
//  The trim function removes leading and trailing spaces from a 
//  string
//*****************************************************************
//
//  The following is an implementation example for the trim function
//  ==================================================================
//  ==================================================================
//
//  Javascript function call of 'trim', this is a sample call
//  of the trim function
//  ================================================
//  function sample()
//  {
//	var strTest=" this is a test with spaces leading and trailing "
//	//Call the filter function.
//	//=========================
//	strTest=trim(strTest)
//  }
//
//  The trim function Code
//  ==================================================
function trim(strText)
{ 
    // This will get rid of leading spaces 
    // ===================================
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);
    // This will get rid of trailing spaces 
    // ====================================
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);
    //	Return the trimmed string
    //	=========================
   return strText;
}

//*****************************************************************
//*****************************************************************
//			   CkLengthFilter
//*****************************************************************
//  The CkLengthFilter function checks the length of text typed into 
//  an input box and filter specified characters
//*****************************************************************
//
//  ==================================================================
//  The CkLengthFilter function is usually called on the onkeyup
//  event of an input box
//
//  Implementation:
//  CkLengthFilter(form,element,length,chr)
//	form 	= form name
//	element = element name
//	length 	= max length of input
//	chrs	= characters to be filtered
//  Values are assigned to the chrs array in the javascript script
//  included in the input tag.
//  ================================================
//  Example:
//  <textarea name='Title' 
//  onkeyup='javascript:var chrs=[34,44,36];CkLengthFilter("frmGO","Title",10,chrs)'>
//  Text</textarea>
//
//  The CkLengthFilter function Code
//  ==================================================
function CkLengthFilter(form,element,length,chrs) {

 	//Call the filter function.
 	//=========================
 	filter(chrs,form,element)
 	varlength=document.forms(form).elements(element).value.length
 	varvalue=document.forms(form).elements(element).value
 	//Trim input
	//=========================
	if (varlength>length) {
		document.forms(form).elements(element).value=document.forms(form).elements(element).value.slice(0,length)
	}
}

//*****************************************************************
//*****************************************************************
//			   CkLengthNumber
//*****************************************************************
//  The CkLengthNumber function checks the length of text typed into 
//  an input box and verifies that it is numeric
//*****************************************************************
//
//  ==================================================================
//  The CkLengthNumber function is usually called on the onkeyup
//  event of an input box
//
//  Implementation:
//  CkLengthNumber(form,element,length)
//	form 	= form name
//	element = element name
//	length 	= max length of input
//  ================================================
//  Example:
//  <input name='inputname' 
//  onkeyup='CkLengthNumber("frmGO","Amount",10)' value="">
//
//  The CkLengthNumber function Code
//  ==================================================
function CkLengthNumber(form,element,length) {
//
//
	varlength=document.forms(form).elements(element).value.length
 	varvalue=document.forms(form).elements(element).value
	//Trim input
	//=========================
	if (varlength>length) {
		document.forms(form).elements(element).value=document.forms(form).elements(element).value.slice(0,length)
	}
	if (isNaN(varvalue)) {
		alert ("Value must be numeric, try again.");
		return(false);
	}
}

//*****************************************************************
//*****************************************************************
//			   DisableAll
//*****************************************************************
//  The DisableAll function disables all html elememts on a
//  document/page.
//*****************************************************************
//
//  ==================================================================
//  The DisableAll function is usually called after submitting a form
//  to prevent the user from attempting work while the page refreshes.
//
//  Implementation:
//  DisableAll()
//  ================================================
//  Example:
//  document.formName.submit()
//  DisableAll()
//
//  The DisableAll function Code
//  ==================================================

function DisableAll()
{
	var Collection=document.all
	var Count=Collection.length
	var i=0
	while (i<Count)
	{
		Collection(i).disabled=true
		i=i+1
	}
}


//*****************************************************************
//*****************************************************************
//			   ShowMenu
//*****************************************************************
//  The ShowMenu function displays expanding location menus
//*****************************************************************
//
//  ==================================================================
//  The ShowMenu function is called when expanding or contracting
//  expanding menus.
//  It is used in http://shelby/Engineering/Components/display/new_look/PNR_ExpandingLocationMenus.asp 
//
//  Implementation:
//  ShowMenu("X"), where the name of the Plus/Minus Image is "iX"
//  X is a unique integer that is assigned to each Menu
//  ================================================
//  Example:
//  <a href='javascript:ShowMenu("3");'><img src='http://Shelby/MultiMedia/images/active/PNR_Plus_Menu.gif' name='i3' border='0'></a>
//
//  The ShowMenu function Code
//  ==================================================
function ShowMenu( spanNum )
{
	
	menu="menu" + spanNum

	if(document.all[menu].style.display == "none" || document.all[menu].style.display == "" || document.all[menu].style.display == null)
	{
		document.all[menu].style.display = "block";
		document.images["i" + spanNum].src = "http://Shelby/MultiMedia/images/active/PNR_Minus_Menu.gif";
	}
	else
	{
		document.all[menu].style.display = "none";
		document.images["i" + spanNum].src = "http://Shelby/MultiMedia/images/active/PNR_Plus_Menu.gif";
	}
}	


//*****************************************************************
//*****************************************************************
//			   ShowMenu_Open
//*****************************************************************
//  The ShowMenu function displays expanding location menus (initially open)
//*****************************************************************
//
//  ==================================================================
//  The ShowMenu function is called when expanding or contracting
//  expanding menus.
//  It is used in http://shelby/Engineering/Components/display/new_look/PNR_ExpandingLocationMenus.asp 
//
//  Implementation:
//  ShowMenu_Open("X"), where the name of the Plus/Minus Image is "iX"
//  X is a unique integer that is assigned to each Menu
//  ================================================
//  Example:
//  <a href='javascript:ShowMenu("3");'><img src='http://Shelby/MultiMedia/images/active/PNR_Plus_Menu.gif' name='i3' border='0'></a>
//
//  The ShowMenu function Code
//  ==================================================
function ShowMenu_Open( spanNum )
{
	menu="menu" + spanNum
	if(document.all[menu].style.display == "block" || document.all[menu].style.display == "" || document.all[menu].style.display == null)
	{
		document.all[menu].style.display = "none";
		document.images["i" + spanNum].src = "http://Shelby/MultiMedia/images/active/PNR_Plus_Menu.gif";
	}
	else
	{
		document.all[menu].style.display = "block";
		document.images["i" + spanNum].src = "http://Shelby/MultiMedia/images/active/PNR_Minus_Menu.gif";
	}
}	



//*****************************************************************
//*****************************************************************
//			   ShowMenuv2
//*****************************************************************
//  The ShowMenuv2 function displays expanding location menus
//*****************************************************************
//
//  ==================================================================
//  The ShowMenuv2 function is called when expanding or contracting
//  expanding menus.
//  It is used in http://shelby/Engineering/Components/display/new_look/std_Menu.asp 
//
//  Implementation:
//  ShowMenuv2("X"), where the name of the Plus/Minus Image is "iX"
//  X is a unique integer that is assigned to each Menu
//  ================================================
//  Example:
//  <a href='javascript:ShowMenuv2("3");'>Display Text</a>
//
//  The ShowMenuv2 function Code
//  ==================================================
function ShowMenuv2( spanNum )
{
	
	menu="menu" + spanNum
	plus="plus" + spanNum
	minus="minus" + spanNum

	if(document.all[menu].style.display == "none" || document.all[menu].style.display == "" || document.all[menu].style.display == null)
	{
		document.all[menu].style.display = "block";
		document.all[plus].style.display = "none";
		document.all[minus].style.display = "block";
	}
	else
	{
		document.all[menu].style.display = "none";
		document.all[plus].style.display = "block";
		document.all[minus].style.display = "none";
	}
}	


//*****************************************************************
//*****************************************************************
//			   ShowMenu_Openv2
//*****************************************************************
//  The ShowMenu_Openv2 function displays expanding location menus (initially open)
//*****************************************************************
//
//  ==================================================================
//  The ShowMenu_Openv2 function is called when expanding or contracting
//  expanding menus.
//  It is used in http://shelby/Engineering/Components/display/new_look/std_Menu.asp 
//
//  Implementation:
//  ShowMenu_Openv2("X"), where the name of the Plus/Minus Image is "iX"
//  X is a unique integer that is assigned to each Menu
//  ================================================
//  Example:
//  <a href='javascript:ShowMenu_Openv2("3");'>Display Text</a>
//
//  The ShowMenu function Code
//  ==================================================
function ShowMenu_Openv2( spanNum )
{
	menu="menu" + spanNum
	plus="plus" + spanNum
	minus="minus" + spanNum
	if(document.all[menu].style.display == "block" || document.all[menu].style.display == "" || document.all[menu].style.display == null)
	{
		document.all[menu].style.display = "none";
		document.all[plus].style.display = "block";
		document.all[minus].style.display = "none";
	}
	else
	{
		document.all[menu].style.display = "block";
		document.all[plus].style.display = "none";
		document.all[minus].style.display = "block";
	}
}



//*****************************************************************
//*****************************************************************
//			   autotab
//*****************************************************************
//  The autotab function tabs to the designated form element once
//  the max length of the current form element is reached
//*****************************************************************
//
//  ==================================================================
//  The autotab function is usefull for phone number, ssn or other other
//  entries were the number of digits in a field are known.
//
//  Implementation:
//  autotab(this,destination)
//	Where: this is the current form element
//		 destination is the next form element that is tabbed to
//  
//  ================================================
//  Example:
//  <input type="text" name="SSN1" Value="<%Response.Write SSN1%>" size="2" style="font-family:arial; font-size:9pt; text-align:center" onKeyup="autotab(this, document.frmGo.SSN2)" maxlength=3>
//
//
//  The autotab function Code
//  ==================================================
function autotab(original,destination)
{
	if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
	destination.focus()
}



