// 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 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="cv_list.php";
}
function searchclear_inquiry()
{
	window.location.href="cv_enquiry.php";
}

function setaction(actiontype)
{	
	document.frm.action = "cv_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();		
	}
	/* to send CV */
	else if (actiontype=="sendcv")
	{		
	    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("Please select CV you wish to send by email.");
			return false;
		}
		
		//if(confirm("Are you sure you want to send selected CV in mail ?"))
		else
		{
			 document.frm.action = "send_selectedcv.php";
			 document.frm.mode.value = "sendcv";
			 document.frm.submit();
		}
			   		
	}
	
}
function setInquirtyaction(actiontype)
{
	document.frm.action = "cvenquiry_db.php";
	
	if (actiontype=="delete_inquiry")
	{
		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_inquiry";
			document.frm.submit();
			return;
		}
		else
			return false;
	}
}

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

/* Check blank value of field*/
function checkBlank(id,caption){
	if(document.getElementById(id).value.split(" ").join("")==""){
		alert("Please enter " + caption + ".");
		document.getElementById(id).focus();
		return false;
	}
	return true;
}

/* validate sencCV form */
function validateSendCV()
{
	   		if(checkBlank("txtsendemail","Email Address")==false)
			return false;
		    if(!isEmail(document.getElementById("txtsendemail").value)){
				alert("Please enter valid email address.");
				document.getElementById("txtsendemail").select();
				return false;
		    }
}

/*Function to validate post CV*/
function validatePostCV(frm)
{ 
	
	if(checkBlank("txtcvpostingname","Name")==false)
			return false;
	if(checkBlank("txtjobtitle","Title")==false)
			return false;
	if(checkBlank("txtcvemail","Email address")==false)
			return false;
			if(!isEmail(document.getElementById("txtcvemail").value)){
				alert("Please enter valid email address.");
				document.getElementById("txtcvemail").select();
				return false;
		    }
	if(checkBlank("txtcvstatment","Personal Statement")==false)
			return false;		
		
	if(document.getElementById("mode").value == "add")
	{
		if(document.getElementById("cv_path").value.split(" ").join("")==""){
			alert("Please select file to upload CV");
			document.getElementById("cv_path").focus();
			return false;
		}
		else
		{
			var ext=document.frm.cv_path.value.split(".");
					if (ext[ext.length-1].toUpperCase().split(" ").join("") != 'PDF' && ext[ext.length-1].toUpperCase().split(" ").join("") != 'DOC' ) 
					{
						alert("Please Select valid File !");
						document.frm.cv_path.focus();
						return false;
					}
		}
	}
			
	return true;
}
/* Validation front side Post CV form*/
function submitfrm(frm)
{ 
	
	if(checkBlank("txtcvpostingname","Name")==false)
			return false;
	if(checkBlank("txtjobtitle","Title")==false)
			return false;
	if(checkBlank("txtcvemail","Email address")==false)
			return false;
			if(!isEmail(document.getElementById("txtcvemail").value)){
				alert("Please enter valid email address.");
				document.getElementById("txtcvemail").select();
				return false;
		    }
	if(checkBlank("txtcvstatment","Personal Statement")==false)
			return false;
	if(document.getElementById("cv_path").value.split(" ").join("")==""){
		alert("Please select file to upload CV");
		document.getElementById("cv_path").focus();
		return false;
	}
	else
	{
		var ext=document.frm.cv_path.value.split(".");
				if (ext[ext.length-1].toUpperCase().split(" ").join("") != 'PDF' && ext[ext.length-1].toUpperCase().split(" ").join("") != 'DOC' ) 
				{
					alert("Please Select valid File !");
					document.frm.cv_path.focus();
					return false;
				}
	}
	
	if(checkBlank("sec_code","Security Code")==false)
		return false;
/*	else if(document.getElementById("sec_code").value != document.getElementById("hdnseccode").value )
	    {
		alert("Please check security Code.");
		document.frm.sec_code.focus();
	    return false;
		}*/
		
	return true;
}
