//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function AllowPhoneNumberOnly(){
  var Expression = '0123456789-()';
  var ch = String.fromCharCode(window.event.keyCode);
  ch = ch.toLowerCase();
  var a = Expression.indexOf(ch);
  if (a == -1) {
    window.event.keyCode = 0;
  }
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function AllowDateOnly()  {
  var Expression = '0123456789-/';
  var ch = String.fromCharCode(window.event.keyCode);
  ch = ch.toLowerCase();
  var a = Expression.indexOf(ch);
  if (a == -1) {
    window.event.keyCode = 0;
  }
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function AllowNumericOnly(){
  var Expression = '0123456789';
  var ch = String.fromCharCode(window.event.keyCode);
  ch = ch.toLowerCase();
  var a = Expression.indexOf(ch);
  if (a == -1) {
    window.event.keyCode = 0;
  }
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function AllowCharOnly(){
  var Expression = 'abcdefghijklmnopqrstuvwxyz';
  var ch = String.fromCharCode(window.event.keyCode);
  ch = ch.toLowerCase();
  var a = Expression.indexOf(ch);
  if (a == -1) {
    window.event.keyCode = 0;
  }
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function SanitizeString(x, y)  {
  var txtX=document.getElementById(x.id);
	var strValue=txtX.value;
	//alert(strValue);

//	strValue = strValue.replace(/<script>document.write(unescape(/gi, "");
//	strValue = strValue.replace(/<script>document.write/gi, "");
//  strValue = replaceString(strValue, "document.write", "");
//  strValue = replaceString(strValue, "write", "");
//	strValue = strValue.replace(/</script>/gi, "");
//  strValue = replaceString(strValue, "unescape", "");
  //strValue = replaceString(strValue, "select", "");
	///microsoft/gi
	//  ---\select * from table; update table; // -- insert test SELECT write unescape <script>document.write(unescape(
  strValue = replaceString(strValue, "<script>document.write(unescape(", "");
  strValue = replaceString(strValue, "<script>document.write", "");
	strValue = strValue.replace(/document.write/gi, "");
	strValue = strValue.replace(/write/gi, "");
  strValue = replaceString(strValue, "<script>", "");
	strValue = strValue.replace(/unescape/gi, "");
  strValue = replaceString(strValue, "</script>", "");
	strValue = strValue.replace(/select/gi, "");
  strValue = replaceString(strValue, "insert", "");
  strValue = replaceString(strValue, "update", "");
  strValue = replaceString(strValue, "delete", "");
  strValue = replaceString(strValue, "create", "");
  strValue = replaceString(strValue, "drop", "");
  strValue = replaceString(strValue, "alter", "");
  strValue = replaceString(strValue, ";", "");
  strValue = replaceString(strValue, "*", "");
  strValue = replaceString(strValue, "'", "");
  strValue = replaceString(strValue, "/", "");
//  strValue = replaceString(strValue, "\", "");
//	strValue = strValue.replace(/\/gi, "");
  strValue = replaceString(strValue, ":", "");
  strValue = replaceString(strValue, "+", "");
  strValue = replaceString(strValue, "--", "");
  strValue = replaceString(strValue, "=", "");
  strValue = replaceString(strValue, "<", "");
  strValue = replaceString(strValue, ">", "");
  strValue = replaceString(strValue, "(", "");
  strValue = replaceString(strValue, ")", "");
  strValue = replaceString(strValue, "{", "");
  strValue = replaceString(strValue, "}", "");
	
	switch(y)
  {
  case 0:
    break;    
  case 1:
    strValue = replaceString(strValue, ".", "");
    break;
  default:
  }

  txtX.value = strValue;
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function SanitizeValueOrig(x)  {
  var txtX=document.getElementById(x.id);
	var strValue=txtX.value;
	//alert(strValue);

  strValue = replaceString(strValue, "<script>document.write(unescape(", "");
  strValue = replaceString(strValue, "<script>document.write", "");
  strValue = replaceString(strValue, "document.write", "");
  strValue = replaceString(strValue, "write", "");
  strValue = replaceString(strValue, "<script>", "");

  strValue = replaceString(strValue, "unescape", "");
  strValue = replaceString(strValue, "</script>", "");
  strValue = replaceString(strValue, "select", "");
  strValue = replaceString(strValue, "insert", "");
  strValue = replaceString(strValue, "update", "");
  strValue = replaceString(strValue, "delete", "");
  strValue = replaceString(strValue, "create", "");
  strValue = replaceString(strValue, "drop", "");
  strValue = replaceString(strValue, "alter", "");
  strValue = replaceString(strValue, ";", "");
  strValue = replaceString(strValue, "*", "");
  strValue = replaceString(strValue, "'", "");
  strValue = replaceString(strValue, "/", "");
//  strValue = replaceString(strValue, "\", "");
  strValue = replaceString(strValue, ":", "");
  strValue = replaceString(strValue, "+", "");
  strValue = replaceString(strValue, "--", "");
  strValue = replaceString(strValue, "=", "");
  strValue = replaceString(strValue, "<", "");
  strValue = replaceString(strValue, ">", "");
  strValue = replaceString(strValue, "(", "");
  strValue = replaceString(strValue, ")", "");
  strValue = replaceString(strValue, "{", "");
  strValue = replaceString(strValue, "}", "");
  strValue = replaceString(strValue, ".", "");

  txtX.value = strValue;
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function replaceString(fullS, oldS, newS) {
// Replaces oldS with newS in the string fullS
//   for (var i=0; i<fullS.length; i++)  {
  for (var i=fullS.length; i>=0; i--)  {
    if (fullS.substring(i,i+oldS.length) == oldS) {
      fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length);
    }   
  }   
  return fullS;
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function AllowNumericOnly2(x)  {
  var strExpression = '0123456789';
  var txtX=document.getElementById(x.id);
	var strValue=txtX.value;
	var intIndex;
	var ch;
	var strValue2 = "";

  for (var i=strValue.length-1; i>=0; i--)  {
	  ch = strValue.substr(i, 1);
    //alert(ch);
    intIndex = strExpression.indexOf(ch);
    if (intIndex != -1) {
      strValue2 = ch + strValue2;
    }   
  }   
  if (strValue2.length != 0)  {
    txtX.value = strValue2;
  }  else  {
    txtX.value = '';
  }
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function AllowNumericOnly2a(x)  {
  // could not get this to work properly
	// would return each valid value separated by a commas
	
  var txtX=document.getElementById(x.id);
	var strValue=txtX.value;
  var patt1 = new RegExp("[0123456789]","g");
  
  var result = strValue.match(patt1);
	
	//result.replace(",", "");
	alert(result);
  if (result != null)  {
	  txtX.value=result;
	}  else  {
	  txtX.value="";
	}
}
