function validateEmail( strValue)
{
	var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
	//check for valid email
	return objRegExp.test(strValue);
}
function trimAll( strValue ) 
{
	var objRegExp = /^(\s*)$/;

    //check for all spaces
    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }
    
   //check for leading & trailing spaces
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
	return strValue;
}
function fnShowCountry(formname)
{
	with(document.forms[formname])
	{		
		if(RadExp[0].checked == true && RadExp[1].checked == false)
		{
			document.getElementById("trExpCountry").style.display="";
		}
		else			
		{
			document.getElementById("trExpCountry").style.display="none";
		}
	}
}
function fnRegisterResume(formname)
{
	with(document.forms[formname])
	{					
		if(txtEmpName.value=="")
		{
			alert("Please enter employee name!");
			txtEmpName.focus();
			return false;
		}		
		else if(txtAddress.value=="")
		{
			alert("Please enter the employee address!");
			txtAddress.focus();
			return false;
		}
		else if(txtCountry.value=="")
		{
			alert("Please enter the employee country name!");
			txtCountry.focus();
			return false;
		}		
		else if(txtPhone.value=="")
		{
			alert("Please enter the employee phone number!");
			txtPhone.focus();
			return false;
		}
		else if(txtMobile.value=="")
		{
			alert("Please enter the employee mobile number!");
			txtMobile.focus();
			return false;
		}
		else if(RadSex[0].checked == false && RadSex[1].checked == false)
		{
		  alert("Please select the employee gender!");
		  RadSex[0].focus();
		  return false;
		}
		else if(DdlDobDay.value=="")
		{
			alert("Please select the employee date of birth day!");
			DdlDobDay.focus();
			return false;
		}
		else if(DdlDobMonth.value=="")
		{
			alert("Please select the employee date of birth month!");
			DdlDobMonth.focus();
			return false;
		}
		else if(DdlDobYear.value=="")
		{
			alert("Please select the employee date of birth year!");
			DdlDobYear.focus();
			return false;
		}
		else if(txtPlaceOfBirth.value=="")
		{
			alert("Please enter the employee place of birth!");
			txtPlaceOfBirth.focus();
			return false;
		}
		else if(DdlReligion.value=="")
		{
			alert("Please select the employee religion!");
			DdlReligion.focus();
			return false;
		}
		else if(txtAge.value=="")
		{
			alert("Please enter the employee age!");
			txtAge.focus();
			return false;
		}
		/*if(Arabic1.checked==false && Arabic2.checked==false && Arabic3.checked==false && English1.checked==false && English2.checked==false && English3.checked==false)
		{
		  alert("Please select the employee acknowledge of languages!");
		  Arabic1.focus();
		  return false;
		}*/
		else if(txtPassportNo.value=="")
		{
			alert("Please enter the employee passport number!");
			txtPassportNo.focus();
			return false;
		}
		else if(DdlDoiDay.value=="")
		{
			alert("Please select the employee passport issue day!");
			DdlDoiDay.focus();
			return false;
		}
		else if(DdlDoiMonth.value=="")
		{
			alert("Please select the employee passport issue month!");
			DdlDoiMonth.focus();
			return false;
		}
		else if(DdlDoiYear.value=="")
		{
			alert("Please select the employee passport issue year!");
			DdlDoiYear.focus();
			return false;
		}
		else if(txtPlaceOfIssue.value=="")
		{
			alert("Please enter the employee passport issued place!");
			txtPlaceOfIssue.focus();
			return false;
		}
		else if(DdlDoeDay.value=="")
		{
			alert("Please select the employee passport expiry day!");
			DdlDoeDay.focus();
			return false;
		}
		else if(DdlDoeMonth.value=="")
		{
			alert("Please select the employee passport expiry month");
			DdlDoeMonth.focus();
			return false;
		}
		else if(DdlDoeYear.value=="")
		{
			alert("Please select the employee passport expiry year!");
			DdlDoeYear.focus();
			return false;
		}
		else if(RadExp[0].checked == false && RadExp[1].checked == false)
		{
			alert("Please select work experience!");
			RadExp[0].focus();
			return false;
		}
		else if(RadExp[0].checked == true && RadExp[1].checked == false && DdlExpCountry.value=="")
		{
			alert("Please select work experience country!");
			DdlExpCountry.focus();
			return false;
		}
		else if(DdlPostApply.value=="")
		{
			alert("Please select the Post applying!");
			DdlPostApply.focus();
			return false;
		}
		else if(DdlPostApply.value=="Other" && PAOther.value=="")
		{
			alert("Please enter your post applying!");
			PAOther.focus();
			return false;
		}
		else if(filePassPhoto.value=="" && formname != "frmResumeUpdation")
		{
			alert("Please select the employee passport size photo!");
			filePassPhoto.focus();
			return false;
		}

		HiddenMode.value="Save";
		//alert(HiddenMode.value);
		if(formname == "frmResumeUpdation")
		{
			action="edit_resume.php";
		}
		else
		{
			action="create_resume.php";
		}
		
		submit();
		return true;			
	}
}

function fnEnterKeyWhenListResume(e,formname)
{
	if(e.keyCode==13)
	{
	 if (navigator.appName=="Netscape")
	 {
	  e.preventDefault();
	 }
	else
	  e.keyCode=0;
	  fnSearchListResume(formname);
	}
}

function fnSearchListResume(formname)
{
	with(document.forms[formname])
	{
		if(formname == "frmRequestedResumes")
			action="list_of_requested_resumes.php?SearchWord="+ txtSearchWord.value
		else if(formname == "frmSelectedResumes")
			action="list_of_selected_resumes.php?SearchWord="+ txtSearchWord.value
		else 
			action="list_of_resumes.php?SearchWord="+ txtSearchWord.value
		submit();
		return true;
	}
}
//Function For Search Page
function fnSearchJobDiv(formname)
{
	with(document.forms[formname])
	{			
		/*if(TxtKeyword.value=="" || TxtKeyword.value=="Enter Keywords")
		{
			alert("Please enter search keyword");
			TxtKeyword.focus();
			return false;
		}
		else
		{*/			
			action="list_of_job.php?searchword="+ TxtKeyword.value +"&category="+ DdlJobCategory.value
			submit();
			return true;
		//}
	}
}

function fnSubAgenApplyJobsToJobseeker()
{	
	if(document.addApplicant.name.value=="")
	{
		document.addApplicant.name.focus();
		document.addApplicant.name.select();
		return false;
	}
	if(!validateEmail(document.addApplicant.email.value))
	{
		document.addApplicant.email.focus();
		document.addApplicant.email.select();
		return false;
	}

	if(document.addApplicant.phone.value == "" && document.addApplicant.mobile.value=="")
	{		
		alert("Please Type Correct Phone No or Mobile No");
		document.addApplicant.phone1.focus();
		return false;		
	}	
	if((document.addApplicant.expYears.value=="Null"))
	{
		alert("Please Select Experisnce Years");
		document.addApplicant.expYears.focus();
		return false;
	}
	if((document.addApplicant.reqSalary.value.length<=0) || (isNaN(document.addApplicant.reqSalary.value)) || (document.addApplicant.reqSalary.value<0))
	{
		alert("Please type Required Salary");
		document.addApplicant.reqSalary.focus();
		return false;
	}
	if((document.addApplicant.coverLetter.value.length<=0))
	{
		alert("Please Type Cover Letter");
		document.addApplicant.coverLetter.focus();
		return false;
	}

	if(getCheckedValue(document.addApplicant.selectCV)=="newCV")
	{
		if(document.addApplicant.resume.value.length>0)
		{
			var str=document.addApplicant.resume.value;
			var arr=str.split(".");
			var len=arr.length;
			var val = arr[len-1].toLowerCase();
			if(val!='doc')
			{
			alert("Resume support Doc format only");
			document.addApplicant.resume.focus();
			document.addApplicant.resume.select();
			return false;
			}
		}
		else
		{
			alert("Please Select a Word Document");
			return false;
		}
	}
	if(getCheckedValue(document.addApplicant.selectCV)=="createdCV")
	{
		if(document.addApplicant.createdCVSelect.value=="Null")
		{
			alert("Please Select A Cv From List");
			return false;
		}
	}
	
	var confirmApply = confirm("Are You Sure to Apply for this job");
	if(confirmApply)
	{
		document.addApplicant.action="cls_apply_jobs_now.php";
		document.addApplicant.submit();
			return true;
	}	
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	//alert(radioLength);
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return false;
}

function reqApplyJob()
{
	if(document.previewAdd.DdlJobseeker.value=="")
	{
		alert("Please select the Jobseeker!");
		document.previewAdd.DdlJobseeker.focus();
		return false;
	}
	else
	{
		var AdvId = document.previewAdd.DdlJobseeker.value;
		document.previewAdd.action = "apply_jobs.php?JobSeekerId="+AdvId;
		document.previewAdd.submit();
		return true;			
	}
}


function fnSubAgenApplyJobsFromJobseeker()
{	
	if(document.addApplicant.ddlJobTitle.value=="")
	{
		alert("Please select the Job Advertisement");
		document.addApplicant.ddlJobTitle.focus();
		return false;
	}
	if(document.addApplicant.name.value=="")
	{
		alert("Please enter the Jobseeker name");
		document.addApplicant.name.focus();
		document.addApplicant.name.select();
		return false;
	}
	if(!validateEmail(document.addApplicant.email.value))
	{
		alert("Please enter the Jobseeker email address");
		document.addApplicant.email.focus();
		document.addApplicant.email.select();
		return false;
	}

	if(document.addApplicant.phone.value == "" && document.addApplicant.mobile.value=="")
	{		
		alert("Please Type Correct Phone No or Mobile No");
		document.addApplicant.phone1.focus();
		return false;		
	}	
	if((document.addApplicant.expYears.value=="Null"))
	{
		alert("Please Select Experience Years");
		document.addApplicant.expYears.focus();
		return false;
	}
	if((document.addApplicant.reqSalary.value.length<=0) || (isNaN(document.addApplicant.reqSalary.value)) || (document.addApplicant.reqSalary.value<0))
	{
		alert("Please type Required Salary");
		document.addApplicant.reqSalary.focus();
		return false;
	}
	if((document.addApplicant.coverLetter.value.length<=0))
	{
		alert("Please Type Cover Letter");
		document.addApplicant.coverLetter.focus();
		return false;
	}

	if(getCheckedValue(document.addApplicant.selectCV)=="newCV")
	{
		if(document.addApplicant.resume.value.length>0)
		{
			var str=document.addApplicant.resume.value;
			var arr=str.split(".");
			var len=arr.length;
			var val = arr[len-1].toLowerCase();
			if(val!='doc')
			{
			alert("Resume support Doc format only");
			document.addApplicant.resume.focus();
			document.addApplicant.resume.select();
			return false;
			}
		}
		else
		{
			alert("Please Select a Word Document");
			return false;
		}
	}
	if(getCheckedValue(document.addApplicant.selectCV)=="createdCV")
	{
		if(document.addApplicant.createdCVSelect.value=="Null")
		{
			alert("Please Select A Cv From List");
			return false;
		}
	}
	
	var confirmApply = confirm("Are You Sure to Apply for this job");
	if(confirmApply)
	{
		var jobId = document.addApplicant.ddlJobTitle.value;
		document.addApplicant.action="cls_apply_jobs_now.php?jobId="+jobId;
		document.addApplicant.submit();
			return true;
	}	
}

function fnCreateCvStep1()
{
	if(document.createCv1.fullName.value=="")
	{
		alert("Please enter the jobseeker name!");
		document.createCv1.fullName.select();
		return false;
	}
	if(document.createCv1.CvTitle.value.length<=0)
	{
		alert("Please enter the Cv Title!");
		document.createCv1.CvTitle.focus();
		document.createCv1.CvTitle.select();
		return false;
	}
	if(document.createCv1.address.value.length<=0)
	{
		alert("Please enter the jobseeker address!");
		document.createCv1.address.focus();
		return false;
	}
	if(document.createCv1.phoneNumber.value.length<=0)
	{
		alert("Please enter the jobseeker phone number!");
		document.createCv1.phoneNumber.focus();
		document.createCv1.phoneNumber.select();
		return false;
	}
	else
	{
		var str=document.createCv1.phoneNumber.value;
		var arr=str.split(",");
		var len=arr.length;
		for(i=0; i<len;i++)
		{
		 	if(isNaN(arr[i]))
			{
				alert("Please Type Correct Phone Number.");
				return false;
			}
		}
	}	

	var confirmstep1 = confirm("Make Sure That Given values are correct");
	if(confirmstep1)
	{
		document.createCv1.submit();
	}
	else
	{
		return false;
	}
}

function fnCreateCvStep2()
{	
	if(document.createCv2.job1CompanyName.value=="")
	{
		alert("Please enter the Jobseeker employer name!");
		document.createCv2.job1CompanyName.focus();
		return false;
	}
	else if(document.createCv2.job1TimePeriod.value=="")
	{
		alert("Please enter the Jobseeker experience time period!");
		document.createCv2.job1TimePeriod.focus();
		return false;
	}
	else if(document.createCv2.job1Desc.value=="")
	{
		alert("Please enter the Jobseeker experience description!");
		document.createCv2.job1Desc.focus();
		return false;
	}

	var confirmstep1 = confirm("Make Sure That Given values are correct");
	if(confirmstep1)
	{	
		document.createCv2.submit();
	}
	else
	{
		return false;
	}
}

function fnCreateCvStep3()
{	
	if(document.createCv3.school1Name.value=="")
	{
		alert("Please enter the Jobseeker school name!");
		document.createCv3.school1Name.focus();
		return false;
	}
	else if(document.createCv3.school1Year.value=="")
	{
		alert("Please enter the Jobseeker year of graduation!");
		document.createCv3.school1Year.focus();
		return false;
	}
	else if(document.createCv3.school1Desc.value=="")
	{
		alert("Please enter the Jobseeker study description!");
		document.createCv3.school1Desc.focus();
		return false;
	}

	var confirmstep1 = confirm("Make Sure That Given values are correct!");
	if(confirmstep1)
	{		
		document.createCv3.submit();
	}
	else
	{
		return false;
	}
}

function fnCreateCvStep4()
{	
	if(document.createCv4.summary.value=="")
	{
		alert("Please enter the resume summary!");
		document.createCv4.summary.focus();
		return false;
	}
	else if(document.createCv4.interests.value=="")
	{
		alert("Please enter the Jobseeker interests!");
		document.createCv4.interests.focus();
		return false;
	}

	var confirmstep1 = confirm("Make Sure That Given values are correct!");
	if(confirmstep1)
	{		
		document.createCv4.submit();
	}
	else
	{
		return false;
	}
}
