

///
var explorer = (navigator.appName.indexOf("Explorer") != -1);

function enableCaptureEvents(val) {
if (explorer) {
	return true;
} //closes if

else {
document.captureEvents(Event.KEYPRESS); 
if (val == "number")
{document.onkeypress = checkNumber;} 
if (val == "letter")
{document.onkeypress = checkLetter;}
} //closes else
} //closes function

function disableCaptureEvents() {
if (explorer) {
	return true;
} //closes if

else {
document.releaseEvents(Event.KEYPRESS); 
} //closes else
} //closes function

/*
checkNumber() 
Only allows numeric values to be entered into a form input field.
NOTE: There is a hard coded check for the "amount" field to allow commas in it. You'll need to alter this code if you want to add commas to other fields to be checked.
*/
function checkNumber(event) {
var checkType = (explorer) ? window.event.srcElement.name : event.target.name; //find name of the source of the event
checkType = checkType.toString();
var isNumber = (checkType.indexOf("CD_POLICY_FACE_AMT") != -1) ? new RegExp("[0-9\b-.]") : new RegExp("[0-9\b-.]"); //create regular expression to test value
if (!explorer) var origChar = event.which; // ASCII code of the key pressed
var charToString = (explorer) ? String.fromCharCode(window.event.keyCode) : String.fromCharCode(origChar); // string of the key pressed
 
if (!isNumber.test(charToString)) { //test the current character against the regular expression
if (explorer) window.event.returnValue=false;
return false;
} //closes if isNumber

return true; // allow the character to appear

} //closes function
function checkZip(event) {
var checkType = (explorer) ? window.event.srcElement.name : event.target.name; //find name of the source of the event
checkType = checkType.toString();
var isNumber =new RegExp("[0-9\b-.]"); //create regular expression to test value
if (!explorer) var origChar = event.which; // ASCII code of the key pressed
var charToString = (explorer) ? String.fromCharCode(window.event.keyCode) : String.fromCharCode(origChar); // string of the key pressed
 
if (!isNumber.test(charToString)) { //test the current character against the regular expression
if (explorer) window.event.returnValue=false;
return false;
} //closes if isNumber

return true; // allow the character to appear

} //closes function



function checkLetter(event) {
var checkType = (explorer) ? window.event.srcElement.name : event.target.name; //find name of the source of the event
checkType = checkType.toString();
var isNumber = new RegExp("[\ba-zA-Z -']"); //create regular expression to test value
if (!explorer) var origChar = event.which; // ASCII code of the key pressed
var charToString = (explorer) ? String.fromCharCode(window.event.keyCode) : String.fromCharCode(origChar); // string of the key pressed
 
if (!isNumber.test(charToString)) { //test the current character against the regular expression
if (explorer) window.event.returnValue=false;
return false;
} //closes if isNumber

return true; // allow the character to appear

} //closes function

function disableEdit(event) {

var isNumber = new RegExp("[\t]"); //allow the user to tab out)
if (!explorer) var origChar = event.which; // ASCII code of the key pressed
var charToString = (explorer) ? String.fromCharCode(window.event.keyCode) : String.fromCharCode(origChar); // string of the key pressed
 
if (!isNumber.test(charToString)) { //test the current character against the regular expression
if (explorer) window.event.returnValue=false;
return false;
} //closes if isNumber

return true; // allow the character to appear

} //closes function

//Begin stripNonNumbers///
//This function strips all non-numeric characters from a user-provided string.
function stripNonNumbers(phone) {
var newNum = "";
var donothing=""
var period = false
var count=0;
for (var i=0; i < phone.length; i++) {
if ((phone.charAt(i) >= "0") && (phone.charAt(i) <= "9")||(phone.charAt(i)==".")) {
	if (period==false)
		if (phone.charAt(i)==".")
			{period=true;
			 newNum += phone.charAt(i);}
		else
			newNum += phone.charAt(i);
	else if (period==true)
		if (phone.charAt(i)==".")
			donothing="";
		else if ((count < 2)&&(i<phone.length))
		  {count++;
			newNum+=phone.charAt(i);}

} //closes if
} // closes for loop      
return newNum;

}  //closes function
//End stripNonNumbers///

//Begin autotab
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
var i=1;
if (input.form[(getIndex(input)+1) % input.form.length].disabled==true)
{do
i++;
while(input.form[(getIndex(input)+i) % input.form.length].disabled==true);}
input.form[(getIndex(input)+i) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}
//  End autotab 

//Begin School Number check/////
function isSSN (num,event)
	{
	var i;
	
	if (((num.length < 4)  || (num.length > 7)) && (num.length > 0))
	{alert("The School Number must be four digits long if you are a student or nine digits long if you are a Friend of Alliance. \nPlease re-enter."); 
		 if (explorer) 
		 	{window.event.srcElement.focus()
		 	 window.event.srcElement.select();}
		//return "";
		}
	//return num;
	}
////////END SSN/TIN /////////////

////Begin isPhone////
function isPhone (num,length,event)//does not need to be changed
	{
	var i;
		if ((num.length < length)&& (num.length > 0))
 		{alert("The number needs to be "+length+" digits long. \nPlease re-enter.");
		 if (explorer) 
		 	{window.event.srcElement.focus()
		 	 window.event.srcElement.select();}
		 else
		 	{event.target.focus();
		 	 event.target.select();}
		}

	}
///End isPhone////

//Begin commaSplit
function here(event)
		{var val=stripNonNumbers(window.event.srcElement.value)
		 if  (val>=100000000)
				{
				alert("You must enter an amount no greater than 99,999,999.99");
				window.event.srcElement.focus();
	 			window.event.srcElement.select();}
		}
		
function commaSplit(srcNumber,event) {

var txtNumber = '' + srcNumber;
//if (isNaN(txtNumber)) {
//var srcNumber2=stripNonNumbers(srcNumber);
//return commaSplit(srcNumber2);
//}
//else {
txtNumber=stripNonNumbers(txtNumber);
var rxSplit = new RegExp('([0-9])([0-9][0-9][0-9][,.])');
var arrNumber = txtNumber.split('.');
arrNumber[0] += '.';
do {
arrNumber[0] = arrNumber[0].replace(rxSplit, '$1,$2');
} while (rxSplit.test(arrNumber[0]));
//alert(arrNumber.length);
if (arrNumber.length > 1) {
return arrNumber.join('');
}
else {
return arrNumber[0].split('.')[0];
      } 
   //}
	 
}
//  End commaSplit

//Begin Erase
function erase(formName)
{
var index="";

for (i=0; i<document.forms[formName].elements.length;i++)
	{if(document.forms[formName].elements['FIRST_NAME']==document.forms[formName].elements[i])
		index = i;}
for (i=index; i < index + 9;i++)
	{document.forms[formName].elements[i].value=""}
document.forms[formName].elements['GENDER'][0].checked = false;
document.forms[formName].elements['GENDER'][1].checked = false;
	}
//End Erase
//Begin Erase
function erase2(formName)
{
var index="";

for (i=0; i<document.forms[formName].elements.length;i++)
	{if(document.forms[formName].elements['FIRST_NAME']==document.forms[formName].elements[i])
		index = i;}
for (i=index; i < index + 18;i++)
	{document.forms[formName].elements[i].value=""}
document.forms[formName].elements['GENDER'][0].checked = false;
document.forms[formName].elements['GENDER'][1].checked = false;
	}
//End Erase
//Begin EMail_check
function checkEmail(FormName,ElemName)
{
var c = true
var t = document.forms[FormName].elements[ElemName]
var at = t.value.indexOf('@')
var dot = t.value.lastIndexOf('.')
var sp = t.value.indexOf(' ')
var ln = t.value.length - 1
if ((at < 1) ||
	(dot <= at+1) ||
	(dot == ln) ||
	(sp != -1))
    {
   		c = false
    }
	return c
}
//End EMail_check

function limitTextLength(event) {
var text = event;
var textAreaMaxSize = 255;
if (!explorer) {

var lastChar = event.which; // ASCII code of the key pressed
if (lastChar == 8) return true;
text = window.event.srcElement; //assign the form field to the text variable
} //closes if not explorer

	if (text.value.length >= (textAreaMaxSize)) {

		if (explorer) window.event.returnValue=false;
		return false;

	} //closes if

return true;
} //closes function
function limitTextLength2(event) {
var text = event;
var textAreaMaxSize = 4000;
if (!explorer) {

var lastChar = event.which; // ASCII code of the key pressed
if (lastChar == 8) return true;
text = window.event.srcElement; //assign the form field to the text variable
} //closes if not explorer

	if (text.value.length >= (textAreaMaxSize)) {

		if (explorer) window.event.returnValue=false;
		return false;

	} //closes if

return true;
} //closes function

function check_days_of_month(month_val,day_val,year_val,type,event)
{var error_string="";

	if ((month_val!="")&&(day_val!="")&&(year_val!="")){
// Check for February
 //alert(month_val+","+day_val+","+year_val);
   if (month_val == 2)
   {

   // Check for leap year date
      if ((year_val % 4 == 0 && year_val % 100 != 0) || year_val % 400 == 0 )
      {
         if (day_val < 1 || day_val > 29)
         {
            error_string = error_string + " Only 29 days in February " + "\n";
         }
      }
      else
      {
         if (day_val < 1 || day_val > 28)
         {
            error_string = error_string + " Only 28 days in February " + "\n";
         }
      }
   }

// Check 30 day months...
   if (((month_val == 4) ||
        (month_val == 6) ||
        (month_val == 9) ||
        (month_val == 11)) &&
       (day_val < 1 || day_val > 30))
   {
      error_string = error_string + " Only 30 days in this month" + "\n";
   }

// Check 31 day months
   if (((month_val == 1) ||
        (month_val == 3) ||
        (month_val == 5) ||
        (month_val == 7) ||
        (month_val == 8) ||
        (month_val == 10) ||
        (month_val == 12)) &&
       (day_val < 1 || day_val > 31))
   {
      error_string = error_string + " Only 31 days in this month"  + "\n";
   }
   function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
		else i++;
		return index;
		}
	 
   if (error_string!="")
   		{alert(error_string);
			 if (type=="mm"){
			   	window.event.srcElement.form[(getIndex(window.event.srcElement)+1)].focus();
					window.event.srcElement.form[(getIndex(window.event.srcElement)+1)].select();}
			 if (type=="dd"){
			 		window.event.srcElement.form[(getIndex(window.event.srcElement))].focus();
					window.event.srcElement.form[(getIndex(window.event.srcElement))].select();}
			 if (type=="yyyy"){
			 		window.event.srcElement.form[(getIndex(window.event.srcElement)-1)].focus();
					window.event.srcElement.form[(getIndex(window.event.srcElement)-1)].select();}
			 
			 }
  }
}// Ends Check_Days_of_Month
function datevalue(dtype,month,day,year2,event)
{	var Tdate = new Date();
	var year = Tdate.getFullYear();
	
	//alert(window.event.srcElement.tabIndex);
if (window.event.srcElement.value != "") 
		{
	if (dtype=='mm' && ((window.event.srcElement.value <1) || (window.event.srcElement.value>12)))
		{alert("You have entered an invalid month \nPlease enter a number 1-12");
		window.event.srcElement.focus()
		window.event.srcElement.select();
		return true;}
	 else if (dtype=='dd' && ((window.event.srcElement.value <1) || (window.event.srcElement.value>31)))
		{alert("You have entered an invalid date \nPlease enter a number 1-31");
		window.event.srcElement.focus()
		window.event.srcElement.select();
		return true;}
	 else if ((dtype=='yyyy') && (window.event.srcElement.value <= 999))
		{alert("You have entered an invalid year \nPlease enter a four digit number");
		window.event.srcElement.focus()
		window.event.srcElement.select();
		return true;}
	}
	 //alert(month+","+day+","+year2);
	check_days_of_month(month,day,year2,dtype,event);
	
}// Ends Date Value

//This function strips all non-numeric characters from a user-provided string.



function check_num()
{
	var allowThrough = true;
	var val = String.fromCharCode(window.event.keyCode);
	var fieldValue = window.event.srcElement.value.toString();
	
	if (fieldValue.indexOf(".") != -1) {
		fieldValue = fieldValue.split(".");
		var decimalPlaces = fieldValue[1].length;
		if (val == ".") allowThrough = false;
	}
	
	if(!((parseInt(val) >= 0 && parseInt(val) <= 9) || val == ".")) allowThrough = false;
	if (decimalPlaces > 1) allowThrough = false;

	if (!allowThrough) {
	window.event.returnValue = false;
	}
	
return true;	
}


function check_num_nodecimal()
{
	var val;

	val = String.fromCharCode(window.event.keyCode);
	if(isNaN(val) && (val != null))
		{
		window.event.returnValue=false;
		}
}

function checkTextBox(formName,textBox,dropDown,val)
{
var theform = document.forms[formName] ;
if (theform.elements[textBox].value != "")	{	theform.elements[dropDown].value = val }
else if (theform.elements[textBox].value == "")	{	theform.elements[dropDown].value = "" }
}

function resetTextBox(formName,textBox,dropDown,val)
{
var theform = document.forms[formName];
if (theform.elements[dropDown].value != val)	{	theform.elements[textBox].value = "" }
}

