/*************************************************************************************
								EMPLOYMENT CATEGORY
*************************************************************************************/

//==================== COUNTER [BEGIN] ====================
function CountDown(f_name, limit, counter)
{
	var inputStr;
	var strlength;
	var maxNumber;
	
	maxNumber = limit;
	if (f_name.value != null)
	{
		inputStr = f_name.value;
		strlength= inputStr.length;
		if (strlength > maxNumber )
		{
			f_name.value=inputStr.substring(0,maxNumber);
			charleft = 0;
		}
		else
		{
			charleft = maxNumber - strlength;
		}
	
	counter.value=charleft;
	//	f_name.value="("+charleft\";
	}
}

//==================== COUNTER [END] ====================


//==================== GENERAL [BEGIN] ====================












function ValidateEmail(email)
{
	var valid;
	var positionOne;
	var positionTwo;
	var positionThree;
	var organisation;
	var emailAddress = new String(email);
	
	valid = 0;
	positionOne = emailAddress.indexOf("@", 0);
	
	positionTwo = emailAddress.indexOf(".", 0);
	//alert(positionTwo);
	
	positionThree = emailAddress.indexOf(".", positionTwo+1);
	
	positionFour = emailAddress.indexOf(".", positionThree+1);
	
	organisation = emailAddress.substr(positionTwo+1);
	
	if (emailAddress != "" && positionOne > 1 && positionTwo > positionOne )
		if (organisation.length == 3)
			valid = 1;
		else if (organisation.length == 6 && positionThree == positionTwo+4)
			valid = 1;
		else
			valid = 0
	else
		valid = 0;
	
	return valid;		
}

function ValidateLength(len, obj)
{
	var txt = new String();
	txt = txt + obj.value;
	if(txt.length > len)
	{
	 alert("Only "+ len +" Characters Allowed");
	 obj.value=txt.substring(0,len-1);
	}
}
//==================== GENERAL [END]   ====================

//==================== MAIN PAGE [BEGIN] ====================

/*else if ( (oldemail.indexOf("@")<1) || (oldemail.indexOf(".")<1)) ) // || hold2.toLowerCase() !="emp" ) || (oldemail=="") || (hold!="emp"))
	{
		alert("You have entered a Invalid Ad Id / E-Mail address /n/rPlz make sure to write emp with ur Adid");
		document.OldUser.oldid.focus();
	}	
*/
function Proceedold() 
{   
    
    var j=0 ;
    var k=0; 
	var oldemail=new String();
	oldemail=document.OldUser.oldemail.value;
	var j2=document.OldUser.oldid.value.length;
	var tmphold=new String();
	var hold2;
	var hold3;
	tmphold=document.OldUser.oldid.value;
	hold2=tmphold.substring(0,3);
	hold3=tmphold.substring(0,2);
 //hold2=document.OldUser.oldid.value.substring(3,j2);
	
		if (document.OldUser.oldid.value=="" || document.OldUser.oldemail.value=="" ) 
    {
		alert("You have entered a wrong Ad Id / E-Mail address");
		document.OldUser.oldid.focus();
	}
	else if ((oldemail.indexOf("@")<1) || (oldemail.indexOf(".")<1) || ( !(hold2.toLowerCase() =="emp" || hold3.toLowerCase() =="cv")) ) 
	{
		alert("You have entered a wrong Ad Id / E-Mail address\n\rPlz make sure to write prefix(emp or cv) with ur Adid");
		document.OldUser.oldid.focus();
	}	
	else
	{
		//document.OldUser.action="check.asp";  	
		
		
		//action = "EmpMember.asp";
		status.value = "Old";
		document.OldUser.submit();
		//submit();
	
	}


}


function ValidateMember()
{
	with(document.Member)
	{
		var emailAddress = new String(Email.value);
		if (AdId.value == "" || !ValidateEmail(emailAddress))
		{
			alert("Invalid Ad Id OR em@il address");
			return;
		}
		action = "EmpMember.asp";
		status.value = "Old";
		submit();
	}
}



function NMember(code)
{
	with(document.NonMember)
	{
		switch(code)
		{
		case 1:
			action = "EmpJobPlacementA.asp";
			subCategory.value = "E";
			break;
		case 2:
			action = "EmpResumeA.asp";
			subCategory.value="R";
			break;
		}
		status.value = "New";
		submit();
	}
}
//==================== MAIN PAGE [END]   ====================

//==================== JOBPLACEMENT [BEGIN] ====================
function ValidateJPFormA()
{
//alert("Hellooo world!!");	
with(document.JobPlacementA)
	{
		//var strJobCity = new String(JobCity.value);
		//strJobCity = strJobCity.toLowerCase();
		//JobCity.value = strJobCity;
		
	var emailchk=new String();
	emailchk=Email.value;
		var count;
		count=0;
		for(ctr1=0; ctr1<CandidateCountry.length; ctr1++)
			if(CandidateCountry[ctr1].selected == true)
				count++;
		
		if(ContactPerson.value == "" || isNaN(parseInt(ContactPerson.value)) == false)
		{
			alert("You have specified an invalid name/designation");
			ContactPerson.focus();
		}
		else if (  (emailchk.indexOf("@")<1) || (emailchk.indexOf(".") <1 ) ) 
		//(!ValidateEmail(Email.value))
		{
			alert("You have specified an invalid em@il address");
			Email.focus();
		}
		else if(CompanyName.value != "" && isNaN(parseInt(CompanyName.value)) == false)
		{
			alert("You have specified an invalid company name");
			CompanyName.focus();
		}
		else if(ContactCode.value != "" && isNaN(parseInt(ContactCode.value)) == true)
		{
			alert("You have specified an invalid contact code");
			ContactCode.focus();
		}
		else if(ContactNumber.value != "" && isNaN(parseInt(ContactNumber.value)) == true)
		{
			alert("You have specified an invalid contact number");
			ContactNumber.focus();
		}
		
		else if(ContactCode.value != "" && ContactNumber.value=="")
		{
			alert("Please enter the Contact Number");
			ContactNumber.focus();
		}
		else if(ContactCode.value == "" && ContactNumber.value!="")
		{
			alert("Please enter the Contact Code");
			ContactCode.focus();
		}
		
		else if(FieldOfCompany.value == "" || isNaN(parseInt(Email.value)) == false)
		{
			alert("You have specified an invalid field of company");
			FieldOfCompany.focus();
		}
		else if(JobCountry.selectedIndex == 0)
		{
			alert("You have specified an invalid job country");
			JobCountry.focus();
		}
		//else if(JobCity.value == "" || isNaN(parseInt(Email.value)) == false)
	//	{
	//		alert("You have specified an invalid job city");
	//		JobCity.focus();
	//	}
		else if(CandidateCountry.selectedIndex == 0)
		{
			alert("You have specified an invalid candidate country");
			CandidateCountry.focus();
		}
		else if(count>5)
		{
			alert("You cannot specify more than 5 candidate countries");
			CandidateCountry.focus();
		}
		else
			return 1;
	}
}

function ValidateJPFormB()
{
	
	with(document.JobPlacementB)
	{
	//alert("I am called");
		var count = 0;
		for(ctr1=0; ctr1<MinimumQualification.length; ctr1++)
			if(MinimumQualification[ctr1].selected == true)
				count++;
		
		if(CandidateCity.selectedIndex == 0)
		{
			alert("You must specify a residence city");
			CandidateCity.focus();
		}
	
		else if(JobCity.selectedIndex =='0')
		{
			alert("You must specify a job city");
			JobCity.focus();
		}
		
		else if(JobType.selectedIndex == 0)
		{
			alert("You have specified an invalid job type");
			JobType.focus();
		}
		else if(JobTitle.value == "" || isNaN(parseInt(JobTitle.value)) == false)
		{
			alert("You have specified an invalid job title");
			JobTitle.focus();
		}
		else if(MinimumQualification.selectedIndex == 0)
		{
			alert("You have specified an invalid minimum qualification");
			MinimumQualification.focus();
		}
		else if(count > 5)
		{
			alert("You cannot specify more than 5 qualifications");
			MinimumQualification.focus();
		}
		else if(region.value != "" && isNaN(parseInt(region.value)) == false)
		{
			alert("You have specified an invalid profession");
			region.focus();
		}
		
		else if(region.selectedIndex == 0 )
		{
			alert("You have specified an invalid profession");
			region.focus();
		}
		
		else if(country.value != "" && isNaN(parseInt(country.value)) == false)
		{
			alert("You have specified an invalid specialized field");
			country.focus();
		}
		
		else if(country.selectedIndex == 0 )
		{
			alert("You have specified an invalid specialized field");
			country.focus();
		}
	
	
		else if(Gender.selectedIndex == 0)
		{
			alert("You have specified an invalid gender");
			Gender.focus();
		}
		else if(MaxAge.selectedIndex == 0)
		{
			alert("You have specified an invalid maximum age");
			MaxAge.focus();
		}
		else if(MinExperience.selectedIndex == 0)
		{
			alert("You have specified an invalid minimum experience");
			MinExperience.focus();
		}
		
		else if(ApplyWithin.selectedIndex == 0)
		{
			alert("Please specify Ad valadity. After this period your Ad will automatically be deleted.");
			ApplyWithin.focus();
		}
		
		else
			return 1;
	}
}

function JPSubmit(mode, status)
{
	if(status == 'New')
	{
		switch(mode)
		{
		case 1:
			if(ValidateJPFormA())
			{
				with(document.JobPlacementA)
				{
					action = "EmpJobPlacementB.asp";
					submit();
				}
			}
			break;
		case 2:
			if(ValidateJPFormB())
			{
				with(document.JobPlacementB)
				{
					action = "EmpConfirm.asp";
					submit();
				}
			}
			break;
		}
	}
	else
	{
		switch(mode)
		{
		case 1:
			if(ValidateJPFormA())
			{
				with(document.JobPlacementA)
				{
					action = "EmpJobPlacementB.asp";
					submit();
				}
			}
			break;
		case 2:
			if(ValidateJPFormB())
			{
				with(document.JobPlacementB)
				{
					action = "EmpUpdateData.asp";
					submit();
				}
			}
			break;
		}
	}
}

function JPReset(mode)
{
	switch(mode)
	{
	case 1:	document.JobPlacementA.reset();	break;
	case 2:	document.JobPlacementB.reset();	break;
	}
}
//==================== JOBPLACEMENT [END]   ====================

//==================== RESUME [BEGIN] ====================
function ValidateRFormA()
{
	with (document.ResumeA)
	{
	var emailchk=new String();
	emailchk=Email.value;
	
		var count=0;
		for(ctr1=1; ctr1<JobCountry.length; ctr1++)
			if(JobCountry[ctr1].selected == true)
				count++;
		
		if(Name.value == "" || isNaN(parseInt(Name.value)) == false)
		{
			alert("You haven't specified your name");
			Name.focus();
		}
		else if (  (emailchk.indexOf("@")<1) || (emailchk.indexOf(".") <1 ) ) 
		{
			alert("You have specified an invalid em@il address");
			Email.focus();
		}
		else if(ContactCode.value != "" && isNaN(parseInt(ContactCode.value)) == true)
		{
			alert("You have specified an invalid contact code");
			ContactCode.focus();
		}
		else if(ContactNumber.value != "" && isNaN(parseInt(ContactNumber.value)) == true)
		{
			alert("You have specified an invalid contact number");
			ContactNumber.focus();
		}
		
		else if(ContactCode.value != "" && ContactNumber.value=="")
		{
			alert("Please enter the Contact Number");
			ContactNumber.focus();
		}
		else if(ContactCode.value == "" && ContactNumber.value!="")
		{
			alert("Please enter the Contact Code");
			ContactCode.focus();
		}
		
		else if(OriginCountry.selectedIndex == 0)
		{
			alert("You have specified an invalid Origin country");
			OriginCountry.focus();
		}	
		else if(ResidenceCountry.selectedIndex == 0)
		{
			alert("You need to specify your country of residence");
			ResidenceCountry.focus();		
		}
				
		else if(Age.selectedIndex == 0)
		{
			alert("You need to specify you age");
			Age.focus();
		}
		else if(Gender.selectedIndex == 0)
		{
			alert("You need to specify your gender");
			Gender.focus();
		}
		else if(MaritalStatus.selectedIndex == 0)
		{
			alert("You have not specified your marital status");
			MaritalStatus.focus();
		}
		else if(Language.selectedIndex == 0)
		{
			alert("You need to specify your mother tongue ");
			Language.focus();
		}
		else if(JobCountry.selectedIndex == 0 || count == 0)
		{
			alert("You need to specify the country where you require the job");
			JobCountry.focus();
		}
		else if(count>5)
		{
			alert("You cannot specify more than 5 countries");
			JobCountry.focus();
		}
		else if(Qualification.selectedIndex == 0)
		{
			alert("You need to specify your qualification");
			Qualification.focus();
		}
		else
			return 1;
	}
}

function ValidateRFormB()
{
//alert("I am click");
//alert (country.selectedIndex.value);
	with(document.ResumeB)
	{
		if(JobCity.selectedIndex == 0)
		{
			alert("You need to specify a job city");
			JobCity.focus();
		}
		else if(ResidenceCity.selectedIndex == 0)
		{
			alert("You need to specify your city of residence");
			ResidenceCity.focus();
		}
		
		else if(region.selectedIndex == 0)
		{
			alert("You need to specify your profession");
			region.focus();
		}
		
	//alert (country.selectedIndex.value);
		else if( (country.selectedIndex == 0) || (country.selectedIndex == "' '") ||(country.selectedIndex == " ") )
		{
			alert("You need to specify your specialized field");
			country.focus();
		}
		
		else if(WorkingExperience.selectedIndex == 0)
		{
			alert("You need to specify your working experience");
			WorkingExperience.focus();
		}
		else if(JobType.selectedIndex == 0)
		{
			alert("You need to specify your job type");
			JobType.focus();
		}
		else
			return 1;
	}
}

function RSubmit(mode, status)
{
	if (status == "New")
	{
		switch(mode)
		{
		case 1:
			if(ValidateRFormA())
			{
				with(document.ResumeA)
				{
					action = "EmpResumeB.asp";
					submit();
				}
			}
			break;
		case 2:
			if(ValidateRFormB())
			{
				with(document.ResumeB)
				{
					action = "EmpConfirm.asp";
					submit();
				}
			}
			break;
		}
	}
	else
	{
		switch(mode)
		{
		case 1:
			if(ValidateRFormA())
			{
				with(document.ResumeA)
				{
					action = "EmpResumeB.asp";
					submit();
				}
			}
			break;
		case 2:
			if(ValidateRFormB())
			{
				with(document.ResumeB)
				{
					action = "EmpUpdateData.asp";
					submit();
				}
			}
			break;
		}
	}
}

function RReset(mode)
{
	switch(mode)
	{
	case 1:	document.ResumeA.reset();	break;
	case 2:	document.ResumeB.reset();	break;
	}
}
//==================== RESUME [END]   ====================

//==================== MEMBER [BEGIN] ====================
//==================== MEMBER [END] ====================

//==================== CONFIRM INFORMATION [BEGIN] ====================
function EmpConfim(mode, action)
{
	alert("emp confirm called");
	/*
	switch(mode)
	{
	case 1:
		if (action == "Submit")	{action = "EmpInsertData.asp";submit();}
		else					{action = "EmpJobPlacement.asp";submit();}
		break;
	case 2:
		break;
	}
	*/
}
//==================== CONFIRM INFORMATION [END] ====================
