//----------e-Plaza JavaScript for FORMS ver 1.0. DATE: 031111 TIME: 0752 -------------

// FORM routines.  The FORM NAME for all of these routines is [Form1]. ----------------

// Help Routine by NW -----------------------------------------------------------------
/* The Help Routine is included for documentation purposes.
   NOTE:  All [Header_HTML.inc] files already include the Help Routine.
*/
//var HelpWindow=null;
//function Help(mypage,myname,w,h,pos,infocus){
//LeftPosition=(screen.width)?(screen.width-w)/2:100;
//TopPosition=(screen.height)?(screen.height-h)/2:100;
//settings='width='+ w + ',height='+ h + ',top=' + TopPosition + ',left=' + LeftPosition + ',location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=no,dependent=no';
//HelpWindow=window.open(mypage,myname,settings);
//HelpWindow.focus();
//HelpWindow.location=mypage;
//}

// Position Cursor by NW --------------------------------------------------------------
/* Position Cursor to the first field in a form - 
   the field name in the FORM must be [FirstField] or change this routine to use the FORMS index.
   Requires an OnLoad event in the BODY tag.  Thus, this routine requires that the
   [Header_HTML.inc] include file have the OnLoad event, or that the file requiring this
   routine use the [Header_HTML_form.inc] file which already has the OnLoad event in the
   BODY tag.  To keep the [Header_HTML.inc] file as clean as possible NW recommends using
   the [Header_HTML_form.inc] file.

   NOTE:  Users with Norton's Internet Security 2003+ will not be able to see this effect if they
          have enabled prevention of pop-up ads. nw on 2/29/04 */
function PositionCursor(){document.Form1.FirstField.focus();}

// Character Counter ------------------------------------------------------------------
/*
Form field Limiter script- By Dynamic Drive
For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
This credit MUST stay intact for use
*/

var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}

function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}

function displaylimit(theform,thelimit)
{
var limit_text='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b> characters remaining on your input limit.'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
}
}


// Change/Delete Submit Value by NW ---------------------------------------------------
/* The Change/Delete Submit Value reads the FORM field [ChgDel] and then sets the value
   of the Submit button to display the Change statement or the Delete statement.
*/
  function changesubmit(strNew) {
    var formChgDel = document.Form1.ChgDel
    if (document.Form1.ChgDel(0).checked) {
       document.Form1.B1.value = "Change this " + strNew +" Item"
   }else{
       document.Form1.B1.value = "Delete this " + strNew +" Item"
   }
 }

/* Disable the ENTER Key --------------------------------------------------------------
* Disable "Enter" key in Form script- By Nurul Fadilah(nurul@REMOVETHISvolmedia.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code

NOTE by NW:
  IF you also use the routine above [Character Counter], then the function below [handleEnter]
  will NOT work, the ENTER key is not handled because of a conflict with the [onKeyPress] event
  used in the Character Counter's [displaylimit] function.  Of course, you chould change the event
  to [onKeyDown] or [onKeyUp] but watch out for browser compatabilities.

  ANOTHER way, if you want to disable the ENTER key, then do the following:
  
  1.  Change the FORM tag:
  
     <FORM NAME="Form1" METHOD="POST" ACTION="somepage.asp" onSubmit="return false">
  
  2.  Change the SUBMIT tag:
  
     <INPUT TYPE="button" VALUE="Submit this form." onClick="document.Form1.submit()">

***********************************************/
                
function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
	}
 
// this is another way to disable the ENTER key.  Also have to include the following in the 
// FORM tag:  onKeyPress="disableEnterKey()"
function disableEnterKey() 
{ 
     if (window.event.keyCode == 13) window.event.keyCode = 0; 
} 
//-------------------------------------------------------------------------------------


// Test field for empty by NW ---------------------------------------------------------
// This is an in-line test, not a batch test.
// Add to form field:  return onBlur="verify(this.value, 'fieldName')"

 var setFocus
 
 function verify(inputStr, titleStr, fieldName) {
    while(''+inputStr.charAt(0)==' ')inputStr=inputStr.substring(1,inputStr.length) //strip blanks
    if (inputStr == null || inputStr == "") {
       alert(titleStr+" Field is required.");
       setFocus = "Y";
       return true;
    } else {
    setFocus = "N";
    return false;
    }
 }


// Auto Tab field ---------------------------------------------------------
// This is an in-line test, not a batch test.
// Add to form field:  onKeyUp="return autoTab(this, 3, event);"

// Original:  Cyanide_7 (leo7278@hotmail.com)
// Web Site:  http://members.xoom.com/cyanide_7

// This script and many more are available free online at
// The JavaScript Source!! http://javascript.internet.com

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);
input.form[(getIndex(input)+1) % 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;
}
//-------------------------------------------------------------------------------------
