//*********************************************************************
// 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          :
//*********************************************************************

/********** date validate function begin here ***********/

// Pass formatdate as '%dd-%mm-%yyyy' or '%dd/%mm/%yyyy' or use following oparators as per requirement
// prefix '%' before followimg string oparators.

/* Here's the list of tokens we support:
   m (or M) : month number, one or two digits.
   mm (or MM) : month number, strictly two digits (i.e. April is 04).
   d (or D) : day number, one or two digits.
   dd (or DD) : day number, strictly two digits.
   y (or Y) : year, two or four digits.
   yy (or YY) : year, strictly two digits.
   yyyy (or YYYY) : year, strictly four digits.
   mon : abbreviated month name (April is apr, Apr, APR, etc.)
   Mon : abbreviated month name, mixed-case (i.e. April is Apr only).
   MON : abbreviated month name, all upper-case (i.e. April is APR only).
   mon_strict : abbreviated month name, all lower-case (i.e. April is apr
         only).
   month : full month name (April is april, April, APRIL, etc.)
   Month : full month name, mixed-case (i.e. April only).
   MONTH: full month name, all upper-case (i.e. APRIL only).
   month_strict : full month name, all lower-case (i.e. april only).
*/

// Be careful with this pattern.  Longer tokens should be placed before shorter
// tokens to disambiguate them.  For example, parsing "mon_strict" should
// result in one token "mon_strict" and not two tokens "mon" and a literal
// "_strict".

var tokPat=new RegExp("^month_strict|month|Month|MONTH|yyyy|YYYY|mon_strict|ampm|AMPM|mon|Mon|MON|min|MIN|dd|DD|mm|MM|yy|YY|hh|HH|ss|SS|m|M|d|D|y|Y|h|H|s|S");

// lowerMonArr is used to map months to their numeric values.

var lowerMonArr={jan:1, feb:2, mar:3, apr:4, may:5, jun:6, jul:7, aug:8, sep:9, oct:10, nov:11, dec:12}

// monPatArr contains regular expressions used for matching abbreviated months
// in a date string.

var monPatArr=new Array();
monPatArr['mon_strict']=new RegExp(/jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec/);
monPatArr['Mon']=new RegExp(/Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec/);
monPatArr['MON']=new RegExp(/JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC/);
monPatArr['mon']=new RegExp("jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec",'i');

// monthPatArr contains regular expressions used for matching full months
// in a date string.

var monthPatArr=new Array();
monthPatArr['month']=new RegExp(/^january|february|march|april|may|june|july|august|september|october|november|december/i);
monthPatArr['Month']=new RegExp(/^January|February|March|April|May|June|July|August|September|October|November|December/);
monthPatArr['MONTH']=new RegExp(/^JANUARY|FEBRUARY|MARCH|APRIL|MAY|JUNE|JULY|AUGUST|SEPTEMBER|OCTOBER|NOVEMBER|DECEMBER/);
monthPatArr['month_strict']=new RegExp(/^january|february|march|april|may|june|july|august|september|october|november|december/);

// cutoffYear is the cut-off for assigning "19" or "20" as century.  Any
// two-digit year >= cutoffYear will get a century of "19", and everything
// else gets a century of "20".

var cutoffYear=50;

// FormatToken is a datatype we use for storing extracted tokens from the
// format string.

function FormatToken (token, type)
{
  this.token=token;
  this.type=type;
}

// getting format string
function parseFormatString (formatStr)
{
 var tokArr=new Array;
 var tokInd=0;
 var strInd=0;
 var foundTok=0;

  //getting the non-word value

  while (strInd < formatStr.length)
   {
     if (formatStr.charAt(strInd)=="%" &&
        (matchArray=formatStr.substr(strInd+1).match(tokPat)) != null)
      {
        strInd+=matchArray[0].length+1;
        tokArr[tokInd++]=new FormatToken(matchArray[0],"symbolic");
      }
     else
     {
     // No token matched current position, so current character should
     // be saved as a required literal.

      if (tokInd>0 && tokArr[tokInd-1].type=="literal")
       {
        // Literal tokens can be combined.Just add to the last token.

         tokArr[tokInd-1].token+=formatStr.charAt(strInd++);
       }
     else
      {
        tokArr[tokInd++]=new FormatToken(formatStr.charAt(strInd++), "literal");
      }
    }
   }
 return tokArr;
}

// function checks the given date value in given date format.

function buildDate(dateStr,formatStr)
{
alert();
// parse the format string first.
var tokArr=parseFormatString(formatStr);
var strInd=0;
var tokInd=0;
var intMonth;
var intDay;
var intYear;
var strOffset;

// Create a date object with the current date so that if the user only
// gives a month or day string, we can still return a valid date.

var curdate=new Date();
intMonth=curdate.getMonth()+1;
intDay=curdate.getDate();
intYear=curdate.getFullYear();

// Walk across dateStr, matching the parsed formatStr until we find a
// mismatch or succeed.

while (strInd < dateStr.length && tokInd < tokArr.length)
 {

   // Start with the easy case of matching a literal.

    if (tokArr[tokInd].type=="literal")
     {
       if (dateStr.indexOf(tokArr[tokInd].token,strInd)==strInd)
        {
         // The current position in the string does match the format
         // pattern.

          strInd+=tokArr[tokInd++].token.length;
          continue;
         }
       else
       {

        // ACK! There was a mismatch; return error.

          //pattern = ;
          //formatStr1 = formatStr.replace("%","");

        return "\"" + dateStr + "\" does not match the expected format: " + formatStr;
       }
     }


     // If we get here, we're matching to a symbolic token.
     switch (tokArr[tokInd].token)
     {
       case 'm':
       case 'M':
       case 'd':
       case 'D':

        // Extract one or two characters from the date-time string and if
        // it's a number, save it as the month, day, hour, or minute, as
        // appropriate.

           curChar=dateStr.charAt(strInd);
           nextChar=dateStr.charAt(strInd+1);
           matchArr=dateStr.substr(strInd).match(/^\d{1,2}/);
           if (matchArr==null)
            {
     		   // First character isn't a number; there's a mismatch between
   			   // the pattern and date string, so return error.

             switch (tokArr[tokInd].token.toLowerCase())
              {
                case 'd': var unit="day"; break;
                case 'm': var unit="month"; break;
              }
                 return "Bad " + unit + " \"" + curChar + "\" or \"" + curChar +
                 nextChar + "\".";
           }
           strOffset=matchArr[0].length;
           switch (tokArr[tokInd].token.toLowerCase())
             {
  			   case 'd': intDay=parseInt(matchArr[0],10); break;
			   case 'm': intMonth=parseInt(matchArr[0],10); break;
             }
           break;
          case 'mm':
          case 'MM':
          case 'dd':
          case 'DD':

         // Extract two characters from the date string and if it's a
	    // number, save it as the month, day, or hour, as appropriate.

        strOffset=2;
        matchArr=dateStr.substr(strInd).match(/^\d{2}/);
        if (matchArr==null)
        {

         // The two characters aren't a number; there's a mismatch
        // between the pattern and date string, so return an error
        // message.

         switch (tokArr[tokInd].token.toLowerCase())
         {
          case 'dd': var unit="day"; break;
          case 'mm': var unit="month"; break;
         }
         return "Bad " + unit + " \"" + dateStr.substr(strInd,2) +
          "\".";
    }
     switch (tokArr[tokInd].token.toLowerCase())
      {
       case 'dd': intDay=parseInt(matchArr[0],10); break;
       case 'mm': intMonth=parseInt(matchArr[0],10); break;
      }
     break;
     case 'y':
     case 'Y':

         // Extract two or four characters from the date string and if it's
        // a number, save it as the year.Convert two-digit years to four
       // digit years by assigning a century of '19' if the year is >=
      // cutoffYear, and '20' otherwise.

   if (dateStr.substr(strInd,4).search(/\d{4}/) != -1)
    {
     // Four digit year.
     intYear=parseInt(dateStr.substr(strInd,4),10);
     strOffset=4;
    }
   else
   {
     if (dateStr.substr(strInd,2).search(/\d{2}/) != -1)
      {
          // Two digit year.

          intYear=parseInt(dateStr.substr(strInd,2),10);
           if (intYear>=cutoffYear)
           {
             intYear+=1900;
           }
           else
           {
             intYear+=2000;
           }
           strOffset=2;
       }
       else
       {
          // Bad year; return error.

          return "Bad year \"" + dateStr.substr(strInd,2) +
          "\". Must be two or four digits.";
       }
     }
    break;
    case 'yy':
    case 'YY':

     // Extract two characters from the date string and if it's a
     // number, save it as the year.Convert two-digit years to four
     // digit years by assigning a century of '19' if the year is >=
    // cutoffYear, and '20' otherwise.

    if (dateStr.substr(strInd,2).search(/\d{2}/) != -1)
    {

    // Two digit year.

      intYear=parseInt(dateStr.substr(strInd,2),10);
        if (intYear>=cutoffYear)
        {
          intYear+=1900;
        }
       else
        {
          intYear+=2000;
        }
      strOffset=2;
     }
     else
      {
       // Bad year; return error
       return "Bad year \"" + dateStr.substr(strInd,2) +
       "\". Must be two digits.";
      }
     break;
     case 'yyyy':
     case 'YYYY':

        // Extract four characters from the date string and if it's a
        // number, save it as the year.

       if (dateStr.substr(strInd,4).search(/\d{4}/) != -1)
       {

        // Four digit year.

        intYear=parseInt(dateStr.substr(strInd,4),10);
        strOffset=4;
       }
      else
      {

       // Bad year; return error.

       return "Bad year \"" + dateStr.substr(strInd,4) +
       "\". Must be four digits.";
      }
      break;
       case 'mon':
       case 'Mon':
       case 'MON':
       case 'mon_strict':

// Extract three characters from dateStr and parse them as
// lower-case, mixed-case, or upper-case abbreviated months,
// as appropriate.

   monPat=monPatArr[tokArr[tokInd].token];
  if (dateStr.substr(strInd,3).search(monPat) != -1)
     {
       intMonth=lowerMonArr[dateStr.substr(strInd,3).toLowerCase()];
     }
  else
  {

   // Bad month, return error.

    switch (tokArr[tokInd].token)
     {
		case 'mon_strict': caseStat="lower-case"; break;
		case 'Mon': caseStat="mixed-case"; break;
		case 'MON': caseStat="upper-case"; break;
		case 'mon': caseStat="between Jan and Dec"; break;
	}
	return "Bad month \"" + dateStr.substr(strInd,3) +
    "\". Must be " + caseStat + ".";
   }
  strOffset=3;
  break;
   case 'month':
   case 'Month':
   case 'MONTH':
   case 'month_strict':

// Extract a full month name at strInd from dateStr if possible.

   monPat=monthPatArr[tokArr[tokInd].token];
   matchArray=dateStr.substr(strInd).match(monPat);
  if (matchArray==null)
  {

  // Bad month, return error.

   return "Can't find a month beginning at \"" +
   dateStr.substr(strInd) + "\".";
  }

// It's a good month.

 intMonth=lowerMonArr[matchArray[0].substr(0,3).toLowerCase()];
 strOffset=matchArray[0].length;
 break;
 strOffset = matchArr[0].length;
 break;
 }
strInd += strOffset;
tokInd++;
}
if (tokInd != tokArr.length || strInd != dateStr.length) {

/* We got through the whole date string or format string, but there's
 more data in the other, so there's a mismatch. */

return "\"" + dateStr + "\" is either missing desired information or has more information than the expected format: " + formatStr;
}

// Make sure all components are in the right ranges.

if (intMonth < 1 || intMonth > 12)
{
  return "Month must be between 1 and 12.";
}
if (intDay < 1 || intDay > 31)
{
  return "Day must be between 1 and 31.";
}

// Make sure user doesn't put 31 for a month that only has 30 days

if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && intDay == 31)
{
  return "Month "+intMonth+" doesn't have 31 days!";
}

// Check for February date validity (including leap years)

if (intMonth == 2)
{

// figure out if "year" is a leap year; don't forget that
// century years are only leap years if divisible by 400

var isleap=(intYear%4==0 && (intYear%100!=0 || intYear%400==0));
if (intDay > 29 || (intDay == 29 && !isleap)) {
return "February " + intYear + " doesn't have " + intDay +
" days!";
   }
}

intHour = 0;
intMin = 0;
intSec = 0;

return new Date(intYear,intMonth-1,intDay);
}


//************** function restricts user from entering blank string and
// from entering only white speces.*****************

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 for allowing only Alpha-Numeric String *****************

function isAlphaNumeric(tmp_str)
{
  // Name      : isAlphanumeric.

  // Purpose   : allow user to enter only Alpha(A-Z)-Numeric(0-9) values.
  // Inputs    : tmp_str -> string for validations.
  // Outputs   : return 1 -> if form field is alphanumeric
  //		 return -1 -> if form field is not alphanumeric

//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 string contains the non Alpha-Nemeric value, return -1.
        //  else return 1.

	 if ((tmp_str.search(/[^\w\s]/) != -1) || (tmp_str.search(/\W/) != -1))
	  {
	 	return -1;
	  }
      }
 }
 return 1;
}


//************** function for allowing only Numeric String *****************

function isNumeric(tmp_int)
{
  // Name      : isNumeric.

  // Purpose   :allow user to enter only Numeric(0-9) values.
  // Inputs    : tmp_int -> string for validations.
  // Outputs   : return 1 -> if form field is Numeric
  //		 return -1 -> if form field is not Numeric

//ignore validation if tmp_int is blank.

if(tmp_int != "")
 {
   // searching whole string word by word
    if (tmp_int.search)
     {
        //checking the words in string.
        //  if string contains the non Nemeric value, return -1.
        //  else return 1.

	if (tmp_int.search((/[^\d]/)) != -1)
	{
		return -1;
	}
     }
 }
 return 1;
}

//************** function for allowing only Numeric String *****************

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 date ***************/

function isDate(dateStr,formatStr)
{

  // Name      : isDate.

  // Purpose   : validate Date.

  // Inputs    : dateStr-> Date Value, formatStr -> format of date.

  // Outputs   : return null -> if user enter enter validate data
  //             else return error text

  // Calls     : buildDate(dateStr,formatStr)
  //             datestr = date value
  //             formatStr = date format


  //calls function for validating date

  var myObj = buildDate(dateStr,formatStr);

  //returns the correct date
  //else returns the appropriate error message

   if (typeof myObj == "object")
   {

   // We got a Date object, so good.

    myObj = "";
    return myObj;
   }
   else
   {

   // We got an error string.

    return myObj;
   }
}

function isFile(tmp_str,fileTyp)
{
  // Name      : isFile.
  // Purpose   : validation for File extention
  // Inputs    : tmp_str -> string for validations.
  //	         fileTyp -> file extention type.
  // Outputs   : return 1 -> if form field is valid
  //		 return -1 -> if form field is unvalid

//ignore validation if tmp_str is blank.
if(tmp_str != "")
 {
	var validExt = "no";
	fileStr   = tmp_str;
	intstrLen = fileStr.length;
	intLoc    = fileStr.lastIndexOf(".");
	extVal    = fileStr.substring(intLoc,intstrLen);
	extVal	  = extVal.toLowerCase();
        valExt    = fileTyp;
	var extArry   = valExt.split('#');
	var maxLng    = extArry.length;

        //alert(maxLng);

	for(i=0;i<maxLng;i++)
	{
	   //alert(extVal);
		if(extArry[i] == extVal)
		{

			validExt  = "yes";
		}
	}
	if(validExt == "no")
	{
	  return -1;
	}
 }
 return 1;
}

function isPhoneNo(tmp_str)
{
  // Name      : isPhoneNo
  // Purpose   : allow user to enter value in phone numbers with only "-" and "." .
  // Inputs    : tmp_str -> string for validation.
  // Outputs   : return 1 -> if form field is as phone no format.
  //		 return -1 -> if form field is not as phone no format.

 Chars = "0123456789+-.";
 flag=0;

      for (i = 0; i < tmp_str.length; i++)
      {
          // Check that current character is number.
          var c = tmp_str.charAt(i);

          if (Chars.indexOf(c) == -1)
          	flag = 1;
      }
      if(flag)
      {
	  return true;
      }
}

//************** function for validates the form feilds *****************

function validate_form(doc)
{
  //On Error Resume Next;

  // Name      : validate_form.

  // Purpose   : validate the form fields.

  // Inputs    : all form feilds values

  // Outputs   : return true -> if user enter enter validate data
  //             else return false
  //             alert box displays with error message.
  // Calls     : isBlank(tmp_str) -> checks the field is blank or containing
  //		                       only white speces.
  //             isAlphaNemeric(tmp_str) -> checks the feild is Alpha-Nemeric
  //		 isNumeric(tmp_int) -> checks the field is nemeric
  //		 isEmailId(tmp_str) -> checks the field is in email id
  //		                        format(xxx@yyy.com)



 //declearing veriables

 var str;                     // stores error messages.
 var blank_field;             // stores a string of form fields and error lable for
                              // blank validation.
 var numeric_field;           // stores a string of form fields and error lable for
                              // numeric[0-9] validation.
 var AlphaNumeric_field;      // stores a string of form fields and error lable for
                              // Alpha-Numeric[A-Z]and[0-9] validation.
 var email_field;             // stores a string of form fields and error lable for
                              // email[xxx@zz.com] validation.
 var date_field               // stores a string of form date fields and error lable for
                              // date validation
 var file_field;              // stores a string of form file fields and error lable for
                              // date validation valid extentions
 var phone_field;             // stores a value of phone no                              
                              
 var str_blank_field;         // array in which value of blank_field stored by
                              // comma separating.
 var str_numeric_field;       // array in which value of numeric_field stored by
                              // comma separating.
 var str_alphanumeric_field;  // array in which value of AlphaNumeric_field stored by
                              // comma separating.
 var str_email_field;         // array in which value of email_field stored by
                              // comma separating.
 var str_date_field;          // array in which value of date_field stored by
                              // comma separating.
 var str_file_field;          // array in which value of file_field stored by
                              // comma separating.

/* if form field is not aailable setts the null value **/
  if(typeof doc.js_Blank == "undefined")
  {
    blank_field = "";
  }
  else
  {
    blank_field = doc.js_Blank.value;
  }

  if(typeof doc.js_Numeric == "undefined")
  {
     numeric_field = "";
  }
  else
  {
      numeric_field = doc.js_Numeric.value;
  }

  if(typeof doc.js_AlphaNumeric == "undefined")
  {
      AlphaNumeric_field = "";
  }
  else
  {
      AlphaNumeric_field = doc.js_AlphaNumeric.value;
  }

  if(typeof doc.js_Email == "undefined")
  {
      email_field = "";
  }
  else
  {
      email_field = doc.js_Email.value;
  }


  if(typeof date_field == "undefined")
  {
      date_field = "";
  }
  else
  {
      date_field = doc.js_Date.value;
  }

  if(typeof doc.js_File == "undefined")
  {
    file_field = "";
  }
  else
  {
    file_field = doc.js_File.value;
  }

  if(typeof doc.js_Phone == "undefined")
  {
     phone_field = "";
  }
  else
  {
     phone_field = doc.js_Phone.value;
  }
  
  
   str = "";

   //calls function is_blank for blank validation, if blank_field is not null

     if(blank_field != "")
     {

       //creats array in which values stores without comma
        str_blank_field = blank_field.split(",");

        //loop for getting value from array for validating fields.
        for(a=0; a<str_blank_field.length; a++)
         {

            //getting error lables for messages
             tmp_str_FlType = str_blank_field[a];

             a=a+1;
             //alert(tmp_str_FlType);

            //getting field name
             tmp_str_FldName = str_blank_field[a];

            //getting value of form fields
            //tmp_str_value = eval('document.'+doc.name+'.'+str_blank_field[a]+'.value');
            
            //getting value of form fields
		if(tmp_str_FlType != "mul")
		{
		  tmp_str_value = eval('document.'+doc.name+'.'+str_blank_field[a]+'.value');
		}
		else
		{
		  tmp_str_value = "";
                }
            a=a+1;

            //getting error lables for messages
            tmp_err_Mess2 = str_blank_field[a];

           //calls function for blank validation

             switch(tmp_str_FlType)
	     {
                case 'text':
                 tmp_Blank_validate = isBlank(tmp_str_value);
                 tmp_str_Mess1 = "Please enter ";
  	        break;
                case 'check':
                 tmp_Blank_validate = "checked";
                 if(eval('document.'+doc.name+'.'+tmp_str_FldName+'.checked') == false)
                 {
                   tmp_Blank_validate = "";
                   tmp_str_Mess1 = "Please check ";
                 }
                break;
                case 'radio':
                 tmp_Blank_validate = "";
                 radiogroup = eval('document.'+doc.name+'.elements[tmp_str_FldName]');
                  for(var r = 0 ; r < radiogroup.length ; ++r)
	           {
	            if(radiogroup[r].checked)
	            {
	              tmp_Blank_validate = "checked";
	            }
	           }
                break;
	        case 'select':
                 tmp_Blank_validate = "selected";
                 if((eval('document.'+doc.name+'.'+tmp_str_FldName+'.selected') == false) || (tmp_str_value == ""))
                 {
                   tmp_Blank_validate = "";
                   tmp_str_Mess1 = "Please select ";
                 }
                break;
 		case 'mul':
                 tmp_Blank_validate = "selected";
                 mulCnt  = eval('document.'+doc.name+'["'+tmp_str_FldName+'"].length');
                 selMulCnt = 0;
		  /* loop through the selected titles.  */
		  for(m=0; m<mulCnt; m++)
		  {
		    tmp_str_value
		    if(eval('document.'+doc.name+'["'+tmp_str_FldName+'"]['+m+'].selected') == true)
		    {
		      if(eval('document.'+doc.name+'["'+tmp_str_FldName+'"]['+m+'].value' != ""))
		      {
		        selMulCnt++;
		      }  
		    }
		  }
		  if(selMulCnt == 0)
		  {
		    tmp_Blank_validate = "";
	            tmp_str_Mess1      = "Please select ";
                  }
                break;                
            }
          //if value of tmp_validate = "", sets the error message.
          if(tmp_Blank_validate == "")
           {
              str +=  tmp_str_Mess1 + tmp_err_Mess2 + "\n";
           }
         }
     }

//calls function isNumeric for numeric validation, if numeric_field is not null

     if(numeric_field != "")
     {
       //creats array in which values stores without comma
       str_numeric_field = numeric_field.split(",");

       //loop for getting value from array for validating fields.
       for(a=0; a<str_numeric_field.length; a++)
       {
         //getting value of form fields
	 tmp_str = eval('document.'+doc.name+'.'+str_numeric_field[a]+'.value');

	  a=a+1;

	 //getting error lables for messages
	 tmp_err_message = str_numeric_field[a];



	   //calls function for Numeric(0-9) validation
	   tmp_validate = isNumeric(tmp_str);

	//if value of tmp_validate = -1 setting error message.
	if(tmp_validate == -1)
	   {
	      str += "Please enter valid " + tmp_err_message + "\n";
	   }
       }
      }

  //calls function isAlphaNumeric for AlphaNumeric validation, if AlphaNumeric_field is not null

      if(AlphaNumeric_field != "")
      {

        //creats array in which values stores without comma
        str_alphanumeric_field = AlphaNumeric_field.split(",");

         //loop for getting value from array for validating fields.
         for(a=0; a<str_alphanumeric_field.length; a++)
          {

            //getting value of form field
            tmp_str = eval('document.'+doc.name+'.'+str_alphanumeric_field[a]+'.value');

            a=a+1;

            //getting error lables for messages
            tmp_err_message = str_alphanumeric_field[a];

           //calls function for Alpha Numeric(A-Z and 0-9)  validation

           tmp_validate = isAlphaNumeric(tmp_str);

          //if value of tmp_validate = -1 setting error message
           if(tmp_validate == -1)
            {
               str += "Please enter valid" + tmp_err_message + "\n";
            }
          }
       }


 //calls function isEmailId for Email Id validation, if email_field is not null


     if(email_field != "")
     {
       //creats array in which values stores without comma
       str_email_field = email_field.split(",");

       //loop for getting value from array for validating fields.
       for(a=0; a<str_email_field.length; a++)
        {

          //getting value of form field
	  tmp_str = eval('document.'+doc.name+'.'+str_email_field[a]+'.value');

	  a=a+1;

	  //getting error lables for messages
	  tmp_err_message = str_email_field[a];



	 //calls function for Email ID(xxx@yyy.com) validation

	 tmp_validate = isEmailId(tmp_str);

	 //if value of tmp_validate = -1 setting error message
	  if(tmp_validate == -1)
	    {
	       str += "Please enter correct " + tmp_err_message + " \n";
            }
        }
     }

      //calls function isDate for Date validation, if date_field is not null

       if(date_field != "")
          {
            //creats array in which values stores without comma
            str_date_field = date_field.split(",");

            //loop for getting value from array for validating fields.
            for(a=0; a<str_date_field.length; a++)
             {

             //getting date format
             tmp_date_format = str_date_field[a];

             a=a+1;

            //getting value of form field
     	    tmp_str = eval('document.'+doc.name+'.'+str_date_field[a]+'.value');

     	    a=a+1;

     	  //getting error lables for messages
     	  tmp_err_message = str_date_field[a];



     	 //calls function for date validation

     	 tmp_validate = isDate(tmp_str,tmp_date_format);

     	 //if value of tmp_validate = -1 setting error message

         if (tmp_str  != "")
         {
     	  if(tmp_validate != "")
     	    {
     	       str += tmp_validate + "\n";
            }
         }
        }
     }

       if(file_field != "")
          {
            //creats array in which values stores without comma
            str_file_field = file_field.split(",");

            //loop for getting value from array for validating fields.
            for(a=0; a<str_file_field.length; a++)
             {
              //getting file extention format
              tmp_file_extention = str_file_field[a];
              a=a+1;

             //getting value of form field

     	     tmp_str = eval('document.'+doc.name+'.'+str_file_field[a]+'.value');

     	    a=a+1;

     	  //getting error lables for messages
     	  tmp_err_message = str_file_field[a];

     	 //calls function for file validation

     	 tmp_validate = isFile(tmp_str,tmp_file_extention);

     	 //alert(tmp_validate);

     	 //if value of tmp_validate = -1 setting error message

     	  if(tmp_validate == -1)
     	    {

     	       /* Replace the # TAGs with "," */
			   	var brk       = new RegExp('#','gi');
				tmp_file_extention = tmp_file_extention.replace(brk,", ");

     	       str += "please upload "+tmp_file_extention+" extension file for "+tmp_err_message+ "\n";
            }
         }
     }


//calls function isPhoneNo for validating values for phone numbers
     if(phone_field != "")
     {
       //creats array in which values stores without comma
       arr_phone_field = phone_field.split(",");

       //loop for getting value from array for validating fields.
       for(a=0; a<arr_phone_field.length; a++)
       {
         //getting value of form fields
	 tmp_str = eval('document.'+doc.name+'.'+arr_phone_field[a]+'.value');

	  a=a+1;

	 //getting error lables for messages
	 tmp_err_message = arr_phone_field[a];


	   //calls function for phone no. validation
	   tmp_validate = isPhoneNo(tmp_str);

	//if value of tmp_validate = -1 setting error message.
	if(tmp_validate)
	   {
	      str += "Please enter valid " + tmp_err_message + "\n";
	   }
       }
      }

// if str contains the error messages return false
// else return true

   if(str)
    {
       alert(str);
       return false;
    }
   else
    {
       return true;
    }

}

function validate_onlineform(doc)
{
	
	var str	=	'';
	if(doc.frm_int_maincat.value == '')
	{
		str += 'Please Select Category'+ '\n'; 
	}
	if(doc.frm_int_crew.value == '' || doc.frm_int_crew.value == '0' )
	{
		str += 'Please Select Designation'+ '\n';
	}
	if(doc.frm_int_type.value == '')
	{
			str += 'Please Select Location'+ '\n';
	}
	
	
	if( !(doc.frmoil.checked) && !(doc.frmgas.checked) && !(doc.frmmarine.checked))
	{
			str += 'Please Select Industry Type'+ '\n';
	}
	
	if( !(doc.frmoffshore.checked) && !(doc.frmonshore.checked))
	{
			str += 'Please Select Experience Sector'+ '\n';
	}
	
	if( !(doc.frmdesign.checked) && !(doc.frmfield.checked) && !(doc.frmoffice.checked))
	{
				str += 'Please Select Specific Area'+ '\n';
	}
	
	if(str)
	{
		 alert(str);
		 return false;
	}
	else
	{
		 return true;
	}
}