var sJobNumber     = "Job Number" ;
var sYourJobNo = "Please Enter a Job Number for your easy referance" ;
var sEmail     = "EMail" ;
var sPositionTitle = "Position Title" ;
var sSkills         = "Skills" ;
var sPassword     = "Password" ;
var sName            ="Name";   
var cName            ="Candidate Name"; 
var sFname          = "First name";
var sLname          = "Last name";
var sTitle          = "Title";
var sDate           ="Date";
var sCompany        = "Company";
var sAddress        = "Address";
var sCity          = "City";
var sState          = "State";
var sZipcode        = "Zip Code";
var sCountry        = "Country";
var sPhone          = "Phone Number";
var iName           = "Name should have only Alphabets";
var iMatchEmail     = "Email Id should be the same";
var iMatchPassword  = "Password should be the same";
var iPhone          = "This field must be a 10 digit U.S. phone number (like 402 555 1212). Please reenter it now";
var iJobNumber      = "This field must greater than 5 digits and should be numeric";
var mPrefix = "Please enter the " ;
var whitespace = " \t\n\r";
var digitsInPhone1 = 3 ;
var digitsInPhone2 = 4 ;
var digitsInJobNo = 5 ;
//***********************************************************
//formVerify
//***********************************************************
function formVerify(form)
{   return (
      checkString(form.elements["jobNumber"],sJobNumber) &&
      checkString(form.elements["positionTitle"],sPositionTitle) &&
      checkString(form.elements["skills"],sSkills) 
           )
}

function formVerifyJob(myform)
{   return (
      checkString(myform.elements["positionTitle"],sPositionTitle) &&
      checkString(myform.elements["skills"],sSkills) 
           )
}

function formVerifyReg(form)
{   return (
      checkEmail(form.elements["emailId"], true) &&
      checkEmail(form.elements["reEmailId"], true) &&
      checkMatchEmail(form) &&
      checkString(form.elements["password"],sPassword) &&
      checkString(form.elements["rePassword"],sPassword) &&
      checkMatchPassword(form) &&
      checkString(form.elements["title"],sTitle) &&
      checkName(form.elements["fName"],sFname) &&
      checkName(form.elements["lName"],sLname) &&
      checkString(form.elements["company"],sCompany) &&
      checkString(form.elements["address"],sAddress) &&
      checkString(form.elements["city"],sCity) &&
      checkString(form.elements["state"],sState) &&
      checkZIPCode(form.elements["zipCode"]) &&
      checkString(form.elements["country"],sCountry) &&
      checkPhoneReq(form.elements["areaCode"],digitsInPhone1) &&
      checkPhoneReq(form.elements["pPhoneNo"],digitsInPhone1) &&
      checkPhoneReq(form.elements["sPhoneNo"],digitsInPhone2) 
       
            )
}


function formVerifyRegUp(form)
{   return (
      checkString(form.elements["title"],sTitle) &&
      checkName(form.elements["fName"],sFname) &&
      checkName(form.elements["lName"],sLname) &&
      checkString(form.elements["company"],sCompany) &&
      checkString(form.elements["address"],sAddress) &&
      checkString(form.elements["city"],sCity) &&
      checkString(form.elements["state"],sState) &&
      checkZIPCode(form.elements["zipCode"]) &&
      checkString(form.elements["country"],sCountry) &&
      checkPhoneReq(form.elements["areaCode"],digitsInPhone1) &&
      checkPhoneReq(form.elements["pPhoneNo"],digitsInPhone1) &&
      checkPhoneReq(form.elements["sPhoneNo"],digitsInPhone2) 
       
            )
}

function formVerifyJobNo(myform)
{  return (
       checkJobNo(myform.elements["tecJobNo"],digitsInJobNo)
          )
} 

function formVerifyProfile1(form)
{   return(
        checkCandidateName(form.elements["canName"],cName) &&
        checkPhoneReq(form.elements["canAreaCode"],digitsInPhone1) &&
        checkPhoneReq(form.elements["canPPhoneNo"],digitsInPhone1) &&
        checkPhoneReq(form.elements["canSPhoneNo"],digitsInPhone2) &&
        checkEmail(form.elements["canEmailId"], true) &&
        checkString(form.elements["skillsSummary"],sSkills)

          )
} 

function formVerifyProfile2(form)
{   return(
          checkString(form.elements["aDate"],sDate) &&
          checkRefPhone(form)
          )
}    

function formVerifyProfile1Modify(form)
{   return(
        checkCandidateName(form.elements["newCanName"],cName) &&
        checkPhoneReq(form.elements["canAreaCode"],digitsInPhone1) &&
        checkPhoneReq(form.elements["canPPhoneNo"],digitsInPhone1) &&
        checkPhoneReq(form.elements["canSPhoneNo"],digitsInPhone2) &&
        checkEmail(form.elements["canEmailId"], true) &&
        checkString(form.elements["skillsSummary"],sSkills)

          )
}              
   
//***********************************************************
// CheckString 
//***********************************************************
function checkString (theField, s)
{   if (isWhitespace(theField.value)) 
       return warnEmpty (theField, s);
    else return true;
}

//***********************************************************
// CheckName
//***********************************************************
function checkName (theField, s)
{   if (isWhitespace(theField.value)) 
       return warnEmpty (theField, s);
    else if (!isAlphabetic(theField.value)) 
         return warnInvalid (theField, iName);
         else return true;
}
//************************************************************
// Returns true if string s is empty or 
// whitespace characters only.
//************************************************************
function isWhitespace (s)

{   var i;
    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

//***********************************************************
// Check whether string s is empty.
//***********************************************************
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

//***********************************************************
// display Warning Message
//***********************************************************

function warnEmpty (theField, s)
{   theField.focus()
    window.alert(mPrefix + s )
    return false
}

//******************************************************************************
// VALIDATING EMAIL ID
//******************************************************************************
var iEmail = "This field must be a valid email address (like foo@bar.com). Please reenter it now."

// checkEmail (theField [,eok])        Check that theField.value is a valid Email.
// checkEmail (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid Email.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkEmail (theField, emptyOK)
{   
    if (isWhitespace(theField.value)) 
       return warnEmpty (theField, sEmail);
    else if (!isEmail(theField.value, false)) 
       return warnInvalid (theField, iEmail);
    else return true;
}


// isEmail (s [,eok])                  True if string s is a valid email address.
// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

//*********************************************************************


// warnInvalid (theField, s)           Notify user that contents of field theField are invalid.
// Notify user that contents of field theField are invalid.
// String s describes expected contents of theField.value.
// Put select theField, pu focus in it, and return false.

function warnInvalid (theField, s)
{   theField.focus()
    theField.select()
    alert(s)
    return false
}

//*********************************************************************

function checkMatchEmail(form) 
{
   var firstEmail =  form.elements["emailId"] ;
   var secondEmail =  form.elements["reEmailId"] ;

      if(firstEmail.value != secondEmail.value)
        {
         return warnInvalid(form.elements["reEmailId"] , iMatchEmail);
         }
       else
         {
         return true;
         }
}

function checkMatchPassword(form) 
{
   var firstPassword =  form.elements["password"] ;
   var secondPassword =  form.elements["rePassword"] ;

      if(firstPassword.value != secondPassword.value)
        {
         return warnInvalid(form.elements["rePassword"] , iMatchPassword);
         }
       else
         {
         return true;
         }
}
//******************************************************************************
// VALIDATING ZIP CODE
//******************************************************************************
// Many of the below functions take an optional parameter eok (for "emptyOK")
// which determines whether the empty string will return true or false.

// Default behavior is controlled by global variable defaultEmptyOK.
// Global variable defaultEmptyOK defines default return value 
// for many functions when they are passed the empty string. 
// By default, they will return defaultEmptyOK.
//
// defaultEmptyOK is false, which means that by default, 
// these functions will do "strict" validation.  Function
// isInteger, for example, will only return true if it is
// passed a string containing an integer; if it is passed
// the empty string, it will return false.
//
// You can change this default behavior globally (for all 
// functions which use defaultEmptyOK) by changing the value
// of defaultEmptyOK.
//
// Most of these functions have an optional argument emptyOK
// which allows you to override the default behavior for 
// the duration of a function call.
//
// This functionality is useful because it is possible to
// say "if the user puts anything in this field, it must
// be an integer (or a phone number, or a string, etc.), 
// but it's OK to leave the field empty too."
// This is the case for fields which are optional but which
// must have a certain kind of content if filled in.

var defaultEmptyOK = false

// checkZIPCode (theField [,eok])      Check that theField.value is a valid ZIP code.
// isZIPCode (s [,eok])                True if string s is a valid U.S. ZIP code.
// stripCharsInBag (s, bag)            Removes all characters in string bag from string s.

// non-digit characters which are allowed in ZIP Codes

var ZIPCodeDelimiters = "-";

// our preferred delimiter for reformatting ZIP Codes
var ZIPCodeDelimeter = "-"

// U.S. ZIP codes have 5 or 9 digits.
// They are formatted as 12345 or 12345-6789.
var digitsInZIPCode1 = 5;
var digitsInZIPCode2 = 9;


var iZIPCode = "This field must be a 5 or 9 digit U.S. ZIP Code (like 94043). Please reenter it now."



// checkZIPCode (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid ZIP code.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkZIPCode (theField, emptyOK)
{  
    if (isWhitespace(theField.value)) 
       return warnEmpty (theField, sZipcode);
    else
    { var normalizedZIP = stripCharsInBag(theField.value, ZIPCodeDelimiters)
      if (!isZIPCode(normalizedZIP, false)) 
         return warnInvalid (theField, iZIPCode);
      else 
      {  
         return true;
      }
    }
}

// isZIPCode (STRING s [, BOOLEAN emptyOK])
// 
// isZIPCode returns true if string s is a valid 
// U.S. ZIP code.  Must be 5 or 9 digits only.
//
// NOTE: Strip out any delimiters (spaces, hyphens, etc.)
// from string s before calling this function.  
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isZIPCode (s)
{  
   return (isInteger(s) && 
            ((s.length == digitsInZIPCode1) ||
             (s.length == digitsInZIPCode2)))
}

function stripCharsInBag (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

// warnInvalid (theField, s)           Notify user that contents of field theField are invalid.

function warnInvalid (theField, s)
{   theField.focus()
    theField.select()
    alert(s)
    return false
}

// isInteger (s [,eok])                True if all characters in string s are numbers.
// isDigit (c)                         Check whether character c is a digit 

// isInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if all characters in string s are numbers.
//
// Accepts non-signed integers only. Does not accept floating 
// point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// By default, returns defaultEmptyOK if s is empty.
// There is an optional second argument called emptyOK.
// emptyOK is used to override for a single function call
//      the default behavior which is specified globally by
//      defaultEmptyOK.
// If emptyOK is false (or any value other than true), 
//      the function will return false if s is empty.
// If emptyOK is true, the function will return true if s is empty.
//
// EXAMPLE FUNCTION CALL:     RESULT:
// isInteger ("5")            true 
// isInteger ("")             defaultEmptyOK
// isInteger ("-5")           false
// isInteger ("", true)       true
// isInteger ("", false)      false
// isInteger ("5", false)     true

function isInteger (s)

{   var i;

     // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

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

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

//*************************************************************************
// VALIDATING FIRST AND LAST NAMES Checks whehter the string is Alphabetic
//*************************************************************************

// isAlphabetic (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is English letters 
// (A .. Z, a..z) only.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function isAlphabetic (s)

{   var i;

    // Search through string's characters one by one
    // until we find a non-alphabetic character.
    // When we do, return false; if we don't, return true.

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

        if (!isLetter(c))
        return false;
    }

    // All characters are letters.
    return true;
}

// Returns true if character c is an English letter 
// (A .. Z, a..z).
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}


//*************************************************************************
// VALIDATING PHONE NUMBERS Checks whehter the string is Numeric
//*************************************************************************

function  checkPhoneReq(theField, n)
  {
    if (isWhitespace(theField.value)) 
       return warnEmpty (theField, sPhone);
    else 
     { if (!isPhonenum(theField.value, n)) 
         return warnInvalid (theField, iPhone);
      else 
      {  
         return true;
      }
    }
}

function isPhonenum(s,n)
{  
   return (isInteger(s) && (s.length == n))
}


// ****************Checking for Job Number **********************

function  checkJobNo(theField, n)
  {
    if (isWhitespace(theField.value)) 
       return warnEmpty (theField, sJobNumber);
    else 
     { if (!isJobnum(theField.value, n)) 
         return warnInvalid (theField, iJobNumber);
      else 
      {  
         return true;
      }
    }
}

function isJobnum(s,n)
{  
   return (isInteger(s) && (s.length > n))
}

// ******************* Checking the Name ******************

function checkCandidateName(theField, s)
{   if (isWhitespace(theField.value)) 
       return warnEmpty (theField, s);
    else 
    {
     var i;
     for (i = 0; i < theField.length; i++)
        {   
        // Check that current character is letter.
        var c = theField.charAt(i);
        if (whitespace.indexOf(c) != -1) 
          { if (!isLetter(c))
             return warnInvalid (theField, iName);
          }
        }
      return true;
    }
}
 

// ****************Checking For Reference Phone No**********
function checkRefPhone(form) 
{
  var i;
  refName = new Array(4);
  refPhoneNo = new Array(4);
  var refNameValue;
  var refPhoneNoValue;

  for(i=1; i<4; i++)
    {
    refNameValue = "refName";
    refNameValue =refNameValue+i;

    refPhoneNoValue = "refPhoneNo";
    refPhoneNoValue = refPhoneNoValue+i;

    refName[i] =  form.elements[refNameValue] ;
    refPhoneNo[i] =  form.elements[refPhoneNoValue] ;

    if (!isWhitespace(refName[i].value)) 
        {
         if (isWhitespace(refPhoneNo[i].value)) 
           return warnEmpty (refPhoneNo[i], sPhone);
        }
     }
}   
 

