// JavaScript Document
function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}
function check1()
{
		var dtCh= "/";

		if (document.frm.txtjobpostingdate.value=="")
		{
			alert("Please select Posting date");
			return false;
		}
		
		if (document.frm.txtjobclosingdate.value=="")
		{
			alert("Please select Closing date");
			return false;
		}
		d1 = document.frm.txtjobpostingdate.value;
		var pos1=d1.indexOf(dtCh);
		var daysInMonth = DaysArray(12);
		var pos2=d1.indexOf(dtCh,pos1+1)
		var strDay=d1.substring(0,pos1)
		var strMonth=d1.substring(pos1+1,pos2)
		var strYear=d1.substring(pos2+1);
		
		d2 = document.frm.txtjobclosingdate.value;
		var pos1=d2.indexOf(dtCh);
		var daysInMonth = DaysArray(12);
		var pos2=d2.indexOf(dtCh,pos1+1)
		var strDay2=d2.substring(0,pos1)
		var strMonth2=d2.substring(pos1+1,pos2)
		var strYear2=d2.substring(pos2+1);
		if (strYear>strYear2)
		{
			alert("Posting date must be less than or equal to Closing Date");
			return false;
		}
		if (strYear==strYear2 && strMonth>strMonth2)
		{
			alert("Posting date must be less than or equal to Closing Date");
			return false;
		}
		if (strYear==strYear2 && strMonth==strMonth2 && strDay>strDay2)
		{
			alert("Posting date must be less than or equal to Closing Date");
			return false;
		}
		return true;
		
}
function submitfrm(frm)
{ 
	if(trim(frm.txtjobpostingname.value).length==0)
	{
		alert("Please enter post name.");
		frm.txtjobpostingname.focus();
		return false;
	}
	/*if(trim(frm.txtjobtype.value).length==0)
	{
		alert("Please enter job type.");
		frm.txtjobtype.focus();
		return false;
	}
	if(trim(frm.txtjobcompany.value).length==0)
	{
		alert("Please enter company name.");
		frm.txtjobcompany.focus();
		return false;
	}*/
	if(trim(frm.txtjoblocation.value).length==0)
	{
		alert("Please enter job location.");
		frm.txtjoblocation.focus();
		return false;
	}
	if(trim(frm.txtjobsynopsis.value).length==0)
	{
		alert("Please enter synopsis.");
		frm.txtjobsynopsis.focus();
		return false;
	}
	if(trim(frm.txtjobdescription.value).length==0)
	{
		alert("Please enter description.");
		frm.txtjobdescription.focus();
		return false;
	}
	
	if(trim(frm.txtjobpostingdate.value).length==0)
	{
		alert("Please enter posting date.");
		frm.txtjobpostingdate.focus();
		return false;
	}
	if(trim(frm.txtjobclosingdate.value).length==0)
	{
		alert("Please enter closing date.");
		frm.txtjobclosingdate.focus();
		return false;
	}
	if(trim(frm.txtjobcontactnum.value).length==0)
	{
		alert("Please enter contact number.");
		frm.txtjobcontactnum.focus();
		return false;
	}
	if(trim(frm.txtjobemail.value).length==0)
	{
		alert("Please enter email.");
		frm.txtjobemail.focus();
		return false;
	}
	if(trim(frm.sec_code.value).length==0)
	{
		alert("Please enter Security Code.");
		frm.sec_code.focus();
		return false;
	}
	
	if(check1())
	return true;
	else
	return false;
}

function searchrecord()
{
	if(trim(document.frm.txtsearchname.value)=="" && trim(document.frm.txtfromdate.value).length==0 )
	{
		alert("Please enter search keyword.");
		document.frm.txtsearchname.focus();
		return false;
	}
	else
	{
			if(trim(document.frm.txtsearchname.value)!="" && trim(document.frm.cbosearchfld.value)=="" )
			{
				alert("Please select search criteria.");
				document.frm.cbosearchfld.focus();
				return false;
			}
	}
	var fdate, tdate;
	
	if (trim(document.frm.txtfromdate.value).length>0 && trim(document.frm.txttodate.value).length>0)
	{
		arfdate = document.frm.txtfromdate.value.split("/");
		artdate = document.frm.txttodate.value.split("/");
		
		fdate = new Date(arfdate[2],arfdate[1],arfdate[0]);
		tdate = new Date(artdate[2],artdate[1],artdate[0]);
		
		if (fdate>tdate)
		{
			alert("'From' date can not be grater than 'To' date");
			return false;
		}
	}
	
	document.frm.txtcurrentpage.value = "1";
	document.frm.submit();	
}

function searchclear()
{
	window.location.href="jobs_list.php";
}

function setaction(actiontype)
{	
	document.frm.action = "job_db.php";
	
	if (actiontype=="delete")
	{
		mycount = 0;
		
		for(i=0;i<document.frm.elements.length;i++)
		{
			if(document.frm.elements[i].name=="deletedids[]" && document.frm.elements[i].checked)
			{
				mycount++;	
			}
		}

		if(mycount==0)
		{
			alert("You must check atleast one checkbox.");
			return false;
		}
	
		if(confirm("Are you sure you want to delete selected item(s)?"))
		{
			document.frm.mode.value = "delete";
			document.frm.submit();
			return;
		}
		else
			return false;
	}
	else if (actiontype=="active")
	{
		document.frm.mode.value = "active";
		document.frm.submit();		
	}
	
}

function setfocus()
{
	document.frm.txtcmspagename.focus();
}
function search_job()
{
	if (document.frm.frmtxtcurrentpage)
		document.frm.frmtxtcurrentpage.value=1;
	document.frm.submit();
}