/*
' Copyright (c) 2007 Affno (Pvt) Ltd, . All rights reserved.
'
' This software is the confidential and proprietary information of        
' Affno  ("Confidential Information").  You shall not disclose such 
' Confidential Information and shall use it only in accordance with
' the terms of the license agreement you entered into with Affno.
'
'Module Name	: AFFWEB3
' File Name		: careers.js
' Description	: This is the page where we validate the form.
' Created By	: NISHAN SHANAKA
' Created Date	: 
' Modified By	: 
' Modified Date	: 
' Version		: 1.00.000
*/

function checkForm(){

	//'Name
	strName = document.OnlineApplication.Name.value		
	if (isEmpty(strName)) 
	{
		alert(msgError_emptyName);
		document.OnlineApplication.Name.focus();
		return false;
	}
	else if (!isName(strName))
	{
		alert(msgError_validName);
		document.OnlineApplication.Name.focus();
		return false;
	}
	else if (isSpace(strName))
	{
		alert(msgError_spaceName);
		document.OnlineApplication.Name.value="";
		document.OnlineApplication.Name.focus();
		return false;
	}
	
	//Email
	strEmail = document.OnlineApplication.Email.value
	if (isEmpty(strEmail)) 
	{
		alert(msgError_emptyEmail);
		document.OnlineApplication.Email.focus();
		return false;
	}

	else if (!isEmail(strEmail))
	{
		alert(msgError_validEmail);
		document.OnlineApplication.Email.focus();
		return false;
	}
	else if (isSpace(strEmail))
	{
		alert(msgError_spaceEmail);
		document.OnlineApplication.Email.value="";
		document.OnlineApplication.Email.focus();
		return false;
	}	
	
	//Address
	strAddress = document.OnlineApplication.Address.value
	if (isSpace(strAddress)||(isEmpty(strAddress))) 
	{
		alert(msgError_emptyAddress)
		document.OnlineApplication.Address.value = "";
		document.OnlineApplication.Address.focus();
		return false;
	}

	//Age	
    strAge = document.OnlineApplication.Age.value         
	if (!isEmpty(strAge)) {
 	 if (isSpace(strAge)) 
	 {
 	 alert(msgError_spaceAge);
 	 document.OnlineApplication.Age.focus();
	 document.OnlineApplication.Age.value=""
	 return false;
     }
	 if (!isNumber(strAge)) 
	 {
 	 alert(msgError_validAge);
	 document.OnlineApplication.Age.focus();
	 return false;
     }
    }
	
	//Sex
	if ( ( document.OnlineApplication.Sex[0].checked == false )
    && ( document.OnlineApplication.Sex[1].checked == false ) )
    {
        alert ( "Please choose your Gender: Male or Female" );
        valid = false;
		return false;
    }
	//Resident
	strResident = document.OnlineApplication.Resident.value
	if (!isEmpty(strResident)) {
		if (!isTelephone(strResident)) {
		alert(msgError_validResidance);
		document.OnlineApplication.Resident.focus();
		return false;
		}
	}
	if (isSpace(strResident)) {
		alert(msgError_spaceResidance);
		document.OnlineApplication.Resident.focus();
		document.OnlineApplication.Resident.value=""
		return false;
	}
	
	//Office
	strOffice = document.OnlineApplication.Office.value
	if (!isEmpty(strOffice)) {
		if (!isTelephone(strOffice)) {
		alert(msgError_validOffice);
		document.OnlineApplication.Office.focus();
		return false;
		}
	}
	if (isSpace(strOffice)) {
		alert(msgError_spaceOffice);
		document.OnlineApplication.Office.focus();
		document.OnlineApplication.Office.value=""
		return false;
	}
	
	//Mobile
	strMobile = document.OnlineApplication.Mobile.value
	if (!isEmpty(strMobile)) {
		if (!isTelephone(strMobile)) {
		alert(msgError_validMobile);
		document.OnlineApplication.Mobile.focus();
		return false;
		}
	}
	if (isSpace(strMobile)) {
		alert(msgError_spaceMobile);
		document.OnlineApplication.Mobile.focus();
		document.OnlineApplication.Mobile.value=""
		return false;
	}
	
	//Position
	strDesPosition = document.OnlineApplication.Position.value
	if (isEmpty(strDesPosition)|| (isSpace(strDesPosition))) {
		alert(msgError_SelectPosition);
		document.OnlineApplication.Position.focus();
		return false;
		}
	
	//Comment
	strComment = document.OnlineApplication.Comment.value	
	if (!isEmpty(strComment)) {
		if (strComment.length > 1000) {
		alert(msgError_lengthOfComment);
		document.OnlineApplication.Comment.focus();
		return false;
		}
	}
	if (isSpace(strComment)) {
		alert(msgError_spaceComment);
		document.OnlineApplication.Comment.focus();
		document.OnlineApplication.Comment.value=""
		return false;
	}

	//AttFile
	strAttchFile = document.OnlineApplication.AttFile.value
	if (isEmpty(strAttchFile)|| (isSpace(strAttchFile))) {
		alert(msgError_emptyCV);
		document.OnlineApplication.AttFile.focus();
		document.OnlineApplication.AttFile.value=""
		return false;
		}

	str=document.OnlineApplication.AttFile.value	
	fileLength = str.substring(str.lastIndexOf("\\")+1, str.length)
	if (fileLength.length >500) {
		alert("Please shorten your File Name. It should not exceed 500 characters");
		document.OnlineApplication.AttFile.focus();
		return false;
	}
	
    hidfileextname = str.substring(str.lastIndexOf(".")+1, str.length);
	if ((hidfileextname!="") && ((hidfileextname.toUpperCase() !="PDF") && (hidfileextname.toUpperCase() !="DOC") && (				    hidfileextname.toUpperCase() !="ZIP") && (hidfileextname.toUpperCase() !="DOCX") && (hidfileextname.toUpperCase() !="TXT"))){
		alert("Please select a file which is a .pdf, .doc, .zip and .txt  To be uploaded");
		document.OnlineApplication.AttFile.focus();
		return false;
	}
	
	fname=str.substring(0,str.lastIndexOf("."))
	if ((fname!="") && (fname.indexOf(".")!== -1)){
	  alert("Please select a valid file");
	  document.OnlineApplication.AttFile.focus();
	  return false;
	}
			
	if ((fname!="") && (str.lastIndexOf(".") == -1)) {
		alert("Please select a valid file");
		document.OnlineApplication.AttFile.focus();
		return false;
   	}

	//return false;
}
