function waitBeforeLoad(){  
  //workaround to make the page wait 5 second before finish renering all the elements on the page
  //for(i=0; i<50; i++) setTimeout('return;', 5000);
}

function openPopup(url)
{
    window.open(url,'','location=no,scrollbars=no,resizable=no,height=300,width=500');
}


function mdnFormat(fld, e) {
	var strCheck = '0123456789';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	var cleanStr = '';
	var i = 0;
	var shiftPressed=0;
        shiftPressed = e.shiftKey;
        if (shiftPressed) {
            return false;
        }
	if (whichCode == 13) { 
		return true;  // Enter
	}
	if (whichCode == 8 || whichCode == 9) {
		return true;  // Delete (Bug fixed)
	}
	if (whichCode >= 96 && whichCode <= 105) whichCode -= 48; //update for numeric keypad entry
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) {
		return false;  // Not a valid key
	}
	
	len = fld.value.length;
	for ( i = 0; i < len; i++ ) {
		if ( fld.value.charAt(i) != ')' && fld.value.charAt(i) != '(' && fld.value.charAt(i) != ' ' && fld.value.charAt(i) != '-') {
			cleanStr += fld.value.charAt(i);
		}
	}
	len = cleanStr.length;
	if (len > 9) {
		fld.value = fld.value.substr(0, 14);
		return false;
	}
	
	if (len >= 3 && len < 6) {
		fld.value = '(' + cleanStr.substr(0, 3) + ') ' + cleanStr.substr(3, len);
	} else if (len >= 6 && len < 9) {
		fld.value = '(' + cleanStr.substr(0, 3) + ') ' + cleanStr.substr(3, 3) + '-' + cleanStr.substr(6, len - 6);
	} else if (len >= 9) {
		fld.value = '(' + cleanStr.substr(0, 3) + ') ' + cleanStr.substr(3, 3) + '-' + cleanStr.substr(6, len - 6);
	}
		
	return true;
}

function inputIsNumeric(ex){       
    var strCheck = '0123456789';
    //var alpha = "qwertyuiopasdfghjklzxcvbnm~!@#$%^&*()_+-={}|\][:\"';<>?/.,";
    if( typeof( ex.keyCode ) == 'number') {
        if (ex.keyCode == 0) 
            e = ex.which;
        else
            e = ex.keyCode;
    } 
    else if( typeof( ex.which ) == 'number' ) {
        e = ex.which;
    } 
    else if( typeof( ex.charCode ) == 'number'  ) {
        e = ex.charCode;
    } 
    else {
        return false;
    }
    
    var inChar = String.fromCharCode(e);
    if (strCheck.indexOf(inChar) == -1 ) 
        return false;
    return true;
}

function mdnFormatOnBlur(t,e, regClientId)
{
    //alert("Inside blur");
    var patt1 = /(\d{3}).*(\d{3}).*(\d{4})/;
    var patt2 = /^\((\d{3})\).(\d{3})-(\d{4})$/;
    var str = t.value;
    var result;
    if (!str.match(patt2))
    {
        result = str.match(patt1);
        if (result!= null)
        {
            t.value = t.value.replace(/[^\d]/gi,'');
            str = '(' + result[1] + ') ' + result[2] + '-' + result[3];
            t.value = str;
        }
        else
        {
            if (t.value.match(/[^\d]/gi))
            t.value = t.value.replace(/[^\d]/gi,'');
        }
    }
          
    var RgValidator =  document.getElementById(regClientId);
    ValidatorValidate(RgValidator);      
    ValidatorUpdateDisplay(RgValidator);
}

function mdnFormat2(t,e)
{
    var patt1 = /(\d{3}).*(\d{3}).*(\d{4})/;
    var patt2 = /^\((\d{3})\).(\d{3})-(\d{4})$/;
    var str = t.value;
    var result;
    if (!str.match(patt2))
    {
        result = str.match(patt1);
        if (result!= null)
        {
            t.value = t.value.replace(/[^\d]/gi,'');
            str = '(' + result[1] + ') ' + result[2] + '-' + result[3];
            t.value = str;
        }
        else
        {
            if (t.value.match(/[^\d]/gi))
            t.value = t.value.replace(/[^\d]/gi,'');
        }
    }
}

function validateMDN(fld, e) {
	var isNS4 = (navigator.appName=="Netscape")?1:0;
	var whichCode = (window.Event) ? e.which : e.keyCode;
	
	if(!isNS4)
	    {
	       if(whichCode < 45 || whichCode > 57) event.returnValue = false;
	    }
	    else
	    {
	       if(whichCode < 45 || whichCode > 57) return false;
	    }
	    if ( cleanMDN(fld.value).length >= 10 ) return false;
	}
function cleanMDN(str){
    var valid = "0123456789";
    var retStr = "";
    for(i=0;i<str.length;i++){
        if (valid.indexOf(str.charAt(i)) >= 0) 
        retStr += str.charAt(i);
    }
    //alert(retStr);
    return retStr;
}

function isMDNOverSize(fld, e) {
    var strCheck = '0123456789';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    var cleanStr = '';
    var i = 0;
    if (whichCode == 13) {
        return true;  // Enter
    }

    if (whichCode == 8 || whichCode == 9) {
        return true;  // Delete (Bug fixed)
    }

    key = String.fromCharCode(whichCode);  // Get key value from key code
    if (strCheck.indexOf(key) == -1) {
        return false;  // Not a valid key
    }

    if (fld.value.length > 13) {
        return false;
    } else {
        return true;
    }
}

function formatMI(fld, e){
    var code = (window.Event) ? e.which : e.keyCode;
    var key = String.fromCharCode(code);
    if (isAlpha(key)){
        fld.value = fld.value.toUpperCase();
        return true;
    } else if (code == 16) {    // shift key
        return true;
    }
    else{
        fld.value = '';
        return false;
    }
}

function formatZIP(fld, e){
    var strCheck = '0123456789';
    var code = (window.Event) ? e.which : e.keyCode;
    var cleanStr = '';
	var i = 0;
	var shiftPressed=0;
    
    shiftPressed = e.shiftKey;
    if (shiftPressed) {
       return false;
    }
	
	if (navigation(code) == true) return true;

	if (code == 13 || code == 8 || code == 9 || code == 46) {
		return true;  // Delete (Bug fixed)
	}
	if (code >= 96 && code <= 105) code -= 48; //update for numeric keypad entry
	key = String.fromCharCode(code);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) {
		return false;  // Not a valid key
	}
	
    len = fld.value.length;
	if (len > 5) {
		return false;
	}
	   
    
    //return inputIsNumeric(e);
}

//I use these functions to test if a character is a number or an alphabetical character

var numb = '0123456789';
var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

function isValid(parm,val) {
    if (parm == "") return true;
    for (i=0; i<parm.length; i++) {
        if (val.indexOf(parm.charAt(i),0) == -1) 
            return false;
    }
    return true;
}

function isNum(parm) {
    return isValid(parm,numb);
}

function isLower(parm) {
    return isValid(parm,lwr);
}

function isUpper(parm) {
    return isValid(parm,upr);
}

function isAlpha(parm) {
    return isValid(parm,lwr+upr);
}

function isAlphanum(parm) {
    return isValid(parm,lwr+upr+numb);
}

//added DOB format, SSN format, ESN Check, language validation, etc

    function checkESN(sender, args) {
        var esn = args.Value;
        if (esn.length != 14) {
            args.IsValid = false;
        } else {
            args.IsValid = true;
        }
    }
    

function checkIssuer(sender, args) {
    var str = args.Value;
    var strCheck = '0123456789~!@#$%^&*()+[]\\|,./';
    var i = 0;
    for (i = 0; i < str.length; i++) {
        key = str.charAt(i)
        if (strCheck.indexOf(key) != -1) {
            args.IsValid = false;
            return;
        }
    }
    args.IsValid = true;
}


function formatZIP2(t) 
{
 
     // Check for correct zip code
     var s = t.value;
     reZip = new RegExp(/^\d{5}$/);
 
     if (!reZip.test(s)) {
          t.value = t.value.replace(/[^\d]/gi,'');
          return false;
     }
 
    return true;
}

function DOBFormat(fld, e) {
    var strCheck = '0123456789';
      var whichCode = (window.Event) ? e.which : e.keyCode;
      var cleanStr = '';
      var i = 0;
      var shiftPressed=0;
        shiftPressed = e.shiftKey;
        if (shiftPressed) {
            return false;
        }
      if (whichCode == 13) {
            return true;  // Enter
      }

      if (whichCode == 8 || whichCode == 9) {
            return true;  // Delete (Bug fixed)
      }
      if (whichCode >= 96 && whichCode <= 105) whichCode -= 48; //update for numeric keypad entry
      key = String.fromCharCode(whichCode);  // Get key value from key code
      if (strCheck.indexOf(key) == -1) {
            return false;  // Not a valid key
      }
      len = fld.value.length;
      for ( i = 0; i < len; i++ ) {
            if (fld.value.charAt(i) != '/') {
                  cleanStr += fld.value.charAt(i);
           }
      }
      len = cleanStr.length;
      if (len > 8) {
            fld.value = fld.value.substr(0, 10);
            return false;
      }
	  if (len >= 2 && len < 4) {
		fld.value = cleanStr.substr(0, 2) + '/' + cleanStr.substr(2, len);
	  } else if (len >= 4 && len < 6) {
		fld.value = cleanStr.substr(0, 2) + '/' + cleanStr.substr(2, 2) + '/' + cleanStr.substr(4, len - 4);
	  }  else if (len >= 6) {
		fld.value = cleanStr.substr(0, 2) + '/' + cleanStr.substr(2, 2) + '/' + cleanStr.substr(4, len - 4);
	  }
}

function SSNFormat(fld, e) {
    var strCheck = '0123456789';
      var whichCode = (window.Event) ? e.which : e.keyCode;
      var cleanStr = '';
      var i = 0;
      var shiftPressed=0;
        shiftPressed = e.shiftKey;
        if (shiftPressed) {
            return false;
        }
      if (whichCode == 13) {
            return true;  // Enter
      }

      if (whichCode == 8 || whichCode == 9) {
            return true;  // Delete (Bug fixed)
      }
      if (whichCode >= 96 && whichCode <= 105) whichCode -= 48; //update for numeric keypad entry
      key = String.fromCharCode(whichCode);  // Get key value from key code
      if (strCheck.indexOf(key) == -1) {
            return false;  // Not a valid key
      }
      len = fld.value.length;
      for ( i = 0; i < len; i++ ) {
            if (fld.value.charAt(i) != '-') {
                  cleanStr += fld.value.charAt(i);
           }
      }
      len = cleanStr.length;
      if (len > 9) {
            fld.value = fld.value.substr(0, 11);
            return false;
      }
	  if (len >= 3 && len < 5) {
		fld.value = cleanStr.substr(0, 3) + '-' + cleanStr.substr(3, len);
	  } else if (len >= 5 && len < 8) {
		fld.value = cleanStr.substr(0, 3) + '-' + cleanStr.substr(3, 2) + '-' + cleanStr.substr(5, len - 4);
	  }  else if (len >= 8) {
		fld.value = cleanStr.substr(0, 3) + '-' + cleanStr.substr(3, 2) + '-' + cleanStr.substr(5, len - 4);
	  }
}

function validateDOB(sender, args) {
    var str = args.Value;
    if (str.length == 0) {
        args.IsValid = true;
    } else {
        var monthfield=str.split("/")[0];
        var dayfield=str.split("/")[1];
        var yearfield=str.split("/")[2];
        
        var dayobj = new Date(yearfield, monthfield-1, dayfield);
        if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield)) {
            args.IsValid = false;
        } else {
            args.IsValid = true;
        }
    }
}

function validateLanguage(sender, args) {
    var str = args.Value;
    
    if (str == '-------') {
        args.IsValid = false;
    } else {
        args.IsValid = true;
    }
}

/*
 *Checks the age to see if its 18 years old
 */
function validateAge(sender, args){
    
    var str = args.Value;
    if (str.Length == 0)
        args.IsValid = false;
    else{   
        var monthfield=str.split("/")[0];
        var dayfield=str.split("/")[1];
        var yearfield=str.split("/")[2];
        
        var dayobj = new Date(yearfield, monthfield-1, dayfield);
        var valid18 = new Date();
        valid18.setFullYear(valid18.getFullYear() - 18);
        
        if (valid18 > dayobj){
            args.IsValid = true;
        }
        else{
            args.IsValid = false;
        }
    }
}


function disableFormJS() {
    try{
        var all = document.all;
        var string = "";
        
	    for(var i=0; i<all.length; i++)
	    {	    
	        if (all[i] != null && all[i].name != undefined && all[i].type == "image"){
	            
	            string += all[i].name + "\n";
	            var imgBtn = document.getElementById(all[i].id);
	            imgBtn.onmouseover = '';
	            imgBtn.onmouseout = '';
	            imgBtn.onclick = function(){ return false; }
	            
	            try{
	                var disImageName = eval("objImageDisable_"+imgBtn.id);
	                if (disImageName != null && disImageName != undefined){
	                    imgBtn.src = disImageName;
	                }
	            }
	            catch(e){}
	            imgBtn.style.cursor = 'not-allowed';
	        }   
	    }
	    
	}
	catch(e){}
}

function reformatMDN(fld) {
	var cleanStr = '';
	var strCheck = '0123456789';
	len = fld.value.length;
	for ( i = 0; i < len; i++ ) {
		if ( fld.value.charAt(i) != ')' && fld.value.charAt(i) != '(' && fld.value.charAt(i) != ' ' && fld.value.charAt(i) != '-') {
			if (strCheck.indexOf(fld.value.charAt(i)) != -1) {
				cleanStr += fld.value.charAt(i);
			} else {
				fld.value = '';
				return false;
			}
		}
	}
	len = cleanStr.length;
	if (len > 10) {
		cleanStr = cleanStr.substr(0, 10);
	}
	if (len >= 3 && len < 6) {
		fld.value = '(' + cleanStr.substr(0, 3) + ')' + cleanStr.substr(3, len);
	} else if (len >= 6 && len < 9) {
		fld.value = '(' + cleanStr.substr(0, 3) + ')' + cleanStr.substr(3, 3) + '-' + cleanStr.substr(6, len - 6);
	} else if (len >= 9) {
		fld.value = '(' + cleanStr.substr(0, 3) + ')' + cleanStr.substr(3, 3) + '-' + cleanStr.substr(6, len - 6);
	}
		
	return true;
}

function popUp(URL) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=505,height=480,left = 387.5,top = 160');");
}

function popUp2(URL, wi, he){
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=1,resizable=1,width="+wi+",height="+he+",left = 20,top = 20');");
}

function disableFormButtons(){
        try{
            var btnlist = document.body.getElementsByTagName("input");
            var input;
            var str = "";
            for(i=0;i<btnlist.length;i++){
                input = btnlist[i];
                if (input.type == "submit"){
                    str += input.id +"\n";
                    var disClassName = eval("class_"+input.id);
                    if (disClassName != null){
                        input.className = disClassName;
                        input.onmouseover = '';
	                    input.onmouseout = '';
	                    input.onclick = function(){ return false; }
                    }
                }   
            }
            //alert(str);
        }
        catch(e){
            //alert(e);
        }
        
    }
    
    // Adding MDN specific code.  This is used when we do a Phone # or MDM style box.
    
    
    
    

function navigation( keyCode )
{
        switch(keyCode)
       {
          case 35:
          case 36:
          case 37:
          case 39:
            return true;
          break;
          
      }

        return false;    
}


function InputMDNNumber(fld, ex)
{    
    var whichCode = (window.Event) ? ex.which : ex.keyCode;
    var strCheck = '0123456789';
	var shiftPressed=0;
	var ctrlPressed=0;
    shiftPressed = ex.shiftKey;
    ctrlPressed = ex.ctrlKey;

	 if (whichCode >= 96 && whichCode <= 105) 
	        whichCode -= 48; //update for numeric keypad entry

    if ((shiftPressed) && (whichCode == 48 || whichCode==57 || whichCode==9)){ // "(" or ")"
        return true;
    }
    
    if ((shiftPressed) && (navigation(whichCode))) return true;
    
    if (shiftPressed) return false;

    if ((ctrlPressed) && (whichCode = 67)) return true;       // allow CTRL C
    
    if (ctrlPressed) return false;
    
    if (navigation(whichCode) == true) return true;
 
    if (whichCode == 13) {
		return true;  // Delete (Bug fixed)
	}
	
    if (whichCode == 8 || whichCode == 9 || whichCode == 46) { 
        iDeleteMode  = 1;
		return true;  // Enter
    }
    
   
    key = String.fromCharCode(whichCode);  // Get key value from key cod
    if (strCheck.indexOf(key) != -1) {
            return true;  // Found in    our list.
    }

	if (whichCode == 189) return true;  // "-" key.
	
    return false;
}




function formatMDNOnKeyUp(fld){
    strval = fld.value;
    if (strval.length > 9) 
    {
        iDeleteMode  = 0;
        return;
    }
     
    strval = strval.replace("(","");
    strval = strval.replace(")","");
    strval = strval.replace("-","");
    strval = strval.replace(" ","");
    strval = strval.replace(")","");
   
    if (iDeleteMode  == 0)
    {
        if (strval.length == 10) 
        {
            fld.value = "("+strval.substr(0,3)+") "+strval.substr(3,3)+"-"+strval.substr(6);
            return;
        }
        if ( (strval.length == 3) /* || (strval.length == 4 )*/ )
        {
            fld.value = "("+strval.substr(0,3)+")";
            return;
        }
        if ( (strval.length >= 3) && (strval.length <6 )/* || (strval.length == 4 )*/ )
        {
            fld.value = "("+strval.substr(0,3)+")"+strval.substr(3);
            return;
        }

        if (strval.length >= 6)
        {
            fld.value = "("+strval.substr(0,3)+")"+strval.substr(3,3)+"-";
            return;
        }
    }
}



function CheckPhone(sender, args)
{

    var theString = args.Value;// same as: var theString = document.forms[0].TextBox2.value;
    var newString = "";
    var myString = theString;
    var theLen = myString.length;
    for ( var i =0; i< theLen; i++ )
    {
      if ( (myString.charCodeAt(i) >= 48 ) && (myString.charCodeAt(i) <= 57) )
      newString = newString + myString.charAt(i);   
    }
    
     

// Now the validation to determine that the remaining string is 10 characters.
 if (newString.length <= 10 )
 {
// reformat to ###-##-#### 
      var newLen = newString.length;
      var newPhone = "(";
      for ( var i = 0 ; i < newLen ; i++ )
      {
           if (  i == 2 )
           {
                newPhone = newPhone + newString.charAt(i) + ")";
           }
           else
           {
               if  ( i == 5 ) 
               {
                    newPhone = newPhone + newString.charAt(i) + "-";
               }
               else
               {
                    newPhone = newPhone + newString.charAt(i);
               }
           }
      }
      
      //sender.ControlToValidate.Text = newPhone;
      //txtMDN.value = newPhone;
      //document.getElementById(document.getElementById(hiddenField)).value = newPhone;
      //mdn.value = newPhone;
      //source.Value = newPhone;
 }
 if (newString.length == 10 )
 {
      args.IsValid = true;
 }else{
      //alert("The phone number you entered "+newString+" does not contain the correct number of digits");
      args.IsValid = false;
 }
}
var iDeleteMode = 0;
function fieldChange(fld)
{
  iDeleteMode  = 0;
  reformatMDN(fld);
}

function EPReadInputAndBackSpace(fld, e){
    var whichCode = (window.Event) ? e.which : e.keyCode;

	//if(whichCode==8 && document.getElementById(EPrbManualID).value == "false")//backspace.  Allow if only swiped, otherwise manual mode takes a normal backspace.  BS 02/04/2007
	if(whichCode==8)
	{
	    
	    document.getElementById(EPtxtPin).value = "";
	    document.getElementById(EPtxtPin).focus();
		entPerUseManual = -1;
		
		//document.getElementById(EPrbManualID).value = "false";
		//document.getElementById(EPrbSwipedID).value = "false";
		EPResetVars();
		return false;
	}
	else if(whichCode == 8){
	    return true;
	}
	else if (whichCode == 13){
	    return false;
	}
	else{
        return EPReadInput(fld,e);
    }
    
}

function EPBackSpace(e){

	var whichCode = (window.Event) ? e.which : e.keyCode;
//	debug("EPBackSpace - "+whichCode);

	//if(whichCode==8 && document.getElementById(EPrbManualID).value == "false")//backspace.  Allow if only swiped, otherwise manual mode takes a normal backspace.  BS 02/04/2007
	if(whichCode==8)
	{
	    
	    document.getElementById(EPtxtPin).value = "";
	    document.getElementById(EPtxtPin).focus();
		entPerUseManual = -1;
		
		//document.getElementById(EPrbManualID).value = "false";
		//document.getElementById(EPrbSwipedID).value = "false";
		EPResetVars();
		return false;
	}
	else if (whichCode == 13){
	    return false;
	}
	else return true;
}

function EPResetVars() {
    if (document.getElementById(EPtxtPin).value == "")
    {
//        debug("EPResetVars called" );
	    entPerCurrentChar = 0;
	    entPerlastChar = 0;
	    entPerPercBFound = false;
	    entPerEndFound = false;
	    entPerUseManual = -1;
    }
}

function EPReadInput(fld, e) {
    
	var whichCode = (window.Event) ? e.which : e.keyCode;
	
	entPerlastChar = entPerCurrentChar;
	entPerCurrentChar = whichCode;
//    debug("Read Input -- "+whichCode);
	if (entPerUseManual != 0 && entPerCurrentChar != 37 && entPerlastChar != 37 && fld.value.length == 0) {
		// manual
		//isEPSwiped(false);
		entPerUseManual = 1;
		document.getElementById(EPtxtPin).value = "";
//		debug("Read Manual Mode Set");
		//return false; // Fall though to below.  BS 02/04/2007
	}
	else
	if (entPerUseManual != 0 && entPerCurrentChar == 66) {
		// swiped
		//isEPSwiped(true);

		entPerUseManual = 0;
		entPerPercBFound = true;
		document.getElementById(EPtxtPin).value = "";
//		debug("Read Swiped Mode Set");
		return false;
	}

	if (entPerUseManual == 1){ //|| 
//	    (document.getElementById(EPrbManualID).value == "false" &&
//	     document.getElementById(EPrbSwipedID).value == "false") ){
//	{     
	     //isEPSwiped(false);
//	     debug("Read Manual -- "+whichCode);
		return EPReadManual(fld, e);
	}
	else if (entPerUseManual == 0) {
//	    debug("Read Swiped -- "+whichCode);
	    if (document.getElementById(EPtxtPin).value == "B")
	        document.getElementById(EPtxtPin).value = "";
		return EPReadSwiped(whichCode);
	}
	
}

function EPReadManual(fld, e) {
    var whichCode = (window.Event) ? e.which : e.keyCode;
    var valid 	= "0123456789";
//    var txtFVal = document.getElementById(EPtxtStoredCardID).value;
    if (inputIsNumeric(e) == true) // BS 02/04/2007
    {
//        debug("input is numeric ");
        return true;
    }
    else
    {
//        debug("input is NOT numeric " );
        return false;
    }
    
	return false;
}


function EPReadSwiped(whichCode) {
//   debug("read swiped");
	if (whichCode == 13) {
		return false;  // Enter
	}
	if (whichCode == 94) { // ^
		entPerEndFound = true;
		return false;
	}

	if (entPerPercBFound == true && entPerEndFound == false) {
//	    debug("* ReadSwiped - "+whichCode);
	    return true;
	} else {
		return false;
	}
}

function validatePIN(fld,e)
{
    var isNS4 = (navigator.appName=="Netscape")?1:0;
	var whichCode = (window.Event) ? e.which : e.keyCode;
	
	if(!isNS4)
    {
        if( (whichCode == 65 || whichCode == 97) && (fld.value).length < 1) return true;
        else if(whichCode < 45 || whichCode > 57 ) event.returnValue = false;
    }
    else
    {
        if( (whichCode == 65 || whichCode == 97) ) return true;
        else if(whichCode < 45 || whichCode > 57 ) event.returnValue = false;
    }   
}

function formatPIN(fld,e)
{
    if( (fld.value).charAt(0) == 'a' )
    {
        fld.value = (fld.value).charAt(0).toUpperCase()+(fld.value).substr(1,(fld.value).length);
    }
}