//This function used to check validate numeric entryfunction validatedigit(fieldname,formname,fieldlabel)
{
    objname = "document." + formname + "." + fieldname;    obj = eval(objname);
    numvalue = obj.value;
    for (i = 0; i < numvalue.length; i++)
    {
        var c = numvalue.charAt(i);        if (!isdigit(c))
        {
            alert(fieldlabel+' - Invalid Number');
            obj.focus();
            obj.select();
            return false;
        }
    }
    return true;
}


//This function used to check alpha numeric chars
function validatealphanumeric(fieldname,formname,fieldlabel) {
  objname = "document." + formname + "." + fieldname;  obj = eval(objname);
  for (var i=0; i<obj.value.length; i++)
  {
	ch = obj.value.substr(i,1);
	if ( !( ( ch >= "a" &&  ch <= "z" ) ||  ( ch >= "A" &&  ch <= "Z" )  || ( ch >= "0" &&  ch <= "9" )))
	{
		alert(fieldlabel+' - Invalid entry');
		obj.focus();
		obj.select();
		return false;
	}
  }
  return true;

}


//This function does the mandatory check
function validatenull(fieldname,formname,fieldlabel)
{  objname = "document." + formname + "." + fieldname;  obj = eval(objname);  if(obj.type=='text' || obj.type=='textarea')  {
	if(jtrim(obj.value).length == 0)
	{
	  alert(fieldlabel + ' can not be blank');
	  obj.focus();
	  return false;
	}
	else
	  return true;  }  else if(obj.type=='select-one' || obj.type=='select-multiple')  {
	if(jtrim(obj.options[obj.selectedIndex].value).length == 0)
	{
	  alert(fieldlabel + ' can not be blank');
	  obj.focus();
	  return false;
	}
	else
	  return true;  }  else if(obj.type=='checkbox' || obj.type=='radio')  {
	if(obj.checked == false)
	{
	  alert(fieldlabel + ' should be selected');
	  obj.focus();
	  return false;
	}
	else
	  return true;  }
}

//This function does the array mandatory check
function validatearraynull(fieldname,cnt,formname,fieldlabel)
{	res = false;	if(cnt>1)
	{ 		for(i=0;i<cnt;i++)
		{			objname = 'document.' + formname + '.' + fieldname + '[' + i + ']';			obj = eval(objname);
			if(obj.type=='checkbox' || obj.type=='radio')
			{
				if(obj.checked == true)				{					res = true;
					break;				}			}
		}
	}
	else if(cnt==1)
	{		objname = 'document.' + formname + '.' + fieldname;
		obj = eval(objname);
		if(obj.type=='checkbox' || obj.type=='radio')
		{
			if(obj.checked == true)			{				res = true;
			}		}
	}	if(res == false && cnt > 0)
	{
	  alert(fieldlabel + ' should be selected');
	  return false;
	}
	else
	  return true;}

//This function checks for the maximum length
function chkmaxlength(fieldname,formname,textlen,fieldlabel)
 {
   objname = "document." + formname + "." + fieldname;   obj = eval(objname);
   val = obj.value;
   val=jtrim(val);
   if (val.length > Number(textlen))
   {
     alert (fieldlabel + ' should not exceed '+textlen+' characters. But you have entered '+val.length+' characters.');
     obj.focus();
     return false;
   }   else
     return true;
 }

//This function removes the trailing blank spacesfunction jtrim(str1)
{
  var i=0;
  l=str1.length;
  for(i=0;i<l;i++)
  {
     if(str1.charAt(i)!=" ")
     break;
  }
  return str1.substring(i,l);
}

//This function is being called from validatedigit fn. Used to determine the valid chars of a number field.
function isdigit (c)
{   	return (((c >= "0") && (c <= "9")) || (c == ".") || (c == ",") )
}
//This function used to check validate timefunction validatetime(fieldname,formname,fieldlabel)
{
    objname = "document." + formname + "." + fieldname;    obj = eval(objname);
    numvalue = obj.value;
    if(numvalue.length == 0)
		return true;    if(numvalue.length < 5)    {
        alert(fieldlabel+' - Invalid Time');
        obj.focus();
        obj.select();
        return false;
    }
    for (i = 0; i < numvalue.length; i++)
    {
        var c = numvalue.charAt(i);
        if(i!=2)
        {			if (!isinteger(c))
			{
			    alert(fieldlabel+' - Invalid Time');
			    obj.focus();
			    obj.select();
			    return false;
			}		} 		else 
		{			if(c != ":")			{
			    alert(fieldlabel+' - Invalid Time');
			    obj.focus();
			    obj.select();
			    return false;
			}		}		
    }
    return true;
}
//Function to check integers
function isinteger (c)
{   	return ((c >= "0") && (c <= "9"))
}
