// Trim function to trim the leading and trailing spaces. 
function trim(l_str)
{
   var l_str_string = new String(l_str); // local variable to store the string
   var l_int_length = l_str_string . length; // local variable to store the length of string
   var l_str_temp = new String(''); // local variable to store the string
   var l_b_flag = true; // local variable to store the boolean value

   for(l_int_i = 0; l_int_i <= l_int_length - 1; ++l_int_i) // start of for loop to check for space from first
   {
      if (l_b_flag == true && l_str_string.charAt(l_int_i) == ' ') // checks for space
      {
         l_b_flag = true;
      } // end of check space if
      else
      {
         l_b_flag = false;
         l_str_temp = l_str_string.substring(l_int_i);
         break;
      } // end of check space else
      if (l_int_i == l_int_length - 1) // checks for length
      {
         return l_str_temp;
      } // end of length check if
   } // end of chack space from first for loop

   l_int_length = l_str_temp.length;
   l_b_flag = true;
   
   for(l_int_i = l_int_length - 1; l_int_i >= 0; l_int_i--) // start of for loop to check for space from the last
   {
      if (l_b_flag == true && l_str_temp.charAt(l_int_i) == ' ') // check for space
      {
         l_b_flag = true;
      } // end of check space if
      else
      {
         l_b_flag = false;
         l_str_string = l_str_temp.substring(0, l_int_i + 1);
         break;
      } // end of check space else
   } // end of chack space from last for loop
   return l_str_string;
} // end of trim function

// Fuction which returns false if the passed control has null value (this calls trim function internally)
function checkNotNull(l_frm_control)
{
   var l_str_string = trim(l_frm_control.value); // local variable to store the string
   l_frm_control.value = l_str_string;

   if (l_str_string.length == 0) // check for length of the string
   {
      alert(TXT_Var46125);
      l_frm_control.select();
      l_frm_control.focus();
      return false;
   } // end of check for length if
   return true;
} // end of checkNotNull function



// function returns true/false
function checkEmail(l_frm_control)
{
   var l_str_string = ""; // local variable to store the string
   var l_int_length = -1; // local variable to store the length of string

   l_str_string = trim(l_frm_control.value);
   l_int_length = l_str_string.length;
   if(l_str_string.match(/[^-_.@a-z0-9A-Z]/))
   {
      alert(TXT_Var46126)
      l_frm_control.select();
      l_frm_control.focus();
      return false; 
   }
   if (l_str_string.indexOf('@') == -1) // checks for '@' character
   {
      alert(TXT_Var46127);
      l_frm_control.select();
      l_frm_control.focus();
      return false;
   } // end of '@' character check if
   else
   {
      if (!(l_str_string.substring(l_str_string.indexOf('@') + 1).indexOf('@') == -1))
      { // checks for the consecutive '@' character
         alert(TXT_Var46128);
         l_frm_control.select();
         l_frm_control.focus();
         return false;
      } // end of consecutive '@' character check if
   } // end of '@' character check else
   if (l_str_string.substring(l_str_string.indexOf('@') + 1).indexOf('.') == -1)
   { // checks for dot operatore
      alert(TXT_Var46129);
      l_frm_control.select();
      l_frm_control.focus();
      return false;
   } // end of dot operator
   for(l_int_i = 0; l_int_i < l_int_length; l_int_i++) // start of for loop
   {

       // checks for allowed characters
      if (l_str_string.charAt(l_int_i) == '@' || l_str_string.charAt(l_int_i) == '_' || l_str_string.charAt(l_int_i) == '-' ||l_str_string.charAt(l_int_i) == '.')
      {
         // checks for allowed consecutive character
         if (!(((l_str_string.charCodeAt(l_int_i + 1) >= 97 && l_str_string.charCodeAt(l_int_i + 1) < 123) ||  (l_str_string.charCodeAt(l_int_i + 1) >= 65 && l_str_string.charCodeAt(l_int_i + 1) < 91) || (l_str_string.charCodeAt(l_int_i + 1) >= 48 && l_str_string.charCodeAt(l_int_i + 1) <= 57)) && ((l_str_string.charCodeAt(l_int_i - 1) >= 97 && l_str_string.charCodeAt(l_int_i - 1) < 123) ||  (l_str_string.charCodeAt(l_int_i - 1) >= 65 && l_str_string.charCodeAt(l_int_i - 1) < 91) || (l_str_string.charCodeAt(l_int_i - 1) >= 48 && l_str_string.charCodeAt(l_int_i - 1) <= 57))))
         {
            alert(TXT_Var46129);
            l_frm_control.select();
            l_frm_control.focus();
            return false;
         } // end of allowed conscutive character if
      } // end of allowed character if    
   } // end of for loop

return true;
} // end of checkEmail function


// function returns true/false
function checkName(l_frm_control)
{
   var l_str_string = "" ; // local variable to store the string
   var l_int_length = -1; // local variable to store the length of string


   if (checkNotNull(l_frm_control) == false) // check for not null function
   {
      return false;
   } // end of checknotnull if

   l_str_string = l_frm_control.value;
   l_int_length = l_str_string.length;

   if(l_str_string.match(/[^ .a-zA-Z]/))   //for checking the allowed chars
   {
      alert(TXT_Var46131);
      l_frm_control.select();
      l_frm_control.focus();
      return false;      
   }


   for(l_int_i = 0; l_int_i < l_int_length; l_int_i++) // start of for loop
   {
      // checks for allowed special character if
      if (l_str_string.charAt(l_int_i) == ' ' || l_str_string.charAt(l_int_i) == '.')
      {
         // checks for allowed consecutive characters
         if (!(((l_str_string.charCodeAt(l_int_i + 1) >= 97 && l_str_string.charCodeAt(l_int_i + 1) < 123) ||  (l_str_string.charCodeAt(l_int_i + 1) >= 65 && l_str_string.charCodeAt(l_int_i + 1) < 91)) && ((l_str_string.charCodeAt(l_int_i - 1) >= 97 && l_str_string.charCodeAt(l_int_i - 1) < 123) ||  (l_str_string.charCodeAt(l_int_i - 1) >= 65 && l_str_string.charCodeAt(l_int_i - 1) < 91))))
         {
            alert(TXT_Var46132);
            l_frm_control.select();
            l_frm_control.focus();
            return false;
         } // end of allowed consecutive charater if
      } // end of allowed special charater if
      
   } // end of for loop

   return true;
} // end of checkName function



function validateFrm(formname)
{
	//alert(display);
	if(display)
	{
	var name = eval(eval(formname).txt_name);
	//alert(name);
	var email = eval(eval(formname).txt_email);
	//alert(email);
	if(!checkNotNull(name)) return false;
	//if(!checkName(name)) return false;
	if(!checkNotNull(email)) return false;
	if(!checkEmail(email)) return false;
	
	var temp =eval(formname);
	var inner_window_width=250;
	var inner_window_height=100;
	var shell_window_top=(window.screen.availHeight/2)-(inner_window_height/2);
	var shell_window_left=(window.screen.availWidth/2)-(inner_window_width/2);

	temp.target="Mail";
	temp.method="POST";
	window.open('', 'Mail','top='+shell_window_top+',left='+shell_window_left+',width=430, height=140, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, copyhistory=no, resizable=no');
	
	temp.submit();
	}
	else
	{
		alert(TXT_Var46133);
		return false;
	}
}