//*********************************** Check Null ******************************
function chknull(txtbox, txtname)
{
  if (txtbox.value == '')
  {
    alert(txtname);
    txtbox.focus();
    return false;	
  }else{
	if (!chkonlyspaces(txtbox, txtname)) return false;	
  }	

  return true;
}

///////////////////////////////////////////////////////////////////////////////////////////
//Function to chk text number and spaces
//Params --> Object,Object value length,Object Label
function chkonlyspaces(txtbox,txtname){
  var spaceCounter = 0;
	
  if (txtbox.value.length > 0) {
    for (i=0;i<txtbox.value.length;i++){
      if(txtbox.value.charAt(i)==' '){
		spaceCounter++;
      }	  
    }	
    if(spaceCounter == txtbox.value.length){
	alert("Only Spaces are not allowed in "+txtname+".");
	txtbox.focus();
	return false;
    }	
  }         
  return true;
}

//********************* Authenticate Email Address ******************************

function chkemail(txtbox, txtlen, txtname)
{

/*  if (!chknull(txtbox, txtname)) return false;

  if(txtbox.value.indexOf('@') == -1 || txtbox.value.indexOf('.') == -1 ) 
  {
    alert("Please enter valid email address.");
    txtbox.focus();
    return false;	
  }	

  return true;*/

  if(!emailCheck(txtbox.value)) 
  {
    alert("Please enter valid email address.");
    txtbox.focus();
    return false;	
  }	

  return true;
}

function chkmax(txtbox, txtlen, txtname)
{
  if (txtbox.value.length > txtlen)
  {
    alert('Please limit ' + txtname + ' to only ' + txtlen + ' characters.')
    txtbox.focus();
    return false;
  }
  return true;
}

function emailCheck(str) {

             var at="@"

             var dot="."

             var lat=str.indexOf(at)

             var lstr=str.length

             var ldot=str.indexOf(dot)

            

             // Check If the @ sign is present in Email, invalid if not present ...

             if (str.indexOf(at)==-1){

               return false

             }

 

            // Check If the @ sign is first or last character of Email, invalid if it is first or last ...

             if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr-1){

                return false

             }

 

             // Check If the Dot '.' is present in the Email and is first or last character

             // invalid if not present and Invalid if first or last character ...

             if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot,lstr-1)==lstr-1){

                 return false

             }

 

             // Check If the @ sign is used more than once in Email ...

             // Invalid if used more than once .

              if (str.indexOf(at,(lat+1))!=-1){

                  return false

              }

 

             // Check If the '.' appears just before or after '@' sign, than that is Invalid ...

              if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

                  return false

              }

 

             // Check If the '.' exists after '@' sign (with 1 char gap), Invalid if it does not ...

              if (str.indexOf(dot,(lat+2))==-1){

                 return false

              }

  

              // Check If there is any space in the Email, than that is Invalid ....

              if (str.indexOf(" ")!=-1){

                 return false

              }

 
   return true     

}