//=========================================================General Functions====================
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}
function isInteger (s)
{   var i;

   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 isZIPCode (s)
{        
   return (isEmpty(s) && ((s.length <= 10) ))
}

function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return false;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;
   
    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;
}

function isEmpty(s)
{  
 return ((s == null) || (s.length == 0) || (s.charAt(0)==" " ))
}
function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function isAlphabetic (s)

         {   var i;
                 for (i = 0; i < s.length; i++)
                      {   
                          // Check that current character is letter.
                          var c = s.charAt(i);
                              if (s.charAt(i)==" " ) continue
                              
                            if (!isLetter(c))
                            return false;
                            
                            
                         }
                         
    // All characters are letters.
    return true;
}

function isWhitespace (s)
{
   var i;
    if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (c.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}
//===================================================================================================
Now = new Date();
NowDay = Now.getDate();
NowMonth = Now.getMonth();
NowYear = Now.getYear();
if (NowYear < 2000) NowYear += 1900; //for Netscape

//function for returning how many days there are in a month including leap years
function DaysInMonth(WhichMonth, WhichYear)
{
  var DaysInMonth = 31;
  if (WhichMonth == "Apr" || WhichMonth == "Jun" || WhichMonth == "Sep" || WhichMonth == "Nov") DaysInMonth = 30;
  if (WhichMonth == "Feb" && (WhichYear/4) != Math.floor(WhichYear/4))	DaysInMonth = 28;
  if (WhichMonth == "Feb" && (WhichYear/4) == Math.floor(WhichYear/4))	DaysInMonth = 29;
  return DaysInMonth;
}

//function to change the available days in a months
function ChangeOptionDays(Which)
{
  DaysObject = eval("document.frmCandidate." + Which + "date");
  MonthObject = eval("document.frmCandidate." + Which + "month");
  YearObject = eval("document.frmCandidate." + Which + "year");

  Month = MonthObject[MonthObject.selectedIndex].text;
  Year = YearObject[YearObject.selectedIndex].text;

  DaysForThisSelection = DaysInMonth(Month, Year);
  CurrentDaysInSelection = DaysObject.length;
  
  if (CurrentDaysInSelection > DaysForThisSelection)
  {
    for (i=0; i<(CurrentDaysInSelection-DaysForThisSelection); i++)
    {
      DaysObject.options[DaysObject.options.length - 1] = null
    }
  }
  if (DaysForThisSelection > CurrentDaysInSelection)
  {
    for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++)
    {
      NewOption = new Option(DaysObject.options.length + 1);
      DaysObject.add(NewOption);
    }
  }
    if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;
}
function SetToToday(Which)
{
  DaysObject = eval("document.Form1." + Which + "Day");
  MonthObject = eval("document.Form1." + Which + "Month");
  YearObject = eval("document.Form1." + Which + "Year");

  YearObject[0].selected = true;
  MonthObject[NowMonth].selected = true;

  ChangeOptionDays(Which);

  DaysObject[NowDay-1].selected = true;
}

//function to write option years plus x
function WriteYearOptions(YearsAhead)
{
  line = "";
  for (i=0; i<YearsAhead; i++)
  {
    line += "<OPTION>";
    line += NowYear - i;
  }
  return line;
}
//  End -->
//===================================================================================================

function checkfirstname()
{
	if (isEmpty(document.frmCandidate.firstname.value)) 
	{
		alert("Please enter your First Name.")
		document.frmCandidate.firstname.focus();
		document.frmCandidate.firstname.select();
		return false;
	}
	else
	{
		return checkmiddlename();
	}
}
function checkmiddlename()
{
	if ((document.frmCandidate.middlename.value != "") && (isEmpty(document.frmCandidate.middlename.value)))
	{
		alert("Please enter your Middle Name (only Alphabets).")
		document.frmCandidate.middlename.focus();
		document.frmCandidate.middlename.select();
		return false;
	}
	else
	{
		return checklastname();
	}
}
function checklastname()
{
	if (isEmpty(document.frmCandidate.lastname.value))
	{
		alert("Please enter your Last Name.")
		document.frmCandidate.lastname.focus();
		document.frmCandidate.lastname.select();
		return false;
	}
	else
	{
		return checkemail();
	}
}

function checkemail()
{
	if (isEmpty(document.frmCandidate.email.value))
	{
		alert("Please enter your E-mail Address.");
		document.frmCandidate.email.select();
		document.frmCandidate.email.focus();
		return false
	}
	else
	{
		return checkvalidemail();
	}
}
function checkvalidemail()
{
	if (validate_textbox('frmCandidate','email','empty')==false)
	{
		alert("Please enter a valid Email.");
		document.frmCandidate.email.focus();
		document.frmCandidate.email.select();
		return false;
	}
	if(document.frmCandidate.email.value!="")
	{
		var elementvalue=document.frmCandidate.email.value;
		var ret=emailvalidate(elementvalue);
		if (ret==false)
		{
			document.frmCandidate.email.focus();		
			return false;
		}
		else
		{
			return checkpassword()
		}

	}
	else
	{
		return checkpassword()
	}
}
function checkpassword()
{
	if (isEmpty(document.frmCandidate.password.value))
	{
		alert("Please enter your Password.");
		document.frmCandidate.password.select();
		document.frmCandidate.password.focus();
		return false;
	
	}
	else
	{
		return checklengthofpassword();
	}
}
function checklengthofpassword()
{
	if (document.frmCandidate.password.value.length < 5)
	{
		alert("Please enter atleast 5 characters as your password.");
		document.frmCandidate.password.select();
		document.frmCandidate.password.focus();
		return false;
	
	}
	else
	{
		return checkconfirmpassword();
	}
}
function checkconfirmpassword()
{
	if (isEmpty(document.frmCandidate.confirmpwd.value))
	{
		alert("Please confirm your Password.");
		document.frmCandidate.confirmpwd.select();
		document.frmCandidate.confirmpwd.focus();
		return false;
	
	}
	else
	{
		return checkmatchpassword();
	}
}
function checkmatchpassword()
{
	if (document.frmCandidate.password.value != document.frmCandidate.confirmpwd.value)
	{
		alert("Passwords are not matching, please try again.");
		document.frmCandidate.confirmpwd.select();
		document.frmCandidate.confirmpwd.focus();
		return false;
	}
	else
	{
		return checkAddress()
	}
}
function checkAddress()
{
	if (isEmpty(document.frmCandidate.address1.value))
	{
		alert("Please enter your Address.")
		document.frmCandidate.address1.focus();
		document.frmCandidate.address1.select();
		return false
	}
  	else
  	{
  		return checkzip();
  	}
}
function checkzip()
{
  	if ((isEmpty(document.frmCandidate.pin.value)) || (!isInteger(document.frmCandidate.pin.value)))
  	{
  		alert("Please enter the Pin Code.")
  		document.frmCandidate.pin.focus();
  		document.frmCandidate.pin.select();
  		return false
  	}
  	else
  	{
  		return checkcountry();
  	}
}
function checkcountry()
{
	Item = document.frmCandidate.selCountry.selectedIndex;
	Result = document.frmCandidate.selCountry.options[Item].value;
	
	if ((Result=="") || (Result=="0"))
	{
		alert("Please select a Country.")
		document.frmCandidate.selCountry.focus();
		return false
	}
	else
	{
		return checkstate();
	}
}
function checkstate()
{
  	Item = document.frmCandidate.selState.selectedIndex;
  	Result = document.frmCandidate.selState.options[Item].value;
  	
  	if ((Result=="") || (Result=="0"))
  	{
  		alert("Please select a State.")
  		document.frmCandidate.selState.focus();
  		return false;
  	}
	else 
	{
		return checkothers()
	}

}
function checkothers()
{
	Item = document.frmCandidate.selState.selectedIndex;
	Result = document.frmCandidate.selState.options[Item].value;
	
	if ((Result=="Others") && (isEmpty(document.frmCandidate.txtOthers.value)))
	{
		alert("Please enter your State.")
		document.frmCandidate.txtOthers.focus();
		return false
	}
	else
	{
		return checkcity();
	}
}

function checkcity()
{
  	if ((isEmpty(document.frmCandidate.city.value)) || (!isAlphabetic(document.frmCandidate.city.value)))
  	{
  		alert("Please enter the City.")
  		document.frmCandidate.city.focus();
  		document.frmCandidate.city.select();
  		return false
  	}
  	else
  	{
  		return checkeitheror();
  	}
}
function checkeitheror()
{
	if (((document.frmCandidate.tnumber.value == "") && (document.frmCandidate.tcountry.value == "") && (document.frmCandidate.tcity.value == "")) && (document.frmCandidate.mobile.value == "")) 
	{
		alert("Please enter either Telephone Number / Mobile Number.")
		return false;
	}
	else if ((document.frmCandidate.tnumber.value != "") && (document.frmCandidate.tcountry.value != "") && (document.frmCandidate.tcity.value != ""))
	{
		return checktelephone()
	}
	else if (document.frmCandidate.mobile.value != "" )
	{
		return checkmobilenumber();
	}
	else
	{
		return checktelephone();
	}
}
function checktelephone()
{
	if ((isEmpty(document.frmCandidate.tcountry.value)) || (!isInteger(document.frmCandidate.tcountry.value)))
	{
		alert("Please enter the Country Code (in Numeric).")
		document.frmCandidate.tcountry.focus();
		document.frmCandidate.tcountry.select();
		return false;
	}
	else
	{
		return checktelcity();
	}
}
function checktelcity()
{
	if ((isEmpty(document.frmCandidate.tcity.value)) || (!isInteger(document.frmCandidate.tcity.value)))
	{
		alert("Please enter the Area Code (in Numeric).")
		document.frmCandidate.tcity.focus();
		document.frmCandidate.tcity.select();
		return false;
	}
	else
	{
		return checktelnumber();
	}
}
function checktelnumber()
{	
	if ((isEmpty(document.frmCandidate.tnumber.value)) || (!isInteger(document.frmCandidate.tnumber.value)))
	{
		alert("Please enter your Telephone Number (in Numeric).")
		document.frmCandidate.tnumber.focus();
		document.frmCandidate.tnumber.select();
		return false;
	}
	else
	{
		return checkmobilenumber();
	}
}
function checkmobilenumber()
{	
	if ((document.frmCandidate.mobile.value != "") && (!isInteger(document.frmCandidate.mobile.value)))
	{
		alert("Please enter your Mobile Number (in Numeric).")
		document.frmCandidate.mobile.focus();
		document.frmCandidate.mobile.select();
		return false;
	}
	else
	{
		return checkprefLocation();
	}
}
function checkprefLocation()
{
  	Item = document.frmCandidate.selJobLocType.selectedIndex;
  	Result = document.frmCandidate.selJobLocType.options[Item].value;
  	
  	if ((Result=="") || (Result=="0"))
  	{
  		alert("Please select your preferred Job Location.")
  		document.frmCandidate.selJobLocType.focus();
  		return false;
  	}
	else 
	{
		return checklocation()
	}

}
function checklocation()
{
 	Item = document.frmCandidate.selJobLoc.selectedIndex;
 	if (Item == "-1")
 	{
 		Result = "0"
 	}
 	else
 	{
 		Result = document.frmCandidate.selJobLoc.options[Item].value;
 	}
  	if ((Result=="") || (Result=="0"))
  	{
		alert("Please select your Location.")
  		document.frmCandidate.selJobLoc.focus();
  		return false;
  	}
	else 
	{
		return checkalternatevalidemail();
	}
}
function checkalternatevalidemail()
{

	if(document.frmCandidate.alternate_email.value!="")
	{
		if (validate_textbox('frmCandidate','alternate_email','empty')==false)
		{
			alert("Please enter a valid Alternate Email.");
			document.frmCandidate.alternate_email.focus();
			document.frmCandidate.alternate_email.select();
			return false;
		}
		var elementvalue=document.frmCandidate.alternate_email.value;
		var ret=emailvalidate(elementvalue);
		if (ret==false)
		{
			document.frmCandidate.alternate_email.focus();		
			return false;
		}
		else
		{
			return checkexpinyrs()
		}

	}
	else
	{
		return checkexpinyrs()
	}
}
function checkexpinyrs()
{
  	Item = document.frmCandidate.expyears.selectedIndex;
  	Result = document.frmCandidate.expyears.options[Item].value;
  	
  	if ((Result==""))
  	{
  		alert("Please select your Experience (in Years).")
  		document.frmCandidate.expyears.focus();
  		return false;
  	}
	else 
	{
		return checkexp()
	}
}
function checkexp()
{
  	Item = document.frmCandidate.expyears.selectedIndex;
  	Result = document.frmCandidate.expyears.options[Item].value;
  	
  	if ((Result=="30+"))
  	{
  		return checkvalid()
  	}
	else 
	{
  		return checkexpinmonths()
	}	
}
function checkexpinmonths()
{
  	Item = document.frmCandidate.expmonths.selectedIndex;
  	Result = document.frmCandidate.expmonths.options[Item].value;
  	
  	if ((Result==""))
  	{
  		alert("Please select your Experience (in Months).")
  		document.frmCandidate.expmonths.focus();
  		return false;
  	}
	else 
	{
		return checkvalid()
	}

}
function checkvalid()
{
	return true;
}
  


