function clickedExp(){
	var years=document.login.expyears.options[document.login.expyears.selectedIndex].value;
	var mons=document.login.months.options[document.login.months.selectedIndex].value;
	document.login.hidyears.value=years+"-"+mons;
}
function clickedPhone(){
	var ccode=document.login.ccode.value;
	var acode=document.login.acode.value;
	var phone=document.login.phone.value;
	var ret = true;
	if(ccode==null || ccode==" "){
		ret = false;
	}
	if(acode==null || acode==" "){
		ret = false;
	}
	if(phone==null || phone==" "){
		ret = false;
	}
	if(isNaN(ccode)){
		ret = false;
	}
	if(isNaN(acode)){
		ret = false;
	}
	if(isNaN(phone)){
		ret = false;
	}
	
		document.login.hidphone.value=ccode+"-"+acode+"-"+phone;
		 
	 
	return ret;	
}
function clickedCity(sel){
	document.login.hidcity.value=sel.options[sel.options.selectedIndex].value;
}
function clickedRole(sel){
	document.login.hidlevel.value=sel.value;
}
function clickedQual(sel){
	document.login.hidqual.value=sel.options[sel.options.selectedIndex].value;
}
function ValidateForm(param){
	if(param=="login"){
		var val = "true";
		var loginreq = document.getElementById("loginreq");
		var passwordreq = document.getElementById("passwordreq");
		if(document.login.login.value==null || document.login.login.value=="")
		{
			loginreq.innerHTML="<font color=red>Required</font>";
			val = "false";
		}
		else{
			loginreq.innerHTML="";
			val="true";
		}
		if(document.login.password.value==null || document.login.password.value=="")
		{
			passwordreq.innerHTML="<font color=red>Required</font>";
			val = "false";
		}
		else{
			passwordreq.innerHTML="";
			val="true";
		}
		if(val=="true"){
			document.login.action="/itjobs/jlogin.it";
			return true;
		}
		else if(val=="false"){
			return false;
		}
		
	}
}
// check registration fields.
function RegJS(){
	if(checkfields()){
		document.login.action="/itjobs/jregister.it";
		document.login.method="post";
		document.login.submit();
	}
	else{
		return false;
	}
}
function checkfields(){
	if(document.login.loginname.value==null || document.login.loginname.value==""){
		document.getElementById("loginexists").innerHTML="Login Required";
		return false;
	}
	else{
		if (!emailCheck(document.login.loginname.value)){
			return false;
		}
		else{
			document.getElementById("loginexists").innerHTML="";
		}
	}
	var pass = document.login.regpassword.value;
	if(pass==null || pass==""){
		document.getElementById("regpassreq").innerHTML="Password Required";
		return false;
	}
	else{
		if(pass.length<6){
			document.getElementById("regpassreq").innerHTML="Required min 06 chars";
			return false;
		}
		else{
			document.getElementById("regpassreq").innerHTML="";
		}
	}
	var conpass = document.login.confirmpwd.value;
	if(conpass==null || conpass==""){
		document.getElementById("confpassreq").innerHTML="Confirm Password Required";
		return false;
	}
	else{
		if(conpass.length<6){
		document.getElementById("confpassreq").innerHTML="Required min 06 chars";
		return false;
		}
		if(pass!=conpass){
			document.getElementById("confpassreq").innerHTML="Confirm Password should be same as password above";
			return false;
		}
		else{
			document.getElementById("confpassreq").innerHTML="";
		}
	}
	if(document.login.firstname.value==null || document.login.firstname.value==""){ 
		document.getElementById("firstnamereq").innerHTML="First Name Required";
		return false;
	}
	else{
		document.getElementById("firstnamereq").innerHTML="";
	}
	if(document.login.lastname.value==null || document.login.lastname.value==""){
		document.getElementById("lastnamereq").innerHTML="Last Name Required";
		return false;
	}
	else{
		document.getElementById("lastnamereq").innerHTML="";
	}
	var city=document.login.city.options[document.login.city.selectedIndex].value;
	if(city=="-1"){
		document.getElementById("cityreq").innerHTML="Current Location Required";
		return false;
	}
	else{
		document.getElementById("cityreq").innerHTML="";
	}
	if(document.login.state.value==null || document.login.state.value==""){
		document.getElementById("statereq").innerHTML="State Required";
		return false;
	}
	else{
		document.getElementById("statereq").innerHTML="";
	}
	if(document.login.zipcode.value==null || document.login.zipcode.value==""){
		document.getElementById("zipreq").innerHTML="ZipCode Required";
		return false;
	}
	else{
		if(isNaN(document.login.zipcode.value)){
			document.getElementById("zipreq").innerHTML="Digits only.";
			return false;
		}
		else{
			document.getElementById("zipreq").innerHTML="";
		}
	}
	if(document.login.phone.value==null || document.login.phone.value==""){
		document.getElementById("phonereq").innerHTML="Phone Required";
		return false;
	}
	if(!clickedPhone()){
		document.getElementById("phonereq").innerHTML="Digits only.";
		return false;
	}
	else{
		document.getElementById("phonereq").innerHTML="";
	}

	var level=document.login.level.value;
	if(level==""){
		document.getElementById("rolereq").innerHTML="Job Role Required";
		return false;
	}
	else{
		document.getElementById("rolereq").innerHTML="";
	}
	if(document.login.skills.value==null || document.login.skills.value==""){
		document.getElementById("skillsreq").innerHTML="Technical Skills Required";
		return false;
	}
	else{
		document.getElementById("skillsreq").innerHTML="";
	}
	var qualification=document.login.qualification.options[document.login.qualification.selectedIndex].value;
	if(qualification=="-1"){
		document.getElementById("qreq").innerHTML="Qualification Required";
		return false;
	}
	else{
		document.getElementById("qreq").innerHTML="";
	}
	
	clickedExp();
	return true;
	
}
function ValidatePass(pass,conpass){
	if(conpass.length<6){
		document.getElementById("confpassreq").innerHTML="Required min 06 chars";
		return "false";
	}
	if(pass!=conpass){
		document.getElementById("confpassreq").innerHTML="Confirm Password should be same as password above";
		return "false";
	}
	else{
		document.getElementById("confpassreq").innerHTML="";
		
	}
}

function emailCheck (emailStr) {
var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|in|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

document.getElementById("loginexists").innerHTML="Incorrect Login Name(check @)";
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
	document.getElementById("loginexists").innerHTML="Invalid characters in Login Name.";
	return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
	document.getElementById("loginexists").innerHTML="Invalid characters in Login Name.";
	return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid
document.getElementById("loginexists").innerHTML="Invalid Login Name.";
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
	document.getElementById("loginexists").innerHTML="Destination IP address is invalid!";
	return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
	document.getElementById("loginexists").innerHTML="Invalid Login Name";
	return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
	document.getElementById("loginexists").innerHTML="The address must end in a well-known domain or two letter " + "country.";
	return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
	document.getElementById("loginexists").innerHTML="This address is missing a hostname!";
	return false;
}

// If we've gotten this far, everything's valid!
return true;
}
