function isValidDate (theElement,fieldName) { 
  var DayArray =new Array(31,28,31,30,31,30,31,31,30,31,30,31); 
  var MonthArray = new Array("01","02","03","04","05","06","07","08","09","10","11","12"); 
  var thisYear = null; 
  var thisMon = null; 
  var thisDay = null; 
  var today = null; 
  inpDate = theElement.value; 
  if (inpDate.length == 0 ) return true; 
  thisDay = inpDate.substr(0,2); 
  thisMonth = inpDate.substr(3,2); 
  thisYear = inpDate.substr(6,4); 
  var filter=/^[0-9]{2}-[0-9]{2}-[0-9]{4}$/; 
  if (! filter.test(inpDate)) {    
       alert(fieldName + ": Please enter Date in DD-MM-YYYY Format !"); 
       theElement.focus();  
       return false;  
  }  
  var filter=/01|02|03|04|05|06|07|08|09|10|11|12/ ; 
  if (! filter.test(thisMonth)) { 
     alert(fieldName + ": Please enter the Correct Month !"); 
     theElement.focus();  
     return false; 
  } 
  N=Number(thisYear); 
  if ( ( N%4==0 && N%100 !=0 ) || ( N%400==0 ) ) { 
    DayArray[1]=29;    
  } 
  for(var ctr=0; ctr<=11; ctr++) { 
    if (MonthArray[ctr]==thisMonth) { 
      if (thisDay<= DayArray[ctr] && thisDay >0 ) 
           return true; 
      else { 
           alert(fieldName + ": Please enter a valid Day !"); 
           theElement.focus();  
           return false;  
      } 
    } 
  } 
} 

function fieldNotNull( fieldObject, 
                       fieldName  ) { 
  if (fieldObject.value == "") { 
    alert(fieldName + " may not be left empty"); 
    fieldObject.focus(); 
    return false; 
  } else { 
    return true; 
  } 
} 

function ValidEmail(form){
  var field =form.p_email; // email field
  var str = field.value; // email string
  var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
  var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
  if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid
    return true;
  }
  alert(str + " is an invalid e-mail!");
  field.focus();
  field.select();
  return false;
}

function UpCase(object) {
  var charCode = event.keyCode;
  switch (charCode) {
    case 37:
    case 38:
    case 39:
    case 40:
      return;
      break;
    default:
      object.value = object.value.toUpperCase();
  }
}

function numbersOnly(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
    if ((charCode >= 48 && charCode <=57) || charCode == 8 || charCode == 9 || charCode == 13 || charCode == 46) {
      return(true);
    }
    else {
      return(false);
    }
} 

function checkLen(Target,StringMaxSize)
{
  StrLen = Target.value.length;
  if (StrLen > StringMaxSize)
  {
    Target.value = Target.value.substring(0,StringMaxSize);
  }
}
