//Check For The Field Is Emptyfunction isText(str) {
  return (str != "");
}
//Check For The Character 
function isAlpha(str) {
   patAlpha = /^[A-Za-z]+$/;
   return patAlpha.test(str);
}
//Check For The Character And Allow Space function isAlphaWithSpace(str) {
   patAlpha = /^[A-Za-z ]+$/;
   return patAlpha.test(str);
}
//Check For The Character with some special character
function isAlphaSplChar(str) {
   patAlphaSplChar = /^[A-Za-z#,'\.\\\/\s]+$/;
   return patAlphaSplChar.test(str);
}//Check For The Character with some special character
function isAlphaWithComma(str) {
   patAlphaSplChar = /^[A-Za-z, ]+$/;
   return patAlphaSplChar.test(str);
}
//Check For The AlphaNumeric
function isAphaNumeric(str) {
   patAlphaNumeric = /^[A-Za-z0-9]+$/;
   return patAlphaNumeric.test(str) && str != "0";
}
//Check For The Numeric With Some Special Characterfunction isNumericSplChar(str,zok) {
   patNumeric = /^[0-9-()/]+$/;
	if(zok){
		return patNumeric.test(str)
	} else {
		return patNumeric.test(str) && str != 0;
	}	
}
//Check For The AlphaNumeric with som special Character
function isAphaNumericSplChar(str) {
   patAlphaNumericSplChar = /^[A-Za-z0-9#,'\.\\\/\s]+$/;
   return patAlphaNumericSplChar.test(str) && str != "0";
}
//Check For The Number to allow Zero pass true as second parameter
// zok - This parameter has to be set to true if "Zero" is to be allowed 
// in the validated field.
function isNumeric(str,zok) {
	patNumeric = /^[0-9]+$/;
	if(zok){
		return patNumeric.test(str)
	} else {
		return patNumeric.test(str) && str != 0;
	}	
}
//Check For The Predefined Pattern
function isPattern(str,pattern) {
   patGeneral = pattern;
   return patGeneral.test(str);
}
//Check For The price 
function isPrice(str) {
   patPrice = /^[ 0-9.\/]+$/
   return patPrice.test(str); //&& str != 0;   
}

//Check whether Form Listbox Has Been Selected
function isSelect(formObj) {
  return (formObj.selectedIndex != 0);
}
//Check whether Form Radiobox Has Been Selected
function isRadio(formObj) {
  for (j=0; j < formObj.length; j++) {
    if (formObj[j].checked) {
      return true;
    }
  }
  return false;
}

//Check From The list of checkbox one is selected
function isCheck(formObj, form, begin, num) {
  for (j=begin; j < begin+num; j++) {
    if (form.elements[j].checked) {
      return true;
    }
  }
  return false;
}
//Check For The Email
function isEmail(str) {
  return ((str != "") && (str.indexOf("@") != -1) && (str.indexOf(".") != -1));
}

function isState(str) {
  str = str.toUpperCase();
  return ( (str == "AK") || (str == "AL") || (str == "AR") || (str == "AZ") || (str == "CA") || (str == "CO") || (str == "CT") || (str == "DC") || (str == "DE") || (str == "FL") || (str == "GA") || (str == "HI") || (str == "IA") || (str == "ID") || (str == "IL") || (str == "IN") || (str == "KS") || (str == "KY") || (str == "LA") || (str == "MA") || (str == "MD") || (str == "ME") || (str == "MI") || (str == "MN") || (str == "MO") || (str == "MS") || (str == "MT") || (str == "NB") || (str == "NC") || (str == "ND") || (str == "NH") || (str == "NJ") || (str == "NM") || (str == "NV") || (str == "NY") || (str == "OH") || (str == "OK") || (str == "OR") || (str == "PA") || (str == "RI") || (str == "SC") || (str == "SD") || (str == "TN") || (str == "TX") || (str == "UT") || (str == "VA") || (str == "VT") || (str == "WA") || (str == "WI") || (str == "WV") || (str == "WY") );
}

function isZipCode(str) {
  var l = str.length;
  if ((l != 5) && (l != 10)) { return false }
  for (j=0; j< l; j++) {
    if ((l == 10) && (j == 5)) {
      if (str.charAt(j) != "-") { return false }
    } else {
      if ((str.charAt(j) < "0") || (str.charAt(j) >  "9")) { return false }
    }
  }
  return true;
}

function isPhoneNum(str) 
{
	// Counter to keep track of number of digits in the Phone Number string
	var numOfDigits = 0;
	
	// Define pattern to match only numbers
	var pattern = /[0-9]/; 
	
	for (j=0; j< str.length; j++) 
	{
	    if (pattern.test(str.charAt(j))) 
		{  
			numOfDigits++;	
		}
	}

	if(numOfDigits != 10)
	{
		return false;
	}
		
  return true;
}

function formatPhoneNumber(frmName,frmEleName)
{
	// Create a Form Object for the Given field
	frmObj = eval("document." + frmName + "." + frmEleName);
	
	// Store the phone number in temp string variable
	var str1 = frmObj.value;
	
	// Define pattern to match a single digit
	var pattern = /[0-9]/; 
		
	// Temp String to store only digits in the number entered
	var str2 = "";
		
	if(isPhoneNum(str1))
	{
		for (j=0; j< str1.length; j++) 
		{
			if (pattern.test(str1.charAt(j))) 
			{  
				str2 += str1.charAt(j);
			}
		}
		
		frmObj.value = "(" + str2.substring(0,3) + ") " + str2.substring(3,6) + " " + str2.substring(6,10);
	}
	else
	{
		alert(str1 + "is not a valid phone number");
		frmObj.focus();
		frmObj.select();
	}
	
	
	
}

function isDate(str) {
  if (str.length != 10) { return false }

  for (j=0; j< str.length; j++) {
    if ((j == 2) || (j == 5)) {
      if (str.charAt(j) != "/") { return false }
    } else {
      if ((str.charAt(j) < "0") || (str.charAt(j) >  "9")) { return false }
    }
  }

  var month = str.charAt(0) == "0" ? parseInt(str.substring(1,2)) : parseInt(str.substring(0,2));
  var day = str.charAt(3) == "0" ? parseInt(str.substring(4,5)) : parseInt(str.substring(3,5));
  var begin = str.charAt(6) == "0" ? (str.charAt(7) == "0" ? (str.charAt(8) == "0" ? 9 : 8) : 7) : 6;
  var year = parseInt(str.substring(begin, 10));

  if (day == 0) { return false }
  if (month == 0 || month >  12) { return false }
  if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
    if (day >  31) { return false }
  } else {
    if (month == 4 || month == 6 || month == 9 || month == 11) {
      if (day >  30) { return false }
    } else {
      if (year%4 != 0) {
        if (day >  28) { return false }
      } else {
        if (day >  29) { return false }
      }
    }
  }
  return true;
}
