function isValideEmail(ele , alertId){
  
  var addr = ele.value;
  var pattern = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
  var atPos = addr.indexOf('@',0);  
  var suffix = addr.substring(addr.lastIndexOf('.')+1);
  
  if (ele.value.trim() == '') {
    initErrorMsg(ele, 'on', alertId, 'email address is mandatory');
    return false;
  }   
  else{
    initErrorMsg(ele, 'off', alertId);
    return true;
  }  
  
}
function isValidEmail(ele , alertId){

  //var emailReg = [a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?;
  var addr = ele.value;
  var pattern = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
  var atPos = addr.indexOf('@',0);  
  var suffix = addr.substring(addr.lastIndexOf('.')+1);
  
  for (i=0; i<invalidChars.length; i++) {
    if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
      initErrorMsg(ele, 'on', alertId, 'email address contains invalid characters');
      return false;
    }
  }
  for (i=0; i<addr.length; i++) {
    if (addr.charCodeAt(i)>127) {
      initErrorMsg(ele, 'on', alertId, 'email address contains non ascii characters.');
      return false;
    }
  }  
  if (addr == '') {
    initErrorMsg(ele, 'on', alertId, 'email address is mandatory');
    return false;
  }  
  else if (atPos == -1) {
    initErrorMsg(ele, 'on', alertId, 'email address must contain an @.');
    return false;
  }
  else if (atPos == 0) {
    initErrorMsg(ele, 'on', alertId, 'email address must not start with @.');
    return false;
  }
  else if (addr.indexOf('@', atPos + 1) > - 1) {
    initErrorMsg(ele, 'on', alertId, 'email address must contain only one @');
    return false;
  }
  else if (addr.indexOf('.', atPos) == -1) {
    initErrorMsg(ele, 'on', alertId, 'period required in the domain name.');
    return false;
  }
  else if (addr.indexOf('@.',0) != -1) {
    initErrorMsg(ele, 'on', alertId, 'period must not immediately follow @ in email address.');
    return false;
  }
  else if (addr.indexOf('.@',0) != -1){
    initErrorMsg(ele, 'on', alertId, 'period must not immediately precede @ in email address.');
    return false;
  }
  else if (addr.indexOf('..',0) != -1) {
    initErrorMsg(ele, 'on', alertId, 'two periods must not be adjacent in email address.');
    return false;
  } 
  else if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
    initErrorMsg(ele, 'on', alertId, 'primary domain in email address required.');
    return false;
  }
  else{
    initErrorMsg(ele, 'off', alertId);
    return true;
  }  
}

function isValidName(ele, alertId){
  //var nameId = (ele.id == 'name_last')? 'alertName_l' : 'alertName';
  var reg =/[0-9\-\(\)\~\@\#\%\&\*\_\-\+\=\!]/gi;;
  if(ele.value.match(reg)){
	initErrorMsg(ele, 'on', alertId, alertMsg.name.invalid);
    return false;
  }
  if(ele.value == ''){
    initErrorMsg(ele, 'on', alertId, alertMsg.name.blank);
    return false;
  }
  else if(!(isNaN(ele.value))){
    initErrorMsg(ele, 'on', alertId, alertMsg.name.invalid);
    return false;
  }
  else{
    initErrorMsg(ele, 'off', alertId);
    return true;
  }  
}
function isValidTelNo(ele, alertId , type){  
  if(ele.value.trim() == ""){
    initErrorMsg(ele, 'on', alertId, type+" number is required");
    return false;
  }  
  else if(ele.value.search(/[^0-9\-()+]/g) != -1 ){
    initErrorMsg(ele, 'on', alertId, "Please enter a valid "+type+" number");
    return false;
  }
  else if(ele.value.trim().length < 10){
    initErrorMsg(ele, 'on', alertId, 'Number should not be less than 10 digits.');
    return false;
  }
  else{
    initErrorMsg(ele, 'off', alertId);
    return true;
  }
  
}

function isValidDate(ele, id, type){
  ele.dataType = "date";
  if(ele.value.trim() == ""){
    initErrorMsg(ele, 'on', id, type+" is required" );
    return false;
  }
  else{
    initErrorMsg(ele, 'off', id);
    return true;
  }
}
function isRequired(ele, id, type){
  if(ele.value.trim() == ""){
    initErrorMsg(ele, 'on', id, type+" is required" );
    return false;
  }
  else{
    initErrorMsg(ele, 'off', id);
    return true;
  }
}

function isValidPin(ele, alertId){  
  if(ele.value.trim() == ""){
    initErrorMsg(ele, 'on', alertId, "Pin code is required");
    return false;
  }  
  else if(ele.value.search(/[^0-9\-()+]/g) != -1 ){
    initErrorMsg(ele, 'on', alertId, "Pin code must be in numbers");
    return false;
  }
  else if(ele.value.trim().length!=6){
    initErrorMsg(ele, 'on', alertId, 'Pin code must be 6 digits');
    return false;
  }
  else{
    initErrorMsg(ele, 'off', alertId);
    return true;
  }
  
}

if(typeof String.prototype.trim !== 'function') {
  String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, ''); 
  }
}
