function onEnter( evt, frm ) {
      var keyCode = null; 
      if( evt.which ) { 
      keyCode = evt.which; 
      } else if( evt.keyCode ) { 
      keyCode = evt.keyCode; 
      } 
      if( 13 == keyCode ) { 
      document.myform.upassword.click(); 
      return false; 
      } 
      return true; 
} 

function checkform(){
var f = document.getElementsByName("myform")[0];


if (f.firstname.value=="") {

alert("Please enter your first name.");
f.firstname.focus();
return false;
}

if (f.lastname.value=="") {

alert("Please enter your last name.");
f.lastname.focus();
return false;
}


for (i=0; i < f.phone_preferred.length; i++){
	if (f.phone_preferred[i].checked){
		var prefPhone = f.phone_preferred[i].value;
	}
}
	
	if (prefPhone == "m" && f.mobile.value == ""){
		
		alert("Please enter your best contact number.");
		f.mobile.focus();
		return false;
	}
	if (prefPhone == "h" && f.homephone.value == ""){
		
		alert("Please enter your best contact number.");
		f.homephone.focus();
		return false;
	}
	if (prefPhone == "w" && f.workphone.value == ""){
		
		alert("Please enter your best contact number.");
		f.workphone.focus();
		return false;
	}
	
if (f.email.value=="") {

alert("Please enter your email address.");
f.email.focus();
return false;
}

if (!validEmail(f.email.value)) {

alert("Please enter a valid Email address.");
f.email.focus();
return false;
}

if (!validEmail(f.confirmemail.value)) {

alert("Please enter a valid Email address.");
f.confirmemail.focus();
return false;
}
if (f.email.value != f.confirmemail.value) {

alert("Your email addresses do not match.  Please check them and try again.");
f.email.focus();
return false;
}



if (f.address.value=="") {

alert("Please enter your address.");
f.address.focus();
return false;
}

if (f.suburb.value=="") {

alert("Please enter your suburb, city or town.");
f.suburb.focus();
return false;
}

if (f.postcode.value=="") {

alert("Please enter your postcode.");
f.postcode.focus();
return false;
}


	
if (f.resume.value=="") {
	
alert("Please attach your resume file.");
	
f.resume.focus();
return false;
}
	

return true;

}

function validEmail(email) {
			//this function also need TrimNumber() function
			invalidChars = " /:,;"
			if (TrimNumber(email) == "" || email.length < 6) {// cannot be empty and less than 6 characters
				return false
			}     
      email = TrimNumber(email);
			for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
				badChar = invalidChars.charAt(i)
				if (email.indexOf(badChar,0) > -1) {
					return false
				}
			}
			atPos = email.indexOf("@",1)			// there must be one "@" symbol
			if (atPos == -1) {
				return false
			}
			if (email.indexOf("@",atPos+1) != -1) {	// and only one "@" symbol
				return false
			}
			periodPos = email.indexOf(".",atPos)
			if (periodPos == -1) {					// and at least one "." after the "@"
				return false
			}
			if (periodPos+3 > email.length)	{		// must be at least 2 characters after the "."
				return false
			}
			return true
}
function TrimNumber(String){			
			var tStart=0;
			var tEnd=0;
			var mStart=0;
			var mEnd=0;	
			for(i=0;tStart=1;i++){		
				if(String.charCodeAt(i)!=32){			
					mStart=i;
					tStart=1;			
					break;
				}
			}
	
			for(i=0;tEnd=1;i++){	  		
				if(String.charCodeAt(String.length-i-1)!=32){
					mEnd=String.length-i
					tEnd=1;
					break;
				}					
			}	
			var StartString=String.substring(0,mStart)
			var FirstTrim=String.replace(StartString,"")
			var LastString=String.substring(mEnd,String.length);
			var SecondTrim=FirstTrim.replace(LastString,"")	
			return SecondTrim;
}
function limitText(limitField) {
fldValue = limitField.value;
var limitNum = 500;
var chars = limitNum - fldValue.length;
if (chars <= 0) {
alert ("You are trying to enter more than the limit of " + limitNum + " characters! ");
fldValue = fldValue.substring(0,limitNum-1)
document.myform.txtcovltr.value = fldValue;
}

}

function pageto(gotopage){
  document.myform.pageno.value=gotopage;
  document.myform.submit();
}	

function saveapp(){
	if (checkform()) {
	  document.myform.submit();

	}
}

function searchresult(){
    document.myform.action = "joblist.php";
    document.myform.submit();
}

function viewadv(){
    document.myform.action = "jobdetail.php";
    document.myform.submit();
}
function jobdetail(id){
    document.myform.jobid.value = id;
    document.myform.action = "jobdetail.php";
    document.myform.submit();
}

function addOption(selectId, val, txt)
{
    var objOption = new Option(txt, val);
    document.getElementById(selectId).options.add(objOption);
}// 
function removeAllOptions(selectName)
{
    for (var element in document.getElementById(selectName))
    {
        document.getElementById(selectName).remove(element);
    }// end for
}// 
function setList(mainid, subid, mainval, subval, subtxt)
{
    removeAllOptions(subid);
    removeAllOptions(subid);
    for(var l = 0; l < mainval.length; l++)
    {
        if(mainval[l] == document.getElementById(mainid).value)
        {
            for(var i = 0; i < subval[l].length; i++)
            { 
                // add options to the select element
                // "subList" should be replaced with
                // the id of the required select element
                addOption(subid, subval[l][i], subtxt[l][i]);
            }// end for i
        }// end if
    }// end for l

}//


var xPos = ((screen.availHeight/2) - 320);
var yPos = ((screen.availWidth/2) - 320);


var popUpWin = null;

function openapplicationform(httpstr)
{
  var width=600;

  if( popUpWin != null && !popUpWin.closed)
  {
    popUpWin.close();
    popUpWin = null;
  }

  //var winName = "popUpWin"+ "-629554623";
  popUpWin = open(httpstr, "winName1111",
  "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width="+width+",height=600,left=0,top=0");
  popUpWin.focus();

}



function openEmailToFriendForm(httpstr) {
  var width=600;

  if( popUpWin != null && !popUpWin.closed)
  {
    popUpWin.close();
    popUpWin = null;
  }

  popUpWin = open(httpstr, "winName1111",
  "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width="+width+",height=215,left=0,top=0");
  popUpWin.focus();
}
