﻿
/*	Form Library - New module should strip out all of these comments */

/*
The form on the page. In ASP.net 1.1 you will have only one form which is
document.forms[0].
*/
function frm()
{
	return document.forms[0];
}

/*
The array of all form elements (fields) in the form. Useful for looping through
the entire collection of form elements in order to do conditional operations, etc.
*/
function flds()
{
	return frm().elements;
}

/*
Clear a field. Useful for when a TextBox has a default value and you want to clear
it out - i.e: <input type="text" name="foo" value="bar" onclick="cf(this)"; /> 
*/
function cf(obj)
{
	obj.value = "";
}

/*
Clear a the Credit Card Field if it is masked with X's. 
*/
function cfCCNum(obj)
{
	if(obj.value.indexOf("X") > -1)
	{
		obj.value = "";
	}
}
/*
Clear a the Credit Card Field if it is masked with X's. 
*/
function cfCCNumS(s)
{
	df = document.forms[0];
	if(df.elements[s].value.indexOf("X") > -1)
	{
		df.elements[s].value = "";
	}
}

/*
Clear TextBox text using the array of names
*/
function clrTB(arrFlds)
{
	for(i=0; i < arrFlds.length; i++) {
		if(flds()[arrFlds[i]] != null) {
			cf(flds()[arrFlds[i]]);
		}
	}
}

/*
Clear Drop Down lists.
*/
function clrDD(arrFlds)
{
	for(i=0; i < arrFlds.length; i++) {
		if(flds()[arrFlds[i]] != null) {
			flds()[arrFlds[i]].selectedIndex = 0;	
		}
	}
}

/*
Focus on a field by name.
*/
function ff(n)
{
	flds()[n].focus();
}

/*
Loop through the array of form fields passed in  by name and then 
*/
function tglFrmCss(arrFlds,bOn,cssStr)
{
	df = document.forms[0];
	for(i=0; i < arrFlds.length; i++)
	{
		if(df.elements[arrFlds[i]] != null)
		{
			df.elements[arrFlds[i]].disabled = !bOn;
			if(ie || dom) {
				df.elements[arrFlds[i]].className = (bOn) ? "TextBox" : cssStr;
			}
		}
	}
}

function tglFrm(arrFlds,bOn)
{
	tglFrmCss(arrFlds,bOn,"TextBoxDisabled");	
}

/*
Get the currently selected value from a DropDownList or select tag.
*/
function getDDVal(s)
{
	df = document.forms[0];
	return df.elements[s].options[df.elements[s].selectedIndex].value;	
}

/*
Get the currently selected text from a DropDownList or select tag.
*/
function getDDTxt(n)
{
	df = document.forms[0];
	return df.elements[s].options[df.elements[s].selectedIndex].text;	
}

/*
Returns a boolean indicating whether or not the DropDownList or select tag
has options.
*/
function hasDDOptions(n)
{
	df = document.forms[0];
	if(df.elements[n] == null) {
		return 0;
	}
	return (df.elements[n].options.length > 0);
}

/*
Returns a boolean indicating whether or not a selection has been made in the
DropDownList or select tag has options. This function assumes that the first
option is empty (not selected).
*/
function isDDSelected(n)
{
	df = document.forms[0];
	return (df.elements[n].selectedIndex >= 1);	
}

function stopType(n)
{
	df = document.forms[0];
	return !df.elements[n].disabled;
}

/*
Enter Key CLick - Add this as an attrruibute by calling the methods
in Web.Tools in the PreRender phase of the ASP.net page to make it so 
that an enter key hit will function as migrating to a button and clicking it.
*/
function ekc(event,n)
{
	//alert("ekc invoked");
	
	if((ns4 ? event.which : event.keyCode) == 13)
	{
		event.returnValue = 0;
		event.cancel = 1;
		
		if(ns4)
		{
			return 0;
        }
		else if(dom && !ie)
		{
			document.getElementById(n).focus();
			document.getElementById(n).click();	
		}
		else 
		{
			document.all[n].click();	
		}
	}
}

/*
Kill Enter Key. Kills the raised events from an enter key
*/
function ke(event)
{
	if((ns4 ? event.which : event.keyCode) == 13)
	{
		event.returnValue = 0;
		event.cancel = 1;
		return 0;
	}	
}

cc = 0;

function StpDblClck()
{
	cc++;
	if(cc > 1) {
		return 0;	
	}
}

/*
Checks a number to see if it is numeric. Called as a protupe method - i.e:
b = "01234569".isNum();
*/
String.prototype.isNum = function()
{
  	d = "0123456789";
  	for(var i=0; i < this.length; ++i) {
    	if(d.indexOf(this.charAt(i)) == -1) {
			return 0;
		}
	}
			
  	return 1;
}

/*
Returns the index of the form element by the name.
*/
function getNdx(n)
{
	df = document.forms[0];
	for(i=0; i < df.elements.length; ++i) {
		if(n == df[i].name) {
			return i;
		}
	}
	
	return i;
}

/*
Functionality for the Phone control tabbing.
*/
function tabPh(event,o,l)
{
	k = (ns4) ? event.which : event.keyCode;
	c = new Array("8","9","16","46");
	b = 1;
	
	for(i=0; i < c.length; ++i) {
		if(c[i] == k.toString()) {
			b = 0;
		}
	}
	
	if(b)
	{	
		if(o.value.length == l && o.value.isNum())
		{
			nxt = getNdx(o.name);
			df = document.forms[0];
			df.elements[++nxt].focus(); 
		}
	}
}