var popUp; 

var keyNumberNonZero = new keybEdit('123456789');
var keyNumber = new keybEdit('01234567890');
var keyDecimal = new keybEdit('01234567890.-');
var keyDate = new keybEdit('01234567890/-.');
var keyPhoneFax = new keybEdit('01234567890(- )');
var keyAlphaNumeric = new keybEdit('abcdefghijklmnopqurstuvwxyz01234567890 ');
var keyAlphaLiteral = new keybEdit('abcdefghijklmnopqurstuvwxyz ');
var keyAlphaLiteralandSymbols = new keybEdit ('abcdefghijklmnopqurstuvwxyz01234567890 _-$+{}[]().');

function OpenCalendarCR(idname, postBack)
{var report= idname;
	popUp = window.open('CalendarCR.aspx?formname=' + document.forms[0].name + 
		'&id=' +report + '&selected=' + document.forms[0].elements[report].value + '&postBack=' + postBack, 
		'popupcal', 
		'width=165,height=208,left=200,top=250');
}

function SetDateCR(formName, id, newDate, postBack)
{
	eval('var theform = document.' + formName + ';');
	theform.elements[id].value = newDate;
	//CloseWindow();
	popUp.close();
	if (postBack)
		__doPostBack(id,'');
}


function OpenCalendar(idname, postBack)
{
	popUp = window.open('Calendar.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 
		'popupcal', 
		'width=165,height=208,left=200,top=250');
}

function SetDate(formName, id, newDate, postBack)
{
	eval('var theform = document.' + formName + ';');
	popUp.close();
	theform.elements[id].value = newDate;
	if (postBack)
		__doPostBack(id,'');
}		


//************ Text Input Formater ***********************************************
function keybEdit(strValid, strMsg) {
           
   //   Variables - Regular Expression
   //   /g - enables "global" matching. When using the replace() method, specify this modifier to replace all matches,
   //			rather than only the first one.      
   //   /i - makes the regex match case insensitive.     
   var reWork = new RegExp('[a-z]','gi');

   //   Properties
   if(reWork.test(strValid))
      this.valid = strValid.toLowerCase() + strValid.toUpperCase();
   else
      this.valid = strValid;

   if((strMsg == null) || (typeof(strMsg) == 'undefined'))
      this.message = '';
   else
      this.message = strMsg;

   //   Methods
   this.getValid = keybEditGetValid;
   this.getMessage = keybEditGetMessage;
   
   function keybEditGetValid() {
      return this.valid.toString();
   }
   
   function keybEditGetMessage() {
      return this.message;
   }
}

void function editKeyBoard(objForm, objKeyb) {

   strWork = objKeyb.getValid();
   strMsg = '';                     // Error message
   blnValidChar = false;               // Valid character flag

   // Part 1: Validate input
   if(!blnValidChar)
      for(i=0;i < strWork.length;i++)
         if(window.event.keyCode == strWork.charCodeAt(i)) {
            blnValidChar = true;

            break;
         }

   // Part 2: Build error message
   if(!blnValidChar) {
      if(objKeyb.getMessage().toString().length != 0)
         alert('Error: ' + objKeyb.getMessage());

      window.event.returnValue = false;      // Clear invalid character
      objForm.focus();                  // Set focus
   }
}
