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
  if (echeck(str)) { // if syntax is valid
    return true;
  }
  alert(str + " is an invalid e-mail!");
  field.focus();
  field.select();
  return false;
}

function ValidEmailField(field){
  var str = field.value; // email string
  if (echeck(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);
  }
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID 1")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID 2")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID 3")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID 4")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID 5")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

