var controlFlag;
var respc = /^[\s]+$/;
var whitespace = " \t";

//alert messages
var alertMsg="";
var alertEmpty="The following fields are mandatory\n\n";
var alertAlpha="The following fields have to be in alphabets\n\n";
var alertNumeric="The following fields have to be numeral\n\n";
var alertAlphanumeric="The following field has to be alphanumeric\n\n";
var alertEmail="The Email Id for the following field is not proper\n\n"
var alertEnd="\nPlease re enter and submit the form";
var retFlag=true;
var re = /\s/g; 

function isEmpty(formObj)
{		
   var reWhitespace = /^\s+$/
   var s=formObj.value;
   if ((s == null) || (s.length == 0) || (reWhitespace.test(s)) )
      return false;
   else
       return true;
}//function isEmpty(formObj)


function isAlphaNumeric(formObj)
{
   var objValk = trimtxt(formObj)

   if (respc.test(formObj.value) == true)
	return false;
	
   formObj.value = objValk;
   var testChar  = " ";
   var objVal 	 = objValk;
   var valLength = objVal.length;
	
   if (objVal == "")
     return true;
	
   for (var i=0; i < valLength; i++)
    {
     testChar = objVal.charAt(i);
     if ( (testChar < '0' || testChar > '9') && (testChar < 'a' || testChar > 'z') && (testChar < 'A' || testChar > 'Z') && (whitespace.indexOf(testChar) == -1))
	return false;
     }//for (var i=0; i < valLength; i++)
	
  return true;
}//function isAlphaNumeric(formObj)


function isAlpha(formObj)
{

   var objValm =trimtxt(formObj);   	

   if (respc.test(formObj.value) == true)
      return false;

   formObj.value = objValm;
   var testChar  = " ";
   var objVal    = objValm;
   var valLength = objVal.length;
	
   if (objVal == "")
     return true;
	
   for (var i=0; i < valLength; i++)
    {
    testChar = objVal.charAt(i);
		
    if ((testChar < 'a' || testChar > 'z') && (testChar < 'A' || testChar > 'Z') && (testChar.indexOf(" ")<=-1))
			return false;
    }//for (var i=0; i < valLength; i++)
	
 return true;
}//function isAlpha(formObj)


function isNumeric(formObj)
{

   var testChar  = " ";
   var objVal    = formObj.value;
   var valLength = objVal.length;
   
   for (var i=0; i < valLength; i++)
    {
    testChar = objVal.charAt(i);
    if (testChar < '0' || testChar > '9') 
	return false;
    }//for (var i=0; i < valLength; i++)
	
  return true;
}//function isNumber(formObj)

function isEmail(s)
{
   if(!isEmpty(s))
	return true;

	var x = s.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	else return false;
}


function isWhitespace (s)
{
  var i;

  if (!isEmpty(s))
    return true;

  for (i = 0; i < s.length; i++)
  {   
    var c = s.charAt(i);
    if (whitespace.indexOf(c) == -1) 
      return false;
  }//for (i = 0; i < s.length; i++)

  return true;
}//function isWhitespace (s)

function trimtxt(formobj)
 {
   var txtval = formobj.value;
   var txtlen = txtval.length;
   var firstindex = -1;
   var lastindex = -1;
   var finaltxt = "";
		
   for (i=0;i<txtlen;i++)
   {
   if (txtval.charAt(i) == " ")
	continue ;
   else
     { 
       firstindex = i;
       break;
     }//else
   }//for (i=0;i<txtlen;i++)
		
   for (i=txtlen-1;i>=0;i--)
   {
    if (txtval.charAt(i) == " ")
	continue ;
    else
     { 
	lastindex = i;
	break;
     }//else
   }//for (i=txtlen-1;i>=0;i--)

   if (firstindex < 0 && lastindex < 0)
	 return "";
	
   finaltxt = txtval.substring(firstindex,lastindex+1); 
	 return finaltxt;

}//function trimtxt(formobj)

function initializeControl()
{
  controlFlag=false;
}//function initializeControl()

function checkingControl()
{
  if(!controlFlag)
  {
    controlFlag=true;
    return true;
  }//if(!controlFlag)
  else
  {
	alert("You can perform this operation only once.");
	return false;
  }//else
}//function checkingControl()
