//*********************************************************************
// File Name               : common_script.js
// Scope Of Program        : validation script for  blank, numeric,
//			     alpha-numeric,email id form field.
// Created On              : 10/03/2004
// Modified On             : 11/03/2004
// Reason of Modification  : Add date validation function
// Special Remark          :
//*********************************************************************

function isBlank(tmp_str)
{
// Name      : isBlank.

// Purpose   : keeping validation for blank field.

// Inputs    : tmp_str -> string for validation

// Outputs   : return the value of veriable newString.
//             if newString = "" returns null

var newString  = ''; //trim value of given string
var substring  = ''; // temporary string for checking white spaces in string.
beginningFound = false; // position of white space

// copy characters over to a new string
// retain whitespace characters if they are between other characters

for (var i = 0; i < tmp_str.length; i++)
 {
	// copy non-whitespace characters
	// hold whitespace characters in a temporary string if they follow a non-whitespace character

	if (tmp_str.charAt(i) != ' ' && tmp_str.charCodeAt(i) != 9)
	{
		// if the temporary string contains some whitespace characters, copy them first
		if (substring != '')
		{
			newString += substring;
			substring = '';
		}
		newString += tmp_str.charAt(i);
		 if (beginningFound == false)
		 {
		   beginningFound = true;
		 }
	}

	else if (beginningFound == true)
	{
	   substring += tmp_str.charAt(i);
	}
  }

  return newString;

}

 function isEmailId(tmp_str)
 {
   // Name      : isEmailId.
   // Purpose   : allow user to enter value in email id format(xxx@kk.com).
   // Inputs    : tmp_str -> string for validation.
   // Outputs   : return 1 -> if form field is as email id format.
   //		 return -1 -> if form field is not as email id format.


 //ignore validation if tmp_str is blank.

  if(tmp_str != "")
  {
     // searching whole string word by word

       if (tmp_str.search)
        {
          //checking the words in string.
          //  if given string is not in email id format(xxx@zzz.com), return -1.
          //  else return 1.

       	       fsign = tmp_str.indexOf("@");
       	       ssign = tmp_str.indexOf(".");

	       if(fsign <= 0 || ssign <= 0)
	       {
		     return -1;
	       }
        }
  }
  return 1;
 }

function validate_form(doc)
{
   str = "";
   tmp_str_Email = doc.frm_str_email.value;
   
   tmp_str_retblEmail = isBlank(tmp_str_Email);
          
          //if value of tmp_validate = "", sets the error message.
           if(tmp_str_retblEmail == "")
            {
              str += "Please enter E-mail Address \n";
            }
           else
           {
             tmp_str_retvlEmail = isEmailId(tmp_str_Email);
		if(tmp_str_retvlEmail == -1)
		 {
		   str += "Please enter valid E-mail Address \n";
                 }             
           }       

    if(str)
    {
      alert(str);
      return false
    }
 return true 
}