// JavaScript Document
// Modified by Ajmal Mohamed
// Modified Date : June 15 2006
// Modified Purpose : Form changes
function SubmitFrmValidation(uploadStatus)
{	
	var objForm=document.frmResume;
	
	if(objForm.ddlPost.value == "0")
	{
		alert("Please select a post to apply");
		objForm.ddlPost.focus();
		return false;
	}
	if(Trim(objForm.txtName.value) == "")
	{
		alert("Please enter the name");
		objForm.txtName.focus();
		return false;
	}
	sName = Trim(objForm.txtName.value);
	sRegExp = /^([A-Za-z\.\s'])*$/i;
	if (sName.search(sRegExp) == -1)		
	{
		alert("Name only allows alphabets, dot or space");
		objForm.txtName.focus();
		return false;
	}
	
	if(Trim(objForm.txtEmail.value) == "")
	{
		alert("Please enter an email");
		objForm.txtEmail.focus();
		return false;
	}
	if(!IsEmail(objForm.txtEmail.value))
	{
		alert("Please enter a valid email");
		objForm.txtEmail.focus();
		return false;	
	}
	if(Trim(objForm.txtTelNo.value) == "")
	{
		alert("Please enter telephone street code ");
		objForm.txtTelNo.focus();
		return false;
	}
	if(isNaN(Trim(objForm.txtTelNo.value)))
	{
		alert("Telephone street code must be numeric");
		objForm.txtTelNo.focus();
		return false;
	}	
	if(Trim(objForm.txtAddress1.value) == "")
	{
		alert("Please enter address");
		objForm.txtAddress1.focus();
		return false;
	}	
	if(objForm.ddlCountry.value == "0")
	{
		alert("Please select the country");
		objForm.ddlCountry.focus();
		return false;
	}
	if(Trim(objForm.txtPin.value) == "")
	{
		alert("Please enter the pin");
		objForm.txtPin.focus();
		return false;
	}
	if(Trim(objForm.ddlTotalExpYear.value) == "0" && Trim(objForm.ddlTotalExpMonth.value) == "0")
	{
		alert("Please select total experience ");
		objForm.ddlTotalExpYear.focus();
		return false;
	}	
	if(Trim(objForm.ddlPostExpYear.value) == "0" && Trim(objForm.ddlPostExpMonth.value) == "0")
	{
		alert("Please select experience in the applied post ");
		objForm.ddlPostExpYear.focus();
		return false;
	}			
	if(Trim(objForm.ddlQual.value) == "0")
	{
		alert("Please select your qualification");
		objForm.ddlQual.focus();
		return false;
	}
	if(objForm.ddlSkillOne.value == "0")
	{
		alert("Please select atleast one skill");
		objForm.ddlSkillOne.focus();
		return false;
	}
	if(objForm.ddlKeySkill1Rate.value == "0")
	{
		alert("Please select a rate for the first skill");
		objForm.ddlKeySkill1Rate.focus();
		return false;
	}
	if(Trim(objForm.ddlSkillOneExpYear.value) == "0" && Trim(objForm.ddlSkillOneExpMonth.value) == "0")
	{
		alert("Please select an experience for first skill ");
		objForm.ddlSkillOneExpYear.focus();
		return false;
	}	
	if(Trim(objForm.fileCVUpload.value) == "")
	{
		alert("Please enter your cv");
		objForm.fileCVUpload.focus();
		return false;
	}
	
	return true;
}

// Trim method
// Accepts one parameter and returns string with all white space removed from both ends.
function Trim(sStringToTrim)
{	
	sStringToTrim = "" + sStringToTrim;
	var iLen = sStringToTrim.length;
	var iFront;
	var iBack;
	for(iFront = 0; iFront < iLen && (sStringToTrim.charAt(iFront) == ' ' || sStringToTrim.charAt(iFront) == '\n' || sStringToTrim.charAt(iFront) == '\r' || sStringToTrim.charAt(iFront) == '\t'); iFront++);
	for(iBack = iLen; iBack > 0 && iBack > iFront && (sStringToTrim.charAt(iBack - 1) == ' ' || sStringToTrim.charAt(iBack - 1) == '\n' || sStringToTrim.charAt(iBack - 1) == '\r' || sStringToTrim.charAt(iBack - 1) == '\t'); iBack--);
	
	return sStringToTrim.substring(iFront, iBack);	
}

// IsEmail method
// Accepts one parameter and returns true if it is a valid email address. Returns false if it is not a valid email.
function IsEmail(sEmail)
{
	sEmail = Trim(sEmail);
//	sEmailRegExp = /^(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})$/i;
	sEmailRegExp = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/i;
	if (sEmail.search(sEmailRegExp) == -1)		
		return false;
	
	return true;
}

function addvalue(dateSelected,monthSelected,yearSelected,obj_element)
{
	var obj_form = document.forms[0];
	if (obj_element.name == "completionDate")
	{
		obj_form.ddlComplDay.selectedIndex = dateSelected-1 ;
		obj_form.ddlComplMonth.selectedIndex = monthSelected ;
		obj_form.ddlComplYear.selectedIndex = func_returnselectedindex(yearSelected) ;
	}
	else if(obj_element.name == "birthDate")
	{
		today1 		=	new	Date()
		yearNow1	=	today1.getFullYear()
		yearPre		=	yearNow1-18;
		if(yearSelected > yearPre)
		{
			alert("Please select a valid birth date.")
			return false;
		}

		obj_form.ddlDOBDay.selectedIndex = dateSelected-1 ;
		obj_form.ddlDOBMonth.selectedIndex = monthSelected ;
		obj_form.ddlDOBYear.selectedIndex = func_returnselectedindex(yearSelected) ;
	}

}

function func_returnselectedindex(par_selected)
{
	var dt_new =  new Date();
	var str_year = dt_new.getFullYear()
	var str_preyear = str_year - 40;
	for(i=str_preyear,j=0;i<str_year+1;i++,j++)
	{
		if (i==par_selected)
		{
			return j;
		}
	}
	if(par_selected < str_preyear){
		alert("Please select a valid year");
	}
	if( par_selected > str_year)
	{
		alert("Please select a valid year");
	}
	
}
function FuncPostAppliedOnChange()
{	
	var objForm = document.forms[0];
	if(objForm.cboPostApplied.options[objForm.cboPostApplied.selectedIndex].value !="")
	{
		var cboType = objForm.cboPostApplied.options[objForm.cboPostApplied.selectedIndex].value;
		TechnicalSkillSelectBox(1,cboType);
		TechnicalSkillSelectBox(2,cboType);
		TechnicalSkillSelectBox(3,cboType);						
	} 
}

function CallOtherQualification()
{
	var objElement = eval("document.forms[0].cboEducation.options[document.forms[0].cboEducation.selectedIndex]");
	var objDivElement = eval("document.getElementById('divEducation').style")
	if((objElement.value) == 8 || (objElement.value) == 9 || (objElement.value) == 10)
	{
		objDivElement.visibility = "visible";
	}
	else
	{
		objDivElement.visibility = "hidden";
	}
}

function CallOtherSkillBox(skillNum)
{
	var objElement = eval("document.forms[0].cboTechnicalSkill"+ skillNum +".options[document.forms[0].cboTechnicalSkill"+ skillNum +".selectedIndex]");
	var objDivElement = eval("document.getElementById('divTechSkill"+ skillNum +"').style")
	if((objElement.value) == 40)
	{
		objDivElement.visibility = "visible";
	}
	else
	{
		objDivElement.visibility = "hidden";
	}

}